From 077321b228814fbca66937812ea204842582f4b2 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Wed, 17 Apr 2019 21:35:53 +0200 Subject: [PATCH] Implemented em_unit() function for getting of em_unit value from correct parent. + Added correct em_unit to Fields --- src/slic3r/GUI/Field.cpp | 49 +++++++++++++++++++++------------ src/slic3r/GUI/Field.hpp | 7 +++++ src/slic3r/GUI/wxExtensions.cpp | 24 +++++++++++++++- src/slic3r/GUI/wxExtensions.hpp | 4 ++- 4 files changed, 64 insertions(+), 20 deletions(-) diff --git a/src/slic3r/GUI/Field.cpp b/src/slic3r/GUI/Field.cpp index 8a98a1ed7..89310e7c3 100644 --- a/src/slic3r/GUI/Field.cpp +++ b/src/slic3r/GUI/Field.cpp @@ -65,6 +65,9 @@ void Field::PostInitialize() break; } + // initialize m_unit_value + m_em_unit = em_unit(m_parent); + BUILD(); } @@ -212,8 +215,8 @@ bool is_defined_input_value(wxWindow* win, const ConfigOptionType& type) void TextCtrl::BUILD() { auto size = wxSize(wxDefaultSize); - if (m_opt.height >= 0) size.SetHeight(m_opt.height*wxGetApp().em_unit()); - if (m_opt.width >= 0) size.SetWidth(m_opt.width*wxGetApp().em_unit()); + if (m_opt.height >= 0) size.SetHeight(m_opt.height*m_em_unit); + if (m_opt.width >= 0) size.SetWidth(m_opt.width*m_em_unit); wxString text_value = wxString(""); @@ -361,8 +364,8 @@ void TextCtrl::rescale() { Field::rescale(); auto size = wxSize(wxDefaultSize); - if (m_opt.height >= 0) size.SetHeight(m_opt.height*wxGetApp().em_unit()); - if (m_opt.width >= 0) size.SetWidth(m_opt.width*wxGetApp().em_unit()); + if (m_opt.height >= 0) size.SetHeight(m_opt.height*m_em_unit); + if (m_opt.width >= 0) size.SetWidth(m_opt.width*m_em_unit); if (size != wxDefaultSize) { @@ -424,8 +427,8 @@ int undef_spin_val = -9999; //! Probably, It's not necessary void SpinCtrl::BUILD() { auto size = wxSize(wxDefaultSize); - if (m_opt.height >= 0) size.SetHeight(m_opt.height*wxGetApp().em_unit()); - if (m_opt.width >= 0) size.SetWidth(m_opt.width*wxGetApp().em_unit()); + if (m_opt.height >= 0) size.SetHeight(m_opt.height*m_em_unit); + if (m_opt.width >= 0) size.SetWidth(m_opt.width*m_em_unit); wxString text_value = wxString(""); int default_value = 0; @@ -529,9 +532,9 @@ void SpinCtrl::rescale() } void Choice::BUILD() { - wxSize size(m_width * wxGetApp().em_unit(), -1); - if (m_opt.height >= 0) size.SetHeight(m_opt.height*wxGetApp().em_unit()); - if (m_opt.width >= 0) size.SetWidth(m_opt.width*wxGetApp().em_unit()); + wxSize size(m_width * m_em_unit, -1); + if (m_opt.height >= 0) size.SetHeight(m_opt.height*m_em_unit); + if (m_opt.width >= 0) size.SetWidth(m_opt.width*m_em_unit); wxBitmapComboBox* temp; if (!m_opt.gui_type.empty() && m_opt.gui_type.compare("select_open") != 0) { @@ -856,8 +859,8 @@ void Choice::rescale() */ field->Clear(); wxSize size(wxDefaultSize); - if (m_opt.height >= 0) size.SetHeight(m_opt.height * wxGetApp().em_unit()); - size.SetWidth((m_opt.width > 0 ? m_opt.width : m_width) * wxGetApp().em_unit()); + if (m_opt.height >= 0) size.SetHeight(m_opt.height * m_em_unit); + size.SetWidth((m_opt.width > 0 ? m_opt.width : m_width) * m_em_unit); field->SetSize(size); @@ -885,8 +888,8 @@ void Choice::rescale() void ColourPicker::BUILD() { auto size = wxSize(wxDefaultSize); - if (m_opt.height >= 0) size.SetHeight(m_opt.height*wxGetApp().em_unit()); - if (m_opt.width >= 0) size.SetWidth(m_opt.width*wxGetApp().em_unit()); + if (m_opt.height >= 0) size.SetHeight(m_opt.height*m_em_unit); + if (m_opt.width >= 0) size.SetWidth(m_opt.width*m_em_unit); // Validate the color wxString clr_str(static_cast(m_opt.default_value)->get_at(m_opt_idx)); @@ -921,7 +924,7 @@ void PointCtrl::BUILD() { auto temp = new wxBoxSizer(wxHORIZONTAL); - const wxSize field_size(4 * wxGetApp().em_unit(), -1); + const wxSize field_size(4 * m_em_unit, -1); auto default_pt = static_cast(m_opt.default_value)->values.at(0); double val = default_pt(0); @@ -964,6 +967,16 @@ void PointCtrl::BUILD() y_textctrl->SetToolTip(get_tooltip_text(X+", "+Y)); } +void PointCtrl::rescale() +{ + Field::rescale(); + + const wxSize field_size(4 * m_em_unit, -1); + + x_textctrl->SetMinSize(field_size); + y_textctrl->SetMinSize(field_size); +} + void PointCtrl::propagate_value(wxTextCtrl* win) { if (!win->GetValue().empty()) @@ -1009,8 +1022,8 @@ boost::any& PointCtrl::get_value() void StaticText::BUILD() { auto size = wxSize(wxDefaultSize); - if (m_opt.height >= 0) size.SetHeight(m_opt.height*wxGetApp().em_unit()); - if (m_opt.width >= 0) size.SetWidth(m_opt.width*wxGetApp().em_unit()); + if (m_opt.height >= 0) size.SetHeight(m_opt.height*m_em_unit); + if (m_opt.width >= 0) size.SetWidth(m_opt.width*m_em_unit); const wxString legend(static_cast(m_opt.default_value)->value); auto temp = new wxStaticText(m_parent, wxID_ANY, legend, wxDefaultPosition, size, wxST_ELLIPSIZE_MIDDLE); @@ -1029,8 +1042,8 @@ void StaticText::rescale() Field::rescale(); auto size = wxSize(wxDefaultSize); - if (m_opt.height >= 0) size.SetHeight(m_opt.height*wxGetApp().em_unit()); - if (m_opt.width >= 0) size.SetWidth(m_opt.width*wxGetApp().em_unit()); + if (m_opt.height >= 0) size.SetHeight(m_opt.height*m_em_unit); + if (m_opt.width >= 0) size.SetWidth(m_opt.width*m_em_unit); if (size != wxDefaultSize) { diff --git a/src/slic3r/GUI/Field.hpp b/src/slic3r/GUI/Field.hpp index 4dfb4e239..c776cadea 100644 --- a/src/slic3r/GUI/Field.hpp +++ b/src/slic3r/GUI/Field.hpp @@ -220,6 +220,9 @@ public: virtual void rescale() { m_Undo_to_sys_btn->rescale(); m_Undo_btn->rescale(); + + // update em_unit value + m_em_unit = em_unit(m_parent); } protected: @@ -241,6 +244,8 @@ protected: // current value boost::any m_value; + int m_em_unit; + bool bEnterPressed = false; friend class OptionsGroup; @@ -432,6 +437,8 @@ public: void set_value(const boost::any& value, bool change_event = false); boost::any& get_value() override; + void rescale() override; + void enable() override { x_textctrl->Enable(); y_textctrl->Enable(); } diff --git a/src/slic3r/GUI/wxExtensions.cpp b/src/slic3r/GUI/wxExtensions.cpp index 4588ab44d..570872363 100644 --- a/src/slic3r/GUI/wxExtensions.cpp +++ b/src/slic3r/GUI/wxExtensions.cpp @@ -18,6 +18,7 @@ #include "GUI_ObjectList.hpp" #include "libslic3r/GCode/PreviewData.hpp" #include "I18N.hpp" +#include "GUI_Utils.hpp" using Slic3r::GUI::from_u8; @@ -420,6 +421,27 @@ void PrusaCollapsiblePaneMSW::Collapse(bool collapse) } #endif //__WXMSW__ +/* Function for getting of em_unit value from correct parent. + * In most of cases it is m_em_unit value from GUI_App, + * but for DPIDialogs it's its own value. + * This value will be used to correct rescale after moving between + * Displays with different HDPI */ +int em_unit(wxWindow* win) +{ + if (win) { + // get TopLevelWindow for some window + wxWindow* top_win = win; + while (!top_win->IsTopLevel()) + top_win = top_win->GetParent(); + + Slic3r::GUI::DPIDialog* dlg = dynamic_cast(top_win); + if (dlg) + // An analog of em_unit value from GUI_App. + return 10 * dlg->scale_factor(); + } + + return Slic3r::GUI::wxGetApp().em_unit(); +} // If an icon has horizontal orientation (width > height) call this function with is_horizontal = true wxBitmap create_scaled_bitmap(wxWindow *win, const std::string& bmp_name_in, const int px_cnt/* = 16*/, const bool is_horizontal /* = false*/) @@ -436,7 +458,7 @@ wxBitmap create_scaled_bitmap(wxWindow *win, const std::string& bmp_name_in, con unsigned int height, width = height = 0; unsigned int& scale_base = is_horizontal ? width : height; - scale_base = (unsigned int)(Slic3r::GUI::wxGetApp().em_unit() * px_cnt * 0.1f + 0.5f); + scale_base = (unsigned int)(em_unit(win) * px_cnt * 0.1f + 0.5f); std::string bmp_name = bmp_name_in; boost::replace_last(bmp_name, ".png", ""); diff --git a/src/slic3r/GUI/wxExtensions.hpp b/src/slic3r/GUI/wxExtensions.hpp index df6191dad..574712849 100644 --- a/src/slic3r/GUI/wxExtensions.hpp +++ b/src/slic3r/GUI/wxExtensions.hpp @@ -31,7 +31,9 @@ wxMenuItem* append_submenu(wxMenu* menu, wxMenu* sub_menu, int id, const wxStrin wxMenuItem* append_menu_radio_item(wxMenu* menu, int id, const wxString& string, const wxString& description, std::function cb, wxEvtHandler* event_handler); -wxBitmap create_scaled_bitmap(wxWindow *win, const std::string& bmp_name, const int px_cnt=16, const bool is_horizontal = false); +int em_unit(wxWindow* win); + +wxBitmap create_scaled_bitmap(wxWindow *win, const std::string& bmp_name, const int px_cnt = 16, const bool is_horizontal = false); class wxCheckListBoxComboPopup : public wxCheckListBox, public wxComboPopup {