Skip to content

Commit

Permalink
Load game controller database. Fixes #25
Browse files Browse the repository at this point in the history
  • Loading branch information
drhelius committed Apr 21, 2020
1 parent ec20614 commit ac4a618
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
10 changes: 10 additions & 0 deletions platforms/desktop-shared/application.cpp
Expand Up @@ -45,6 +45,8 @@ static void frame_throttle(void);

int application_init(void)
{
Log ("<·> %s %s Desktop App <·>", GEARSYSTEM_TITLE, GEARSYSTEM_VERSION);

int ret = sdl_init();

config_init();
Expand Down Expand Up @@ -117,6 +119,14 @@ static int sdl_init(void)

SDL_SetWindowMinimumSize(sdl_window, 770, 600);

application_gamepad_mappings = SDL_GameControllerAddMappingsFromRW(SDL_RWFromFile("gamecontrollerdb.txt", "rb"), 1);

if (application_gamepad_mappings > 0)
Log("Succesfuly loaded %d game controller mappings", application_gamepad_mappings);
else
Log("Game controller database not found!");


int gamepads_found = 0;

for (int i = 0; i < SDL_NumJoysticks(); ++i)
Expand Down
1 change: 1 addition & 0 deletions platforms/desktop-shared/application.h
Expand Up @@ -29,6 +29,7 @@
#endif

EXTERN SDL_GameController* application_gamepad[2];
EXTERN int application_gamepad_mappings;
EXTERN float application_display_scale;
EXTERN SDL_version application_sdl_build_version;
EXTERN SDL_version application_sdl_link_version;
Expand Down
17 changes: 16 additions & 1 deletion platforms/desktop-shared/gui.cpp
Expand Up @@ -882,7 +882,22 @@ static void popup_modal_about(void)
ImGui::Text("Dear ImGui %s (%d)", IMGUI_VERSION, IMGUI_VERSION_NUM);

ImGui::Separator();


for (int i = 0; i < 2; i++)
{
if (application_gamepad[i])
ImGui::Text("Gamepad detected for Player %d", i+1);
else
ImGui::Text("No gamepad detected for Player %d", i+1);
}

if (application_gamepad_mappings > 0)
ImGui::Text("%d gamepad mappings loaded", application_gamepad_mappings);
else
ImGui::Text("Gamepad database not found");

ImGui::Separator();

if (ImGui::Button("OK", ImVec2(120, 0)))
{
ImGui::CloseCurrentPopup();
Expand Down

0 comments on commit ac4a618

Please sign in to comment.