From dcf68aefd75d904e9c2fa372fa4efb299f17a4d4 Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Mon, 15 Jun 2020 16:20:34 +0200 Subject: [PATCH] Enable built-in DPI changed event handler when building against wxWidgets 3.1.3 --- src/libslic3r/Technologies.hpp | 3 +++ src/slic3r/GUI/GUI_Utils.hpp | 34 ++++++++++++++++++++++++++++++++-- src/slic3r/GUI/MainFrame.cpp | 4 ++++ 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/src/libslic3r/Technologies.hpp b/src/libslic3r/Technologies.hpp index e0d534e00..e4b71697d 100644 --- a/src/libslic3r/Technologies.hpp +++ b/src/libslic3r/Technologies.hpp @@ -51,5 +51,8 @@ // Enable error logging for OpenGL calls when SLIC3R_LOGLEVEL >= 5 #define ENABLE_OPENGL_ERROR_LOGGING (1 && ENABLE_2_3_0_ALPHA1) +// Enable built-in DPI changed event handler of wxWidgets 3.1.3 +#define ENABLE_WX_3_1_3_DPI_CHANGED_EVENT (1 && ENABLE_2_3_0_ALPHA1) + #endif // _prusaslicer_technologies_h_ diff --git a/src/slic3r/GUI/GUI_Utils.hpp b/src/slic3r/GUI/GUI_Utils.hpp index a2f939fac..3c2506b86 100644 --- a/src/slic3r/GUI/GUI_Utils.hpp +++ b/src/slic3r/GUI/GUI_Utils.hpp @@ -24,6 +24,11 @@ class wxCheckBox; class wxTopLevelWindow; class wxRect; +#if ENABLE_WX_3_1_3_DPI_CHANGED_EVENT +#define wxVERSION_EQUAL_OR_GREATER_THAN(major, minor, release) ((wxMAJOR_VERSION >= major) && (wxMINOR_VERSION >= minor) && (wxRELEASE_NUMBER >= release)) +#else +#define wxVERSION_EQUAL_OR_GREATER_THAN(major, minor, release) 0 +#endif // ENABLE_WX_3_1_3_DPI_CHANGED_EVENT namespace Slic3r { namespace GUI { @@ -86,11 +91,29 @@ public: 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 + m_em_unit = std::max(10, 10.0f * m_scale_factor); +#else m_em_unit = std::max(10, this->GetTextExtent("m").x - 1); +#endif // ENABLE_WX_3_1_3_DPI_CHANGED_EVENT // recalc_font(); - this->Bind(EVT_DPI_CHANGED_SLICER, [this](const DpiChangedEvent &evt) { +#if wxVERSION_EQUAL_OR_GREATER_THAN(3, 1, 3) + this->Bind(wxEVT_DPI_CHANGED, [this](wxDPIChangedEvent& evt) { + m_scale_factor = (float)evt.GetNewDPI().x / (float)DPI_DEFAULT; + + m_new_font_point_size = get_default_font_for_dpi(evt.GetNewDPI().x).GetPointSize(); + + if (!m_can_rescale) + return; + + if (is_new_scale_factor()) + rescale(wxRect()); + + }); +#else + this->Bind(EVT_DPI_CHANGED_SLICER, [this](const DpiChangedEvent& evt) { m_scale_factor = (float)evt.dpi / (float)DPI_DEFAULT; m_new_font_point_size = get_default_font_for_dpi(evt.dpi).GetPointSize(); @@ -100,7 +123,8 @@ public: if (is_new_scale_factor()) rescale(evt.rect); - }); + }); +#endif // wxMAJOR_VERSION this->Bind(wxEVT_MOVE_START, [this](wxMoveEvent& event) { @@ -192,17 +216,23 @@ private: { this->Freeze(); +#if !wxVERSION_EQUAL_OR_GREATER_THAN(3, 1, 3) // rescale fonts of all controls scale_controls_fonts(this, m_new_font_point_size); // rescale current window font scale_win_font(this, m_new_font_point_size); +#endif // wxMAJOR_VERSION // set normal application font as a current window font m_normal_font = this->GetFont(); // update em_unit value for new window font +#if ENABLE_WX_3_1_3_DPI_CHANGED_EVENT + m_em_unit = std::max(10, 10.0f * m_scale_factor); +#else m_em_unit = std::max(10, this->GetTextExtent("m").x - 1); +#endif // ENABLE_WX_3_1_3_DPI_CHANGED_EVENT // rescale missed controls sizes and images on_dpi_changed(suggested_rect); diff --git a/src/slic3r/GUI/MainFrame.cpp b/src/slic3r/GUI/MainFrame.cpp index ef837c200..d406dc8ad 100644 --- a/src/slic3r/GUI/MainFrame.cpp +++ b/src/slic3r/GUI/MainFrame.cpp @@ -537,7 +537,11 @@ bool MainFrame::can_reslice() const void MainFrame::on_dpi_changed(const wxRect &suggested_rect) { +#if ENABLE_WX_3_1_3_DPI_CHANGED_EVENT + wxGetApp().update_fonts(this); +#else wxGetApp().update_fonts(); +#endif // ENABLE_WX_3_1_3_DPI_CHANGED_EVENT this->SetFont(this->normal_font()); /* Load default preset bitmaps before a tabpanel initialization,