diff options
author | Arisotura <thetotalworm@gmail.com> | 2019-06-20 16:31:28 +0200 |
---|---|---|
committer | Arisotura <thetotalworm@gmail.com> | 2019-06-20 16:31:28 +0200 |
commit | e2dc98d1449c3e6682837f04eda60814f8d6a5fc (patch) | |
tree | 77a5ac99cff93aecd54bea97827a495e2a320019 /src/libui_sdl/main.cpp | |
parent | f59094e033fafc28664700061e2726be70a1568c (diff) |
fix bug when mapping a joystick axis control but no button
Diffstat (limited to 'src/libui_sdl/main.cpp')
-rw-r--r-- | src/libui_sdl/main.cpp | 37 |
1 files changed, 21 insertions, 16 deletions
diff --git a/src/libui_sdl/main.cpp b/src/libui_sdl/main.cpp index 693e9e3..01f67d7 100644 --- a/src/libui_sdl/main.cpp +++ b/src/libui_sdl/main.cpp @@ -710,26 +710,31 @@ bool JoystickButtonDown(int val) { if (val == -1) return false; - if (val & 0x100) + bool hasbtn = ((val & 0xFFFF) != 0xFFFF); + + if (hasbtn) { - int hatnum = (val >> 4) & 0xF; - int hatdir = val & 0xF; - Uint8 hatval = SDL_JoystickGetHat(Joystick, hatnum); + if (val & 0x100) + { + int hatnum = (val >> 4) & 0xF; + int hatdir = val & 0xF; + Uint8 hatval = SDL_JoystickGetHat(Joystick, hatnum); - bool pressed = false; - if (hatdir == 0x1) pressed = (hatval & SDL_HAT_UP); - else if (hatdir == 0x4) pressed = (hatval & SDL_HAT_DOWN); - else if (hatdir == 0x2) pressed = (hatval & SDL_HAT_RIGHT); - else if (hatdir == 0x8) pressed = (hatval & SDL_HAT_LEFT); + bool pressed = false; + if (hatdir == 0x1) pressed = (hatval & SDL_HAT_UP); + else if (hatdir == 0x4) pressed = (hatval & SDL_HAT_DOWN); + else if (hatdir == 0x2) pressed = (hatval & SDL_HAT_RIGHT); + else if (hatdir == 0x8) pressed = (hatval & SDL_HAT_LEFT); - if (pressed) return true; - } - else - { - int btnnum = val & 0xFFFF; - Uint8 btnval = SDL_JoystickGetButton(Joystick, btnnum); + if (pressed) return true; + } + else + { + int btnnum = val & 0xFFFF; + Uint8 btnval = SDL_JoystickGetButton(Joystick, btnnum); - if (btnval) return true; + if (btnval) return true; + } } if (val & 0x10000) |