From ffc29a253671e203f64c6f9ea754da3f9aa22850 Mon Sep 17 00:00:00 2001 From: David Kocik Date: Wed, 13 Oct 2021 16:45:05 +0200 Subject: [PATCH] Preferences Highlighter --- src/slic3r/GUI/GUI_App.cpp | 4 +- src/slic3r/GUI/GUI_App.hpp | 2 +- src/slic3r/GUI/HintNotification.cpp | 2 +- src/slic3r/GUI/OG_CustomCtrl.cpp | 2 + src/slic3r/GUI/Preferences.cpp | 69 ++++++++++++++++++++++++++++- src/slic3r/GUI/Preferences.hpp | 19 +++++++- 6 files changed, 92 insertions(+), 6 deletions(-) diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index a19858eea..a98998a84 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -2020,14 +2020,14 @@ void GUI_App::add_config_menu(wxMenuBar *menu) menu->Append(local_menu, _L("&Configuration")); } -void GUI_App::open_preferences(size_t open_on_tab) +void GUI_App::open_preferences(size_t open_on_tab, const std::string& highlight_option) { bool app_layout_changed = false; { // the dialog needs to be destroyed before the call to recreate_GUI() // or sometimes the application crashes into wxDialogBase() destructor // so we put it into an inner scope - PreferencesDialog dlg(mainframe, open_on_tab); + PreferencesDialog dlg(mainframe, open_on_tab, highlight_option); dlg.ShowModal(); app_layout_changed = dlg.settings_layout_changed(); #if ENABLE_GCODE_LINES_ID_IN_H_SLIDER diff --git a/src/slic3r/GUI/GUI_App.hpp b/src/slic3r/GUI/GUI_App.hpp index 3061bbe13..d350da969 100644 --- a/src/slic3r/GUI/GUI_App.hpp +++ b/src/slic3r/GUI/GUI_App.hpp @@ -259,7 +259,7 @@ public: wxString current_language_code_safe() const; bool is_localized() const { return m_wxLocale->GetLocale() != "English"; } - void open_preferences(size_t open_on_tab = 0); + void open_preferences(size_t open_on_tab = 0, const std::string& highlight_option = std::string()); virtual bool OnExceptionInMainLoop() override; // Calls wxLaunchDefaultBrowser if user confirms in dialog. diff --git a/src/slic3r/GUI/HintNotification.cpp b/src/slic3r/GUI/HintNotification.cpp index fc410fce2..21aecd15b 100644 --- a/src/slic3r/GUI/HintNotification.cpp +++ b/src/slic3r/GUI/HintNotification.cpp @@ -919,7 +919,7 @@ void NotificationManager::HintNotification::render_preferences_button(ImGuiWrapp } if (imgui.button(button_text.c_str(), button_size.x, button_size.y)) { - wxGetApp().open_preferences(2); + wxGetApp().open_preferences(2, "show_hints"); } ImGui::PopStyleColor(5); diff --git a/src/slic3r/GUI/OG_CustomCtrl.cpp b/src/slic3r/GUI/OG_CustomCtrl.cpp index 9c31f679b..18553b9cf 100644 --- a/src/slic3r/GUI/OG_CustomCtrl.cpp +++ b/src/slic3r/GUI/OG_CustomCtrl.cpp @@ -597,6 +597,8 @@ 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(), field->blink()) + ctrl->m_h_gap; + else if (field && !field->undo_to_sys_bitmap() && field->blink()) + draw_blinking_bmp(dc, wxPoint(h_pos, v_pos), field->blink()); // update width for full_width fields if (option_set.front().opt.full_width && field->getWindow()) field->getWindow()->SetSize(ctrl->GetSize().x - h_pos, -1); diff --git a/src/slic3r/GUI/Preferences.cpp b/src/slic3r/GUI/Preferences.cpp index ae52b52a9..ee80131e0 100644 --- a/src/slic3r/GUI/Preferences.cpp +++ b/src/slic3r/GUI/Preferences.cpp @@ -43,7 +43,7 @@ namespace Slic3r { namespace GUI { -PreferencesDialog::PreferencesDialog(wxWindow* parent, int selected_tab) : +PreferencesDialog::PreferencesDialog(wxWindow* parent, int selected_tab, const std::string& highlight_opt_key) : DPIDialog(parent, wxID_ANY, _L("Preferences"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE) { @@ -51,6 +51,8 @@ PreferencesDialog::PreferencesDialog(wxWindow* parent, int selected_tab) : isOSX = true; #endif build(selected_tab); + if (!highlight_opt_key.empty()) + init_highlighter(highlight_opt_key); } static std::shared_ptrcreate_options_tab(const wxString& title, wxBookCtrlBase* tabs) @@ -755,6 +757,71 @@ void PreferencesDialog::create_settings_text_color_widget() m_optgroup_gui->sizer->Add(sizer, 0, wxEXPAND | wxTOP, em_unit()); } +void PreferencesDialog::init_highlighter(const t_config_option_key& opt_key) +{ + m_highlighter.set_timer_owner(this, 0); + this->Bind(wxEVT_TIMER, [this](wxTimerEvent&) + { + m_highlighter.blink(); + }); + + std::pair ctrl = { nullptr, nullptr }; + for (auto opt_group : { m_optgroup_general, m_optgroup_camera, m_optgroup_gui }) { + ctrl = opt_group->get_custom_ctrl_with_blinking_ptr(opt_key, -1); + if (ctrl.first && ctrl.second) { + m_highlighter.init(ctrl); + break; + } + } +} + +void PreferencesDialog::PreferencesHighlighter::set_timer_owner(wxEvtHandler* owner, int timerid/* = wxID_ANY*/) +{ + m_timer.SetOwner(owner, timerid); +} + +void PreferencesDialog::PreferencesHighlighter::init(std::pair params) +{ + if (m_timer.IsRunning()) + invalidate(); + if (!params.first || !params.second) + return; + + m_timer.Start(300, false); + + m_custom_ctrl = params.first; + m_show_blink_ptr = params.second; + + *m_show_blink_ptr = true; + m_custom_ctrl->Refresh(); +} + +void PreferencesDialog::PreferencesHighlighter::invalidate() +{ + m_timer.Stop(); + + 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; + } + + m_blink_counter = 0; +} + +void PreferencesDialog::PreferencesHighlighter::blink() +{ + if (m_custom_ctrl && m_show_blink_ptr) { + *m_show_blink_ptr = !*m_show_blink_ptr; + m_custom_ctrl->Refresh(); + } + else + return; + + if ((++m_blink_counter) == 11) + invalidate(); +} } // GUI } // Slic3r diff --git a/src/slic3r/GUI/Preferences.hpp b/src/slic3r/GUI/Preferences.hpp index 7f708ff9c..fdfa39455 100644 --- a/src/slic3r/GUI/Preferences.hpp +++ b/src/slic3r/GUI/Preferences.hpp @@ -20,6 +20,7 @@ namespace Slic3r { namespace GUI { class ConfigOptionsGroup; +class OG_CustomCtrl; class PreferencesDialog : public DPIDialog { @@ -39,7 +40,7 @@ class PreferencesDialog : public DPIDialog bool m_recreate_GUI{false}; public: - explicit PreferencesDialog(wxWindow* parent, int selected_tab = 0); + explicit PreferencesDialog(wxWindow* parent, int selected_tab = 0, const std::string& highlight_opt_key = std::string()); ~PreferencesDialog() = default; bool settings_layout_changed() const { return m_settings_layout_changed; } @@ -55,6 +56,22 @@ protected: void create_icon_size_slider(); void create_settings_mode_widget(); void create_settings_text_color_widget(); + void init_highlighter(const t_config_option_key& opt_key); + + struct PreferencesHighlighter + { + void set_timer_owner(wxEvtHandler* owner, int timerid = wxID_ANY); + void init(std::pair); + void blink(); + void invalidate(); + + private: + OG_CustomCtrl* m_custom_ctrl{ nullptr }; + bool* m_show_blink_ptr{ nullptr }; + int m_blink_counter{ 0 }; + wxTimer m_timer; + } + m_highlighter; }; } // GUI