From 1c22d788aabc5c87e601d85aa4326fc1930f375d Mon Sep 17 00:00:00 2001 From: YuSanka Date: Tue, 27 Oct 2020 22:19:12 +0100 Subject: [PATCH] Custom control : Implemented blinking icon --- src/slic3r/GUI/Field.hpp | 7 ++++ src/slic3r/GUI/OG_CustomCtrl.cpp | 17 ++++---- src/slic3r/GUI/OG_CustomCtrl.hpp | 4 +- src/slic3r/GUI/OptionsGroup.cpp | 15 +++++++ src/slic3r/GUI/OptionsGroup.hpp | 3 ++ src/slic3r/GUI/Tab.cpp | 71 +++++++++++++++++++++++++------- src/slic3r/GUI/Tab.hpp | 10 ++++- 7 files changed, 98 insertions(+), 29 deletions(-) diff --git a/src/slic3r/GUI/Field.hpp b/src/slic3r/GUI/Field.hpp index c83c7248b9..c223b5b121 100644 --- a/src/slic3r/GUI/Field.hpp +++ b/src/slic3r/GUI/Field.hpp @@ -227,6 +227,10 @@ public: m_side_text = side_text; } + bool* get_blink_ptr() { + return &m_blink; + } + virtual void msw_rescale(bool rescale_sidetext = false); void sys_color_changed(); @@ -245,6 +249,7 @@ public: const ScalableBitmap* undo_to_sys_bitmap() { return m_undo_to_sys_bitmap; } const wxString* undo_to_sys_tooltip() { return m_undo_to_sys_tooltip; } const wxColour* label_color() { return m_label_color; } + const bool blink() { return m_blink; } protected: RevertButton* m_Undo_btn = nullptr; @@ -256,6 +261,8 @@ protected: const ScalableBitmap* m_undo_to_sys_bitmap = nullptr; const wxString* m_undo_to_sys_tooltip = nullptr; + bool m_blink{ false }; + BlinkingBitmap* m_blinking_bmp{ nullptr }; wxStaticText* m_Label = nullptr; diff --git a/src/slic3r/GUI/OG_CustomCtrl.cpp b/src/slic3r/GUI/OG_CustomCtrl.cpp index 443d6c1482..b21ef7e2f5 100644 --- a/src/slic3r/GUI/OG_CustomCtrl.cpp +++ b/src/slic3r/GUI/OG_CustomCtrl.cpp @@ -426,7 +426,7 @@ void OG_CustomCtrl::CtrlLine::render(wxDC& dc, wxCoord v_pos) if (draw_just_act_buttons) { if (field) - draw_act_bmps(dc, wxPoint(0, v_pos), field->undo_to_sys_bitmap()->bmp(), field->undo_bitmap()->bmp()); + draw_act_bmps(dc, wxPoint(0, v_pos), field->undo_to_sys_bitmap()->bmp(), field->undo_bitmap()->bmp(), field->blink()); return; } @@ -445,7 +445,7 @@ void OG_CustomCtrl::CtrlLine::render(wxDC& dc, wxCoord v_pos) // If there's a widget, build it and set result to the correct position. if (og_line.widget != nullptr) { - draw_blinking_bmp(dc, wxPoint(h_pos, v_pos)); + draw_blinking_bmp(dc, wxPoint(h_pos, v_pos), og_line.blink); return; } @@ -458,7 +458,7 @@ void OG_CustomCtrl::CtrlLine::render(wxDC& dc, wxCoord v_pos) option_set.front().side_widget == nullptr && og_line.get_extra_widgets().size() == 0) { if (field && field->undo_to_sys_bitmap()) - draw_act_bmps(dc, wxPoint(h_pos, v_pos), field->undo_to_sys_bitmap()->bmp(), field->undo_bitmap()->bmp()); + draw_act_bmps(dc, wxPoint(h_pos, v_pos), field->undo_to_sys_bitmap()->bmp(), field->undo_bitmap()->bmp(), field->blink()); return; } @@ -477,7 +477,7 @@ void OG_CustomCtrl::CtrlLine::render(wxDC& dc, wxCoord v_pos) } if (field && field->undo_to_sys_bitmap()) { - h_pos = draw_act_bmps(dc, wxPoint(h_pos, v_pos), field->undo_to_sys_bitmap()->bmp(), field->undo_bitmap()->bmp(), bmp_rect_id++); + h_pos = draw_act_bmps(dc, wxPoint(h_pos, v_pos), field->undo_to_sys_bitmap()->bmp(), field->undo_bitmap()->bmp(), field->blink(), bmp_rect_id++); if (field->getSizer()) { auto children = field->getSizer()->GetChildren(); @@ -559,10 +559,9 @@ wxCoord OG_CustomCtrl::CtrlLine::draw_text(wxDC& dc, wxPoint pos, const wxStr return pos.x + width + ctrl->m_h_gap; } -wxPoint OG_CustomCtrl::CtrlLine::draw_blinking_bmp(wxDC& dc, wxPoint pos, size_t rect_id) +wxPoint OG_CustomCtrl::CtrlLine::draw_blinking_bmp(wxDC& dc, wxPoint pos, bool is_blinking, size_t rect_id) { -// wxBitmap bmp_blinking = create_scaled_bitmap("search_blink", ctrl); - wxBitmap bmp_blinking = create_scaled_bitmap("empty", ctrl); + wxBitmap bmp_blinking = create_scaled_bitmap(is_blinking ? "search_blink" : "empty", ctrl); wxCoord h_pos = pos.x; wxCoord v_pos = pos.y + lround((height - bmp_blinking.GetHeight()) / 2); @@ -575,9 +574,9 @@ wxPoint OG_CustomCtrl::CtrlLine::draw_blinking_bmp(wxDC& dc, wxPoint pos, size_t return wxPoint(h_pos, v_pos); } -wxCoord OG_CustomCtrl::CtrlLine::draw_act_bmps(wxDC& dc, wxPoint pos, const wxBitmap& bmp_undo_to_sys, const wxBitmap& bmp_undo, size_t rect_id) +wxCoord OG_CustomCtrl::CtrlLine::draw_act_bmps(wxDC& dc, wxPoint pos, const wxBitmap& bmp_undo_to_sys, const wxBitmap& bmp_undo, bool is_blinking, size_t rect_id) { - pos = draw_blinking_bmp(dc, pos, rect_id); + pos = draw_blinking_bmp(dc, pos, is_blinking, rect_id); wxCoord h_pos = pos.x; wxCoord v_pos = pos.y; diff --git a/src/slic3r/GUI/OG_CustomCtrl.hpp b/src/slic3r/GUI/OG_CustomCtrl.hpp index dcd43fe200..dfaf97d8b9 100644 --- a/src/slic3r/GUI/OG_CustomCtrl.hpp +++ b/src/slic3r/GUI/OG_CustomCtrl.hpp @@ -56,8 +56,8 @@ class OG_CustomCtrl :public wxControl void render(wxDC& dc, wxCoord v_pos); wxCoord draw_mode_bmp(wxDC& dc, wxCoord v_pos); wxCoord draw_text (wxDC& dc, wxPoint pos, const wxString& text, const wxColour* color, int width); - wxPoint draw_blinking_bmp(wxDC& dc, wxPoint pos, size_t rect_id = 0); - wxCoord draw_act_bmps(wxDC& dc, wxPoint pos, const wxBitmap& bmp_undo_to_sys, const wxBitmap& bmp_undo, size_t rect_id = 0); + wxPoint draw_blinking_bmp(wxDC& dc, wxPoint pos, bool is_blinking, size_t rect_id = 0); + wxCoord draw_act_bmps(wxDC& dc, wxPoint pos, const wxBitmap& bmp_undo_to_sys, const wxBitmap& bmp_undo, bool is_blinking, size_t rect_id = 0); std::vector rects_blinking; std::vector rects_undo_icon; diff --git a/src/slic3r/GUI/OptionsGroup.cpp b/src/slic3r/GUI/OptionsGroup.cpp index 4044e80e7b..7c0ff2ee92 100644 --- a/src/slic3r/GUI/OptionsGroup.cpp +++ b/src/slic3r/GUI/OptionsGroup.cpp @@ -923,6 +923,21 @@ Field* ConfigOptionsGroup::get_fieldc(const t_config_option_key& opt_key, int op return opt_id.empty() ? nullptr : get_field(opt_id); } +std::pair ConfigOptionsGroup::get_custom_ctrl_with_blinking_ptr(const t_config_option_key& opt_key, int opt_index/* = -1*/) +{ + Field* field = get_fieldc(opt_key, opt_index); + + if (field) + return {custom_ctrl, field->get_blink_ptr()}; + + for (Line& line : m_lines) + for (const Option& opt : line.get_options()) + if (opt.opt_id == opt_key && line.widget) + return { custom_ctrl, line.get_blink_ptr() }; + + return { nullptr, nullptr }; +} + // Change an option on m_config, possibly call ModelConfig::touch(). void ConfigOptionsGroup::change_opt_value(const t_config_option_key& opt_key, const boost::any& value, int opt_index /*= 0*/) diff --git a/src/slic3r/GUI/OptionsGroup.hpp b/src/slic3r/GUI/OptionsGroup.hpp index 02b641ab5c..e20a92b6be 100644 --- a/src/slic3r/GUI/OptionsGroup.hpp +++ b/src/slic3r/GUI/OptionsGroup.hpp @@ -54,6 +54,7 @@ public: size_t full_width {0}; wxStaticText** full_Label {nullptr}; wxColour* full_Label_color {nullptr}; + bool blink {false}; widget_t widget {nullptr}; std::function near_label_widget{ nullptr }; wxWindow* near_label_widget_win {nullptr}; @@ -71,6 +72,7 @@ public: const std::vector& get_extra_widgets() const {return m_extra_widgets;} const std::vector