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
This commit is contained in:
Jon Evans 2020-06-21 14:43:33 -04:00
parent 7240b3e4d3
commit 713cd4a47a
4 changed files with 43 additions and 7 deletions

View File

@ -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" );

View File

@ -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 )
{

View File

@ -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<EDIT_CONSTRAINT<EDIT_POINT> > m_constraint;
///> True if this point is being manipulated
bool m_isActive;
};

View File

@ -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 );
}