Debounce button control drawing.

Fixes https://gitlab.com/kicad/code/kicad/issues/13288
This commit is contained in:
Jeff Young 2022-12-27 23:55:09 +00:00
parent 6940333f40
commit fc15454dd1
3 changed files with 97 additions and 41 deletions

View File

@ -115,24 +115,36 @@ void BITMAP_BUTTON::AcceptDragInAsClick( bool aAcceptDragIn )
void BITMAP_BUTTON::OnMouseLeave( wxEvent& aEvent )
{
clearFlag( wxCONTROL_CURRENT | wxCONTROL_PRESSED );
Refresh();
if( hasFlag( wxCONTROL_CURRENT | wxCONTROL_PRESSED ) )
{
clearFlag( wxCONTROL_CURRENT | wxCONTROL_PRESSED );
Refresh();
}
aEvent.Skip();
}
void BITMAP_BUTTON::OnMouseEnter( wxEvent& aEvent )
{
setFlag( wxCONTROL_CURRENT );
Refresh();
if( !hasFlag( wxCONTROL_CURRENT ) )
{
setFlag( wxCONTROL_CURRENT );
Refresh();
}
aEvent.Skip();
}
void BITMAP_BUTTON::OnKillFocus( wxEvent& aEvent )
{
clearFlag( wxCONTROL_FOCUSED );
Refresh();
if( hasFlag( wxCONTROL_FOCUSED | wxCONTROL_CURRENT | wxCONTROL_PRESSED ) )
{
clearFlag( wxCONTROL_FOCUSED | wxCONTROL_CURRENT | wxCONTROL_PRESSED );
Refresh();
}
aEvent.Skip();
}
@ -140,9 +152,14 @@ void BITMAP_BUTTON::OnKillFocus( wxEvent& aEvent )
void BITMAP_BUTTON::OnSetFocus( wxEvent& aEvent )
{
if( !hasFlag( wxCONTROL_CHECKABLE ) )
setFlag( wxCONTROL_FOCUSED );
{
if( !hasFlag( wxCONTROL_FOCUSED ) )
{
setFlag( wxCONTROL_FOCUSED );
Refresh();
}
}
Refresh();
aEvent.Skip();
}
@ -288,12 +305,17 @@ bool BITMAP_BUTTON::Enable( bool aEnable )
wxPanel::Enable( aEnable );
if( aEnable )
if( aEnable && hasFlag( wxCONTROL_DISABLED ) )
{
clearFlag( wxCONTROL_DISABLED );
else
setFlag( wxCONTROL_DISABLED );
Refresh();
}
Refresh();
if( !aEnable && !hasFlag( wxCONTROL_DISABLED ) )
{
setFlag( wxCONTROL_DISABLED );
Refresh();
}
return true;
}
@ -323,12 +345,17 @@ void BITMAP_BUTTON::Check( bool aCheck )
{
wxASSERT_MSG( hasFlag( wxCONTROL_CHECKABLE ), "Button is not a checkButton." );
if( aCheck )
if( aCheck && !hasFlag( wxCONTROL_CHECKED ) )
{
setFlag( wxCONTROL_CHECKED );
else
clearFlag( wxCONTROL_CHECKED );
Refresh();
}
Refresh();
if( !aCheck && hasFlag( wxCONTROL_CHECKED ) )
{
clearFlag( wxCONTROL_CHECKED );
Refresh();
}
}

View File

