summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2013-08-23 19:12:36 +0300
committerAndrei Karas <akaras@inbox.ru>2013-08-24 21:08:16 +0300
commit270d6d2753473955a2b691a934eb2e550d13ebc3 (patch)
tree2ba55bab0c21b1775bfcd85e80d24cbfbbe652e9 /src
parentc7f5d0a71d7318ccc4c3f28ab90d688a1a0868b3 (diff)
downloadmv-270d6d2753473955a2b691a934eb2e550d13ebc3.tar.gz
mv-270d6d2753473955a2b691a934eb2e550d13ebc3.tar.bz2
mv-270d6d2753473955a2b691a934eb2e550d13ebc3.tar.xz
mv-270d6d2753473955a2b691a934eb2e550d13ebc3.zip
fix gui text input in SDL2.
copy/paste broken for SDL2.
Diffstat (limited to 'src')
-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