]> git.lizzy.rs Git - minetest.git/blobdiff - src/guiFormSpecMenu.h
Remove superfluous pointer null checks
[minetest.git] / src / guiFormSpecMenu.h
index 4bc2448d847eb997936c65976ec0e3ff589dc880..d08bb4ab59cdbdebed78c896365a7ea2423c3810 100644 (file)
@@ -55,12 +55,10 @@ typedef enum {
 
 struct TextDest
 {
-       virtual ~TextDest() {};
+       virtual ~TextDest() {}
        // This is deprecated I guess? -celeron55
-       virtual void gotText(std::wstring text){}
+       virtual void gotText(const std::wstring &text) {}
        virtual void gotText(const StringMap &fields) = 0;
-       virtual void setFormName(std::string formname)
-       { m_formname = formname;};
 
        std::string m_formname;
 };
@@ -71,30 +69,29 @@ class IFormSource
        virtual ~IFormSource(){}
        virtual std::string getForm() = 0;
        // Fill in variables in field text
-       virtual std::string resolveText(std::string str){ return str; }
+       virtual std::string resolveText(const std::string &str) { return str; }
 };
 
 class GUIFormSpecMenu : public GUIModalMenu
 {
        struct ItemSpec
        {
-               ItemSpec()
+               ItemSpec() :
+                       i(-1)
                {
-                       i = -1;
                }
+
                ItemSpec(const InventoryLocation &a_inventoryloc,
                                const std::string &a_listname,
-                               s32 a_i)
-               {
-                       inventoryloc = a_inventoryloc;
-                       listname = a_listname;
-                       i = a_i;
-               }
-               bool isValid() const
+                               s32 a_i) :
+                       inventoryloc(a_inventoryloc),
+                       listname(a_listname),
+                       i(a_i)
                {
-                       return i != -1;
                }
 
+               bool isValid() const { return i != -1; }
+
                InventoryLocation inventoryloc;
                std::string listname;
                s32 i;
@@ -144,7 +141,8 @@ class GUIFormSpecMenu : public GUIModalMenu
                ImageDrawSpec():
                        parent_button(NULL),
                        clip(false)
-               {}
+               {
+               }
 
                ImageDrawSpec(const std::string &a_name,
                                const std::string &a_item_name,
@@ -157,7 +155,8 @@ class GUIFormSpecMenu : public GUIModalMenu
                        geom(a_geom),
                        scale(true),
                        clip(false)
-               {}
+               {
+               }
 
                ImageDrawSpec(const std::string &a_name,
                                const std::string &a_item_name,
@@ -169,7 +168,8 @@ class GUIFormSpecMenu : public GUIModalMenu
                        geom(a_geom),
                        scale(true),
                        clip(false)
-               {}
+               {
+               }
 
                ImageDrawSpec(const std::string &a_name,
                                const v2s32 &a_pos, const v2s32 &a_geom, bool clip=false):
@@ -179,7 +179,8 @@ class GUIFormSpecMenu : public GUIModalMenu
                        geom(a_geom),
                        scale(true),
                        clip(clip)
-               {}
+               {
+               }
 
                ImageDrawSpec(const std::string &a_name,
                                const v2s32 &a_pos):
@@ -188,7 +189,8 @@ class GUIFormSpecMenu : public GUIModalMenu
                        pos(a_pos),
                        scale(false),
                        clip(false)
-               {}
+               {
+               }
 
                std::string name;
                std::string item_name;
@@ -208,14 +210,14 @@ class GUIFormSpecMenu : public GUIModalMenu
                                const std::wstring &default_text, int id) :
                        fname(name),
                        flabel(label),
+                       fdefault(unescape_enriched(default_text)),
                        fid(id),
                        send(false),
                        ftype(f_Unknown),
                        is_exit(false)
                {
-                       //flabel = unescape_enriched(label);
-                       fdefault = unescape_enriched(default_text);
                }
+
                std::string fname;
                std::wstring flabel;
                std::wstring fdefault;
@@ -226,7 +228,8 @@ class GUIFormSpecMenu : public GUIModalMenu
                core::rect<s32> rect;
        };
 
-       struct BoxDrawSpec {
+       struct BoxDrawSpec
+       {
                BoxDrawSpec(v2s32 a_pos, v2s32 a_geom,irr::video::SColor a_color):
                        pos(a_pos),
                        geom(a_geom),
@@ -238,45 +241,46 @@ class GUIFormSpecMenu : public GUIModalMenu
                irr::video::SColor color;
        };
 
-       struct TooltipSpec {
-               TooltipSpec()
-               {
-               }
-               TooltipSpec(std::string a_tooltip, irr::video::SColor a_bgcolor,
+       struct TooltipSpec
+       {
+               TooltipSpec() {}
+               TooltipSpec(const std::string &a_tooltip, irr::video::SColor a_bgcolor,
                                irr::video::SColor a_color):
+                       tooltip(utf8_to_wide(a_tooltip)),
                        bgcolor(a_bgcolor),
                        color(a_color)
                {
-                       //tooltip = unescape_enriched(utf8_to_wide(a_tooltip));
-                       tooltip = utf8_to_wide(a_tooltip);
                }
+
                std::wstring tooltip;
                irr::video::SColor bgcolor;
                irr::video::SColor color;
        };
 
-       struct StaticTextSpec {
+       struct StaticTextSpec
+       {
                StaticTextSpec():
                        parent_button(NULL)
                {
                }
+
                StaticTextSpec(const std::wstring &a_text,
                                const core::rect<s32> &a_rect):
+                       text(a_text),
                        rect(a_rect),
                        parent_button(NULL)
                {
-                       //text = unescape_enriched(a_text);
-                       text = a_text;
                }
+
                StaticTextSpec(const std::wstring &a_text,
                                const core::rect<s32> &a_rect,
                                gui::IGUIButton *a_parent_button):
+                       text(a_text),
                        rect(a_rect),
                        parent_button(a_parent_button)
                {
-                       //text = unescape_enriched(a_text);
-                       text = a_text;
                }
+
                std::wstring text;
                core::rect<s32> rect;
                gui::IGUIButton *parent_button;
@@ -296,7 +300,7 @@ class GUIFormSpecMenu : public GUIModalMenu
        ~GUIFormSpecMenu();
 
        void setFormSpec(const std::string &formspec_string,
-                       InventoryLocation current_inventory_location)
+                       const InventoryLocation &current_inventory_location)
        {
                m_formspec_string = formspec_string;
                m_current_inventory_location = current_inventory_location;
@@ -306,18 +310,14 @@ class GUIFormSpecMenu : public GUIModalMenu
        // form_src is deleted by this GUIFormSpecMenu
        void setFormSource(IFormSource *form_src)
        {
-               if (m_form_src != NULL) {
-                       delete m_form_src;
-               }
+               delete m_form_src;
                m_form_src = form_src;
        }
 
        // text_dst is deleted by this GUIFormSpecMenu
        void setTextDest(TextDest *text_dst)
        {
-               if (m_text_dst != NULL) {
-                       delete m_text_dst;
-               }
+               delete m_text_dst;
                m_text_dst = text_dst;
        }
 
@@ -393,7 +393,7 @@ class GUIFormSpecMenu : public GUIModalMenu
        std::vector<ImageDrawSpec> m_images;
        std::vector<ImageDrawSpec> m_itemimages;
        std::vector<BoxDrawSpec> m_boxes;
-       UNORDERED_MAP<std::string, bool> field_close_on_enter;
+       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;
@@ -416,8 +416,8 @@ class GUIFormSpecMenu : public GUIModalMenu
        v2s32 m_old_pointer;  // Mouse position after previous mouse event
        gui::IGUIStaticText *m_tooltip_element;
 
-       u32 m_tooltip_show_delay;
-       s32 m_hovered_time;
+       u64 m_tooltip_show_delay;
+       u64 m_hovered_time;
        s32 m_old_tooltip_id;
        std::wstring m_old_tooltip;
 
@@ -456,7 +456,7 @@ class GUIFormSpecMenu : public GUIModalMenu
                GUITable::TableOptions table_options;
                GUITable::TableColumns table_columns;
                // used to restore table selection/scroll/treeview state
-               UNORDERED_MAP<std::string, GUITable::DynamicData> table_dyndata;
+               std::unordered_map<std::string, GUITable::DynamicData> table_dyndata;
        } parserData;
 
        typedef struct {
@@ -469,7 +469,7 @@ class GUIFormSpecMenu : public GUIModalMenu
        fs_key_pendig current_keys_pending;
        std::string current_field_enter_pending;
 
-       void parseElement(parserData* data, std::string element);
+       void parseElement(parserData* data, const std::string &element);
 
        void parseSize(parserData* data, const std::string &element);
        void parseContainer(parserData* data, const std::string &element);
@@ -513,6 +513,9 @@ class GUIFormSpecMenu : public GUIModalMenu
 
        void tryClose();
 
+       void showTooltip(const std::wstring &text, const irr::video::SColor &color,
+               const irr::video::SColor &bgcolor);
+
        /**
         * check if event is part of a double click
         * @param event event to evaluate
@@ -523,7 +526,7 @@ class GUIFormSpecMenu : public GUIModalMenu
        struct clickpos
        {
                v2s32 pos;
-               s32 time;
+               s64 time;
        };
        clickpos m_doubleclickdetect[2];
 
@@ -550,23 +553,22 @@ class GUIFormSpecMenu : public GUIModalMenu
 class FormspecFormSource: public IFormSource
 {
 public:
-       FormspecFormSource(const std::string &formspec)
+       FormspecFormSource(const std::string &formspec):
+               m_formspec(formspec)
        {
-               m_formspec = formspec;
        }
 
        ~FormspecFormSource()
-       {}
-
-       void setForm(const std::string &formspec) {
-               m_formspec = FORMSPEC_VERSION_STRING + formspec;
+       {
        }
 
-       std::string getForm()
+       void setForm(const std::string &formspec)
        {
-               return m_formspec;
+               m_formspec = FORMSPEC_VERSION_STRING + formspec;
        }
 
+       std::string getForm() { return m_formspec; }
+
        std::string m_formspec;
 };