diff options
author | DS <vorunbekannt75@web.de> | 2020-03-31 19:34:42 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-31 18:34:42 +0100 |
commit | d7825bca1b3e0ed21c766da3b86c69f1da98917f (patch) | |
tree | b025d3e344bb1ffa93e3cb8b02cb6e6f63379cd2 /src | |
parent | 9953145a4efe5d2487ec8f5edc76cf8e418b7b41 (diff) | |
download | minetest-d7825bca1b3e0ed21c766da3b86c69f1da98917f.tar.gz minetest-d7825bca1b3e0ed21c766da3b86c69f1da98917f.tar.bz2 minetest-d7825bca1b3e0ed21c766da3b86c69f1da98917f.zip |
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.)
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/guiFormSpecMenu.cpp | 30 | ||||
-rw-r--r-- | src/gui/guiFormSpecMenu.h | 1 |
2 files changed, 30 insertions, 1 deletions
diff --git a/src/gui/guiFormSpecMenu.cpp b/src/gui/guiFormSpecMenu.cpp index 012ac953f..59cd130ef 100644 --- a/src/gui/guiFormSpecMenu.cpp +++ b/src/gui/guiFormSpecMenu.cpp @@ -141,6 +141,8 @@ GUIFormSpecMenu::~GUIFormSpecMenu() background_it->drop(); for (auto &tooltip_rect_it : m_tooltip_rects) tooltip_rect_it.first->drop(); + for (auto &clickthrough_it : m_clickthrough_elements) + clickthrough_it->drop(); delete m_selected_item; delete m_form_src; @@ -742,6 +744,9 @@ void GUIFormSpecMenu::parseImage(parserData* data, const std::string &element) e->setNotClipped(style.getBool(StyleSpec::NOCLIP, m_formspec_version < 3)); m_fields.push_back(spec); + // images should let events through + e->grab(); + m_clickthrough_elements.push_back(e); return; } @@ -775,6 +780,9 @@ void GUIFormSpecMenu::parseImage(parserData* data, const std::string &element) e->setNotClipped(style.getBool(StyleSpec::NOCLIP, m_formspec_version < 3)); m_fields.push_back(spec); + // images should let events through + e->grab(); + m_clickthrough_elements.push_back(e); return; } errorstream<< "Invalid image element(" << parts.size() << "): '" << element << "'" << std::endl; @@ -882,7 +890,9 @@ void GUIFormSpecMenu::parseItemImage(parserData* data, const std::string &elemen core::rect<s32>(pos, pos + geom), name, m_font, m_client); auto style = getStyleForElement("item_image", spec.fname); e->setNotClipped(style.getBool(StyleSpec::NOCLIP, false)); - e->drop(); + + // item images should let events through + m_clickthrough_elements.push_back(e); m_fields.push_back(spec); return; @@ -1747,6 +1757,10 @@ void GUIFormSpecMenu::parseLabel(parserData* data, const std::string &element) e->setOverrideColor(style.getColor(StyleSpec::TEXTCOLOR, video::SColor(0xFFFFFFFF))); m_fields.push_back(spec); + + // labels should let events through + e->grab(); + m_clickthrough_elements.push_back(e); } return; @@ -1823,6 +1837,10 @@ void GUIFormSpecMenu::parseVertLabel(parserData* data, const std::string &elemen e->setOverrideColor(style.getColor(StyleSpec::TEXTCOLOR, video::SColor(0xFFFFFFFF))); m_fields.push_back(spec); + + // vertlabels should let events through + e->grab(); + m_clickthrough_elements.push_back(e); return; } errorstream<< "Invalid vertlabel element(" << parts.size() << "): '" << element << "'" << std::endl; @@ -2745,6 +2763,8 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize) background_it->drop(); for (auto &tooltip_rect_it : m_tooltip_rects) tooltip_rect_it.first->drop(); + for (auto &clickthrough_it : m_clickthrough_elements) + clickthrough_it->drop(); mydata.size= v2s32(100,100); mydata.screensize = screensize; @@ -2767,6 +2787,7 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize) m_dropdowns.clear(); theme_by_name.clear(); theme_by_type.clear(); + m_clickthrough_elements.clear(); m_bgnonfullscreen = true; m_bgfullscreen = false; @@ -3248,12 +3269,19 @@ void GUIFormSpecMenu::drawMenu() e->setVisible(false); } + // Some elements are only visible while being drawn + for (gui::IGUIElement *e : m_clickthrough_elements) + e->setVisible(true); + /* Call base class (This is where all the drawing happens.) */ gui::IGUIElement::draw(); + for (gui::IGUIElement *e : m_clickthrough_elements) + e->setVisible(false); + // Draw hovered item tooltips for (const std::string &tooltip : m_hovered_item_tooltips) { showTooltip(utf8_to_wide(tooltip), m_default_tooltip_color, diff --git a/src/gui/guiFormSpecMenu.h b/src/gui/guiFormSpecMenu.h index 184b26f3c..17bfef205 100644 --- a/src/gui/guiFormSpecMenu.h +++ b/src/gui/guiFormSpecMenu.h @@ -307,6 +307,7 @@ protected: 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; + std::vector<gui::IGUIElement *> m_clickthrough_elements; GUIInventoryList::ItemSpec *m_selected_item = nullptr; u16 m_selected_amount = 0; |