diff --git a/CMakeLists.txt b/CMakeLists.txt index 64a8afbcc..518addedc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -316,6 +316,10 @@ foreach( KBCTRL_BUTTON_START KBCTRL_BUTTON_BACK KBCTRL_MODIFIER_KEY + JOY_AXIS_LEFTX + JOY_AXIS_LEFTY + JOY_AXIS_RIGHTX + JOY_AXIS_RIGHTY JOY_BUTTON_DPAD_LEFT JOY_BUTTON_DPAD_RIGHT JOY_BUTTON_DPAD_UP diff --git a/SourceX/controls/controller_motion.cpp b/SourceX/controls/controller_motion.cpp index d97df7c1f..731c35108 100644 --- a/SourceX/controls/controller_motion.cpp +++ b/SourceX/controls/controller_motion.cpp @@ -1,6 +1,7 @@ #include "controls/controller_motion.h" #include "controls/devices/game_controller.h" +#include "controls/devices/joystick.h" namespace dvl { @@ -85,6 +86,8 @@ bool ProcessControllerMotion(const SDL_Event &event) if (ProcessGameControllerAxisMotion(event)) return true; #endif + if (ProcessJoystickAxisMotion(event)) + return true; return false; } diff --git a/SourceX/controls/devices/joystick.cpp b/SourceX/controls/devices/joystick.cpp index bd48c6414..9109428e7 100644 --- a/SourceX/controls/devices/joystick.cpp +++ b/SourceX/controls/devices/joystick.cpp @@ -1,6 +1,7 @@ #include "controls/devices/joystick.h" +#include "controls/controller_motion.h" #include "stubs.h" #ifdef SWITCH @@ -154,6 +155,41 @@ bool IsJoystickButtonPressed(ControllerButton button) { return joy_button != -1 && SDL_JoystickGetButton(CurrentJoystick(), joy_button); } +bool ProcessJoystickAxisMotion(const SDL_Event &event) +{ + if (event.type != SDL_JOYAXISMOTION) + return false; + switch (event.jaxis.axis) { +#ifdef JOY_AXIS_LEFTX + case JOY_AXIS_LEFTX: + leftStickXUnscaled = event.jaxis.value; + leftStickNeedsScaling = true; + break; +#endif +#ifdef JOY_AXIS_LEFTY + case JOY_AXIS_LEFTY: + leftStickYUnscaled = -event.jaxis.value; + leftStickNeedsScaling = true; + break; +#endif +#ifdef JOY_AXIS_RIGHTX + case JOY_AXIS_RIGHTX: + rightStickXUnscaled = event.jaxis.value; + rightStickNeedsScaling = true; + break; +#endif +#ifdef JOY_AXIS_RIGHTY + case JOY_AXIS_RIGHTY: + rightStickYUnscaled = -event.jaxis.value; + rightStickNeedsScaling = true; + break; +#endif + default: + return false; + } + return true; +} + static SDL_Joystick *current_joystick = nullptr; SDL_Joystick *CurrentJoystick() diff --git a/SourceX/controls/devices/joystick.h b/SourceX/controls/devices/joystick.h index 815fdc74b..14806a57f 100644 --- a/SourceX/controls/devices/joystick.h +++ b/SourceX/controls/devices/joystick.h @@ -11,6 +11,8 @@ ControllerButton JoyButtonToControllerButton(const SDL_Event &event); bool IsJoystickButtonPressed(ControllerButton button); +bool ProcessJoystickAxisMotion(const SDL_Event &event); + SDL_Joystick *CurrentJoystick(); int CurrentJoystickIndex();