Skip to content

Commit 5506e97

Browse files
DesourSmallJoker
authored andcommittedNov 7, 2019
Formspec: draw order and clipping for all elements (#8740)
1 parent 15a030e commit 5506e97

14 files changed

+824
-454
lines changed
 

Diff for: ‎build/android/jni/Android.mk

+3
Original file line numberDiff line numberDiff line change
@@ -178,12 +178,15 @@ LOCAL_SRC_FILES := \
178178
jni/src/filesys.cpp \
179179
jni/src/genericobject.cpp \
180180
jni/src/gettext.cpp \
181+
jni/src/gui/guiBackgroundImage.cpp \
182+
jni/src/gui/guiBox.cpp \
181183
jni/src/gui/guiButton.cpp \
182184
jni/src/gui/guiChatConsole.cpp \
183185
jni/src/gui/guiConfirmRegistration.cpp \
184186
jni/src/gui/guiEditBoxWithScrollbar.cpp \
185187
jni/src/gui/guiEngine.cpp \
186188
jni/src/gui/guiFormSpecMenu.cpp \
189+
jni/src/gui/guiItemImage.cpp \
187190
jni/src/gui/guiKeyChangeMenu.cpp \
188191
jni/src/gui/guiPasswordChange.cpp \
189192
jni/src/gui/guiPathSelectMenu.cpp \

Diff for: ‎doc/lua_api.txt

+7
Original file line numberDiff line numberDiff line change
@@ -1923,6 +1923,11 @@ When displaying text which can contain formspec code, e.g. text set by a player,
19231923
use `minetest.formspec_escape`.
19241924
For coloured text you can use `minetest.colorize`.
19251925

1926+
Since formspec version 3, elements drawn in the order they are defined. All
1927+
background elements are drawn before all other elements.
1928+
`list` elements are an exception here. They are drawn last. This, however, might
1929+
be changed at any time.
1930+
19261931
**WARNING**: do _not_ use a element name starting with `key_`; those names are
19271932
reserved to pass key press events to formspec!
19281933

@@ -2032,13 +2037,15 @@ Elements
20322037
be shown if the inventory list is of size 0.
20332038
* **Note**: With the new coordinate system, the spacing between inventory
20342039
slots is one-fourth the size of an inventory slot.
2040+
* **Note**: Lists are drawn after every other element. This might change at any time.
20352041

20362042
### `list[<inventory location>;<list name>;<X>,<Y>;<W>,<H>;<starting item index>]`
20372043

20382044
* Show an inventory list if it has been sent to the client. Nothing will
20392045
be shown if the inventory list is of size 0.
20402046
* **Note**: With the new coordinate system, the spacing between inventory
20412047
slots is one-fourth the size of an inventory slot.
2048+
* **Note**: Lists are drawn after every other element. This might change at any time.
20422049

20432050
### `listring[<inventory location>;<list name>]`
20442051

Diff for: ‎src/client/guiscalingfilter.cpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,8 @@ void draw2DImageFilterScaled(video::IVideoDriver *driver, video::ITexture *txr,
171171
}
172172

173173
void draw2DImage9Slice(video::IVideoDriver *driver, video::ITexture *texture,
174-
const core::rect<s32> &rect, const core::rect<s32> &middle)
174+
const core::rect<s32> &rect, const core::rect<s32> &middle,
175+
const core::rect<s32> *cliprect)
175176
{
176177
const video::SColor color(255,255,255,255);
177178
const video::SColor colors[] = {color,color,color,color};
@@ -222,9 +223,7 @@ void draw2DImage9Slice(video::IVideoDriver *driver, video::ITexture *texture,
222223
break;
223224
}
224225

225-
draw2DImageFilterScaled(driver, texture, dest,
226-
src,
227-
NULL/*&AbsoluteClippingRect*/, colors, true);
226+
draw2DImageFilterScaled(driver, texture, dest, src, cliprect, colors, true);
228227
}
229228
}
230229
}

