diff options
author | Andrei Karas <akaras@inbox.ru> | 2013-05-11 22:25:21 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2013-05-11 22:25:21 +0300 |
commit | 120ef46ea296729baee0c88c046008d8e18644fa (patch) | |
tree | 36ac86de113f11e60c31008ea15d286bb30d831d /src | |
parent | c4d16b36a373ba5609360e2698372926d7f2dc0f (diff) | |
download | manaplus-120ef46ea296729baee0c88c046008d8e18644fa.tar.gz manaplus-120ef46ea296729baee0c88c046008d8e18644fa.tar.bz2 manaplus-120ef46ea296729baee0c88c046008d8e18644fa.tar.xz manaplus-120ef46ea296729baee0c88c046008d8e18644fa.zip |
Add ability to show onscreen keyboard if input field focused.
Diffstat (limited to 'src')
-rw-r--r-- | src/client.cpp | 5 | ||||
-rw-r--r-- | src/client.h | 4 | ||||
-rw-r--r-- | src/gui/chatwindow.cpp | 6 | ||||
-rw-r--r-- | src/gui/widgets/popuplist.h | 2 | ||||
-rw-r--r-- | src/gui/widgets/textfield.cpp | 20 | ||||
-rw-r--r-- | src/gui/widgets/textfield.h | 6 |
6 files changed, 37 insertions, 6 deletions
diff --git a/src/client.cpp b/src/client.cpp index f02759c01..8dd2e663a 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -298,7 +298,8 @@ Client::Client(const Options &options) : mFpsManager(), mSkin(nullptr), mButtonPadding(1), - mButtonSpacing(3) + mButtonSpacing(3), + mKeyboardHeight(0) { mInstance = this; @@ -2931,7 +2932,7 @@ void Client::windowRemoved(const Window *const window) void Client::updateScreenKeyboard(int height A_UNUSED) { -// logger->log("keyboard height: %d", height); + instance()->mKeyboardHeight = height; } void Client::checkConfigVersion() diff --git a/src/client.h b/src/client.h index 733bc21e8..c321cd385 100644 --- a/src/client.h +++ b/src/client.h @@ -291,6 +291,9 @@ public: const bool always = false) { instance()->resizeVideo(width, height, always); } + static bool isKeyboardVisible() + { return instance()->mKeyboardHeight > 1; } + static void setGuiAlpha(const float n); static float getGuiAlpha() A_WARN_UNUSED; @@ -422,6 +425,7 @@ private: Skin *mSkin; int mButtonPadding; int mButtonSpacing; + int mKeyboardHeight; }; #endif // CLIENT_H diff --git a/src/gui/chatwindow.cpp b/src/gui/chatwindow.cpp index 19555e90d..0e043ea71 100644 --- a/src/gui/chatwindow.cpp +++ b/src/gui/chatwindow.cpp @@ -73,12 +73,11 @@ /** * The chat input hides when it loses focus. It is also invisible by default. */ -class ChatInput final : public TextField, public gcn::FocusListener +class ChatInput final : public TextField { public: ChatInput(ChatWindow *const window, TabbedArea *const tabs): TextField(window, "", false), - gcn::FocusListener(), mWindow(window), mChatTabs(tabs), mFocusGaining(false) @@ -93,8 +92,9 @@ class ChatInput final : public TextField, public gcn::FocusListener * Called if the chat input loses focus. It will set itself to * invisible as result. */ - void focusLost(const gcn::Event &event A_UNUSED) + void focusLost(const gcn::Event &event) { + TextField::focusLost(event); if (mFocusGaining || !config.getBoolValue("protectChatFocus")) { processVisible(false); diff --git a/src/gui/widgets/popuplist.h b/src/gui/widgets/popuplist.h index 5e0f4f260..59e04df63 100644 --- a/src/gui/widgets/popuplist.h +++ b/src/gui/widgets/popuplist.h @@ -25,7 +25,7 @@ #include "gui/widgets/popup.h" #include <guichan/actionlistener.hpp> -#include "guichan/focuslistener.hpp" +#include <guichan/focuslistener.hpp> #include <guichan/listmodel.hpp> #include "localconsts.h" diff --git a/src/gui/widgets/textfield.cpp b/src/gui/widgets/textfield.cpp index 73e01fb63..5d0621e1e 100644 --- a/src/gui/widgets/textfield.cpp +++ b/src/gui/widgets/textfield.cpp @@ -24,6 +24,7 @@ #include "client.h" #include "configuration.h" +#include "inputmanager.h" #include "keyevent.h" #include "gui/popupmenu.h" @@ -51,6 +52,7 @@ TextField::TextField(const Widget2 *const widget, gcn::ActionListener *const listener, std::string eventId, const bool sendAlwaysEvents): gcn::TextField(text), + gcn::FocusListener(), Widget2(widget), mSendAlwaysEvents(sendAlwaysEvents), mNumeric(false), @@ -66,6 +68,8 @@ TextField::TextField(const Widget2 *const widget, setFrameSize(2); mForegroundColor = getThemeColor(Theme::TEXTFIELD); + addFocusListener(this); + if (instances == 0) { if (Theme::instance()) @@ -529,6 +533,10 @@ void TextField::fontChanged() void TextField::mousePressed(gcn::MouseEvent &mouseEvent) { +#ifdef ANDROID + if (!Client::isKeyboardVisible()) + inputManager.executeAction(Input::KEY_SHOW_KEYBOARD); +#endif if (mouseEvent.getButton() == gcn::MouseEvent::RIGHT) { if (viewport) @@ -550,3 +558,15 @@ void TextField::mousePressed(gcn::MouseEvent &mouseEvent) gcn::TextField::mousePressed(mouseEvent); } } + +void TextField::focusGained(const gcn::Event &event A_UNUSED) +{ +#ifdef ANDROID + if (!Client::isKeyboardVisible()) + inputManager.executeAction(Input::KEY_SHOW_KEYBOARD); +#endif +} + +void TextField::focusLost(const gcn::Event &event A_UNUSED) +{ +} diff --git a/src/gui/widgets/textfield.h b/src/gui/widgets/textfield.h index 0c30fc819..0569d5d30 100644 --- a/src/gui/widgets/textfield.h +++ b/src/gui/widgets/textfield.h @@ -25,6 +25,7 @@ #include "gui/widgets/widget2.h" +#include <guichan/focuslistener.hpp> #include <guichan/widgets/textfield.hpp> #include "localconsts.h" @@ -39,6 +40,7 @@ class TextField; * \ingroup GUI */ class TextField : public gcn::TextField, + public gcn::FocusListener, public Widget2 { public: @@ -122,6 +124,10 @@ class TextField : public gcn::TextField, void handleCopy() const; + void focusGained(const gcn::Event &event); + + void focusLost(const gcn::Event &event); + protected: void drawCaret(gcn::Graphics* graphics, int x) override; |