From 6b28de6634688dde6550a51ba688c5a9773fae58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Hejl?= Date: Wed, 12 Feb 2025 10:41:41 +0100 Subject: [PATCH] SPE-2501: Add support for blinking arrow for more items on the same tab. --- src/slic3r/GUI/Plater.cpp | 2 +- src/slic3r/GUI/Tab.cpp | 9 +++-- src/slic3r/GUI/Tab.hpp | 2 +- src/slic3r/GUI/wxExtensions.cpp | 61 ++++++++++++++++++++++++--------- src/slic3r/GUI/wxExtensions.hpp | 19 ++++++++-- 5 files changed, 69 insertions(+), 24 deletions(-) diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index b40b8dd47c..0d16e1ea6d 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -2138,7 +2138,7 @@ void Plater::priv::process_validation_warning(const std::vector& wa multiline = true; notification_type = NotificationType::BedTemperaturesDiffer; action_fn = [](wxEvtHandler*) { - GUI::wxGetApp().jump_to_option("bed_temperature_extruder", Preset::Type::TYPE_PRINT, boost::nowide::widen("Multiple Extruders")); + GUI::wxGetApp().get_tab(Preset::Type::TYPE_PRINT)->activate_option("bed_temperature_extruder", boost::nowide::widen("Multiple Extruders"), { "wipe_tower_extruder" }); return true; }; } else if (text == "_FILAMENT_SHRINKAGE_DIFFER") { diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index ba75abb3b1..f8f3751759 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -1149,7 +1149,7 @@ void Tab::update_wiping_button_visibility() { } } -void Tab::activate_option(const std::string& opt_key, const wxString& category) +void Tab::activate_option(const std::string &opt_key, const wxString &category, const std::vector &another_blinking_opt_keys) { wxString page_title = translate_category(category, m_type); @@ -1197,7 +1197,12 @@ void Tab::activate_option(const std::string& opt_key, const wxString& category) set_focus(field->getWindow()); } - m_highlighter.init(get_custom_ctrl_with_blinking_ptr(opt_key)); + std::vector> custom_blinking_ctrls = { get_custom_ctrl_with_blinking_ptr(opt_key) }; + for (const std::string &another_blinking_opt_key : another_blinking_opt_keys) { + custom_blinking_ctrls.emplace_back(get_custom_ctrl_with_blinking_ptr(another_blinking_opt_key)); + } + + m_highlighter.init(custom_blinking_ctrls); } void Tab::cache_config_diff(const std::vector& selected_options, const DynamicPrintConfig* config/* = nullptr*/) diff --git a/src/slic3r/GUI/Tab.hpp b/src/slic3r/GUI/Tab.hpp index 71c80d7ad6..1d0dd6b414 100644 --- a/src/slic3r/GUI/Tab.hpp +++ b/src/slic3r/GUI/Tab.hpp @@ -398,7 +398,7 @@ public: void on_value_change(const std::string& opt_key, const boost::any& value); void update_wiping_button_visibility(); - void activate_option(const std::string& opt_key, const wxString& category); + void activate_option(const std::string &opt_key, const wxString &category, const std::vector &another_blinking_opt_keys = {}); void cache_config_diff(const std::vector& selected_options, const DynamicPrintConfig* config = nullptr); void apply_config_from_cache(); diff --git a/src/slic3r/GUI/wxExtensions.cpp b/src/slic3r/GUI/wxExtensions.cpp index aa29db9ae2..602bf4c601 100644 --- a/src/slic3r/GUI/wxExtensions.cpp +++ b/src/slic3r/GUI/wxExtensions.cpp @@ -731,11 +731,33 @@ void HighlighterForWx::init(std::pair params) if (!Highlighter::init(!params.first && !params.second)) return; - m_custom_ctrl = params.first; - m_show_blink_ptr = params.second; + assert(m_blinking_custom_ctrls.empty()); + m_blinking_custom_ctrls.push_back({params.first, params.second}); - *m_show_blink_ptr = true; - m_custom_ctrl->Refresh(); + BlinkingCustomCtrl &blinking_custom_ctrl = m_blinking_custom_ctrls.back(); + *blinking_custom_ctrl.show_blink_ptr = true; + blinking_custom_ctrl.custom_ctrl_ptr->Refresh(); +} + +void HighlighterForWx::init(const std::vector> &blinking_custom_ctrls_params) +{ + this->invalidate(); + + const bool input_failed = blinking_custom_ctrls_params.empty() || + std::any_of(blinking_custom_ctrls_params.cbegin(), blinking_custom_ctrls_params.cend(), + [](auto ¶ms) { return params.first == nullptr || params.second == nullptr; }); + + if (!Highlighter::init(input_failed)) + return; + + assert(m_blinking_custom_ctrls.empty()); + for (const std::pair &blinking_custom_ctrl_params : blinking_custom_ctrls_params) { + m_blinking_custom_ctrls.push_back({blinking_custom_ctrl_params.first, blinking_custom_ctrl_params.second}); + + BlinkingCustomCtrl &blinking_custom_ctrl = m_blinking_custom_ctrls.back(); + *blinking_custom_ctrl.show_blink_ptr = true; + blinking_custom_ctrl.custom_ctrl_ptr->Refresh(); + } } // - using a BlinkingBitmap. Change state of this bitmap @@ -753,13 +775,15 @@ void HighlighterForWx::invalidate() { Highlighter::invalidate(); - if (m_custom_ctrl && m_show_blink_ptr) { - *m_show_blink_ptr = false; - m_custom_ctrl->Refresh(); - m_show_blink_ptr = nullptr; - m_custom_ctrl = nullptr; - } - else if (m_blinking_bitmap) { + if (!m_blinking_custom_ctrls.empty()) { + for (BlinkingCustomCtrl &blinking_custom_ctrl : m_blinking_custom_ctrls) { + assert(blinking_custom_ctrl.is_valid()); + *blinking_custom_ctrl.show_blink_ptr = false; + blinking_custom_ctrl.custom_ctrl_ptr->Refresh(); + } + + m_blinking_custom_ctrls.clear(); + } else if (m_blinking_bitmap) { m_blinking_bitmap->invalidate(); m_blinking_bitmap = nullptr; } @@ -767,14 +791,17 @@ void HighlighterForWx::invalidate() void HighlighterForWx::blink() { - if (m_custom_ctrl && m_show_blink_ptr) { - *m_show_blink_ptr = !*m_show_blink_ptr; - m_custom_ctrl->Refresh(); - } - else if (m_blinking_bitmap) + if (!m_blinking_custom_ctrls.empty()) { + for (BlinkingCustomCtrl &blinking_custom_ctrl : m_blinking_custom_ctrls) { + assert(blinking_custom_ctrl.is_valid()); + *blinking_custom_ctrl.show_blink_ptr = !*blinking_custom_ctrl.show_blink_ptr; + blinking_custom_ctrl.custom_ctrl_ptr->Refresh(); + } + } else if (m_blinking_bitmap) { m_blinking_bitmap->blink(); - else + } else { return; + } Highlighter::blink(); } diff --git a/src/slic3r/GUI/wxExtensions.hpp b/src/slic3r/GUI/wxExtensions.hpp index fc96f48cbd..9ab9ad8855 100644 --- a/src/slic3r/GUI/wxExtensions.hpp +++ b/src/slic3r/GUI/wxExtensions.hpp @@ -283,12 +283,24 @@ public: class HighlighterForWx : public Highlighter { + struct BlinkingCustomCtrl + { + OG_CustomCtrl *custom_ctrl_ptr; + bool *show_blink_ptr; + + bool is_valid() const + { + return custom_ctrl_ptr != nullptr && show_blink_ptr != nullptr; + } + }; + + using BlinkingCustomCtrls = std::vector; + // There are 2 possible cases to use HighlighterForWx: // - using a BlinkingBitmap. Change state of this bitmap - BlinkingBitmap* m_blinking_bitmap { nullptr }; + BlinkingBitmap *m_blinking_bitmap { nullptr }; // - using OG_CustomCtrl where arrow will be rendered and flag indicated "show/hide" state of this arrow - OG_CustomCtrl* m_custom_ctrl { nullptr }; - bool* m_show_blink_ptr { nullptr }; + BlinkingCustomCtrls m_blinking_custom_ctrls; public: HighlighterForWx() {} @@ -297,6 +309,7 @@ public: void bind_timer(wxWindow* owner) override; void init(BlinkingBitmap* blinking_bitmap); void init(std::pair); + void init(const std::vector> &blinking_custom_ctrls_params); void blink(); void invalidate(); };