Refactored LockButton class

This commit is contained in:
YuSanka 2019-07-31 17:14:32 +02:00
parent 12a98bea94
commit cf6cc1d863
4 changed files with 43 additions and 27 deletions

View file

@ -2743,21 +2743,20 @@ LockButton::LockButton( wxWindow *parent,
const wxSize& size /*= wxDefaultSize*/):
wxButton(parent, id, wxEmptyString, pos, size, wxBU_EXACTFIT | wxNO_BORDER)
{
m_bmp_lock_on = ScalableBitmap(this, "one_layer_lock_on.png");
m_bmp_lock_off = ScalableBitmap(this, "one_layer_lock_off.png");
m_bmp_unlock_on = ScalableBitmap(this, "one_layer_unlock_on.png");
m_bmp_unlock_off = ScalableBitmap(this, "one_layer_unlock_off.png");
m_bmp_lock_closed = ScalableBitmap(this, "lock_closed");
m_bmp_lock_closed_f = ScalableBitmap(this, "lock_closed_f");
m_bmp_lock_open = ScalableBitmap(this, "lock_open");
m_bmp_lock_open_f = ScalableBitmap(this, "lock_open_f");
#ifdef __WXMSW__
SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
#endif // __WXMSW__
SetBitmap(m_bmp_unlock_on.bmp());
SetBitmapDisabled(m_bmp_lock_on.bmp());
SetBitmap(m_bmp_lock_open.bmp());
SetBitmapDisabled(m_bmp_lock_open.bmp());
SetBitmapHover(m_bmp_lock_closed_f.bmp());
//button events
Bind(wxEVT_BUTTON, &LockButton::OnButton, this);
Bind(wxEVT_ENTER_WINDOW, &LockButton::OnEnterBtn, this);
Bind(wxEVT_LEAVE_WINDOW, &LockButton::OnLeaveBtn, this);
Bind(wxEVT_BUTTON, &LockButton::OnButton, this);
}
void LockButton::OnButton(wxCommandEvent& event)
@ -2766,7 +2765,7 @@ void LockButton::OnButton(wxCommandEvent& event)
return;
m_is_pushed = !m_is_pushed;
enter_button(true);
update_button_bitmaps();
event.Skip();
}
@ -2774,23 +2773,21 @@ void LockButton::OnButton(wxCommandEvent& event)
void LockButton::SetLock(bool lock)
{
m_is_pushed = lock;
enter_button(true);
update_button_bitmaps();
}
void LockButton::msw_rescale()
{
m_bmp_lock_on .msw_rescale();
m_bmp_lock_off .msw_rescale();
m_bmp_unlock_on .msw_rescale();
m_bmp_unlock_off.msw_rescale();
m_bmp_lock_closed.msw_rescale();
m_bmp_lock_closed_f.msw_rescale();
m_bmp_lock_open.msw_rescale();
m_bmp_lock_open_f.msw_rescale();
}
void LockButton::enter_button(const bool enter)
void LockButton::update_button_bitmaps()
{
const wxBitmap& icon = m_is_pushed ?
enter ? m_bmp_lock_off.bmp() : m_bmp_lock_on.bmp() :
enter ? m_bmp_unlock_off.bmp() : m_bmp_unlock_on.bmp();
SetBitmap(icon);
SetBitmap(m_is_pushed ? m_bmp_lock_closed.bmp() : m_bmp_lock_open.bmp());
SetBitmapHover(m_is_pushed ? m_bmp_lock_closed_f.bmp() : m_bmp_lock_open_f.bmp());
Refresh();
Update();