diff options
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/gui.cpp | 16 | ||||
-rw-r--r-- | src/gui/sdlinput.cpp | 198 | ||||
-rw-r--r-- | src/gui/sdlinput.h | 10 |
3 files changed, 118 insertions, 106 deletions
diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index e45bc71c0..61e434d77 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -35,6 +35,8 @@ #include "configlistener.h" #include "configuration.h" #include "graphics.h" +#include "keyevent.h" +#include "keyinput.h" #include "logger.h" #include "resources/image.h" @@ -284,11 +286,14 @@ bool Gui::handleInput() bool Gui::handleKeyInput2() { + if (!guiInput) + return false; + bool consumed(false); while (!mInput->isKeyQueueEmpty()) { - gcn::KeyInput keyInput = mInput->dequeueKeyInput(); + KeyInput keyInput = guiInput->dequeueKeyInput2(); // Save modifiers state mShiftPressed = keyInput.isShiftPressed(); @@ -296,9 +301,10 @@ bool Gui::handleKeyInput2() mControlPressed = keyInput.isControlPressed(); mAltPressed = keyInput.isAltPressed(); - gcn::KeyEvent keyEventToGlobalKeyListeners(nullptr, + KeyEvent keyEventToGlobalKeyListeners(nullptr, mShiftPressed, mControlPressed, mAltPressed, mMetaPressed, - keyInput.getType(), keyInput.isNumericPad(), keyInput.getKey()); + keyInput.getType(), keyInput.isNumericPad(), + keyInput.getActionId(), keyInput.getKey()); distributeKeyEventToGlobalKeyListeners( keyEventToGlobalKeyListeners); @@ -318,10 +324,10 @@ bool Gui::handleKeyInput2() // Send key inputs to the focused widgets if (mFocusHandler->getFocused()) { - gcn::KeyEvent keyEvent(getKeyEventSource(), + KeyEvent keyEvent(getKeyEventSource(), mShiftPressed, mControlPressed, mAltPressed, mMetaPressed, keyInput.getType(), keyInput.isNumericPad(), - keyInput.getKey()); + keyInput.getActionId(), keyInput.getKey()); if (!mFocusHandler->getFocused()->isFocusable()) mFocusHandler->focusNone(); diff --git a/src/gui/sdlinput.cpp b/src/gui/sdlinput.cpp index 3a4940d8b..94519469b 100644 --- a/src/gui/sdlinput.cpp +++ b/src/gui/sdlinput.cpp @@ -58,6 +58,10 @@ #include "sdlinput.h" +#include "keyinput.h" + +#include "inputmanager.h" + #include <guichan/exception.hpp> SDLInput::SDLInput() @@ -71,9 +75,9 @@ bool SDLInput::isKeyQueueEmpty() return mKeyInputQueue.empty(); } -gcn::KeyInput SDLInput::dequeueKeyInput() +KeyInput SDLInput::dequeueKeyInput2() { - gcn::KeyInput keyInput; + KeyInput keyInput; if (mKeyInputQueue.empty()) { @@ -108,107 +112,105 @@ gcn::MouseInput SDLInput::dequeueMouseInput() void SDLInput::pushInput(const SDL_Event &event) { - gcn::KeyInput keyInput; + KeyInput keyInput; gcn::MouseInput mouseInput; switch (event.type) { - 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); - - 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); - - mKeyInputQueue.push(keyInput); - break; - - case SDL_MOUSEBUTTONDOWN: - mMouseDown = true; - 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.setTimeStamp(SDL_GetTicks()); - mMouseInputQueue.push(mouseInput); - break; - - case SDL_MOUSEBUTTONUP: - mMouseDown = false; - mouseInput.setX(event.button.x); - mouseInput.setY(event.button.y); - mouseInput.setButton(convertMouseButton(event.button.button)); - mouseInput.setType(gcn::MouseInput::RELEASED); - mouseInput.setTimeStamp(SDL_GetTicks()); - mMouseInputQueue.push(mouseInput); - break; - - case SDL_MOUSEMOTION: - mouseInput.setX(event.button.x); - mouseInput.setY(event.button.y); - mouseInput.setButton(gcn::MouseInput::EMPTY); - mouseInput.setType(gcn::MouseInput::MOVED); - mouseInput.setTimeStamp(SDL_GetTicks()); - mMouseInputQueue.push(mouseInput); - break; - - case SDL_ACTIVEEVENT: - /* - * This occurs when the mouse leaves the window and the Gui-chan - * application loses its mousefocus. - */ - if ((event.active.state & SDL_APPMOUSEFOCUS) - && !event.active.gain) - { - mMouseInWindow = false; - - if (!mMouseDown) - { - mouseInput.setX(-1); - mouseInput.setY(-1); - mouseInput.setButton(gcn::MouseInput::EMPTY); - mouseInput.setType(gcn::MouseInput::MOVED); - mMouseInputQueue.push(mouseInput); - } - } - - if ((event.active.state & SDL_APPMOUSEFOCUS) - && event.active.gain) - { - mMouseInWindow = true; - } - break; + 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); + int actionId = inputManager.getActionByKey(event); + if (actionId >= 0) + keyInput.setActionId(actionId); + mKeyInputQueue.push(keyInput); + break; + } - default: - 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); + + mKeyInputQueue.push(keyInput); + break; + + case SDL_MOUSEBUTTONDOWN: + mMouseDown = true; + 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.setTimeStamp(SDL_GetTicks()); + mMouseInputQueue.push(mouseInput); + break; + + case SDL_MOUSEBUTTONUP: + mMouseDown = false; + mouseInput.setX(event.button.x); + mouseInput.setY(event.button.y); + mouseInput.setButton(convertMouseButton(event.button.button)); + mouseInput.setType(gcn::MouseInput::RELEASED); + mouseInput.setTimeStamp(SDL_GetTicks()); + mMouseInputQueue.push(mouseInput); + break; + + case SDL_MOUSEMOTION: + mouseInput.setX(event.button.x); + mouseInput.setY(event.button.y); + mouseInput.setButton(gcn::MouseInput::EMPTY); + mouseInput.setType(gcn::MouseInput::MOVED); + mouseInput.setTimeStamp(SDL_GetTicks()); + mMouseInputQueue.push(mouseInput); + break; + + case SDL_ACTIVEEVENT: + /* + * This occurs when the mouse leaves the window and the Gui-chan + * application loses its mousefocus. + */ + if ((event.active.state & SDL_APPMOUSEFOCUS) + && !event.active.gain) + { + mMouseInWindow = false; + + if (!mMouseDown) + { + mouseInput.setX(-1); + mouseInput.setY(-1); + mouseInput.setButton(gcn::MouseInput::EMPTY); + mouseInput.setType(gcn::MouseInput::MOVED); + mMouseInputQueue.push(mouseInput); + } + } + + if ((event.active.state & SDL_APPMOUSEFOCUS) + && event.active.gain) + { + mMouseInWindow = true; + } + break; + + default: + break; } // end switch } diff --git a/src/gui/sdlinput.h b/src/gui/sdlinput.h index af74534c3..c3c0628ff 100644 --- a/src/gui/sdlinput.h +++ b/src/gui/sdlinput.h @@ -68,6 +68,8 @@ #include <guichan/mouseinput.hpp> #include <guichan/platform.hpp> +class KeyInput; + namespace Key { enum @@ -150,13 +152,15 @@ public: virtual void _pollInput() { } + virtual KeyInput dequeueKeyInput2(); + + virtual gcn::KeyInput dequeueKeyInput() + { return gcn::KeyInput(); } // Inherited from Input virtual bool isKeyQueueEmpty(); - virtual gcn::KeyInput dequeueKeyInput(); - virtual bool isMouseQueueEmpty(); virtual gcn::MouseInput dequeueMouseInput(); @@ -180,7 +184,7 @@ protected: */ int convertKeyCharacter(SDL_Event event); - std::queue<gcn::KeyInput> mKeyInputQueue; + std::queue<KeyInput> mKeyInputQueue; std::queue<gcn::MouseInput> mMouseInputQueue; bool mMouseDown; |