diff options
author | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2024-01-26 10:13:40 +0100 |
---|---|---|
committer | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2024-01-26 10:13:40 +0100 |
commit | eb2e62609992ab8b47f8805f2bc2cafce271b66f (patch) | |
tree | 58d6c387f910e3a3348a6528127f4216b524ec57 /src/gui/sdlinput.cpp | |
parent | 05dc1666dc794ed6aa7f6568b768c652f8922c4e (diff) | |
parent | 8d06606835e3d01f537ebe96de8b216e64a1f969 (diff) | |
download | mana-eb2e62609992ab8b47f8805f2bc2cafce271b66f.tar.gz mana-eb2e62609992ab8b47f8805f2bc2cafce271b66f.tar.bz2 mana-eb2e62609992ab8b47f8805f2bc2cafce271b66f.tar.xz mana-eb2e62609992ab8b47f8805f2bc2cafce271b66f.zip |
Merge branch 'master' into lpc2012lpc2012
Diffstat (limited to 'src/gui/sdlinput.cpp')
-rw-r--r-- | src/gui/sdlinput.cpp | 120 |
1 files changed, 71 insertions, 49 deletions
diff --git a/src/gui/sdlinput.cpp b/src/gui/sdlinput.cpp index 46636d52..c0f24a7a 100644 --- a/src/gui/sdlinput.cpp +++ b/src/gui/sdlinput.cpp @@ -109,6 +109,23 @@ gcn::MouseInput SDLInput::dequeueMouseInput() return mouseInput; } +bool SDLInput::isTextQueueEmpty() const +{ + return mTextInputQueue.empty(); +} + +TextInput SDLInput::dequeueTextInput() +{ + if (mTextInputQueue.empty()) + { + throw GCN_EXCEPTION("The queue is empty."); + } + + TextInput textInput(mTextInputQueue.front()); + mTextInputQueue.pop(); + return textInput; +} + void SDLInput::pushInput(SDL_Event event) { gcn::KeyInput keyInput; @@ -122,8 +139,8 @@ void SDLInput::pushInput(SDL_Event 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); - keyInput.setNumericPad(event.key.keysym.sym >= SDLK_KP0 + keyInput.setMetaPressed(event.key.keysym.mod & KMOD_GUI); + keyInput.setNumericPad(event.key.keysym.sym >= SDLK_KP_0 && event.key.keysym.sym <= SDLK_KP_EQUALS); mKeyInputQueue.push(keyInput); @@ -135,8 +152,8 @@ void SDLInput::pushInput(SDL_Event 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); - keyInput.setNumericPad(event.key.keysym.sym >= SDLK_KP0 + keyInput.setMetaPressed(event.key.keysym.mod & KMOD_GUI); + keyInput.setNumericPad(event.key.keysym.sym >= SDLK_KP_0 && event.key.keysym.sym <= SDLK_KP_EQUALS); mKeyInputQueue.push(keyInput); @@ -147,19 +164,7 @@ void SDLInput::pushInput(SDL_Event event) mouseInput.setX(event.button.x); mouseInput.setY(event.button.y); mouseInput.setButton(convertMouseButton(event.button.button)); - - if (event.button.button == SDL_BUTTON_WHEELDOWN) - { - mouseInput.setType(gcn::MouseInput::WHEEL_MOVED_DOWN); - } - else if (event.button.button == SDL_BUTTON_WHEELUP) - { - mouseInput.setType(gcn::MouseInput::WHEEL_MOVED_UP); - } - else - { - mouseInput.setType(gcn::MouseInput::PRESSED); - } + mouseInput.setType(gcn::MouseInput::PRESSED); mouseInput.setTimeStamp(SDL_GetTicks()); mMouseInputQueue.push(mouseInput); break; @@ -183,6 +188,35 @@ void SDLInput::pushInput(SDL_Event event) mMouseInputQueue.push(mouseInput); break; + case SDL_MOUSEWHEEL: + if (event.wheel.y) { +#if SDL_VERSION_ATLEAST(2, 26, 0) + mouseInput.setX(event.wheel.mouseX); + mouseInput.setY(event.wheel.mouseY); +#else + int x, y; + SDL_GetMouseState(&x, &y); + mouseInput.setX(x); + mouseInput.setY(y); +#endif + mouseInput.setButton(gcn::MouseInput::EMPTY); + mouseInput.setType(event.wheel.y > 0 ? gcn::MouseInput::WHEEL_MOVED_UP + : gcn::MouseInput::WHEEL_MOVED_DOWN); + mouseInput.setTimeStamp(SDL_GetTicks()); + mMouseInputQueue.push(mouseInput); + } + break; + + case SDL_TEXTINPUT: + mTextInputQueue.emplace(event.text.text); + break; + + // TODO_SDL2: This is now a window event + // case SDL_WINDOWEVENT: + // switch (event.window.event) { + // } + // break; +#if 0 case SDL_ACTIVEEVENT: /* * This occurs when the mouse leaves the window and the Gui-chan @@ -209,7 +243,7 @@ void SDLInput::pushInput(SDL_Event event) mMouseInWindow = true; } break; - +#endif } // end switch } @@ -231,9 +265,9 @@ int SDLInput::convertMouseButton(int button) int SDLInput::convertKeyCharacter(SDL_Event event) { - SDL_keysym keysym = event.key.keysym; + SDL_Keysym keysym = event.key.keysym; - int value = keysym.unicode; + int value = keysym.sym; switch (keysym.sym) { @@ -265,16 +299,10 @@ int SDLInput::convertKeyCharacter(SDL_Event event) value = Key::PAUSE; break; case SDLK_SPACE: - // Special characters like ~ (tilde) ends up - // with the keysym.sym SDLK_SPACE which - // without this check would be lost. The check - // is only valid on key down events in SDL. - if (event.type == SDL_KEYUP || keysym.unicode == ' ') - { - value = Key::SPACE; - } + value = Key::SPACE; break; case SDLK_ESCAPE: + case SDLK_AC_BACK: value = Key::ESCAPE; break; case SDLK_DELETE: @@ -292,7 +320,7 @@ int SDLInput::convertKeyCharacter(SDL_Event event) case SDLK_PAGEUP: value = Key::PAGE_UP; break; - case SDLK_PRINT: + case SDLK_PRINTSCREEN: value = Key::PRINT_SCREEN; break; case SDLK_PAGEDOWN: @@ -343,27 +371,21 @@ int SDLInput::convertKeyCharacter(SDL_Event event) case SDLK_F15: value = Key::F15; break; - case SDLK_NUMLOCK: + case SDLK_NUMLOCKCLEAR: value = Key::NUM_LOCK; break; case SDLK_CAPSLOCK: value = Key::CAPS_LOCK; break; - case SDLK_SCROLLOCK: + case SDLK_SCROLLLOCK: value = Key::SCROLL_LOCK; break; - case SDLK_RMETA: + case SDLK_RGUI: value = Key::RIGHT_META; break; - case SDLK_LMETA: + case SDLK_LGUI: value = Key::LEFT_META; break; - case SDLK_LSUPER: - value = Key::LEFT_SUPER; - break; - case SDLK_RSUPER: - value = Key::RIGHT_SUPER; - break; case SDLK_MODE: value = Key::ALT_GR; break; @@ -394,34 +416,34 @@ int SDLInput::convertKeyCharacter(SDL_Event event) { switch (keysym.sym) { - case SDLK_KP0: + case SDLK_KP_0: value = Key::INSERT; break; - case SDLK_KP1: + case SDLK_KP_1: value = Key::END; break; - case SDLK_KP2: + case SDLK_KP_2: value = Key::DOWN; break; - case SDLK_KP3: + case SDLK_KP_3: value = Key::PAGE_DOWN; break; - case SDLK_KP4: + case SDLK_KP_4: value = Key::LEFT; break; - case SDLK_KP5: + case SDLK_KP_5: value = 0; break; - case SDLK_KP6: + case SDLK_KP_6: value = Key::RIGHT; break; - case SDLK_KP7: + case SDLK_KP_7: value = Key::HOME; break; - case SDLK_KP8: + case SDLK_KP_8: value = Key::UP; break; - case SDLK_KP9: + case SDLK_KP_9: value = Key::PAGE_UP; break; default: |