diff --git a/src/libslic3r/Technologies.hpp b/src/libslic3r/Technologies.hpp index 8233ba40a..c6991c057 100644 --- a/src/libslic3r/Technologies.hpp +++ b/src/libslic3r/Technologies.hpp @@ -51,6 +51,9 @@ // 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) + // Enable changing application layout without the need to restart #define ENABLE_LAYOUT_NO_RESTART (1 && ENABLE_2_3_0_ALPHA1) 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<size_t>(10, 10.0f * m_scale_factor); +#else m_em_unit = std::max<size_t>(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<int>(10, 10.0f * m_scale_factor); +#else m_em_unit = std::max<size_t>(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 52d1f778d..d85d9feee 100644 --- a/src/slic3r/GUI/MainFrame.cpp +++ b/src/slic3r/GUI/MainFrame.cpp @@ -673,7 +673,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,