Browse Source

Controller: Support SDL1 joystick axes

pull/420/head
Gleb Mazovetskiy 6 years ago committed by Anders Jenbo
parent
commit
6d7014b0a9
  1. 4
      CMakeLists.txt
  2. 3
      SourceX/controls/controller_motion.cpp
  3. 36
      SourceX/controls/devices/joystick.cpp
  4. 2
      SourceX/controls/devices/joystick.h

4
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

3
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;
}

36
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()

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

Loading…
Cancel
Save