diff --git a/common/widgets/bitmap_toggle.cpp b/common/widgets/bitmap_toggle.cpp index 1957d3f41a..90af3c033c 100644 --- a/common/widgets/bitmap_toggle.cpp +++ b/common/widgets/bitmap_toggle.cpp @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2020 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2020-2022 KiCad Developers, see AUTHORS.txt for contributors. * @author Jon Evans * * This program is free software; you can redistribute it and/or @@ -26,6 +26,7 @@ #include #include +#include wxDEFINE_EVENT( TOGGLE_CHANGED, wxCommandEvent ); @@ -35,7 +36,8 @@ BITMAP_TOGGLE::BITMAP_TOGGLE( wxWindow *aParent, wxWindowID aId, const wxBitmap& wxPanel( aParent, aId ), m_checked( aChecked ), m_unchecked_bitmap( aUncheckedBitmap ), - m_checked_bitmap( aCheckedBitmap ) + m_checked_bitmap( aCheckedBitmap ), + m_debounce( 0 ) { wxBoxSizer* sizer = new wxBoxSizer( wxHORIZONTAL ); SetSizer( sizer ); @@ -47,13 +49,21 @@ BITMAP_TOGGLE::BITMAP_TOGGLE( wxWindow *aParent, wxWindowID aId, const wxBitmap& sizer->Add( m_bitmap, 0, 0 ); m_bitmap->Bind( wxEVT_LEFT_UP, - [&]( wxMouseEvent& ) + [&]( wxMouseEvent& event ) { + wxLongLong now = wxGetLocalTimeMillis(); + + if( now - m_debounce < 50 ) + return; + else + m_debounce = now; + SetValue( !GetValue() ); - wxCommandEvent event( TOGGLE_CHANGED ); - event.SetInt( m_checked ); - event.SetEventObject( this ); - wxPostEvent( this, event ); + + wxCommandEvent command( TOGGLE_CHANGED ); + command.SetInt( m_checked ); + command.SetEventObject( this ); + wxPostEvent( this, command ); } ); auto passOnEvent = diff --git a/include/widgets/bitmap_toggle.h b/include/widgets/bitmap_toggle.h index faef9674a8..55c4a99a2d 100644 --- a/include/widgets/bitmap_toggle.h +++ b/include/widgets/bitmap_toggle.h @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 2019-2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2019-2022 KiCad Developers, see AUTHORS.txt for contributors. * @author Jon Evans * * This program is free software; you can redistribute it and/or @@ -65,15 +65,13 @@ public: } private: - bool m_checked; + bool m_checked; wxStaticBitmap* m_bitmap; + wxBitmap m_unchecked_bitmap; + wxBitmap m_checked_bitmap; - ///< Bitmap to display in unchecked state - wxBitmap m_unchecked_bitmap; - - ///< Bitmap to display in checked state - wxBitmap m_checked_bitmap; + wxLongLong m_debounce; // Timestamp for debouncing events }; #endif diff --git a/pcbnew/widgets/appearance_controls.cpp b/pcbnew/widgets/appearance_controls.cpp index cbbb9522e0..658e6e2fae 100644 --- a/pcbnew/widgets/appearance_controls.cpp +++ b/pcbnew/widgets/appearance_controls.cpp @@ -1493,25 +1493,15 @@ void APPEARANCE_CONTROLS::rebuildLayers() [&]( wxCommandEvent& aEvent ) { wxObject* btn = aEvent.GetEventObject(); - int layId = static_cast( btn )->GetId(); - bool isVisible = aEvent.GetInt(); + int layerId = static_cast( btn )->GetId(); - wxASSERT( layId >= 0 && layId < PCB_LAYER_ID_COUNT ); - - if( m_isFpEditor && LSET::ForbiddenFootprintLayers().test( layId ) ) - { - static_cast( btn )->SetValue( !isVisible ); - return; - } - - onLayerVisibilityChanged( static_cast( layId ), - isVisible, true ); + onLayerVisibilityToggled( static_cast( layerId ) ); } ); swatch->Bind( COLOR_SWATCH_CHANGED, &APPEARANCE_CONTROLS::OnColorSwatchChanged, this ); - swatch->SetReadOnlyCallback(std::bind( &APPEARANCE_CONTROLS::onReadOnlySwatch, - this ) ); + swatch->SetReadOnlyCallback( std::bind( &APPEARANCE_CONTROLS::onReadOnlySwatch, + this ) ); swatch->SetReadOnly( readOnly ); panel->Bind( wxEVT_RIGHT_DOWN, &APPEARANCE_CONTROLS::rightClickHandler, this ); @@ -1926,24 +1916,15 @@ void APPEARANCE_CONTROLS::rightClickHandler( wxMouseEvent& aEvent ) }; -void APPEARANCE_CONTROLS::onLayerVisibilityChanged( PCB_LAYER_ID aLayer, bool isVisible, - bool isFinal ) +void APPEARANCE_CONTROLS::onLayerVisibilityToggled( PCB_LAYER_ID aLayer ) { LSET visibleLayers = getVisibleLayers(); - if( visibleLayers.test( aLayer ) != isVisible ) - { - visibleLayers.set( aLayer, isVisible ); - - setVisibleLayers( visibleLayers ); - - m_frame->GetCanvas()->GetView()->SetLayerVisible( aLayer, isVisible ); - } + visibleLayers.set( aLayer, !visibleLayers.test( aLayer ) ); + m_frame->GetCanvas()->GetView()->SetLayerVisible( aLayer, visibleLayers.test( aLayer ) ); syncLayerPresetSelection(); - - if( isFinal ) - m_frame->GetCanvas()->Refresh(); + m_frame->GetCanvas()->Refresh(); } diff --git a/pcbnew/widgets/appearance_controls.h b/pcbnew/widgets/appearance_controls.h index 66cd4903fc..878f3499b9 100644 --- a/pcbnew/widgets/appearance_controls.h +++ b/pcbnew/widgets/appearance_controls.h @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2020 Jon Evans - * Copyright (C) 2020-2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2020-2022 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software: you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the @@ -315,7 +315,7 @@ private: void rightClickHandler( wxMouseEvent& aEvent ); - void onLayerVisibilityChanged( PCB_LAYER_ID aLayer, bool isVisible, bool isFinal ); + void onLayerVisibilityToggled( PCB_LAYER_ID aLayer ); void onObjectVisibilityChanged( GAL_LAYER_ID aLayer, bool isVisible, bool isFinal );