summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorewewukek <ewewukek@gmail.com>2024-01-11 14:20:39 +0300
committerewewukek <ewewukek@gmail.com>2024-03-27 13:18:30 +0300
commit8076db57ec709d76d0861e0fde0aa610d64fdf17 (patch)
tree229085be0cbd40af23f099c6925ce4109d82aedc
parent5fcfc0ae8222de65e83857947e23eb6b449f3f03 (diff)
downloadmanaverse-8076db57ec709d76d0861e0fde0aa610d64fdf17.tar.gz
manaverse-8076db57ec709d76d0861e0fde0aa610d64fdf17.tar.bz2
manaverse-8076db57ec709d76d0861e0fde0aa610d64fdf17.tar.xz
manaverse-8076db57ec709d76d0861e0fde0aa610d64fdf17.zip
Extend gui support to joystick hat (d-pad)
-rw-r--r--src/gui/sdlinput.cpp1
-rw-r--r--src/input/inputmanager.cpp6
-rw-r--r--src/input/joystick.cpp5
-rw-r--r--src/input/joystick.h2
4 files changed, 12 insertions, 2 deletions
diff --git a/src/gui/sdlinput.cpp b/src/gui/sdlinput.cpp
index f9ff0f618..bf6f0536c 100644
--- a/src/gui/sdlinput.cpp
+++ b/src/gui/sdlinput.cpp
@@ -172,6 +172,7 @@ void SDLInput::pushInput(const SDL_Event &event)
}
case SDL_JOYBUTTONDOWN:
+ case SDL_JOYHATMOTION:
{
const InputActionT actionId = inputManager.getActionByKey(event);
if (actionId > InputAction::NO_VALUE)
diff --git a/src/input/inputmanager.cpp b/src/input/inputmanager.cpp
index 8c5b01a7d..1db2fd07d 100644
--- a/src/input/inputmanager.cpp
+++ b/src/input/inputmanager.cpp
@@ -738,7 +738,9 @@ bool InputManager::handleEvent(const SDL_Event &restrict event) restrict2
if (gui != nullptr)
{
const bool res = gui->handleInput();
- if (res && (event.type == SDL_KEYDOWN || event.type == SDL_JOYBUTTONDOWN))
+ const bool joystickActionEvent =
+ joystick != nullptr && joystick->isActionEvent(event);
+ if (res && (event.type == SDL_KEYDOWN || joystickActionEvent))
{
BLOCK_END("InputManager::handleEvent")
return true;
@@ -1112,7 +1114,7 @@ InputActionT InputManager::getActionByKey(const SDL_Event &restrict event)
return idx;
}
}
- if (joystick != nullptr && event.type == SDL_JOYBUTTONDOWN)
+ if (joystick != nullptr && joystick->isActionEvent(event))
{
const InputActionT idx = joystick->getActionId(event);
if (CAST_S32(idx) >= 0 &&
diff --git a/src/input/joystick.cpp b/src/input/joystick.cpp
index 3a4a47fb1..1e375cb0a 100644
--- a/src/input/joystick.cpp
+++ b/src/input/joystick.cpp
@@ -341,6 +341,11 @@ void Joystick::update()
mKeyTimeMap, InputType::JOYSTICK);
}
+bool Joystick::isActionEvent(const SDL_Event &event)
+{
+ return getButtonFromEvent(event) >= 0;
+}
+
KeysVector *Joystick::getActionVector(const SDL_Event &event)
{
const int i = getButtonFromEvent(event);
diff --git a/src/input/joystick.h b/src/input/joystick.h
index 2a43d1a14..293e75a22 100644
--- a/src/input/joystick.h
+++ b/src/input/joystick.h
@@ -147,6 +147,8 @@ class Joystick final
void update();
+ bool isActionEvent(const SDL_Event &event) A_WARN_UNUSED;
+
KeysVector *getActionVector(const SDL_Event &event) A_WARN_UNUSED;
KeysVector *getActionVectorByKey(const int i) A_WARN_UNUSED;