From eb8b68dcb6d1caff5c18ebf09c97a564312f3971 Mon Sep 17 00:00:00 2001 From: Benau Date: Fri, 16 Nov 2018 19:46:48 +0800 Subject: [PATCH] Allow text box widget to process left / right events --- src/guiengine/widgets/CGUIEditBox.hpp | 3 ++- src/guiengine/widgets/text_box_widget.cpp | 19 +++++++++++++++++++ src/guiengine/widgets/text_box_widget.hpp | 3 +++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/guiengine/widgets/CGUIEditBox.hpp b/src/guiengine/widgets/CGUIEditBox.hpp index 0db5f3731..cf3a0dd56 100644 --- a/src/guiengine/widgets/CGUIEditBox.hpp +++ b/src/guiengine/widgets/CGUIEditBox.hpp @@ -120,7 +120,8 @@ using namespace gui; virtual void setDrawBackground(bool) { } void openScreenKeyboard(); - + s32 getCursorPosInBox() const { return CursorPos; } + s32 getTextCount() const { return (s32)Text.size(); } protected: //! Breaks the single text line. void breakText(); diff --git a/src/guiengine/widgets/text_box_widget.cpp b/src/guiengine/widgets/text_box_widget.cpp index 57d3d7185..e6d7712a9 100644 --- a/src/guiengine/widgets/text_box_widget.cpp +++ b/src/guiengine/widgets/text_box_widget.cpp @@ -209,3 +209,22 @@ EventPropagation TextBoxWidget::onActivationInput(const int playerID) // event to avoid breaking something return EVENT_BLOCK; } + +// ----------------------------------------------------------------------------- +EventPropagation TextBoxWidget::rightPressed(const int playerID) +{ + if (((MyCGUIEditBox*)m_element)->getTextCount() == + ((MyCGUIEditBox*)m_element)->getCursorPosInBox()) + return EVENT_BLOCK; + + return EVENT_LET; +} // rightPressed + +// ----------------------------------------------------------------------------- +EventPropagation TextBoxWidget::leftPressed (const int playerID) +{ + if (((MyCGUIEditBox*)m_element)->getCursorPosInBox() == 0) + return EVENT_BLOCK; + + return EVENT_LET; +} // leftPressed diff --git a/src/guiengine/widgets/text_box_widget.hpp b/src/guiengine/widgets/text_box_widget.hpp index 54d462387..db53359b7 100644 --- a/src/guiengine/widgets/text_box_widget.hpp +++ b/src/guiengine/widgets/text_box_widget.hpp @@ -77,6 +77,9 @@ namespace GUIEngine virtual void setActive(bool active=true); virtual EventPropagation onActivationInput(const int playerID); + virtual EventPropagation rightPressed(const int playerID); + virtual EventPropagation leftPressed (const int playerID); + }; }