summaryrefslogtreecommitdiff
path: root/src/joystick.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2012-04-11 03:40:16 +0300
committerAndrei Karas <akaras@inbox.ru>2012-04-11 03:40:16 +0300
commitdc53f8b7f360a489bd10355131339809d66378ef (patch)
treed97daa27aefe91866e8b64864c58236291f38b14 /src/joystick.cpp
parentc810ee1fe7b42202a66935575a88264911f2c625 (diff)
downloadplus-dc53f8b7f360a489bd10355131339809d66378ef.tar.gz
plus-dc53f8b7f360a489bd10355131339809d66378ef.tar.bz2
plus-dc53f8b7f360a489bd10355131339809d66378ef.tar.xz
plus-dc53f8b7f360a489bd10355131339809d66378ef.zip
Add joystick validation before triggering events from it.
Diffstat (limited to 'src/joystick.cpp')
-rw-r--r--src/joystick.cpp13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/joystick.cpp b/src/joystick.cpp
index 2bd8b582a..3222c9825 100644
--- a/src/joystick.cpp
+++ b/src/joystick.cpp
@@ -275,7 +275,7 @@ KeysVector *Joystick::getActionVector(const SDL_Event &event)
return nullptr;
}
-int Joystick::getButtonFromEvent(const SDL_Event &event)
+int Joystick::getButtonFromEvent(const SDL_Event &event) const
{
if (event.jbutton.which != mNumber)
return -1;
@@ -284,6 +284,9 @@ int Joystick::getButtonFromEvent(const SDL_Event &event)
bool Joystick::isActionActive(int index) const
{
+ if (!validate())
+ return false;
+
const KeyFunction &key = inputManager.getKey(index);
for (size_t i = 0; i < KeyFunctionSize; i ++)
{
@@ -298,3 +301,11 @@ bool Joystick::isActionActive(int index) const
}
return false;
}
+
+bool Joystick::validate() const
+{
+ if (mCalibrating || !mEnabled || !mCalibrated)
+ return false;
+
+ return (mUseInactive || Client::getInputFocused());
+}