Diff for: ‎src/client/guiscalingfilter.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,5 @@ void draw2DImageFilterScaled(video::IVideoDriver *driver, video::ITexture *txr,
5353
* 9-slice / segment drawing
5454
*/
5555
void draw2DImage9Slice(video::IVideoDriver *driver, video::ITexture *texture,
56-
const core::rect<s32> &rect, const core::rect<s32> &middle);
56+
const core::rect<s32> &rect, const core::rect<s32> &middle,
57+
const core::rect<s32> *cliprect = nullptr);

Diff for: ‎src/gui/CMakeLists.txt

+3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
set(gui_SRCS
2+
${CMAKE_CURRENT_SOURCE_DIR}/guiBackgroundImage.cpp
3+
${CMAKE_CURRENT_SOURCE_DIR}/guiBox.cpp
24
${CMAKE_CURRENT_SOURCE_DIR}/guiButton.cpp
35
${CMAKE_CURRENT_SOURCE_DIR}/guiChatConsole.cpp
46
${CMAKE_CURRENT_SOURCE_DIR}/guiConfirmRegistration.cpp
57
${CMAKE_CURRENT_SOURCE_DIR}/guiEditBoxWithScrollbar.cpp
68
${CMAKE_CURRENT_SOURCE_DIR}/guiEngine.cpp
79
${CMAKE_CURRENT_SOURCE_DIR}/guiFormSpecMenu.cpp
10+
${CMAKE_CURRENT_SOURCE_DIR}/guiItemImage.cpp
811
${CMAKE_CURRENT_SOURCE_DIR}/guiKeyChangeMenu.cpp
912
${CMAKE_CURRENT_SOURCE_DIR}/guiPasswordChange.cpp
1013
${CMAKE_CURRENT_SOURCE_DIR}/guiPathSelectMenu.cpp

Diff for: ‎src/gui/guiBackgroundImage.cpp

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
Part of Minetest
3+
Copyright (C) 2013 RealBadAngel, Maciej Kasatkin <mk@realbadangel.pl>
4+
5+
Permission to use, copy, modify, and distribute this software for any
6+
purpose with or without fee is hereby granted, provided that the above
7+
copyright notice and this permission notice appear in all copies.
8+
9+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16+
*/
17+
18+
#include "guiBackgroundImage.h"
19+
#include "client/guiscalingfilter.h"
20+
#include "log.h"
21+
22+
GUIBackgroundImage::GUIBackgroundImage(gui::IGUIEnvironment *env,
23+
gui::IGUIElement *parent, s32 id, const core::rect<s32> &rectangle,
24+
const std::string &name, const core::rect<s32> &middle,
25+
ISimpleTextureSource *tsrc, bool autoclip) :
26+
gui::IGUIElement(gui::EGUIET_ELEMENT, env, parent, id, rectangle),
27+
m_name(name), m_middle(middle), m_tsrc(tsrc), m_autoclip(autoclip)
28+
{
29+
}
30+
31+
void GUIBackgroundImage::draw()
32+
{
33+
if (!IsVisible)
34+
return;
35+
36+
video::ITexture *texture = m_tsrc->getTexture(m_name);
37+
38+
if (!texture) {
39+
errorstream << "GUIBackgroundImage::draw() Unable to load texture:"
40+
<< std::endl;
41+
errorstream << "\t" << m_name << std::endl;
42+
return;
43+
}
44+
45+
core::rect<s32> rect = AbsoluteRect;
46+
if (m_autoclip)
47+
rect.LowerRightCorner += Parent->getAbsolutePosition().getSize();
48+
49+
video::IVideoDriver *driver = Environment->getVideoDriver();
50+
51+
if (m_middle.getArea() == 0) {
52+
const video::SColor color(255, 255, 255, 255);
53+
const video::SColor colors[] = {color, color, color, color};
54+
draw2DImageFilterScaled(driver, texture, rect,
55+
core::rect<s32>(core::position2d<s32>(0, 0),
56+
core::dimension2di(texture->getOriginalSize())),
57+
nullptr, colors, true);
58+
} else {
59+
core::rect<s32> middle = m_middle;
60+
// `-x` is interpreted as `w - x`
61+
if (middle.LowerRightCorner.X < 0)
62+
middle.LowerRightCorner.X += texture->getOriginalSize().Width;
63+
if (middle.LowerRightCorner.Y < 0)
64+
middle.LowerRightCorner.Y += texture->getOriginalSize().Height;
65+
draw2DImage9Slice(driver, texture, rect, middle);
66+
}
67+
68+
IGUIElement::draw();
69+
}

Diff for: ‎src/gui/guiBackgroundImage.h

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
Part of Minetest
3+
Copyright (C) 2013 RealBadAngel, Maciej Kasatkin <mk@realbadangel.pl>
4+
5+
Permission to use, copy, modify, and distribute this software for any
6+
purpose with or without fee is hereby granted, provided that the above
7+
copyright notice and this permission notice appear in all copies.
8+
9+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16+
*/
17+
18+
#pragma once
19+
20+
#include "irrlichttypes_extrabloated.h"
21+
#include "util/string.h"
22+
#include "client/tile.h" // ITextureSource
23+
24+
class GUIBackgroundImage : public gui::IGUIElement
25+
{
26+
public:
27+
GUIBackgroundImage(gui::IGUIEnvironment *env, gui::IGUIElement *parent, s32 id,
28+
const core::rect<s32> &rectangle, const std::string &name,
29+
const core::rect<s32> &middle, ISimpleTextureSource *tsrc, bool autoclip);
30+
31+
virtual void draw() override;
32+
33+
private:
34+
std::string m_name;
35+
core::rect<s32> m_middle;
36+
ISimpleTextureSource *m_tsrc;
37+
bool m_autoclip;
38+
};

Diff for: ‎src/gui/guiBox.cpp

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
Minetest
3+
Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4+
5+
This program is free software; you can redistribute it and/or modify
6+
it under the terms of the GNU Lesser General Public License as published by
7+
the Free Software Foundation; either version 2.1 of the License, or
8+
(at your option) any later version.
9+
10+
This program is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU Lesser General Public License for more details.
14+
15+
You should have received a copy of the GNU Lesser General Public License along
16+
with this program; if not, write to the Free Software Foundation, Inc.,
17+
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*/
19+
20+
#include "guiBox.h"
21+
22+
GUIBox::GUIBox(gui::IGUIEnvironment *env, gui::IGUIElement *parent, s32 id,
23+
const core::rect<s32> &rectangle, const video::SColor &color) :
24+
gui::IGUIElement(gui::EGUIET_ELEMENT, env, parent, id, rectangle),
25+
m_color(color)
26+
{
27+
}
28+
29+
void GUIBox::draw()
30+
{
31+
if (!IsVisible)
32+
return;
33+
34+
Environment->getVideoDriver()->draw2DRectangle(m_color, AbsoluteRect,
35+
&AbsoluteClippingRect);
36+
37+
IGUIElement::draw();
38+
}

Diff for: ‎src/gui/guiBox.h

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
Minetest
3+
Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4+
5+
This program is free software; you can redistribute it and/or modify
6+
it under the terms of the GNU Lesser General Public License as published by
7+
the Free Software Foundation; either version 2.1 of the License, or
8+
(at your option) any later version.
9+
10+
This program is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU Lesser General Public License for more details.
14+
15+
You should have received a copy of the GNU Lesser General Public License along
16+
with this program; if not, write to the Free Software Foundation, Inc.,
17+
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*/
19+
20+
#pragma once
21+
22+
#include "irrlichttypes_extrabloated.h"
23+
24+
class GUIBox : public gui::IGUIElement
25+
{
26+
public:
27+
GUIBox(gui::IGUIEnvironment *env, gui::IGUIElement *parent, s32 id,
28+
const core::rect<s32> &rectangle, const video::SColor &color);
29+
30+
virtual void draw() override;
31+
32+
private:
33+
video::SColor m_color;
34+
};

Diff for: ‎src/gui/guiFormSpecMenu.cpp

+490-339
Large diffs are not rendered by default.

Diff for: ‎src/gui/guiFormSpecMenu.h

+23-108
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
3636
class InventoryManager;
3737
class ISimpleTextureSource;
3838
class Client;
39+
class GUIScrollBar;
3940

4041
typedef enum {
4142
f_Button,
@@ -44,6 +45,8 @@ typedef enum {
4445
f_CheckBox,
4546
f_DropDown,
4647
f_ScrollBar,
48+
f_Box,
49+
f_ItemImage,
4750
f_Unknown
4851
} FormspecFieldType;
4952

@@ -101,11 +104,11 @@ class GUIFormSpecMenu : public GUIModalMenu
101104

102105
ListDrawSpec(const InventoryLocation &a_inventoryloc,
103106
const std::string &a_listname,
104-
v2s32 a_pos, v2s32 a_geom, s32 a_start_item_i,
107+
IGUIElement *elem, v2s32 a_geom, s32 a_start_item_i,
105108
bool a_real_coordinates):
106109
inventoryloc(a_inventoryloc),
107110
listname(a_listname),
108-
pos(a_pos),
111+
e(elem),
109112
geom(a_geom),
110113
start_item_i(a_start_item_i),
111114
real_coordinates(a_real_coordinates)
@@ -114,7 +117,7 @@ class GUIFormSpecMenu : public GUIModalMenu
114117

115118
InventoryLocation inventoryloc;
116119
std::string listname;
117-
v2s32 pos;
120+
IGUIElement *e;
118121
v2s32 geom;
119122
s32 start_item_i;
120123
bool real_coordinates;
@@ -135,84 +138,6 @@ class GUIFormSpecMenu : public GUIModalMenu
135138
std::string listname;
136139
};
137140

138-
struct ImageDrawSpec
139-
{
140-
ImageDrawSpec():
141-
parent_button(NULL),
142-
clip(false)
143-
{
144-
}
145-
146-
ImageDrawSpec(const std::string &a_name,
147-
const std::string &a_item_name,
148-
gui::IGUIButton *a_parent_button,
149-
const v2s32 &a_pos, const v2s32 &a_geom):
150-
name(a_name),
151-
item_name(a_item_name),
152-
parent_button(a_parent_button),
153-
pos(a_pos),
154-
geom(a_geom),
155-
scale(true),
156-
clip(false)
157-
{
158-
}
159-
160-
ImageDrawSpec(const std::string &a_name,
161-
const std::string &a_item_name,
162-
const v2s32 &a_pos, const v2s32 &a_geom):
163-
name(a_name),
164-
item_name(a_item_name),
165-
parent_button(NULL),
166-
pos(a_pos),
167-
geom(a_geom),
168-
scale(true),
169-
clip(false)
170-
{
171-
}
172-
173-
ImageDrawSpec(const std::string &a_name,
174-
const v2s32 &a_pos, const v2s32 &a_geom, bool clip=false):
175-
name(a_name),
176-
parent_button(NULL),
177-
pos(a_pos),
178-
geom(a_geom),
179-
scale(true),
180-
clip(clip)
181-
{
182-
}
183-
184-
ImageDrawSpec(const std::string &a_name,
185-
const v2s32 &a_pos, const v2s32 &a_geom, const core::rect<s32> &middle, bool clip=false):
186-
name(a_name),
187-
parent_button(NULL),
188-
pos(a_pos),
189-
geom(a_geom),
190-
middle(middle),
191-
scale(true),
192-
clip(clip)
193-
{
194-
}
195-
196-
ImageDrawSpec(const std::string &a_name,
197-
const v2s32 &a_pos):
198-
name(a_name),
199-
parent_button(NULL),
200-
pos(a_pos),
201-
scale(false),
202-
clip(false)
203-
{
204-
}
205-
206-
std::string name;
207-
std::string item_name;
208-
gui::IGUIButton *parent_button;
209-
v2s32 pos;
210-
v2s32 geom;
211-
core::rect<s32> middle;
212-
bool scale;
213-
bool clip;
214-
};
215-
216141
struct FieldSpec
217142
{
218143
FieldSpec() = default;
@@ -239,19 +164,6 @@ class GUIFormSpecMenu : public GUIModalMenu
239164
core::rect<s32> rect;
240165
};
241166

242-
struct BoxDrawSpec
243-
{
244-
BoxDrawSpec(v2s32 a_pos, v2s32 a_geom, irr::video::SColor a_color):
245-
pos(a_pos),
246-
geom(a_geom),
247-
color(a_color)
248-
{
249-
}
250-
v2s32 pos;
251-
v2s32 geom;
252-
irr::video::SColor color;
253-
};
254-
255167
struct TooltipSpec
256168
{
257169
TooltipSpec() = default;
@@ -397,10 +309,9 @@ class GUIFormSpecMenu : public GUIModalMenu
397309
}
398310
std::wstring getLabelByID(s32 id);
399311
std::string getNameByID(s32 id);
400-
v2s32 getElementBasePos(bool absolute,
401-
const std::vector<std::string> *v_pos);
402-
v2s32 getRealCoordinateBasePos(bool absolute,
403-
const std::vector<std::string> &v_pos);
312+
FormspecFieldType getTypeByID(s32 id);
313+
v2s32 getElementBasePos(const std::vector<std::string> *v_pos);
314+
v2s32 getRealCoordinateBasePos(const std::vector<std::string> &v_pos);
404315
v2s32 getRealCoordinateGeometry(const std::vector<std::string> &v_geom);
405316

406317
std::unordered_map<std::string, StyleSpec> theme_by_type;
@@ -427,19 +338,15 @@ class GUIFormSpecMenu : public GUIModalMenu
427338

428339
std::vector<ListDrawSpec> m_inventorylists;
429340
std::vector<ListRingSpec> m_inventory_rings;
430-
std::vector<ImageDrawSpec> m_backgrounds;
431-
std::vector<ImageDrawSpec> m_images;
432-
std::vector<ImageDrawSpec> m_itemimages;
433-
std::vector<BoxDrawSpec> m_boxes;
341+
std::vector<gui::IGUIElement *> m_backgrounds;
434342
std::unordered_map<std::string, bool> field_close_on_enter;
435343
std::vector<FieldSpec> m_fields;
436-
std::vector<StaticTextSpec> m_static_texts;
437-
std::vector<std::pair<FieldSpec,GUITable*> > m_tables;
438-
std::vector<std::pair<FieldSpec,gui::IGUICheckBox*> > m_checkboxes;
344+
std::vector<std::pair<FieldSpec, GUITable *>> m_tables;
345+
std::vector<std::pair<FieldSpec, gui::IGUICheckBox *>> m_checkboxes;
439346
std::map<std::string, TooltipSpec> m_tooltips;
440-
std::vector<std::pair<irr::core::rect<s32>, TooltipSpec>> m_tooltip_rects;
441-
std::vector<std::pair<FieldSpec,gui::IGUIScrollBar*> > m_scrollbars;
442-
std::vector<std::pair<FieldSpec, std::vector<std::string> > > m_dropdowns;
347+
std::vector<std::pair<gui::IGUIElement *, TooltipSpec>> m_tooltip_rects;
348+
std::vector<std::pair<FieldSpec, GUIScrollBar *>> m_scrollbars;
349+
std::vector<std::pair<FieldSpec, std::vector<std::string>>> m_dropdowns;
443350

444351
ItemSpec *m_selected_item = nullptr;
445352
u16 m_selected_amount = 0;
@@ -480,6 +387,7 @@ class GUIFormSpecMenu : public GUIModalMenu
480387
typedef struct {
481388
bool explicit_size;
482389
bool real_coordinates;
390+
u8 simple_field_count;
483391
v2f invsize;
484392
v2s32 size;
485393
v2f32 offset;
@@ -555,6 +463,13 @@ class GUIFormSpecMenu : public GUIModalMenu
555463
void showTooltip(const std::wstring &text, const irr::video::SColor &color,
556464
const irr::video::SColor &bgcolor);
557465

466+
/**
467+
* In formspec version < 2 the elements were not ordered properly. Some element
468+
* types were drawn before others.
469+
* This function sorts the elements in the old order for backwards compatibility.
470+
*/
471+
void legacySortElements(core::list<IGUIElement *>::Iterator from);
472+
558473
/**
559474
* check if event is part of a double click
560475
* @param event event to evaluate

Diff for: ‎src/gui/guiItemImage.cpp

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
Minetest
3+
Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4+
5+
This program is free software; you can redistribute it and/or modify
6+
it under the terms of the GNU Lesser General Public License as published by
7+
the Free Software Foundation; either version 2.1 of the License, or
8+
(at your option) any later version.
9+
10+
This program is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU Lesser General Public License for more details.
14+
15+
You should have received a copy of the GNU Lesser General Public License along
16+
with this program; if not, write to the Free Software Foundation, Inc.,
17+
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*/
19+
20+
#include "guiItemImage.h"
21+
#include "client/client.h"
22+
23+
GUIItemImage::GUIItemImage(gui::IGUIEnvironment *env, gui::IGUIElement *parent,
24+
s32 id, const core::rect<s32> &rectangle, const std::string &item_name,
25+
gui::IGUIFont *font, Client *client) :
26+
gui::IGUIElement(gui::EGUIET_ELEMENT, env, parent, id, rectangle),
27+
m_item_name(item_name), m_font(font), m_client(client), m_label(core::stringw())
28+
{
29+
}
30+
31+
void GUIItemImage::draw()
32+
{
33+
if (!IsVisible)
34+
return;
35+
36+
if (!m_client) {
37+
IGUIElement::draw();
38+
return;
39+
}
40+
41+
IItemDefManager *idef = m_client->idef();
42+
ItemStack item;
43+
item.deSerialize(m_item_name, idef);
44+
// Viewport rectangle on screen
45+
core::rect<s32> rect = core::rect<s32>(AbsoluteRect);
46+
if (Parent->getType() == gui::EGUIET_BUTTON &&
47+
((irr::gui::IGUIButton *)Parent)->isPressed()) {
48+
#if (IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR < 8)
49+
rect += core::dimension2d<s32>(0.05 * (float)rect.getWidth(),
50+
0.05 * (float)rect.getHeight());
51+
#else
52+
gui::IGUISkin *skin = Environment->getSkin();
53+
rect += core::dimension2d<s32>(
54+
skin->getSize(irr::gui::EGDS_BUTTON_PRESSED_IMAGE_OFFSET_X),
55+
skin->getSize(irr::gui::EGDS_BUTTON_PRESSED_IMAGE_OFFSET_Y));
56+
#endif
57+
}
58+
drawItemStack(Environment->getVideoDriver(), m_font, item, rect,
59+
&AbsoluteClippingRect, m_client, IT_ROT_NONE);
60+
video::SColor color(255, 255, 255, 255);
61+
m_font->draw(m_label, rect, color, true, true, &AbsoluteClippingRect);
62+
63+
IGUIElement::draw();
64+
}

Diff for: ‎src/gui/guiItemImage.h

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
Minetest
3+
Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4+
5+
This program is free software; you can redistribute it and/or modify
6+
it under the terms of the GNU Lesser General Public License as published by
7+
the Free Software Foundation; either version 2.1 of the License, or
8+
(at your option) any later version.
9+
10+
This program is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU Lesser General Public License for more details.
14+
15+
You should have received a copy of the GNU Lesser General Public License along
16+
with this program; if not, write to the Free Software Foundation, Inc.,
17+
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*/
19+
20+
#pragma once
21+
22+
#include "irrlichttypes_extrabloated.h"
23+
#include "util/string.h"
24+
25+
class Client;
26+
27+
class GUIItemImage : public gui::IGUIElement
28+
{
29+
public:
30+
GUIItemImage(gui::IGUIEnvironment *env, gui::IGUIElement *parent, s32 id,
31+
const core::rect<s32> &rectangle, const std::string &item_name,
32+
gui::IGUIFont *font, Client *client);
33+
34+
virtual void draw() override;
35+
36+
virtual void setText(const wchar_t *text) override
37+
{
38+
m_label = text;
39+
}
40+
41+
private:
42+
std::string m_item_name;
43+
gui::IGUIFont *m_font;
44+
Client *m_client;
45+
core::stringw m_label;
46+
};

Diff for: ‎src/network/networkprotocol.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
228228
(too much)
229229
FORMSPEC VERSION 2:
230230
Forced real coordinates
231-
background[]: 9-slice scaling parameters
231+
background9[]: 9-slice scaling parameters
232+
FORMSPEC VERSION 3:
233+
Formspec elements are drawn in the order of definition
232234
*/
233-
#define FORMSPEC_API_VERSION 2
235+
#define FORMSPEC_API_VERSION 3
234236

235237
#define TEXTURENAME_ALLOWED_CHARS "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_.-"
236238

0 commit comments

Comments
 (0)
Please sign in to comment.