diff --git a/src/GUI/Dialogs/PresetEditor.cpp b/src/GUI/Dialogs/PresetEditor.cpp index 0533fc911..b91f18935 100644 --- a/src/GUI/Dialogs/PresetEditor.cpp +++ b/src/GUI/Dialogs/PresetEditor.cpp @@ -15,7 +15,7 @@ PresetEditor::PresetEditor(wxWindow* parent, t_config_option_keys options) : { // choice menu this->_presets_choice = new wxChoice(this, wxID_ANY, wxDefaultPosition, wxSize(left_col_width, -1)); - this->_presets_choice->SetFont(small_font()); + this->_presets_choice->SetFont(ui_settings->small_font()); // buttons diff --git a/src/GUI/GUI.cpp b/src/GUI/GUI.cpp index d31344810..3a2bb3c11 100644 --- a/src/GUI/GUI.cpp +++ b/src/GUI/GUI.cpp @@ -10,6 +10,7 @@ #include "MainFrame.hpp" #include "GUI.hpp" #include "misc_ui.hpp" +#include "Settings.hpp" #include "Preset.hpp" // Logging mechanism @@ -48,6 +49,8 @@ bool App::OnInit() // TODO: Call a logging function with channel GUI, severity info for datadir path Slic3r::Log::info(LogChannel, (_("Data dir: ") + datadir).ToStdWstring()); + ui_settings = Settings::init_settings(); + // Load gui settings from slic3r.ini if (wxFileExists(slic3r_ini)) { /* @@ -62,15 +65,14 @@ bool App::OnInit() */ } - - this->gui_config->save_settings(); + ui_settings->save_settings(); // Load presets this->load_presets(); wxImage::AddHandler(new wxPNGHandler()); - MainFrame *frame = new MainFrame( "Slic3r", wxDefaultPosition, wxDefaultSize, this->gui_config); + MainFrame *frame = new MainFrame( "Slic3r", wxDefaultPosition, wxDefaultSize); this->SetTopWindow(frame); // Load init bundle @@ -135,18 +137,18 @@ bool App::OnInit() } void App::save_window_pos(const wxTopLevelWindow* window, const wxString& name ) { - this->gui_config->window_pos[name] = + ui_settings->window_pos[name] = std::make_tuple( window->GetScreenPosition(), window->GetSize(), window->IsMaximized()); - this->gui_config->save_settings(); + ui_settings->save_settings(); } void App::restore_window_pos(wxTopLevelWindow* window, const wxString& name ) { try { - auto tmp = gui_config->window_pos[name]; + auto tmp = ui_settings->window_pos[name]; const auto& size = std::get<1>(tmp); const auto& pos = std::get<0>(tmp); window->SetSize(size); diff --git a/src/GUI/GUI.hpp b/src/GUI/GUI.hpp index 96f18ca3b..d6e38f3b3 100644 --- a/src/GUI/GUI.hpp +++ b/src/GUI/GUI.hpp @@ -18,7 +18,7 @@ class App: public wxApp { public: virtual bool OnInit(); - App(std::shared_ptr config) : wxApp(), gui_config(config) {} + App() : wxApp() {} /// Save position, size, and maximize state for a TopLevelWindow (includes Frames) by name in Settings. void save_window_pos(const wxTopLevelWindow* window, const wxString& name ); @@ -33,7 +33,6 @@ public: void OnUnhandledException() override; private: - std::shared_ptr gui_config; // GUI-specific configuration options std::unique_ptr notifier {nullptr}; std::vector presets { preset_types, Presets() }; diff --git a/src/GUI/MainFrame.cpp b/src/GUI/MainFrame.cpp index 28fecd971..dfad27820 100644 --- a/src/GUI/MainFrame.cpp +++ b/src/GUI/MainFrame.cpp @@ -13,10 +13,8 @@ wxBEGIN_EVENT_TABLE(MainFrame, wxFrame) wxEND_EVENT_TABLE() MainFrame::MainFrame(const wxString& title, const wxPoint& pos, const wxSize& size) - : MainFrame(title, pos, size, nullptr) {} -MainFrame::MainFrame(const wxString& title, const wxPoint& pos, const wxSize& size, std::shared_ptr _gui_config) : wxFrame(NULL, wxID_ANY, title, pos, size), loaded(false), - tabpanel(nullptr), controller(nullptr), plater(nullptr), gui_config(_gui_config), preset_editor_tabs(std::map()) + tabpanel(nullptr), controller(nullptr), plater(nullptr), preset_editor_tabs(std::map()) { this->SetIcon(wxIcon(var("Slic3r_128px.png"), wxBITMAP_TYPE_PNG)); @@ -44,7 +42,7 @@ MainFrame::MainFrame(const wxString& title, const wxPoint& pos, const wxSize& si this->SetMinSize(wxSize(760, 490)); this->SetSize(this->GetMinSize()); wxTheApp->SetTopWindow(this); - gui_config->restore_window_pos(this, "main_frame"); + ui_settings->restore_window_pos(this, "main_frame"); this->Show(); this->Layout(); } @@ -67,7 +65,7 @@ MainFrame::MainFrame(const wxString& title, const wxPoint& pos, const wxSize& si */ // save window size - gui_config->save_window_pos(this, "main_frame"); + ui_settings->save_window_pos(this, "main_frame"); // Propagate event e.Skip(); @@ -87,7 +85,7 @@ void MainFrame::init_tabpanel() // TODO: trigger processing for activation event if (tabpanel->GetSelection() > 1) { tabpanel->SetWindowStyle(tabpanel->GetWindowStyleFlag() | wxAUI_NB_CLOSE_ON_ACTIVE_TAB); - } else if (this->gui_config->show_host == false && tabpanel->GetSelection() == 1) { + } else if (ui_settings->show_host == false && tabpanel->GetSelection() == 1) { tabpanel->SetWindowStyle(tabpanel->GetWindowStyleFlag() | wxAUI_NB_CLOSE_ON_ACTIVE_TAB); } else { tabpanel->SetWindowStyle(tabpanel->GetWindowStyleFlag() | ~wxAUI_NB_CLOSE_ON_ACTIVE_TAB); @@ -102,11 +100,11 @@ void MainFrame::init_tabpanel() wxTheApp->CallAfter([=] { this->tabpanel->SetSelection(0); }); }), panel->GetId()); - this->plater = new Slic3r::GUI::Plater(panel, _("Plater"), gui_config); + this->plater = new Slic3r::GUI::Plater(panel, _("Plater")); this->controller = new Slic3r::GUI::Controller(panel, _("Controller")); panel->AddPage(this->plater, this->plater->GetName()); - if (this->gui_config->show_host) panel->AddPage(this->controller, this->controller->GetName()); + if (ui_settings->show_host) panel->AddPage(this->controller, this->controller->GetName()); } diff --git a/src/GUI/MainFrame.hpp b/src/GUI/MainFrame.hpp index d5a8ca61c..54f0bfdc9 100644 --- a/src/GUI/MainFrame.hpp +++ b/src/GUI/MainFrame.hpp @@ -29,7 +29,6 @@ class MainFrame: public wxFrame { public: MainFrame(const wxString& title, const wxPoint& pos, const wxSize& size); - MainFrame(const wxString& title, const wxPoint& pos, const wxSize& size, std::shared_ptr _gui_config); ProgressStatusBar* statusbar {new ProgressStatusBar(this, -1)}; bool has_plater_menu() { return this->plater_menu != nullptr; } @@ -50,8 +49,6 @@ private: wxMenu* plater_menu {nullptr}; - - std::shared_ptr gui_config; std::map preset_editor_tabs; void on_plater_object_list_changed(bool force) {}; diff --git a/src/GUI/Plater.cpp b/src/GUI/Plater.cpp index 77a213680..a5fe7de9a 100644 --- a/src/GUI/Plater.cpp +++ b/src/GUI/Plater.cpp @@ -35,8 +35,8 @@ const auto TB_SETTINGS {wxNewId()}; const auto PROGRESS_BAR_EVENT = wxNewEventType(); -Plater::Plater(wxWindow* parent, const wxString& title, std::shared_ptr _settings) : - wxPanel(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, title), settings(_settings) +Plater::Plater(wxWindow* parent, const wxString& title) : + wxPanel(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, title) { // Set callback for status event for worker threads @@ -154,7 +154,7 @@ Plater::Plater(wxWindow* parent, const wxString& title, std::shared_ptrAdd(sizer, 0, wxEXPAND | wxBOTTOM, 5); auto* text {new wxStaticText(this, wxID_ANY, _("Object:"), wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT)}; - text->SetFont(small_font()); + text->SetFont(ui_settings->small_font()); sizer->Add(text, 0, wxALIGN_CENTER_VERTICAL); /* We supply a bogus width to wxChoice (sizer will override it and stretch @@ -162,7 +162,7 @@ Plater::Plater(wxWindow* parent, const wxString& title, std::shared_ptrobject_info.choice = new wxChoice(this, wxID_ANY, wxDefaultPosition, wxSize(100, -1)); - this->object_info.choice->SetFont(small_font()); + this->object_info.choice->SetFont(ui_settings->small_font()); sizer->Add(this->object_info.choice, 1, wxALIGN_CENTER_VERTICAL); // Select object on change. @@ -183,11 +183,11 @@ Plater::Plater(wxWindow* parent, const wxString& title, std::shared_ptrSetFont(small_font()); + text->SetFont(ui_settings->small_font()); grid_sizer->Add(text, 0); this->object_info.manifold = new wxStaticText(parent, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT); - this->object_info.manifold->SetFont(small_font()); + this->object_info.manifold->SetFont(ui_settings->small_font()); this->object_info.manifold_warning_icon = new wxStaticBitmap(this, wxID_ANY, wxBitmap(var("error.png"), wxBITMAP_TYPE_PNG)); this->object_info.manifold_warning_icon->Hide(); @@ -1091,7 +1091,7 @@ void Plater::build_preset_chooser() { break; } auto* text {new wxStaticText(this, wxID_ANY, name, wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT)}; - text->SetFont(small_font()); + text->SetFont(ui_settings->small_font()); auto* choice {new wxBitmapComboBox(this, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, 0, nullptr, wxCB_READONLY)}; this->preset_choosers[static_cast(group)] = choice; diff --git a/src/GUI/Plater.hpp b/src/GUI/Plater.hpp index 7dd226d89..f4cd4dbdf 100644 --- a/src/GUI/Plater.hpp +++ b/src/GUI/Plater.hpp @@ -68,7 +68,7 @@ struct info_fields { class Plater : public wxPanel { public: - Plater(wxWindow* parent, const wxString& title, std::shared_ptr _settings); + Plater(wxWindow* parent, const wxString& title); /// User-level function called through external interface. /// Pops file dialog. @@ -112,7 +112,6 @@ public: private: std::shared_ptr print {std::make_shared(Slic3r::Print())}; std::shared_ptr model {std::make_shared(Slic3r::Model())}; - std::shared_ptr settings {}; std::shared_ptr config { Slic3r::Config::new_from_defaults( {"bed_shape", "complete_objects", "extruder_clearance_radius", "skirts", "skirt_distance", @@ -266,11 +265,11 @@ template static void add_info_field(wxWindow* parent, T*& field, wxString name, wxGridSizer* sizer) { name << ":"; auto* text {new wxStaticText(parent, wxID_ANY, name, wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT)}; - text->SetFont(small_font()); + text->SetFont(ui_settings->small_font()); sizer->Add(text, 0); field = new wxStaticText(parent, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT); - field->SetFont(small_font()); + field->SetFont(ui_settings->small_font()); sizer->Add(field, 0); } diff --git a/src/GUI/Plater/Plate2D.cpp b/src/GUI/Plater/Plate2D.cpp index 05573b750..e83836adc 100644 --- a/src/GUI/Plater/Plate2D.cpp +++ b/src/GUI/Plater/Plate2D.cpp @@ -13,8 +13,8 @@ namespace Slic3r { namespace GUI { -Plate2D::Plate2D(wxWindow* parent, const wxSize& size, std::vector& _objects, std::shared_ptr _model, std::shared_ptr _config, std::shared_ptr _settings) : - wxPanel(parent, wxID_ANY, wxDefaultPosition, size, wxTAB_TRAVERSAL), objects(_objects), model(_model), config(_config), settings(_settings) +Plate2D::Plate2D(wxWindow* parent, const wxSize& size, std::vector& _objects, std::shared_ptr _model, std::shared_ptr _config) : + wxPanel(parent, wxID_ANY, wxDefaultPosition, size, wxTAB_TRAVERSAL), objects(_objects), model(_model), config(_config) { this->Bind(wxEVT_PAINT, [this](wxPaintEvent &e) { this->repaint(e); }); @@ -56,8 +56,8 @@ void Plate2D::repaint(wxPaintEvent& e) { // On MacOS the background is erased, on Windows the background is not erased // and on Linux/GTK the background is erased to gray color. // Fill DC with the background on Windows & Linux/GTK. - const auto& brush_background {wxBrush(this->settings->color->BACKGROUND255(), wxBRUSHSTYLE_SOLID)}; - const auto& pen_background {wxPen(this->settings->color->BACKGROUND255(), 1, wxPENSTYLE_SOLID)}; + const auto& brush_background {wxBrush(ui_settings->color->BACKGROUND255(), wxBRUSHSTYLE_SOLID)}; + const auto& pen_background {wxPen(ui_settings->color->BACKGROUND255(), 1, wxPENSTYLE_SOLID)}; dc.SetPen(pen_background); dc.SetBrush(brush_background); const auto& rect {this->GetUpdateRegion().GetBox()}; diff --git a/src/GUI/Plater/Plate2D.hpp b/src/GUI/Plater/Plate2D.hpp index 67bbd4a57..6cadf0b00 100644 --- a/src/GUI/Plater/Plate2D.hpp +++ b/src/GUI/Plater/Plate2D.hpp @@ -12,7 +12,6 @@ #include "ColorScheme.hpp" #include "Plater.hpp" #include "Plater/PlaterObject.hpp" -#include "Settings.hpp" #include "misc_ui.hpp" #include "Log.hpp" @@ -39,7 +38,7 @@ class Plate2D : public wxPanel { public: /// Constructor. Keeps a reference to the main configuration, the model, and the gui settings. - Plate2D(wxWindow* parent, const wxSize& size, std::vector& _objects, std::shared_ptr _model, std::shared_ptr _config, std::shared_ptr _settings); + Plate2D(wxWindow* parent, const wxSize& size, std::vector& _objects, std::shared_ptr _model, std::shared_ptr _config); /// Read print bed size from config and calculate the scaled rendition of the bed given the draw canvas. void update_bed_size(); @@ -63,7 +62,6 @@ private: std::vector& objects; //< reference to parent vector std::shared_ptr model; std::shared_ptr config; - std::shared_ptr settings; /// Different brushes to draw with, initialized from settings->Color during the constructor wxBrush objects_brush {}; diff --git a/src/GUI/Plater/Preview2D.hpp b/src/GUI/Plater/Preview2D.hpp index 2a17b68da..a77239562 100644 --- a/src/GUI/Plater/Preview2D.hpp +++ b/src/GUI/Plater/Preview2D.hpp @@ -5,7 +5,6 @@ #include #endif -#include "Settings.hpp" #include "Model.hpp" #include "Config.hpp" @@ -14,7 +13,7 @@ namespace Slic3r { namespace GUI { class Preview2D : public wxPanel { public: void reload_print() {}; - Preview2D(wxWindow* parent, const wxSize& size, std::vector& _objects, std::shared_ptr _model, std::shared_ptr _config, std::shared_ptr _settings) : + Preview2D(wxWindow* parent, const wxSize& size, std::vector& _objects, std::shared_ptr _model, std::shared_ptr _config) : wxPanel(parent, wxID_ANY, wxDefaultPosition, size, wxTAB_TRAVERSAL), objects(_objects), model(_model), config(_config), settings(_settings) {} @@ -23,7 +22,6 @@ private: std::vector& objects; //< reference to parent vector std::shared_ptr model; std::shared_ptr config; - std::shared_ptr settings; }; } } // Namespace Slic3r::GUI diff --git a/src/GUI/Plater/Preview3D.hpp b/src/GUI/Plater/Preview3D.hpp index 49aa98c2d..3e2a66ab0 100644 --- a/src/GUI/Plater/Preview3D.hpp +++ b/src/GUI/Plater/Preview3D.hpp @@ -5,7 +5,6 @@ #include #endif -#include "Settings.hpp" #include "Model.hpp" #include "Config.hpp" @@ -14,7 +13,7 @@ namespace Slic3r { namespace GUI { class Preview3D : public wxPanel { public: void reload_print() {}; - Preview3D(wxWindow* parent, const wxSize& size, std::vector& _objects, std::shared_ptr _model, std::shared_ptr _config, std::shared_ptr _settings) : + Preview3D(wxWindow* parent, const wxSize& size, std::vector& _objects, std::shared_ptr _model, std::shared_ptr _config) : wxPanel(parent, wxID_ANY, wxDefaultPosition, size, wxTAB_TRAVERSAL), objects(_objects), model(_model), config(_config), settings(_settings) {} @@ -23,7 +22,6 @@ private: std::vector& objects; //< reference to parent vector std::shared_ptr model; std::shared_ptr config; - std::shared_ptr settings; }; } } // Namespace Slic3r::GUI diff --git a/src/GUI/Plater/PreviewDLP.hpp b/src/GUI/Plater/PreviewDLP.hpp index 17b52cae5..c4d80b99c 100644 --- a/src/GUI/Plater/PreviewDLP.hpp +++ b/src/GUI/Plater/PreviewDLP.hpp @@ -5,7 +5,6 @@ #include #endif -#include "Settings.hpp" #include "Model.hpp" #include "Config.hpp" @@ -14,7 +13,7 @@ namespace Slic3r { namespace GUI { class PreviewDLP : public wxPanel { public: void reload_print() {}; - PreviewDLP(wxWindow* parent, const wxSize& size, std::vector& _objects, std::shared_ptr _model, std::shared_ptr _config, std::shared_ptr _settings) : + PreviewDLP(wxWindow* parent, const wxSize& size, std::vector& _objects, std::shared_ptr _model, std::shared_ptr _config) : wxPanel(parent, wxID_ANY, wxDefaultPosition, size, wxTAB_TRAVERSAL), objects(_objects), model(_model), config(_config), settings(_settings) {} @@ -23,7 +22,6 @@ private: std::vector& objects; //< reference to parent vector std::shared_ptr model; std::shared_ptr config; - std::shared_ptr settings; }; } } // Namespace Slic3r::GUI diff --git a/src/GUI/Settings.cpp b/src/GUI/Settings.cpp index 23d5808d5..a0e8fea55 100644 --- a/src/GUI/Settings.cpp +++ b/src/GUI/Settings.cpp @@ -1,7 +1,20 @@ #include "Settings.hpp" +#include "misc_ui.hpp" namespace Slic3r { namespace GUI { +void Settings::Settings() { + // Initialize fonts + _small_font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); + if (the_os == OS::Mac) _small_font.SetPointSize(11); + _small_bold_font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); + if (the_os == OS::Mac) _small_bold_font.SetPointSize(11); + _small_bold_font.MakeBold() + _medium_font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); + _medium_font.SetPointSize(12); + + _scroll_step = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT)->GetPointSize(); +} void Settings::save_settings() { /* sub save_settings { diff --git a/src/GUI/Settings.hpp b/src/GUI/Settings.hpp index aaa9bd72b..d5b7b07be 100644 --- a/src/GUI/Settings.hpp +++ b/src/GUI/Settings.hpp @@ -6,6 +6,7 @@ #include #endif #include +#include #include #include "libslic3r.h" @@ -32,7 +33,7 @@ class Settings { bool invert_zoom {false}; bool background_processing {false}; - bool preset_editor_tabs {false}; + bool preset_editor_tabs {true}; bool hide_reload_dialog {false}; @@ -57,9 +58,31 @@ class Settings { void save_window_pos(wxWindow* ref, wxString name); void restore_window_pos(wxWindow* ref, wxString name); - private: - const std::string LogChannel {"GUI_Settings"}; //< Which log these messages should go to. + + const wxFont& small_font() { return _small_font;} + const wxFont& small_bold_font() { return _small_bold_font;} + const wxFont& medium_font() { return _medium_font;} + const int& scroll_step() { return _scroll_step; } + + static std::unique_ptr init_settings() { + return std::make_unique(); + } + Settings(Settings&&) = default; + Settings& operator=(Settings&&) = default; + Settings(); + private: + Settings& operator=(const Settings&) = default; + Settings(const Settings&) = default; + + const std::string LogChannel {"GUI_Settings"}; //< Which log these messages should go to. + + /// Fonts used by the UI. + wxFont _small_font; + wxFont _small_bold_font; + wxFont _medium_font; + + int _scroll_step {0}; }; }} //namespace Slic3r::GUI diff --git a/src/GUI/misc_ui.cpp b/src/GUI/misc_ui.cpp index 95febae57..41c1f17f0 100644 --- a/src/GUI/misc_ui.cpp +++ b/src/GUI/misc_ui.cpp @@ -147,7 +147,5 @@ std::vector open_model(wxWindow* parent, const Settings& settings, wxW return tmp; } -wxFont small_font() { return wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); } - }} // namespace Slic3r::GUI diff --git a/src/GUI/misc_ui.hpp b/src/GUI/misc_ui.hpp index cbf1e5134..cc4d5e158 100644 --- a/src/GUI/misc_ui.hpp +++ b/src/GUI/misc_ui.hpp @@ -11,6 +11,7 @@ #include #include #include +#include #include "Settings.hpp" @@ -22,6 +23,7 @@ /// Avoids wx pollution of libslic3r #define LOG_WSTRING(...) ((wxString("") << __VA_ARGS__).ToStdWstring()) + /// Common static (that is, free-standing) functions, not part of an object hierarchy. namespace Slic3r { namespace GUI { @@ -51,8 +53,6 @@ constexpr bool isDev = false; constexpr bool threaded = false; -/// Font definition -wxFont small_font(); // hopefully the compiler is smart enough to figure this out const std::map FILE_WILDCARDS { @@ -152,6 +152,9 @@ std::vector open_model(wxWindow* parent, const Settings& settings, wxW inline Slic3r::Point new_scale(const wxPoint& p) { return Slic3r::Point::new_scale(p.x, p.y); } +/// Singleton for UI settings. +std::unique_ptr ui_settings {nullptr}; + }} // namespace Slic3r::GUI #endif // MISC_UI_HPP