@ -103,8 +103,11 @@ void SPLIT_BUTTON::SetBitmap( const wxBitmap& aBmp )
void SPLIT_BUTTON::SetLabel( const wxString& aLabel )
{
m_label = aLabel;
Refresh();
if( m_label != aLabel )
{
m_label = aLabel;
Refresh();
}
}
@ -116,9 +119,12 @@ wxMenu* SPLIT_BUTTON::GetSplitButtonMenu()
void SPLIT_BUTTON::OnKillFocus( wxFocusEvent& aEvent )
{
m_stateButton = wxCONTROL_CURRENT;
m_stateMenu = wxCONTROL_CURRENT;
Refresh();
if( m_stateButton != 0 || m_stateMenu != 0 )
{
m_stateButton = 0;
m_stateMenu = 0;
Refresh();
}
aEvent.Skip();
}
@ -126,9 +132,12 @@ void SPLIT_BUTTON::OnKillFocus( wxFocusEvent& aEvent )
void SPLIT_BUTTON::OnMouseLeave( wxMouseEvent& aEvent )
{
m_stateButton = 0;
m_stateMenu = 0;
Refresh();
if( m_stateButton != 0 || m_stateMenu != 0 )
{
m_stateButton = 0;
m_stateMenu = 0;
Refresh();
}
aEvent.Skip();
}
@ -136,9 +145,12 @@ void SPLIT_BUTTON::OnMouseLeave( wxMouseEvent& aEvent )
void SPLIT_BUTTON::OnMouseEnter( wxMouseEvent& aEvent )
{
m_stateButton = wxCONTROL_CURRENT;
m_stateMenu = wxCONTROL_CURRENT;
Refresh();
if( m_stateButton != wxCONTROL_CURRENT || m_stateMenu != wxCONTROL_CURRENT )
{
m_stateButton = wxCONTROL_CURRENT;
m_stateMenu = wxCONTROL_CURRENT;
Refresh();
}
aEvent.Skip();
}
@ -313,18 +325,21 @@ bool SPLIT_BUTTON::Enable( bool aEnable )
m_bIsEnable = aEnable;
wxPanel::Enable( m_bIsEnable );
if( m_bIsEnable )
if( m_bIsEnable
&& ( m_stateButton == wxCONTROL_DISABLED || m_stateMenu == wxCONTROL_DISABLED ) )
{
m_stateButton = 0;
m_stateMenu = 0;
Refresh();
}
else
if( !m_bIsEnable
&& ( m_stateButton != wxCONTROL_DISABLED || m_stateMenu != wxCONTROL_DISABLED ) )
{
m_stateButton = wxCONTROL_DISABLED;
m_stateMenu = wxCONTROL_DISABLED;
Refresh();
}
Refresh();
return aEnable;
}

View File

@ -83,8 +83,11 @@ void STD_BITMAP_BUTTON::SetBitmap( const wxBitmap& aBmp )
void STD_BITMAP_BUTTON::OnKillFocus( wxFocusEvent& aEvent )
{
m_stateButton = wxCONTROL_CURRENT;
Refresh();
if( m_stateButton != 0 )
{
m_stateButton = 0;
Refresh();
}
aEvent.Skip();
}
@ -92,8 +95,11 @@ void STD_BITMAP_BUTTON::OnKillFocus( wxFocusEvent& aEvent )
void STD_BITMAP_BUTTON::OnMouseLeave( wxMouseEvent& aEvent )
{
m_stateButton = 0;
Refresh();
if( m_stateButton != 0 )
{
m_stateButton = 0;
Refresh();
}
aEvent.Skip();
}
@ -101,8 +107,11 @@ void STD_BITMAP_BUTTON::OnMouseLeave( wxMouseEvent& aEvent )
void STD_BITMAP_BUTTON::OnMouseEnter( wxMouseEvent& aEvent )
{
m_stateButton = wxCONTROL_CURRENT;
Refresh();
if( m_stateButton != wxCONTROL_CURRENT )
{
m_stateButton = wxCONTROL_CURRENT;
Refresh();
}
aEvent.Skip();
}
@ -213,12 +222,17 @@ bool STD_BITMAP_BUTTON::Enable( bool aEnable )
m_bIsEnable = aEnable;
wxPanel::Enable( m_bIsEnable );
if( m_bIsEnable )
if( m_bIsEnable && m_stateButton == wxCONTROL_DISABLED )
{
m_stateButton = 0;
else
m_stateButton = wxCONTROL_DISABLED;
Refresh();
}
Refresh();
if( !m_bIsEnable && m_stateButton != wxCONTROL_DISABLED )
{
m_stateButton = wxCONTROL_DISABLED;
Refresh();
}
return aEnable;
}