summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/gui.cpp5
-rw-r--r--src/gui/sdlinput.cpp9
-rw-r--r--src/gui/sdlinput.h3
-rw-r--r--src/gui/widgets/textfield.cpp16
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)