@@ -55,12 +55,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
55
55
#include " irrlicht_changes/static_text.h"
56
56
#include " guiscalingfilter.h"
57
57
#include " guiEditBoxWithScrollbar.h"
58
-
59
- #if USE_FREETYPE && IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR < 9
60
58
#include " intlGUIEditBox.h"
61
- #include " mainmenumanager.h"
62
-
63
- #endif
64
59
65
60
#define MY_CHECKPOS (a,b ) \
66
61
if (v_pos.size() != 2 ) { \
@@ -1007,6 +1002,71 @@ void GUIFormSpecMenu::parsePwdField(parserData* data, const std::string &element
1007
1002
errorstream<< " Invalid pwdfield element(" << parts.size () << " ): '" << element << " '" << std::endl;
1008
1003
}
1009
1004
1005
+ void GUIFormSpecMenu::createTextField (parserData *data, FieldSpec &spec,
1006
+ core::rect<s32> &rect, bool is_multiline)
1007
+ {
1008
+ bool is_editable = !spec.fname .empty ();
1009
+ if (!is_editable && !is_multiline) {
1010
+ // spec field id to 0, this stops submit searching for a value that isn't there
1011
+ gui::StaticText::add (Environment, spec.flabel .c_str (), rect, false , true ,
1012
+ this , spec.fid );
1013
+ return ;
1014
+ }
1015
+
1016
+ if (is_editable) {
1017
+ spec.send = true ;
1018
+ } else if (is_multiline &&
1019
+ spec.fdefault .empty () && !spec.flabel .empty ()) {
1020
+ // Multiline textareas: swap default and label for backwards compat
1021
+ spec.flabel .swap (spec.fdefault );
1022
+ }
1023
+
1024
+ gui::IGUIEditBox *e = nullptr ;
1025
+ static constexpr bool use_intl_edit_box = USE_FREETYPE &&
1026
+ IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR < 9 ;
1027
+
1028
+ if (use_intl_edit_box && g_settings->getBool (" freetype" )) {
1029
+ e = new gui::intlGUIEditBox (spec.fdefault .c_str (),
1030
+ true , Environment, this , spec.fid , rect, is_editable, is_multiline);
1031
+ e->drop ();
1032
+ } else {
1033
+ if (is_multiline)
1034
+ e = new GUIEditBoxWithScrollBar (spec.fdefault .c_str (), true ,
1035
+ Environment, this , spec.fid , rect, is_editable, true );
1036
+ else if (is_editable)
1037
+ e = Environment->addEditBox (spec.fdefault .c_str (), rect, true ,
1038
+ this , spec.fid );
1039
+ }
1040
+
1041
+ if (e) {
1042
+ if (is_editable && spec.fname == data->focused_fieldname )
1043
+ Environment->setFocus (e);
1044
+
1045
+ if (is_multiline) {
1046
+ e->setMultiLine (true );
1047
+ e->setWordWrap (true );
1048
+ e->setTextAlignment (gui::EGUIA_UPPERLEFT, gui::EGUIA_UPPERLEFT);
1049
+ } else {
1050
+ irr::SEvent evt;
1051
+ evt.EventType = EET_KEY_INPUT_EVENT;
1052
+ evt.KeyInput .Key = KEY_END;
1053
+ evt.KeyInput .Char = 0 ;
1054
+ evt.KeyInput .Control = 0 ;
1055
+ evt.KeyInput .Shift = 0 ;
1056
+ evt.KeyInput .PressedDown = true ;
1057
+ e->OnEvent (evt);
1058
+ }
1059
+ }
1060
+
1061
+ if (!spec.flabel .empty ()) {
1062
+ int font_height = g_fontengine->getTextHeight ();
1063
+ rect.UpperLeftCorner .Y -= font_height;
1064
+ rect.LowerRightCorner .Y = rect.UpperLeftCorner .Y + font_height;
1065
+ gui::StaticText::add (Environment, spec.flabel .c_str (), rect, false , true ,
1066
+ this , 0 );
1067
+ }
1068
+ }
1069
+
1010
1070
void GUIFormSpecMenu::parseSimpleField (parserData* data,
1011
1071
std::vector<std::string> &parts)
1012
1072
{
@@ -1040,46 +1100,7 @@ void GUIFormSpecMenu::parseSimpleField(parserData* data,
1040
1100
258 +m_fields.size ()
1041
1101
);
1042
1102
1043
- if (name.empty ()) {
1044
- // spec field id to 0, this stops submit searching for a value that isn't there
1045
- gui::StaticText::add (Environment, spec.flabel .c_str (), rect, false , true , this ,
1046
- spec.fid );
1047
- } else {
1048
- spec.send = true ;
1049
- gui::IGUIElement *e;
1050
- #if USE_FREETYPE && IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR < 9
1051
- if (g_settings->getBool (" freetype" )) {
1052
- e = (gui::IGUIElement *) new gui::intlGUIEditBox (spec.fdefault .c_str (),
1053
- true , Environment, this , spec.fid , rect);
1054
- e->drop ();
1055
- } else {
1056
- #else
1057
- {
1058
- #endif
1059
- e = Environment->addEditBox (spec.fdefault .c_str (), rect, true , this , spec.fid );
1060
- }
1061
- if (spec.fname == data->focused_fieldname ) {
1062
- Environment->setFocus (e);
1063
- }
1064
-
1065
- irr::SEvent evt;
1066
- evt.EventType = EET_KEY_INPUT_EVENT;
1067
- evt.KeyInput .Key = KEY_END;
1068
- evt.KeyInput .Char = 0 ;
1069
- evt.KeyInput .Control = 0 ;
1070
- evt.KeyInput .Shift = 0 ;
1071
- evt.KeyInput .PressedDown = true ;
1072
- e->OnEvent (evt);
1073
-
1074
- if (label.length () >= 1 )
1075
- {
1076
- int font_height = g_fontengine->getTextHeight ();
1077
- rect.UpperLeftCorner .Y -= font_height;
1078
- rect.LowerRightCorner .Y = rect.UpperLeftCorner .Y + font_height;
1079
- gui::StaticText::add (Environment, spec.flabel .c_str (), rect, false , true ,
1080
- this , 0 );
1081
- }
1082
- }
1103
+ createTextField (data, spec, rect, false );
1083
1104
1084
1105
if (parts.size () >= 4 ) {
1085
1106
// TODO: remove after 2016-11-03
@@ -1142,56 +1163,7 @@ void GUIFormSpecMenu::parseTextArea(parserData* data, std::vector<std::string>&
1142
1163
258 +m_fields.size ()
1143
1164
);
1144
1165
1145
- bool is_editable = !name.empty ();
1146
-
1147
- if (is_editable)
1148
- spec.send = true ;
1149
-
1150
- gui::IGUIEditBox *e = nullptr ;
1151
- const wchar_t *text = spec.fdefault .empty () ?
1152
- wlabel.c_str () : spec.fdefault .c_str ();
1153
-
1154
- #if USE_FREETYPE && IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR < 9
1155
- if (g_settings->getBool (" freetype" )) {
1156
- e = (gui::IGUIEditBox *) new gui::intlGUIEditBox (text,
1157
- true , Environment, this , spec.fid , rect, is_editable, true );
1158
- e->drop ();
1159
- } else {
1160
- #else
1161
- {
1162
- #endif
1163
- e = new GUIEditBoxWithScrollBar (text, true ,
1164
- Environment, this , spec.fid , rect, is_editable, true );
1165
- }
1166
-
1167
- if (is_editable && spec.fname == data->focused_fieldname )
1168
- Environment->setFocus (e);
1169
-
1170
- if (e) {
1171
- if (type == " textarea" )
1172
- {
1173
- e->setMultiLine (true );
1174
- e->setWordWrap (true );
1175
- e->setTextAlignment (gui::EGUIA_UPPERLEFT, gui::EGUIA_UPPERLEFT);
1176
- } else {
1177
- irr::SEvent evt;
1178
- evt.EventType = EET_KEY_INPUT_EVENT;
1179
- evt.KeyInput .Key = KEY_END;
1180
- evt.KeyInput .Char = 0 ;
1181
- evt.KeyInput .Control = 0 ;
1182
- evt.KeyInput .Shift = 0 ;
1183
- evt.KeyInput .PressedDown = true ;
1184
- e->OnEvent (evt);
1185
- }
1186
- }
1187
-
1188
- if (is_editable && !label.empty ()) {
1189
- int font_height = g_fontengine->getTextHeight ();
1190
- rect.UpperLeftCorner .Y -= font_height;
1191
- rect.LowerRightCorner .Y = rect.UpperLeftCorner .Y + font_height;
1192
- gui::StaticText::add (Environment, spec.flabel .c_str (), rect, false , true ,
1193
- this , 0 );
1194
- }
1166
+ createTextField (data, spec, rect, type == " textarea" );
1195
1167
1196
1168
if (parts.size () >= 6 ) {
1197
1169
// TODO: remove after 2016-11-03
0 commit comments