summaryrefslogtreecommitdiff
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
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.
-rw-r--r--src/inputmanager.cpp7
-rw-r--r--src/joystick.cpp13
-rw-r--r--src/joystick.h4
3 files changed, 20 insertions, 4 deletions
diff --git a/src/inputmanager.cpp b/src/inputmanager.cpp
index 8a9e89995..e7ac40cf0 100644
--- a/src/inputmanager.cpp
+++ b/src/inputmanager.cpp
@@ -489,8 +489,11 @@ bool InputManager::handleEvent(const SDL_Event &event)
break;
case SDL_JOYBUTTONDOWN:
- if (triggerAction(joystick->getActionVector(event)))
- return true;
+ if (joystick && joystick->validate())
+ {
+ if (triggerAction(joystick->getActionVector(event)))
+ return true;
+ }
break;
default:
break;
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());
+}
diff --git a/src/joystick.h b/src/joystick.h
index 55b75d373..740fa7cbd 100644
--- a/src/joystick.h
+++ b/src/joystick.h
@@ -121,10 +121,12 @@ class Joystick
KeysVector *getActionVector(const SDL_Event &event);
- int getButtonFromEvent(const SDL_Event &event);
+ int getButtonFromEvent(const SDL_Event &event) const;
bool isActionActive(int index) const;
+ bool validate() const;
+
protected:
unsigned char mDirection;