From f3b9f69ba50052fc5339f73b140d6b35bb8b57cb Mon Sep 17 00:00:00 2001 From: Roman Fomin Date: Sun, 11 Feb 2024 16:04:26 +0700 Subject: [PATCH] don't send ev_joystick and ev_mouse if menu is open (#1460) --- src/i_input.c | 21 +++++++++++++++++++-- src/i_input.h | 1 + src/i_video.c | 36 +++++++++++++++++++++++++----------- 3 files changed, 45 insertions(+), 13 deletions(-) diff --git a/src/i_input.c b/src/i_input.c index d366f066..a53fdffd 100644 --- a/src/i_input.c +++ b/src/i_input.c @@ -98,14 +98,31 @@ void I_UpdateJoystick(boolean axis_buttons) if (axis_buttons) { AxisToButtons(&ev); - ev.type = ev_joystick_state; - D_PostEvent(&ev); } ev.type = ev_joystick; D_PostEvent(&ev); } +void I_UpdateJoystickMenu(void) +{ + static event_t ev; + + if (controller == NULL) + { + return; + } + + ev.data1 = GetAxisState(SDL_CONTROLLER_AXIS_LEFTX); + ev.data2 = GetAxisState(SDL_CONTROLLER_AXIS_LEFTY); + ev.data3 = GetAxisState(SDL_CONTROLLER_AXIS_RIGHTX); + ev.data4 = GetAxisState(SDL_CONTROLLER_AXIS_RIGHTY); + + AxisToButtons(&ev); + ev.type = ev_joystick_state; + D_PostEvent(&ev); +} + static void UpdateJoystickButtonState(unsigned int button, boolean on) { static event_t event; diff --git a/src/i_input.h b/src/i_input.h index 1f95d1ae..dca3a943 100644 --- a/src/i_input.h +++ b/src/i_input.h @@ -26,6 +26,7 @@ void I_CloseController(int which); double I_AccelerateMouse(int val); void I_ReadMouse(void); void I_UpdateJoystick(boolean axis_buttons); +void I_UpdateJoystickMenu(void); void I_DelayEvent(void); void I_HandleJoystickEvent(SDL_Event *sdlevent); diff --git a/src/i_video.c b/src/i_video.c index e75dc64a..219cdc51 100644 --- a/src/i_video.c +++ b/src/i_video.c @@ -196,7 +196,15 @@ void I_ShowMouseCursor(boolean on) state = on; } - SDL_ShowCursor(on ? SDL_ENABLE : SDL_DISABLE); + if (on) + { + SDL_ShowCursor(SDL_ENABLE); + } + else + { + SDL_ShowCursor(SDL_DISABLE); + SDL_GetRelativeMouseState(NULL, NULL); + } } // [FG] window event handling from Chocolate Doom 3.0 @@ -458,18 +466,13 @@ void I_StartTic (void) { I_GetEvent(); - if (window_focused) - { - I_ReadMouse(); - } - - if (I_UseController()) - { - I_UpdateJoystick(true); - } - if (menuactive) { + if (I_UseController()) + { + I_UpdateJoystickMenu(); + } + static event_t ev; static int oldx, oldy; static SDL_Rect old_rect; @@ -515,6 +518,17 @@ void I_StartTic (void) ev.data3 = y; D_PostEvent(&ev); + return; + } + + if (window_focused) + { + I_ReadMouse(); + } + + if (I_UseController()) + { + I_UpdateJoystick(true); } }