#include <iterator>
#include <sstream>
#include <limits>
-#include "guiButton.h"
#include "guiFormSpecMenu.h"
-#include "guiTable.h"
#include "constants.h"
#include "gamedef.h"
#include "client/keycode.h"
#include "util/strfnd.h"
+#include <IGUIButton.h>
#include <IGUICheckBox.h>
+#include <IGUIComboBox.h>
#include <IGUIEditBox.h>
-#include <IGUIButton.h>
#include <IGUIStaticText.h>
#include <IGUIFont.h>
#include <IGUITabControl.h>
-#include <IGUIComboBox.h>
#include "client/renderingengine.h"
#include "log.h"
#include "client/tile.h" // ITextureSource
#include "util/string.h" // for parseColorString()
#include "irrlicht_changes/static_text.h"
#include "client/guiscalingfilter.h"
+#include "guiBackgroundImage.h"
+#include "guiBox.h"
+#include "guiButton.h"
#include "guiEditBoxWithScrollbar.h"
+#include "guiItemImage.h"
+#include "guiScrollBar.h"
+#include "guiTable.h"
#include "intlGUIEditBox.h"
#include "guiHyperText.h"
for (auto &table_it : m_tables) {
table_it.second->drop();
}
+ for (auto &inventorylist_it : m_inventorylists) {
+ inventorylist_it.e->drop();
+ }
+ for (auto &checkbox_it : m_checkboxes) {
+ checkbox_it.second->drop();
+ }
+ for (auto &scrollbar_it : m_scrollbars) {
+ scrollbar_it.second->drop();
+ }
+ for (auto &background_it : m_backgrounds) {
+ background_it->drop();
+ }
+ for (auto &tooltip_rect_it : m_tooltip_rects) {
+ tooltip_rect_it.first->drop();
+ }
delete m_selected_item;
delete m_form_src;
return NULL;
}
-v2s32 GUIFormSpecMenu::getElementBasePos(bool absolute,
- const std::vector<std::string> *v_pos)
+v2s32 GUIFormSpecMenu::getElementBasePos(const std::vector<std::string> *v_pos)
{
- v2s32 pos = padding;
- if (absolute)
- pos += AbsoluteRect.UpperLeftCorner;
-
- v2f32 pos_f = v2f32(pos.X, pos.Y) + pos_offset * spacing;
+ v2f32 pos_f = v2f32(padding.X, padding.Y) + pos_offset * spacing;
if (v_pos) {
pos_f.X += stof((*v_pos)[0]) * spacing.X;
pos_f.Y += stof((*v_pos)[1]) * spacing.Y;
return v2s32(pos_f.X, pos_f.Y);
}
-v2s32 GUIFormSpecMenu::getRealCoordinateBasePos(bool absolute,
- const std::vector<std::string> &v_pos)
+v2s32 GUIFormSpecMenu::getRealCoordinateBasePos(const std::vector<std::string> &v_pos)
{
- v2f32 pos_f = v2f32(0.0f, 0.0f);
-
- pos_f.X += stof(v_pos[0]) + pos_offset.X;
- pos_f.Y += stof(v_pos[1]) + pos_offset.Y;
-
- if (absolute)
- return v2s32(pos_f.X * imgsize.X + AbsoluteRect.UpperLeftCorner.X,
- pos_f.Y * imgsize.Y + AbsoluteRect.UpperLeftCorner.Y);
- return v2s32(pos_f.X * imgsize.X, pos_f.Y * imgsize.Y);
+ return v2s32((stof(v_pos[0]) + pos_offset.X) * imgsize.X,
+ (stof(v_pos[1]) + pos_offset.Y) * imgsize.Y);
}
v2s32 GUIFormSpecMenu::getRealCoordinateGeometry(const std::vector<std::string> &v_geom)
else
loc.deSerialize(location);
- v2s32 pos;
v2s32 geom;
-
- if (data->real_coordinates)
- pos = getRealCoordinateBasePos(true, v_pos);
- else
- pos = getElementBasePos(true, &v_pos);
-
geom.X = stoi(v_geom[0]);
geom.Y = stoi(v_geom[1]);
return;
}
- if(!data->explicit_size)
- warningstream<<"invalid use of list without a size[] element"<<std::endl;
- m_inventorylists.emplace_back(loc, listname, pos, geom, start_i, data->real_coordinates);
+ // check for the existence of inventory and list
+ Inventory *inv = m_invmgr->getInventory(loc);
+ if (!inv) {
+ warningstream << "GUIFormSpecMenu::parseList(): "
+ << "The inventory location "
+ << "\"" << loc.dump() << "\" doesn't exist"
+ << std::endl;
+ return;
+ }
+ InventoryList *ilist = inv->getList(listname);
+ if (!ilist) {
+ warningstream << "GUIFormSpecMenu::parseList(): "
+ << "The inventory list \"" << listname << "\" "
+ << "@ \"" << loc.dump() << "\" doesn't exist"
+ << std::endl;
+ return;
+ }
+
+ // trim geom if it is larger than the actual inventory size
+ s32 list_size = (s32)ilist->getSize();
+ if (list_size < geom.X * geom.Y + start_i) {
+ list_size -= MYMAX(start_i, 0);
+ geom.Y = list_size / geom.X;
+ geom.Y += list_size % geom.X > 0 ? 1 : 0;
+ if (geom.Y <= 1)
+ geom.X = list_size;
+ }
+
+ if (!data->explicit_size)
+ warningstream << "invalid use of list without a size[] element" << std::endl;
+
+ FieldSpec spec(
+ "",
+ L"",
+ L"",
+ 258 + m_fields.size()
+ );
+
+ v2s32 pos;
+ core::rect<s32> rect;
+
+ if (data->real_coordinates) {
+ pos = getRealCoordinateBasePos(v_pos);
+ rect = core::rect<s32>(pos.X, pos.Y,
+ pos.X + (geom.X - 1) * (imgsize.X * 1.25) + imgsize.X,
+ pos.Y + (geom.Y - 1) * (imgsize.Y * 1.25) + imgsize.Y);
+ } else {
+ pos = getElementBasePos(&v_pos);
+ rect = core::rect<s32>(pos.X, pos.Y,
+ pos.X + (geom.X - 1) * spacing.X + imgsize.X,
+ pos.Y + (geom.Y - 1) * spacing.Y + imgsize.Y);
+ }
+
+ gui::IGUIElement *e = new gui::IGUIElement(EGUIET_ELEMENT, Environment,
+ this, spec.fid, rect);
+
+ m_inventorylists.emplace_back(loc, listname, e, geom, start_i,
+ data->real_coordinates);
+ m_fields.push_back(spec);
return;
}
errorstream<< "Invalid list element(" << parts.size() << "): '" << element << "'" << std::endl;
core::rect<s32> rect;
if (data->real_coordinates) {
- pos = getRealCoordinateBasePos(false, v_pos);
+ pos = getRealCoordinateBasePos(v_pos);
rect = core::rect<s32>(
pos.X,
pos.Y + y_center
);
} else {
- pos = getElementBasePos(false, &v_pos);
+ pos = getElementBasePos(&v_pos);
rect = core::rect<s32>(
pos.X,
pos.Y + imgsize.Y / 2 - y_center,
spec.ftype = f_CheckBox;
- gui::IGUICheckBox* e = Environment->addCheckBox(fselected, rect, this,
+ gui::IGUICheckBox *e = Environment->addCheckBox(fselected, rect, this,
spec.fid, spec.flabel.c_str());
auto style = getStyleForElement("checkbox", name);
Environment->setFocus(e);
}
- m_checkboxes.emplace_back(spec,e);
+ e->grab();
+ m_checkboxes.emplace_back(spec, e);
m_fields.push_back(spec);
return;
}
v2s32 dim;
if (data->real_coordinates) {
- pos = getRealCoordinateBasePos(false, v_pos);
+ pos = getRealCoordinateBasePos(v_pos);
dim = getRealCoordinateGeometry(v_geom);
} else {
- pos = getElementBasePos(false, &v_pos);
+ pos = getElementBasePos(&v_pos);
dim.X = stof(v_geom[0]) * spacing.X;
dim.Y = stof(v_geom[1]) * spacing.Y;
}
spec.ftype = f_ScrollBar;
spec.send = true;
- gui::IGUIScrollBar* e =
- Environment->addScrollBar(is_horizontal,rect,this,spec.fid);
+ GUIScrollBar *e = new GUIScrollBar(Environment, this, spec.fid, rect,
+ is_horizontal, false);
auto style = getStyleForElement("scrollbar", name);
e->setNotClipped(style.getBool(StyleSpec::NOCLIP, false));
v2s32 geom;
if (data->real_coordinates) {
- pos = getRealCoordinateBasePos(true, v_pos);
+ pos = getRealCoordinateBasePos(v_pos);
geom = getRealCoordinateGeometry(v_geom);
} else {
- pos = getElementBasePos(true, &v_pos);
+ pos = getElementBasePos(&v_pos);
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.emplace_back(name, pos, geom);
+
+ video::ITexture *texture = m_tsrc->getTexture(name);
+ if (!texture) {
+ errorstream << "GUIFormSpecMenu::parseImage() Unable to load texture:"
+ << std::endl << "\t" << name << std::endl;
+ return;
+ }
+
+ FieldSpec spec(
+ name,
+ L"",
+ L"",
+ 258 + m_fields.size()
+ );
+ core::rect<s32> rect(pos, pos + geom);
+ gui::IGUIImage *e = Environment->addImage(rect, this, spec.fid, 0, true);
+ e->setImage(texture);
+ e->setScaleImage(true);
+ e->setNotClipped(true);
+ m_fields.push_back(spec);
+
return;
}
MY_CHECKPOS("image", 0);
- v2s32 pos = getElementBasePos(true, &v_pos);
+ v2s32 pos = getElementBasePos(&v_pos);
if (!data->explicit_size)
warningstream<<"invalid use of image without a size[] element"<<std::endl;
- m_images.emplace_back(name, pos);
+
+ video::ITexture *texture = m_tsrc->getTexture(name);
+ if (!texture) {
+ errorstream << "GUIFormSpecMenu::parseImage() Unable to load texture:"
+ << std::endl << "\t" << name << std::endl;
+ return;
+ }
+
+ FieldSpec spec(
+ name,
+ L"",
+ L"",
+ 258 + m_fields.size()
+ );
+ gui::IGUIImage *e = Environment->addImage(texture, pos, true, this,
+ spec.fid, 0);
+ e->setNotClipped(true);
+ m_fields.push_back(spec);
+
return;
}
errorstream<< "Invalid image element(" << parts.size() << "): '" << element << "'" << std::endl;
v2s32 geom;
if (data->real_coordinates) {
- pos = getRealCoordinateBasePos(true, v_pos);
+ pos = getRealCoordinateBasePos(v_pos);
geom = getRealCoordinateGeometry(v_geom);
} else {
- pos = getElementBasePos(true, &v_pos);
+ pos = getElementBasePos(&v_pos);
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.emplace_back("", name, pos, geom);
+
+ FieldSpec spec(
+ "",
+ L"",
+ L"",
+ 258 + m_fields.size()
+ );
+ spec.ftype = f_ItemImage;
+
+ GUIItemImage *e = new GUIItemImage(Environment, this, spec.fid,
+ core::rect<s32>(pos, pos + geom), name, m_font, m_client);
+ e->drop();
+
+ m_fields.push_back(spec);
return;
}
errorstream<< "Invalid ItemImage element(" << parts.size() << "): '" << element << "'" << std::endl;
core::rect<s32> rect;
if (data->real_coordinates) {
- pos = getRealCoordinateBasePos(false, v_pos);
+ pos = getRealCoordinateBasePos(v_pos);
geom = getRealCoordinateGeometry(v_geom);
rect = core::rect<s32>(pos.X, pos.Y, pos.X+geom.X,
pos.Y+geom.Y);
} else {
- pos = getElementBasePos(false, &v_pos);
+ pos = getElementBasePos(&v_pos);
geom.X = (stof(v_geom[0]) * spacing.X) - (spacing.X - imgsize.X);
pos.Y += (stof(v_geom[1]) * (float)imgsize.Y)/2;
name,
wlabel,
L"",
- 258+m_fields.size()
+ 258 + m_fields.size()
);
spec.ftype = f_Button;
if(type == "button_exit")
v2s32 geom;
if (data->real_coordinates) {
- pos = getRealCoordinateBasePos(true, v_pos);
+ pos = getRealCoordinateBasePos(v_pos);
geom = getRealCoordinateGeometry(v_geom);
} else {
- pos = getElementBasePos(true, &v_pos);
+ pos = getElementBasePos(&v_pos);
pos.X -= (spacing.X - (float)imgsize.X) / 2;
pos.Y -= (spacing.Y - (float)imgsize.Y) / 2;
bool clip = false;
if (parts.size() >= 4 && is_yes(parts[3])) {
if (data->real_coordinates) {
- pos = getRealCoordinateBasePos(false, v_pos) * -1;
+ pos = getRealCoordinateBasePos(v_pos) * -1;
geom = v2s32(0, 0);
} else {
pos.X = stoi(v_pos[0]); //acts as offset
if (!data->explicit_size && !clip)
warningstream << "invalid use of unclipped background without a size[] element" << std::endl;
- m_backgrounds.emplace_back(name, pos, geom, middle, clip);
+ FieldSpec spec(
+ name,
+ L"",
+ L"",
+ 258 + m_fields.size()
+ );
+
+ core::rect<s32> rect;
+ if (!clip) {
+ // no auto_clip => position like normal image
+ rect = core::rect<s32>(pos, pos + geom);
+ } else {
+ // it will be auto-clipped when drawing
+ rect = core::rect<s32>(-pos, pos);
+ }
+
+ GUIBackgroundImage *e = new GUIBackgroundImage(Environment, this, spec.fid,
+ rect, name, middle, m_tsrc, clip);
+
+ FATAL_ERROR_IF(!e, "Failed to create background formspec element");
+
+ e->setNotClipped(true);
+
+ e->setVisible(false); // the element is drawn manually before all others
+ m_backgrounds.push_back(e);
+ m_fields.push_back(spec);
return;
}
errorstream<< "Invalid background element(" << parts.size() << "): '" << element << "'" << std::endl;
v2s32 geom;
if (data->real_coordinates) {
- pos = getRealCoordinateBasePos(false, v_pos);
+ pos = getRealCoordinateBasePos(v_pos);
geom = getRealCoordinateGeometry(v_geom);
} else {
- pos = getElementBasePos(false, &v_pos);
+ pos = getElementBasePos(&v_pos);
geom.X = stof(v_geom[0]) * spacing.X;
geom.Y = stof(v_geom[1]) * spacing.Y;
}
name,
L"",
L"",
- 258+m_fields.size()
+ 258 + m_fields.size()
);
spec.ftype = f_Table;
}
//now really show table
- GUITable *e = new GUITable(Environment, this, spec.fid, rect,
- m_tsrc);
+ GUITable *e = new GUITable(Environment, this, spec.fid, rect, m_tsrc);
if (spec.fname == data->focused_fieldname) {
Environment->setFocus(e);
v2s32 geom;
if (data->real_coordinates) {
- pos = getRealCoordinateBasePos(false, v_pos);
+ pos = getRealCoordinateBasePos(v_pos);
geom = getRealCoordinateGeometry(v_geom);
} else {
- pos = getElementBasePos(false, &v_pos);
+ pos = getElementBasePos(&v_pos);
geom.X = stof(v_geom[0]) * spacing.X;
geom.Y = stof(v_geom[1]) * spacing.Y;
}
name,
L"",
L"",
- 258+m_fields.size()
+ 258 + m_fields.size()
);
spec.ftype = f_Table;
}
//now really show list
- GUITable *e = new GUITable(Environment, this, spec.fid, rect,
- m_tsrc);
+ GUITable *e = new GUITable(Environment, this, spec.fid, rect, m_tsrc);
if (spec.fname == data->focused_fieldname) {
Environment->setFocus(e);
MY_CHECKGEOM("dropdown",1);
- pos = getRealCoordinateBasePos(false, v_pos);
+ pos = getRealCoordinateBasePos(v_pos);
geom = getRealCoordinateGeometry(v_geom);
rect = core::rect<s32>(pos.X, pos.Y, pos.X+geom.X, pos.Y+geom.Y);
} else {
- pos = getElementBasePos(false, &v_pos);
+ pos = getElementBasePos(&v_pos);
s32 width = stof(parts[1]) * spacing.Y;
name,
L"",
L"",
- 258+m_fields.size()
+ 258 + m_fields.size()
);
spec.ftype = f_DropDown;
spec.send = true;
//now really show list
- gui::IGUIComboBox *e = Environment->addComboBox(rect, this,spec.fid);
+ gui::IGUIComboBox *e = Environment->addComboBox(rect, this, spec.fid);
if (spec.fname == data->focused_fieldname) {
Environment->setFocus(e);
v2s32 geom;
if (data->real_coordinates) {
- pos = getRealCoordinateBasePos(false, v_pos);
+ pos = getRealCoordinateBasePos(v_pos);
geom = getRealCoordinateGeometry(v_geom);
} else {
- pos = getElementBasePos(false, &v_pos);
+ pos = getElementBasePos(&v_pos);
pos -= padding;
geom.X = (stof(v_geom[0]) * spacing.X) - (spacing.X - imgsize.X);
name,
wlabel,
L"",
- 258+m_fields.size()
+ 258 + m_fields.size()
);
spec.send = true;
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);
+ this, spec.fid);
return;
}
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();
+ e = new gui::intlGUIEditBox(spec.fdefault.c_str(), true, Environment,
+ this, spec.fid, rect, is_editable, is_multiline);
} else {
if (is_multiline) {
e = new GUIEditBoxWithScrollBar(spec.fdefault.c_str(), true,
- Environment, this, spec.fid, rect, is_editable, true);
- e->drop();
+ Environment, this, spec.fid, rect, is_editable, true);
} else if (is_editable) {
- e = Environment->addEditBox(spec.fdefault.c_str(), rect, true,
- this, spec.fid);
+ e = Environment->addEditBox(spec.fdefault.c_str(), rect, true, this,
+ spec.fid);
+ e->grab();
}
}
+ auto style = getStyleForElement(is_multiline ? "textarea" : "field", spec.fname);
+
if (e) {
if (is_editable && spec.fname == data->focused_fieldname)
Environment->setFocus(e);
e->OnEvent(evt);
}
- auto style = getStyleForElement(is_multiline ? "textarea" : "field", spec.fname);
e->setNotClipped(style.getBool(StyleSpec::NOCLIP, false));
e->setDrawBorder(style.getBool(StyleSpec::BORDER, true));
e->setOverrideColor(style.getColor(StyleSpec::TEXTCOLOR, video::SColor(0xFFFFFFFF)));
if (style.get(StyleSpec::BGCOLOR, "") == "transparent") {
e->setDrawBackground(false);
}
+
+ e->drop();
}
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);
+ IGUIElement *t = gui::StaticText::add(Environment, spec.flabel.c_str(),
+ rect, false, true, this, 0);
+
+ if (t)
+ t->setNotClipped(style.getBool(StyleSpec::NOCLIP, false));
}
}
-void GUIFormSpecMenu::parseSimpleField(parserData* data,
- std::vector<std::string> &parts)
+void GUIFormSpecMenu::parseSimpleField(parserData *data,
+ std::vector<std::string> &parts)
{
std::string name = parts[0];
std::string label = parts[1];
core::rect<s32> rect;
- if(data->explicit_size)
- warningstream<<"invalid use of unpositioned \"field\" in inventory"<<std::endl;
+ if (data->explicit_size)
+ warningstream << "invalid use of unpositioned \"field\" in inventory" << std::endl;
- v2s32 pos = getElementBasePos(false, nullptr);
- pos.Y = ((m_fields.size()+2)*60);
+ v2s32 pos = getElementBasePos(nullptr);
+ pos.Y = (data->simple_field_count + 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));
+ 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)
+ if (m_form_src)
default_val = m_form_src->resolveText(default_val);
name,
wlabel,
utf8_to_wide(unescape_string(default_val)),
- 258+m_fields.size()
+ 258 + m_fields.size()
);
createTextField(data, spec, rect, false);
- if (parts.size() >= 4) {
- // TODO: remove after 2016-11-03
- warningstream << "field/simple: use field_close_on_enter[name, enabled]" <<
- " instead of the 4th param" << std::endl;
- field_close_on_enter[name] = is_yes(parts[3]);
- }
-
m_fields.push_back(spec);
+
+ data->simple_field_count++;
}
void GUIFormSpecMenu::parseTextArea(parserData* data, std::vector<std::string>& parts,
v2s32 geom;
if (data->real_coordinates) {
- pos = getRealCoordinateBasePos(false, v_pos);
+ pos = getRealCoordinateBasePos(v_pos);
geom = getRealCoordinateGeometry(v_geom);
} else {
- pos = getElementBasePos(false, &v_pos);
+ pos = getElementBasePos(&v_pos);
pos -= padding;
geom.X = (stof(v_geom[0]) * spacing.X) - (spacing.X - imgsize.X);
name,
wlabel,
utf8_to_wide(unescape_string(default_val)),
- 258+m_fields.size()
+ 258 + m_fields.size()
);
createTextField(data, spec, rect, type == "textarea");
v2s32 geom;
if (data->real_coordinates) {
- pos = getRealCoordinateBasePos(false, v_pos);
+ pos = getRealCoordinateBasePos(v_pos);
geom = getRealCoordinateGeometry(v_geom);
} else {
- pos = getElementBasePos(false, &v_pos);
+ pos = getElementBasePos(&v_pos);
pos -= padding;
pos.X += stof(v_pos[0]) * spacing.X;
// easily without sacrificing good line distance. If
// it was one whole imgsize, it would have too much
// spacing.
- v2s32 pos = getRealCoordinateBasePos(false, v_pos);
+ v2s32 pos = getRealCoordinateBasePos(v_pos);
// Labels are positioned by their center, not their top.
pos.Y += (((float) imgsize.Y) / -2) + (((float) imgsize.Y) * i / 2);
// in the integer cases: 0.4 is not exactly
// representable in binary floating point.
- v2s32 pos = getElementBasePos(false, nullptr);
+ v2s32 pos = getElementBasePos(nullptr);
pos.X += stof(v_pos[0]) * spacing.X;
pos.Y += (stof(v_pos[1]) + 7.0f / 30.0f) * spacing.Y;
"",
wlabel_colors,
L"",
- 258+m_fields.size()
+ 258 + m_fields.size()
);
gui::IGUIStaticText *e = gui::StaticText::add(Environment,
- spec.flabel.c_str(), rect, false, false, this, spec.fid);
+ spec.flabel.c_str(), rect, false, false, this, spec.fid);
e->setTextAlignment(gui::EGUIA_UPPERLEFT, gui::EGUIA_CENTER);
auto style = getStyleForElement("label", spec.fname);
core::rect<s32> rect;
if (data->real_coordinates) {
- pos = getRealCoordinateBasePos(false, v_pos);
+ pos = getRealCoordinateBasePos(v_pos);
// Vertlabels are positioned by center, not left.
pos.X -= imgsize.X / 2;
(text.length() + 1));
} else {
- pos = getElementBasePos(false, &v_pos);
+ pos = getElementBasePos(&v_pos);
// As above, the length must be one longer. The width of
// the rect (15 pixels) seems rather arbitrary, but
"",
label,
L"",
- 258+m_fields.size()
+ 258 + m_fields.size()
);
gui::IGUIStaticText *e = gui::StaticText::add(Environment, spec.flabel.c_str(),
- rect, false, false, this, spec.fid);
+ rect, false, false, this, spec.fid);
e->setTextAlignment(gui::EGUIA_CENTER, gui::EGUIA_CENTER);
auto style = getStyleForElement("vertlabel", spec.fname, "label");
v2s32 geom;
if (data->real_coordinates) {
- pos = getRealCoordinateBasePos(false, v_pos);
+ pos = getRealCoordinateBasePos(v_pos);
geom = getRealCoordinateGeometry(v_geom);
} else {
- pos = getElementBasePos(false, &v_pos);
+ pos = getElementBasePos(&v_pos);
geom.X = (stof(v_geom[0]) * spacing.X) - (spacing.X - imgsize.X);
geom.Y = (stof(v_geom[1]) * spacing.Y) - (spacing.Y - imgsize.Y);
}
name,
wlabel,
utf8_to_wide(image_name),
- 258+m_fields.size()
+ 258 + m_fields.size()
);
spec.ftype = f_Button;
if (type == "image_button_exit")
name,
L"",
L"",
- 258+m_fields.size()
+ 258 + m_fields.size()
);
spec.ftype = f_TabHeader;
v2s32 geom;
if (data->real_coordinates) {
- pos = getRealCoordinateBasePos(false, v_pos);
+ pos = getRealCoordinateBasePos(v_pos);
geom = getRealCoordinateGeometry(v_geom);
pos.Y -= geom.Y; // TabHeader base pos is the bottom, not the top.
v2s32 geom;
if (data->real_coordinates) {
- pos = getRealCoordinateBasePos(false, v_pos);
+ pos = getRealCoordinateBasePos(v_pos);
geom = getRealCoordinateGeometry(v_geom);
} else {
- pos = getElementBasePos(false, &v_pos);
+ pos = getElementBasePos(&v_pos);
geom.X = (stof(v_geom[0]) * spacing.X) - (spacing.X - imgsize.X);
geom.Y = (stof(v_geom[1]) * spacing.Y) - (spacing.Y - imgsize.Y);
}
m_default_tooltip_bgcolor,
m_default_tooltip_color);
- FieldSpec spec(
+ // the spec for the button
+ FieldSpec spec_btn(
name,
utf8_to_wide(label),
utf8_to_wide(item_name),
258 + m_fields.size()
);
- gui::IGUIButton *e = GUIButton::addButton(Environment, rect, this, spec.fid, L"");
+ gui::IGUIButton *e_btn = GUIButton::addButton(Environment, rect, this, spec_btn.fid, L"");
- auto style = getStyleForElement("item_image_button", spec.fname, "image_button");
- e->setNotClipped(style.getBool(StyleSpec::NOCLIP, false));
- e->setDrawBorder(style.getBool(StyleSpec::BORDER, true));
+ auto style = getStyleForElement("item_image_button", spec_btn.fname, "image_button");
+ e_btn->setNotClipped(style.getBool(StyleSpec::NOCLIP, false));
+ e_btn->setDrawBorder(style.getBool(StyleSpec::BORDER, true));
- if (spec.fname == data->focused_fieldname) {
- Environment->setFocus(e);
+ if (spec_btn.fname == data->focused_fieldname) {
+ Environment->setFocus(e_btn);
}
- spec.ftype = f_Button;
- rect+=data->basepos-padding;
- spec.rect=rect;
- m_fields.push_back(spec);
+ spec_btn.ftype = f_Button;
+ rect += data->basepos-padding;
+ spec_btn.rect = rect;
+ m_fields.push_back(spec_btn);
- if (data->real_coordinates)
- pos = getRealCoordinateBasePos(true, v_pos);
- else
- pos = getElementBasePos(true, &v_pos);
+ // the spec for the item-image
+ FieldSpec spec_img(
+ "",
+ L"",
+ L"",
+ 258 + m_fields.size()
+ );
+
+ GUIItemImage *e_img = new GUIItemImage(Environment, e_btn, spec_img.fid,
+ core::rect<s32>(0, 0, geom.X, geom.Y), item_name, m_font, m_client);
+
+ e_img->setText(utf8_to_wide(label).c_str());
- m_itemimages.emplace_back("", item_name, e, pos, geom);
- m_static_texts.emplace_back(utf8_to_wide(label), rect, e);
+ e_img->drop();
+
+ m_fields.push_back(spec_img);
return;
}
errorstream<< "Invalid ItemImagebutton element(" << parts.size() << "): '" << element << "'" << std::endl;
v2s32 geom;
if (data->real_coordinates) {
- pos = getRealCoordinateBasePos(true, v_pos);
+ pos = getRealCoordinateBasePos(v_pos);
geom = getRealCoordinateGeometry(v_geom);
} else {
- pos = getElementBasePos(true, &v_pos);
+ pos = getElementBasePos(&v_pos);
geom.X = stof(v_geom[0]) * spacing.X;
geom.Y = stof(v_geom[1]) * spacing.Y;
}
video::SColor tmp_color;
if (parseColorString(parts[2], tmp_color, false, 0x8C)) {
- BoxDrawSpec spec(pos, geom, tmp_color);
+ FieldSpec spec(
+ "",
+ L"",
+ L"",
+ 258 + m_fields.size()
+ );
+ spec.ftype = f_Box;
- m_boxes.push_back(spec);
- }
- else {
+ core::rect<s32> rect(pos, pos + geom);
+
+ GUIBox *e = new GUIBox(Environment, this, spec.fid, rect, tmp_color);
+
+ e->setNotClipped(true);
+
+ e->drop();
+
+ m_fields.push_back(spec);
+
+ } else {
errorstream<< "Invalid Box element(" << parts.size() << "): '" << element << "' INVALID COLOR" << std::endl;
}
return;
v2s32 geom;
if (data->real_coordinates) {
- pos = getRealCoordinateBasePos(true, v_pos);
+ pos = getRealCoordinateBasePos(v_pos);
geom = getRealCoordinateGeometry(v_geom);
} else {
- pos = getElementBasePos(true, &v_pos);
+ pos = getElementBasePos(&v_pos);
geom.X = stof(v_geom[0]) * spacing.X;
geom.Y = stof(v_geom[1]) * spacing.Y;
}
- irr::core::rect<s32> rect(pos, pos + geom);
- m_tooltip_rects.emplace_back(rect, spec);
+ FieldSpec fieldspec(
+ "",
+ L"",
+ L"",
+ 258 + m_fields.size()
+ );
+
+ core::rect<s32> rect(pos, pos + geom);
+
+ gui::IGUIElement *e = new gui::IGUIElement(EGUIET_ELEMENT, Environment,
+ this, fieldspec.fid, rect);
+
+ m_fields.push_back(fieldspec);
+ m_tooltip_rects.emplace_back(e, spec);
+
} else {
m_tooltips[parts[0]] = spec;
}
for (auto &table_it : m_tables) {
table_it.second->drop();
}
+ for (auto &inventorylist_it : m_inventorylists) {
+ inventorylist_it.e->drop();
+ }
+ for (auto &checkbox_it : m_checkboxes) {
+ checkbox_it.second->drop();
+ }
+ for (auto &scrollbar_it : m_scrollbars) {
+ scrollbar_it.second->drop();
+ }
+ for (auto &background_it : m_backgrounds) {
+ background_it->drop();
+ }
+ for (auto &tooltip_rect_it : m_tooltip_rects) {
+ tooltip_rect_it.first->drop();
+ }
mydata.size= v2s32(100,100);
mydata.screensize = screensize;
mydata.offset = v2f32(0.5f, 0.5f);
mydata.anchor = v2f32(0.5f, 0.5f);
+ mydata.simple_field_count = 0;
// 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_tooltip_rects.clear();
m_inventory_rings.clear();
- m_static_texts.clear();
m_dropdowns.clear();
theme_by_name.clear();
theme_by_type.clear();
pos_offset = v2f32();
+ // used for formspec versions < 3
+ core::list<IGUIElement *>::Iterator legacy_sort_start = Children.getLast();
+
if (enable_prepends) {
// Backup the coordinates so that prepends can use the coordinates of choice.
bool rc_backup = mydata.real_coordinates;
for (const auto &element : prepend_elements)
parseElement(&mydata, element);
+ // legacy sorting for formspec versions < 3
+ if (m_formspec_version >= 3)
+ // prepends do not need to be reordered
+ legacy_sort_start = Children.getLast();
+ else if (version_backup >= 3)
+ // only prepends elements have to be reordered
+ legacySortElements(legacy_sort_start);
+
m_formspec_version = version_backup;
mydata.real_coordinates = rc_backup; // Restore coordinates
}
// If there are fields without explicit size[], add a "Proceed"
// button and adjust size to fit all the fields.
- if (!m_fields.empty() && !mydata.explicit_size) {
+ if (mydata.simple_field_count > 0 && !mydata.explicit_size) {
mydata.rect = core::rect<s32>(
- mydata.screensize.X/2 - 580/2,
- mydata.screensize.Y/2 - 300/2,
- mydata.screensize.X/2 + 580/2,
- mydata.screensize.Y/2 + 240/2+(m_fields.size()*60)
+ mydata.screensize.X / 2 - 580 / 2,
+ mydata.screensize.Y / 2 - 300 / 2,
+ mydata.screensize.X / 2 + 580 / 2,
+ mydata.screensize.Y / 2 + 240 / 2 + mydata.simple_field_count * 60
);
+
DesiredRect = mydata.rect;
recalculateAbsolutePosition(false);
mydata.basepos = getBasePos();
{
v2s32 pos = mydata.basepos;
- pos.Y = ((m_fields.size()+2)*60);
+ pos.Y = (mydata.simple_field_count + 2) * 60;
v2s32 size = DesiredRect.getSize();
- mydata.rect =
- core::rect<s32>(size.X/2-70, pos.Y,
- (size.X/2-70)+140, pos.Y + (m_btn_height*2));
+ mydata.rect = core::rect<s32>(
+ size.X / 2 - 70, pos.Y,
+ size.X / 2 - 70 + 140, pos.Y + m_btn_height * 2
+ );
const wchar_t *text = wgettext("Proceed");
GUIButton::addButton(Environment, mydata.rect, this, 257, text);
delete[] text;
}
-
}
//set initial focus if parser didn't set it
setInitialFocus();
skin->setFont(old_font);
+
+ // legacy sorting
+ if (m_formspec_version < 3)
+ legacySortElements(legacy_sort_start);
+}
+
+void GUIFormSpecMenu::legacySortElements(core::list<IGUIElement *>::Iterator from)
+{
+ /*
+ * The order was:
+ * (0. background colors and backgrounds)
+ * 1. boxes
+ * 2. all normal elements (like buttons)
+ * 3. images
+ * 4. item images
+ * 5. item lists (TODO)
+ */
+
+ if (from == Children.end())
+ from = Children.begin();
+ else
+ from++;
+
+ core::list<IGUIElement *>::Iterator to = Children.end();
+
+ // step 1: move all boxes to back and all images to front
+ // (drawn in back = drawn first = in front of list)
+ for (auto i = from; i != to;) {
+ if (getTypeByID((*i)->getID()) == f_Box && i != from) {
+ auto e = *i;
+ i = Children.erase(i);
+ Children.insert_before(from, e);
+ } else if ((*i)->hasType(gui::EGUIET_IMAGE)) {
+ auto e = *i;
+ i = Children.erase(i);
+ Children.push_back(e);
+ if (to == Children.end())
+ to = Children.getLast(); // do not touch sorted back
+ if (i == Children.end())
+ break;
+ } else {
+ i++;
+ }
+ }
+
+ // step 2: move all item images to front
+ for (auto i = from; i != to;) {
+ if (getTypeByID((*i)->getID()) == f_ItemImage) {
+ auto e = *i;
+ i = Children.erase(i);
+ Children.push_back(e);
+ if (to == Children.end())
+ to = Children.getLast(); // do not touch sorted back
+ if (i == Children.end())
+ break;
+ } else {
+ i++;
+ }
+ }
+
+ // step 3: move all item lists to front
+ // TODO when item lists are drawn in order
}
#ifdef __ANDROID__
if (iter->fname != fieldname) {
continue;
}
- IGUIElement* tochange = getElementFromId(iter->fid);
+ IGUIElement *tochange = getElementFromId(iter->fid, true);
if (tochange == 0) {
return false;
GUIFormSpecMenu::ItemSpec GUIFormSpecMenu::getItemAtPos(v2s32 p) const
{
- core::rect<s32> imgrect(0,0,imgsize.X,imgsize.Y);
+ core::rect<s32> imgrect(0, 0, imgsize.X, imgsize.Y);
for (const GUIFormSpecMenu::ListDrawSpec &s : m_inventorylists) {
+ core::rect<s32> clipping_rect = s.e->getAbsoluteClippingRect();
+ v2s32 base_pos = s.e->getAbsolutePosition().UpperLeftCorner;
for(s32 i=0; i<s.geom.X*s.geom.Y; i++) {
s32 item_i = i + s.start_item_i;
y = (i/s.geom.X) * spacing.Y;
}
v2s32 p0(x,y);
- core::rect<s32> rect = imgrect + s.pos + p0;
- if(rect.isPointInside(p))
- {
+ core::rect<s32> rect = imgrect + base_pos + p0;
+ rect.clipAgainst(clipping_rect);
+ if (rect.getArea() > 0 && rect.isPointInside(p))
return ItemSpec(s.inventoryloc, s.listname, item_i);
- }
}
}
video::IVideoDriver* driver = Environment->getVideoDriver();
Inventory *inv = m_invmgr->getInventory(s.inventoryloc);
- if(!inv){
+ if (!inv) {
warningstream<<"GUIFormSpecMenu::drawList(): "
- <<"The inventory location "
- <<"\""<<s.inventoryloc.dump()<<"\" doesn't exist"
- <<std::endl;
+ << "The inventory location "
+ << "\"" << s.inventoryloc.dump() << "\" doesn't exist anymore"
+ << std::endl;
return;
}
InventoryList *ilist = inv->getList(s.listname);
- if(!ilist){
- warningstream<<"GUIFormSpecMenu::drawList(): "
- <<"The inventory list \""<<s.listname<<"\" @ \""
- <<s.inventoryloc.dump()<<"\" doesn't exist"
- <<std::endl;
+ if (!ilist) {
+ warningstream << "GUIFormSpecMenu::drawList(): "
+ << "The inventory list \"" << s.listname << "\" @ \""
+ << s.inventoryloc.dump() << "\" doesn't exist anymore"
+ << std::endl;
return;
}
- core::rect<s32> imgrect(0,0,imgsize.X,imgsize.Y);
+ core::rect<s32> imgrect(0, 0, imgsize.X, imgsize.Y);
+ core::rect<s32> clipping_rect = s.e->getAbsoluteClippingRect();
+ v2s32 base_pos = s.e->getAbsolutePosition().UpperLeftCorner;
for (s32 i = 0; i < s.geom.X * s.geom.Y; i++) {
s32 item_i = i + s.start_item_i;
y = (i/s.geom.X) * spacing.Y;
}
v2s32 p(x,y);
- core::rect<s32> rect = imgrect + s.pos + p;
+ core::rect<s32> rect = imgrect + base_pos + p;
ItemStack item = ilist->getItem(item_i);
bool selected = m_selected_item
&& m_invmgr->getInventory(m_selected_item->inventoryloc) == inv
&& m_selected_item->listname == s.listname
&& m_selected_item->i == item_i;
- bool hovering = rect.isPointInside(m_pointer);
+ core::rect<s32> clipped_rect(rect);
+ clipped_rect.clipAgainst(clipping_rect);
+ bool hovering = clipped_rect.getArea() > 0 &&
+ clipped_rect.isPointInside(m_pointer);
ItemRotationKind rotation_kind = selected ? IT_ROT_SELECTED :
(hovering ? IT_ROT_HOVERED : IT_ROT_NONE);
if (layer == 0) {
if (hovering) {
item_hovered = true;
- driver->draw2DRectangle(m_slotbg_h, rect, &AbsoluteClippingRect);
+ driver->draw2DRectangle(m_slotbg_h, rect, &clipping_rect);
} else {
- driver->draw2DRectangle(m_slotbg_n, rect, &AbsoluteClippingRect);
+ driver->draw2DRectangle(m_slotbg_n, rect, &clipping_rect);
}
}
s32 border = 1;
driver->draw2DRectangle(m_slotbordercolor,
core::rect<s32>(v2s32(x1 - border, y1 - border),
- v2s32(x2 + border, y1)), NULL);
+ v2s32(x2 + border, y1)), &clipping_rect);
driver->draw2DRectangle(m_slotbordercolor,
core::rect<s32>(v2s32(x1 - border, y2),
- v2s32(x2 + border, y2 + border)), NULL);
+ v2s32(x2 + border, y2 + border)), &clipping_rect);
driver->draw2DRectangle(m_slotbordercolor,
core::rect<s32>(v2s32(x1 - border, y1),
- v2s32(x1, y2)), NULL);
+ v2s32(x1, y2)), &clipping_rect);
driver->draw2DRectangle(m_slotbordercolor,
core::rect<s32>(v2s32(x2, y1),
- v2s32(x2 + border, y2)), NULL);
+ v2s32(x2 + border, y2)), &clipping_rect);
}
if (layer == 1) {
if (!item.empty()) {
// Draw item stack
drawItemStack(driver, m_font, item,
- rect, &AbsoluteClippingRect, m_client, rotation_kind);
-
+ rect, &clipping_rect, m_client, rotation_kind);
// Draw tooltip
if (hovering && !m_selected_item) {
std::string tooltip = item.getDescription(m_client->idef());
video::IVideoDriver* driver = Environment->getVideoDriver();
if (!m_selected_item) {
+ // reset rotation time
drawItemStack(driver, m_font, ItemStack(),
core::rect<s32>(v2s32(0, 0), v2s32(0, 0)), NULL,
m_client, IT_ROT_DRAGGED);
video::IVideoDriver* driver = Environment->getVideoDriver();
+ /*
+ Draw background color
+ */
v2u32 screenSize = driver->getScreenSize();
core::rect<s32> allbg(0, 0, screenSize.X, screenSize.Y);
else
driver->draw2DRectangle(m_bgcolor, AbsoluteRect, &AbsoluteClippingRect);
+ /*
+ Draw rect_mode tooltip
+ */
m_tooltip_element->setVisible(false);
for (const auto &pair : m_tooltip_rects) {
- if (pair.first.isPointInside(m_pointer)) {
+ const core::rect<s32> &rect = pair.first->getAbsoluteClippingRect();
+ if (rect.getArea() > 0 && rect.isPointInside(m_pointer)) {
const std::wstring &text = pair.second.tooltip;
if (!text.empty()) {
showTooltip(text, pair.second.color, pair.second.bgcolor);
/*
Draw backgrounds
*/
- for (const GUIFormSpecMenu::ImageDrawSpec &spec : m_backgrounds) {
- video::ITexture *texture = m_tsrc->getTexture(spec.name);
-
- if (texture != 0) {
- // Image size on screen
- core::rect<s32> imgrect(0, 0, spec.geom.X, spec.geom.Y);
- // Image rectangle on screen
- core::rect<s32> rect = imgrect + spec.pos;
- // Middle rect for 9-slicing
- core::rect<s32> middle = spec.middle;
-
- if (spec.clip) {
- core::dimension2d<s32> absrec_size = AbsoluteRect.getSize();
- rect = core::rect<s32>(AbsoluteRect.UpperLeftCorner.X - spec.pos.X,
- AbsoluteRect.UpperLeftCorner.Y - spec.pos.Y,
- AbsoluteRect.UpperLeftCorner.X + absrec_size.Width + spec.pos.X,
- AbsoluteRect.UpperLeftCorner.Y + absrec_size.Height + spec.pos.Y);
- }
-
- if (middle.getArea() == 0) {
- const video::SColor color(255, 255, 255, 255);
- const video::SColor colors[] = {color, color, color, color};
- draw2DImageFilterScaled(driver, texture, rect,
- core::rect<s32>(core::position2d<s32>(0, 0),
- core::dimension2di(texture->getOriginalSize())),
- NULL/*&AbsoluteClippingRect*/, colors, true);
- } else {
- // `-x` is interpreted as `w - x`
- if (middle.LowerRightCorner.X < 0) {
- middle.LowerRightCorner.X += texture->getOriginalSize().Width;
- }
- if (middle.LowerRightCorner.Y < 0) {
- middle.LowerRightCorner.Y += texture->getOriginalSize().Height;
- }
- draw2DImage9Slice(driver, texture, rect, middle);
- }
- } else {
- errorstream << "GUIFormSpecMenu::drawMenu() Draw backgrounds unable to load texture:" << std::endl;
- errorstream << "\t" << spec.name << std::endl;
- }
- }
-
- /*
- Draw Boxes
- */
- for (const GUIFormSpecMenu::BoxDrawSpec &spec : m_boxes) {
- irr::video::SColor todraw = spec.color;
-
- core::rect<s32> rect(spec.pos.X,spec.pos.Y,
- spec.pos.X + spec.geom.X,spec.pos.Y + spec.geom.Y);
-
- driver->draw2DRectangle(todraw, rect, 0);
+ for (gui::IGUIElement *e : m_backgrounds) {
+ e->setVisible(true);
+ e->draw();
+ e->setVisible(false);
}
/*
*/
gui::IGUIElement::draw();
- /*
- Draw images
- */
- for (const GUIFormSpecMenu::ImageDrawSpec &spec : m_images) {
- video::ITexture *texture = m_tsrc->getTexture(spec.name);
-
- if (texture != 0) {
- const core::dimension2d<u32>& img_origsize = texture->getOriginalSize();
- // Image size on screen
- core::rect<s32> imgrect;
-
- if (spec.scale)
- imgrect = core::rect<s32>(0,0,spec.geom.X, spec.geom.Y);
- else {
-
- imgrect = core::rect<s32>(0,0,img_origsize.Width,img_origsize.Height);
- }
- // Image rectangle on screen
- core::rect<s32> rect = imgrect + spec.pos;
- const video::SColor color(255,255,255,255);
- const video::SColor colors[] = {color,color,color,color};
- draw2DImageFilterScaled(driver, texture, rect,
- core::rect<s32>(core::position2d<s32>(0,0),img_origsize),
- NULL/*&AbsoluteClippingRect*/, colors, true);
- }
- else {
- errorstream << "GUIFormSpecMenu::drawMenu() Draw images unable to load texture:" << std::endl;
- errorstream << "\t" << spec.name << std::endl;
- }
- }
-
- /*
- Draw item images
- */
- for (const GUIFormSpecMenu::ImageDrawSpec &spec : m_itemimages) {
- if (m_client == 0)
- break;
-
- IItemDefManager *idef = m_client->idef();
- ItemStack item;
- item.deSerialize(spec.item_name, idef);
- core::rect<s32> imgrect(0, 0, spec.geom.X, spec.geom.Y);
- // Viewport rectangle on screen
- core::rect<s32> rect = imgrect + spec.pos;
- if (spec.parent_button && spec.parent_button->isPressed()) {
-#if (IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR < 8)
- rect += core::dimension2d<s32>(
- 0.05 * (float)rect.getWidth(), 0.05 * (float)rect.getHeight());
-#else
- rect += core::dimension2d<s32>(
- skin->getSize(irr::gui::EGDS_BUTTON_PRESSED_IMAGE_OFFSET_X),
- skin->getSize(irr::gui::EGDS_BUTTON_PRESSED_IMAGE_OFFSET_Y));
-#endif
- }
- drawItemStack(driver, m_font, item, rect, &AbsoluteClippingRect,
- m_client, IT_ROT_NONE);
- }
-
/*
Draw items
Layer 0: Item slot rectangles
}
}
if (!item_hovered) {
+ // reset rotation time
drawItemStack(driver, m_font, ItemStack(),
core::rect<s32>(v2s32(0, 0), v2s32(0, 0)),
NULL, m_client, IT_ROT_HOVERED);
m_pointer = RenderingEngine::get_raw_device()->getCursorControl()->getPosition();
#endif
- /*
- Draw static text elements
- */
- for (const GUIFormSpecMenu::StaticTextSpec &spec : m_static_texts) {
- core::rect<s32> rect = spec.rect;
- if (spec.parent_button && spec.parent_button->isPressed()) {
-#if (IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR < 8)
- rect += core::dimension2d<s32>(
- 0.05 * (float)rect.getWidth(), 0.05 * (float)rect.getHeight());
-#else
- // Use image offset instead of text's because its a bit smaller
- // and fits better, also TEXT_OFFSET_X is always 0
- rect += core::dimension2d<s32>(
- skin->getSize(irr::gui::EGDS_BUTTON_PRESSED_IMAGE_OFFSET_X),
- skin->getSize(irr::gui::EGDS_BUTTON_PRESSED_IMAGE_OFFSET_Y));
-#endif
- }
- video::SColor color(255, 255, 255, 255);
- m_font->draw(spec.text.c_str(), rect, color, true, true, &rect);
- }
-
/*
Draw fields/buttons tooltips
*/
else if(s.ftype == f_DropDown) {
// no dynamic cast possible due to some distributions shipped
// without rtti support in irrlicht
- IGUIElement * element = getElementFromId(s.fid);
+ IGUIElement *element = getElementFromId(s.fid, true);
gui::IGUIComboBox *e = NULL;
if ((element) && (element->getType() == gui::EGUIET_COMBO_BOX)) {
e = static_cast<gui::IGUIComboBox*>(element);
+ } else {
+ warningstream << "GUIFormSpecMenu::acceptInput: dropdown "
+ << "field without dropdown element" << std::endl;
+ continue;
}
s32 selected = e->getSelected();
if (selected >= 0) {
else if (s.ftype == f_TabHeader) {
// no dynamic cast possible due to some distributions shipped
// without rttzi support in irrlicht
- IGUIElement * element = getElementFromId(s.fid);
- gui::IGUITabControl *e = NULL;
+ IGUIElement *element = getElementFromId(s.fid, true);
+ gui::IGUITabControl *e = nullptr;
if ((element) && (element->getType() == gui::EGUIET_TAB_CONTROL)) {
e = static_cast<gui::IGUITabControl *>(element);
}
else if (s.ftype == f_CheckBox) {
// no dynamic cast possible due to some distributions shipped
// without rtti support in irrlicht
- IGUIElement * element = getElementFromId(s.fid);
- gui::IGUICheckBox *e = NULL;
+ IGUIElement *element = getElementFromId(s.fid, true);
+ gui::IGUICheckBox *e = nullptr;
if ((element) && (element->getType() == gui::EGUIET_CHECK_BOX)) {
e = static_cast<gui::IGUICheckBox*>(element);
}
else if (s.ftype == f_ScrollBar) {
// no dynamic cast possible due to some distributions shipped
// without rtti support in irrlicht
- IGUIElement * element = getElementFromId(s.fid);
- gui::IGUIScrollBar *e = NULL;
- if ((element) && (element->getType() == gui::EGUIET_SCROLL_BAR)) {
- e = static_cast<gui::IGUIScrollBar*>(element);
- }
+ IGUIElement *element = getElementFromId(s.fid, true);
+ GUIScrollBar *e = nullptr;
+ if (element && element->getType() == gui::EGUIET_ELEMENT)
+ e = static_cast<GUIScrollBar *>(element);
- if (e != 0) {
+ if (e) {
std::stringstream os;
os << e->getPos();
if (s.fdefault == L"Changed")
fields[name] = "VAL:" + os.str();
}
}
- else
- {
- IGUIElement* e = getElementFromId(s.fid);
- if(e != NULL) {
+ else {
+ IGUIElement *e = getElementFromId(s.fid, true);
+ if (e)
fields[name] = wide_to_utf8(e->getText());
- }
}
}
}
std::string GUIFormSpecMenu::getNameByID(s32 id)
{
for (FieldSpec &spec : m_fields) {
- if (spec.fid == id) {
+ if (spec.fid == id)
return spec.fname;
- }
}
return "";
}
+
+FormspecFieldType GUIFormSpecMenu::getTypeByID(s32 id)
+{
+ for (FieldSpec &spec : m_fields) {
+ if (spec.fid == id)
+ return spec.ftype;
+ }
+ return f_Unknown;
+}
+
/**
* get label of element by id
* @param id of element
std::wstring GUIFormSpecMenu::getLabelByID(s32 id)
{
for (FieldSpec &spec : m_fields) {
- if (spec.fid == id) {
+ if (spec.fid == id)
return spec.flabel;
- }
}
return L"";
}