summaryrefslogtreecommitdiff
path: root/src/joystick.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2011-11-09 03:54:55 +0300
committerAndrei Karas <akaras@inbox.ru>2011-11-09 03:58:39 +0300
commita9c6d1da99732437d56b9ca964bb1b13b8d76887 (patch)
tree0c5e8ed1bd721c50dd9e15c564287e131b071251 /src/joystick.cpp
parentffbd974deb426cdda39e1f0137a7fc4df681418d (diff)
downloadmanaverse-a9c6d1da99732437d56b9ca964bb1b13b8d76887.tar.gz
manaverse-a9c6d1da99732437d56b9ca964bb1b13b8d76887.tar.bz2
manaverse-a9c6d1da99732437d56b9ca964bb1b13b8d76887.tar.xz
manaverse-a9c6d1da99732437d56b9ca964bb1b13b8d76887.zip
Add option to use joystick only if game window is active.
Diffstat (limited to 'src/joystick.cpp')
-rw-r--r--src/joystick.cpp50
1 files changed, 31 insertions, 19 deletions
diff --git a/src/joystick.cpp b/src/joystick.cpp
index 3084a5ae6..bc4572370 100644
--- a/src/joystick.cpp
+++ b/src/joystick.cpp
@@ -20,8 +20,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "configuration.h"
#include "joystick.h"
+
+#include "client.h"
+#include "configuration.h"
#include "logger.h"
#include "debug.h"
@@ -57,7 +59,8 @@ Joystick::Joystick(int no):
mRightTolerance(0),
mCalibrating(false),
mCalibrated(false),
- mButtonsNumber(MAX_BUTTONS)
+ mButtonsNumber(MAX_BUTTONS),
+ mUseInactive(false)
{
if (no >= joystickCount)
no = joystickCount;
@@ -102,6 +105,7 @@ bool Joystick::open()
mDownTolerance = config.getIntValue("downTolerance" + toString(mNumber));
mLeftTolerance = config.getIntValue("leftTolerance" + toString(mNumber));
mRightTolerance = config.getIntValue("rightTolerance" + toString(mNumber));
+ mUseInactive = config.getBoolValue("useInactiveJoystick");
return true;
}
@@ -144,23 +148,31 @@ void Joystick::update()
if (!mEnabled || !mCalibrated)
return;
- // X-Axis
- int position = SDL_JoystickGetAxis(mJoystick, 0);
- if (position >= mRightTolerance)
- mDirection |= RIGHT;
- else if (position <= mLeftTolerance)
- mDirection |= LEFT;
-
- // Y-Axis
- position = SDL_JoystickGetAxis(mJoystick, 1);
- if (position <= mUpTolerance)
- mDirection |= UP;
- else if (position >= mDownTolerance)
- mDirection |= DOWN;
-
- // Buttons
- for (int i = 0; i < mButtonsNumber; i++)
- mButtons[i] = (SDL_JoystickGetButton(mJoystick, i) == 1);
+ if (mUseInactive || Client::getInputFocused())
+ {
+ // X-Axis
+ int position = SDL_JoystickGetAxis(mJoystick, 0);
+ if (position >= mRightTolerance)
+ mDirection |= RIGHT;
+ else if (position <= mLeftTolerance)
+ mDirection |= LEFT;
+
+ // Y-Axis
+ position = SDL_JoystickGetAxis(mJoystick, 1);
+ if (position <= mUpTolerance)
+ mDirection |= UP;
+ else if (position >= mDownTolerance)
+ mDirection |= DOWN;
+
+ // Buttons
+ for (int i = 0; i < mButtonsNumber; i++)
+ mButtons[i] = (SDL_JoystickGetButton(mJoystick, i) == 1);
+ }
+ else
+ {
+ for (int i = 0; i < mButtonsNumber; i++)
+ mButtons[i] = false;
+ }
}
void Joystick::startCalibration()