From 690575e2b679b262848308676829cbe93da96e34 Mon Sep 17 00:00:00 2001 From: Jon Evans Date: Wed, 23 Sep 2020 21:27:23 -0400 Subject: [PATCH] Improve edit point legibility with a hover state --- common/settings/color_settings.cpp | 2 +- common/tool/edit_points.cpp | 33 +++++++++++++++----------- include/tool/edit_points.h | 24 +++++++++++-------- pcbnew/tools/point_editor.cpp | 37 ++++++++++++++++++++++++++---- pcbnew/tools/point_editor.h | 2 ++ 5 files changed, 71 insertions(+), 27 deletions(-) diff --git a/common/settings/color_settings.cpp b/common/settings/color_settings.cpp index 01bbc06a2e..99e91fe665 100644 --- a/common/settings/color_settings.cpp +++ b/common/settings/color_settings.cpp @@ -136,7 +136,7 @@ COLOR_SETTINGS::COLOR_SETTINGS( wxString aFilename ) : CLR( "board.pad_through_hole", LAYER_PADS_TH, COLOR4D( YELLOW ) ); CLR( "board.plated_hole", LAYER_NON_PLATEDHOLES, COLOR4D( YELLOW ) ); CLR( "board.ratsnest", LAYER_RATSNEST, COLOR4D( WHITE ) ); - CLR( "board.select_overlay", LAYER_SELECT_OVERLAY, COLOR4D( DARKRED ) ); + CLR( "board.select_overlay", LAYER_SELECT_OVERLAY, COLOR4D( PUREGREEN ) ); CLR( "board.through_via", LAYER_VIA_THROUGH, COLOR4D( LIGHTGRAY ) ); CLR( "board.via_blind_buried", LAYER_VIA_BBLIND, COLOR4D( BROWN ) ); CLR( "board.via_hole", LAYER_VIAS_HOLES, COLOR4D( WHITE ) ); diff --git a/common/tool/edit_points.cpp b/common/tool/edit_points.cpp index db8db1c71a..985c39fe55 100644 --- a/common/tool/edit_points.cpp +++ b/common/tool/edit_points.cpp @@ -243,36 +243,43 @@ void EDIT_POINTS::ViewDraw( int aLayer, KIGFX::VIEW* aView ) const { auto gal = aView->GetGAL(); - KIGFX::COLOR4D drawColor = aView->GetPainter()->GetSettings()->GetLayerColor( LAYER_AUX_ITEMS ); + KIGFX::RENDER_SETTINGS* settings = aView->GetPainter()->GetSettings(); - KIGFX::COLOR4D highlightColor = - aView->GetPainter()->GetSettings()->GetLayerColor( LAYER_SELECT_OVERLAY ); + KIGFX::COLOR4D drawColor = settings->GetLayerColor( LAYER_AUX_ITEMS ); + KIGFX::COLOR4D bgColor = drawColor.Darkened( 0.3 ).WithAlpha( 0.8 ); + KIGFX::COLOR4D highlightColor = settings->GetLayerColor( LAYER_SELECT_OVERLAY ); gal->SetFillColor( drawColor ); + gal->SetStrokeColor( bgColor ); gal->SetIsFill( true ); - gal->SetIsStroke( false ); + gal->SetIsStroke( true ); gal->PushDepth(); gal->SetLayerDepth( gal->GetMinDepth() ); - float size = aView->ToWorld( EDIT_POINT::POINT_SIZE ); - float shadowSize = aView->ToWorld( EDIT_POINT::POINT_SIZE * 1.5 ); + double size = aView->ToWorld( EDIT_POINT::POINT_SIZE ) / 2.0; + double borderSize = aView->ToWorld( EDIT_POINT::BORDER_SIZE ); + double hoverSize = aView->ToWorld( EDIT_POINT::HOVER_SIZE ); for( const EDIT_POINT& point : m_points ) { - if( point.IsActive() ) + if( point.IsHover() || point.IsActive() ) { - gal->SetFillColor( highlightColor ); - gal->DrawRectangle( point.GetPosition() - shadowSize / 2, - point.GetPosition() + shadowSize / 2 ); - gal->SetFillColor( drawColor ); + gal->SetStrokeColor( highlightColor ); + gal->SetLineWidth( hoverSize ); + } + else + { + gal->SetStrokeColor( bgColor ); + gal->SetLineWidth( borderSize ); } - gal->DrawRectangle( point.GetPosition() - size / 2, point.GetPosition() + size / 2 ); + gal->SetFillColor( point.IsActive() ? highlightColor : drawColor ); + gal->DrawRectangle( point.GetPosition() - size, point.GetPosition() + size ); } for( const EDIT_LINE& line : m_lines ) { - gal->DrawCircle( line.GetPosition(), size / 2 ); + gal->DrawCircle( line.GetPosition(), size ); } gal->PopDepth(); diff --git a/include/tool/edit_points.h b/include/tool/edit_points.h index ae46cad594..e2d50c81bd 100644 --- a/include/tool/edit_points.h +++ b/include/tool/edit_points.h @@ -54,7 +54,8 @@ public: EDIT_POINT( const VECTOR2I& aPoint, EDA_ITEM* aConnection = nullptr ) : m_position( aPoint ), m_connection( aConnection ), - m_isActive( false ) + m_isActive( false ), + m_isHover( false ) { } @@ -177,15 +178,11 @@ public: m_constraint->Apply(); } - inline bool IsActive() const - { - return m_isActive; - } + bool IsActive() const { return m_isActive; } + void SetActive( bool aActive = true ) { m_isActive = aActive; } - inline void SetActive( bool aActive = true ) - { - m_isActive = aActive; - } + bool IsHover() const { return m_isHover; } + void SetHover( bool aHover = true ) { m_isHover = aHover; } bool operator==( const EDIT_POINT& aOther ) const { @@ -195,6 +192,12 @@ public: ///> Single point size in pixels static const int POINT_SIZE = 10; + ///> Border size when not hovering + static const int BORDER_SIZE = 2; + + ///> Border size when hovering + static const int HOVER_SIZE = 5; + private: ///> Position of EDIT_POINT VECTOR2I m_position; @@ -208,6 +211,9 @@ private: ///> True if this point is being manipulated bool m_isActive; + + ///> True if this point is being hovered over + bool m_isHover; }; diff --git a/pcbnew/tools/point_editor.cpp b/pcbnew/tools/point_editor.cpp index 43dfba4001..f0e48a4840 100644 --- a/pcbnew/tools/point_editor.cpp +++ b/pcbnew/tools/point_editor.cpp @@ -308,8 +308,9 @@ private: POINT_EDITOR::POINT_EDITOR() : PCB_TOOL_BASE( "pcbnew.PointEditor" ), - m_selectionTool( NULL ), - m_editedPoint( NULL ), + m_selectionTool( nullptr ), + m_editedPoint( nullptr ), + m_hoveredPoint( nullptr ), m_original( VECTOR2I( 0, 0 ) ), m_altConstrainer( VECTOR2I( 0, 0 ) ), m_refill( false ), @@ -350,10 +351,12 @@ bool POINT_EDITOR::Init() void POINT_EDITOR::updateEditedPoint( const TOOL_EVENT& aEvent ) { EDIT_POINT* point; + EDIT_POINT* hovered = nullptr; if( aEvent.IsMotion() ) { point = m_editPoints->FindPoint( aEvent.Position(), getView() ); + hovered = point; } else if( aEvent.IsDrag( BUT_LEFT ) ) { @@ -364,6 +367,23 @@ void POINT_EDITOR::updateEditedPoint( const TOOL_EVENT& aEvent ) point = m_editPoints->FindPoint( getViewControls()->GetCursorPosition(), getView() ); } + if( hovered ) + { + if( m_hoveredPoint != hovered ) + { + if( m_hoveredPoint ) + m_hoveredPoint->SetHover( false ); + + m_hoveredPoint = hovered; + m_hoveredPoint->SetHover(); + } + } + else if( m_hoveredPoint ) + { + m_hoveredPoint->SetHover( false ); + m_hoveredPoint = nullptr; + } + if( m_editedPoint != point ) setEditedPoint( point ); } @@ -421,9 +441,14 @@ int POINT_EDITOR::OnSelectionChange( const TOOL_EVENT& aEvent ) if( !m_editPoints || evt->IsSelectionEvent() ) break; - if ( !inDrag ) + EDIT_POINT* prevHover = m_hoveredPoint; + + if( !inDrag ) updateEditedPoint( *evt ); + if( prevHover != m_hoveredPoint ) + getView()->Update( m_editPoints.get() ); + if( evt->IsDrag( BUT_LEFT ) && m_editedPoint ) { if( !inDrag ) @@ -459,7 +484,11 @@ int POINT_EDITOR::OnSelectionChange( const TOOL_EVENT& aEvent ) updateItem(); updatePoints(); } - + else if( m_editedPoint && evt->Action() == TA_MOUSE_DOWN && evt->Buttons() == BUT_LEFT ) + { + m_editedPoint->SetActive(); + getView()->Update( m_editPoints.get() ); + } else if( inDrag && evt->IsMouseUp( BUT_LEFT ) ) { if( m_editedPoint ) diff --git a/pcbnew/tools/point_editor.h b/pcbnew/tools/point_editor.h index d4b83aaf80..b54d8ad6bf 100644 --- a/pcbnew/tools/point_editor.h +++ b/pcbnew/tools/point_editor.h @@ -74,6 +74,8 @@ private: ///> Currently edited point, NULL if there is none. EDIT_POINT* m_editedPoint; + EDIT_POINT* m_hoveredPoint; + ///> Original position for the current drag point. EDIT_POINT m_original;