From fd4d600694cfc25ee6e8dc3d4387c313d45db60a Mon Sep 17 00:00:00 2001 From: Jaime Moreira Date: Thu, 27 Aug 2020 16:17:54 -0400 Subject: [PATCH] SDL joystick events now work while in menus - DirectInput axes are now X first, Y second. - Menu axes controls swapped/fixed. - Added SDL DualShock3 buttons in menu actions. - Fixed SDL mouse system cursor; it could appear in-game. --- src/common/console/keydef.h | 2 ++ src/common/platform/posix/sdl/i_gui.cpp | 2 ++ src/common/platform/posix/sdl/i_input.cpp | 11 ++++------- src/common/platform/win32/i_dijoy.cpp | 2 +- src/menu/menu.cpp | 13 ++++++++----- 5 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/common/console/keydef.h b/src/common/console/keydef.h index 2cbdf621b..108806774 100644 --- a/src/common/console/keydef.h +++ b/src/common/console/keydef.h @@ -75,6 +75,8 @@ enum EKeyCodes KEY_JOY6, KEY_JOY7, KEY_JOY8, + KEY_JOY14 = KEY_FIRSTJOYBUTTON+13, + KEY_JOY15 = KEY_FIRSTJOYBUTTON+14, KEY_LASTJOYBUTTON = 0x187, KEY_JOYPOV1_UP = 0x188, KEY_JOYPOV1_RIGHT = 0x189, diff --git a/src/common/platform/posix/sdl/i_gui.cpp b/src/common/platform/posix/sdl/i_gui.cpp index d06732624..9290f063f 100644 --- a/src/common/platform/posix/sdl/i_gui.cpp +++ b/src/common/platform/posix/sdl/i_gui.cpp @@ -52,6 +52,7 @@ bool I_SetCursor(FGameTexture *cursorpic) return false; } + SDL_ShowCursor(SDL_DISABLE); if (cursorSurface == NULL) cursorSurface = SDL_CreateRGBSurface (0, 32, 32, 32, MAKEARGB(0,255,0,0), MAKEARGB(0,0,255,0), MAKEARGB(0,0,0,255), MAKEARGB(255,0,0,0)); @@ -67,6 +68,7 @@ bool I_SetCursor(FGameTexture *cursorpic) SDL_FreeCursor (cursor); cursor = SDL_CreateColorCursor (cursorSurface, 0, 0); SDL_SetCursor (cursor); + SDL_ShowCursor(SDL_ENABLE); } else { diff --git a/src/common/platform/posix/sdl/i_input.cpp b/src/common/platform/posix/sdl/i_input.cpp index 846796831..63bf4b638 100644 --- a/src/common/platform/posix/sdl/i_input.cpp +++ b/src/common/platform/posix/sdl/i_input.cpp @@ -493,13 +493,10 @@ void MessagePump (const SDL_Event &sev) case SDL_JOYBUTTONDOWN: case SDL_JOYBUTTONUP: - if (!GUICapture) - { - event.type = sev.type == SDL_JOYBUTTONDOWN ? EV_KeyDown : EV_KeyUp; - event.data1 = KEY_FIRSTJOYBUTTON + sev.jbutton.button; - if(event.data1 != 0) - D_PostEvent(&event); - } + event.type = sev.type == SDL_JOYBUTTONDOWN ? EV_KeyDown : EV_KeyUp; + event.data1 = KEY_FIRSTJOYBUTTON + sev.jbutton.button; + if(event.data1 != 0) + D_PostEvent(&event); break; } } diff --git a/src/common/platform/win32/i_dijoy.cpp b/src/common/platform/win32/i_dijoy.cpp index eb016fdd4..79b6fcf8f 100644 --- a/src/common/platform/win32/i_dijoy.cpp +++ b/src/common/platform/win32/i_dijoy.cpp @@ -459,7 +459,7 @@ void FDInputJoystick::ProcessInput() { // Since we sorted the axes, we know that the first two are definitely X and Y. // They are probably a single stick, so use angular position to determine buttons. - buttonstate = Joy_XYAxesToButtons(axisval, Axes[0].Value); + buttonstate = Joy_XYAxesToButtons(Axes[0].Value, axisval); Joy_GenerateButtonEvents(info->ButtonValue, buttonstate, 4, KEY_JOYAXIS1PLUS); } info->ButtonValue = buttonstate; diff --git a/src/menu/menu.cpp b/src/menu/menu.cpp index 62cfc482a..2780826f9 100644 --- a/src/menu/menu.cpp +++ b/src/menu/menu.cpp @@ -588,16 +588,19 @@ bool M_Responder (event_t *ev) switch (ch) { case KEY_JOY1: + case KEY_JOY3: + case KEY_JOY15: case KEY_PAD_A: mkey = MKEY_Enter; break; case KEY_JOY2: + case KEY_JOY14: case KEY_PAD_B: mkey = MKEY_Back; break; - case KEY_JOY3: + case KEY_JOY4: case KEY_PAD_X: mkey = MKEY_Clear; break; @@ -614,28 +617,28 @@ bool M_Responder (event_t *ev) case KEY_PAD_DPAD_UP: case KEY_PAD_LTHUMB_UP: - case KEY_JOYAXIS1MINUS: + case KEY_JOYAXIS2MINUS: case KEY_JOYPOV1_UP: mkey = MKEY_Up; break; case KEY_PAD_DPAD_DOWN: case KEY_PAD_LTHUMB_DOWN: - case KEY_JOYAXIS1PLUS: + case KEY_JOYAXIS2PLUS: case KEY_JOYPOV1_DOWN: mkey = MKEY_Down; break; case KEY_PAD_DPAD_LEFT: case KEY_PAD_LTHUMB_LEFT: - case KEY_JOYAXIS2MINUS: + case KEY_JOYAXIS1MINUS: case KEY_JOYPOV1_LEFT: mkey = MKEY_Left; break; case KEY_PAD_DPAD_RIGHT: case KEY_PAD_LTHUMB_RIGHT: - case KEY_JOYAXIS2PLUS: + case KEY_JOYAXIS1PLUS: case KEY_JOYPOV1_RIGHT: mkey = MKEY_Right; break;