aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDS <vorunbekannt75@web.de>2019-11-07 20:11:01 +0100
committerSmallJoker <SmallJoker@users.noreply.github.com>2019-11-07 20:11:01 +0100
commit5506e97ed897dde2d4820fe1b021a4622bae03b3 (patch)
tree85a029b7f9bb046bcf338abad3ea1e50362d6164
parent15a030ec9f5d9016c287cf3964894683121e59fd (diff)
downloadminetest-5506e97ed897dde2d4820fe1b021a4622bae03b3.tar.gz
minetest-5506e97ed897dde2d4820fe1b021a4622bae03b3.tar.bz2
minetest-5506e97ed897dde2d4820fe1b021a4622bae03b3.zip
Formspec: draw order and clipping for all elements (#8740)
-rw-r--r--build/android/jni/Android.mk3
-rw-r--r--doc/lua_api.txt7
-rw-r--r--src/client/guiscalingfilter.cpp7
-rw-r--r--src/client/guiscalingfilter.h3
-rw-r--r--src/gui/CMakeLists.txt3
-rw-r--r--src/gui/guiBackgroundImage.cpp69
-rw-r--r--src/gui/guiBackgroundImage.h38
-rw-r--r--src/gui/guiBox.cpp38
-rw-r--r--src/gui/guiBox.h34
-rw-r--r--src/gui/guiFormSpecMenu.cpp829
-rw-r--r--src/gui/guiFormSpecMenu.h131
-rw-r--r--src/gui/guiItemImage.cpp64
-rw-r--r--src/gui/guiItemImage.h46
-rw-r--r--src/network/networkprotocol.h6
14 files changed, 824 insertions, 454 deletions
diff --git a/build/android/jni/Android.mk b/build/android/jni/Android.mk
index 22e1f8a08..1038b83c6 100644
--- a/build/android/jni/Android.mk
+++ b/build/android/jni/Android.mk
@@ -178,12 +178,15 @@ LOCAL_SRC_FILES := \
jni/src/filesys.cpp \
jni/src/genericobject.cpp \
jni/src/gettext.cpp \
+ jni/src/gui/guiBackgroundImage.cpp \
+ jni/src/gui/guiBox.cpp \
jni/src/gui/guiButton.cpp \
jni/src/gui/guiChatConsole.cpp \
jni/src/gui/guiConfirmRegistration.cpp \
jni/src/gui/guiEditBoxWithScrollbar.cpp \
jni/src/gui/guiEngine.cpp \
jni/src/gui/guiFormSpecMenu.cpp \
+ jni/src/gui/guiItemImage.cpp \
jni/src/gui/guiKeyChangeMenu.cpp \
jni/src/gui/guiPasswordChange.cpp \
jni/src/gui/guiPathSelectMenu.cpp \
diff --git a/doc/lua_api.txt b/doc/lua_api.txt
index c0501f6bf..f7cb4ca7c 100644
--- a/doc/lua_api.txt
+++ b/doc/lua_api.txt
@@ -1923,6 +1923,11 @@ When displaying text which can contain formspec code, e.g. text set by a player,
use `minetest.formspec_escape`.
For coloured text you can use `minetest.colorize`.
+Since formspec version 3, elements drawn in the order they are defined. All
+background elements are drawn before all other elements.
+`list` elements are an exception here. They are drawn last. This, however, might
+be changed at any time.
+
**WARNING**: do _not_ use a element name starting with `key_`; those names are
reserved to pass key press events to formspec!
@@ -2032,6 +2037,7 @@ Elements
be shown if the inventory list is of size 0.
* **Note**: With the new coordinate system, the spacing between inventory
slots is one-fourth the size of an inventory slot.
+* **Note**: Lists are drawn after every other element. This might change at any time.
### `list[<inventory location>;<list name>;<X>,<Y>;<W>,<H>;<starting item index>]`
@@ -2039,6 +2045,7 @@ Elements
be shown if the inventory list is of size 0.
* **Note**: With the new coordinate system, the spacing between inventory
slots is one-fourth the size of an inventory slot.
+* **Note**: Lists are drawn after every other element. This might change at any time.
### `listring[<inventory location>;<list name>]`
diff --git a/src/client/guiscalingfilter.cpp b/src/client/guiscalingfilter.cpp
index 2ff57ab74..4262331bd 100644
--- a/src/client/guiscalingfilter.cpp
+++ b/src/client/guiscalingfilter.cpp
@@ -171,7 +171,8 @@ void draw2DImageFilterScaled(video::IVideoDriver *driver, video::ITexture *txr,
}
void draw2DImage9Slice(video::IVideoDriver *driver, video::ITexture *texture,
- const core::rect<s32> &rect, const core::rect<s32> &middle)
+ const core::rect<s32> &rect, const core::rect<s32> &middle,
+ const core::rect<s32> *cliprect)
{
const video::SColor color(255,255,255,255);
const video::SColor colors[] = {color,color,color,color};
@@ -222,9 +223,7 @@ void draw2DImage9Slice(video::IVideoDriver *driver, video::ITexture *texture,
break;
}
- draw2DImageFilterScaled(driver, texture, dest,
- src,
- NULL/*&AbsoluteClippingRect*/, colors, true);
+ draw2DImageFilterScaled(driver, texture, dest, src, cliprect, colors, true);
}
}
}
diff --git a/src/client/guiscalingfilter.h b/src/client/guiscalingfilter.h
index 181009551..b703d91f0 100644
--- a/src/client/guiscalingfilter.h
+++ b/src/client/guiscalingfilter.h
@@ -53,4 +53,5 @@ void draw2DImageFilterScaled(video::IVideoDriver *driver, video::ITexture *txr,
* 9-slice / segment drawing
*/
void draw2DImage9Slice(video::IVideoDriver *driver, video::ITexture *texture,
- const core::rect<s32> &rect, const core::rect<s32> &middle);
+ const core::rect<s32> &rect, const core::rect<s32> &middle,
+ const core::rect<s32> *cliprect = nullptr);
diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt
index c9f750b9a..7b6f8fdb4 100644
--- a/src/gui/CMakeLists.txt
+++ b/src/gui/CMakeLists.txt
@@ -1,10 +1,13 @@
set(gui_SRCS
+ ${CMAKE_CURRENT_SOURCE_DIR}/guiBackgroundImage.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/guiBox.cpp
${CMAKE_CURRENT_SOURCE_DIR}/guiButton.cpp
${CMAKE_CURRENT_SOURCE_DIR}/guiChatConsole.cpp
${CMAKE_CURRENT_SOURCE_DIR}/guiConfirmRegistration.cpp
${CMAKE_CURRENT_SOURCE_DIR}/guiEditBoxWithScrollbar.cpp
${CMAKE_CURRENT_SOURCE_DIR}/guiEngine.cpp
${CMAKE_CURRENT_SOURCE_DIR}/guiFormSpecMenu.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/guiItemImage.cpp
${CMAKE_CURRENT_SOURCE_DIR}/guiKeyChangeMenu.cpp
${CMAKE_CURRENT_SOURCE_DIR}/guiPasswordChange.cpp
${CMAKE_CURRENT_SOURCE_DIR}/guiPathSelectMenu.cpp
diff --git a/src/gui/guiBackgroundImage.cpp b/src/gui/guiBackgroundImage.cpp
new file mode 100644
index 000000000..21c1e88cf
--- /dev/null
+++ b/src/gui/guiBackgroundImage.cpp
@@ -0,0 +1,69 @@
+/*
+Part of Minetest
+Copyright (C) 2013 RealBadAngel, Maciej Kasatkin <mk@realbadangel.pl>
+
+Permission to use, copy, modify, and distribute this software for any
+purpose with or without fee is hereby granted, provided that the above
+copyright notice and this permission notice appear in all copies.
+
+THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+*/
+
+#include "guiBackgroundImage.h"
+#include "client/guiscalingfilter.h"
+#include "log.h"
+
+GUIBackgroundImage::GUIBackgroundImage(gui::IGUIEnvironment *env,
+ gui::IGUIElement *parent, s32 id, const core::rect<s32> &rectangle,
+ const std::string &name, const core::rect<s32> &middle,
+ ISimpleTextureSource *tsrc, bool autoclip) :
+ gui::IGUIElement(gui::EGUIET_ELEMENT, env, parent, id, rectangle),
+ m_name(name), m_middle(middle), m_tsrc(tsrc), m_autoclip(autoclip)
+{
+}
+
+void GUIBackgroundImage::draw()
+{
+ if (!IsVisible)
+ return;
+
+ video::ITexture *texture = m_tsrc->getTexture(m_name);
+
+ if (!texture) {
+ errorstream << "GUIBackgroundImage::draw() Unable to load texture:"
+ << std::endl;
+ errorstream << "\t" << m_name << std::endl;
+ return;
+ }
+
+ core::rect<s32> rect = AbsoluteRect;
+ if (m_autoclip)
+ rect.LowerRightCorner += Parent->getAbsolutePosition().getSize();
+
+ video::IVideoDriver *driver = Environment->getVideoDriver();
+
+ if (m_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())),
+ nullptr, colors, true);
+ } else {
+ core::rect<s32> middle = m_middle;
+ // `-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);
+ }
+
+ IGUIElement::draw();
+}
diff --git a/src/gui/guiBackgroundImage.h b/src/gui/guiBackgroundImage.h
new file mode 100644
index 000000000..31fbfd09c
--- /dev/null
+++ b/src/gui/guiBackgroundImage.h
@@ -0,0 +1,38 @@
+/*
+Part of Minetest
+Copyright (C) 2013 RealBadAngel, Maciej Kasatkin <mk@realbadangel.pl>
+
+Permission to use, copy, modify, and distribute this software for any
+purpose with or without fee is hereby granted, provided that the above
+copyright notice and this permission notice appear in all copies.
+
+THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+*/
+
+#pragma once
+
+#include "irrlichttypes_extrabloated.h"
+#include "util/string.h"
+#include "client/tile.h" // ITextureSource
+
+class GUIBackgroundImage : public gui::IGUIElement
+{
+public:
+ GUIBackgroundImage(gui::IGUIEnvironment *env, gui::IGUIElement *parent, s32 id,
+ const core::rect<s32> &rectangle, const std::string &name,
+ const core::rect<s32> &middle, ISimpleTextureSource *tsrc, bool autoclip);
+
+ virtual void draw() override;
+
+private:
+ std::string m_name;
+ core::rect<s32> m_middle;
+ ISimpleTextureSource *m_tsrc;
+ bool m_autoclip;
+};
diff --git a/src/gui/guiBox.cpp b/src/gui/guiBox.cpp
new file mode 100644
index 000000000..7f329cc32
--- /dev/null
+++ b/src/gui/guiBox.cpp
@@ -0,0 +1,38 @@
+/*
+Minetest
+Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 2.1 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License along
+with this program; if not, write to the Free Software Foundation, Inc.,
+51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+#include "guiBox.h"
+
+GUIBox::GUIBox(gui::IGUIEnvironment *env, gui::IGUIElement *parent, s32 id,
+ const core::rect<s32> &rectangle, const video::SColor &color) :
+ gui::IGUIElement(gui::EGUIET_ELEMENT, env, parent, id, rectangle),
+ m_color(color)
+{
+}
+
+void GUIBox::draw()
+{
+ if (!IsVisible)
+ return;
+
+ Environment->getVideoDriver()->draw2DRectangle(m_color, AbsoluteRect,
+ &AbsoluteClippingRect);
+
+ IGUIElement::draw();
+}
diff --git a/src/gui/guiBox.h b/src/gui/guiBox.h
new file mode 100644
index 000000000..5306fdf65
--- /dev/null
+++ b/src/gui/guiBox.h
@@ -0,0 +1,34 @@
+/*
+Minetest
+Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 2.1 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License along
+with this program; if not, write to the Free Software Foundation, Inc.,
+51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+#pragma once
+
+#include "irrlichttypes_extrabloated.h"
+
+class GUIBox : public gui::IGUIElement
+{
+public:
+ GUIBox(gui::IGUIEnvironment *env, gui::IGUIElement *parent, s32 id,
+ const core::rect<s32> &rectangle, const video::SColor &color);
+
+ virtual void draw() override;
+
+private:
+ video::SColor m_color;
+};
diff --git a/src/gui/guiFormSpecMenu.cpp b/src/gui/guiFormSpecMenu.cpp
index 44fdf7862..11c1e36b2 100644
--- a/src/gui/guiFormSpecMenu.cpp
+++ b/src/gui/guiFormSpecMenu.cpp
@@ -23,20 +23,18 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#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
@@ -55,7 +53,13 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#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"
@@ -122,6 +126,21 @@ GUIFormSpecMenu::~GUIFormSpecMenu()
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;
@@ -256,14 +275,9 @@ std::vector<std::string>* GUIFormSpecMenu::getDropDownValues(const std::string &
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;
@@ -271,18 +285,10 @@ v2s32 GUIFormSpecMenu::getElementBasePos(bool absolute,
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)
@@ -373,14 +379,7 @@ void GUIFormSpecMenu::parseList(parserData* data, const std::string &element)
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]);
@@ -393,9 +392,65 @@ void GUIFormSpecMenu::parseList(parserData* data, const std::string &element)
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;
@@ -470,7 +525,7 @@ void GUIFormSpecMenu::parseCheckbox(parserData* data, const std::string &element
core::rect<s32> rect;
if (data->real_coordinates) {
- pos = getRealCoordinateBasePos(false, v_pos);
+ pos = getRealCoordinateBasePos(v_pos);
rect = core::rect<s32>(
pos.X,
@@ -479,7 +534,7 @@ void GUIFormSpecMenu::parseCheckbox(parserData* data, const std::string &element
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,
@@ -497,7 +552,7 @@ void GUIFormSpecMenu::parseCheckbox(parserData* data, const std::string &element
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);
@@ -507,7 +562,8 @@ void GUIFormSpecMenu::parseCheckbox(parserData* data, const std::string &element
Environment->setFocus(e);
}
- m_checkboxes.emplace_back(spec,e);
+ e->grab();
+ m_checkboxes.emplace_back(spec, e);
m_fields.push_back(spec);
return;
}
@@ -531,10 +587,10 @@ void GUIFormSpecMenu::parseScrollBar(parserData* data, const std::string &elemen
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;
}
@@ -556,8 +612,8 @@ void GUIFormSpecMenu::parseScrollBar(parserData* data, const std::string &elemen
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));
@@ -593,17 +649,37 @@ void GUIFormSpecMenu::parseImage(parserData* data, const std::string &element)
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;
}
@@ -613,11 +689,29 @@ void GUIFormSpecMenu::parseImage(parserData* data, const std::string &element)
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;
@@ -641,17 +735,30 @@ void GUIFormSpecMenu::parseItemImage(parserData* data, const std::string &elemen
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;
@@ -678,12 +785,12 @@ void GUIFormSpecMenu::parseButton(parserData* data, const std::string &element,
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;
@@ -700,7 +807,7 @@ void GUIFormSpecMenu::parseButton(parserData* data, const std::string &element,
name,
wlabel,
L"",
- 258+m_fields.size()
+ 258 + m_fields.size()
);
spec.ftype = f_Button;
if(type == "button_exit")
@@ -780,10 +887,10 @@ void GUIFormSpecMenu::parseBackground(parserData* data, const std::string &eleme
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;
@@ -794,7 +901,7 @@ void GUIFormSpecMenu::parseBackground(parserData* data, const std::string &eleme
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
@@ -827,8 +934,33 @@ void GUIFormSpecMenu::parseBackground(parserData* data, const std::string &eleme
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;
@@ -890,10 +1022,10 @@ void GUIFormSpecMenu::parseTable(parserData* data, const std::string &element)
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;
}
@@ -904,7 +1036,7 @@ void GUIFormSpecMenu::parseTable(parserData* data, const std::string &element)
name,
L"",
L"",
- 258+m_fields.size()
+ 258 + m_fields.size()
);
spec.ftype = f_Table;
@@ -914,8 +1046,7 @@ void GUIFormSpecMenu::parseTable(parserData* data, const std::string &element)
}
//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);
@@ -967,10 +1098,10 @@ void GUIFormSpecMenu::parseTextList(parserData* data, const std::string &element
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;
}
@@ -981,7 +1112,7 @@ void GUIFormSpecMenu::parseTextList(parserData* data, const std::string &element
name,
L"",
L"",
- 258+m_fields.size()
+ 258 + m_fields.size()
);
spec.ftype = f_Table;
@@ -991,8 +1122,7 @@ void GUIFormSpecMenu::parseTextList(parserData* data, const std::string &element
}
//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);
@@ -1045,11 +1175,11 @@ void GUIFormSpecMenu::parseDropDown(parserData* data, const std::string &element
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;
@@ -1061,14 +1191,14 @@ void GUIFormSpecMenu::parseDropDown(parserData* data, const std::string &element
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);
@@ -1127,10 +1257,10 @@ void GUIFormSpecMenu::parsePwdField(parserData* data, const std::string &element
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);
@@ -1148,7 +1278,7 @@ void GUIFormSpecMenu::parsePwdField(parserData* data, const std::string &element
name,
wlabel,
L"",
- 258+m_fields.size()
+ 258 + m_fields.size()
);
spec.send = true;
@@ -1202,7 +1332,7 @@ void GUIFormSpecMenu::createTextField(parserData *data, FieldSpec &spec,
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;
}
@@ -1219,20 +1349,21 @@ void GUIFormSpecMenu::createTextField(parserData *data, FieldSpec &spec,
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);
@@ -1252,26 +1383,30 @@ void GUIFormSpecMenu::createTextField(parserData *data, FieldSpec &spec,
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];
@@ -1279,18 +1414,20 @@ void GUIFormSpecMenu::parseSimpleField(parserData* data,
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);
@@ -1300,19 +1437,14 @@ void GUIFormSpecMenu::parseSimpleField(parserData* data,
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,
@@ -1331,10 +1463,10 @@ void GUIFormSpecMenu::parseTextArea(parserData* data, std::vector<std::string>&
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);
@@ -1367,7 +1499,7 @@ void GUIFormSpecMenu::parseTextArea(parserData* data, std::vector<std::string>&
name,
wlabel,
utf8_to_wide(unescape_string(default_val)),
- 258+m_fields.size()
+ 258 + m_fields.size()
);
createTextField(data, spec, rect, type == "textarea");
@@ -1422,10 +1554,10 @@ void GUIFormSpecMenu::parseHyperText(parserData *data, const std::string &elemen
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;
@@ -1485,7 +1617,7 @@ void GUIFormSpecMenu::parseLabel(parserData* data, const std::string &element)
// 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);
@@ -1506,7 +1638,7 @@ void GUIFormSpecMenu::parseLabel(parserData* data, const std::string &element)
// 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;
@@ -1522,10 +1654,10 @@ void GUIFormSpecMenu::parseLabel(parserData* data, const std::string &element)
"",
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);
@@ -1558,7 +1690,7 @@ void GUIFormSpecMenu::parseVertLabel(parserData* data, const std::string &elemen
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;
@@ -1571,7 +1703,7 @@ void GUIFormSpecMenu::parseVertLabel(parserData* data, const std::string &elemen
(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
@@ -1598,10 +1730,10 @@ void GUIFormSpecMenu::parseVertLabel(parserData* data, const std::string &elemen
"",
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");
@@ -1650,10 +1782,10 @@ void GUIFormSpecMenu::parseImageButton(parserData* data, const std::string &elem
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);
}
@@ -1673,7 +1805,7 @@ void GUIFormSpecMenu::parseImageButton(parserData* data, const std::string &elem
name,
wlabel,
utf8_to_wide(image_name),
- 258+m_fields.size()
+ 258 + m_fields.size()
);
spec.ftype = f_Button;
if (type == "image_button_exit")
@@ -1762,7 +1894,7 @@ void GUIFormSpecMenu::parseTabHeader(parserData* data, const std::string &elemen
name,
L"",
L"",
- 258+m_fields.size()
+ 258 + m_fields.size()
);
spec.ftype = f_TabHeader;
@@ -1771,7 +1903,7 @@ void GUIFormSpecMenu::parseTabHeader(parserData* data, const std::string &elemen
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.
@@ -1856,10 +1988,10 @@ void GUIFormSpecMenu::parseItemImageButton(parserData* data, const std::string &
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);
}
@@ -1878,35 +2010,45 @@ void GUIFormSpecMenu::parseItemImageButton(parserData* data, const std::string &
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;
@@ -1929,10 +2071,10 @@ void GUIFormSpecMenu::parseBox(parserData* data, const std::string &element)
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;
}
@@ -1940,11 +2082,25 @@ void GUIFormSpecMenu::parseBox(parserData* data, const std::string &element)
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;
@@ -2045,16 +2201,29 @@ void GUIFormSpecMenu::parseTooltip(parserData* data, const std::string &element)
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;
}
@@ -2460,11 +2629,27 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize)
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();
@@ -2472,18 +2657,14 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize)
/* 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();
@@ -2726,6 +2907,9 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize)
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;
@@ -2736,6 +2920,14 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize)
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
}
@@ -2751,30 +2943,31 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize)
// 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
@@ -2785,6 +2978,68 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize)
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__
@@ -2802,7 +3057,7 @@ bool GUIFormSpecMenu::getAndroidUIInput()
if (iter->fname != fieldname) {
continue;
}
- IGUIElement* tochange = getElementFromId(iter->fid);
+ IGUIElement *tochange = getElementFromId(iter->fid, true);
if (tochange == 0) {
return false;
@@ -2822,9 +3077,11 @@ bool GUIFormSpecMenu::getAndroidUIInput()
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;
@@ -2838,11 +3095,10 @@ GUIFormSpecMenu::ItemSpec GUIFormSpecMenu::getItemAtPos(v2s32 p) const
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);
- }
}
}
@@ -2855,23 +3111,25 @@ void GUIFormSpecMenu::drawList(const ListDrawSpec &s, int layer,
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;
@@ -2888,23 +3146,26 @@ void GUIFormSpecMenu::drawList(const ListDrawSpec &s, int layer,
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);
}
}
@@ -2917,16 +3178,16 @@ void GUIFormSpecMenu::drawList(const ListDrawSpec &s, int layer,
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) {
@@ -2936,8 +3197,7 @@ void GUIFormSpecMenu::drawList(const ListDrawSpec &s, int layer,
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());
@@ -2956,6 +3216,7 @@ void GUIFormSpecMenu::drawSelectedItem()
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);
@@ -2994,6 +3255,9 @@ void GUIFormSpecMenu::drawMenu()
video::IVideoDriver* driver = Environment->getVideoDriver();
+ /*
+ Draw background color
+ */
v2u32 screenSize = driver->getScreenSize();
core::rect<s32> allbg(0, 0, screenSize.X, screenSize.Y);
@@ -3002,10 +3266,14 @@ void GUIFormSpecMenu::drawMenu()
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);
@@ -3017,58 +3285,10 @@ void GUIFormSpecMenu::drawMenu()
/*
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);
}
/*
@@ -3077,64 +3297,6 @@ void GUIFormSpecMenu::drawMenu()
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
Layer 1: Item images; prepare tooltip
@@ -3146,6 +3308,7 @@ void GUIFormSpecMenu::drawMenu()
}
}
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);
@@ -3157,27 +3320,6 @@ void GUIFormSpecMenu::drawMenu()
#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
*/
gui::IGUIElement *hovered =
@@ -3407,10 +3549,14 @@ void GUIFormSpecMenu::acceptInput(FormspecQuitMode quitmode=quit_mode_no)
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) {
@@ -3424,8 +3570,8 @@ void GUIFormSpecMenu::acceptInput(FormspecQuitMode quitmode=quit_mode_no)
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);
}
@@ -3439,8 +3585,8 @@ void GUIFormSpecMenu::acceptInput(FormspecQuitMode quitmode=quit_mode_no)
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);
}
@@ -3455,13 +3601,12 @@ void GUIFormSpecMenu::acceptInput(FormspecQuitMode quitmode=quit_mode_no)
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")
@@ -3470,12 +3615,10 @@ void GUIFormSpecMenu::acceptInput(FormspecQuitMode quitmode=quit_mode_no)
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());
- }
}
}
}
@@ -4253,13 +4396,22 @@ bool GUIFormSpecMenu::OnEvent(const SEvent& event)
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
@@ -4268,9 +4420,8 @@ std::string GUIFormSpecMenu::getNameByID(s32 id)
std::wstring GUIFormSpecMenu::getLabelByID(s32 id)
{
for (FieldSpec &spec : m_fields) {
- if (spec.fid == id) {
+ if (spec.fid == id)
return spec.flabel;
- }
}
return L"";
}
diff --git a/src/gui/guiFormSpecMenu.h b/src/gui/guiFormSpecMenu.h
index 39af1e7c2..f15bba35a 100644
--- a/src/gui/guiFormSpecMenu.h
+++ b/src/gui/guiFormSpecMenu.h
@@ -36,6 +36,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
class InventoryManager;
class ISimpleTextureSource;
class Client;
+class GUIScrollBar;
typedef enum {
f_Button,
@@ -44,6 +45,8 @@ typedef enum {
f_CheckBox,
f_DropDown,
f_ScrollBar,
+ f_Box,
+ f_ItemImage,
f_Unknown
} FormspecFieldType;
@@ -101,11 +104,11 @@ class GUIFormSpecMenu : public GUIModalMenu
ListDrawSpec(const InventoryLocation &a_inventoryloc,
const std::string &a_listname,
- v2s32 a_pos, v2s32 a_geom, s32 a_start_item_i,
+ IGUIElement *elem, v2s32 a_geom, s32 a_start_item_i,
bool a_real_coordinates):
inventoryloc(a_inventoryloc),
listname(a_listname),
- pos(a_pos),
+ e(elem),
geom(a_geom),
start_item_i(a_start_item_i),
real_coordinates(a_real_coordinates)
@@ -114,7 +117,7 @@ class GUIFormSpecMenu : public GUIModalMenu
InventoryLocation inventoryloc;
std::string listname;
- v2s32 pos;
+ IGUIElement *e;
v2s32 geom;
s32 start_item_i;
bool real_coordinates;
@@ -135,84 +138,6 @@ class GUIFormSpecMenu : public GUIModalMenu
std::string listname;
};
- struct ImageDrawSpec
- {
- ImageDrawSpec():
- parent_button(NULL),
- clip(false)
- {
- }
-
- ImageDrawSpec(const std::string &a_name,
- const std::string &a_item_name,
- gui::IGUIButton *a_parent_button,
- const v2s32 &a_pos, const v2s32 &a_geom):
- name(a_name),
- item_name(a_item_name),
- parent_button(a_parent_button),
- pos(a_pos),
- geom(a_geom),
- scale(true),
- clip(false)
- {
- }
-
- ImageDrawSpec(const std::string &a_name,
- const std::string &a_item_name,
- const v2s32 &a_pos, const v2s32 &a_geom):
- name(a_name),
- item_name(a_item_name),
- parent_button(NULL),
- pos(a_pos),
- geom(a_geom),
- scale(true),
- clip(false)
- {
- }
-
- ImageDrawSpec(const std::string &a_name,
- const v2s32 &a_pos, const v2s32 &a_geom, bool clip=false):
- name(a_name),
- parent_button(NULL),
- pos(a_pos),
- geom(a_geom),
- scale(true),
- clip(clip)
- {
- }
-
- ImageDrawSpec(const std::string &a_name,
- const v2s32 &a_pos, const v2s32 &a_geom, const core::rect<s32> &middle, bool clip=false):
- name(a_name),
- parent_button(NULL),
- pos(a_pos),
- geom(a_geom),
- middle(middle),
- scale(true),
- clip(clip)
- {
- }
-
- ImageDrawSpec(const std::string &a_name,
- const v2s32 &a_pos):
- name(a_name),
- parent_button(NULL),
- pos(a_pos),
- scale(false),
- clip(false)
- {
- }
-
- std::string name;
- std::string item_name;
- gui::IGUIButton *parent_button;
- v2s32 pos;
- v2s32 geom;
- core::rect<s32> middle;
- bool scale;
- bool clip;
- };
-
struct FieldSpec
{
FieldSpec() = default;
@@ -239,19 +164,6 @@ class GUIFormSpecMenu : public GUIModalMenu
core::rect<s32> rect;
};
- struct BoxDrawSpec
- {
- BoxDrawSpec(v2s32 a_pos, v2s32 a_geom, irr::video::SColor a_color):
- pos(a_pos),
- geom(a_geom),
- color(a_color)
- {
- }
- v2s32 pos;
- v2s32 geom;
- irr::video::SColor color;
- };
-
struct TooltipSpec
{
TooltipSpec() = default;
@@ -397,10 +309,9 @@ protected:
}
std::wstring getLabelByID(s32 id);
std::string getNameByID(s32 id);
- v2s32 getElementBasePos(bool absolute,
- const std::vector<std::string> *v_pos);
- v2s32 getRealCoordinateBasePos(bool absolute,
- const std::vector<std::string> &v_pos);
+ FormspecFieldType getTypeByID(s32 id);
+ v2s32 getElementBasePos(const std::vector<std::string> *v_pos);
+ v2s32 getRealCoordinateBasePos(const std::vector<std::string> &v_pos);
v2s32 getRealCoordinateGeometry(const std::vector<std::string> &v_geom);
std::unordered_map<std::string, StyleSpec> theme_by_type;
@@ -427,19 +338,15 @@ protected:
std::vector<ListDrawSpec> m_inventorylists;
std::vector<ListRingSpec> m_inventory_rings;
- std::vector<ImageDrawSpec> m_backgrounds;
- std::vector<ImageDrawSpec> m_images;
- std::vector<ImageDrawSpec> m_itemimages;
- std::vector<BoxDrawSpec> m_boxes;
+ std::vector<gui::IGUIElement *> m_backgrounds;
std::unordered_map<std::string, bool> field_close_on_enter;
std::vector<FieldSpec> m_fields;
- std::vector<StaticTextSpec> m_static_texts;
- std::vector<std::pair<FieldSpec,GUITable*> > m_tables;
- std::vector<std::pair<FieldSpec,gui::IGUICheckBox*> > m_checkboxes;
+ std::vector<std::pair<FieldSpec, GUITable *>> m_tables;
+ std::vector<std::pair<FieldSpec, gui::IGUICheckBox *>> m_checkboxes;
std::map<std::string, TooltipSpec> m_tooltips;
- std::vector<std::pair<irr::core::rect<s32>, TooltipSpec>> m_tooltip_rects;
- std::vector<std::pair<FieldSpec,gui::IGUIScrollBar*> > m_scrollbars;
- std::vector<std::pair<FieldSpec, std::vector<std::string> > > m_dropdowns;
+ std::vector<std::pair<gui::IGUIElement *, TooltipSpec>> m_tooltip_rects;
+ std::vector<std::pair<FieldSpec, GUIScrollBar *>> m_scrollbars;
+ std::vector<std::pair<FieldSpec, std::vector<std::string>>> m_dropdowns;
ItemSpec *m_selected_item = nullptr;
u16 m_selected_amount = 0;
@@ -480,6 +387,7 @@ private:
typedef struct {
bool explicit_size;
bool real_coordinates;
+ u8 simple_field_count;
v2f invsize;
v2s32 size;
v2f32 offset;
@@ -556,6 +464,13 @@ private:
const irr::video::SColor &bgcolor);
/**
+ * In formspec version < 2 the elements were not ordered properly. Some element
+ * types were drawn before others.
+ * This function sorts the elements in the old order for backwards compatibility.
+ */
+ void legacySortElements(core::list<IGUIElement *>::Iterator from);
+
+ /**
* check if event is part of a double click
* @param event event to evaluate
* @return true/false if a doubleclick was detected
diff --git a/src/gui/guiItemImage.cpp b/src/gui/guiItemImage.cpp
new file mode 100644
index 000000000..799a60c66
--- /dev/null
+++ b/src/gui/guiItemImage.cpp
@@ -0,0 +1,64 @@
+/*
+Minetest
+Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 2.1 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License along
+with this program; if not, write to the Free Software Foundation, Inc.,
+51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+#include "guiItemImage.h"
+#include "client/client.h"
+
+GUIItemImage::GUIItemImage(gui::IGUIEnvironment *env, gui::IGUIElement *parent,
+ s32 id, const core::rect<s32> &rectangle, const std::string &item_name,
+ gui::IGUIFont *font, Client *client) :
+ gui::IGUIElement(gui::EGUIET_ELEMENT, env, parent, id, rectangle),
+ m_item_name(item_name), m_font(font), m_client(client), m_label(core::stringw())
+{
+}
+
+void GUIItemImage::draw()
+{
+ if (!IsVisible)
+ return;
+
+ if (!m_client) {
+ IGUIElement::draw();
+ return;
+ }
+
+ IItemDefManager *idef = m_client->idef();
+ ItemStack item;
+ item.deSerialize(m_item_name, idef);
+ // Viewport rectangle on screen
+ core::rect<s32> rect = core::rect<s32>(AbsoluteRect);
+ if (Parent->getType() == gui::EGUIET_BUTTON &&
+ ((irr::gui::IGUIButton *)Parent)->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
+ gui::IGUISkin *skin = Environment->getSkin();
+ 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(Environment->getVideoDriver(), m_font, item, rect,
+ &AbsoluteClippingRect, m_client, IT_ROT_NONE);
+ video::SColor color(255, 255, 255, 255);
+ m_font->draw(m_label, rect, color, true, true, &AbsoluteClippingRect);
+
+ IGUIElement::draw();
+}
diff --git a/src/gui/guiItemImage.h b/src/gui/guiItemImage.h
new file mode 100644
index 000000000..6fede6564
--- /dev/null
+++ b/src/gui/guiItemImage.h
@@ -0,0 +1,46 @@
+/*
+Minetest
+Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU Lesser General Public License as published by
+the Free Software Foundation; either version 2.1 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License along
+with this program; if not, write to the Free Software Foundation, Inc.,
+51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+*/
+
+#pragma once
+
+#include "irrlichttypes_extrabloated.h"
+#include "util/string.h"
+
+class Client;
+
+class GUIItemImage : public gui::IGUIElement
+{
+public:
+ GUIItemImage(gui::IGUIEnvironment *env, gui::IGUIElement *parent, s32 id,
+ const core::rect<s32> &rectangle, const std::string &item_name,
+ gui::IGUIFont *font, Client *client);
+
+ virtual void draw() override;
+
+ virtual void setText(const wchar_t *text) override
+ {
+ m_label = text;
+ }
+
+private:
+ std::string m_item_name;
+ gui::IGUIFont *m_font;
+ Client *m_client;
+ core::stringw m_label;
+};
diff --git a/src/network/networkprotocol.h b/src/network/networkprotocol.h
index 5a13c1353..236c7892e 100644
--- a/src/network/networkprotocol.h
+++ b/src/network/networkprotocol.h
@@ -228,9 +228,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
(too much)
FORMSPEC VERSION 2:
Forced real coordinates
- background[]: 9-slice scaling parameters
+ background9[]: 9-slice scaling parameters
+ FORMSPEC VERSION 3:
+ Formspec elements are drawn in the order of definition
*/
-#define FORMSPEC_API_VERSION 2
+#define FORMSPEC_API_VERSION 3
#define TEXTURENAME_ALLOWED_CHARS "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_.-"