diff options
author | Enrico Turri <enricoturri@seznam.cz> | 2019-07-11 16:29:46 +0300 |
---|---|---|
committer | Enrico Turri <enricoturri@seznam.cz> | 2019-07-11 16:29:46 +0300 |
commit | 4c6c608342e92d6769205ea8b68bde7ebbef04d6 (patch) | |
tree | 8c2e507634184e4607970409fb6942d66fa656bf /src/slic3r/GUI/GLToolbar.hpp | |
parent | f964f5e99a5f432569ce3e04a26a420a1490c7ae (diff) |
GLToolbar and GLToolbarItem refactored to allow two different actions when left/right clicking on items.
Stack dialog for undo and redo items is now shown on right click only
Diffstat (limited to 'src/slic3r/GUI/GLToolbar.hpp')
-rw-r--r-- | src/slic3r/GUI/GLToolbar.hpp | 47 |
1 files changed, 36 insertions, 11 deletions
diff --git a/src/slic3r/GUI/GLToolbar.hpp b/src/slic3r/GUI/GLToolbar.hpp index 33e1ca234..86cd1a7fc 100644 --- a/src/slic3r/GUI/GLToolbar.hpp +++ b/src/slic3r/GUI/GLToolbar.hpp @@ -36,8 +36,8 @@ class GLToolbarItem public: typedef std::function<void()> ActionCallback; typedef std::function<bool()> VisibilityCallback; - typedef std::function<bool()> EnabledStateCallback; - typedef std::function<void(float, float,float, float)> RenderCallback; + typedef std::function<bool()> EnablingCallback; + typedef std::function<void(float, float, float, float)> RenderCallback; enum EType : unsigned char { @@ -46,6 +46,14 @@ public: Num_Types }; + enum EActionType : unsigned char + { + Undefined, + Left, + Right, + Num_Action_Types + }; + enum EState : unsigned char { Normal, @@ -64,25 +72,33 @@ public: #endif // ENABLE_SVG_ICONS std::string tooltip; unsigned int sprite_id; - bool is_toggable; + bool left_toggable; + bool right_toggable; bool visible; - ActionCallback action_callback; + // action on left click + ActionCallback left_action_callback; + // action on right click + ActionCallback right_action_callback; VisibilityCallback visibility_callback; - EnabledStateCallback enabled_state_callback; - RenderCallback render_callback; + EnablingCallback enabling_callback; + // render callback on left click + RenderCallback left_render_callback; + // render callback on right click + RenderCallback right_render_callback; Data(); }; static const ActionCallback Default_Action_Callback; static const VisibilityCallback Default_Visibility_Callback; - static const EnabledStateCallback Default_Enabled_State_Callback; + static const EnablingCallback Default_Enabling_Callback; static const RenderCallback Default_Render_Callback; private: EType m_type; EState m_state; Data m_data; + EActionType m_last_action; public: GLToolbarItem(EType type, const Data& data); @@ -96,17 +112,25 @@ public: #endif // ENABLE_SVG_ICONS const std::string& get_tooltip() const { return m_data.tooltip; } - void do_action() { m_data.action_callback(); } + void do_left_action() { m_last_action = Left; m_data.left_action_callback(); } + void do_right_action() { m_last_action = Right; m_data.right_action_callback(); } bool is_enabled() const { return m_state != Disabled; } bool is_disabled() const { return m_state == Disabled; } bool is_hovered() const { return (m_state == Hover) || (m_state == HoverPressed); } bool is_pressed() const { return (m_state == Pressed) || (m_state == HoverPressed); } - bool is_toggable() const { return m_data.is_toggable; } + bool is_left_toggable() const { return m_data.left_toggable; } + bool is_right_toggable() const { return m_data.right_toggable; } bool is_visible() const { return m_data.visible; } bool is_separator() const { return m_type == Separator; } + bool has_left_render_callback() const { return m_data.left_render_callback != nullptr; } + bool has_right_render_callback() const { return m_data.right_render_callback != nullptr; } + + EActionType get_last_action() const { return m_last_action; } + void reset_last_action() { m_last_action = Undefined; } + // returns true if the state changes bool update_visibility(); // returns true if the state changes @@ -303,7 +327,8 @@ public: unsigned int get_item_id(const std::string& name) const; - void force_action(unsigned int item_id, GLCanvas3D& parent); + void force_left_action(unsigned int item_id, GLCanvas3D& parent); + void force_right_action(unsigned int item_id, GLCanvas3D& parent); const std::string& get_tooltip() const { return m_tooltip; } @@ -321,7 +346,7 @@ private: float get_height_horizontal() const; float get_height_vertical() const; float get_main_size() const; - void do_action(unsigned int item_id, GLCanvas3D& parent, bool check_hover); + void do_action(GLToolbarItem::EActionType type, unsigned int item_id, GLCanvas3D& parent, bool check_hover); std::string update_hover_state(const Vec2d& mouse_pos, GLCanvas3D& parent); std::string update_hover_state_horizontal(const Vec2d& mouse_pos, GLCanvas3D& parent); std::string update_hover_state_vertical(const Vec2d& mouse_pos, GLCanvas3D& parent); |