From 46d431e7c3cb1345c34613647a6eb61aabeb087a Mon Sep 17 00:00:00 2001 From: Jeija Date: Fri, 28 Dec 2012 09:52:21 +0100 Subject: Implement textarea in formspec, a multiline input field --- src/guiFormSpecMenu.cpp | 80 +++++++++++++++++++++++++++++-------------------- 1 file changed, 47 insertions(+), 33 deletions(-) (limited to 'src') diff --git a/src/guiFormSpecMenu.cpp b/src/guiFormSpecMenu.cpp index ea537deb2..e1ccee91a 100644 --- a/src/guiFormSpecMenu.cpp +++ b/src/guiFormSpecMenu.cpp @@ -318,13 +318,16 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize) errorstream<<"WARNING: invalid use of background without a size[] element"<( @@ -339,7 +342,7 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize) bp_set = 1; } else if(bp_set == 2) - errorstream<<"WARNING: invalid use of unpositioned field in inventory"<(pos.X, pos.Y, pos.X+geom.X, pos.Y+geom.Y); + - rect = core::rect(pos.X, pos.Y-15, pos.X+geom.X, pos.Y+15); fname = f.next(";"); flabel = f.next(";"); if(bp_set != 2) - errorstream<<"WARNING: invalid use of positioned field without a size[] element"<addEditBox(spec.fdefault.c_str(), rect, true, this, spec.fid); - Environment->setFocus(e); - irr::SEvent evt; - evt.EventType = EET_KEY_INPUT_EVENT; - evt.KeyInput.Key = KEY_END; - evt.KeyInput.PressedDown = true; - e->OnEvent(evt); - } - else if (fname == "") + // three cases: field name and no label, label and field, label name and no field + gui::IGUIEditBox *e; + if (fname == "") { - // set spec field id to 0, this stops submit searching for a value that isn't there + // spec field id to 0, this stops submit searching for a value that isn't there Environment->addStaticText(spec.flabel.c_str(), rect, false, true, this, spec.fid); } else { spec.send = true; - gui::IGUIElement *e = Environment->addEditBox(spec.fdefault.c_str(), rect, true, this, spec.fid); + e = Environment->addEditBox(spec.fdefault.c_str(), rect, true, this, spec.fid); Environment->setFocus(e); - rect.UpperLeftCorner.Y -= 15; - rect.LowerRightCorner.Y -= 15; - Environment->addStaticText(spec.flabel.c_str(), rect, false, true, this, 0); - - irr::SEvent evt; - evt.EventType = EET_KEY_INPUT_EVENT; - evt.KeyInput.Key = KEY_END; - evt.KeyInput.PressedDown = true; - e->OnEvent(evt); + + if (type == "textarea") + { + e->setMultiLine(true); + e->setTextAlignment(gui::EGUIA_UPPERLEFT, gui::EGUIA_UPPERLEFT); + } else { + irr::SEvent evt; + evt.KeyInput.Key = KEY_END; + evt.EventType = EET_KEY_INPUT_EVENT; + evt.KeyInput.PressedDown = true; + e->OnEvent(evt); + } + + if (flabel != "") + { + rect.UpperLeftCorner.Y -= 15; + rect.LowerRightCorner.Y = rect.UpperLeftCorner.Y + 15; + Environment->addStaticText(spec.flabel.c_str(), rect, false, true, this, 0); + } } - + m_fields.push_back(spec); } else if(type == "label") -- cgit v1.2.3