From 5506e97ed897dde2d4820fe1b021a4622bae03b3 Mon Sep 17 00:00:00 2001 From: DS Date: Thu, 7 Nov 2019 20:11:01 +0100 Subject: Formspec: draw order and clipping for all elements (#8740) --- src/gui/guiFormSpecMenu.h | 131 ++++++++-------------------------------------- 1 file changed, 23 insertions(+), 108 deletions(-) (limited to 'src/gui/guiFormSpecMenu.h') 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 &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 middle; - bool scale; - bool clip; - }; - struct FieldSpec { FieldSpec() = default; @@ -239,19 +164,6 @@ class GUIFormSpecMenu : public GUIModalMenu core::rect 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 *v_pos); - v2s32 getRealCoordinateBasePos(bool absolute, - const std::vector &v_pos); + FormspecFieldType getTypeByID(s32 id); + v2s32 getElementBasePos(const std::vector *v_pos); + v2s32 getRealCoordinateBasePos(const std::vector &v_pos); v2s32 getRealCoordinateGeometry(const std::vector &v_geom); std::unordered_map theme_by_type; @@ -427,19 +338,15 @@ protected: std::vector m_inventorylists; std::vector m_inventory_rings; - std::vector m_backgrounds; - std::vector m_images; - std::vector m_itemimages; - std::vector m_boxes; + std::vector m_backgrounds; std::unordered_map field_close_on_enter; std::vector m_fields; - std::vector m_static_texts; - std::vector > m_tables; - std::vector > m_checkboxes; + std::vector> m_tables; + std::vector> m_checkboxes; std::map m_tooltips; - std::vector, TooltipSpec>> m_tooltip_rects; - std::vector > m_scrollbars; - std::vector > > m_dropdowns; + std::vector> m_tooltip_rects; + std::vector> m_scrollbars; + std::vector>> 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; @@ -555,6 +463,13 @@ private: void showTooltip(const std::wstring &text, const irr::video::SColor &color, 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::Iterator from); + /** * check if event is part of a double click * @param event event to evaluate -- cgit v1.2.3