Mirroring buttons: Fixed scaling issues and ensured proper hiding on Win

This commit is contained in:
YuSanka 2019-08-01 11:35:43 +02:00 committed by Lukas Matena
parent 98e08e356f
commit c2a43dc864
3 changed files with 35 additions and 7 deletions

View file

@ -210,6 +210,7 @@ ObjectManipulation::ObjectManipulation(wxWindow* parent) :
wxSize btn_size(em_unit(parent) * mirror_btn_width, em_unit(parent) * mirror_btn_width);
auto btn = new ScalableButton(parent, wxID_ANY, "mirroring_off", wxEmptyString, btn_size, wxDefaultPosition, wxBU_EXACTFIT | wxNO_BORDER | wxTRANSPARENT_WINDOW);
btn->SetToolTip(wxString::Format(_(L("Toggle %c axis mirroring")), (int)label));
btn->SetBitmapDisabled_(m_mirror_bitmap_hidden);
m_mirror_buttons[axis_idx].first = btn;
m_mirror_buttons[axis_idx].second = mbShown;
@ -648,13 +649,13 @@ void ObjectManipulation::update_mirror_buttons_visibility()
wxGetApp().CallAfter([this, new_states]{
for (int i=0; i<3; ++i) {
if (new_states[i] != m_mirror_buttons[i].second) {
const wxBitmap* bmp;
const ScalableBitmap* bmp;
switch (new_states[i]) {
case mbHidden : bmp = &m_mirror_bitmap_hidden.bmp(); m_mirror_buttons[i].first->Enable(false); break;
case mbShown : bmp = &m_mirror_bitmap_off.bmp(); m_mirror_buttons[i].first->Enable(true); break;
case mbActive : bmp = &m_mirror_bitmap_on.bmp(); m_mirror_buttons[i].first->Enable(true); break;
case mbHidden : bmp = &m_mirror_bitmap_hidden; m_mirror_buttons[i].first->Enable(false); break;
case mbShown : bmp = &m_mirror_bitmap_off; m_mirror_buttons[i].first->Enable(true); break;
case mbActive : bmp = &m_mirror_bitmap_on; m_mirror_buttons[i].first->Enable(true); break;
}
m_mirror_buttons[i].first->SetBitmap(*bmp);
m_mirror_buttons[i].first->SetBitmap_(*bmp);
m_mirror_buttons[i].second = new_states[i];
}
}
@ -927,6 +928,9 @@ void ObjectManipulation::msw_rescale()
m_reset_rotation_button->msw_rescale();
m_drop_to_bed_button->msw_rescale();
for (int id = 0; id < 3; ++id)
m_mirror_buttons[id].first->msw_rescale();
get_og()->msw_rescale();
}

View file

@ -2966,6 +2966,13 @@ ScalableButton::ScalableButton( wxWindow * parent,
#endif // __WXMSW__
SetBitmap(create_scaled_bitmap(parent, icon_name));
if (size != wxDefaultSize)
{
const int em = em_unit(parent);
m_width = size.x/em;
m_height= size.y/em;
}
}
@ -2992,11 +2999,24 @@ void ScalableButton::SetBitmap_(const ScalableBitmap& bmp)
m_current_icon_name = bmp.name();
}
void ScalableButton::SetBitmapDisabled_(const ScalableBitmap& bmp)
{
SetBitmapDisabled(bmp.bmp());
m_disabled_icon_name = bmp.name();
}
void ScalableButton::msw_rescale()
{
const wxBitmap bmp = create_scaled_bitmap(m_parent, m_current_icon_name);
SetBitmap(create_scaled_bitmap(m_parent, m_current_icon_name));
if (!m_disabled_icon_name.empty())
SetBitmapDisabled(create_scaled_bitmap(m_parent, m_disabled_icon_name));
SetBitmap(bmp);
if (m_width > 0 || m_height>0)
{
const int em = em_unit(m_parent);
wxSize size(m_width * em, m_height * em);
SetMinSize(size);
}
}

View file

@ -904,12 +904,16 @@ public:
~ScalableButton() {}
void SetBitmap_(const ScalableBitmap& bmp);
void SetBitmapDisabled_(const ScalableBitmap &bmp);
void msw_rescale();
private:
wxWindow* m_parent;
std::string m_current_icon_name = "";
std::string m_disabled_icon_name = "";
int m_width {-1}; // should be multiplied to em_unit
int m_height{-1}; // should be multiplied to em_unit
};