diff --git a/src/slic3r/GUI/BitmapCache.cpp b/src/slic3r/GUI/BitmapCache.cpp index 7ad36f09b..b0da3b08a 100644 --- a/src/slic3r/GUI/BitmapCache.cpp +++ b/src/slic3r/GUI/BitmapCache.cpp @@ -23,6 +23,8 @@ void BitmapCache::clear() { for (std::pair &bitmap : m_map) delete bitmap.second; + + m_map.clear(); } static wxBitmap wxImage_to_wxBitmap_with_alpha(wxImage &&image) diff --git a/src/slic3r/GUI/GUI_Utils.hpp b/src/slic3r/GUI/GUI_Utils.hpp index e12153625..d68ac8b0d 100644 --- a/src/slic3r/GUI/GUI_Utils.hpp +++ b/src/slic3r/GUI/GUI_Utils.hpp @@ -58,9 +58,18 @@ public: : P(parent, id, title, pos, size, style, name) { m_scale_factor = (float)get_dpi_for_window(this) / (float)DPI_DEFAULT; + + // ->- + m_prev_scale_factor = -1; + // -<- + recalc_font(); this->Bind(EVT_DPI_CHANGED, [this](const DpiChangedEvent &evt) { + // ->- + m_prev_scale_factor = m_scale_factor; + // -<- + m_scale_factor = (float)evt.dpi / (float)DPI_DEFAULT; on_dpi_changed(evt.rect); }); @@ -69,14 +78,20 @@ public: virtual ~DPIAware() {} float scale_factor() const { return m_scale_factor; } + float prev_scale_factor() const { return m_prev_scale_factor; } int em_unit() const { return m_em_unit; } int font_size() const { return m_font_size; } + protected: virtual void on_dpi_changed(const wxRect &suggested_rect) = 0; + // ->- +// virtual void scale(wxWindow *window, const float& scale) = 0; + // -<- private: - int m_scale_factor; + float m_scale_factor; + float m_prev_scale_factor; int m_em_unit; int m_font_size; diff --git a/src/slic3r/GUI/MainFrame.cpp b/src/slic3r/GUI/MainFrame.cpp index 059d04f85..fe5768dbb 100644 --- a/src/slic3r/GUI/MainFrame.cpp +++ b/src/slic3r/GUI/MainFrame.cpp @@ -256,9 +256,63 @@ bool MainFrame::can_delete_all() const return (m_plater != nullptr) ? !m_plater->model().objects.empty() : false; } +static void scale(wxWindow *window, const float scale_f) +{ + auto children = window->GetChildren(); + + for (auto child : children) + { + scale(child, scale_f); + + child->SetFont(child->GetFont().Scaled(scale_f)); + +// const wxSize& sz = child->GetSize(); +// if (sz != wxDefaultSize) +// child->SetSize(sz*scale_f); + + child->Layout(); + } +} + void MainFrame::on_dpi_changed(const wxRect &suggested_rect) { - // TODO + printf("WM_DPICHANGED: %.2f\n", scale_factor()); + + // ->- + const float old_sc_factor = prev_scale_factor(); + const float new_sc_factor = scale_factor(); + + if (fabs(old_sc_factor - new_sc_factor) > 0.001) + { + Freeze(); + + const auto new_em_unit = wxGetApp().em_unit()*new_sc_factor / old_sc_factor; + + scale(this, new_sc_factor / old_sc_factor/*, 1/new_em_unit*/); + + wxGetApp().set_em_unit(std::max(10, new_em_unit)); + + /* Load default preset bitmaps before a tabpanel initialization, + * but after filling of an em_unit value + */ + wxGetApp().preset_bundle->load_default_preset_bitmaps(); + + wxGetApp().sidebar().scrolled_panel()->SetSize(40 * wxGetApp().em_unit(), -1); + wxGetApp().sidebar().scrolled_panel()->Layout(); + + // update preset comboboxes on Tabs + for (auto tab : wxGetApp().tabs_list) + tab->rescale();//update_tab_ui(); + + // update preset comboboxes on Plater + wxGetApp().sidebar().update_all_preset_comboboxes(); + + Refresh(); + Layout(); + + Thaw(); + } + // -<- } void MainFrame::init_menubar() diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 8f75d0ec9..344c9f079 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -781,6 +781,31 @@ void Sidebar::remove_unused_filament_combos(const int current_extruder_count) } } +void Sidebar::update_all_preset_comboboxes() +{ + PresetBundle &preset_bundle = *wxGetApp().preset_bundle; + const auto print_tech = preset_bundle.printers.get_edited_preset().printer_technology(); + +// wxWindowUpdateLocker noUpdates_scrolled(p->scrolled); + + // Update the print choosers to only contain the compatible presets, update the dirty flags. + if (print_tech == ptFFF) + preset_bundle.prints.update_platter_ui(p->combo_print); + else { + preset_bundle.sla_prints.update_platter_ui(p->combo_sla_print); + preset_bundle.sla_materials.update_platter_ui(p->combo_sla_material); + } + // Update the printer choosers, update the dirty flags. + preset_bundle.printers.update_platter_ui(p->combo_printer); + // Update the filament choosers to only contain the compatible presets, update the color preview, + // update the dirty flags. + if (print_tech == ptFFF) { + for (size_t i = 0; i < p->combos_filament.size(); ++i) + preset_bundle.update_platter_filament_ui(i, p->combos_filament[i]); + } + p->show_preset_comboboxes(); +} + void Sidebar::update_presets(Preset::Type preset_type) { PresetBundle &preset_bundle = *wxGetApp().preset_bundle; @@ -822,22 +847,23 @@ void Sidebar::update_presets(Preset::Type preset_type) { // wxWindowUpdateLocker noUpdates_scrolled(p->scrolled); - // Update the print choosers to only contain the compatible presets, update the dirty flags. - if (print_tech == ptFFF) - preset_bundle.prints.update_platter_ui(p->combo_print); - else { - preset_bundle.sla_prints.update_platter_ui(p->combo_sla_print); - preset_bundle.sla_materials.update_platter_ui(p->combo_sla_material); - } - // Update the printer choosers, update the dirty flags. - preset_bundle.printers.update_platter_ui(p->combo_printer); - // Update the filament choosers to only contain the compatible presets, update the color preview, - // update the dirty flags. - if (print_tech == ptFFF) { - for (size_t i = 0; i < p->combos_filament.size(); ++ i) - preset_bundle.update_platter_filament_ui(i, p->combos_filament[i]); - } - p->show_preset_comboboxes(); +// // Update the print choosers to only contain the compatible presets, update the dirty flags. +// if (print_tech == ptFFF) +// preset_bundle.prints.update_platter_ui(p->combo_print); +// else { +// preset_bundle.sla_prints.update_platter_ui(p->combo_sla_print); +// preset_bundle.sla_materials.update_platter_ui(p->combo_sla_material); +// } +// // Update the printer choosers, update the dirty flags. +// preset_bundle.printers.update_platter_ui(p->combo_printer); +// // Update the filament choosers to only contain the compatible presets, update the color preview, +// // update the dirty flags. +// if (print_tech == ptFFF) { +// for (size_t i = 0; i < p->combos_filament.size(); ++ i) +// preset_bundle.update_platter_filament_ui(i, p->combos_filament[i]); +// } +// p->show_preset_comboboxes(); + update_all_preset_comboboxes(); break; } diff --git a/src/slic3r/GUI/Plater.hpp b/src/slic3r/GUI/Plater.hpp index f830edce3..75b71b982 100644 --- a/src/slic3r/GUI/Plater.hpp +++ b/src/slic3r/GUI/Plater.hpp @@ -79,6 +79,7 @@ public: void init_filament_combo(PresetComboBox **combo, const int extr_idx); void remove_unused_filament_combos(const int current_extruder_count); + void update_all_preset_comboboxes(); void update_presets(Slic3r::Preset::Type preset_type); void update_mode_sizer() const; void update_reslice_btn_tooltip() const; diff --git a/src/slic3r/GUI/Preset.cpp b/src/slic3r/GUI/Preset.cpp index 7d1cedc96..9b642338a 100644 --- a/src/slic3r/GUI/Preset.cpp +++ b/src/slic3r/GUI/Preset.cpp @@ -1288,6 +1288,11 @@ std::string PresetCollection::path_from_name(const std::string &new_name) const return (boost::filesystem::path(m_dir_path) / file_name).make_preferred().string(); } +void PresetCollection::clear_bitmap_cache() +{ + m_bitmap_cache->clear(); +} + wxString PresetCollection::separator(const std::string &label) { return wxString::FromUTF8(PresetCollection::separator_head()) + _(label) + wxString::FromUTF8(PresetCollection::separator_tail()); diff --git a/src/slic3r/GUI/Preset.hpp b/src/slic3r/GUI/Preset.hpp index ac1171e18..989d0c392 100644 --- a/src/slic3r/GUI/Preset.hpp +++ b/src/slic3r/GUI/Preset.hpp @@ -411,6 +411,8 @@ public: // Generate a file path from a profile name. Add the ".ini" suffix if it is missing. std::string path_from_name(const std::string &new_name) const; + void clear_bitmap_cache(); + #ifdef __linux__ static const char* separator_head() { return "------- "; } static const char* separator_tail() { return " -------"; } diff --git a/src/slic3r/GUI/PresetBundle.cpp b/src/slic3r/GUI/PresetBundle.cpp index 19f9040bf..4d3890a02 100644 --- a/src/slic3r/GUI/PresetBundle.cpp +++ b/src/slic3r/GUI/PresetBundle.cpp @@ -1448,6 +1448,14 @@ bool PresetBundle::parse_color(const std::string &scolor, unsigned char *rgb_out void PresetBundle::load_default_preset_bitmaps() { + // Clear bitmap cache, before load new scaled default preset bitmaps + m_bitmapCache->clear(); + this->prints.clear_bitmap_cache(); + this->sla_prints.clear_bitmap_cache(); + this->filaments.clear_bitmap_cache(); + this->sla_materials.clear_bitmap_cache(); + this->printers.clear_bitmap_cache(); + this->prints.load_bitmap_default("cog"); this->sla_prints.load_bitmap_default("cog"); this->filaments.load_bitmap_default("spool.png"); diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index 5b200a194..d3618efdc 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -726,6 +726,16 @@ void Tab::update_visibility() update_changed_tree_ui(); } +void Tab::rescale() +{ + m_em_unit = wxGetApp().em_unit(); + + m_presets_choice->SetSize(25 * m_em_unit, -1); + m_treectrl->SetSize(20 * m_em_unit, -1); + + update_tab_ui(); +} + 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 58950990c..1901c9b29 100644 --- a/src/slic3r/GUI/Tab.hpp +++ b/src/slic3r/GUI/Tab.hpp @@ -274,6 +274,7 @@ public: virtual void reload_config(); void update_mode(); void update_visibility(); + void rescale(); Field* get_field(const t_config_option_key& opt_key, int opt_index = -1) const; bool set_value(const t_config_option_key& opt_key, const boost::any& value); wxSizer* description_line_widget(wxWindow* parent, ogStaticText** StaticText); diff --git a/src/slic3r/GUI/wxExtensions.cpp b/src/slic3r/GUI/wxExtensions.cpp index a27b84058..9b8daecfa 100644 --- a/src/slic3r/GUI/wxExtensions.cpp +++ b/src/slic3r/GUI/wxExtensions.cpp @@ -2387,7 +2387,7 @@ PrusaModeButton::PrusaModeButton( wxWindow *parent, const wxBitmap& bmp_on/* = wxNullBitmap*/, const wxSize& size/* = wxDefaultSize*/, const wxPoint& pos/* = wxDefaultPosition*/) : - wxButton(parent, id, mode, pos, size, /*wxBU_EXACTFIT | */wxNO_BORDER), + wxButton(parent, id, mode, pos, wxDefaultSize/*size*/, wxBU_EXACTFIT | wxNO_BORDER), m_bmp_on(bmp_on) { #ifdef __WXMSW__ @@ -2425,7 +2425,11 @@ void PrusaModeButton::focus_button(const bool focus) { // const wxBitmap& bmp = focus ? m_bmp_on : m_bmp_off; // SetBitmap(bmp); - const wxFont& new_font = focus ? Slic3r::GUI::wxGetApp().bold_font() : Slic3r::GUI::wxGetApp().small_font(); + +// const wxFont& new_font = focus ? Slic3r::GUI::wxGetApp().bold_font() : Slic3r::GUI::wxGetApp().small_font(); + wxFont font = GetFont(); + const wxFont& new_font = focus ? font.Bold() : font.GetBaseFont(); + SetFont(new_font); Refresh();