ENABLE_LAYOUT_NO_RESTART -> Fixed font scaling when switching to/from non modal setting dialog layout when building against wxWidgets prior to 3.1.3
This commit is contained in:
parent
87c9163a5e
commit
9608103d58
3 changed files with 75 additions and 15 deletions
|
@ -122,7 +122,7 @@ static void register_win32_dpi_event()
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
#endif // !ENABLE_WX_3_1_3_DPI_CHANGED_EVENT
|
#endif // !wxVERSION_EQUAL_OR_GREATER_THAN
|
||||||
|
|
||||||
static GUID GUID_DEVINTERFACE_HID = { 0x4D1E55B2, 0xF16F, 0x11CF, 0x88, 0xCB, 0x00, 0x11, 0x11, 0x00, 0x00, 0x30 };
|
static GUID GUID_DEVINTERFACE_HID = { 0x4D1E55B2, 0xF16F, 0x11CF, 0x88, 0xCB, 0x00, 0x11, 0x11, 0x00, 0x00, 0x30 };
|
||||||
|
|
||||||
|
@ -412,7 +412,7 @@ bool GUI_App::on_init_inner()
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
#if !wxVERSION_EQUAL_OR_GREATER_THAN(3,1,3)
|
#if !wxVERSION_EQUAL_OR_GREATER_THAN(3,1,3)
|
||||||
register_win32_dpi_event();
|
register_win32_dpi_event();
|
||||||
#endif // !ENABLE_WX_3_1_3_DPI_CHANGED_EVENT
|
#endif // !wxVERSION_EQUAL_OR_GREATER_THAN
|
||||||
register_win32_device_notification_event();
|
register_win32_device_notification_event();
|
||||||
#endif // WIN32
|
#endif // WIN32
|
||||||
|
|
||||||
|
@ -1079,10 +1079,11 @@ void GUI_App::add_config_menu(wxMenuBar *menu)
|
||||||
#endif // ENABLE_LAYOUT_NO_RESTART
|
#endif // ENABLE_LAYOUT_NO_RESTART
|
||||||
}
|
}
|
||||||
#if ENABLE_LAYOUT_NO_RESTART
|
#if ENABLE_LAYOUT_NO_RESTART
|
||||||
if (app_layout_changed)
|
if (app_layout_changed) {
|
||||||
{
|
mainframe->Hide();
|
||||||
mainframe->update_layout();
|
mainframe->update_layout();
|
||||||
mainframe->select_tab(0);
|
mainframe->select_tab(0);
|
||||||
|
mainframe->Show();
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
if (recreate_app)
|
if (recreate_app)
|
||||||
|
|
|
@ -101,18 +101,22 @@ public:
|
||||||
|
|
||||||
// recalc_font();
|
// recalc_font();
|
||||||
|
|
||||||
#if wxVERSION_EQUAL_OR_GREATER_THAN(3, 1, 3)
|
#if wxVERSION_EQUAL_OR_GREATER_THAN(3,1,3)
|
||||||
this->Bind(wxEVT_DPI_CHANGED, [this](wxDPIChangedEvent& evt) {
|
this->Bind(wxEVT_DPI_CHANGED, [this](wxDPIChangedEvent& evt) {
|
||||||
m_scale_factor = (float)evt.GetNewDPI().x / (float)DPI_DEFAULT;
|
m_scale_factor = (float)evt.GetNewDPI().x / (float)DPI_DEFAULT;
|
||||||
|
|
||||||
m_new_font_point_size = get_default_font_for_dpi(evt.GetNewDPI().x).GetPointSize();
|
m_new_font_point_size = get_default_font_for_dpi(evt.GetNewDPI().x).GetPointSize();
|
||||||
|
|
||||||
if (!m_can_rescale)
|
if (!m_can_rescale)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
#if ENABLE_LAYOUT_NO_RESTART
|
||||||
|
if (m_force_rescale || is_new_scale_factor())
|
||||||
|
rescale(wxRect());
|
||||||
|
#else
|
||||||
if (is_new_scale_factor())
|
if (is_new_scale_factor())
|
||||||
rescale(wxRect());
|
rescale(wxRect());
|
||||||
|
#endif // ENABLE_LAYOUT_NO_RESTART
|
||||||
});
|
});
|
||||||
#else
|
#else
|
||||||
this->Bind(EVT_DPI_CHANGED_SLICER, [this](const DpiChangedEvent& evt) {
|
this->Bind(EVT_DPI_CHANGED_SLICER, [this](const DpiChangedEvent& evt) {
|
||||||
|
@ -123,10 +127,15 @@ public:
|
||||||
if (!m_can_rescale)
|
if (!m_can_rescale)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
#if ENABLE_LAYOUT_NO_RESTART
|
||||||
|
if (m_force_rescale || is_new_scale_factor())
|
||||||
|
rescale(evt.rect);
|
||||||
|
#else
|
||||||
if (is_new_scale_factor())
|
if (is_new_scale_factor())
|
||||||
rescale(evt.rect);
|
rescale(evt.rect);
|
||||||
|
#endif // ENABLE_LAYOUT_NO_RESTART
|
||||||
});
|
});
|
||||||
#endif // wxMAJOR_VERSION
|
#endif // wxVERSION_EQUAL_OR_GREATER_THAN
|
||||||
|
|
||||||
this->Bind(wxEVT_MOVE_START, [this](wxMoveEvent& event)
|
this->Bind(wxEVT_MOVE_START, [this](wxMoveEvent& event)
|
||||||
{
|
{
|
||||||
|
@ -166,6 +175,9 @@ public:
|
||||||
int em_unit() const { return m_em_unit; }
|
int em_unit() const { return m_em_unit; }
|
||||||
// int font_size() const { return m_font_size; }
|
// int font_size() const { return m_font_size; }
|
||||||
const wxFont& normal_font() const { return m_normal_font; }
|
const wxFont& normal_font() const { return m_normal_font; }
|
||||||
|
#if ENABLE_LAYOUT_NO_RESTART
|
||||||
|
void enable_force_rescale() { m_force_rescale = true; }
|
||||||
|
#endif // ENABLE_LAYOUT_NO_RESTART
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void on_dpi_changed(const wxRect &suggested_rect) = 0;
|
virtual void on_dpi_changed(const wxRect &suggested_rect) = 0;
|
||||||
|
@ -179,6 +191,9 @@ private:
|
||||||
wxFont m_normal_font;
|
wxFont m_normal_font;
|
||||||
float m_prev_scale_factor;
|
float m_prev_scale_factor;
|
||||||
bool m_can_rescale{ true };
|
bool m_can_rescale{ true };
|
||||||
|
#if ENABLE_LAYOUT_NO_RESTART
|
||||||
|
bool m_force_rescale{ false };
|
||||||
|
#endif // ENABLE_LAYOUT_NO_RESTART
|
||||||
|
|
||||||
int m_new_font_point_size;
|
int m_new_font_point_size;
|
||||||
|
|
||||||
|
@ -218,13 +233,15 @@ private:
|
||||||
{
|
{
|
||||||
this->Freeze();
|
this->Freeze();
|
||||||
|
|
||||||
#if !wxVERSION_EQUAL_OR_GREATER_THAN(3, 1, 3)
|
#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
|
#if ENABLE_LAYOUT_NO_RESTART
|
||||||
|
m_force_rescale = false;
|
||||||
|
#endif // ENABLE_LAYOUT_NO_RESTART
|
||||||
|
#endif // !wxVERSION_EQUAL_OR_GREATER_THAN
|
||||||
|
|
||||||
// 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();
|
||||||
|
|
|
@ -42,6 +42,37 @@
|
||||||
namespace Slic3r {
|
namespace Slic3r {
|
||||||
namespace GUI {
|
namespace GUI {
|
||||||
|
|
||||||
|
#if ENABLE_LAYOUT_NO_RESTART
|
||||||
|
enum class ERescaleTarget
|
||||||
|
{
|
||||||
|
Mainframe,
|
||||||
|
SettingsDialog
|
||||||
|
};
|
||||||
|
|
||||||
|
static void rescale_dialog_after_dpi_change(MainFrame& mainframe, SettingsDialog& dialog, ERescaleTarget target)
|
||||||
|
{
|
||||||
|
int mainframe_dpi = get_dpi_for_window(&mainframe);
|
||||||
|
int dialog_dpi = get_dpi_for_window(&dialog);
|
||||||
|
if (mainframe_dpi != dialog_dpi) {
|
||||||
|
if (target == ERescaleTarget::SettingsDialog) {
|
||||||
|
dialog.enable_force_rescale();
|
||||||
|
#if wxVERSION_EQUAL_OR_GREATER_THAN(3,1,3)
|
||||||
|
dialog.GetEventHandler()->AddPendingEvent(wxDPIChangedEvent(wxSize(mainframe_dpi, mainframe_dpi), wxSize(dialog_dpi, dialog_dpi)));
|
||||||
|
#else
|
||||||
|
dialog.GetEventHandler()->AddPendingEvent(DpiChangedEvent(EVT_DPI_CHANGED_SLICER, dialog_dpi, dialog.GetRect()));
|
||||||
|
#endif // wxVERSION_EQUAL_OR_GREATER_THAN
|
||||||
|
} else {
|
||||||
|
#if wxVERSION_EQUAL_OR_GREATER_THAN(3,1,3)
|
||||||
|
mainframe.GetEventHandler()->AddPendingEvent(wxDPIChangedEvent(wxSize(dialog_dpi, dialog_dpi), wxSize(mainframe_dpi, mainframe_dpi)));
|
||||||
|
#else
|
||||||
|
mainframe.enable_force_rescale();
|
||||||
|
mainframe.GetEventHandler()->AddPendingEvent(DpiChangedEvent(EVT_DPI_CHANGED_SLICER, mainframe_dpi, mainframe.GetRect()));
|
||||||
|
#endif // wxVERSION_EQUAL_OR_GREATER_THAN
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif // ENABLE_LAYOUT_NO_RESTART
|
||||||
|
|
||||||
MainFrame::MainFrame() :
|
MainFrame::MainFrame() :
|
||||||
DPIFrame(NULL, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE, "mainframe"),
|
DPIFrame(NULL, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE, "mainframe"),
|
||||||
m_printhost_queue_dlg(new PrintHostQueueDialog(this))
|
m_printhost_queue_dlg(new PrintHostQueueDialog(this))
|
||||||
|
@ -259,6 +290,9 @@ void MainFrame::update_layout()
|
||||||
m_plater_page = nullptr;
|
m_plater_page = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (m_layout == ESettingsLayout::Dlg)
|
||||||
|
rescale_dialog_after_dpi_change(*this, m_settings_dialog, ERescaleTarget::Mainframe);
|
||||||
|
|
||||||
clean_sizer(GetSizer());
|
clean_sizer(GetSizer());
|
||||||
clean_sizer(m_settings_dialog.GetSizer());
|
clean_sizer(m_settings_dialog.GetSizer());
|
||||||
|
|
||||||
|
@ -318,6 +352,9 @@ void MainFrame::update_layout()
|
||||||
GetSizer()->Add(m_plater, 1, wxEXPAND);
|
GetSizer()->Add(m_plater, 1, wxEXPAND);
|
||||||
m_tabpanel->Reparent(&m_settings_dialog);
|
m_tabpanel->Reparent(&m_settings_dialog);
|
||||||
m_settings_dialog.GetSizer()->Add(m_tabpanel, 1, wxEXPAND);
|
m_settings_dialog.GetSizer()->Add(m_tabpanel, 1, wxEXPAND);
|
||||||
|
|
||||||
|
rescale_dialog_after_dpi_change(*this, m_settings_dialog, ERescaleTarget::SettingsDialog);
|
||||||
|
|
||||||
m_tabpanel->Show();
|
m_tabpanel->Show();
|
||||||
m_plater->Show();
|
m_plater->Show();
|
||||||
break;
|
break;
|
||||||
|
@ -699,7 +736,7 @@ bool MainFrame::can_reslice() const
|
||||||
return (m_plater != nullptr) && !m_plater->model().objects.empty();
|
return (m_plater != nullptr) && !m_plater->model().objects.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
#if ENABLE_WX_3_1_3_DPI_CHANGED_EVENT
|
||||||
wxGetApp().update_fonts(this);
|
wxGetApp().update_fonts(this);
|
||||||
|
@ -718,7 +755,7 @@ void MainFrame::on_dpi_changed(const wxRect &suggested_rect)
|
||||||
|
|
||||||
// update Tabs
|
// update Tabs
|
||||||
#if ENABLE_LAYOUT_NO_RESTART
|
#if ENABLE_LAYOUT_NO_RESTART
|
||||||
if (m_layout != ESettingsLayout::Dlg) // Update tabs later, from the SettingsDialog, when the Settings are in the separated dialog
|
if (m_layout != ESettingsLayout::Dlg) // Do not update tabs if the Settings are in the separated dialog
|
||||||
#else
|
#else
|
||||||
if (m_layout != slDlg) // Update tabs later, from the SettingsDialog, when the Settings are in the separated dialog
|
if (m_layout != slDlg) // Update tabs later, from the SettingsDialog, when the Settings are in the separated dialog
|
||||||
#endif // ENABLE_LAYOUT_NO_RESTART
|
#endif // ENABLE_LAYOUT_NO_RESTART
|
||||||
|
@ -731,7 +768,7 @@ void MainFrame::on_dpi_changed(const wxRect &suggested_rect)
|
||||||
|
|
||||||
// Workarounds for correct Window rendering after rescale
|
// Workarounds for correct Window rendering after rescale
|
||||||
|
|
||||||
/* Even if Window is maximized during moving,
|
/* Even if Window is maximized during moving,
|
||||||
* first of all we should imitate Window resizing. So:
|
* first of all we should imitate Window resizing. So:
|
||||||
* 1. cancel maximization, if it was set
|
* 1. cancel maximization, if it was set
|
||||||
* 2. imitate resizing
|
* 2. imitate resizing
|
||||||
|
@ -749,6 +786,11 @@ void MainFrame::on_dpi_changed(const wxRect &suggested_rect)
|
||||||
this->SetSize(sz);
|
this->SetSize(sz);
|
||||||
|
|
||||||
this->Maximize(is_maximized);
|
this->Maximize(is_maximized);
|
||||||
|
|
||||||
|
#if ENABLE_LAYOUT_NO_RESTART
|
||||||
|
if (m_layout == ESettingsLayout::Dlg)
|
||||||
|
rescale_dialog_after_dpi_change(*this, m_settings_dialog, ERescaleTarget::SettingsDialog);
|
||||||
|
#endif // ENABLE_LAYOUT_NO_RESTART
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainFrame::on_sys_color_changed()
|
void MainFrame::on_sys_color_changed()
|
||||||
|
|
Loading…
Reference in a new issue