summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/client.cpp3
-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
-rw-r--r--src/keyevent.cpp5
-rw-r--r--src/keyevent.h11
-rw-r--r--src/keyinput.cpp5
-rw-r--r--src/keyinput.h11
9 files changed, 66 insertions, 2 deletions
diff --git a/src/client.cpp b/src/client.cpp
index ea1da8247..9fa220b8c 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -3001,6 +3001,9 @@ void Client::logEvent(const SDL_Event &event)
str.c_str(), data1, data2);
break;
}
+ case SDL_TEXTINPUT:
+ logger->log("event: SDL_TEXTINPUT: %s", event.text.text);
+ break;
#else
case SDL_KEYDOWN:
logger->log("event: SDL_KEYDOWN: %d,%d,%d", event.key.state,
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)
diff --git a/src/keyevent.cpp b/src/keyevent.cpp
index 1cbd32402..fef854fbf 100644
--- a/src/keyevent.cpp
+++ b/src/keyevent.cpp
@@ -33,7 +33,12 @@ KeyEvent::KeyEvent(gcn::Widget *const source,
const gcn::Key& key) :
gcn::KeyEvent(source, shiftPressed, controlPressed, altPressed,
metaPressed, type, numericPad, key),
+#ifdef USE_SDL2
+ mActionId(actionId),
+ mText()
+#else
mActionId(actionId)
+#endif
{
}
diff --git a/src/keyevent.h b/src/keyevent.h
index 455717f85..081ea3d3c 100644
--- a/src/keyevent.h
+++ b/src/keyevent.h
@@ -49,8 +49,19 @@ class KeyEvent final : public gcn::KeyEvent
int getActionId() const A_WARN_UNUSED
{ return mActionId; }
+#ifdef USE_SDL2
+ void setText(const std::string &text)
+ { mText = text; }
+
+ std::string getText() const
+ { return mText; }
+#endif
+
protected:
int mActionId;
+#ifdef USE_SDL2
+ std::string mText;
+#endif
};
#endif // KEYEVENT_H
diff --git a/src/keyinput.cpp b/src/keyinput.cpp
index 3a40eac7e..bbc53bff2 100644
--- a/src/keyinput.cpp
+++ b/src/keyinput.cpp
@@ -24,7 +24,12 @@
KeyInput::KeyInput() :
gcn::KeyInput(),
+#ifdef USE_SDL2
+ mActionId(-2),
+ mText()
+#else
mActionId(-2)
+#endif
{
}
diff --git a/src/keyinput.h b/src/keyinput.h
index 70aab4049..7e5de4bb3 100644
--- a/src/keyinput.h
+++ b/src/keyinput.h
@@ -40,8 +40,19 @@ class KeyInput final : public gcn::KeyInput
int getActionId() const A_WARN_UNUSED
{ return mActionId; }
+#ifdef USE_SDL2
+ void setText(const std::string &text)
+ { mText = text; }
+
+ std::string getText() const
+ { return mText; }
+#endif
+
protected:
int mActionId;
+#ifdef USE_SDL2
+ std::string mText;
+#endif
};
#endif // KEYINPUT_H