From 0bcb449fb4e3771b35f9f5b4e7d819d47f1f6eb7 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Wed, 15 May 2019 16:44:33 +0200 Subject: [PATCH 1/2] em_unit initialization in one place (DPIAware constructor) --- src/slic3r/GUI/GUI_Utils.hpp | 4 ++-- src/slic3r/GUI/MainFrame.cpp | 4 ++-- src/slic3r/GUI/Tab.cpp | 5 +++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/slic3r/GUI/GUI_Utils.hpp b/src/slic3r/GUI/GUI_Utils.hpp index 8cefb68d0..d7bf2a014 100644 --- a/src/slic3r/GUI/GUI_Utils.hpp +++ b/src/slic3r/GUI/GUI_Utils.hpp @@ -65,8 +65,8 @@ public: if (std::abs(m_scale_factor - scale_primary_display) > 1e-6) m_normal_font = m_normal_font.Scale(m_scale_factor / scale_primary_display); - // An analog of em_unit value from GUI_App. - m_em_unit = std::max(10, 10 * m_scale_factor); + // 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/*10 * m_scale_factor*/); // recalc_font(); diff --git a/src/slic3r/GUI/MainFrame.cpp b/src/slic3r/GUI/MainFrame.cpp index 296776da4..f1526aaf6 100644 --- a/src/slic3r/GUI/MainFrame.cpp +++ b/src/slic3r/GUI/MainFrame.cpp @@ -42,7 +42,7 @@ DPIFrame(NULL, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_S this->SetFont(this->normal_font()); #endif // initialize default width_unit according to the width of the one symbol ("m") of the currently active font of this window. - wxGetApp().set_em_unit(std::max(10, GetTextExtent("m").x - 1)); +// wxGetApp().set_em_unit(std::max(10, GetTextExtent("m").x - 1)); // Load the icon either from the exe, or from the ico file. #if _WIN32 @@ -316,7 +316,7 @@ void MainFrame::on_dpi_changed(const wxRect &suggested_rect) wxGetApp().update_fonts(); this->SetFont(this->normal_font()); // initialize default width_unit according to the width of the one symbol ("m") of the currently active font of this window. - wxGetApp().set_em_unit(std::max(10, GetTextExtent("m").x - 1)); +// wxGetApp().set_em_unit(std::max(10, GetTextExtent("m").x - 1)); /* Load default preset bitmaps before a tabpanel initialization, * but after filling of an em_unit value diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index a9f63afd8..acd1b9087 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -178,7 +178,7 @@ void Tab::create_preset_tab() // Sizer with buttons for mode changing m_mode_sizer = new ModeSizer(panel); - const float scale_factor = wxGetApp().em_unit()*0.1;// GetContentScaleFactor(); + const float scale_factor = /*wxGetApp().*/em_unit(this)*0.1;// GetContentScaleFactor(); m_hsizer = new wxBoxSizer(wxHORIZONTAL); sizer->Add(m_hsizer, 0, wxEXPAND | wxBOTTOM, 3); m_hsizer->Add(m_presets_choice, 0, wxLEFT | wxRIGHT | wxTOP | wxALIGN_CENTER_VERTICAL, 3); @@ -212,7 +212,8 @@ void Tab::create_preset_tab() m_treectrl = new wxTreeCtrl(panel, wxID_ANY, wxDefaultPosition, wxSize(20 * m_em_unit, -1), wxTR_NO_BUTTONS | wxTR_HIDE_ROOT | wxTR_SINGLE | wxTR_NO_LINES | wxBORDER_SUNKEN | wxWANTS_CHARS); m_left_sizer->Add(m_treectrl, 1, wxEXPAND); - m_icons = new wxImageList(int(16 * scale_factor), int(16 * scale_factor), true, 1); + const int img_sz = int(16 * scale_factor + 0.5f); + m_icons = new wxImageList(img_sz, img_sz, true, 1); // Index of the last icon inserted into $self->{icons}. m_icon_count = -1; m_treectrl->AssignImageList(m_icons); From cc933789ebcc55d92a05ff765db06936093a062b Mon Sep 17 00:00:00 2001 From: YuSanka Date: Thu, 16 May 2019 13:16:43 +0200 Subject: [PATCH 2/2] Fix of #2249 --- src/slic3r/GUI/GUI_Utils.hpp | 2 +- src/slic3r/GUI/MainFrame.cpp | 4 ---- src/slic3r/GUI/wxExtensions.cpp | 6 +++--- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/slic3r/GUI/GUI_Utils.hpp b/src/slic3r/GUI/GUI_Utils.hpp index d7bf2a014..9577cebf4 100644 --- a/src/slic3r/GUI/GUI_Utils.hpp +++ b/src/slic3r/GUI/GUI_Utils.hpp @@ -66,7 +66,7 @@ public: m_normal_font = m_normal_font.Scale(m_scale_factor / scale_primary_display); // 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/*10 * m_scale_factor*/); + m_em_unit = std::max(10, this->GetTextExtent("m").x - 1); // recalc_font(); diff --git a/src/slic3r/GUI/MainFrame.cpp b/src/slic3r/GUI/MainFrame.cpp index f1526aaf6..41d25cff3 100644 --- a/src/slic3r/GUI/MainFrame.cpp +++ b/src/slic3r/GUI/MainFrame.cpp @@ -41,8 +41,6 @@ DPIFrame(NULL, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_S #ifndef __WXOSX__ // Don't call SetFont under OSX to avoid name cutting in ObjectList this->SetFont(this->normal_font()); #endif - // initialize default width_unit according to the width of the one symbol ("m") of the currently active font of this window. -// wxGetApp().set_em_unit(std::max(10, GetTextExtent("m").x - 1)); // Load the icon either from the exe, or from the ico file. #if _WIN32 @@ -315,8 +313,6 @@ void MainFrame::on_dpi_changed(const wxRect &suggested_rect) { wxGetApp().update_fonts(); this->SetFont(this->normal_font()); - // initialize default width_unit according to the width of the one symbol ("m") of the currently active font of this window. -// wxGetApp().set_em_unit(std::max(10, GetTextExtent("m").x - 1)); /* Load default preset bitmaps before a tabpanel initialization, * but after filling of an em_unit value diff --git a/src/slic3r/GUI/wxExtensions.cpp b/src/slic3r/GUI/wxExtensions.cpp index 24fe778c9..0e89a72f2 100644 --- a/src/slic3r/GUI/wxExtensions.cpp +++ b/src/slic3r/GUI/wxExtensions.cpp @@ -1871,9 +1871,9 @@ void DoubleSlider::draw_action_icon(wxDC& dc, const wxPoint pt_beg, const wxPoin { const int tick = m_selection == ssLower ? m_lower_value : m_higher_value; - wxBitmap& icon = m_is_action_icon_focesed ? m_bmp_add_tick_off.bmp() : m_bmp_add_tick_on.bmp(); + wxBitmap* icon = m_is_action_icon_focesed ? &m_bmp_add_tick_off.bmp() : &m_bmp_add_tick_on.bmp(); if (m_ticks.find(tick) != m_ticks.end()) - icon = m_is_action_icon_focesed ? m_bmp_del_tick_off.bmp() : m_bmp_del_tick_on.bmp(); + icon = m_is_action_icon_focesed ? &m_bmp_del_tick_off.bmp() : &m_bmp_del_tick_on.bmp(); wxCoord x_draw, y_draw; is_horizontal() ? x_draw = pt_beg.x - 0.5*m_tick_icon_dim : y_draw = pt_beg.y - 0.5*m_tick_icon_dim; @@ -1882,7 +1882,7 @@ void DoubleSlider::draw_action_icon(wxDC& dc, const wxPoint pt_beg, const wxPoin else is_horizontal() ? y_draw = pt_beg.y - m_tick_icon_dim-2 : x_draw = pt_end.x + 3; - dc.DrawBitmap(icon, x_draw, y_draw); + dc.DrawBitmap(*icon, x_draw, y_draw); //update rect of the tick action icon m_rect_tick_action = wxRect(x_draw, y_draw, m_tick_icon_dim, m_tick_icon_dim);