From db32c1f15a8e13e3007ea27251367ed2dcbf38d3 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Thu, 21 May 2020 17:29:00 +0200 Subject: [PATCH] Changed processing of a wxEVT_SYS_COLOUR_CHANGED event. Only UI is updated. The application doesn't recreated now --- src/slic3r/GUI/GUI_ObjectList.cpp | 20 ++++++++++ src/slic3r/GUI/GUI_ObjectList.hpp | 1 + src/slic3r/GUI/GUI_ObjectManipulation.cpp | 17 ++++++++ src/slic3r/GUI/GUI_ObjectManipulation.hpp | 1 + src/slic3r/GUI/GUI_Utils.hpp | 7 ++++ src/slic3r/GUI/MainFrame.cpp | 24 ++++++++++++ src/slic3r/GUI/MainFrame.hpp | 1 + src/slic3r/GUI/Plater.cpp | 39 +++++++++++++++++++ src/slic3r/GUI/Plater.hpp | 2 + src/slic3r/GUI/Search.cpp | 8 ++++ src/slic3r/GUI/Search.hpp | 1 + src/slic3r/GUI/Tab.cpp | 47 +++++++++++++++++++++++ src/slic3r/GUI/Tab.hpp | 2 + 13 files changed, 170 insertions(+) diff --git a/src/slic3r/GUI/GUI_ObjectList.cpp b/src/slic3r/GUI/GUI_ObjectList.cpp index 419f64567d..35ec2e4850 100644 --- a/src/slic3r/GUI/GUI_ObjectList.cpp +++ b/src/slic3r/GUI/GUI_ObjectList.cpp @@ -4029,6 +4029,26 @@ void ObjectList::msw_rescale() Layout(); } +void ObjectList::sys_color_changed() +{ + // msw_rescale_icons() updates icons, so use it + msw_rescale_icons(); + + // update existing items with bitmaps + m_objects_model->Rescale(); + + // msw_rescale_menu updates just icons, so use it + for (MenuWithSeparators* menu : { &m_menu_object, + &m_menu_part, + &m_menu_sla_object, + &m_menu_instance, + &m_menu_layer, + &m_menu_default}) + msw_rescale_menu(menu); + + Layout(); +} + void ObjectList::ItemValueChanged(wxDataViewEvent &event) { if (event.GetColumn() == colName) diff --git a/src/slic3r/GUI/GUI_ObjectList.hpp b/src/slic3r/GUI/GUI_ObjectList.hpp index a0370bd9de..0924d4216e 100644 --- a/src/slic3r/GUI/GUI_ObjectList.hpp +++ b/src/slic3r/GUI/GUI_ObjectList.hpp @@ -386,6 +386,7 @@ public: void paste_objects_into_list(const std::vector& object_idxs); void msw_rescale(); + void sys_color_changed(); void update_after_undo_redo(); //update printable state for item from objects model diff --git a/src/slic3r/GUI/GUI_ObjectManipulation.cpp b/src/slic3r/GUI/GUI_ObjectManipulation.cpp index 471369a006..2179a9559e 100644 --- a/src/slic3r/GUI/GUI_ObjectManipulation.cpp +++ b/src/slic3r/GUI/GUI_ObjectManipulation.cpp @@ -981,6 +981,23 @@ void ObjectManipulation::msw_rescale() get_og()->msw_rescale(); } +void ObjectManipulation::sys_color_changed() +{ + // btn...->msw_rescale() updates icon on button, so use it + m_mirror_bitmap_on.msw_rescale(); + m_mirror_bitmap_off.msw_rescale(); + m_mirror_bitmap_hidden.msw_rescale(); + m_reset_scale_button->msw_rescale(); + m_reset_rotation_button->msw_rescale(); + m_drop_to_bed_button->msw_rescale(); + m_lock_bnt->msw_rescale(); + + for (int id = 0; id < 3; ++id) + m_mirror_buttons[id].first->msw_rescale(); + + get_og()->msw_rescale(); +} + static const char axes[] = { 'x', 'y', 'z' }; ManipulationEditor::ManipulationEditor(ObjectManipulation* parent, const std::string& opt_key, diff --git a/src/slic3r/GUI/GUI_ObjectManipulation.hpp b/src/slic3r/GUI/GUI_ObjectManipulation.hpp index 64a59ac9b8..f002491f06 100644 --- a/src/slic3r/GUI/GUI_ObjectManipulation.hpp +++ b/src/slic3r/GUI/GUI_ObjectManipulation.hpp @@ -173,6 +173,7 @@ public: void update_item_name(const wxString &item_name); void update_warning_icon_state(const wxString& tooltip); void msw_rescale(); + void sys_color_changed(); void on_change(const std::string& opt_key, int axis, double new_value); void set_focused_editor(ManipulationEditor* focused_editor) { #ifndef __APPLE__ diff --git a/src/slic3r/GUI/GUI_Utils.hpp b/src/slic3r/GUI/GUI_Utils.hpp index 0d5249e254..934845fb37 100644 --- a/src/slic3r/GUI/GUI_Utils.hpp +++ b/src/slic3r/GUI/GUI_Utils.hpp @@ -124,6 +124,12 @@ public: // set value to _true_ in purpose of possibility of a display dpi changing from System Settings m_can_rescale = true; }); + + this->Bind(wxEVT_SYS_COLOUR_CHANGED, [this](wxSysColourChangedEvent& event) + { + event.Skip(); + on_sys_color_changed(); + }); } virtual ~DPIAware() {} @@ -137,6 +143,7 @@ public: protected: virtual void on_dpi_changed(const wxRect &suggested_rect) = 0; + virtual void on_sys_color_changed() {}; private: float m_scale_factor; diff --git a/src/slic3r/GUI/MainFrame.cpp b/src/slic3r/GUI/MainFrame.cpp index 69fa4b86be..65c212d11f 100644 --- a/src/slic3r/GUI/MainFrame.cpp +++ b/src/slic3r/GUI/MainFrame.cpp @@ -190,6 +190,7 @@ DPIFrame(NULL, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_S event.Skip(); }); + /* Bind(wxEVT_SYS_COLOUR_CHANGED, [this](wxSysColourChangedEvent& event) { bool recreate_gui = false; @@ -210,6 +211,7 @@ DPIFrame(NULL, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_S wxGetApp().recreate_GUI(_L("Changing of an application in respect to the system mode") + dots); event.Skip(); }); + */ wxGetApp().persist_window_geometry(this, true); @@ -575,6 +577,28 @@ void MainFrame::on_dpi_changed(const wxRect &suggested_rect) this->Maximize(is_maximized); } +void MainFrame::on_sys_color_changed() +{ + wxBusyCursor wait; + + // update label colors in respect to the system mode + wxGetApp().init_label_colours(); + + wxGetApp().preset_bundle->load_default_preset_bitmaps(); + + // update Plater + wxGetApp().plater()->sys_color_changed(); + + // update Tabs + for (auto tab : wxGetApp().tabs_list) + tab->sys_color_changed(); + + // msw_rescale_menu updates just icons, so use it + wxMenuBar* menu_bar = this->GetMenuBar(); + for (size_t id = 0; id < menu_bar->GetMenuCount(); id++) + msw_rescale_menu(menu_bar->GetMenu(id)); +} + void MainFrame::init_menubar() { #ifdef __APPLE__ diff --git a/src/slic3r/GUI/MainFrame.hpp b/src/slic3r/GUI/MainFrame.hpp index 219f683194..43375d3441 100644 --- a/src/slic3r/GUI/MainFrame.hpp +++ b/src/slic3r/GUI/MainFrame.hpp @@ -121,6 +121,7 @@ class MainFrame : public DPIFrame protected: virtual void on_dpi_changed(const wxRect &suggested_rect); + virtual void on_sys_color_changed() override; public: MainFrame(); diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 7c25c8ea93..23ef1acc03 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -1090,6 +1090,34 @@ void Sidebar::msw_rescale() p->scrolled->Layout(); } +void Sidebar::sys_color_changed() +{ + // Update preset comboboxes in respect to the system color ... + // combo->msw_rescale() updates icon on button, so use it + for (PresetComboBox* combo : std::vector{ p->combo_print, + p->combo_sla_print, + p->combo_sla_material, + p->combo_printer }) + combo->msw_rescale(); + for (PresetComboBox* combo : p->combos_filament) + combo->msw_rescale(); + + // ... then refill them and set min size to correct layout of the sidebar + update_all_preset_comboboxes(); + + p->object_list->sys_color_changed(); + p->object_manipulation->sys_color_changed(); +// p->object_settings->msw_rescale(); +// p->object_layers->msw_rescale(); + + // btn...->msw_rescale() updates icon on button, so use it + p->btn_send_gcode->msw_rescale(); + p->btn_remove_device->msw_rescale(); + p->btn_export_gcode_removable->msw_rescale(); + + p->scrolled->Layout(); +} + void Sidebar::search() { p->searcher.search(); @@ -5475,6 +5503,17 @@ void Plater::msw_rescale() GetParent()->Layout(); } +void Plater::sys_color_changed() +{ + p->sidebar->sys_color_changed(); + + // msw_rescale_menu updates just icons, so use it + p->msw_rescale_object_menu(); + + Layout(); + GetParent()->Layout(); +} + bool Plater::init_view_toolbar() { return p->init_view_toolbar(); diff --git a/src/slic3r/GUI/Plater.hpp b/src/slic3r/GUI/Plater.hpp index c67d92bc47..dcbda00f26 100644 --- a/src/slic3r/GUI/Plater.hpp +++ b/src/slic3r/GUI/Plater.hpp @@ -105,6 +105,7 @@ public: void update_mode_sizer() const; void update_reslice_btn_tooltip() const; void msw_rescale(); + void sys_color_changed(); void search(); void jump_to_option(size_t selected); @@ -308,6 +309,7 @@ public: bool can_reload_from_disk() const; void msw_rescale(); + void sys_color_changed(); bool init_view_toolbar(); diff --git a/src/slic3r/GUI/Search.cpp b/src/slic3r/GUI/Search.cpp index 967f6c5376..a94b776a18 100644 --- a/src/slic3r/GUI/Search.cpp +++ b/src/slic3r/GUI/Search.cpp @@ -668,6 +668,14 @@ void SearchDialog::on_dpi_changed(const wxRect& suggested_rect) Refresh(); } +void SearchDialog::on_sys_color_changed() +{ + // msw_rescale updates just icons, so use it + search_list_model->msw_rescale(); + + Refresh(); +} + // ---------------------------------------------------------------------------- // SearchListModel // ---------------------------------------------------------------------------- diff --git a/src/slic3r/GUI/Search.hpp b/src/slic3r/GUI/Search.hpp index 533ecf8f38..45a96034ac 100644 --- a/src/slic3r/GUI/Search.hpp +++ b/src/slic3r/GUI/Search.hpp @@ -198,6 +198,7 @@ public: protected: void on_dpi_changed(const wxRect& suggested_rect) override; + virtual void on_sys_color_changed() override; }; diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index ae08777638..49fa036183 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -590,6 +590,18 @@ void TabPrinter::msw_rescale() Layout(); } +void TabPrinter::sys_color_changed() +{ + Tab::sys_color_changed(); + + // update missed options_groups + const std::vector& pages = m_printer_technology == ptFFF ? m_pages_sla : m_pages_fff; + for (auto page : pages) + page->msw_rescale(); + + Layout(); +} + void TabSLAMaterial::init_options_list() { if (!m_options_list.empty()) @@ -869,6 +881,41 @@ void Tab::msw_rescale() Layout(); } +void Tab::sys_color_changed() +{ + update_tab_ui(); + + // update buttons and cached bitmaps + for (const auto btn : m_scaled_buttons) + btn->msw_rescale(); + for (const auto bmp : m_scaled_bitmaps) + bmp->msw_rescale(); + for (ScalableBitmap& bmp : m_mode_bitmap_cache) + bmp.msw_rescale(); + + // update icons for tree_ctrl + for (ScalableBitmap& bmp : m_scaled_icons_list) + bmp.msw_rescale(); + // recreate and set new ImageList for tree_ctrl + m_icons->RemoveAll(); + m_icons = new wxImageList(m_scaled_icons_list.front().bmp().GetWidth(), m_scaled_icons_list.front().bmp().GetHeight()); + for (ScalableBitmap& bmp : m_scaled_icons_list) + m_icons->Add(bmp.bmp()); + m_treectrl->AssignImageList(m_icons); + + + // Colors for ui "decoration" + m_sys_label_clr = wxGetApp().get_label_clr_sys(); + m_modified_label_clr = wxGetApp().get_label_clr_modified(); + update_labels_colour(); + + // update options_groups + for (auto page : m_pages) + page->msw_rescale(); + + Layout(); +} + Field* Tab::get_field(const t_config_option_key& opt_key, int opt_index/* = -1*/) const { Field* field = nullptr; diff --git a/src/slic3r/GUI/Tab.hpp b/src/slic3r/GUI/Tab.hpp index a13d13f2db..affe8c2c85 100644 --- a/src/slic3r/GUI/Tab.hpp +++ b/src/slic3r/GUI/Tab.hpp @@ -318,6 +318,7 @@ public: void update_mode(); void update_visibility(); virtual void msw_rescale(); + virtual void sys_color_changed(); Field* get_field(const t_config_option_key& opt_key, int opt_index = -1) const; Field* get_field(const t_config_option_key &opt_key, Page** selected_page, int opt_index = -1); bool set_value(const t_config_option_key& opt_key, const boost::any& value); @@ -436,6 +437,7 @@ public: void on_preset_loaded() override; void init_options_list() override; void msw_rescale() override; + void sys_color_changed() override; bool supports_printer_technology(const PrinterTechnology /* tech */) override { return true; } wxSizer* create_bed_shape_widget(wxWindow* parent);