summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2011-11-09 04:08:14 +0300
committerAndrei Karas <akaras@inbox.ru>2011-11-09 04:08:14 +0300
commitcda0e9f6f9b9461f87af33f8a2f46c4464d473b5 (patch)
tree8085b03aa12a4470c8442a3c40819de217a26d35
parenta9c6d1da99732437d56b9ca964bb1b13b8d76887 (diff)
downloadmanaverse-cda0e9f6f9b9461f87af33f8a2f46c4464d473b5.tar.gz
manaverse-cda0e9f6f9b9461f87af33f8a2f46c4464d473b5.tar.bz2
manaverse-cda0e9f6f9b9461f87af33f8a2f46c4464d473b5.tar.xz
manaverse-cda0e9f6f9b9461f87af33f8a2f46c4464d473b5.zip
Enable joystick hat support for moving. Now only support hat with index 0.
-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.