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

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 23.0.3, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg version="1.0" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 16 16" enable-background="new 0 0 16 16" xml:space="preserve">
<g id="lock_x5F_closed">
<path fill="none" stroke="#808080" stroke-width="3" stroke-miterlimit="9" d="M4,8V4c0,0,0-2,2-2c1,0,3,0,4,0c2,0,2,2,2,2v4"/>
<path fill="#808080" d="M13,8H3C2.45,8,2,8.45,2,9v5c0,0.55,0.45,1,1,1h10c0.55,0,1-0.45,1-1V9C14,8.45,13.55,8,13,8z M10,12H8.91
c-0.21,0.58-0.76,1-1.41,1C6.67,13,6,12.33,6,11.5S6.67,10,7.5,10c0.65,0,1.2,0.42,1.41,1H10V12z"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 728 B

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 23.0.3, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg version="1.0" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 16 16" enable-background="new 0 0 16 16" xml:space="preserve">
<g id="lock_x5F_open">
<path fill="none" stroke="#ED6B21" stroke-width="3" stroke-linecap="round" stroke-miterlimit="10" d="M4,8V4c0,0,0-2,2-2
c1,0,3,0,4,0c2,0,2,2,2,2v1"/>
<path fill="#ED6B21" d="M13,8H3C2.45,8,2,8.45,2,9v5c0,0.55,0.45,1,1,1h10c0.55,0,1-0.45,1-1V9C14,8.45,13.55,8,13,8z M10,12H8.91
c-0.21,0.58-0.76,1-1.41,1C6.67,13,6,12.33,6,11.5S6.67,10,7.5,10c0.65,0,1.2,0.42,1.41,1H10V12z"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 753 B

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();

View File

@ -843,8 +843,6 @@ public:
~LockButton() {}
void OnButton(wxCommandEvent& event);
void OnEnterBtn(wxMouseEvent& event) { enter_button(true); event.Skip(); }
void OnLeaveBtn(wxMouseEvent& event) { enter_button(false); event.Skip(); }
bool IsLocked() const { return m_is_pushed; }
void SetLock(bool lock);
@ -856,16 +854,16 @@ public:
void msw_rescale();
protected:
void enter_button(const bool enter);
void update_button_bitmaps();
private:
bool m_is_pushed = false;
bool m_disabled = false;
ScalableBitmap m_bmp_lock_on;
ScalableBitmap m_bmp_lock_off;
ScalableBitmap m_bmp_unlock_on;
ScalableBitmap m_bmp_unlock_off;
ScalableBitmap m_bmp_lock_closed;
ScalableBitmap m_bmp_lock_closed_f;
ScalableBitmap m_bmp_lock_open;
ScalableBitmap m_bmp_lock_open_f;
};