diff options
Diffstat (limited to 'src/i_joystick.c')
-rw-r--r-- | src/i_joystick.c | 48 |
1 files changed, 41 insertions, 7 deletions
diff --git a/src/i_joystick.c b/src/i_joystick.c index c363cfaa..8822f288 100644 --- a/src/i_joystick.c +++ b/src/i_joystick.c @@ -96,6 +96,11 @@ static boolean IsValidAxis(int axis) return true; } + if (IS_HAT_AXIS(axis)) + { + return HAT_AXIS_HAT(axis) < SDL_JoystickNumHats(joystick); + } + num_axes = SDL_JoystickNumAxes(joystick); return axis < num_axes; @@ -187,12 +192,13 @@ static int GetAxisState(int axis, int invert) return 0; } - // Is this a button axis? If so, we need to handle it specially. + // Is this a button axis, or a hat axis? + // If so, we need to handle it specially. + + result = 0; if (IS_BUTTON_AXIS(axis)) { - result = 0; - if (SDL_JoystickGetButton(joystick, BUTTON_AXIS_NEG(axis))) { result -= 32767; @@ -202,14 +208,37 @@ static int GetAxisState(int axis, int invert) result += 32767; } } - else + else if (IS_HAT_AXIS(axis)) { - result = SDL_JoystickGetAxis(joystick, axis); + int direction = HAT_AXIS_DIRECTION(axis); + int hatval = SDL_JoystickGetHat(joystick, HAT_AXIS_HAT(axis)); - if (invert) + if (direction == HAT_AXIS_HORIZONTAL) { - result = -result; + if ((hatval & SDL_HAT_LEFT) != 0) + { + result -= 32767; + } + else if ((hatval & SDL_HAT_RIGHT) != 0) + { + result += 32767; + } } + else if (direction == HAT_AXIS_VERTICAL) + { + if ((hatval & SDL_HAT_UP) != 0) + { + result -= 32767; + } + else if ((hatval & SDL_HAT_DOWN) != 0) + { + result += 32767; + } + } + } + else + { + result = SDL_JoystickGetAxis(joystick, axis); if (result < DEAD_ZONE && result > -DEAD_ZONE) { @@ -217,6 +246,11 @@ static int GetAxisState(int axis, int invert) } } + if (invert) + { + result = -result; + } + return result; } |