Debounce layer visibility buttons and fix issues with FP Editor.

This commit is contained in:
Jeff Young 2022-02-23 17:39:06 +00:00
parent a36bc27e6d
commit cb16ad7557
4 changed files with 32 additions and 43 deletions

View File

@ -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 <jon@craftyjon.com>
*
* This program is free software; you can redistribute it and/or
@ -26,6 +26,7 @@
#include <wx/sizer.h>
#include <wx/statbmp.h>
#include <wx/timer.h>
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 =

View File

@ -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 <jon@craftyjon.com>
*
* This program is free software; you can redistribute it and/or
@ -68,12 +68,10 @@ private:
bool m_checked;
wxStaticBitmap* m_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

View File

@ -1498,19 +1498,9 @@ void APPEARANCE_CONTROLS::rebuildLayers()
[&]( wxCommandEvent& aEvent )
{
wxObject* btn = aEvent.GetEventObject();
int layId = static_cast<wxWindow*>( btn )->GetId();
bool isVisible = aEvent.GetInt();
int layerId = static_cast<wxWindow*>( btn )->GetId();
wxASSERT( layId >= 0 && layId < PCB_LAYER_ID_COUNT );
if( m_isFpEditor && LSET::ForbiddenFootprintLayers().test( layId ) )
{
static_cast<BITMAP_TOGGLE*>( btn )->SetValue( !isVisible );
return;
}
onLayerVisibilityChanged( static_cast<PCB_LAYER_ID>( layId ),
isVisible, true );
onLayerVisibilityToggled( static_cast<PCB_LAYER_ID>( layerId ) );
} );
swatch->Bind( COLOR_SWATCH_CHANGED, &APPEARANCE_CONTROLS::OnColorSwatchChanged,
@ -1927,23 +1917,14 @@ 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();
}

View File

@ -2,7 +2,7 @@
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2020 Jon Evans <jon@craftyjon.com>
* 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
@ -329,7 +329,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 );