mirror of
https://github.com/k4zmu2a/SpaceCadetPinball.git
synced 2024-12-18 10:37:53 +01:00
Enabled ImGui navigation with keyboard and game controller.
Ref issue #92.
This commit is contained in:
parent
8ab50ea7b7
commit
200a7dbf79
2 changed files with 12 additions and 3 deletions
|
@ -379,7 +379,9 @@ static void ImGui_ImplSDL2_UpdateGamepads()
|
|||
return;
|
||||
|
||||
// Get gamepad
|
||||
SDL_GameController* game_controller = SDL_GameControllerOpen(0);
|
||||
SDL_GameController* game_controller = nullptr;
|
||||
if (SDL_NumJoysticks() > 0 && SDL_IsGameController(0))
|
||||
game_controller = SDL_GameControllerOpen(0);
|
||||
if (!game_controller)
|
||||
{
|
||||
io.BackendFlags &= ~ImGuiBackendFlags_HasGamepad;
|
||||
|
|
|
@ -144,6 +144,7 @@ int winmain::WinMain(LPCSTR lpCmdLine)
|
|||
ImIO = &io;
|
||||
// ImGui_ImplSDL2_Init is private, we are not actually using ImGui OpenGl backend
|
||||
ImGui_ImplSDL2_InitForOpenGL(window, nullptr);
|
||||
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard | ImGuiConfigFlags_NavEnableGamepad;
|
||||
|
||||
auto prefPath = SDL_GetPrefPath(nullptr, "SpaceCadetPinball");
|
||||
auto iniPath = std::string(prefPath) + "imgui_pb.ini";
|
||||
|
@ -334,7 +335,7 @@ void winmain::RenderUi()
|
|||
if (ImGui::Begin("main", nullptr,
|
||||
ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoBackground |
|
||||
ImGuiWindowFlags_AlwaysAutoResize |
|
||||
ImGuiWindowFlags_NoMove))
|
||||
ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoFocusOnAppearing))
|
||||
{
|
||||
ImGui::PushID(1);
|
||||
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4{});
|
||||
|
@ -347,6 +348,10 @@ void winmain::RenderUi()
|
|||
}
|
||||
ImGui::End();
|
||||
ImGui::PopStyleVar();
|
||||
|
||||
// This window can not loose nav focus for some reason, clear it manually.
|
||||
if (ImGui::IsNavInputDown(ImGuiNavInput_Cancel))
|
||||
ImGui::FocusWindow(NULL);
|
||||
}
|
||||
|
||||
// No demo window in release to save space
|
||||
|
@ -611,12 +616,14 @@ int winmain::event_handler(const SDL_Event* event)
|
|||
default: ;
|
||||
}
|
||||
}
|
||||
if (ImIO->WantCaptureKeyboard)
|
||||
if (ImIO->WantCaptureKeyboard && !options::WaitingForInput())
|
||||
{
|
||||
switch (event->type)
|
||||
{
|
||||
case SDL_KEYDOWN:
|
||||
case SDL_KEYUP:
|
||||
case SDL_CONTROLLERBUTTONDOWN:
|
||||
case SDL_CONTROLLERBUTTONUP:
|
||||
return 1;
|
||||
default: ;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue