diff options
author | Andrei Karas <akaras@inbox.ru> | 2013-08-23 18:03:05 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2013-08-24 21:08:16 +0300 |
commit | c7f5d0a71d7318ccc4c3f28ab90d688a1a0868b3 (patch) | |
tree | 6585eb0acd0afa4f11cd0b87661ce527cabda9ae /src/gui/sdlinput.cpp | |
parent | b9fe47de21f8c899bfe36f70633a8c8110314d77 (diff) | |
download | manaplus-c7f5d0a71d7318ccc4c3f28ab90d688a1a0868b3.tar.gz manaplus-c7f5d0a71d7318ccc4c3f28ab90d688a1a0868b3.tar.bz2 manaplus-c7f5d0a71d7318ccc4c3f28ab90d688a1a0868b3.tar.xz manaplus-c7f5d0a71d7318ccc4c3f28ab90d688a1a0868b3.zip |
fix keyboard handling in gui in SDL2.
Diffstat (limited to 'src/gui/sdlinput.cpp')
-rw-r--r-- | src/gui/sdlinput.cpp | 43 |
1 files changed, 23 insertions, 20 deletions
diff --git a/src/gui/sdlinput.cpp b/src/gui/sdlinput.cpp index fd72cb962..19ec87f02 100644 --- a/src/gui/sdlinput.cpp +++ b/src/gui/sdlinput.cpp @@ -60,6 +60,7 @@ #include "inputmanager.h" #include "keydata.h" +#include "logger.h" #include "mouseinput.h" #include "sdlshared.h" @@ -133,34 +134,16 @@ void SDLInput::pushInput(const SDL_Event &event) { case SDL_KEYDOWN: { - keyInput.setKey(gcn::Key(convertKeyCharacter(event))); keyInput.setType(gcn::KeyInput::PRESSED); - keyInput.setShiftPressed(event.key.keysym.mod & KMOD_SHIFT); - keyInput.setControlPressed(event.key.keysym.mod & KMOD_CTRL); - keyInput.setAltPressed(event.key.keysym.mod & KMOD_ALT); - keyInput.setMetaPressed(event.key.keysym.mod & KMOD_META); - keyInput.setNumericPad(event.key.keysym.sym >= SDLK_KP0 - && event.key.keysym.sym <= SDLK_KP_EQUALS); - const int actionId = inputManager.getActionByKey(event); - if (actionId >= 0) - keyInput.setActionId(actionId); + convertKeyEventToKey(event, keyInput); mKeyInputQueue.push(keyInput); break; } case SDL_KEYUP: { - keyInput.setKey(gcn::Key(convertKeyCharacter(event))); keyInput.setType(gcn::KeyInput::RELEASED); - keyInput.setShiftPressed(event.key.keysym.mod & KMOD_SHIFT); - keyInput.setControlPressed(event.key.keysym.mod & KMOD_CTRL); - keyInput.setAltPressed(event.key.keysym.mod & KMOD_ALT); - keyInput.setMetaPressed(event.key.keysym.mod & KMOD_META); - keyInput.setNumericPad(event.key.keysym.sym >= SDLK_KP0 - && event.key.keysym.sym <= SDLK_KP_EQUALS); - const int actionId = inputManager.getActionByKey(event); - if (actionId >= 0) - keyInput.setActionId(actionId); + convertKeyEventToKey(event, keyInput); mKeyInputQueue.push(keyInput); break; } @@ -249,6 +232,26 @@ void SDLInput::pushInput(const SDL_Event &event) } // end switch } +void SDLInput::convertKeyEventToKey(const SDL_Event &event, KeyInput &keyInput) +{ + keyInput.setKey(gcn::Key(convertKeyCharacter(event))); + keyInput.setShiftPressed(event.key.keysym.mod & KMOD_SHIFT); + keyInput.setControlPressed(event.key.keysym.mod & KMOD_CTRL); + keyInput.setAltPressed(event.key.keysym.mod & KMOD_ALT); + keyInput.setMetaPressed(event.key.keysym.mod & KMOD_META); +#ifdef USE_SDL2 + const int code = event.key.keysym.scancode; + keyInput.setNumericPad((code >= SDL_SCANCODE_KP_DIVIDE + && code <= SDL_SCANCODE_KP_PERIOD) || code == SDL_SCANCODE_KP_EQUALS); +#else + const int code = event.key.keysym.sym; + keyInput.setNumericPad(code >= SDLK_KP0 && code <= SDLK_KP_EQUALS); +#endif + const int actionId = inputManager.getActionByKey(event); + if (actionId >= 0) + keyInput.setActionId(actionId); +} + int SDLInput::convertMouseButton(const int button) { switch (button) |