From 9ce3086f0209fdea07285635b50aceb79b49602a Mon Sep 17 00:00:00 2001 From: YuSanka Date: Tue, 8 Sep 2020 13:40:14 +0200 Subject: [PATCH 1/3] Splash screen : Try to fix scaling on Linux --- src/slic3r/GUI/GUI_App.cpp | 51 ++++++++++++++++++++++++-------------- 1 file changed, 33 insertions(+), 18 deletions(-) diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index c16aeaada..1e0d4ef85 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -78,23 +78,33 @@ namespace GUI { class MainFrame; // ysFIXME -static int get_dpi_for_main_display() +static float get_scale_for_main_display() { wxFrame fr(nullptr, wxID_ANY, wxEmptyString); - return get_dpi_for_window(&fr); + +#if ENABLE_WX_3_1_3_DPI_CHANGED_EVENT && !defined(__WXGTK__) + int dpi = get_dpi_for_window(&fr); + float sf = dpi != DPI_DEFAULT ? sf = (float)dpi / DPI_DEFAULT : 1.0; +#else + printf("dpi = %d\n", get_dpi_for_window(&fr)); + // initialize default width_unit according to the width of the one symbol ("m") of the currently active font of this window. + float sf = 0.1 * std::max(10, fr.GetTextExtent("m").x - 1); +#endif // ENABLE_WX_3_1_3_DPI_CHANGED_EVENT + + printf("scale factor = %f\n", sf); + return sf; } // scale input bitmap and return scale factor static float scale_bitmap(wxBitmap& bmp) { - int dpi = get_dpi_for_main_display(); - float sf = 1.0; + float sf = get_scale_for_main_display(); + // scale bitmap if needed - if (dpi != DPI_DEFAULT) { + if (sf > 1.0) { wxImage image = bmp.ConvertToImage(); if (image.IsOk() && image.GetWidth() != 0 && image.GetHeight() != 0) { - sf = (float)dpi / DPI_DEFAULT; int width = int(sf * image.GetWidth()); int height = int(sf * image.GetHeight()); image.Rescale(width, height, wxIMAGE_QUALITY_BILINEAR); @@ -102,11 +112,13 @@ static float scale_bitmap(wxBitmap& bmp) bmp = wxBitmap(std::move(image)); } } + return sf; } -static void word_wrap_string(wxString& input, int line_len) +static void word_wrap_string(wxString& input, int line_px_len, float scalef) { + int line_len = std::roundf( (float)line_px_len / (scalef * 10)) + 10; int idx = -1; int cur_len = 0; for (size_t i = 0; i < input.Len(); i++) @@ -136,11 +148,12 @@ static void DecorateSplashScreen(wxBitmap& bmp) wxMemoryDC memDc(bmp); // draw an dark grey box at the left of the splashscreen. - // this box will be 2/9 of the weight of the bitmap, and be at the left. - const wxRect bannerRect(wxPoint(0, (bmp.GetHeight() / 9) * 2 - 2), wxPoint((bmp.GetWidth() / 5) * 2, bmp.GetHeight())); + // this box will be 2/5 of the weight of the bitmap, and be at the left. + int banner_width = (bmp.GetWidth() / 5) * 2 - 2; + const wxRect banner_rect(wxPoint(0, (bmp.GetHeight() / 9) * 2), wxPoint(banner_width, bmp.GetHeight())); wxDCBrushChanger bc(memDc, wxBrush(wxColour(51, 51, 51))); wxDCPenChanger pc(memDc, wxPen(wxColour(51, 51, 51))); - memDc.DrawRectangle(bannerRect); + memDc.DrawRectangle(banner_rect); // title wxString title_string = SLIC3R_APP_NAME; @@ -156,14 +169,15 @@ static void DecorateSplashScreen(wxBitmap& bmp) wxString cr_symbol = wxString::FromUTF8("\xc2\xa9"); wxString copyright_string = wxString::Format("%s 2016-%s Prusa Research.\n" "%s 2011-2018 Alessandro Ranellucci.", - cr_symbol, year.Mid(year.Length() - 4), cr_symbol); + cr_symbol, year.Mid(year.Length() - 4), cr_symbol) + "\n\n"; wxFont copyright_font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT).Larger(); - copyright_string += "Slic3r" + _L("is licensed under the") + _L("GNU Affero General Public License, version 3") + "\n\n" + + copyright_string += //"Slic3r" + _L("is licensed under the") + _L("GNU Affero General Public License, version 3") + "\n\n" + _L("PrusaSlicer is based on Slic3r by Alessandro Ranellucci and the RepRap community.") + "\n\n" + _L("Contributions by Henrik Brix Andersen, Nicolas Dandrimont, Mark Hindess, Petr Ledvina, Joseph Lenox, Y. Sapir, Mike Sheldrake, Vojtech Bubnik and numerous others."); - word_wrap_string(copyright_string, 50); +// word_wrap_string(copyright_string, 50); + word_wrap_string(copyright_string, banner_width, scale_factor); wxCoord margin = int(scale_factor * 20); @@ -171,13 +185,13 @@ static void DecorateSplashScreen(wxBitmap& bmp) memDc.SetTextForeground(wxColour(237, 107, 33)); memDc.SetFont(title_font); - memDc.DrawLabel(title_string, bannerRect.Deflate(margin, 0), wxALIGN_TOP | wxALIGN_LEFT); + memDc.DrawLabel(title_string, banner_rect.Deflate(margin, 0), wxALIGN_TOP | wxALIGN_LEFT); memDc.SetFont(version_font); - memDc.DrawLabel(version_string, bannerRect.Deflate(margin, 2 * margin), wxALIGN_TOP | wxALIGN_LEFT); + memDc.DrawLabel(version_string, banner_rect.Deflate(margin, 2 * margin), wxALIGN_TOP | wxALIGN_LEFT); memDc.SetFont(copyright_font); - memDc.DrawLabel(copyright_string, bannerRect.Deflate(margin, 2 * margin), wxALIGN_BOTTOM | wxALIGN_LEFT); + memDc.DrawLabel(copyright_string, banner_rect.Deflate(margin, 2 * margin), wxALIGN_BOTTOM | wxALIGN_LEFT); } class SplashScreen : public wxSplashScreen @@ -189,9 +203,10 @@ public: wxASSERT(bitmap.IsOk()); m_main_bitmap = bitmap; - int dpi = get_dpi_for_main_display(); +/* int dpi = get_dpi_for_main_display(); if (dpi != DPI_DEFAULT) - m_scale_factor = (float)dpi / DPI_DEFAULT; + m_scale_factor = (float)dpi / DPI_DEFAULT; */ + m_scale_factor = get_scale_for_main_display(); } void SetText(const wxString& text) From 07499ff9d099a2f2a3b2da5e6dfc8e7dba6f8f05 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Tue, 8 Sep 2020 15:15:00 +0200 Subject: [PATCH 2/3] Fixed Scale on Linux --- src/slic3r/GUI/GUI_App.cpp | 13 +++++++------ src/slic3r/GUI/GUI_Utils.hpp | 7 +++++-- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index 1e0d4ef85..7b6d8c5aa 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -77,9 +77,11 @@ namespace GUI { class MainFrame; -// ysFIXME static float get_scale_for_main_display() { + // ysFIXME : Workaround : + // wxFrame is created on the main monitor, so we can take a scale factor from this one + // before The Application and the Mainframe are created wxFrame fr(nullptr, wxID_ANY, wxEmptyString); #if ENABLE_WX_3_1_3_DPI_CHANGED_EVENT && !defined(__WXGTK__) @@ -118,7 +120,9 @@ static float scale_bitmap(wxBitmap& bmp) static void word_wrap_string(wxString& input, int line_px_len, float scalef) { + // calculate count od symbols in one line according to the scale int line_len = std::roundf( (float)line_px_len / (scalef * 10)) + 10; + int idx = -1; int cur_len = 0; for (size_t i = 0; i < input.Len(); i++) @@ -176,7 +180,6 @@ static void DecorateSplashScreen(wxBitmap& bmp) _L("PrusaSlicer is based on Slic3r by Alessandro Ranellucci and the RepRap community.") + "\n\n" + _L("Contributions by Henrik Brix Andersen, Nicolas Dandrimont, Mark Hindess, Petr Ledvina, Joseph Lenox, Y. Sapir, Mike Sheldrake, Vojtech Bubnik and numerous others."); -// word_wrap_string(copyright_string, 50); word_wrap_string(copyright_string, banner_width, scale_factor); wxCoord margin = int(scale_factor * 20); @@ -198,14 +201,12 @@ class SplashScreen : public wxSplashScreen { public: SplashScreen(const wxBitmap& bitmap, long splashStyle, int milliseconds, wxWindow* parent) - : wxSplashScreen(bitmap, splashStyle, milliseconds, parent, wxID_ANY) + : wxSplashScreen(bitmap, splashStyle, milliseconds, parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, + wxSIMPLE_BORDER | wxFRAME_NO_TASKBAR) { wxASSERT(bitmap.IsOk()); m_main_bitmap = bitmap; -/* int dpi = get_dpi_for_main_display(); - if (dpi != DPI_DEFAULT) - m_scale_factor = (float)dpi / DPI_DEFAULT; */ m_scale_factor = get_scale_for_main_display(); } diff --git a/src/slic3r/GUI/GUI_Utils.hpp b/src/slic3r/GUI/GUI_Utils.hpp index f29e0cd84..1c88de570 100644 --- a/src/slic3r/GUI/GUI_Utils.hpp +++ b/src/slic3r/GUI/GUI_Utils.hpp @@ -92,10 +92,13 @@ public: #ifndef __WXOSX__ // Don't call SetFont under OSX to avoid name cutting in ObjectList this->SetFont(m_normal_font); #endif - // initialize default width_unit according to the width of the one symbol ("m") of the currently active font of this window. -#if ENABLE_WX_3_1_3_DPI_CHANGED_EVENT + + // Linux specific issue : get_dpi_for_window(this) still doesn't responce to the Display's scale in new wxWidgets(3.1.3). + // So, calculate the m_em_unit value from the font size, as before +#if ENABLE_WX_3_1_3_DPI_CHANGED_EVENT && !defined(__WXGTK__) m_em_unit = std::max(10, 10.0f * m_scale_factor); #else + // initialize default width_unit according to the width of the one symbol ("m") of the currently active font of this window. m_em_unit = std::max(10, this->GetTextExtent("m").x - 1); #endif // ENABLE_WX_3_1_3_DPI_CHANGED_EVENT From 3c14d883a1b9a73ae04324a1dc062791e5721a2b Mon Sep 17 00:00:00 2001 From: YuSanka Date: Tue, 8 Sep 2020 16:11:01 +0200 Subject: [PATCH 3/3] PhysicalPrinterDialog: Fixed memory leak --- src/slic3r/GUI/PhysicalPrinterDialog.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/slic3r/GUI/PhysicalPrinterDialog.cpp b/src/slic3r/GUI/PhysicalPrinterDialog.cpp index ca2d62556..3d832ae56 100644 --- a/src/slic3r/GUI/PhysicalPrinterDialog.cpp +++ b/src/slic3r/GUI/PhysicalPrinterDialog.cpp @@ -187,8 +187,7 @@ PhysicalPrinterDialog::PhysicalPrinterDialog(wxString printer_name) : PhysicalPrinter* printer = printers.find_printer(into_u8(printer_name)); if (!printer) { const Preset& preset = wxGetApp().preset_bundle->printers.get_edited_preset(); - //FIXME Vojtech: WTF??? Memory leak? - printer = new PhysicalPrinter(into_u8(printer_name), m_printer.config, preset); + m_printer = PhysicalPrinter(into_u8(printer_name), m_printer.config, preset); // if printer_name is empty it means that new printer is created, so enable all items in the preset list m_presets.emplace_back(new PresetForPrinter(this, preset.name)); } @@ -197,9 +196,8 @@ PhysicalPrinterDialog::PhysicalPrinterDialog(wxString printer_name) : const std::set& preset_names = printer->get_preset_names(); for (const std::string& preset_name : preset_names) m_presets.emplace_back(new PresetForPrinter(this, preset_name)); + m_printer = *printer; } - assert(printer); - m_printer = *printer; if (m_presets.size() == 1) m_presets.front()->SuppressDelete();