From b1cbca03972d93d68b02b3834c5593148cab0dd3 Mon Sep 17 00:00:00 2001 From: SmallJoker Date: Thu, 14 Dec 2017 18:16:23 +0100 Subject: [PATCH 1/4] textarea[], field[]: Unify function, fix wrong fallback text --- src/gui/guiFormSpecMenu.cpp | 158 ++++++++++++++++-------------------- src/gui/guiFormSpecMenu.h | 2 + 2 files changed, 70 insertions(+), 90 deletions(-) diff --git a/src/gui/guiFormSpecMenu.cpp b/src/gui/guiFormSpecMenu.cpp index 89cf19973cc2..73d1e422b21b 100644 --- a/src/gui/guiFormSpecMenu.cpp +++ b/src/gui/guiFormSpecMenu.cpp @@ -1007,6 +1007,72 @@ void GUIFormSpecMenu::parsePwdField(parserData* data, const std::string &element errorstream<< "Invalid pwdfield element(" << parts.size() << "): '" << element << "'" << std::endl; } +void GUIFormSpecMenu::createTextField(parserData *data, FieldSpec &spec, + core::rect &rect, bool is_multiline) +{ + bool is_editable = !spec.fname.empty(); + if (!is_editable && !is_multiline) { + // spec field id to 0, this stops submit searching for a value that isn't there + gui::StaticText::add(Environment, spec.flabel.c_str(), rect, false, true, + this, spec.fid); + return; + } + + if (is_editable) + spec.send = true; + + // Multiline textareas: swap default and label for backwards compat + if (!is_editable && is_multiline && + spec.fdefault.empty() && !spec.flabel.empty()) + spec.flabel.swap(spec.fdefault); + + gui::IGUIEditBox *e = nullptr; +#if USE_FREETYPE && IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR < 9 + if (g_settings->getBool("freetype")) { + e = (gui::IGUIEditBox *) new gui::intlGUIEditBox(spec.fdefault.c_str(), + true, Environment, this, spec.fid, rect, is_editable, true); + e->drop(); + } else { +#else + { +#endif + if (is_multiline) + e = new GUIEditBoxWithScrollBar(spec.fdefault.c_str(), true, + Environment, this, spec.fid, rect, is_editable, true); + else if (is_editable) + e = Environment->addEditBox(spec.fdefault.c_str(), rect, true, + this, spec.fid); + } + + if (e != nullptr) { + if (is_editable && spec.fname == data->focused_fieldname) + Environment->setFocus(e); + + if (is_multiline) { + e->setMultiLine(true); + e->setWordWrap(true); + e->setTextAlignment(gui::EGUIA_UPPERLEFT, gui::EGUIA_UPPERLEFT); + } else { + irr::SEvent evt; + evt.EventType = EET_KEY_INPUT_EVENT; + evt.KeyInput.Key = KEY_END; + evt.KeyInput.Char = 0; + evt.KeyInput.Control = 0; + evt.KeyInput.Shift = 0; + evt.KeyInput.PressedDown = true; + e->OnEvent(evt); + } + } + + if (!spec.flabel.empty()) { + int font_height = g_fontengine->getTextHeight(); + rect.UpperLeftCorner.Y -= font_height; + rect.LowerRightCorner.Y = rect.UpperLeftCorner.Y + font_height; + gui::StaticText::add(Environment, spec.flabel.c_str(), rect, false, true, + this, 0); + } +} + void GUIFormSpecMenu::parseSimpleField(parserData* data, std::vector &parts) { @@ -1040,46 +1106,7 @@ void GUIFormSpecMenu::parseSimpleField(parserData* data, 258+m_fields.size() ); - if (name.empty()) { - // spec field id to 0, this stops submit searching for a value that isn't there - gui::StaticText::add(Environment, spec.flabel.c_str(), rect, false, true, this, - spec.fid); - } else { - spec.send = true; - gui::IGUIElement *e; -#if USE_FREETYPE && IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR < 9 - if (g_settings->getBool("freetype")) { - e = (gui::IGUIElement *) new gui::intlGUIEditBox(spec.fdefault.c_str(), - true, Environment, this, spec.fid, rect); - e->drop(); - } else { -#else - { -#endif - e = Environment->addEditBox(spec.fdefault.c_str(), rect, true, this, spec.fid); - } - if (spec.fname == data->focused_fieldname) { - Environment->setFocus(e); - } - - irr::SEvent evt; - evt.EventType = EET_KEY_INPUT_EVENT; - evt.KeyInput.Key = KEY_END; - evt.KeyInput.Char = 0; - evt.KeyInput.Control = 0; - evt.KeyInput.Shift = 0; - evt.KeyInput.PressedDown = true; - e->OnEvent(evt); - - if (label.length() >= 1) - { - int font_height = g_fontengine->getTextHeight(); - rect.UpperLeftCorner.Y -= font_height; - rect.LowerRightCorner.Y = rect.UpperLeftCorner.Y + font_height; - gui::StaticText::add(Environment, spec.flabel.c_str(), rect, false, true, - this, 0); - } - } + createTextField(data, spec, rect, false); if (parts.size() >= 4) { // TODO: remove after 2016-11-03 @@ -1142,56 +1169,7 @@ void GUIFormSpecMenu::parseTextArea(parserData* data, std::vector& 258+m_fields.size() ); - bool is_editable = !name.empty(); - - if (is_editable) - spec.send = true; - - gui::IGUIEditBox *e = nullptr; - const wchar_t *text = spec.fdefault.empty() ? - wlabel.c_str() : spec.fdefault.c_str(); - -#if USE_FREETYPE && IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR < 9 - if (g_settings->getBool("freetype")) { - e = (gui::IGUIEditBox *) new gui::intlGUIEditBox(text, - true, Environment, this, spec.fid, rect, is_editable, true); - e->drop(); - } else { -#else - { -#endif - e = new GUIEditBoxWithScrollBar(text, true, - Environment, this, spec.fid, rect, is_editable, true); - } - - if (is_editable && spec.fname == data->focused_fieldname) - Environment->setFocus(e); - - if (e) { - if (type == "textarea") - { - e->setMultiLine(true); - e->setWordWrap(true); - e->setTextAlignment(gui::EGUIA_UPPERLEFT, gui::EGUIA_UPPERLEFT); - } else { - irr::SEvent evt; - evt.EventType = EET_KEY_INPUT_EVENT; - evt.KeyInput.Key = KEY_END; - evt.KeyInput.Char = 0; - evt.KeyInput.Control = 0; - evt.KeyInput.Shift = 0; - evt.KeyInput.PressedDown = true; - e->OnEvent(evt); - } - } - - if (is_editable && !label.empty()) { - int font_height = g_fontengine->getTextHeight(); - rect.UpperLeftCorner.Y -= font_height; - rect.LowerRightCorner.Y = rect.UpperLeftCorner.Y + font_height; - gui::StaticText::add(Environment, spec.flabel.c_str(), rect, false, true, - this, 0); - } + createTextField(data, spec, rect, type == "textarea"); if (parts.size() >= 6) { // TODO: remove after 2016-11-03 diff --git a/src/gui/guiFormSpecMenu.h b/src/gui/guiFormSpecMenu.h index 8b16f24cf525..736dd8ddb304 100644 --- a/src/gui/guiFormSpecMenu.h +++ b/src/gui/guiFormSpecMenu.h @@ -484,6 +484,8 @@ class GUIFormSpecMenu : public GUIModalMenu void parseFieldCloseOnEnter(parserData *data, const std::string &element); void parsePwdField(parserData* data, const std::string &element); void parseField(parserData* data, const std::string &element, const std::string &type); + void createTextField(parserData *data, FieldSpec &spec, + core::rect &rect, bool is_multiline); void parseSimpleField(parserData* data,std::vector &parts); void parseTextArea(parserData* data,std::vector& parts, const std::string &type); From fb401a5461eb9a58a7fb019c507d10596a5002c9 Mon Sep 17 00:00:00 2001 From: SmallJoker Date: Sun, 21 Jan 2018 10:55:48 +0100 Subject: [PATCH 2/4] Remove apparently superflous mainmenumanager.h incldue --- src/gui/guiFormSpecMenu.cpp | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/gui/guiFormSpecMenu.cpp b/src/gui/guiFormSpecMenu.cpp index 73d1e422b21b..0506ec25ca0a 100644 --- a/src/gui/guiFormSpecMenu.cpp +++ b/src/gui/guiFormSpecMenu.cpp @@ -55,12 +55,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "irrlicht_changes/static_text.h" #include "guiscalingfilter.h" #include "guiEditBoxWithScrollbar.h" - -#if USE_FREETYPE && IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR < 9 #include "intlGUIEditBox.h" -#include "mainmenumanager.h" - -#endif #define MY_CHECKPOS(a,b) \ if (v_pos.size() != 2) { \ @@ -1027,15 +1022,14 @@ void GUIFormSpecMenu::createTextField(parserData *data, FieldSpec &spec, spec.flabel.swap(spec.fdefault); gui::IGUIEditBox *e = nullptr; -#if USE_FREETYPE && IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR < 9 - if (g_settings->getBool("freetype")) { - e = (gui::IGUIEditBox *) new gui::intlGUIEditBox(spec.fdefault.c_str(), - true, Environment, this, spec.fid, rect, is_editable, true); + static constexpr bool use_intl_edit_box = USE_FREETYPE && + IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR < 9; + + if (use_intl_edit_box && g_settings->getBool("freetype")) { + e = new gui::intlGUIEditBox(spec.fdefault.c_str(), + true, Environment, this, spec.fid, rect, is_editable, is_multiline); e->drop(); } else { -#else - { -#endif if (is_multiline) e = new GUIEditBoxWithScrollBar(spec.fdefault.c_str(), true, Environment, this, spec.fid, rect, is_editable, true); @@ -1044,7 +1038,7 @@ void GUIFormSpecMenu::createTextField(parserData *data, FieldSpec &spec, this, spec.fid); } - if (e != nullptr) { + if (e) { if (is_editable && spec.fname == data->focused_fieldname) Environment->setFocus(e); From 8ed3f1329860ef7c025b300c4b475f5fb424299b Mon Sep 17 00:00:00 2001 From: SmallJoker Date: Sun, 21 Jan 2018 17:32:04 +0100 Subject: [PATCH 3/4] intlGUIEditBox.cpp: make read-only boxes really read-only --- src/gui/intlGUIEditBox.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/gui/intlGUIEditBox.cpp b/src/gui/intlGUIEditBox.cpp index 8b0f10721551..8c661b9f3746 100644 --- a/src/gui/intlGUIEditBox.cpp +++ b/src/gui/intlGUIEditBox.cpp @@ -354,8 +354,7 @@ bool intlGUIEditBox::processKey(const SEvent& event) break; case KEY_KEY_X: // cut to the clipboard - if (!PasswordBox && Operator && MarkBegin != MarkEnd) - { + if (!PasswordBox && Operator && MarkBegin != MarkEnd) { const s32 realmbgn = MarkBegin < MarkEnd ? MarkBegin : MarkEnd; const s32 realmend = MarkBegin < MarkEnd ? MarkEnd : MarkBegin; @@ -364,8 +363,7 @@ bool intlGUIEditBox::processKey(const SEvent& event) sc = Text.subString(realmbgn, realmend - realmbgn).c_str(); Operator->copyToClipboard(sc.c_str()); - if (IsEnabled) - { + if (IsEnabled && m_writable) { // delete core::stringw s; s = Text.subString(0, realmbgn); @@ -380,7 +378,7 @@ bool intlGUIEditBox::processKey(const SEvent& event) } break; case KEY_KEY_V: - if ( !IsEnabled ) + if (!IsEnabled || !m_writable) break; // paste from the clipboard @@ -636,7 +634,7 @@ bool intlGUIEditBox::processKey(const SEvent& event) break; case KEY_BACK: - if ( !this->IsEnabled ) + if (!this->IsEnabled || !m_writable) break; if (!Text.empty()) { @@ -675,7 +673,7 @@ bool intlGUIEditBox::processKey(const SEvent& event) } break; case KEY_DELETE: - if ( !this->IsEnabled ) + if (!this->IsEnabled || !m_writable) break; if (!Text.empty()) { @@ -1351,7 +1349,7 @@ s32 intlGUIEditBox::getLineFromPos(s32 pos) void intlGUIEditBox::inputChar(wchar_t c) { - if (!IsEnabled) + if (!IsEnabled || !m_writable) return; if (c != 0) From 9785cc5fa836a1ddba01c626c34b66ceb83114a8 Mon Sep 17 00:00:00 2001 From: SmallJoker Date: Mon, 22 Jan 2018 19:11:38 +0100 Subject: [PATCH 4/4] Use elseif (trivial) --- src/gui/guiFormSpecMenu.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/gui/guiFormSpecMenu.cpp b/src/gui/guiFormSpecMenu.cpp index 0506ec25ca0a..dfb167ce7f51 100644 --- a/src/gui/guiFormSpecMenu.cpp +++ b/src/gui/guiFormSpecMenu.cpp @@ -1013,13 +1013,13 @@ void GUIFormSpecMenu::createTextField(parserData *data, FieldSpec &spec, return; } - if (is_editable) + if (is_editable) { spec.send = true; - - // Multiline textareas: swap default and label for backwards compat - if (!is_editable && is_multiline && - spec.fdefault.empty() && !spec.flabel.empty()) + } else if (is_multiline && + spec.fdefault.empty() && !spec.flabel.empty()) { + // Multiline textareas: swap default and label for backwards compat spec.flabel.swap(spec.fdefault); + } gui::IGUIEditBox *e = nullptr; static constexpr bool use_intl_edit_box = USE_FREETYPE &&