From 51479c20425094698ee3e02c2264bad66a949e9f Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sat, 29 Jun 2019 19:45:32 +0100 Subject: [PATCH] Fix several bugs in selection exhibited by 74LS02. 1) Use PenWidth() (which is clipped at 0) instead of Width() 2) Implement an interior HitTest when a PolyLine is filled 3) Brighten background objects as well as foreground 4) Don't HitTest last segment when PolyLine is not filled Fixes: lp:1834703 * https://bugs.launchpad.net/kicad/+bug/1834703 --- eeschema/lib_polyline.cpp | 26 ++++++++++++++------------ eeschema/sch_painter.cpp | 17 +++++++++++++---- 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/eeschema/lib_polyline.cpp b/eeschema/lib_polyline.cpp index e9b1ebd961..6eee79945f 100644 --- a/eeschema/lib_polyline.cpp +++ b/eeschema/lib_polyline.cpp @@ -228,19 +228,19 @@ void LIB_POLYLINE::print( wxDC* aDC, const wxPoint& aOffset, void* aData, bool LIB_POLYLINE::HitTest( const wxPoint& aPosition, int aAccuracy ) const { - int mindist = std::max( aAccuracy + GetPenSize() / 2, MINIMUM_SELECTION_DISTANCE ); - wxPoint start, end; + int delta = std::max( aAccuracy + GetPenSize() / 2, MINIMUM_SELECTION_DISTANCE ); + SHAPE_LINE_CHAIN shape; - for( unsigned ii = 1; ii < GetCornerCount(); ii++ ) + for( wxPoint pt : m_PolyPoints ) + shape.Append( DefaultTransform.TransformCoordinate( pt ) ); + + if( m_Fill != NO_FILL && m_PolyPoints.size() > 2 ) { - start = DefaultTransform.TransformCoordinate( m_PolyPoints[ii - 1] ); - end = DefaultTransform.TransformCoordinate( m_PolyPoints[ii] ); - - if( TestSegmentHit( aPosition, start, end, mindist ) ) - return true; + shape.SetClosed( true ); + return shape.PointInside( aPosition, delta ); } - - return false; + else + return shape.PointOnEdge( aPosition, delta ); } @@ -262,8 +262,10 @@ bool LIB_POLYLINE::HitTest( const EDA_RECT& aRect, bool aContained, int aAccurac return false; // Account for the width of the line - sel.Inflate( GetWidth() / 2 ); - int count = m_PolyPoints.size(); + sel.Inflate( GetPenSize() / 2 ); + + // Only test closing segment if the polyline is filled + int count = m_Fill == NO_FILL ? m_PolyPoints.size() - 1 : m_PolyPoints.size(); for( int ii = 0; ii < count; ii++ ) { diff --git a/eeschema/sch_painter.cpp b/eeschema/sch_painter.cpp index c3ccea822a..0a96c41673 100644 --- a/eeschema/sch_painter.cpp +++ b/eeschema/sch_painter.cpp @@ -227,14 +227,23 @@ COLOR4D SCH_PAINTER::getRenderColor( const EDA_ITEM* aItem, int aLayer, bool aOn { COLOR4D color = m_schSettings.GetLayerColor( aLayer ); - if( aItem->IsBrightened() && !aOnBackgroundLayer ) - color = m_schSettings.GetLayerColor( LAYER_BRIGHTENED ); - else if( aItem->Type() == SCH_LINE_T ) + if( aItem->Type() == SCH_LINE_T ) color = static_cast( aItem )->GetLineColor(); + if( aItem->IsBrightened() ) + { + color = m_schSettings.GetLayerColor( LAYER_BRIGHTENED ); + + if( aOnBackgroundLayer ) + color = color.WithAlpha( 0.2 ); + } + if( aItem->IsSelected() ) { - return color.Brightened( 0.5 ); + if( aOnBackgroundLayer ) + return color.Brightened( 0.2 ); + else + return color.Brightened( 0.5 ); } else if( aItem->IsHighlighted() ) {