diff options
author | Andrei Karas <akaras@inbox.ru> | 2012-04-11 03:40:16 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2012-04-11 03:40:16 +0300 |
commit | dc53f8b7f360a489bd10355131339809d66378ef (patch) | |
tree | d97daa27aefe91866e8b64864c58236291f38b14 /src/joystick.cpp | |
parent | c810ee1fe7b42202a66935575a88264911f2c625 (diff) | |
download | mv-dc53f8b7f360a489bd10355131339809d66378ef.tar.gz mv-dc53f8b7f360a489bd10355131339809d66378ef.tar.bz2 mv-dc53f8b7f360a489bd10355131339809d66378ef.tar.xz mv-dc53f8b7f360a489bd10355131339809d66378ef.zip |
Add joystick validation before triggering events from it.
Diffstat (limited to 'src/joystick.cpp')
-rw-r--r-- | src/joystick.cpp | 13 |
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()); +} |