From cd738297b072e556164e52fecb701ef9283d89f2 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Tue, 9 May 2017 17:28:54 +1000 Subject: [PATCH] SELECTION_AREA color now indicates selection mode BLUE = Normal GREEN = Addition RED = Subtraction Line color indicates "window" or "crossing" selection mode --- common/preview_items/selection_area.cpp | 49 +++++++++++++++++++++---- include/preview_items/selection_area.h | 10 +++++ pcbnew/tools/selection_tool.cpp | 7 ++-- 3 files changed, 55 insertions(+), 11 deletions(-) diff --git a/common/preview_items/selection_area.cpp b/common/preview_items/selection_area.cpp index 001e6df6a3..ecee3c386e 100644 --- a/common/preview_items/selection_area.cpp +++ b/common/preview_items/selection_area.cpp @@ -30,16 +30,36 @@ using namespace KIGFX::PREVIEW; // Selection area colours -const COLOR4D SELECT_COLOR_L2R( 0.3, 0.3, 0.6, 0.3 ); // Slight blue -const COLOR4D SELECT_COLOR_R2L( 0.3, 0.6, 0.3, 0.3 ); // Slight green +const COLOR4D SELECT_MODE_NORMAL( 0.3, 0.3, 0.7, 0.3 ); // Slight blue +const COLOR4D SELECT_MODE_ADDITIVE( 0.3, 0.7, 0.3, 0.3 ); // Slight green +const COLOR4D SELECT_MODE_SUBTRACT( 0.7, 0.3, 0.3, 0.3 ); // Slight red +const COLOR4D SELECT_OUTLINE_L2R( 1.0, 1.0, 0.4, 1.0 ); +const COLOR4D SELECT_OUTLINE_R2L( 0.4, 0.4, 1.0, 1.0 ); -SELECTION_AREA::SELECTION_AREA() +SELECTION_AREA::SELECTION_AREA() : + m_additive( false ), + m_subtractive( false ) { - SetStrokeColor( COLOR4D( 1.0, 1.0, 0.4, 1.0 ) ); - SetFillColor( COLOR4D( 0.3, 0.3, 0.5, 0.3 ) ); + SetStrokeColor( SELECT_OUTLINE_L2R ); + SetFillColor( SELECT_MODE_NORMAL ); } +void SELECTION_AREA::SetAdditive( bool aAdditive ) +{ + m_additive = aAdditive; + + if( m_additive ) + m_subtractive = false; +} + +void SELECTION_AREA::SetSubtractive( bool aSubtractive ) +{ + m_subtractive = aSubtractive; + + if ( m_subtractive ) + m_additive = false; +} const BOX2I SELECTION_AREA::ViewBBox() const { @@ -54,8 +74,23 @@ const BOX2I SELECTION_AREA::ViewBBox() const void SELECTION_AREA::drawPreviewShape( KIGFX::GAL& aGal ) const { - // Set the fill color based on the direction of selection - aGal.SetFillColor( ( m_origin.x <= m_end.x ) ? SELECT_COLOR_L2R : SELECT_COLOR_R2L ); + // Set the fill of the selection rectangle + // based on the selection mode + if( m_additive ) + { + aGal.SetFillColor( SELECT_MODE_ADDITIVE ); + } + else if( m_subtractive ) + { + aGal.SetFillColor( SELECT_MODE_SUBTRACT ); + } + else + { + aGal.SetFillColor( SELECT_MODE_NORMAL ); + } + + // Set the stroke color to indicate window or crossing selection + aGal.SetStrokeColor( ( m_origin.x <= m_end.x ) ? SELECT_OUTLINE_L2R : SELECT_OUTLINE_R2L ); aGal.DrawRectangle( m_origin, m_end ); } diff --git a/include/preview_items/selection_area.h b/include/preview_items/selection_area.h index d45924bd6e..a2b1db2059 100644 --- a/include/preview_items/selection_area.h +++ b/include/preview_items/selection_area.h @@ -80,8 +80,18 @@ public: VECTOR2I GetEnd() const { return m_end; } + bool IsAdditive() const { return m_additive; } + bool IsSubtractive() const { return m_subtractive; } + + void SetAdditive( bool aAdditive ); + void SetSubtractive( bool aSubtractive ); + + private: + bool m_additive; + bool m_subtractive; + /** * Draw the selection rectangle onto the GAL */ diff --git a/pcbnew/tools/selection_tool.cpp b/pcbnew/tools/selection_tool.cpp index ec4e980a47..dd339f3f7d 100644 --- a/pcbnew/tools/selection_tool.cpp +++ b/pcbnew/tools/selection_tool.cpp @@ -488,14 +488,13 @@ bool SELECTION_TOOL::selectMultiple() if( evt->IsDrag( BUT_LEFT ) ) { - if( !m_additive && !m_subtractive ) - { - clearSelection(); - } // Start drawing a selection box area.SetOrigin( evt->DragOrigin() ); area.SetEnd( evt->Position() ); + area.SetAdditive( m_additive ); + area.SetSubtractive( m_subtractive ); + view->SetVisible( &area, true ); view->Update( &area ); }