summaryrefslogtreecommitdiff
path: root/src/input/inputmanager.cpp
diff options
context:
space:
mode:
authorewewukek <ewewukek@gmail.com>2024-01-11 13:50:03 +0300
committerFedja Beader <fedja@protonmail.ch>2024-05-15 00:11:38 +0200
commit1dc559144c8809e2d9ab91a5f90a2047fc0595bc (patch)
tree47fbac5776f2277df4a625cc5a8547c99d28589f /src/input/inputmanager.cpp
parent046ac8fceda89092f01325abbc8d2b5b8602719c (diff)
downloadplus-1dc559144c8809e2d9ab91a5f90a2047fc0595bc.tar.gz
plus-1dc559144c8809e2d9ab91a5f90a2047fc0595bc.tar.bz2
plus-1dc559144c8809e2d9ab91a5f90a2047fc0595bc.tar.xz
plus-1dc559144c8809e2d9ab91a5f90a2047fc0595bc.zip
Gui support for joystick buttons
Diffstat (limited to 'src/input/inputmanager.cpp')
-rw-r--r--src/input/inputmanager.cpp12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/input/inputmanager.cpp b/src/input/inputmanager.cpp
index 0a113bd76..0bffbe231 100644
--- a/src/input/inputmanager.cpp
+++ b/src/input/inputmanager.cpp
@@ -738,7 +738,7 @@ bool InputManager::handleEvent(const SDL_Event &restrict event) restrict2
if (gui != nullptr)
{
const bool res = gui->handleInput();
- if (res && event.type == SDL_KEYDOWN)
+ if (res && (event.type == SDL_KEYDOWN || event.type == SDL_JOYBUTTONDOWN))
{
BLOCK_END("InputManager::handleEvent")
return true;
@@ -1103,7 +1103,6 @@ InputActionT InputManager::getKeyIndex(const int value,
InputActionT InputManager::getActionByKey(const SDL_Event &restrict event)
const restrict2
{
- // for now support only keyboard events
if (event.type == SDL_KEYDOWN || event.type == SDL_KEYUP)
{
const InputActionT idx = keyboard.getActionId(event);
@@ -1113,6 +1112,15 @@ InputActionT InputManager::getActionByKey(const SDL_Event &restrict event)
return idx;
}
}
+ if (joystick != nullptr && event.type == SDL_JOYBUTTONDOWN)
+ {
+ const InputActionT idx = joystick->getActionId(event);
+ if (CAST_S32(idx) >= 0 &&
+ checkKey(&inputActionData[CAST_SIZE(idx)]))
+ {
+ return idx;
+ }
+ }
return InputAction::NO_VALUE;
}