diff options
author | Andrei Karas <akaras@inbox.ru> | 2013-08-23 19:12:36 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2013-08-24 21:08:16 +0300 |
commit | 270d6d2753473955a2b691a934eb2e550d13ebc3 (patch) | |
tree | 2ba55bab0c21b1775bfcd85e80d24cbfbbe652e9 /src/gui | |
parent | c7f5d0a71d7318ccc4c3f28ab90d688a1a0868b3 (diff) | |
download | plus-270d6d2753473955a2b691a934eb2e550d13ebc3.tar.gz plus-270d6d2753473955a2b691a934eb2e550d13ebc3.tar.bz2 plus-270d6d2753473955a2b691a934eb2e550d13ebc3.tar.xz plus-270d6d2753473955a2b691a934eb2e550d13ebc3.zip |
fix gui text input in SDL2.
copy/paste broken for SDL2.
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/gui.cpp | 5 | ||||
-rw-r--r-- | src/gui/sdlinput.cpp | 9 | ||||
-rw-r--r-- | src/gui/sdlinput.h | 3 | ||||
-rw-r--r-- | src/gui/widgets/textfield.cpp | 16 |
4 files changed, 31 insertions, 2 deletions
diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index ba7a0de06..8068ffad7 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -376,6 +376,9 @@ bool Gui::handleKeyInput2() keyInput.getType(), keyInput.isNumericPad(), keyInput.getActionId(), keyInput.getKey()); + if (!keyInput.getText().empty()) + keyEventToGlobalKeyListeners.setText(keyInput.getText()); + distributeKeyEventToGlobalKeyListeners( keyEventToGlobalKeyListeners); @@ -398,6 +401,8 @@ bool Gui::handleKeyInput2() mShiftPressed, mControlPressed, mAltPressed, mMetaPressed, keyInput.getType(), keyInput.isNumericPad(), keyInput.getActionId(), keyInput.getKey()); + if (!keyInput.getText().empty()) + keyEvent.setText(keyInput.getText()); if (!mFocusHandler->getFocused()->isFocusable()) mFocusHandler->focusNone(); diff --git a/src/gui/sdlinput.cpp b/src/gui/sdlinput.cpp index 19ec87f02..884ce25dd 100644 --- a/src/gui/sdlinput.cpp +++ b/src/gui/sdlinput.cpp @@ -148,6 +148,15 @@ void SDLInput::pushInput(const SDL_Event &event) break; } +#ifdef USE_SDL2 + case SDL_TEXTINPUT: + keyInput.setType(gcn::KeyInput::PRESSED); + keyInput.setKey(gcn::Key(Key::TEXTINPUT)); + keyInput.setText(event.text.text); + mKeyInputQueue.push(keyInput); + break; +#endif + #ifdef ANDROID case SDL_ACCELEROMETER: break; diff --git a/src/gui/sdlinput.h b/src/gui/sdlinput.h index cbe5863ed..8f0f0b793 100644 --- a/src/gui/sdlinput.h +++ b/src/gui/sdlinput.h @@ -122,7 +122,8 @@ namespace Key LEFT, RIGHT, UP, - DOWN + DOWN, + TEXTINPUT }; } // namespace Key diff --git a/src/gui/widgets/textfield.cpp b/src/gui/widgets/textfield.cpp index bc2d9c946..0fec552e3 100644 --- a/src/gui/widgets/textfield.cpp +++ b/src/gui/widgets/textfield.cpp @@ -195,7 +195,20 @@ int TextField::getValue() const void TextField::keyPressed(gcn::KeyEvent &keyEvent) { const int val = keyEvent.getKey().getValue(); - +#ifdef USE_SDL2 + if (val == Key::TEXTINPUT) + { + std::string str = static_cast<KeyEvent*>(&keyEvent)->getText(); + mText.insert(mCaretPosition, str); + mCaretPosition += str.size(); + keyEvent.consume(); + fixScroll(); + if (mSendAlwaysEvents) + distributeActionEvent(); + return; + } + bool consumed(false); +#else if (val >= 32) { if (mNumeric) @@ -366,6 +379,7 @@ void TextField::keyPressed(gcn::KeyEvent &keyEvent) fixScroll(); return; } +#endif const int action = static_cast<KeyEvent*>(&keyEvent)->getActionId(); switch (action) |