From 0df741a7997082b100fb7b956b1c1181e201c060 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Mon, 16 Dec 2019 00:05:26 +1000 Subject: [PATCH] Frontend: Disable controller input for navigating UI It seems to interfere too much with normal gameplay. --- dep/imgui/src/imgui_impl_sdl.cpp | 71 +------------------------- src/duckstation/sdl_host_interface.cpp | 3 +- 2 files changed, 2 insertions(+), 72 deletions(-) diff --git a/dep/imgui/src/imgui_impl_sdl.cpp b/dep/imgui/src/imgui_impl_sdl.cpp index bcd9ecf38..892b2ccb1 100644 --- a/dep/imgui/src/imgui_impl_sdl.cpp +++ b/dep/imgui/src/imgui_impl_sdl.cpp @@ -54,7 +54,7 @@ #include "TargetConditionals.h" #endif -#define SDL_HAS_CAPTURE_AND_GLOBAL_MOUSE SDL_VERSION_ATLEAST(2,0,6) +#define SDL_HAS_CAPTURE_AND_GLOBAL_MOUSE SDL_VERSION_ATLEAST(2,0,4) #define SDL_HAS_WINDOW_ALPHA SDL_VERSION_ATLEAST(2,0,5) #define SDL_HAS_ALWAYS_ON_TOP SDL_VERSION_ATLEAST(2,0,5) #define SDL_HAS_USABLE_DISPLAY_BOUNDS SDL_VERSION_ATLEAST(2,0,5) @@ -71,7 +71,6 @@ static Uint64 g_Time = 0; static bool g_MousePressed[3] = { false, false, false }; static SDL_Cursor* g_MouseCursors[ImGuiMouseCursor_COUNT] = {}; static char* g_ClipboardTextData = NULL; -static float g_ControllerNavInputs[ImGuiNavInput_COUNT] = {}; // Forward Declarations static void ImGui_ImplSDL2_InitPlatformInterface(SDL_Window* window, void* sdl_gl_context); @@ -132,74 +131,6 @@ bool ImGui_ImplSDL2_ProcessEvent(const SDL_Event* event) io.KeySuper = ((SDL_GetModState() & KMOD_GUI) != 0); return true; } - - case SDL_CONTROLLERAXISMOTION: - { - const SDL_GameControllerAxis axis = static_cast(event->caxis.axis); - switch (axis) - { - case SDL_CONTROLLER_AXIS_LEFTX: - { - if (event->caxis.value < 0) - { - g_ControllerNavInputs[ImGuiNavInput_LStickLeft] = event->caxis.value < -4000 ? (static_cast(event->caxis.value) / -32768.0f) : 0.0f; - g_ControllerNavInputs[ImGuiNavInput_LStickRight] = 0.0f; - } - else - { - g_ControllerNavInputs[ImGuiNavInput_LStickLeft] = 0.0f; - g_ControllerNavInputs[ImGuiNavInput_LStickRight] = event->caxis.value > 4000 ? static_cast(event->caxis.value) / 32767.0f : 0.0f; - } - - return true; - } - - case SDL_CONTROLLER_AXIS_LEFTY: - { - if (event->caxis.value < 0) - { - g_ControllerNavInputs[ImGuiNavInput_LStickUp] = event->caxis.value < -4000 ? (static_cast(event->caxis.value) / -32768.0f) : 0.0f; - g_ControllerNavInputs[ImGuiNavInput_LStickDown] = 0.0f; - } - else - { - g_ControllerNavInputs[ImGuiNavInput_LStickUp] = 0.0f; - g_ControllerNavInputs[ImGuiNavInput_LStickDown] = event->caxis.value > 4000 ? static_cast(event->caxis.value) / 32767.0f : 0.0f; - } - - return true; - } - - default: - break; - } - } - break; - - case SDL_CONTROLLERBUTTONDOWN: - case SDL_CONTROLLERBUTTONUP: - { - static constexpr unsigned int mapping[][2] = { {SDL_CONTROLLER_BUTTON_A, ImGuiNavInput_Activate}, - {SDL_CONTROLLER_BUTTON_B, ImGuiNavInput_Cancel}, - {SDL_CONTROLLER_BUTTON_Y, ImGuiNavInput_Input}, - // {SDL_CONTROLLER_BUTTON_X, ImGuiNavInput_Menu}, - {SDL_CONTROLLER_BUTTON_LEFTSHOULDER, ImGuiNavInput_FocusPrev}, - {SDL_CONTROLLER_BUTTON_RIGHTSHOULDER, ImGuiNavInput_FocusNext}, - {SDL_CONTROLLER_BUTTON_DPAD_UP, ImGuiNavInput_DpadUp}, - {SDL_CONTROLLER_BUTTON_DPAD_DOWN, ImGuiNavInput_DpadDown}, - {SDL_CONTROLLER_BUTTON_DPAD_LEFT, ImGuiNavInput_DpadLeft}, - {SDL_CONTROLLER_BUTTON_DPAD_RIGHT, ImGuiNavInput_DpadRight} }; - for (int i = 0; i < IM_ARRAYSIZE(mapping); i++) - { - if (event->cbutton.button == mapping[i][0]) - { - g_ControllerNavInputs[mapping[i][1]] = (event->type == SDL_CONTROLLERBUTTONDOWN) ? 1.0f : 0.0f; - return true; - } - } - } - break; - // Multi-viewport support case SDL_WINDOWEVENT: Uint8 window_event = event->window.event; diff --git a/src/duckstation/sdl_host_interface.cpp b/src/duckstation/sdl_host_interface.cpp index f73f552f4..d84c873d3 100644 --- a/src/duckstation/sdl_host_interface.cpp +++ b/src/duckstation/sdl_host_interface.cpp @@ -117,8 +117,7 @@ void SDLHostInterface::CreateImGuiContext() { ImGui::CreateContext(); ImGui::GetIO().IniFilename = nullptr; - ImGui::GetIO().ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard | ImGuiConfigFlags_NavEnableGamepad; - ImGui::GetIO().BackendFlags |= ImGuiBackendFlags_HasGamepad; + ImGui::GetIO().ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; ImGui::StyleColorsDarker(); ImGui::AddRobotoRegularFont();