SDL: Remove gamepad handler from ImGui
This commit is contained in:
parent
48f78a9c41
commit
96a36f4850
|
@ -245,48 +245,7 @@ static void ImGui_ImplSDL2_UpdateMouseCursor()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ImGui_ImplSDL2_UpdateGamepads()
|
void ImGui_ImplSDL2_NewFrame()
|
||||||
{
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
memset(io.NavInputs, 0, sizeof(io.NavInputs));
|
|
||||||
if ((io.ConfigFlags & ImGuiConfigFlags_NavEnableGamepad) == 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
// Get gamepad
|
|
||||||
SDL_GameController* game_controller = SDL_GameControllerOpen(0);
|
|
||||||
if (!game_controller)
|
|
||||||
{
|
|
||||||
io.BackendFlags &= ~ImGuiBackendFlags_HasGamepad;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update gamepad inputs
|
|
||||||
#define MAP_BUTTON(NAV_NO, BUTTON_NO) { io.NavInputs[NAV_NO] = (SDL_GameControllerGetButton(game_controller, BUTTON_NO) != 0) ? 1.0f : 0.0f; }
|
|
||||||
#define MAP_ANALOG(NAV_NO, AXIS_NO, V0, V1) { float vn = (float)(SDL_GameControllerGetAxis(game_controller, AXIS_NO) - V0) / (float)(V1 - V0); if (vn > 1.0f) vn = 1.0f; if (vn > 0.0f && io.NavInputs[NAV_NO] < vn) io.NavInputs[NAV_NO] = vn; }
|
|
||||||
const int thumb_dead_zone = 8000; // SDL_gamecontroller.h suggests using this value.
|
|
||||||
MAP_BUTTON(ImGuiNavInput_Activate, SDL_CONTROLLER_BUTTON_A); // Cross / A
|
|
||||||
MAP_BUTTON(ImGuiNavInput_Cancel, SDL_CONTROLLER_BUTTON_B); // Circle / B
|
|
||||||
MAP_BUTTON(ImGuiNavInput_Menu, SDL_CONTROLLER_BUTTON_X); // Square / X
|
|
||||||
MAP_BUTTON(ImGuiNavInput_Input, SDL_CONTROLLER_BUTTON_Y); // Triangle / Y
|
|
||||||
MAP_BUTTON(ImGuiNavInput_DpadLeft, SDL_CONTROLLER_BUTTON_DPAD_LEFT); // D-Pad Left
|
|
||||||
MAP_BUTTON(ImGuiNavInput_DpadRight, SDL_CONTROLLER_BUTTON_DPAD_RIGHT); // D-Pad Right
|
|
||||||
MAP_BUTTON(ImGuiNavInput_DpadUp, SDL_CONTROLLER_BUTTON_DPAD_UP); // D-Pad Up
|
|
||||||
MAP_BUTTON(ImGuiNavInput_DpadDown, SDL_CONTROLLER_BUTTON_DPAD_DOWN); // D-Pad Down
|
|
||||||
MAP_BUTTON(ImGuiNavInput_FocusPrev, SDL_CONTROLLER_BUTTON_LEFTSHOULDER); // L1 / LB
|
|
||||||
MAP_BUTTON(ImGuiNavInput_FocusNext, SDL_CONTROLLER_BUTTON_RIGHTSHOULDER); // R1 / RB
|
|
||||||
MAP_BUTTON(ImGuiNavInput_TweakSlow, SDL_CONTROLLER_BUTTON_LEFTSHOULDER); // L1 / LB
|
|
||||||
MAP_BUTTON(ImGuiNavInput_TweakFast, SDL_CONTROLLER_BUTTON_RIGHTSHOULDER); // R1 / RB
|
|
||||||
MAP_ANALOG(ImGuiNavInput_LStickLeft, SDL_CONTROLLER_AXIS_LEFTX, -thumb_dead_zone, -32768);
|
|
||||||
MAP_ANALOG(ImGuiNavInput_LStickRight, SDL_CONTROLLER_AXIS_LEFTX, +thumb_dead_zone, +32767);
|
|
||||||
MAP_ANALOG(ImGuiNavInput_LStickUp, SDL_CONTROLLER_AXIS_LEFTY, -thumb_dead_zone, -32767);
|
|
||||||
MAP_ANALOG(ImGuiNavInput_LStickDown, SDL_CONTROLLER_AXIS_LEFTY, +thumb_dead_zone, +32767);
|
|
||||||
|
|
||||||
io.BackendFlags |= ImGuiBackendFlags_HasGamepad;
|
|
||||||
#undef MAP_BUTTON
|
|
||||||
#undef MAP_ANALOG
|
|
||||||
}
|
|
||||||
|
|
||||||
void ImGui_ImplSDL2_NewFrame(SDL_Window* window)
|
|
||||||
{
|
{
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
|
||||||
|
@ -298,7 +257,4 @@ void ImGui_ImplSDL2_NewFrame(SDL_Window* window)
|
||||||
|
|
||||||
ImGui_ImplSDL2_UpdateMousePosAndButtons();
|
ImGui_ImplSDL2_UpdateMousePosAndButtons();
|
||||||
ImGui_ImplSDL2_UpdateMouseCursor();
|
ImGui_ImplSDL2_UpdateMouseCursor();
|
||||||
|
|
||||||
// Update game controllers (if enabled and available)
|
|
||||||
ImGui_ImplSDL2_UpdateGamepads();
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,5 +24,5 @@ typedef union SDL_Event SDL_Event;
|
||||||
|
|
||||||
IMGUI_IMPL_API bool ImGui_ImplSDL2_Init(SDL_Window* window);
|
IMGUI_IMPL_API bool ImGui_ImplSDL2_Init(SDL_Window* window);
|
||||||
IMGUI_IMPL_API void ImGui_ImplSDL2_Shutdown();
|
IMGUI_IMPL_API void ImGui_ImplSDL2_Shutdown();
|
||||||
IMGUI_IMPL_API void ImGui_ImplSDL2_NewFrame(SDL_Window* window);
|
IMGUI_IMPL_API void ImGui_ImplSDL2_NewFrame();
|
||||||
IMGUI_IMPL_API bool ImGui_ImplSDL2_ProcessEvent(const SDL_Event* event);
|
IMGUI_IMPL_API bool ImGui_ImplSDL2_ProcessEvent(const SDL_Event* event);
|
||||||
|
|
|
@ -1861,7 +1861,7 @@ void SDLHostInterface::Run()
|
||||||
DrawImGuiWindows();
|
DrawImGuiWindows();
|
||||||
|
|
||||||
m_display->Render();
|
m_display->Render();
|
||||||
ImGui_ImplSDL2_NewFrame(m_window);
|
ImGui_ImplSDL2_NewFrame();
|
||||||
ImGui::NewFrame();
|
ImGui::NewFrame();
|
||||||
|
|
||||||
if (System::IsRunning())
|
if (System::IsRunning())
|
||||||
|
|
Loading…
Reference in New Issue