+
+ bool is_horizontal = true;
+
+ if (parts[2] == "vertical")
+ is_horizontal = false;
+
+ spec.ftype = f_ScrollBar;
+ spec.send = true;
+ gui::IGUIScrollBar* e =
+ Environment->addScrollBar(is_horizontal,rect,this,spec.fid);
+
+ e->setMax(1000);
+ e->setMin(0);
+ e->setPos(stoi(parts[4]));
+ e->setSmallStep(10);
+ e->setLargeStep(100);
+
+ m_scrollbars.push_back(std::pair<FieldSpec,gui::IGUIScrollBar*>(spec,e));
+ m_fields.push_back(spec);
+ return;
+ }
+ errorstream<< "Invalid scrollbar element(" << parts.size() << "): '" << element << "'" << std::endl;
+}
+
+void GUIFormSpecMenu::parseImage(parserData* data,std::string element)
+{
+ std::vector<std::string> parts = split(element,';');
+
+ if ((parts.size() == 3) ||
+ ((parts.size() > 3) && (m_formspec_version > FORMSPEC_API_VERSION)))
+ {
+ std::vector<std::string> v_pos = split(parts[0],',');
+ std::vector<std::string> v_geom = split(parts[1],',');
+ std::string name = unescape_string(parts[2]);
+
+ MY_CHECKPOS("image",0);
+ MY_CHECKGEOM("image",1);
+
+ v2s32 pos = padding + AbsoluteRect.UpperLeftCorner;
+ pos.X += stof(v_pos[0]) * (float) spacing.X;
+ pos.Y += stof(v_pos[1]) * (float) spacing.Y;
+
+ v2s32 geom;
+ geom.X = stof(v_geom[0]) * (float)imgsize.X;
+ geom.Y = stof(v_geom[1]) * (float)imgsize.Y;
+
+ if(!data->explicit_size)
+ warningstream<<"invalid use of image without a size[] element"<<std::endl;
+ m_images.push_back(ImageDrawSpec(name, pos, geom));
+ return;
+ }
+
+ if (parts.size() == 2) {
+ std::vector<std::string> v_pos = split(parts[0],',');
+ std::string name = unescape_string(parts[1]);
+
+ MY_CHECKPOS("image",0);
+
+ v2s32 pos = padding + AbsoluteRect.UpperLeftCorner;
+ pos.X += stof(v_pos[0]) * (float) spacing.X;
+ pos.Y += stof(v_pos[1]) * (float) spacing.Y;
+
+ if(!data->explicit_size)
+ warningstream<<"invalid use of image without a size[] element"<<std::endl;
+ m_images.push_back(ImageDrawSpec(name, pos));
+ return;
+ }
+ errorstream<< "Invalid image element(" << parts.size() << "): '" << element << "'" << std::endl;
+}
+
+void GUIFormSpecMenu::parseItemImage(parserData* data,std::string element)
+{
+ std::vector<std::string> parts = split(element,';');
+
+ if ((parts.size() == 3) ||
+ ((parts.size() > 3) && (m_formspec_version > FORMSPEC_API_VERSION)))
+ {
+ std::vector<std::string> v_pos = split(parts[0],',');
+ std::vector<std::string> v_geom = split(parts[1],',');
+ std::string name = parts[2];
+
+ MY_CHECKPOS("itemimage",0);
+ MY_CHECKGEOM("itemimage",1);
+
+ v2s32 pos = padding + AbsoluteRect.UpperLeftCorner;
+ pos.X += stof(v_pos[0]) * (float) spacing.X;
+ pos.Y += stof(v_pos[1]) * (float) spacing.Y;
+
+ v2s32 geom;
+ geom.X = stof(v_geom[0]) * (float)imgsize.X;
+ geom.Y = stof(v_geom[1]) * (float)imgsize.Y;
+
+ if(!data->explicit_size)
+ warningstream<<"invalid use of item_image without a size[] element"<<std::endl;
+ m_itemimages.push_back(ImageDrawSpec("", name, pos, geom));
+ return;
+ }
+ errorstream<< "Invalid ItemImage element(" << parts.size() << "): '" << element << "'" << std::endl;
+}
+
+void GUIFormSpecMenu::parseButton(parserData* data,std::string element,
+ std::string type)
+{
+ std::vector<std::string> parts = split(element,';');
+
+ if ((parts.size() == 4) ||
+ ((parts.size() > 4) && (m_formspec_version > FORMSPEC_API_VERSION)))
+ {
+ std::vector<std::string> v_pos = split(parts[0],',');
+ std::vector<std::string> v_geom = split(parts[1],',');
+ std::string name = parts[2];
+ std::string label = parts[3];
+
+ MY_CHECKPOS("button",0);
+ MY_CHECKGEOM("button",1);
+
+ v2s32 pos = padding;
+ pos.X += stof(v_pos[0]) * (float)spacing.X;
+ pos.Y += stof(v_pos[1]) * (float)spacing.Y;
+
+ v2s32 geom;
+ geom.X = (stof(v_geom[0]) * (float)spacing.X)-(spacing.X-imgsize.X);
+ pos.Y += (stof(v_geom[1]) * (float)imgsize.Y)/2;
+
+ core::rect<s32> rect =
+ core::rect<s32>(pos.X, pos.Y - m_btn_height,
+ pos.X + geom.X, pos.Y + m_btn_height);
+
+ if(!data->explicit_size)
+ warningstream<<"invalid use of button without a size[] element"<<std::endl;
+
+ std::wstring wlabel = utf8_to_wide(unescape_string(label));
+
+ FieldSpec spec(
+ name,
+ wlabel,
+ L"",
+ 258+m_fields.size()
+ );
+ spec.ftype = f_Button;
+ if(type == "button_exit")
+ spec.is_exit = true;
+ gui::IGUIButton* e = Environment->addButton(rect, this, spec.fid,
+ spec.flabel.c_str());
+
+ if (spec.fname == data->focused_fieldname) {
+ Environment->setFocus(e);
+ }
+
+ m_fields.push_back(spec);
+ return;
+ }
+ errorstream<< "Invalid button element(" << parts.size() << "): '" << element << "'" << std::endl;
+}
+
+void GUIFormSpecMenu::parseBackground(parserData* data,std::string element)
+{
+ std::vector<std::string> parts = split(element,';');
+
+ if (((parts.size() == 3) || (parts.size() == 4)) ||
+ ((parts.size() > 4) && (m_formspec_version > FORMSPEC_API_VERSION)))
+ {
+ std::vector<std::string> v_pos = split(parts[0],',');
+ std::vector<std::string> v_geom = split(parts[1],',');
+ std::string name = unescape_string(parts[2]);
+
+ MY_CHECKPOS("background",0);
+ MY_CHECKGEOM("background",1);
+
+ v2s32 pos = padding + AbsoluteRect.UpperLeftCorner;
+ pos.X += stof(v_pos[0]) * (float)spacing.X - ((float)spacing.X-(float)imgsize.X)/2;
+ pos.Y += stof(v_pos[1]) * (float)spacing.Y - ((float)spacing.Y-(float)imgsize.Y)/2;
+
+ v2s32 geom;
+ geom.X = stof(v_geom[0]) * (float)spacing.X;
+ geom.Y = stof(v_geom[1]) * (float)spacing.Y;
+
+ if (!data->explicit_size)
+ warningstream<<"invalid use of background without a size[] element"<<std::endl;
+
+ bool clip = false;
+ if (parts.size() == 4 && is_yes(parts[3])) {
+ pos.X = stoi(v_pos[0]); //acts as offset
+ pos.Y = stoi(v_pos[1]); //acts as offset
+ clip = true;
+ }
+ m_backgrounds.push_back(ImageDrawSpec(name, pos, geom, clip));
+
+ return;
+ }
+ errorstream<< "Invalid background element(" << parts.size() << "): '" << element << "'" << std::endl;
+}
+
+void GUIFormSpecMenu::parseTableOptions(parserData* data,std::string element)
+{
+ std::vector<std::string> parts = split(element,';');
+
+ data->table_options.clear();
+ for (size_t i = 0; i < parts.size(); ++i) {
+ // Parse table option
+ std::string opt = unescape_string(parts[i]);
+ data->table_options.push_back(GUITable::splitOption(opt));
+ }
+}
+
+void GUIFormSpecMenu::parseTableColumns(parserData* data,std::string element)
+{
+ std::vector<std::string> parts = split(element,';');
+
+ data->table_columns.clear();
+ for (size_t i = 0; i < parts.size(); ++i) {
+ std::vector<std::string> col_parts = split(parts[i],',');
+ GUITable::TableColumn column;
+ // Parse column type
+ if (!col_parts.empty())
+ column.type = col_parts[0];
+ // Parse column options
+ for (size_t j = 1; j < col_parts.size(); ++j) {
+ std::string opt = unescape_string(col_parts[j]);
+ column.options.push_back(GUITable::splitOption(opt));
+ }
+ data->table_columns.push_back(column);
+ }
+}
+
+void GUIFormSpecMenu::parseTable(parserData* data,std::string element)
+{
+ std::vector<std::string> parts = split(element,';');
+
+ if (((parts.size() == 4) || (parts.size() == 5)) ||
+ ((parts.size() > 5) && (m_formspec_version > FORMSPEC_API_VERSION)))
+ {
+ std::vector<std::string> v_pos = split(parts[0],',');
+ std::vector<std::string> v_geom = split(parts[1],',');
+ std::string name = parts[2];
+ std::vector<std::string> items = split(parts[3],',');
+ std::string str_initial_selection = "";
+ std::string str_transparent = "false";
+
+ if (parts.size() >= 5)
+ str_initial_selection = parts[4];
+
+ MY_CHECKPOS("table",0);
+ MY_CHECKGEOM("table",1);
+
+ v2s32 pos = padding;
+ pos.X += stof(v_pos[0]) * (float)spacing.X;
+ pos.Y += stof(v_pos[1]) * (float)spacing.Y;
+
+ v2s32 geom;
+ geom.X = stof(v_geom[0]) * (float)spacing.X;
+ geom.Y = stof(v_geom[1]) * (float)spacing.Y;
+
+ core::rect<s32> rect = core::rect<s32>(pos.X, pos.Y, pos.X+geom.X, pos.Y+geom.Y);
+
+ FieldSpec spec(
+ name,
+ L"",
+ L"",
+ 258+m_fields.size()
+ );
+
+ spec.ftype = f_Table;
+
+ for (unsigned int i = 0; i < items.size(); ++i) {
+ items[i] = unescape_enriched(unescape_string(items[i]));
+ }
+
+ //now really show table
+ GUITable *e = new GUITable(Environment, this, spec.fid, rect,
+ m_tsrc);
+
+ if (spec.fname == data->focused_fieldname) {
+ Environment->setFocus(e);
+ }
+
+ e->setTable(data->table_options, data->table_columns, items);
+
+ if (data->table_dyndata.find(name) != data->table_dyndata.end()) {
+ e->setDynamicData(data->table_dyndata[name]);
+ }
+
+ if ((str_initial_selection != "") &&
+ (str_initial_selection != "0"))
+ e->setSelected(stoi(str_initial_selection.c_str()));
+
+ m_tables.push_back(std::pair<FieldSpec,GUITable*>(spec, e));
+ m_fields.push_back(spec);
+ return;
+ }
+ errorstream<< "Invalid table element(" << parts.size() << "): '" << element << "'" << std::endl;
+}
+
+void GUIFormSpecMenu::parseTextList(parserData* data,std::string element)
+{
+ std::vector<std::string> parts = split(element,';');
+
+ if (((parts.size() == 4) || (parts.size() == 5) || (parts.size() == 6)) ||
+ ((parts.size() > 6) && (m_formspec_version > FORMSPEC_API_VERSION)))
+ {
+ std::vector<std::string> v_pos = split(parts[0],',');
+ std::vector<std::string> v_geom = split(parts[1],',');
+ std::string name = parts[2];
+ std::vector<std::string> items = split(parts[3],',');
+ std::string str_initial_selection = "";
+ std::string str_transparent = "false";
+
+ if (parts.size() >= 5)
+ str_initial_selection = parts[4];
+
+ if (parts.size() >= 6)
+ str_transparent = parts[5];
+
+ MY_CHECKPOS("textlist",0);
+ MY_CHECKGEOM("textlist",1);
+
+ v2s32 pos = padding;
+ pos.X += stof(v_pos[0]) * (float)spacing.X;
+ pos.Y += stof(v_pos[1]) * (float)spacing.Y;
+
+ v2s32 geom;
+ geom.X = stof(v_geom[0]) * (float)spacing.X;
+ geom.Y = stof(v_geom[1]) * (float)spacing.Y;
+
+
+ core::rect<s32> rect = core::rect<s32>(pos.X, pos.Y, pos.X+geom.X, pos.Y+geom.Y);
+
+ FieldSpec spec(
+ name,
+ L"",
+ L"",
+ 258+m_fields.size()
+ );
+
+ spec.ftype = f_Table;
+
+ for (unsigned int i = 0; i < items.size(); ++i) {
+ items[i] = unescape_enriched(unescape_string(items[i]));
+ }
+
+ //now really show list
+ GUITable *e = new GUITable(Environment, this, spec.fid, rect,
+ m_tsrc);
+
+ if (spec.fname == data->focused_fieldname) {
+ Environment->setFocus(e);
+ }
+
+ e->setTextList(items, is_yes(str_transparent));
+
+ if (data->table_dyndata.find(name) != data->table_dyndata.end()) {
+ e->setDynamicData(data->table_dyndata[name]);
+ }
+
+ if ((str_initial_selection != "") &&
+ (str_initial_selection != "0"))
+ e->setSelected(stoi(str_initial_selection.c_str()));
+
+ m_tables.push_back(std::pair<FieldSpec,GUITable*>(spec, e));
+ m_fields.push_back(spec);
+ return;
+ }
+ errorstream<< "Invalid textlist element(" << parts.size() << "): '" << element << "'" << std::endl;
+}
+
+
+void GUIFormSpecMenu::parseDropDown(parserData* data,std::string element)
+{
+ std::vector<std::string> parts = split(element,';');
+
+ if ((parts.size() == 5) ||
+ ((parts.size() > 5) && (m_formspec_version > FORMSPEC_API_VERSION)))
+ {
+ std::vector<std::string> v_pos = split(parts[0],',');
+ std::string name = parts[2];
+ std::vector<std::string> items = split(parts[3],',');
+ std::string str_initial_selection = "";
+ str_initial_selection = parts[4];
+
+ MY_CHECKPOS("dropdown",0);
+
+ v2s32 pos = padding;
+ pos.X += stof(v_pos[0]) * (float)spacing.X;
+ pos.Y += stof(v_pos[1]) * (float)spacing.Y;
+
+ s32 width = stof(parts[1]) * (float)spacing.Y;
+
+ core::rect<s32> rect = core::rect<s32>(pos.X, pos.Y,
+ pos.X + width, pos.Y + (m_btn_height * 2));
+
+ FieldSpec spec(
+ name,
+ L"",
+ L"",
+ 258+m_fields.size()
+ );
+
+ spec.ftype = f_DropDown;
+ spec.send = true;
+
+ //now really show list
+ gui::IGUIComboBox *e = Environment->addComboBox(rect, this,spec.fid);
+
+ if (spec.fname == data->focused_fieldname) {
+ Environment->setFocus(e);
+ }
+
+ for (unsigned int i=0; i < items.size(); i++) {
+ e->addItem(unescape_enriched(unescape_string(
+ utf8_to_wide(items[i]))).c_str());
+ }
+
+ if (str_initial_selection != "")
+ e->setSelected(stoi(str_initial_selection.c_str())-1);
+
+ m_fields.push_back(spec);
+
+ m_dropdowns.push_back(std::pair<FieldSpec,
+ std::vector<std::string> >(spec, std::vector<std::string>()));
+ std::vector<std::string> &values = m_dropdowns.back().second;
+ for (unsigned int i = 0; i < items.size(); i++) {
+ values.push_back(unescape_string(items[i]));
+ }
+
+ return;
+ }
+ errorstream << "Invalid dropdown element(" << parts.size() << "): '"
+ << element << "'" << std::endl;
+}
+
+void GUIFormSpecMenu::parsePwdField(parserData* data,std::string element)
+{
+ std::vector<std::string> parts = split(element,';');
+
+ if ((parts.size() == 4) || (parts.size() == 5) ||
+ ((parts.size() > 5) && (m_formspec_version > FORMSPEC_API_VERSION)))
+ {
+ std::vector<std::string> v_pos = split(parts[0],',');
+ std::vector<std::string> v_geom = split(parts[1],',');
+ std::string name = parts[2];
+ std::string label = parts[3];
+
+ MY_CHECKPOS("pwdfield",0);
+ MY_CHECKGEOM("pwdfield",1);
+
+ v2s32 pos;
+ pos.X += stof(v_pos[0]) * (float)spacing.X;
+ pos.Y += stof(v_pos[1]) * (float)spacing.Y;
+
+ v2s32 geom;
+ geom.X = (stof(v_geom[0]) * (float)spacing.X)-(spacing.X-imgsize.X);
+
+ pos.Y += (stof(v_geom[1]) * (float)imgsize.Y)/2;
+ pos.Y -= m_btn_height;
+ geom.Y = m_btn_height*2;
+
+ core::rect<s32> rect = core::rect<s32>(pos.X, pos.Y, pos.X+geom.X, pos.Y+geom.Y);
+
+ std::wstring wlabel = utf8_to_wide(unescape_string(label));
+
+ FieldSpec spec(
+ name,
+ wlabel,
+ L"",
+ 258+m_fields.size()
+ );
+
+ spec.send = true;
+ gui::IGUIEditBox * e = Environment->addEditBox(0, rect, true, this, spec.fid);
+
+ if (spec.fname == data->focused_fieldname) {
+ Environment->setFocus(e);
+ }
+
+ if (label.length() >= 1)
+ {
+ int font_height = g_fontengine->getTextHeight();
+ rect.UpperLeftCorner.Y -= font_height;
+ rect.LowerRightCorner.Y = rect.UpperLeftCorner.Y + font_height;
+ addStaticText(Environment, spec.flabel.c_str(), rect, false, true, this, 0);
+ }
+
+ e->setPasswordBox(true,L'*');
+
+ 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 (parts.size() >= 5 && !is_yes(parts[4])) {
+ spec.close_on_enter = false;
+ }
+
+ m_fields.push_back(spec);
+ return;
+ }
+ errorstream<< "Invalid pwdfield element(" << parts.size() << "): '" << element << "'" << std::endl;
+}
+
+void GUIFormSpecMenu::parseSimpleField(parserData* data,
+ std::vector<std::string> &parts)
+{
+ std::string name = parts[0];
+ std::string label = parts[1];
+ std::string default_val = parts[2];
+
+ core::rect<s32> rect;
+
+ if(data->explicit_size)
+ warningstream<<"invalid use of unpositioned \"field\" in inventory"<<std::endl;
+
+ v2s32 pos = padding + AbsoluteRect.UpperLeftCorner;
+ pos.Y = ((m_fields.size()+2)*60);
+ v2s32 size = DesiredRect.getSize();
+
+ rect = core::rect<s32>(size.X / 2 - 150, pos.Y,
+ (size.X / 2 - 150) + 300, pos.Y + (m_btn_height*2));
+
+
+ if(m_form_src)
+ default_val = m_form_src->resolveText(default_val);
+
+
+ std::wstring wlabel = utf8_to_wide(unescape_string(label));
+
+ FieldSpec spec(
+ name,
+ wlabel,
+ utf8_to_wide(unescape_string(default_val)),
+ 258+m_fields.size()
+ );
+
+ if (name == "")
+ {
+ // spec field id to 0, this stops submit searching for a value that isn't there
+ addStaticText(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;
+ addStaticText(Environment, spec.flabel.c_str(), rect, false, true, this, 0);
+ }
+ }
+
+ if (parts.size() >= 4 && !is_yes(parts[3])) {
+ spec.close_on_enter = false;
+ }
+
+ m_fields.push_back(spec);
+}
+
+void GUIFormSpecMenu::parseTextArea(parserData* data,
+ std::vector<std::string>& parts,std::string type)
+{
+
+ std::vector<std::string> v_pos = split(parts[0],',');
+ std::vector<std::string> v_geom = split(parts[1],',');
+ std::string name = parts[2];
+ std::string label = parts[3];
+ std::string default_val = parts[4];
+
+ MY_CHECKPOS(type,0);
+ MY_CHECKGEOM(type,1);
+
+ v2s32 pos;
+ pos.X = stof(v_pos[0]) * (float) spacing.X;
+ pos.Y = stof(v_pos[1]) * (float) spacing.Y;
+
+ v2s32 geom;
+
+ geom.X = (stof(v_geom[0]) * (float)spacing.X)-(spacing.X-imgsize.X);
+
+ if (type == "textarea")
+ {
+ geom.Y = (stof(v_geom[1]) * (float)imgsize.Y) - (spacing.Y-imgsize.Y);
+ pos.Y += m_btn_height;
+ }
+ else
+ {
+ pos.Y += (stof(v_geom[1]) * (float)imgsize.Y)/2;
+ pos.Y -= m_btn_height;
+ geom.Y = m_btn_height*2;
+ }
+
+ core::rect<s32> rect = core::rect<s32>(pos.X, pos.Y, pos.X+geom.X, pos.Y+geom.Y);
+
+ if(!data->explicit_size)
+ warningstream<<"invalid use of positioned "<<type<<" without a size[] element"<<std::endl;
+
+ if(m_form_src)
+ default_val = m_form_src->resolveText(default_val);
+
+
+ std::wstring wlabel = utf8_to_wide(unescape_string(label));
+
+ FieldSpec spec(
+ name,
+ wlabel,
+ utf8_to_wide(unescape_string(default_val)),
+ 258+m_fields.size()
+ );
+
+ if (name == "")
+ {
+ // spec field id to 0, this stops submit searching for a value that isn't there
+ addStaticText(Environment, spec.flabel.c_str(), rect, false, true, this, spec.fid);
+ }
+ else
+ {
+ spec.send = true;
+
+ gui::IGUIEditBox *e;
+#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);
+ 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);
+ }
+
+ 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 (label.length() >= 1)
+ {
+ int font_height = g_fontengine->getTextHeight();
+ rect.UpperLeftCorner.Y -= font_height;
+ rect.LowerRightCorner.Y = rect.UpperLeftCorner.Y + font_height;
+ addStaticText(Environment, spec.flabel.c_str(), rect, false, true, this, 0);
+ }
+ }
+
+ if (parts.size() >= 6 && !is_yes(parts[5])) {
+ spec.close_on_enter = false;
+ }
+
+ m_fields.push_back(spec);
+}
+
+void GUIFormSpecMenu::parseField(parserData* data,std::string element,
+ std::string type)
+{
+ std::vector<std::string> parts = split(element,';');
+
+ if (parts.size() == 3 || parts.size() == 4) {
+ parseSimpleField(data,parts);
+ return;
+ }
+
+ if ((parts.size() == 5) || (parts.size() == 6) ||
+ ((parts.size() > 6) && (m_formspec_version > FORMSPEC_API_VERSION)))
+ {
+ parseTextArea(data,parts,type);
+ return;
+ }
+ errorstream<< "Invalid field element(" << parts.size() << "): '" << element << "'" << std::endl;
+}
+
+void GUIFormSpecMenu::parseLabel(parserData* data,std::string element)
+{
+ std::vector<std::string> parts = split(element,';');
+
+ if ((parts.size() == 2) ||
+ ((parts.size() > 2) && (m_formspec_version > FORMSPEC_API_VERSION)))
+ {
+ std::vector<std::string> v_pos = split(parts[0],',');
+ std::string text = parts[1];
+
+ MY_CHECKPOS("label",0);
+
+ v2s32 pos = padding;
+ pos.X += stof(v_pos[0]) * (float)spacing.X;
+ pos.Y += (stof(v_pos[1]) + 7.0/30.0) * (float)spacing.Y;
+
+ if(!data->explicit_size)
+ warningstream<<"invalid use of label without a size[] element"<<std::endl;
+
+ std::vector<std::string> lines = split(text, '\n');
+
+ for (unsigned int i = 0; i != lines.size(); i++) {
+ // Lines are spaced at the nominal distance of
+ // 2/5 inventory slot, even if the font doesn't
+ // quite match that. This provides consistent
+ // form layout, at the expense of sometimes
+ // having sub-optimal spacing for the font.
+ // We multiply by 2 and then divide by 5, rather
+ // than multiply by 0.4, to get exact results
+ // in the integer cases: 0.4 is not exactly
+ // representable in binary floating point.
+ s32 posy = pos.Y + ((float)i) * spacing.Y * 2.0 / 5.0;
+ std::wstring wlabel = utf8_to_wide(unescape_string(lines[i]));
+ core::rect<s32> rect = core::rect<s32>(
+ pos.X, posy - m_btn_height,
+ pos.X + m_font->getDimension(wlabel.c_str()).Width,
+ posy + m_btn_height);
+ FieldSpec spec(
+ "",
+ wlabel,
+ L"",
+ 258+m_fields.size()
+ );
+ gui::IGUIStaticText *e =
+ addStaticText(Environment, spec.flabel.c_str(),
+ rect, false, false, this, spec.fid);
+ e->setTextAlignment(gui::EGUIA_UPPERLEFT,
+ gui::EGUIA_CENTER);
+ m_fields.push_back(spec);
+ }
+
+ return;
+ }
+ errorstream<< "Invalid label element(" << parts.size() << "): '" << element << "'" << std::endl;
+}
+
+void GUIFormSpecMenu::parseVertLabel(parserData* data,std::string element)
+{
+ std::vector<std::string> parts = split(element,';');
+
+ if ((parts.size() == 2) ||
+ ((parts.size() > 2) && (m_formspec_version > FORMSPEC_API_VERSION)))
+ {
+ std::vector<std::string> v_pos = split(parts[0],',');
+ std::wstring text = unescape_enriched(
+ unescape_string(utf8_to_wide(parts[1])));
+
+ MY_CHECKPOS("vertlabel",1);
+
+ v2s32 pos = padding;
+ pos.X += stof(v_pos[0]) * (float)spacing.X;
+ pos.Y += stof(v_pos[1]) * (float)spacing.Y;
+
+ core::rect<s32> rect = core::rect<s32>(
+ pos.X, pos.Y+((imgsize.Y/2)- m_btn_height),
+ pos.X+15, pos.Y +
+ font_line_height(m_font)
+ * (text.length()+1)
+ +((imgsize.Y/2)- m_btn_height));
+ //actually text.length() would be correct but adding +1 avoids to break all mods
+
+ if(!data->explicit_size)
+ warningstream<<"invalid use of label without a size[] element"<<std::endl;
+
+ std::wstring label = L"";
+
+ for (unsigned int i=0; i < text.length(); i++) {
+ label += text[i];
+ label += L"\n";
+ }
+
+ FieldSpec spec(
+ "",
+ label,
+ L"",
+ 258+m_fields.size()
+ );
+ gui::IGUIStaticText *t =
+ addStaticText(Environment, spec.flabel.c_str(), rect, false, false, this, spec.fid);
+ t->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_CENTER);
+ m_fields.push_back(spec);
+ return;
+ }
+ errorstream<< "Invalid vertlabel element(" << parts.size() << "): '" << element << "'" << std::endl;
+}
+
+void GUIFormSpecMenu::parseImageButton(parserData* data,std::string element,
+ std::string type)
+{
+ std::vector<std::string> parts = split(element,';');
+
+ if ((((parts.size() >= 5) && (parts.size() <= 8)) && (parts.size() != 6)) ||
+ ((parts.size() > 8) && (m_formspec_version > FORMSPEC_API_VERSION)))
+ {
+ std::vector<std::string> v_pos = split(parts[0],',');
+ std::vector<std::string> v_geom = split(parts[1],',');
+ std::string image_name = parts[2];
+ std::string name = parts[3];
+ std::string label = parts[4];
+
+ MY_CHECKPOS("imagebutton",0);
+ MY_CHECKGEOM("imagebutton",1);
+
+ v2s32 pos = padding;
+ pos.X += stof(v_pos[0]) * (float)spacing.X;
+ pos.Y += stof(v_pos[1]) * (float)spacing.Y;
+ v2s32 geom;
+ geom.X = (stof(v_geom[0]) * (float)spacing.X)-(spacing.X-imgsize.X);
+ geom.Y = (stof(v_geom[1]) * (float)spacing.Y)-(spacing.Y-imgsize.Y);
+
+ bool noclip = false;
+ bool drawborder = true;
+ std::string pressed_image_name = "";
+
+ if (parts.size() >= 7) {
+ if (parts[5] == "true")
+ noclip = true;
+ if (parts[6] == "false")
+ drawborder = false;
+ }
+
+ if (parts.size() >= 8) {
+ pressed_image_name = parts[7];
+ }
+
+ core::rect<s32> rect = core::rect<s32>(pos.X, pos.Y, pos.X+geom.X, pos.Y+geom.Y);
+
+ if(!data->explicit_size)
+ warningstream<<"invalid use of image_button without a size[] element"<<std::endl;
+
+ image_name = unescape_string(image_name);
+ pressed_image_name = unescape_string(pressed_image_name);
+
+ std::wstring wlabel = utf8_to_wide(unescape_string(label));
+
+ FieldSpec spec(
+ name,
+ wlabel,
+ utf8_to_wide(image_name),
+ 258+m_fields.size()
+ );
+ spec.ftype = f_Button;
+ if(type == "image_button_exit")
+ spec.is_exit = true;
+
+ video::ITexture *texture = 0;
+ video::ITexture *pressed_texture = 0;
+ texture = m_tsrc->getTexture(image_name);
+ if (pressed_image_name != "")
+ pressed_texture = m_tsrc->getTexture(pressed_image_name);
+ else
+ pressed_texture = texture;
+
+ gui::IGUIButton *e = Environment->addButton(rect, this, spec.fid, spec.flabel.c_str());
+
+ if (spec.fname == data->focused_fieldname) {
+ Environment->setFocus(e);
+ }
+
+ e->setUseAlphaChannel(true);
+ e->setImage(guiScalingImageButton(
+ Environment->getVideoDriver(), texture, geom.X, geom.Y));
+ e->setPressedImage(guiScalingImageButton(
+ Environment->getVideoDriver(), pressed_texture, geom.X, geom.Y));
+ e->setScaleImage(true);
+ e->setNotClipped(noclip);
+ e->setDrawBorder(drawborder);
+
+ m_fields.push_back(spec);
+ return;
+ }
+
+ errorstream<< "Invalid imagebutton element(" << parts.size() << "): '" << element << "'" << std::endl;
+}
+
+void GUIFormSpecMenu::parseTabHeader(parserData* data,std::string element)
+{
+ std::vector<std::string> parts = split(element,';');
+
+ if (((parts.size() == 4) || (parts.size() == 6)) ||
+ ((parts.size() > 6) && (m_formspec_version > FORMSPEC_API_VERSION)))
+ {
+ std::vector<std::string> v_pos = split(parts[0],',');
+ std::string name = parts[1];
+ std::vector<std::string> buttons = split(parts[2],',');
+ std::string str_index = parts[3];
+ bool show_background = true;
+ bool show_border = true;
+ int tab_index = stoi(str_index) -1;
+
+ MY_CHECKPOS("tabheader",0);
+
+ if (parts.size() == 6) {
+ if (parts[4] == "true")
+ show_background = false;
+ if (parts[5] == "false")
+ show_border = false;
+ }
+
+ FieldSpec spec(
+ name,
+ L"",
+ L"",
+ 258+m_fields.size()
+ );
+
+ spec.ftype = f_TabHeader;
+
+ v2s32 pos(0,0);
+ pos.X += stof(v_pos[0]) * (float)spacing.X;
+ pos.Y += stof(v_pos[1]) * (float)spacing.Y - m_btn_height * 2;
+ v2s32 geom;
+ geom.X = DesiredRect.getWidth();
+ geom.Y = m_btn_height*2;
+
+ core::rect<s32> rect = core::rect<s32>(pos.X, pos.Y, pos.X+geom.X,
+ pos.Y+geom.Y);
+
+ gui::IGUITabControl *e = Environment->addTabControl(rect, this,
+ show_background, show_border, spec.fid);
+ e->setAlignment(irr::gui::EGUIA_UPPERLEFT, irr::gui::EGUIA_UPPERLEFT,
+ irr::gui::EGUIA_UPPERLEFT, irr::gui::EGUIA_LOWERRIGHT);
+ e->setTabHeight(m_btn_height*2);
+
+ if (spec.fname == data->focused_fieldname) {
+ Environment->setFocus(e);
+ }
+
+ e->setNotClipped(true);
+
+ for (unsigned int i = 0; i < buttons.size(); i++) {
+ e->addTab(unescape_enriched(unescape_string(
+ utf8_to_wide(buttons[i]))).c_str(), -1);
+ }
+
+ if ((tab_index >= 0) &&
+ (buttons.size() < INT_MAX) &&
+ (tab_index < (int) buttons.size()))
+ e->setActiveTab(tab_index);
+
+ m_fields.push_back(spec);
+ return;
+ }
+ errorstream << "Invalid TabHeader element(" << parts.size() << "): '"
+ << element << "'" << std::endl;
+}
+
+void GUIFormSpecMenu::parseItemImageButton(parserData* data,std::string element)
+{
+
+ if (m_gamedef == 0) {
+ warningstream << "invalid use of item_image_button with m_gamedef==0"
+ << std::endl;
+ return;
+ }
+
+ std::vector<std::string> parts = split(element,';');
+
+ if ((parts.size() == 5) ||
+ ((parts.size() > 5) && (m_formspec_version > FORMSPEC_API_VERSION)))
+ {
+ std::vector<std::string> v_pos = split(parts[0],',');
+ std::vector<std::string> v_geom = split(parts[1],',');
+ std::string item_name = parts[2];
+ std::string name = parts[3];
+ std::string label = parts[4];
+
+ label = unescape_string(label);
+ item_name = unescape_string(item_name);
+
+ MY_CHECKPOS("itemimagebutton",0);
+ MY_CHECKGEOM("itemimagebutton",1);
+
+ v2s32 pos = padding;
+ pos.X += stof(v_pos[0]) * (float)spacing.X;
+ pos.Y += stof(v_pos[1]) * (float)spacing.Y;
+ v2s32 geom;
+ geom.X = (stof(v_geom[0]) * (float)spacing.X)-(spacing.X-imgsize.X);
+ geom.Y = (stof(v_geom[1]) * (float)spacing.Y)-(spacing.Y-imgsize.Y);
+
+ core::rect<s32> rect = core::rect<s32>(pos.X, pos.Y, pos.X+geom.X, pos.Y+geom.Y);
+
+ if(!data->explicit_size)
+ warningstream<<"invalid use of item_image_button without a size[] element"<<std::endl;
+
+ IItemDefManager *idef = m_gamedef->idef();
+ ItemStack item;
+ item.deSerialize(item_name, idef);
+
+ m_tooltips[name] =
+ TooltipSpec(item.getDefinition(idef).description,
+ m_default_tooltip_bgcolor,
+ m_default_tooltip_color);
+
+ FieldSpec spec(
+ name,
+ utf8_to_wide(label),
+ utf8_to_wide(item_name),
+ 258 + m_fields.size()
+ );
+
+ gui::IGUIButton *e = Environment->addButton(rect, this, spec.fid, L"");
+
+ if (spec.fname == data->focused_fieldname) {
+ Environment->setFocus(e);
+ }
+
+ spec.ftype = f_Button;
+ rect+=data->basepos-padding;
+ spec.rect=rect;
+ m_fields.push_back(spec);
+ pos = padding + AbsoluteRect.UpperLeftCorner;
+ pos.X += stof(v_pos[0]) * (float) spacing.X;
+ pos.Y += stof(v_pos[1]) * (float) spacing.Y;
+ m_itemimages.push_back(ImageDrawSpec("", item_name, e, pos, geom));
+ m_static_texts.push_back(StaticTextSpec(utf8_to_wide(label), rect, e));
+ return;
+ }
+ errorstream<< "Invalid ItemImagebutton element(" << parts.size() << "): '" << element << "'" << std::endl;
+}
+
+void GUIFormSpecMenu::parseBox(parserData* data,std::string element)
+{
+ std::vector<std::string> parts = split(element,';');
+
+ if ((parts.size() == 3) ||
+ ((parts.size() > 3) && (m_formspec_version > FORMSPEC_API_VERSION)))
+ {
+ std::vector<std::string> v_pos = split(parts[0],',');
+ std::vector<std::string> v_geom = split(parts[1],',');
+
+ MY_CHECKPOS("box",0);
+ MY_CHECKGEOM("box",1);
+
+ v2s32 pos = padding + AbsoluteRect.UpperLeftCorner;
+ pos.X += stof(v_pos[0]) * (float) spacing.X;
+ pos.Y += stof(v_pos[1]) * (float) spacing.Y;
+
+ v2s32 geom;
+ geom.X = stof(v_geom[0]) * (float)spacing.X;
+ geom.Y = stof(v_geom[1]) * (float)spacing.Y;
+
+ video::SColor tmp_color;
+
+ if (parseColorString(parts[2], tmp_color, false)) {
+ BoxDrawSpec spec(pos, geom, tmp_color);
+
+ m_boxes.push_back(spec);
+ }
+ else {
+ errorstream<< "Invalid Box element(" << parts.size() << "): '" << element << "' INVALID COLOR" << std::endl;
+ }
+ return;
+ }
+ errorstream<< "Invalid Box element(" << parts.size() << "): '" << element << "'" << std::endl;
+}
+
+void GUIFormSpecMenu::parseBackgroundColor(parserData* data,std::string element)
+{
+ std::vector<std::string> parts = split(element,';');
+
+ if (((parts.size() == 1) || (parts.size() == 2)) ||
+ ((parts.size() > 2) && (m_formspec_version > FORMSPEC_API_VERSION)))
+ {
+ parseColorString(parts[0],m_bgcolor,false);
+
+ if (parts.size() == 2) {
+ std::string fullscreen = parts[1];
+ m_bgfullscreen = is_yes(fullscreen);
+ }
+ return;
+ }
+ errorstream<< "Invalid bgcolor element(" << parts.size() << "): '" << element << "'" << std::endl;
+}
+
+void GUIFormSpecMenu::parseListColors(parserData* data,std::string element)
+{
+ std::vector<std::string> parts = split(element,';');
+
+ if (((parts.size() == 2) || (parts.size() == 3) || (parts.size() == 5)) ||
+ ((parts.size() > 5) && (m_formspec_version > FORMSPEC_API_VERSION)))
+ {
+ parseColorString(parts[0], m_slotbg_n, false);
+ parseColorString(parts[1], m_slotbg_h, false);
+
+ if (parts.size() >= 3) {
+ if (parseColorString(parts[2], m_slotbordercolor, false)) {
+ m_slotborder = true;
+ }
+ }
+ if (parts.size() == 5) {
+ video::SColor tmp_color;
+
+ if (parseColorString(parts[3], tmp_color, false))
+ m_default_tooltip_bgcolor = tmp_color;
+ if (parseColorString(parts[4], tmp_color, false))
+ m_default_tooltip_color = tmp_color;
+ }
+ return;
+ }
+ errorstream<< "Invalid listcolors element(" << parts.size() << "): '" << element << "'" << std::endl;
+}
+
+void GUIFormSpecMenu::parseTooltip(parserData* data, std::string element)
+{
+ std::vector<std::string> parts = split(element,';');
+ if (parts.size() == 2) {
+ std::string name = parts[0];
+ m_tooltips[name] = TooltipSpec(unescape_string(parts[1]),
+ m_default_tooltip_bgcolor, m_default_tooltip_color);
+ return;
+ } else if (parts.size() == 4) {
+ std::string name = parts[0];
+ video::SColor tmp_color1, tmp_color2;
+ if ( parseColorString(parts[2], tmp_color1, false) && parseColorString(parts[3], tmp_color2, false) ) {
+ m_tooltips[name] = TooltipSpec(unescape_string(parts[1]),
+ tmp_color1, tmp_color2);
+ return;
+ }
+ }
+ errorstream<< "Invalid tooltip element(" << parts.size() << "): '" << element << "'" << std::endl;
+}
+
+bool GUIFormSpecMenu::parseVersionDirect(std::string data)
+{
+ //some prechecks
+ if (data == "")
+ return false;
+
+ std::vector<std::string> parts = split(data,'[');
+
+ if (parts.size() < 2) {
+ return false;
+ }
+
+ if (parts[0] != "formspec_version") {
+ return false;
+ }
+
+ if (is_number(parts[1])) {
+ m_formspec_version = mystoi(parts[1]);
+ return true;
+ }
+
+ return false;
+}
+
+bool GUIFormSpecMenu::parseSizeDirect(parserData* data, std::string element)
+{
+ if (element == "")
+ return false;
+
+ std::vector<std::string> parts = split(element,'[');
+
+ if (parts.size() < 2)
+ return false;
+
+ std::string type = trim(parts[0]);
+ std::string description = trim(parts[1]);
+
+ if (type != "size" && type != "invsize")
+ return false;
+
+ if (type == "invsize")
+ log_deprecated("Deprecated formspec element \"invsize\" is used");
+
+ parseSize(data, description);
+
+ return true;
+}
+
+void GUIFormSpecMenu::parseElement(parserData* data, std::string element)
+{
+ //some prechecks
+ if (element == "")
+ return;
+
+ std::vector<std::string> parts = split(element,'[');
+
+ // ugly workaround to keep compatibility
+ if (parts.size() > 2) {
+ if (trim(parts[0]) == "image") {
+ for (unsigned int i=2;i< parts.size(); i++) {
+ parts[1] += "[" + parts[i];
+ }
+ }
+ else { return; }
+ }
+
+ if (parts.size() < 2) {
+ return;
+ }
+
+ std::string type = trim(parts[0]);
+ std::string description = trim(parts[1]);
+
+ if (type == "list") {
+ parseList(data,description);
+ return;
+ }
+
+ if (type == "listring") {
+ parseListRing(data, description);
+ return;
+ }
+
+ if (type == "checkbox") {
+ parseCheckbox(data,description);
+ return;
+ }
+
+ if (type == "image") {
+ parseImage(data,description);
+ return;
+ }
+
+ if (type == "item_image") {
+ parseItemImage(data,description);
+ return;
+ }
+
+ if ((type == "button") || (type == "button_exit")) {
+ parseButton(data,description,type);
+ return;
+ }
+
+ if (type == "background") {
+ parseBackground(data,description);
+ return;
+ }
+
+ if (type == "tableoptions"){
+ parseTableOptions(data,description);
+ return;
+ }
+
+ if (type == "tablecolumns"){
+ parseTableColumns(data,description);
+ return;
+ }
+
+ if (type == "table"){
+ parseTable(data,description);
+ return;
+ }
+
+ if (type == "textlist"){
+ parseTextList(data,description);
+ return;
+ }
+
+ if (type == "dropdown"){
+ parseDropDown(data,description);
+ return;
+ }
+
+ if (type == "pwdfield") {
+ parsePwdField(data,description);
+ return;
+ }
+
+ if ((type == "field") || (type == "textarea")){
+ parseField(data,description,type);
+ return;
+ }
+
+ if (type == "label") {
+ parseLabel(data,description);
+ return;
+ }
+
+ if (type == "vertlabel") {
+ parseVertLabel(data,description);
+ return;
+ }
+
+ if (type == "item_image_button") {
+ parseItemImageButton(data,description);
+ return;
+ }
+
+ if ((type == "image_button") || (type == "image_button_exit")) {
+ parseImageButton(data,description,type);
+ return;
+ }
+
+ if (type == "tabheader") {
+ parseTabHeader(data,description);
+ return;
+ }
+
+ if (type == "box") {
+ parseBox(data,description);
+ return;
+ }
+
+ if (type == "bgcolor") {
+ parseBackgroundColor(data,description);
+ return;
+ }
+
+ if (type == "listcolors") {
+ parseListColors(data,description);
+ return;
+ }
+
+ if (type == "tooltip") {
+ parseTooltip(data,description);
+ return;
+ }
+
+ if (type == "scrollbar") {
+ parseScrollBar(data, description);
+ return;
+ }
+
+ // Ignore others
+ infostream
+ << "Unknown DrawSpec: type="<<type<<", data=\""<<description<<"\""
+ <<std::endl;
+}
+
+void GUIFormSpecMenu::regenerateGui(v2u32 screensize)
+{
+ /* useless to regenerate without a screensize */
+ if ((screensize.X <= 0) || (screensize.Y <= 0)) {
+ return;
+ }
+
+ parserData mydata;
+
+ //preserve tables
+ for (u32 i = 0; i < m_tables.size(); ++i) {
+ std::string tablename = m_tables[i].first.fname;
+ GUITable *table = m_tables[i].second;
+ mydata.table_dyndata[tablename] = table->getDynamicData();
+ }
+
+ //set focus
+ if (!m_focused_element.empty())
+ mydata.focused_fieldname = m_focused_element;
+
+ //preserve focus
+ gui::IGUIElement *focused_element = Environment->getFocus();
+ if (focused_element && focused_element->getParent() == this) {
+ s32 focused_id = focused_element->getID();
+ if (focused_id > 257) {
+ for (u32 i=0; i<m_fields.size(); i++) {
+ if (m_fields[i].fid == focused_id) {
+ mydata.focused_fieldname =
+ m_fields[i].fname;
+ break;
+ }
+ }
+ }
+ }
+
+ // Remove children
+ removeChildren();
+
+ for (u32 i = 0; i < m_tables.size(); ++i) {
+ GUITable *table = m_tables[i].second;
+ table->drop();
+ }
+
+ mydata.size= v2s32(100,100);
+ mydata.screensize = screensize;
+
+ // Base position of contents of form
+ mydata.basepos = getBasePos();
+
+ /* Convert m_init_draw_spec to m_inventorylists */
+
+ m_inventorylists.clear();
+ m_images.clear();
+ m_backgrounds.clear();
+ m_itemimages.clear();
+ m_tables.clear();
+ m_checkboxes.clear();
+ m_scrollbars.clear();
+ m_fields.clear();
+ m_boxes.clear();
+ m_tooltips.clear();
+ m_inventory_rings.clear();
+ m_static_texts.clear();
+
+ // Set default values (fits old formspec values)
+ m_bgcolor = video::SColor(140,0,0,0);
+ m_bgfullscreen = false;
+
+ m_slotbg_n = video::SColor(255,128,128,128);
+ m_slotbg_h = video::SColor(255,192,192,192);
+
+ m_default_tooltip_bgcolor = video::SColor(255,110,130,60);
+ m_default_tooltip_color = video::SColor(255,255,255,255);
+
+ m_slotbordercolor = video::SColor(200,0,0,0);
+ m_slotborder = false;
+
+ // Add tooltip
+ {
+ assert(m_tooltip_element == NULL);
+ // Note: parent != this so that the tooltip isn't clipped by the menu rectangle
+ m_tooltip_element = addStaticText(Environment, L"",core::rect<s32>(0,0,110,18));
+ m_tooltip_element->enableOverrideColor(true);
+ m_tooltip_element->setBackgroundColor(m_default_tooltip_bgcolor);
+ m_tooltip_element->setDrawBackground(true);
+ m_tooltip_element->setDrawBorder(true);
+ m_tooltip_element->setOverrideColor(m_default_tooltip_color);
+ m_tooltip_element->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_CENTER);
+ m_tooltip_element->setWordWrap(false);
+ //we're not parent so no autograb for this one!
+ m_tooltip_element->grab();
+ }
+
+ std::vector<std::string> elements = split(m_formspec_string,']');
+ unsigned int i = 0;
+
+ /* try to read version from first element only */
+ if (elements.size() >= 1) {
+ if ( parseVersionDirect(elements[0]) ) {
+ i++;
+ }
+ }
+
+ /* we need size first in order to calculate image scale */
+ mydata.explicit_size = false;
+ for (; i< elements.size(); i++) {
+ if (!parseSizeDirect(&mydata, elements[i])) {
+ break;