From 713cd4a47a6f9353d2245e7467555e6e87eaf8a6 Mon Sep 17 00:00:00 2001 From: Jon Evans Date: Sun, 21 Jun 2020 14:43:33 -0400 Subject: [PATCH] Point editor: show dragged points with a highlight Take points editor colors from color theme Also fix an issue where the edited object sometimes didn't update when a point is dragged. Fixes https://gitlab.com/kicad/code/kicad/-/issues/4600 --- common/layer_id.cpp | 2 +- common/tool/edit_points.cpp | 23 ++++++++++++++++++----- include/tool/edit_points.h | 16 +++++++++++++++- pcbnew/tools/point_editor.cpp | 9 +++++++++ 4 files changed, 43 insertions(+), 7 deletions(-) diff --git a/common/layer_id.cpp b/common/layer_id.cpp index bd0d6a2ac5..1c569c62ff 100644 --- a/common/layer_id.cpp +++ b/common/layer_id.cpp @@ -198,7 +198,7 @@ wxString LayerName( int aLayer ) return _( "Cursor" ); case LAYER_AUX_ITEMS: - return _( "Aux Items" ); + return _( "Helper items" ); case LAYER_GRID: return _( "Grid" ); diff --git a/common/tool/edit_points.cpp b/common/tool/edit_points.cpp index 2ba358e5ab..db8db1c71a 100644 --- a/common/tool/edit_points.cpp +++ b/common/tool/edit_points.cpp @@ -243,19 +243,32 @@ void EDIT_POINTS::ViewDraw( int aLayer, KIGFX::VIEW* aView ) const { auto gal = aView->GetGAL(); - if( aView->GetGAL()->GetClearColor().GetBrightness() > 0.5 ) - gal->SetFillColor( KIGFX::COLOR4D( 0, 0, 0, 1.0 ) ); - else - gal->SetFillColor( KIGFX::COLOR4D( 1.0, 1.0, 1.0, 1.0 ) ); + KIGFX::COLOR4D drawColor = aView->GetPainter()->GetSettings()->GetLayerColor( LAYER_AUX_ITEMS ); + + KIGFX::COLOR4D highlightColor = + aView->GetPainter()->GetSettings()->GetLayerColor( LAYER_SELECT_OVERLAY ); + + gal->SetFillColor( drawColor ); gal->SetIsFill( true ); gal->SetIsStroke( false ); gal->PushDepth(); gal->SetLayerDepth( gal->GetMinDepth() ); - float size = aView->ToWorld( EDIT_POINT::POINT_SIZE ); + float size = aView->ToWorld( EDIT_POINT::POINT_SIZE ); + float shadowSize = aView->ToWorld( EDIT_POINT::POINT_SIZE * 1.5 ); for( const EDIT_POINT& point : m_points ) + { + if( point.IsActive() ) + { + gal->SetFillColor( highlightColor ); + gal->DrawRectangle( point.GetPosition() - shadowSize / 2, + point.GetPosition() + shadowSize / 2 ); + gal->SetFillColor( drawColor ); + } + gal->DrawRectangle( point.GetPosition() - size / 2, point.GetPosition() + size / 2 ); + } for( const EDIT_LINE& line : m_lines ) { diff --git a/include/tool/edit_points.h b/include/tool/edit_points.h index 7c324d3f45..ae46cad594 100644 --- a/include/tool/edit_points.h +++ b/include/tool/edit_points.h @@ -53,7 +53,8 @@ public: */ EDIT_POINT( const VECTOR2I& aPoint, EDA_ITEM* aConnection = nullptr ) : m_position( aPoint ), - m_connection( aConnection ) + m_connection( aConnection ), + m_isActive( false ) { } @@ -176,6 +177,16 @@ public: m_constraint->Apply(); } + inline bool IsActive() const + { + return m_isActive; + } + + inline void SetActive( bool aActive = true ) + { + m_isActive = aActive; + } + bool operator==( const EDIT_POINT& aOther ) const { return m_position == aOther.m_position; @@ -194,6 +205,9 @@ private: ///> Constraint for the point, NULL if none std::shared_ptr > m_constraint; + + ///> True if this point is being manipulated + bool m_isActive; }; diff --git a/pcbnew/tools/point_editor.cpp b/pcbnew/tools/point_editor.cpp index 41635e64e5..fa1a9e7f71 100644 --- a/pcbnew/tools/point_editor.cpp +++ b/pcbnew/tools/point_editor.cpp @@ -361,6 +361,7 @@ int POINT_EDITOR::OnSelectionChange( const TOOL_EVENT& aEvent ) controls->SetAutoPan( true ); inDrag = true; grid.SetAuxAxes( true, m_original.GetPosition() ); + m_editedPoint->SetActive(); } //TODO: unify the constraints to solve simultaneously instead of sequentially @@ -387,6 +388,12 @@ int POINT_EDITOR::OnSelectionChange( const TOOL_EVENT& aEvent ) else if( inDrag && evt->IsMouseUp( BUT_LEFT ) ) { + if( m_editedPoint ) + { + m_editedPoint->SetActive( false ); + getView()->Update( m_editPoints.get() ); + } + controls->SetAutoPan( false ); setAltConstraint( false ); @@ -649,6 +656,8 @@ void POINT_EDITOR::updateItem() const break; } + getView()->Update( item ); + if( frame() ) frame()->SetMsgPanel( item ); }