From 82573390c7c1b918ad4d2d7f9837984aca20316b Mon Sep 17 00:00:00 2001 From: YuSanka Date: Wed, 10 Apr 2019 09:56:32 +0200 Subject: [PATCH 01/19] First scaling experiments --- src/slic3r/GUI/BitmapCache.cpp | 2 ++ src/slic3r/GUI/GUI_Utils.hpp | 17 +++++++++- src/slic3r/GUI/MainFrame.cpp | 56 ++++++++++++++++++++++++++++++- src/slic3r/GUI/Plater.cpp | 58 ++++++++++++++++++++++++--------- src/slic3r/GUI/Plater.hpp | 1 + src/slic3r/GUI/Preset.cpp | 5 +++ src/slic3r/GUI/Preset.hpp | 2 ++ src/slic3r/GUI/PresetBundle.cpp | 8 +++++ src/slic3r/GUI/Tab.cpp | 10 ++++++ src/slic3r/GUI/Tab.hpp | 1 + src/slic3r/GUI/wxExtensions.cpp | 8 +++-- 11 files changed, 148 insertions(+), 20 deletions(-) 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(); From f7ddddcff58b1c3de8740c70e3c297f2734602f5 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Sat, 13 Apr 2019 23:46:52 +0200 Subject: [PATCH 02/19] Application Scaling for MSW: Next big step - Added rescale() function for the most of controls - Created PrusaBitmap and PrusaButton classes like a wrap to wxBitmap and wxButton accordingly --- src/libslic3r/PrintConfig.cpp | 34 +-- src/slic3r/GUI/ButtonsDescription.cpp | 3 +- src/slic3r/GUI/ButtonsDescription.hpp | 4 +- src/slic3r/GUI/Field.cpp | 120 ++++++++-- src/slic3r/GUI/Field.hpp | 56 +++-- src/slic3r/GUI/GUI_App.cpp | 7 + src/slic3r/GUI/GUI_App.hpp | 1 + src/slic3r/GUI/GUI_ObjectList.cpp | 12 + src/slic3r/GUI/GUI_ObjectList.hpp | 3 + src/slic3r/GUI/GUI_ObjectManipulation.cpp | 6 +- src/slic3r/GUI/GUI_ObjectSettings.cpp | 32 ++- src/slic3r/GUI/GUI_ObjectSettings.hpp | 4 + src/slic3r/GUI/MainFrame.cpp | 24 +- src/slic3r/GUI/OptionsGroup.cpp | 62 +++++- src/slic3r/GUI/OptionsGroup.hpp | 7 +- src/slic3r/GUI/Plater.cpp | 95 +++++--- src/slic3r/GUI/Plater.hpp | 6 +- src/slic3r/GUI/Preferences.cpp | 4 +- src/slic3r/GUI/Tab.cpp | 258 +++++++++++++++------- src/slic3r/GUI/Tab.hpp | 61 ++--- src/slic3r/GUI/wxExtensions.cpp | 114 ++++++++-- src/slic3r/GUI/wxExtensions.hpp | 74 ++++++- 22 files changed, 737 insertions(+), 250 deletions(-) diff --git a/src/libslic3r/PrintConfig.cpp b/src/libslic3r/PrintConfig.cpp index a978a3175..46efceb9a 100644 --- a/src/libslic3r/PrintConfig.cpp +++ b/src/libslic3r/PrintConfig.cpp @@ -131,7 +131,7 @@ void PrintConfigDef::init_fff_params() "as [layer_num] and [layer_z]."); def->multiline = true; def->full_width = true; - def->height = 50; + def->height = 5; def->mode = comExpert; def->default_value = new ConfigOptionString(""); @@ -140,7 +140,7 @@ void PrintConfigDef::init_fff_params() def->tooltip = L("This code is inserted between objects when using sequential printing. By default extruder and bed temperature are reset using non-wait command; however if M104, M109, M140 or M190 are detected in this custom code, Slic3r will not add temperature commands. Note that you can use placeholder variables for all Slic3r settings, so you can put a \"M109 S[first_layer_temperature]\" command wherever you want."); def->multiline = true; def->full_width = true; - def->height = 120; + def->height = 12; def->mode = comExpert; def->default_value = new ConfigOptionString(""); @@ -360,7 +360,7 @@ void PrintConfigDef::init_fff_params() "Note that you can use placeholder variables for all Slic3r settings."); def->multiline = true; def->full_width = true; - def->height = 120; + def->height = 12; def->mode = comExpert; def->default_value = new ConfigOptionString("M104 S0 ; turn off temperature\nG28 X0 ; home X axis\nM84 ; disable motors\n"); @@ -539,7 +539,7 @@ void PrintConfigDef::init_fff_params() def->tooltip = L("If layer print time is estimated below this number of seconds, fan will be enabled " "and its speed will be calculated by interpolating the minimum and maximum speeds."); def->sidetext = L("approximate seconds"); - def->width = 60; + def->width = 6; def->min = 0; def->max = 1000; def->mode = comExpert; @@ -556,7 +556,7 @@ void PrintConfigDef::init_fff_params() def->tooltip = L("You can put your notes regarding the filament here."); def->multiline = true; def->full_width = true; - def->height = 130; + def->height = 13; def->mode = comAdvanced; def->default_value = new ConfigOptionStrings { "" }; @@ -1007,7 +1007,7 @@ void PrintConfigDef::init_fff_params() def->label = L("Inherits profile"); def->tooltip = L("Name of the profile, from which this profile inherits."); def->full_width = true; - def->height = 50; + def->height = 5; def->default_value = new ConfigOptionString(); def->cli = ConfigOptionDef::nocli; @@ -1034,7 +1034,7 @@ void PrintConfigDef::init_fff_params() def->cli = "after-layer-gcode|layer-gcode"; def->multiline = true; def->full_width = true; - def->height = 50; + def->height = 5; def->mode = comExpert; def->default_value = new ConfigOptionString(""); @@ -1053,7 +1053,7 @@ void PrintConfigDef::init_fff_params() def->mode = comExpert; def->default_value = new ConfigOptionBool(true); - const int machine_limits_opt_width = 70; + const int machine_limits_opt_width = 7; { struct AxisDefault { std::string name; @@ -1252,7 +1252,7 @@ void PrintConfigDef::init_fff_params() "header comments."); def->multiline = true; def->full_width = true; - def->height = 130; + def->height = 13; def->mode = comAdvanced; def->default_value = new ConfigOptionString(""); @@ -1387,7 +1387,7 @@ void PrintConfigDef::init_fff_params() def->gui_flags = "serialized"; def->multiline = true; def->full_width = true; - def->height = 60; + def->height = 6; def->mode = comExpert; def->default_value = new ConfigOptionStrings(); @@ -1402,7 +1402,7 @@ void PrintConfigDef::init_fff_params() def->tooltip = L("You can put your notes regarding the printer here."); def->multiline = true; def->full_width = true; - def->height = 130; + def->height = 13; def->mode = comAdvanced; def->default_value = new ConfigOptionString(""); @@ -1589,7 +1589,7 @@ void PrintConfigDef::init_fff_params() def->label = ""; def->full_label = L("Serial port"); def->tooltip = L("USB/serial port for printer connection."); - def->width = 200; + def->width = 20; def->default_value = new ConfigOptionString(""); def = this->add("serial_speed", coInt); @@ -1635,7 +1635,7 @@ void PrintConfigDef::init_fff_params() def->tooltip = L("If layer print time is estimated below this number of seconds, print moves " "speed will be scaled down to extend duration to this value."); def->sidetext = L("approximate seconds"); - def->width = 60; + def->width = 6; def->min = 0; def->max = 1000; def->mode = comExpert; @@ -1742,7 +1742,7 @@ void PrintConfigDef::init_fff_params() "a \"M109 S[first_layer_temperature]\" command wherever you want."); def->multiline = true; def->full_width = true; - def->height = 120; + def->height = 12; def->mode = comExpert; def->default_value = new ConfigOptionString("G28 ; home all axes\nG1 Z5 F5000 ; lift nozzle\n"); @@ -1758,7 +1758,7 @@ void PrintConfigDef::init_fff_params() "in extruder order."); def->multiline = true; def->full_width = true; - def->height = 120; + def->height = 12; def->mode = comExpert; def->default_value = new ConfigOptionStrings { "; Filament gcode\n" }; @@ -2008,7 +2008,7 @@ void PrintConfigDef::init_fff_params() "as [previous_extruder] and [next_extruder]."); def->multiline = true; def->full_width = true; - def->height = 50; + def->height = 5; def->mode = comExpert; def->default_value = new ConfigOptionString(""); @@ -2330,7 +2330,7 @@ void PrintConfigDef::init_sla_params() def->tooltip = L("You can put your notes regarding the SLA print material here."); def->multiline = true; def->full_width = true; - def->height = 130; + def->height = 13; def->mode = comAdvanced; def->default_value = new ConfigOptionString(""); diff --git a/src/slic3r/GUI/ButtonsDescription.cpp b/src/slic3r/GUI/ButtonsDescription.cpp index fb4c24286..9def34749 100644 --- a/src/slic3r/GUI/ButtonsDescription.cpp +++ b/src/slic3r/GUI/ButtonsDescription.cpp @@ -7,6 +7,7 @@ #include "GUI.hpp" #include "GUI_App.hpp" #include "I18N.hpp" +#include "wxExtensions.hpp" namespace Slic3r { namespace GUI { @@ -23,7 +24,7 @@ ButtonsDescription::ButtonsDescription(wxWindow* parent, t_icon_descriptions* ic // Icon description for (auto pair : *m_icon_descriptions) { - auto icon = new wxStaticBitmap(this, wxID_ANY, *pair.first); + auto icon = new wxStaticBitmap(this, wxID_ANY, /***/pair.first->bmp()); grid_sizer->Add(icon, -1, wxALIGN_CENTRE_VERTICAL); std::istringstream f(pair.second); diff --git a/src/slic3r/GUI/ButtonsDescription.hpp b/src/slic3r/GUI/ButtonsDescription.hpp index 81baaf191..ccd992406 100644 --- a/src/slic3r/GUI/ButtonsDescription.hpp +++ b/src/slic3r/GUI/ButtonsDescription.hpp @@ -4,10 +4,12 @@ #include #include +class PrusaBitmap; + namespace Slic3r { namespace GUI { -using t_icon_descriptions = std::vector>; +using t_icon_descriptions = std::vector>; class ButtonsDescription : public wxDialog { diff --git a/src/slic3r/GUI/Field.cpp b/src/slic3r/GUI/Field.cpp index d77405230..22229d764 100644 --- a/src/slic3r/GUI/Field.cpp +++ b/src/slic3r/GUI/Field.cpp @@ -33,22 +33,21 @@ wxString double_to_string(double const value, const int max_precision /*= 4*/) void Field::PostInitialize() { auto color = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW); - m_Undo_btn = new MyButton(m_parent, wxID_ANY, "", wxDefaultPosition,wxDefaultSize, wxBU_EXACTFIT | wxNO_BORDER); - m_Undo_to_sys_btn = new MyButton(m_parent, wxID_ANY, "", wxDefaultPosition,wxDefaultSize, wxBU_EXACTFIT | wxNO_BORDER); - if (wxMSW) { - m_Undo_btn->SetBackgroundColour(color); - m_Undo_btn->SetBackgroundStyle(wxBG_STYLE_PAINT); - m_Undo_to_sys_btn->SetBackgroundColour(color); - m_Undo_to_sys_btn->SetBackgroundStyle(wxBG_STYLE_PAINT); - } + m_Undo_btn = new RevertButton(m_parent, "bullet_white.png");//(m_parent, wxID_ANY, "", wxDefaultPosition,wxDefaultSize, wxBU_EXACTFIT | wxNO_BORDER); + m_Undo_to_sys_btn = new RevertButton(m_parent, "bullet_white.png");//(m_parent, wxID_ANY, "", wxDefaultPosition,wxDefaultSize, wxBU_EXACTFIT | wxNO_BORDER); +// if (wxMSW) { +// m_Undo_btn->SetBackgroundColour(color); +// m_Undo_btn->SetBackgroundStyle(wxBG_STYLE_PAINT); +// m_Undo_to_sys_btn->SetBackgroundColour(color); +// m_Undo_to_sys_btn->SetBackgroundStyle(wxBG_STYLE_PAINT); +// } m_Undo_btn->Bind(wxEVT_BUTTON, ([this](wxCommandEvent) { on_back_to_initial_value(); })); m_Undo_to_sys_btn->Bind(wxEVT_BUTTON, ([this](wxCommandEvent) { on_back_to_sys_value(); })); //set default bitmap - wxBitmap bmp; - bmp.LoadFile(from_u8(var("bullet_white.png")), wxBITMAP_TYPE_PNG); - set_undo_bitmap(&bmp); - set_undo_to_sys_bitmap(&bmp); +// wxBitmap bmp = create_scaled_bitmap(m_parent, "bullet_white.png" ); +// set_undo_bitmap(&bmp); +// set_undo_to_sys_bitmap(&bmp); switch (m_opt.type) { @@ -213,8 +212,8 @@ bool is_defined_input_value(wxWindow* win, const ConfigOptionType& type) void TextCtrl::BUILD() { auto size = wxSize(wxDefaultSize); - if (m_opt.height >= 0) size.SetHeight(m_opt.height); - if (m_opt.width >= 0) size.SetWidth(m_opt.width); + if (m_opt.height >= 0) size.SetHeight(m_opt.height*wxGetApp().em_unit()); + if (m_opt.width >= 0) size.SetWidth(m_opt.width*wxGetApp().em_unit()); wxString text_value = wxString(""); @@ -358,6 +357,21 @@ boost::any& TextCtrl::get_value() return m_value; } +void TextCtrl::rescale() +{ + Field::rescale(); + auto size = wxSize(wxDefaultSize); + if (m_opt.height >= 0) size.SetHeight(m_opt.height*wxGetApp().em_unit()); + if (m_opt.width >= 0) size.SetWidth(m_opt.width*wxGetApp().em_unit()); + + if (size != wxDefaultSize) + { + wxTextCtrl* field = dynamic_cast(window); + field->SetMinSize(size); + } + +} + void TextCtrl::enable() { dynamic_cast(window)->Enable(); dynamic_cast(window)->SetEditable(true); } void TextCtrl::disable() { dynamic_cast(window)->Disable(); dynamic_cast(window)->SetEditable(false); } @@ -380,7 +394,8 @@ void CheckBox::BUILD() { static_cast(m_opt.default_value)->get_at(m_opt_idx) : false; - auto temp = new wxCheckBox(m_parent, wxID_ANY, wxString(""), wxDefaultPosition, size); + // Set Label as a string of at least one space simbol to correct system scaling of a CheckBox + auto temp = new wxCheckBox(m_parent, wxID_ANY, wxString(" "), wxDefaultPosition, size); temp->SetFont(Slic3r::GUI::wxGetApp().normal_font()); temp->SetBackgroundStyle(wxBG_STYLE_PAINT); temp->SetValue(check_value); @@ -505,10 +520,18 @@ void SpinCtrl::propagate_value() on_change_field(); } +void SpinCtrl::rescale() +{ + Field::rescale(); + + wxSpinCtrl* field = dynamic_cast(window); + field->SetMinSize(wxSize(-1, int(1.9f*field->GetFont().GetPixelSize().y))); +} + void Choice::BUILD() { - wxSize size(15 * wxGetApp().em_unit(), -1); - if (m_opt.height >= 0) size.SetHeight(m_opt.height); - if (m_opt.width >= 0) size.SetWidth(m_opt.width); + wxSize size(m_width * wxGetApp().em_unit(), -1); + if (m_opt.height >= 0) size.SetHeight(m_opt.height*wxGetApp().em_unit()); + if (m_opt.width >= 0) size.SetWidth(m_opt.width*wxGetApp().em_unit()); wxBitmapComboBox* temp; if (!m_opt.gui_type.empty() && m_opt.gui_type.compare("select_open") != 0) { @@ -817,6 +840,48 @@ boost::any& Choice::get_value() return m_value; } +void Choice::rescale() +{ + Field::rescale(); + + wxBitmapComboBox* field = dynamic_cast(window); + + const wxString selection = field->GetStringSelection(); + + /* To correct scaling (set new controll size) of a wxBitmapCombobox + * we need to refill control with new bitmaps. So, in our case : + * 1. clear conrol + * 2. add content + * 3. add scaled "empty" bitmap to the at least one item + */ + field->Clear(); + wxSize size(wxDefaultSize); + if (m_opt.height >= 0) size.SetHeight(m_opt.height * wxGetApp().em_unit()); + size.SetWidth((m_opt.width > 0 ? m_opt.width : m_width) * wxGetApp().em_unit()); + + field->SetSize(size); + + size_t idx, counter = idx = 0; + if (m_opt.enum_labels.empty() && m_opt.enum_values.empty()) {} + else{ + for (auto el : m_opt.enum_labels.empty() ? m_opt.enum_values : m_opt.enum_labels) { + const wxString& str = _(el); + field->Append(str); + if (el.compare(selection) == 0) + idx = counter; + ++counter; + } + } + + wxBitmap empty_bmp(1, field->GetFont().GetPixelSize().y + 2); + empty_bmp.SetWidth(0); + field->SetItemBitmap(0, empty_bmp); + + idx == m_opt.enum_values.size() ? + field->SetValue(selection) : + field->SetSelection(idx); +} + void ColourPicker::BUILD() { auto size = wxSize(wxDefaultSize); @@ -944,8 +1009,8 @@ boost::any& PointCtrl::get_value() void StaticText::BUILD() { auto size = wxSize(wxDefaultSize); - if (m_opt.height >= 0) size.SetHeight(m_opt.height); - if (m_opt.width >= 0) size.SetWidth(m_opt.width); + if (m_opt.height >= 0) size.SetHeight(m_opt.height*wxGetApp().em_unit()); + if (m_opt.width >= 0) size.SetWidth(m_opt.width*wxGetApp().em_unit()); const wxString legend(static_cast(m_opt.default_value)->value); auto temp = new wxStaticText(m_parent, wxID_ANY, legend, wxDefaultPosition, size, wxST_ELLIPSIZE_MIDDLE); @@ -959,6 +1024,21 @@ void StaticText::BUILD() temp->SetToolTip(get_tooltip_text(legend)); } +void StaticText::rescale() +{ + Field::rescale(); + + auto size = wxSize(wxDefaultSize); + if (m_opt.height >= 0) size.SetHeight(m_opt.height*wxGetApp().em_unit()); + if (m_opt.width >= 0) size.SetWidth(m_opt.width*wxGetApp().em_unit()); + + if (size != wxDefaultSize) + { + wxStaticText* field = dynamic_cast(window); + field->SetSize(size); + } +} + void SliderCtrl::BUILD() { auto size = wxSize(wxDefaultSize); diff --git a/src/slic3r/GUI/Field.hpp b/src/slic3r/GUI/Field.hpp index 128d60d47..4dfb4e239 100644 --- a/src/slic3r/GUI/Field.hpp +++ b/src/slic3r/GUI/Field.hpp @@ -19,6 +19,7 @@ #include "libslic3r/Utils.hpp" #include "GUI.hpp" +#include "wxExtensions.hpp" #ifdef __WXMSW__ #define wxMSW true @@ -36,19 +37,24 @@ using t_back_to_init = std::function; wxString double_to_string(double const value, const int max_precision = 4); -class MyButton : public wxButton +class RevertButton : public /*wxButton*/PrusaButton { bool hidden = false; // never show button if it's hidden ones public: - MyButton() {} - MyButton(wxWindow* parent, wxWindowID id, const wxString& label = wxEmptyString, - const wxPoint& pos = wxDefaultPosition, - const wxSize& size = wxDefaultSize, long style = 0, - const wxValidator& validator = wxDefaultValidator, - const wxString& name = wxTextCtrlNameStr) - { - this->Create(parent, id, label, pos, size, style, validator, name); - } +// RevertButton() {} +// RevertButton(wxWindow* parent, wxWindowID id, const wxString& label = wxEmptyString, +// const wxPoint& pos = wxDefaultPosition, +// const wxSize& size = wxDefaultSize, long style = 0, +// const wxValidator& validator = wxDefaultValidator, +// const wxString& name = wxTextCtrlNameStr) +// { +// this->Create(parent, id, label, pos, size, style, validator, name); +// } + RevertButton( + wxWindow *parent, + const std::string& icon_name = "" + ) : + PrusaButton(parent, wxID_ANY, icon_name) {} // overridden from wxWindow base class virtual bool @@ -154,19 +160,19 @@ public: return std::move(p); //!p; } - bool set_undo_bitmap(const wxBitmap *bmp) { + bool set_undo_bitmap(const /*wxBitmap*/PrusaBitmap *bmp) { if (m_undo_bitmap != bmp) { m_undo_bitmap = bmp; - m_Undo_btn->SetBitmap(*bmp); + m_Undo_btn->SetBitmap_(*bmp); return true; } return false; } - bool set_undo_to_sys_bitmap(const wxBitmap *bmp) { + bool set_undo_to_sys_bitmap(const /*wxBitmap*/PrusaBitmap *bmp) { if (m_undo_to_sys_bitmap != bmp) { m_undo_to_sys_bitmap = bmp; - m_Undo_to_sys_btn->SetBitmap(*bmp); + m_Undo_to_sys_btn->SetBitmap_(*bmp); return true; } return false; @@ -211,14 +217,19 @@ public: m_side_text = side_text; } + virtual void rescale() { + m_Undo_to_sys_btn->rescale(); + m_Undo_btn->rescale(); + } + protected: - MyButton* m_Undo_btn = nullptr; + RevertButton* m_Undo_btn = nullptr; // Bitmap and Tooltip text for m_Undo_btn. The wxButton will be updated only if the new wxBitmap pointer differs from the currently rendered one. - const wxBitmap* m_undo_bitmap = nullptr; + const /*wxBitmap*/PrusaBitmap* m_undo_bitmap = nullptr; const wxString* m_undo_tooltip = nullptr; - MyButton* m_Undo_to_sys_btn = nullptr; + RevertButton* m_Undo_to_sys_btn = nullptr; // Bitmap and Tooltip text for m_Undo_to_sys_btn. The wxButton will be updated only if the new wxBitmap pointer differs from the currently rendered one. - const wxBitmap* m_undo_to_sys_bitmap = nullptr; + const /*wxBitmap*/PrusaBitmap* m_undo_to_sys_bitmap = nullptr; const wxString* m_undo_to_sys_tooltip = nullptr; wxStaticText* m_Label = nullptr; @@ -273,6 +284,8 @@ public: } boost::any& get_value() override; + + void rescale() override; virtual void enable(); virtual void disable(); @@ -337,6 +350,8 @@ public: return m_value = tmp_value; } + void rescale() override; + void enable() override { dynamic_cast(window)->Enable(); } void disable() override { dynamic_cast(window)->Disable(); } wxWindow* getWindow() override { return window; } @@ -344,6 +359,7 @@ public: class Choice : public Field { using Field::Field; + int m_width{ 15 }; public: Choice(const ConfigOptionDef& opt, const t_config_option_key& id) : Field(opt, id) {} Choice(wxWindow* parent, const ConfigOptionDef& opt, const t_config_option_key& id) : Field(parent, opt, id) {} @@ -363,6 +379,8 @@ public: void set_values(const std::vector &values); boost::any& get_value() override; + void rescale() override; + void enable() override { dynamic_cast(window)->Enable(); }; void disable() override{ dynamic_cast(window)->Disable(); }; wxWindow* getWindow() override { return window; } @@ -446,6 +464,8 @@ public: boost::any& get_value()override { return m_value; } + void rescale() override; + void enable() override { dynamic_cast(window)->Enable(); }; void disable() override{ dynamic_cast(window)->Disable(); }; wxWindow* getWindow() override { return window; } diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index 049447e96..b0e585cb9 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -325,6 +325,13 @@ void GUI_App::init_fonts() #endif /*__WXMAC__*/ } +void GUI_App::scale_fonts(const float scale_f) +{ + m_small_font = m_small_font.Scaled(scale_f); + m_bold_font = m_bold_font.Scaled(scale_f); + m_normal_font = m_normal_font.Scaled(scale_f); +} + void GUI_App::set_label_clr_modified(const wxColour& clr) { m_color_label_modified = clr; auto clr_str = wxString::Format(wxT("#%02X%02X%02X"), clr.Red(), clr.Green(), clr.Blue()); diff --git a/src/slic3r/GUI/GUI_App.hpp b/src/slic3r/GUI/GUI_App.hpp index 41805702b..87c773164 100644 --- a/src/slic3r/GUI/GUI_App.hpp +++ b/src/slic3r/GUI/GUI_App.hpp @@ -98,6 +98,7 @@ public: void init_label_colours(); void update_label_colours_from_appconfig(); void init_fonts(); + void scale_fonts(const float scale_f); void set_label_clr_modified(const wxColour& clr); void set_label_clr_sys(const wxColour& clr); diff --git a/src/slic3r/GUI/GUI_ObjectList.cpp b/src/slic3r/GUI/GUI_ObjectList.cpp index dc3909351..c3bc808f4 100644 --- a/src/slic3r/GUI/GUI_ObjectList.cpp +++ b/src/slic3r/GUI/GUI_ObjectList.cpp @@ -2613,6 +2613,18 @@ void ObjectList::update_item_error_icon(const int obj_idx, const int vol_idx) co } } +void ObjectList::rescale() +{ + // update min size !!! Width shouldn't be a wxDefaultCoord + SetMinSize(wxSize(1, 15 * wxGetApp().em_unit())); + + GetColumn(0)->SetWidth(19 * wxGetApp().em_unit()); + GetColumn(1)->SetWidth(8 * wxGetApp().em_unit()); + GetColumn(2)->SetWidth(int(2 * wxGetApp().em_unit())); + + Layout(); +} + void ObjectList::ItemValueChanged(wxDataViewEvent &event) { if (event.GetColumn() == 0) diff --git a/src/slic3r/GUI/GUI_ObjectList.hpp b/src/slic3r/GUI/GUI_ObjectList.hpp index 2f465a4ab..c3d76f656 100644 --- a/src/slic3r/GUI/GUI_ObjectList.hpp +++ b/src/slic3r/GUI/GUI_ObjectList.hpp @@ -285,6 +285,9 @@ public: void rename_item(); void fix_through_netfabb() const; void update_item_error_icon(const int obj_idx, int vol_idx) const ; + + void rescale(); + private: void OnChar(wxKeyEvent& event); void OnContextMenu(wxDataViewEvent &event); diff --git a/src/slic3r/GUI/GUI_ObjectManipulation.cpp b/src/slic3r/GUI/GUI_ObjectManipulation.cpp index df54f16d4..358d85721 100644 --- a/src/slic3r/GUI/GUI_ObjectManipulation.cpp +++ b/src/slic3r/GUI/GUI_ObjectManipulation.cpp @@ -23,7 +23,7 @@ ObjectManipulation::ObjectManipulation(wxWindow* parent) : #endif // __APPLE__ { m_og->set_name(_(L("Object Manipulation"))); - m_og->label_width = 12 * wxGetApp().em_unit();//125; + m_og->label_width = 12;//125; m_og->set_grid_vgap(5); m_og->m_on_change = std::bind(&ObjectManipulation::on_change, this, std::placeholders::_1, std::placeholders::_2); @@ -45,11 +45,11 @@ ObjectManipulation::ObjectManipulation(wxWindow* parent) : def.label = L("Name"); def.gui_type = "legend"; def.tooltip = L("Object name"); - def.width = 21 * wxGetApp().em_unit(); + def.width = 21; def.default_value = new ConfigOptionString{ " " }; m_og->append_single_option_line(Option(def, "object_name")); - const int field_width = 5 * wxGetApp().em_unit()/*50*/; + const int field_width = 5; // Legend for object modification auto line = Line{ "", "" }; diff --git a/src/slic3r/GUI/GUI_ObjectSettings.cpp b/src/slic3r/GUI/GUI_ObjectSettings.cpp index 72eeb76de..fb9421a54 100644 --- a/src/slic3r/GUI/GUI_ObjectSettings.cpp +++ b/src/slic3r/GUI/GUI_ObjectSettings.cpp @@ -59,6 +59,8 @@ ObjectSettings::ObjectSettings(wxWindow* parent) : m_settings_list_sizer = new wxBoxSizer(wxVERTICAL); m_og->sizer->Add(m_settings_list_sizer, 1, wxEXPAND | wxLEFT, 5); + + m_bmp_delete = PrusaBitmap(parent, "cross"); } void ObjectSettings::update_settings_list() @@ -77,11 +79,12 @@ void ObjectSettings::update_settings_list() { auto opt_key = (line.get_options())[0].opt_id; //we assume that we have one option per line - auto btn = new wxBitmapButton(parent, wxID_ANY, create_scaled_bitmap(m_parent, "cross"/*"colorchange_delete_on.png"*/), - wxDefaultPosition, wxDefaultSize, wxBORDER_NONE); -#ifdef __WXMSW__ - btn->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)); -#endif // __WXMSW__ +// auto btn = new wxBitmapButton(parent, wxID_ANY, create_scaled_bitmap(m_parent, "cross"/*"colorchange_delete_on.png"*/), +// wxDefaultPosition, wxDefaultSize, wxBORDER_NONE); + auto btn = new PrusaButton(parent, wxID_ANY, m_bmp_delete); +//#ifdef __WXMSW__ +// btn->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)); +//#endif // __WXMSW__ btn->Bind(wxEVT_BUTTON, [opt_key, config, this](wxEvent &event) { config->erase(opt_key); wxGetApp().obj_list()->part_settings_changed(); @@ -123,7 +126,7 @@ void ObjectSettings::update_settings_list() continue; auto optgroup = std::make_shared(m_og->ctrl_parent(), cat.first, config, false, extra_column); - optgroup->label_width = 15 * wxGetApp().em_unit(); + optgroup->label_width = 15; optgroup->sidetext_width = 5.5 * wxGetApp().em_unit(); optgroup->m_on_change = [](const t_config_option_key& opt_id, const boost::any& value) { @@ -139,6 +142,15 @@ void ObjectSettings::update_settings_list() } optgroup->reload_config(); m_settings_list_sizer->Add(optgroup->sizer, 0, wxEXPAND | wxALL, 0); + + // call back for rescaling of the extracolumn control + optgroup->rescale_extra_column = [this](wxWindow* win) { + auto *ctrl = dynamic_cast(win); + if (ctrl == nullptr) + return; + ctrl->SetBitmap_(m_bmp_delete); + }; + m_og_settings.push_back(optgroup); categories.push_back(cat.first); @@ -163,5 +175,13 @@ void ObjectSettings::UpdateAndShow(const bool show) OG_Settings::UpdateAndShow(show); } +void ObjectSettings::rescale() +{ + m_bmp_delete.rescale(); + + for (auto group : m_og_settings) + group->rescale(); +} + } //namespace GUI } //namespace Slic3r \ No newline at end of file diff --git a/src/slic3r/GUI/GUI_ObjectSettings.hpp b/src/slic3r/GUI/GUI_ObjectSettings.hpp index 12115e208..17accda18 100644 --- a/src/slic3r/GUI/GUI_ObjectSettings.hpp +++ b/src/slic3r/GUI/GUI_ObjectSettings.hpp @@ -4,6 +4,7 @@ #include #include #include +#include "wxExtensions.hpp" class wxBoxSizer; @@ -37,12 +38,15 @@ class ObjectSettings : public OG_Settings // option groups for settings std::vector > m_og_settings; + PrusaBitmap m_bmp_delete; + public: ObjectSettings(wxWindow* parent); ~ObjectSettings() {} void update_settings_list(); void UpdateAndShow(const bool show) override; + void rescale(); }; }} diff --git a/src/slic3r/GUI/MainFrame.cpp b/src/slic3r/GUI/MainFrame.cpp index d6a3942d5..5f3434390 100644 --- a/src/slic3r/GUI/MainFrame.cpp +++ b/src/slic3r/GUI/MainFrame.cpp @@ -256,6 +256,7 @@ bool MainFrame::can_delete_all() const return (m_plater != nullptr) ? !m_plater->model().objects.empty() : false; } +// scale font for existing controls static void scale(wxWindow *window, const float scale_f) { auto children = window->GetChildren(); @@ -268,10 +269,9 @@ static void scale(wxWindow *window, const float scale_f) // const wxSize& sz = child->GetSize(); // if (sz != wxDefaultSize) -// child->SetSize(sz*scale_f); - - child->Layout(); +// child->SetSize(sz*scale_f); } + window->Layout(); } void MainFrame::on_dpi_changed(const wxRect &suggested_rect) @@ -286,28 +286,24 @@ void MainFrame::on_dpi_changed(const wxRect &suggested_rect) { Freeze(); + scale(this, new_sc_factor / old_sc_factor); + wxGetApp().scale_fonts(new_sc_factor / old_sc_factor); + 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().preset_bundle->load_default_preset_bitmaps(this); - wxGetApp().sidebar().scrolled_panel()->SetSize(40 * wxGetApp().em_unit(), -1); - wxGetApp().sidebar().scrolled_panel()->Layout(); + // update preset comboboxes on Plater + wxGetApp().sidebar().rescale(); // update preset comboboxes on Tabs for (auto tab : wxGetApp().tabs_list) - tab->rescale();//update_tab_ui(); + tab->rescale(); - // update preset comboboxes on Plater - wxGetApp().sidebar().update_all_preset_comboboxes(); - - Refresh(); Layout(); Thaw(); diff --git a/src/slic3r/GUI/OptionsGroup.cpp b/src/slic3r/GUI/OptionsGroup.cpp index df2f7b582..fda6b80ca 100644 --- a/src/slic3r/GUI/OptionsGroup.cpp +++ b/src/slic3r/GUI/OptionsGroup.cpp @@ -166,8 +166,11 @@ void OptionsGroup::append_line(const Line& line, wxStaticText** full_Label/* = n #endif /* __WXGTK__ */ // if we have an extra column, build it - if (extra_column) - grid_sizer->Add(extra_column(this->ctrl_parent(), line), 0, wxALIGN_CENTER_VERTICAL|wxRIGHT, 3); + if (extra_column) + { + m_extra_column_ptrs.push_back(extra_column(this->ctrl_parent(), line)); + grid_sizer->Add(m_extra_column_ptrs.back(), 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, 3); + } // Build a label if we have it wxStaticText* label=nullptr; @@ -180,10 +183,10 @@ void OptionsGroup::append_line(const Line& line, wxStaticText** full_Label/* = n label_style |= staticbox ? 0 : wxST_ELLIPSIZE_END; #endif /* __WXGTK__ */ label = new wxStaticText(this->ctrl_parent(), wxID_ANY, line.label + (line.label.IsEmpty() ? "" : ": "), - wxDefaultPosition, wxSize(label_width, -1), label_style); + wxDefaultPosition, wxSize(label_width*wxGetApp().em_unit(), -1), label_style); label->SetBackgroundStyle(wxBG_STYLE_PAINT); - label->SetFont(label_font); - label->Wrap(label_width); // avoid a Linux/GTK bug + label->SetFont(wxGetApp().normal_font()); + label->Wrap(label_width*wxGetApp().em_unit()); // avoid a Linux/GTK bug if (!line.near_label_widget) grid_sizer->Add(label, 0, (staticbox ? 0 : wxALIGN_RIGHT | wxRIGHT) | wxALIGN_CENTER_VERTICAL, line.label.IsEmpty() ? 0 : 5); else if (line.near_label_widget && line.label.IsEmpty()) @@ -235,14 +238,13 @@ void OptionsGroup::append_line(const Line& line, wxStaticText** full_Label/* = n wxSizer* sizer_tmp = sizer; // add label if any if (option.label != "") { -// wxString str_label = _(option.label); //! To correct translation by context have to use wxGETTEXT_IN_CONTEXT macro from wxWidget 3.1.1 wxString str_label = (option.label == "Top" || option.label == "Bottom") ? _CTX(option.label, "Layers") : _(option.label); label = new wxStaticText(this->ctrl_parent(), wxID_ANY, str_label + ": ", wxDefaultPosition, wxDefaultSize); label->SetBackgroundStyle(wxBG_STYLE_PAINT); - label->SetFont(label_font); + label->SetFont(wxGetApp().normal_font()); sizer_tmp->Add(label, 0, /*wxALIGN_RIGHT |*/ wxALIGN_CENTER_VERTICAL, 0); } @@ -269,7 +271,7 @@ void OptionsGroup::append_line(const Line& line, wxStaticText** full_Label/* = n auto sidetext = new wxStaticText( this->ctrl_parent(), wxID_ANY, _(option.sidetext), wxDefaultPosition, wxSize(sidetext_width, -1)/*wxDefaultSize*/, wxALIGN_LEFT); sidetext->SetBackgroundStyle(wxBG_STYLE_PAINT); - sidetext->SetFont(sidetext_font); + sidetext->SetFont(wxGetApp().normal_font()); sizer_tmp->Add(sidetext, 0, wxLEFT | wxALIGN_CENTER_VERTICAL, 4); field->set_side_text_ptr(sidetext); } @@ -478,6 +480,50 @@ bool ConfigOptionsGroup::update_visibility(ConfigOptionMode mode) { return true; } +void ConfigOptionsGroup::rescale() +{ + // update bitmaps for mode markers : set new (rescaled) bitmaps + if (rescale_extra_column) + for (auto extra_col : m_extra_column_ptrs) + rescale_extra_column(extra_col); + + // update undo buttons : rescale bitmaps + for (const auto& field : m_fields) + field.second->rescale(); + + // rescale width of label column + if (!m_options_mode.empty() && label_width > 1) + { + const int cols = m_grid_sizer->GetCols(); + const int rows = m_grid_sizer->GetEffectiveRowsCount(); + const int label_col = extra_column == nullptr ? 0 : 1; + + for (int i = 0; i < rows; i++) + { + const wxSizerItem* label_item = m_grid_sizer->GetItem(i*cols+label_col); + if (label_item->IsWindow()) + { + auto label = dynamic_cast(label_item->GetWindow()); + if (label != nullptr) { + label->SetMinSize(wxSize(label_width*wxGetApp().em_unit(), -1)); + } + } + else if (label_item->IsSizer()) // case when we nave near_label_widget + { + const wxSizerItem* l_item = label_item->GetSizer()->GetItem(1); + if (l_item->IsWindow()) + { + auto label = dynamic_cast(l_item->GetWindow()); + if (label != nullptr) { + label->SetMinSize(wxSize(label_width*wxGetApp().em_unit(), -1)); + } + } + } + } + m_grid_sizer->Layout(); + } +} + boost::any ConfigOptionsGroup::config_value(const std::string& opt_key, int opt_index, bool deserialize) { if (deserialize) { diff --git a/src/slic3r/GUI/OptionsGroup.hpp b/src/slic3r/GUI/OptionsGroup.hpp index dbe1ea1a2..34f571603 100644 --- a/src/slic3r/GUI/OptionsGroup.hpp +++ b/src/slic3r/GUI/OptionsGroup.hpp @@ -72,7 +72,7 @@ private: std::vector m_extra_widgets;//! {std::vector()}; }; -using column_t = std::function;//std::function; +using column_t = std::function; using t_optionfield_map = std::map; using t_opt_map = std::map< std::string, std::pair >; @@ -82,9 +82,10 @@ class OptionsGroup { public: const bool staticbox {true}; const wxString title {wxString("")}; - size_t label_width = 20 * wxGetApp().em_unit();// {200}; + size_t label_width = 20 ;// {200}; wxSizer* sizer {nullptr}; column_t extra_column {nullptr}; + std::function rescale_extra_column { nullptr }; t_change m_on_change { nullptr }; t_kill_focus m_fill_empty_value { nullptr }; t_kill_focus m_set_focus { nullptr }; @@ -191,6 +192,7 @@ protected: std::map m_options; wxWindow* m_parent {nullptr}; std::vector m_options_mode; + std::vector m_extra_column_ptrs; /// Field list, contains unique_ptrs of the derived type. /// using types that need to know what it is beyond the public interface @@ -259,6 +261,7 @@ public: void Hide(); void Show(const bool show); bool update_visibility(ConfigOptionMode mode); + void rescale(); boost::any config_value(const std::string& opt_key, int opt_index, bool deserialize); // return option value from config boost::any get_config_value(const DynamicPrintConfig& config, const std::string& opt_key, int opt_index = -1); diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 9a5fedfdc..5b7ac86fa 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -111,6 +111,7 @@ public: bool showing_manifold_warning_icon; void show_sizer(bool show); + void rescale(); }; ObjectInfo::ObjectInfo(wxWindow *parent) : @@ -118,10 +119,10 @@ ObjectInfo::ObjectInfo(wxWindow *parent) : { GetStaticBox()->SetFont(wxGetApp().bold_font()); - auto *grid_sizer = new wxFlexGridSizer(4, 5, 5); + auto *grid_sizer = new wxFlexGridSizer(4, 5, 15); grid_sizer->SetFlexibleDirection(wxHORIZONTAL); - grid_sizer->AddGrowableCol(1, 1); - grid_sizer->AddGrowableCol(3, 1); +// grid_sizer->AddGrowableCol(1, 1); +// grid_sizer->AddGrowableCol(3, 1); auto init_info_label = [parent, grid_sizer](wxStaticText **info_label, wxString text_label) { auto *text = new wxStaticText(parent, wxID_ANY, text_label+":"); @@ -161,6 +162,11 @@ void ObjectInfo::show_sizer(bool show) manifold_warning_icon->Show(showing_manifold_warning_icon && show); } +void ObjectInfo::rescale() +{ + manifold_warning_icon->SetBitmap(create_scaled_bitmap(nullptr, "exclamation_mark_")); +} + enum SlisedInfoIdx { siFilament_m, @@ -282,11 +288,12 @@ wxBitmapComboBox(parent, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(15 * }); } - edit_btn = new wxButton(parent, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT | wxNO_BORDER); -#ifdef __WINDOWS__ - edit_btn->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)); -#endif - edit_btn->SetBitmap(create_scaled_bitmap(this, "cog")); +// edit_btn = new wxButton(parent, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT | wxNO_BORDER); +// #ifdef __WINDOWS__ +// edit_btn->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)); +// #endif +// edit_btn->SetBitmap(create_scaled_bitmap(this, "cog")); + edit_btn = new PrusaButton(parent, wxID_ANY, "cog"); edit_btn->SetToolTip(_(L("Click to edit preset"))); edit_btn->Bind(wxEVT_BUTTON, ([preset_type, this](wxCommandEvent) @@ -332,6 +339,13 @@ void PresetComboBox::check_selection() this->last_selected = GetSelection(); } +void PresetComboBox::rescale() +{ + // update min control's height from new scaled size + this->SetMinSize(wxSize(20*wxGetApp().em_unit(), this->GetSize().GetHeight())); + edit_btn->rescale(); +} + // Frequently changed parameters class FreqChangedParams : public OG_Settings @@ -429,7 +443,7 @@ FreqChangedParams::FreqChangedParams(wxWindow* parent, const int label_width) : option = m_og->get_option("fill_density"); option.opt.label = L("Infill"); - option.opt.width = 6 * wxGetApp().em_unit(); + option.opt.width = 6; option.opt.sidetext = " "; line.append_option(option); @@ -615,9 +629,9 @@ void Sidebar::priv::show_preset_comboboxes() // Sidebar / public Sidebar::Sidebar(Plater *parent) - : wxPanel(parent), p(new priv(parent)) + : wxPanel(parent, wxID_ANY, wxDefaultPosition, wxSize(40 * wxGetApp().em_unit(), -1)), p(new priv(parent)) { - p->scrolled = new wxScrolledWindow(this, wxID_ANY, wxDefaultPosition, wxSize(40 * wxGetApp().em_unit(), -1)); + p->scrolled = new wxScrolledWindow(this, wxID_ANY/*, wxDefaultPosition, wxSize(40 * wxGetApp().em_unit(), -1)*/); p->scrolled->SetScrollbars(0, 20, 1, 2); @@ -676,13 +690,8 @@ Sidebar::Sidebar(Plater *parent) init_combo(&p->combo_sla_material, _(L("SLA material")), Preset::TYPE_SLA_MATERIAL, false); init_combo(&p->combo_printer, _(L("Printer")), Preset::TYPE_PRINTER, false); - // calculate width of the preset labels -// p->sizer_presets->Layout(); -// const wxArrayInt& ar = p->sizer_presets->GetColWidths(); -// const int label_width = ar.IsEmpty() ? 10*wxGetApp().em_unit() : ar.front()-4; - const int margin_5 = int(0.5*wxGetApp().em_unit());// 5; - const int margin_10 = int(1.5*wxGetApp().em_unit());// 15; + const int margin_10 = 10;//int(1.5*wxGetApp().em_unit());// 15; p->sizer_params = new wxBoxSizer(wxVERTICAL); @@ -704,10 +713,6 @@ Sidebar::Sidebar(Plater *parent) p->object_settings->Hide(); p->sizer_params->Add(p->object_settings->get_sizer(), 0, wxEXPAND | wxTOP, margin_5); - p->btn_send_gcode = new wxButton(this, wxID_ANY, _(L("Send to printer"))); - p->btn_send_gcode->SetFont(wxGetApp().bold_font()); - p->btn_send_gcode->Hide(); - // Info boxes p->object_info = new ObjectInfo(p->scrolled); p->sliced_info = new SlicedInfo(p->scrolled); @@ -722,10 +727,16 @@ Sidebar::Sidebar(Plater *parent) scrolled_sizer->Add(p->sliced_info, 0, wxEXPAND | wxTOP | wxLEFT, margin_5); // Buttons underneath the scrolled area - p->btn_export_gcode = new wxButton(this, wxID_ANY, _(L("Export G-code")) + dots); - p->btn_export_gcode->SetFont(wxGetApp().bold_font()); - p->btn_reslice = new wxButton(this, wxID_ANY, _(L("Slice now"))); - p->btn_reslice->SetFont(wxGetApp().bold_font()); + + auto init_btn = [this](wxButton **btn, wxString label) { + *btn = new wxButton(this, wxID_ANY, label); + (*btn)->SetFont(wxGetApp().bold_font()); + }; + + init_btn(&p->btn_send_gcode, _(L("Send to printer"))); + p->btn_send_gcode->Hide(); + init_btn(&p->btn_export_gcode, _(L("Export G-code")) + dots); + init_btn(&p->btn_reslice, _(L("Slice now"))); enable_buttons(false); auto *btns_sizer = new wxBoxSizer(wxVERTICAL); @@ -888,6 +899,40 @@ void Sidebar::update_reslice_btn_tooltip() const p->btn_reslice->SetToolTip(tooltip); } +void Sidebar::rescale() +{ + SetMinSize(wxSize(40 * wxGetApp().em_unit(), -1)); + + p->mode_sizer->rescale(); + + // first of all : recreate preset comboboxes, because of + // in AddBitmap() function autonaticaly set the size of controll + update_all_preset_comboboxes(); + // then rescale them to current min size to correct layout of the sidebar + for (PresetComboBox* combo : std::vector { p->combo_print, + p->combo_sla_print, + p->combo_sla_material, + p->combo_printer } ) + combo->rescale(); + + for (PresetComboBox* combo : p->combos_filament) + combo->rescale(); + + p->frequently_changed_parameters->get_og(true)->rescale(); + p->frequently_changed_parameters->get_og(false)->rescale(); + + p->object_list->rescale(); + + p->object_manipulation->get_og()->rescale(); + p->object_settings->rescale(); + + p->object_info->rescale(); + + p->scrolled->Layout(); + p->plater->Layout(); + p->plater->GetParent()->Layout(); +} + ObjectManipulation* Sidebar::obj_manipul() { return p->object_manipulation; diff --git a/src/slic3r/GUI/Plater.hpp b/src/slic3r/GUI/Plater.hpp index 75b71b982..b2d904a2e 100644 --- a/src/slic3r/GUI/Plater.hpp +++ b/src/slic3r/GUI/Plater.hpp @@ -14,6 +14,7 @@ #include "GLTexture.hpp" class wxButton; +class PrusaButton; class wxBoxSizer; class wxGLCanvas; class wxScrolledWindow; @@ -46,7 +47,7 @@ public: PresetComboBox(wxWindow *parent, Preset::Type preset_type); ~PresetComboBox(); - wxButton* edit_btn { nullptr }; + /*wxButton*/PrusaButton* edit_btn { nullptr }; enum LabelItemType { LABEL_ITEM_MARKER = 0x4d, @@ -58,6 +59,8 @@ public: int get_extruder_idx() const { return extruder_idx; } void check_selection(); + void rescale(); + private: typedef std::size_t Marker; @@ -83,6 +86,7 @@ public: void update_presets(Slic3r::Preset::Type preset_type); void update_mode_sizer() const; void update_reslice_btn_tooltip() const; + void rescale(); ObjectManipulation* obj_manipul(); ObjectList* obj_list(); diff --git a/src/slic3r/GUI/Preferences.cpp b/src/slic3r/GUI/Preferences.cpp index 8ffff1a41..96a2f3618 100644 --- a/src/slic3r/GUI/Preferences.cpp +++ b/src/slic3r/GUI/Preferences.cpp @@ -15,7 +15,7 @@ void PreferencesDialog::build() { auto app_config = get_app_config(); m_optgroup = std::make_shared(this, _(L("General"))); - m_optgroup->label_width = 40 * wxGetApp().em_unit(); //400; + m_optgroup->label_width = 40; //400; m_optgroup->m_on_change = [this](t_config_option_key opt_key, boost::any value){ m_values[opt_key] = boost::any_cast(value) ? "1" : "0"; }; @@ -110,6 +110,8 @@ void PreferencesDialog::build() auto sizer = new wxBoxSizer(wxVERTICAL); sizer->Add(m_optgroup->sizer, 0, wxEXPAND | wxBOTTOM | wxLEFT | wxRIGHT, 10); + SetFont(wxGetApp().normal_font()); + auto buttons = CreateStdDialogButtonSizer(wxOK | wxCANCEL); wxButton* btn = static_cast(FindWindowById(wxID_OK, this)); btn->Bind(wxEVT_BUTTON, [this](wxCommandEvent&) { accept(); }); diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index e1915f6f0..2dd277d7b 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -115,32 +115,43 @@ void Tab::create_preset_tab() auto color = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW); //buttons - wxBitmap bmpMenu; - bmpMenu = create_scaled_bitmap(this, "save"); - m_btn_save_preset = new wxBitmapButton(panel, wxID_ANY, bmpMenu, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE); - if (wxMSW) m_btn_save_preset->SetBackgroundColour(color); - bmpMenu = create_scaled_bitmap(this, "cross"/*"delete.png"*/); - m_btn_delete_preset = new wxBitmapButton(panel, wxID_ANY, bmpMenu, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE); - if (wxMSW) m_btn_delete_preset->SetBackgroundColour(color); + m_scaled_buttons.reserve(6); + m_scaled_buttons.reserve(2); +// wxBitmap bmpMenu; +// bmpMenu = create_scaled_bitmap(this, "save"); +// m_btn_save_preset = new wxBitmapButton(panel, wxID_ANY, bmpMenu, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE); +// if (wxMSW) m_btn_save_preset->SetBackgroundColour(color); +// bmpMenu = create_scaled_bitmap(this, "cross"/*"delete.png"*/); +// m_btn_delete_preset = new wxBitmapButton(panel, wxID_ANY, bmpMenu, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE); +// if (wxMSW) m_btn_delete_preset->SetBackgroundColour(color); + + add_scaled_button(panel, &m_btn_save_preset, "save"); + add_scaled_button(panel, &m_btn_delete_preset, "cross"); m_show_incompatible_presets = false; - m_bmp_show_incompatible_presets = create_scaled_bitmap(this, "flag_red"); - m_bmp_hide_incompatible_presets = create_scaled_bitmap(this, "flag_green"); - m_btn_hide_incompatible_presets = new wxBitmapButton(panel, wxID_ANY, m_bmp_hide_incompatible_presets, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE); - if (wxMSW) m_btn_hide_incompatible_presets->SetBackgroundColour(color); +// m_bmp_show_incompatible_presets = create_scaled_bitmap(this, "flag_red"); +// m_bmp_hide_incompatible_presets = create_scaled_bitmap(this, "flag_green"); + add_scaled_bitmap(this, m_bmp_show_incompatible_presets, "flag_red"); + add_scaled_bitmap(this, m_bmp_hide_incompatible_presets, "flag_green"); +// m_btn_hide_incompatible_presets = new wxBitmapButton(panel, wxID_ANY, m_bmp_hide_incompatible_presets, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE); +// if (wxMSW) m_btn_hide_incompatible_presets->SetBackgroundColour(color); + add_scaled_button(panel, &m_btn_hide_incompatible_presets, m_bmp_hide_incompatible_presets.name()); m_btn_save_preset->SetToolTip(_(L("Save current ")) + m_title); m_btn_delete_preset->SetToolTip(_(L("Delete this preset"))); m_btn_delete_preset->Disable(); - m_undo_btn = new wxButton(panel, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT | wxNO_BORDER); - m_undo_to_sys_btn = new wxButton(panel, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT | wxNO_BORDER); - m_question_btn = new wxButton(panel, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT | wxNO_BORDER); - if (wxMSW) { - m_undo_btn->SetBackgroundColour(color); - m_undo_to_sys_btn->SetBackgroundColour(color); - m_question_btn->SetBackgroundColour(color); - } +// m_undo_btn = new wxButton(panel, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT | wxNO_BORDER); +// m_undo_to_sys_btn = new wxButton(panel, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT | wxNO_BORDER); +// m_question_btn = new wxButton(panel, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT | wxNO_BORDER); + + add_scaled_button(panel, &m_question_btn, "question"); + +// if (wxMSW) { +// m_undo_btn->SetBackgroundColour(color); +// m_undo_to_sys_btn->SetBackgroundColour(color); +// m_question_btn->SetBackgroundColour(color); +// } m_question_btn->SetToolTip(_(L("Hover the cursor over buttons to find more information \n" "or click this button."))); @@ -148,22 +159,28 @@ void Tab::create_preset_tab() // Determine the theme color of OS (dark or light) auto luma = wxGetApp().get_colour_approx_luma(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)); // Bitmaps to be shown on the "Revert to system" aka "Lock to system" button next to each input field. - m_bmp_value_lock = create_scaled_bitmap(this, luma >= 128 ? "lock_closed" : "lock_closed_white"); - m_bmp_value_unlock = create_scaled_bitmap(this, "lock_open"); +// m_bmp_value_lock = create_scaled_bitmap(this, luma >= 128 ? "lock_closed" : "lock_closed_white"); +// m_bmp_value_unlock = create_scaled_bitmap(this, "lock_open"); + add_scaled_bitmap(this, m_bmp_value_lock , luma >= 128 ? "lock_closed" : "lock_closed_white"); + add_scaled_bitmap(this, m_bmp_value_unlock, "lock_open"); m_bmp_non_system = &m_bmp_white_bullet; // Bitmaps to be shown on the "Undo user changes" button next to each input field. - m_bmp_value_revert = create_scaled_bitmap(this, "undo"); - m_bmp_white_bullet = create_scaled_bitmap(this, "bullet_white.png"); - m_bmp_question = create_scaled_bitmap(this, "question"); +// m_bmp_value_revert = create_scaled_bitmap(this, "undo"); +// m_bmp_white_bullet = create_scaled_bitmap(this, "bullet_white.png"); + add_scaled_bitmap(this, m_bmp_value_revert, "undo"); + add_scaled_bitmap(this, m_bmp_white_bullet, "bullet_white.png"); fill_icon_descriptions(); set_tooltips_text(); - m_undo_btn->SetBitmap(m_bmp_white_bullet); + add_scaled_button(panel, &m_undo_btn, m_bmp_white_bullet.name()); + add_scaled_button(panel, &m_undo_to_sys_btn, m_bmp_white_bullet.name()); + +// m_undo_btn->SetBitmap(m_bmp_white_bullet); m_undo_btn->Bind(wxEVT_BUTTON, ([this](wxCommandEvent) { on_roll_back_value(); })); - m_undo_to_sys_btn->SetBitmap(m_bmp_white_bullet); +// m_undo_to_sys_btn->SetBitmap(m_bmp_white_bullet); m_undo_to_sys_btn->Bind(wxEVT_BUTTON, ([this](wxCommandEvent) { on_roll_back_value(true); })); - m_question_btn->SetBitmap(m_bmp_question); +// m_question_btn->SetBitmap(m_bmp_question); m_question_btn->Bind(wxEVT_BUTTON, ([this](wxCommandEvent) { auto dlg = new ButtonsDescription(this, &m_icon_descriptions); @@ -259,12 +276,32 @@ void Tab::create_preset_tab() toggle_show_hide_incompatible(); })); + // Fill cache for mode bitmaps + m_mode_bitmap_cache.reserve(3); + m_mode_bitmap_cache.push_back(PrusaBitmap(this, "mode_simple_.png")); + m_mode_bitmap_cache.push_back(PrusaBitmap(this, "mode_middle_.png")); + m_mode_bitmap_cache.push_back(PrusaBitmap(this, "mode_expert_.png")); + // Initialize the DynamicPrintConfig by default keys/values. build(); rebuild_page_tree(); m_complited = true; } +void Tab::add_scaled_button(wxWindow* parent, PrusaButton** btn, const std::string& icon_name, + const wxString& label/* = wxEmptyString*/, + long style /*= wxBU_EXACTFIT | wxNO_BORDER*/) +{ + *btn = new PrusaButton(parent, wxID_ANY, icon_name, label, wxDefaultSize, wxDefaultPosition, style); + m_scaled_buttons.push_back(*btn); +} + +void Tab::add_scaled_bitmap(wxWindow* parent, PrusaBitmap& bmp, const std::string& icon_name) +{ + bmp = PrusaBitmap(parent, icon_name); + m_scaled_bitmaps.push_back(&bmp); +} + void Tab::load_initial_data() { m_config = &m_presets->get_edited_preset().config; @@ -281,9 +318,9 @@ Slic3r::GUI::PageShp Tab::add_options_page(const wxString& title, const std::str icon_idx = (m_icon_index.find(icon) == m_icon_index.end()) ? -1 : m_icon_index.at(icon); if (icon_idx == -1) { // Add a new icon to the icon list. -// wxIcon img_icon(from_u8(Slic3r::var(icon)), wxBITMAP_TYPE_PNG); -// m_icons->Add(img_icon); - m_icons->Add(create_scaled_bitmap(this, icon)); +// m_icons->Add(create_scaled_bitmap(this, icon)); + m_scaled_icons_list.push_back(PrusaBitmap(this, icon)); + m_icons->Add(m_scaled_icons_list.back().bmp()); icon_idx = ++m_icon_count; m_icon_index[icon] = icon_idx; } @@ -294,7 +331,7 @@ Slic3r::GUI::PageShp Tab::add_options_page(const wxString& title, const std::str #else auto panel = this; #endif - PageShp page(new Page(panel, title, icon_idx)); + PageShp page(new Page(panel, title, icon_idx, m_mode_bitmap_cache)); // page->SetBackgroundStyle(wxBG_STYLE_SYSTEM); #ifdef __WINDOWS__ // page->SetDoubleBuffered(true); @@ -402,8 +439,8 @@ void Tab::update_changed_ui() { bool is_nonsys_value = false; bool is_modified_value = true; - const wxBitmap *sys_icon = &m_bmp_value_lock; - const wxBitmap *icon = &m_bmp_value_revert; + const /*wxBitmap*/PrusaBitmap *sys_icon = &m_bmp_value_lock; + const /*wxBitmap*/PrusaBitmap *icon = &m_bmp_value_revert; const wxColour *color = &m_sys_label_clr; @@ -595,8 +632,8 @@ void Tab::update_changed_tree_ui() void Tab::update_undo_buttons() { - m_undo_btn->SetBitmap(m_is_modified_values ? m_bmp_value_revert : m_bmp_white_bullet); - m_undo_to_sys_btn->SetBitmap(m_is_nonsys_values ? *m_bmp_non_system : m_bmp_value_lock); + m_undo_btn-> SetBitmap_(m_is_modified_values ? m_bmp_value_revert: m_bmp_white_bullet); + m_undo_to_sys_btn-> SetBitmap_(m_is_nonsys_values ? *m_bmp_non_system : m_bmp_value_lock); m_undo_btn->SetToolTip(m_is_modified_values ? m_ttg_value_revert : m_ttg_white_bullet); m_undo_to_sys_btn->SetToolTip(m_is_nonsys_values ? *m_ttg_non_system : m_ttg_value_lock); @@ -730,10 +767,36 @@ void Tab::rescale() { m_em_unit = wxGetApp().em_unit(); + m_mode_sizer->rescale(); + m_presets_choice->SetSize(25 * m_em_unit, -1); - m_treectrl->SetSize(20 * m_em_unit, -1); + m_treectrl->SetMinSize(wxSize(20 * m_em_unit, -1)); update_tab_ui(); + + // rescale buttons and cached bitmaps + for (const auto btn : m_scaled_buttons) + btn->rescale(); + for (const auto bmp : m_scaled_bitmaps) + bmp->rescale(); + for (PrusaBitmap& bmp : m_mode_bitmap_cache) + bmp.rescale(); + + // rescale icons for tree_ctrl + for (PrusaBitmap& bmp : m_scaled_icons_list) + bmp.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 (PrusaBitmap& bmp : m_scaled_icons_list) + m_icons->Add(bmp.bmp()); + m_treectrl->AssignImageList(m_icons); + + // rescale options_groups + for (auto page : m_pages) + page->rescale(); + + Layout(); } Field* Tab::get_field(const t_config_option_key& opt_key, int opt_index/* = -1*/) const @@ -1131,10 +1194,10 @@ void TabPrint::build() optgroup->append_single_option_line("complete_objects"); line = { _(L("Extruder clearance (mm)")), "" }; Option option = optgroup->get_option("extruder_clearance_radius"); - option.opt.width = 60; + option.opt.width = 6; line.append_option(option); option = optgroup->get_option("extruder_clearance_height"); - option.opt.width = 60; + option.opt.width = 6; line.append_option(option); optgroup->append_line(line); @@ -1148,14 +1211,14 @@ void TabPrint::build() optgroup = page->new_optgroup(_(L("Post-processing scripts")), 0); option = optgroup->get_option("post_process"); option.opt.full_width = true; - option.opt.height = 5 * m_em_unit;//50; + option.opt.height = 5;//50; optgroup->append_single_option_line(option); page = add_options_page(_(L("Notes")), "note.png"); optgroup = page->new_optgroup(_(L("Notes")), 0); option = optgroup->get_option("notes"); option.opt.full_width = true; - option.opt.height = 25 * m_em_unit;//250; + option.opt.height = 25;//250; optgroup->append_single_option_line(option); page = add_options_page(_(L("Dependencies")), "wrench.png"); @@ -1468,7 +1531,7 @@ void TabFilament::build() optgroup->append_single_option_line("bridge_fan_speed"); optgroup->append_single_option_line("disable_fan_first_layers"); - optgroup = page->new_optgroup(_(L("Cooling thresholds")), 250); + optgroup = page->new_optgroup(_(L("Cooling thresholds")), 25); optgroup->append_single_option_line("fan_below_layer_time"); optgroup->append_single_option_line("slowdown_below_layer_time"); optgroup->append_single_option_line("min_print_speed"); @@ -1518,8 +1581,8 @@ void TabFilament::build() }; optgroup->append_line(line); - const int gcode_field_height = 15 * m_em_unit; // 150 - const int notes_field_height = 25 * m_em_unit; // 250 + const int gcode_field_height = 15; // 150 + const int notes_field_height = 25; // 250 page = add_options_page(_(L("Custom G-code")), "cog"); optgroup = page->new_optgroup(_(L("Start G-code")), 0); @@ -1616,8 +1679,8 @@ wxSizer* Tab::description_line_widget(wxWindow* parent, ogStaticText* *StaticTex { *StaticText = new ogStaticText(parent, ""); - auto font = (new wxSystemSettings)->GetFont(wxSYS_DEFAULT_GUI_FONT); - (*StaticText)->SetFont(font); +// auto font = (new wxSystemSettings)->GetFont(wxSYS_DEFAULT_GUI_FONT); + (*StaticText)->SetFont(wxGetApp().normal_font()); auto sizer = new wxBoxSizer(wxHORIZONTAL); sizer->Add(*StaticText, 1, wxEXPAND|wxALL, 0); @@ -1639,10 +1702,12 @@ void TabPrinter::build_printhost(ConfigOptionsGroup *optgroup) } auto printhost_browse = [=](wxWindow* parent) { - auto btn = m_printhost_browse_btn = new wxButton(parent, wxID_ANY, _(L(" Browse ")) + dots, - wxDefaultPosition, wxDefaultSize, wxBU_LEFT | wxBU_EXACTFIT); - btn->SetFont(Slic3r::GUI::wxGetApp().normal_font()); - btn->SetBitmap(create_scaled_bitmap(this, "zoom.png")); +// auto btn = m_printhost_browse_btn = new wxButton(parent, wxID_ANY, _(L(" Browse ")) + dots, +// wxDefaultPosition, wxDefaultSize, wxBU_LEFT | wxBU_EXACTFIT); +// btn->SetBitmap(create_scaled_bitmap(this, "zoom.png")); + add_scaled_button(parent, &m_printhost_browse_btn, "zoom.png", _(L(" Browse ")) + dots, wxBU_LEFT | wxBU_EXACTFIT); + PrusaButton* btn = m_printhost_browse_btn; + btn->SetFont(Slic3r::GUI::wxGetApp().normal_font()); auto sizer = new wxBoxSizer(wxHORIZONTAL); sizer->Add(btn); @@ -1657,11 +1722,13 @@ void TabPrinter::build_printhost(ConfigOptionsGroup *optgroup) return sizer; }; - auto print_host_test = [this](wxWindow* parent) { - auto btn = m_print_host_test_btn = new wxButton(parent, wxID_ANY, _(L("Test")), - wxDefaultPosition, wxDefaultSize, wxBU_LEFT | wxBU_EXACTFIT); - btn->SetFont(Slic3r::GUI::wxGetApp().normal_font()); - btn->SetBitmap(create_scaled_bitmap(this, "wrench.png")); + auto print_host_test = [this](wxWindow* parent) { +// auto btn = m_print_host_test_btn = new wxButton(parent, wxID_ANY, _(L("Test")), +// wxDefaultPosition, wxDefaultSize, wxBU_LEFT | wxBU_EXACTFIT); +// btn->SetBitmap(create_scaled_bitmap(this, "wrench.png")); + add_scaled_button(parent, &m_print_host_test_btn, "wrench_white", _(L("Test")), wxBU_LEFT | wxBU_EXACTFIT); + PrusaButton* btn = m_print_host_test_btn; + btn->SetFont(Slic3r::GUI::wxGetApp().normal_font()); auto sizer = new wxBoxSizer(wxHORIZONTAL); sizer->Add(btn); @@ -1774,9 +1841,13 @@ void TabPrinter::build_fff() Line line = optgroup->create_single_option_line("bed_shape");//{ _(L("Bed shape")), "" }; line.widget = [this](wxWindow* parent) { - auto btn = new wxButton(parent, wxID_ANY, _(L(" Set "))+dots, wxDefaultPosition, wxDefaultSize, wxBU_LEFT | wxBU_EXACTFIT); - btn->SetFont(wxGetApp().small_font()); - btn->SetBitmap(create_scaled_bitmap(this, "printer")); +// auto btn = new wxButton(parent, wxID_ANY, _(L(" Set "))+dots, wxDefaultPosition, wxDefaultSize, wxBU_LEFT | wxBU_EXACTFIT); +// btn->SetFont(wxGetApp().small_font()); +// btn->SetBitmap(create_scaled_bitmap(this, "printer")); + + PrusaButton* btn; + add_scaled_button(parent, &btn, "printer_white", _(L(" Set ")) + dots, wxBU_LEFT | wxBU_EXACTFIT); + btn->SetFont(wxGetApp().normal_font()); auto sizer = new wxBoxSizer(wxHORIZONTAL); sizer->Add(btn); @@ -1903,8 +1974,8 @@ void TabPrinter::build_fff() optgroup->append_single_option_line("use_volumetric_e"); optgroup->append_single_option_line("variable_layer_height"); - const int gcode_field_height = 15 * m_em_unit; // 150 - const int notes_field_height = 25 * m_em_unit; // 250 + const int gcode_field_height = 15; // 150 + const int notes_field_height = 25; // 250 page = add_options_page(_(L("Custom G-code")), "cog"); optgroup = page->new_optgroup(_(L("Start G-code")), 0); option = optgroup->get_option("start_gcode"); @@ -1975,9 +2046,14 @@ void TabPrinter::build_sla() Line line = optgroup->create_single_option_line("bed_shape");//{ _(L("Bed shape")), "" }; line.widget = [this](wxWindow* parent) { - auto btn = new wxButton(parent, wxID_ANY, _(L(" Set ")) + dots, wxDefaultPosition, wxDefaultSize, wxBU_LEFT | wxBU_EXACTFIT); - btn->SetFont(wxGetApp().small_font()); - btn->SetBitmap(create_scaled_bitmap(this, "printer")); +// auto btn = new wxButton(parent, wxID_ANY, _(L(" Set ")) + dots, wxDefaultPosition, wxDefaultSize, wxBU_LEFT | wxBU_EXACTFIT); +// btn->SetFont(wxGetApp().small_font()); +// btn->SetBitmap(create_scaled_bitmap(this, "printer")); + + PrusaButton* btn; + add_scaled_button(parent, &btn, "printer_white", _(L(" Set ")) + dots, wxBU_LEFT | wxBU_EXACTFIT); + btn->SetFont(wxGetApp().normal_font()); + auto sizer = new wxBoxSizer(wxHORIZONTAL); sizer->Add(btn); @@ -2033,7 +2109,7 @@ void TabPrinter::build_sla() optgroup = page->new_optgroup(_(L("Print Host upload"))); build_printhost(optgroup.get()); - const int notes_field_height = 25 * m_em_unit; // 250 + const int notes_field_height = 25; // 250 page = add_options_page(_(L("Notes")), "note.png"); optgroup = page->new_optgroup(_(L("Notes")), 0); @@ -2088,12 +2164,12 @@ PageShp TabPrinter::build_kinematics_page() // Legend for OptionsGroups auto optgroup = page->new_optgroup(""); optgroup->set_show_modified_btns_val(false); - optgroup->label_width = 23 * m_em_unit;// 230; + optgroup->label_width = 23;// 230; auto line = Line{ "", "" }; ConfigOptionDef def; def.type = coString; - def.width = 150; + def.width = 15; def.gui_type = "legend"; def.mode = comAdvanced; def.tooltip = L("Values in this column are for Full Power mode"); @@ -2887,7 +2963,7 @@ void Tab::toggle_show_hide_incompatible() void Tab::update_show_hide_incompatible_button() { - m_btn_hide_incompatible_presets->SetBitmap(m_show_incompatible_presets ? + m_btn_hide_incompatible_presets->SetBitmap_(m_show_incompatible_presets ? m_bmp_show_incompatible_presets : m_bmp_hide_incompatible_presets); m_btn_hide_incompatible_presets->SetToolTip(m_show_incompatible_presets ? "Both compatible an incompatible presets are shown. Click to hide presets not compatible with the current printer." : @@ -2919,10 +2995,11 @@ wxSizer* Tab::compatible_widget_create(wxWindow* parent, PresetDependencies &dep { deps.checkbox = new wxCheckBox(parent, wxID_ANY, _(L("All"))); deps.checkbox->SetFont(Slic3r::GUI::wxGetApp().normal_font()); - deps.btn = new wxButton(parent, wxID_ANY, _(L(" Set "))+dots, wxDefaultPosition, wxDefaultSize, wxBU_LEFT | wxBU_EXACTFIT); - deps.btn->SetFont(Slic3r::GUI::wxGetApp().normal_font()); +// deps.btn = new wxButton(parent, wxID_ANY, _(L(" Set "))+dots, wxDefaultPosition, wxDefaultSize, wxBU_LEFT | wxBU_EXACTFIT); + add_scaled_button(parent, &deps.btn, "printer_white", _(L(" Set ")) + dots, wxBU_LEFT | wxBU_EXACTFIT); + deps.btn->SetFont(Slic3r::GUI::wxGetApp().normal_font()); - deps.btn->SetBitmap(create_scaled_bitmap(this, "printer")); +// deps.btn->SetBitmap(create_scaled_bitmap(this, "printer")); auto sizer = new wxBoxSizer(wxHORIZONTAL); sizer->Add((deps.checkbox), 0, wxALIGN_CENTER_VERTICAL); @@ -3079,6 +3156,12 @@ void Page::update_visibility(ConfigOptionMode mode) m_show = ret_val; } +void Page::rescale() +{ + for (auto group : m_optgroups) + group->rescale(); +} + Field* Page::get_field(const t_config_option_key& opt_key, int opt_index /*= -1*/) const { Field* field = nullptr; @@ -3102,18 +3185,23 @@ bool Page::set_value(const t_config_option_key& opt_key, const boost::any& value // package Slic3r::GUI::Tab::Page; ConfigOptionsGroupShp Page::new_optgroup(const wxString& title, int noncommon_label_width /*= -1*/) { - auto extra_column = [](wxWindow* parent, const Line& line) + auto extra_column = [this](wxWindow* parent, const Line& line) { std::string bmp_name; const std::vector