Frontend: Disable controller input for navigating UI

It seems to interfere too much with normal gameplay.
This commit is contained in:
Connor McLaughlin 2019-12-16 00:05:26 +10:00
parent 6f7154fbef
commit 0df741a799
2 changed files with 2 additions and 72 deletions

View file

@ -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<SDL_GameControllerAxis>(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<float>(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<float>(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<float>(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<float>(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;

View file

@ -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();