Enable built-in DPI changed event handler when building against wxWidgets 3.1.3
This commit is contained in:
parent
76d9f0f509
commit
dcf68aefd7
3 changed files with 39 additions and 2 deletions
|
@ -51,5 +51,8 @@
|
||||||
// Enable error logging for OpenGL calls when SLIC3R_LOGLEVEL >= 5
|
// Enable error logging for OpenGL calls when SLIC3R_LOGLEVEL >= 5
|
||||||
#define ENABLE_OPENGL_ERROR_LOGGING (1 && ENABLE_2_3_0_ALPHA1)
|
#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_
|
#endif // _prusaslicer_technologies_h_
|
||||||
|
|
|
@ -24,6 +24,11 @@ class wxCheckBox;
|
||||||
class wxTopLevelWindow;
|
class wxTopLevelWindow;
|
||||||
class wxRect;
|
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 Slic3r {
|
||||||
namespace GUI {
|
namespace GUI {
|
||||||
|
@ -86,11 +91,29 @@ public:
|
||||||
this->SetFont(m_normal_font);
|
this->SetFont(m_normal_font);
|
||||||
#endif
|
#endif
|
||||||
// initialize default width_unit according to the width of the one symbol ("m") of the currently active font of this window.
|
// 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);
|
m_em_unit = std::max<size_t>(10, this->GetTextExtent("m").x - 1);
|
||||||
|
#endif // ENABLE_WX_3_1_3_DPI_CHANGED_EVENT
|
||||||
|
|
||||||
// recalc_font();
|
// 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_scale_factor = (float)evt.dpi / (float)DPI_DEFAULT;
|
||||||
|
|
||||||
m_new_font_point_size = get_default_font_for_dpi(evt.dpi).GetPointSize();
|
m_new_font_point_size = get_default_font_for_dpi(evt.dpi).GetPointSize();
|
||||||
|
@ -100,7 +123,8 @@ public:
|
||||||
|
|
||||||
if (is_new_scale_factor())
|
if (is_new_scale_factor())
|
||||||
rescale(evt.rect);
|
rescale(evt.rect);
|
||||||
});
|
});
|
||||||
|
#endif // wxMAJOR_VERSION
|
||||||
|
|
||||||
this->Bind(wxEVT_MOVE_START, [this](wxMoveEvent& event)
|
this->Bind(wxEVT_MOVE_START, [this](wxMoveEvent& event)
|
||||||
{
|
{
|
||||||
|
@ -192,17 +216,23 @@ private:
|
||||||
{
|
{
|
||||||
this->Freeze();
|
this->Freeze();
|
||||||
|
|
||||||
|
#if !wxVERSION_EQUAL_OR_GREATER_THAN(3, 1, 3)
|
||||||
// rescale fonts of all controls
|
// rescale fonts of all controls
|
||||||
scale_controls_fonts(this, m_new_font_point_size);
|
scale_controls_fonts(this, m_new_font_point_size);
|
||||||
// rescale current window font
|
// rescale current window font
|
||||||
scale_win_font(this, m_new_font_point_size);
|
scale_win_font(this, m_new_font_point_size);
|
||||||
|
#endif // wxMAJOR_VERSION
|
||||||
|
|
||||||
|
|
||||||
// set normal application font as a current window font
|
// set normal application font as a current window font
|
||||||
m_normal_font = this->GetFont();
|
m_normal_font = this->GetFont();
|
||||||
|
|
||||||
// update em_unit value for new window font
|
// 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);
|
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
|
// rescale missed controls sizes and images
|
||||||
on_dpi_changed(suggested_rect);
|
on_dpi_changed(suggested_rect);
|
||||||
|
|
|
@ -537,7 +537,11 @@ bool MainFrame::can_reslice() const
|
||||||
|
|
||||||
void MainFrame::on_dpi_changed(const wxRect &suggested_rect)
|
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();
|
wxGetApp().update_fonts();
|
||||||
|
#endif // ENABLE_WX_3_1_3_DPI_CHANGED_EVENT
|
||||||
this->SetFont(this->normal_font());
|
this->SetFont(this->normal_font());
|
||||||
|
|
||||||
/* Load default preset bitmaps before a tabpanel initialization,
|
/* Load default preset bitmaps before a tabpanel initialization,
|
||||||
|
|
Loading…
Reference in a new issue