Application Scaling for MSW: Next big step

- Added rescale() function for the most of controls
 - Created PrusaBitmap and PrusaButton classes like a wrap to wxBitmap and wxButton accordingly
This commit is contained in:
YuSanka 2019-04-13 23:46:52 +02:00
parent a74c608c7a
commit f7ddddcff5
22 changed files with 737 additions and 250 deletions

View file

@ -33,22 +33,21 @@ wxString double_to_string(double const value, const int max_precision /*= 4*/)
void Field::PostInitialize()
{
auto color = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
m_Undo_btn = new MyButton(m_parent, wxID_ANY, "", wxDefaultPosition,wxDefaultSize, wxBU_EXACTFIT | wxNO_BORDER);
m_Undo_to_sys_btn = new MyButton(m_parent, wxID_ANY, "", wxDefaultPosition,wxDefaultSize, wxBU_EXACTFIT | wxNO_BORDER);
if (wxMSW) {
m_Undo_btn->SetBackgroundColour(color);
m_Undo_btn->SetBackgroundStyle(wxBG_STYLE_PAINT);
m_Undo_to_sys_btn->SetBackgroundColour(color);
m_Undo_to_sys_btn->SetBackgroundStyle(wxBG_STYLE_PAINT);
}
m_Undo_btn = new RevertButton(m_parent, "bullet_white.png");//(m_parent, wxID_ANY, "", wxDefaultPosition,wxDefaultSize, wxBU_EXACTFIT | wxNO_BORDER);
m_Undo_to_sys_btn = new RevertButton(m_parent, "bullet_white.png");//(m_parent, wxID_ANY, "", wxDefaultPosition,wxDefaultSize, wxBU_EXACTFIT | wxNO_BORDER);
// if (wxMSW) {
// m_Undo_btn->SetBackgroundColour(color);
// m_Undo_btn->SetBackgroundStyle(wxBG_STYLE_PAINT);
// m_Undo_to_sys_btn->SetBackgroundColour(color);
// m_Undo_to_sys_btn->SetBackgroundStyle(wxBG_STYLE_PAINT);
// }
m_Undo_btn->Bind(wxEVT_BUTTON, ([this](wxCommandEvent) { on_back_to_initial_value(); }));
m_Undo_to_sys_btn->Bind(wxEVT_BUTTON, ([this](wxCommandEvent) { on_back_to_sys_value(); }));
//set default bitmap
wxBitmap bmp;
bmp.LoadFile(from_u8(var("bullet_white.png")), wxBITMAP_TYPE_PNG);
set_undo_bitmap(&bmp);
set_undo_to_sys_bitmap(&bmp);
// wxBitmap bmp = create_scaled_bitmap(m_parent, "bullet_white.png" );
// set_undo_bitmap(&bmp);
// set_undo_to_sys_bitmap(&bmp);
switch (m_opt.type)
{
@ -213,8 +212,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);
if (m_opt.width >= 0) size.SetWidth(m_opt.width);
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());
wxString text_value = wxString("");
@ -358,6 +357,21 @@ boost::any& TextCtrl::get_value()
return m_value;
}
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 (size != wxDefaultSize)
{
wxTextCtrl* field = dynamic_cast<wxTextCtrl*>(window);
field->SetMinSize(size);
}
}
void TextCtrl::enable() { dynamic_cast<wxTextCtrl*>(window)->Enable(); dynamic_cast<wxTextCtrl*>(window)->SetEditable(true); }
void TextCtrl::disable() { dynamic_cast<wxTextCtrl*>(window)->Disable(); dynamic_cast<wxTextCtrl*>(window)->SetEditable(false); }
@ -380,7 +394,8 @@ void CheckBox::BUILD() {
static_cast<const ConfigOptionBools*>(m_opt.default_value)->get_at(m_opt_idx) :
false;
auto temp = new wxCheckBox(m_parent, wxID_ANY, wxString(""), wxDefaultPosition, size);
// Set Label as a string of at least one space simbol to correct system scaling of a CheckBox
auto temp = new wxCheckBox(m_parent, wxID_ANY, wxString(" "), wxDefaultPosition, size);
temp->SetFont(Slic3r::GUI::wxGetApp().normal_font());
temp->SetBackgroundStyle(wxBG_STYLE_PAINT);
temp->SetValue(check_value);
@ -505,10 +520,18 @@ void SpinCtrl::propagate_value()
on_change_field();
}
void SpinCtrl::rescale()
{
Field::rescale();
wxSpinCtrl* field = dynamic_cast<wxSpinCtrl*>(window);
field->SetMinSize(wxSize(-1, int(1.9f*field->GetFont().GetPixelSize().y)));
}
void Choice::BUILD() {
wxSize size(15 * wxGetApp().em_unit(), -1);
if (m_opt.height >= 0) size.SetHeight(m_opt.height);
if (m_opt.width >= 0) size.SetWidth(m_opt.width);
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());
wxBitmapComboBox* temp;
if (!m_opt.gui_type.empty() && m_opt.gui_type.compare("select_open") != 0) {
@ -817,6 +840,48 @@ boost::any& Choice::get_value()
return m_value;
}
void Choice::rescale()
{
Field::rescale();
wxBitmapComboBox* field = dynamic_cast<wxBitmapComboBox*>(window);
const wxString selection = field->GetStringSelection();
/* To correct scaling (set new controll size) of a wxBitmapCombobox
* we need to refill control with new bitmaps. So, in our case :
* 1. clear conrol
* 2. add content
* 3. add scaled "empty" bitmap to the at least one item
*/
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());
field->SetSize(size);
size_t idx, counter = idx = 0;
if (m_opt.enum_labels.empty() && m_opt.enum_values.empty()) {}
else{
for (auto el : m_opt.enum_labels.empty() ? m_opt.enum_values : m_opt.enum_labels) {
const wxString& str = _(el);
field->Append(str);
if (el.compare(selection) == 0)
idx = counter;
++counter;
}
}
wxBitmap empty_bmp(1, field->GetFont().GetPixelSize().y + 2);
empty_bmp.SetWidth(0);
field->SetItemBitmap(0, empty_bmp);
idx == m_opt.enum_values.size() ?
field->SetValue(selection) :
field->SetSelection(idx);
}
void ColourPicker::BUILD()
{
auto size = wxSize(wxDefaultSize);
@ -944,8 +1009,8 @@ boost::any& PointCtrl::get_value()
void StaticText::BUILD()
{
auto size = wxSize(wxDefaultSize);
if (m_opt.height >= 0) size.SetHeight(m_opt.height);
if (m_opt.width >= 0) size.SetWidth(m_opt.width);
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());
const wxString legend(static_cast<const ConfigOptionString*>(m_opt.default_value)->value);
auto temp = new wxStaticText(m_parent, wxID_ANY, legend, wxDefaultPosition, size, wxST_ELLIPSIZE_MIDDLE);
@ -959,6 +1024,21 @@ void StaticText::BUILD()
temp->SetToolTip(get_tooltip_text(legend));
}
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 (size != wxDefaultSize)
{
wxStaticText* field = dynamic_cast<wxStaticText*>(window);
field->SetSize(size);
}
}
void SliderCtrl::BUILD()
{
auto size = wxSize(wxDefaultSize);