summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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;