summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/joystick.cpp19
-rw-r--r--src/joystick.h1
2 files changed, 19 insertions, 1 deletions
diff --git a/src/joystick.cpp b/src/joystick.cpp
index bc4572370..6925ca27e 100644
--- a/src/joystick.cpp
+++ b/src/joystick.cpp
@@ -60,7 +60,8 @@ Joystick::Joystick(int no):
mCalibrating(false),
mCalibrated(false),
mButtonsNumber(MAX_BUTTONS),
- mUseInactive(false)
+ mUseInactive(false),
+ mHaveHats(false)
{
if (no >= joystickCount)
no = joystickCount;
@@ -96,6 +97,8 @@ bool Joystick::open()
logger->log("Hats: %i", SDL_JoystickNumHats(mJoystick));
logger->log("Buttons: %i", mButtonsNumber);
+ mHaveHats = (SDL_JoystickNumHats(mJoystick) > 0);
+
if (mButtonsNumber > MAX_BUTTONS)
mButtonsNumber = MAX_BUTTONS;
@@ -164,6 +167,20 @@ void Joystick::update()
else if (position >= mDownTolerance)
mDirection |= DOWN;
+ if (!mDirection && mHaveHats)
+ {
+ // reading only hat 0
+ Uint8 hat = SDL_JoystickGetHat(mJoystick, 0);
+ if (hat & SDL_HAT_RIGHT)
+ mDirection |= RIGHT;
+ else if (hat & SDL_HAT_LEFT)
+ mDirection |= LEFT;
+ if (hat & SDL_HAT_UP)
+ mDirection |= UP;
+ else if (hat & SDL_HAT_DOWN)
+ mDirection |= DOWN;
+ }
+
// Buttons
for (int i = 0; i < mButtonsNumber; i++)
mButtons[i] = (SDL_JoystickGetButton(mJoystick, i) == 1);
diff --git a/src/joystick.h b/src/joystick.h
index 16f4b9bd3..be23599c9 100644
--- a/src/joystick.h
+++ b/src/joystick.h
@@ -129,6 +129,7 @@ class Joystick
bool mCalibrated;
int mButtonsNumber;
bool mUseInactive;
+ bool mHaveHats;
/**
* Is joystick support enabled.