Skip to content

Commit d7825bc

Browse files
authoredMar 31, 2020
Fix GUI element click-through by changing visibility (#9534)
This adds a vector that holds pointers to elements that should only be visible while being drawn. In the guifsmenu's draw func, all elements in this vector are made visible and invisible again. Apart from there, they are always invisible. (Well they are still visible before the first drawn, does this matter? If yes, it could be fixed easily with some lines of code everywhere.)
1 parent 9953145 commit d7825bc

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed
 

‎src/gui/guiFormSpecMenu.cpp

+29-1
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ GUIFormSpecMenu::~GUIFormSpecMenu()
141141
background_it->drop();
142142
for (auto &tooltip_rect_it : m_tooltip_rects)
143143
tooltip_rect_it.first->drop();
144+
for (auto &clickthrough_it : m_clickthrough_elements)
145+
clickthrough_it->drop();
144146

145147
delete m_selected_item;
146148
delete m_form_src;
@@ -742,6 +744,9 @@ void GUIFormSpecMenu::parseImage(parserData* data, const std::string &element)
742744
e->setNotClipped(style.getBool(StyleSpec::NOCLIP, m_formspec_version < 3));
743745
m_fields.push_back(spec);
744746

747+
// images should let events through
748+
e->grab();
749+
m_clickthrough_elements.push_back(e);
745750
return;
746751
}
747752

@@ -775,6 +780,9 @@ void GUIFormSpecMenu::parseImage(parserData* data, const std::string &element)
775780
e->setNotClipped(style.getBool(StyleSpec::NOCLIP, m_formspec_version < 3));
776781
m_fields.push_back(spec);
777782

783+
// images should let events through
784+
e->grab();
785+
m_clickthrough_elements.push_back(e);
778786
return;
779787
}
780788
errorstream<< "Invalid image element(" << parts.size() << "): '" << element << "'" << std::endl;
@@ -882,7 +890,9 @@ void GUIFormSpecMenu::parseItemImage(parserData* data, const std::string &elemen
882890
core::rect<s32>(pos, pos + geom), name, m_font, m_client);
883891
auto style = getStyleForElement("item_image", spec.fname);
884892
e->setNotClipped(style.getBool(StyleSpec::NOCLIP, false));
885-
e->drop();
893+
894+
// item images should let events through
895+
m_clickthrough_elements.push_back(e);
886896

887897
m_fields.push_back(spec);
888898
return;
@@ -1747,6 +1757,10 @@ void GUIFormSpecMenu::parseLabel(parserData* data, const std::string &element)
17471757
e->setOverrideColor(style.getColor(StyleSpec::TEXTCOLOR, video::SColor(0xFFFFFFFF)));
17481758

17491759
m_fields.push_back(spec);
1760+
1761+
// labels should let events through
1762+
e->grab();
1763+
m_clickthrough_elements.push_back(e);
17501764
}
17511765

17521766
return;
@@ -1823,6 +1837,10 @@ void GUIFormSpecMenu::parseVertLabel(parserData* data, const std::string &elemen
18231837
e->setOverrideColor(style.getColor(StyleSpec::TEXTCOLOR, video::SColor(0xFFFFFFFF)));
18241838

18251839
m_fields.push_back(spec);
1840+
1841+
// vertlabels should let events through
1842+
e->grab();
1843+
m_clickthrough_elements.push_back(e);
18261844
return;
18271845
}
18281846
errorstream<< "Invalid vertlabel element(" << parts.size() << "): '" << element << "'" << std::endl;
@@ -2745,6 +2763,8 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize)
27452763
background_it->drop();
27462764
for (auto &tooltip_rect_it : m_tooltip_rects)
27472765
tooltip_rect_it.first->drop();
2766+
for (auto &clickthrough_it : m_clickthrough_elements)
2767+
clickthrough_it->drop();
27482768

27492769
mydata.size= v2s32(100,100);
27502770
mydata.screensize = screensize;
@@ -2767,6 +2787,7 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize)
27672787
m_dropdowns.clear();
27682788
theme_by_name.clear();
27692789
theme_by_type.clear();
2790+
m_clickthrough_elements.clear();
27702791

27712792
m_bgnonfullscreen = true;
27722793
m_bgfullscreen = false;
@@ -3248,12 +3269,19 @@ void GUIFormSpecMenu::drawMenu()
32483269
e->setVisible(false);
32493270
}
32503271

3272+
// Some elements are only visible while being drawn
3273+
for (gui::IGUIElement *e : m_clickthrough_elements)
3274+
e->setVisible(true);
3275+
32513276
/*
32523277
Call base class
32533278
(This is where all the drawing happens.)
32543279
*/
32553280
gui::IGUIElement::draw();
32563281

3282+
for (gui::IGUIElement *e : m_clickthrough_elements)
3283+
e->setVisible(false);
3284+
32573285
// Draw hovered item tooltips
32583286
for (const std::string &tooltip : m_hovered_item_tooltips) {
32593287
showTooltip(utf8_to_wide(tooltip), m_default_tooltip_color,

‎src/gui/guiFormSpecMenu.h

+1
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ class GUIFormSpecMenu : public GUIModalMenu
307307
std::vector<std::pair<gui::IGUIElement *, TooltipSpec>> m_tooltip_rects;
308308
std::vector<std::pair<FieldSpec, GUIScrollBar *>> m_scrollbars;
309309
std::vector<std::pair<FieldSpec, std::vector<std::string>>> m_dropdowns;
310+
std::vector<gui::IGUIElement *> m_clickthrough_elements;
310311

311312
GUIInventoryList::ItemSpec *m_selected_item = nullptr;
312313
u16 m_selected_amount = 0;

0 commit comments

Comments
 (0)
Please sign in to comment.