Fixed conflict after merge with master

This commit is contained in:
enricoturri1966 2020-06-19 11:49:59 +02:00
commit 5c7b0948bc
25 changed files with 1168 additions and 366 deletions

View file

@ -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) || ((wxMAJOR_VERSION == major) && (wxMINOR_VERSION > minor)) || ((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 {
@ -51,6 +56,7 @@ enum { DPI_DEFAULT = 96 };
int get_dpi_for_window(wxWindow *window);
wxFont get_default_font_for_dpi(int dpi);
#if !wxVERSION_EQUAL_OR_GREATER_THAN(3,1,3)
struct DpiChangedEvent : public wxEvent {
int dpi;
wxRect rect;
@ -66,6 +72,7 @@ struct DpiChangedEvent : public wxEvent {
};
wxDECLARE_EVENT(EVT_DPI_CHANGED_SLICER, DpiChangedEvent);
#endif // !wxVERSION_EQUAL_OR_GREATER_THAN
template<class P> class DPIAware : public P
{
@ -86,11 +93,33 @@ 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 ENABLE_LAYOUT_NO_RESTART
if (m_force_rescale || is_new_scale_factor())
rescale(wxRect());
#else
if (is_new_scale_factor())
rescale(wxRect());
#endif // ENABLE_LAYOUT_NO_RESTART
});
#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();
@ -98,9 +127,15 @@ public:
if (!m_can_rescale)
return;
#if ENABLE_LAYOUT_NO_RESTART
if (m_force_rescale || is_new_scale_factor())
rescale(evt.rect);
#else
if (is_new_scale_factor())
rescale(evt.rect);
});
#endif // ENABLE_LAYOUT_NO_RESTART
});
#endif // wxVERSION_EQUAL_OR_GREATER_THAN
this->Bind(wxEVT_MOVE_START, [this](wxMoveEvent& event)
{
@ -140,6 +175,9 @@ public:
int em_unit() const { return m_em_unit; }
// int font_size() const { return m_font_size; }
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:
virtual void on_dpi_changed(const wxRect &suggested_rect) = 0;
@ -153,6 +191,9 @@ private:
wxFont m_normal_font;
float m_prev_scale_factor;
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;
@ -192,17 +233,27 @@ private:
{
this->Freeze();
// 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);
#if ENABLE_LAYOUT_NO_RESTART
if (m_force_rescale) {
#endif // ENABLE_LAYOUT_NO_RESTART
// 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);
#if ENABLE_LAYOUT_NO_RESTART
m_force_rescale = false;
}
#endif // ENABLE_LAYOUT_NO_RESTART
// 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);