Improve edit point legibility with a hover state

This commit is contained in:
Jon Evans 2020-09-23 21:27:23 -04:00
parent 22891c326d
commit 690575e2b6
5 changed files with 71 additions and 27 deletions

View File

@ -136,7 +136,7 @@ COLOR_SETTINGS::COLOR_SETTINGS( wxString aFilename ) :
CLR( "board.pad_through_hole", LAYER_PADS_TH, COLOR4D( YELLOW ) ); CLR( "board.pad_through_hole", LAYER_PADS_TH, COLOR4D( YELLOW ) );
CLR( "board.plated_hole", LAYER_NON_PLATEDHOLES, COLOR4D( YELLOW ) ); CLR( "board.plated_hole", LAYER_NON_PLATEDHOLES, COLOR4D( YELLOW ) );
CLR( "board.ratsnest", LAYER_RATSNEST, COLOR4D( WHITE ) ); 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.through_via", LAYER_VIA_THROUGH, COLOR4D( LIGHTGRAY ) );
CLR( "board.via_blind_buried", LAYER_VIA_BBLIND, COLOR4D( BROWN ) ); CLR( "board.via_blind_buried", LAYER_VIA_BBLIND, COLOR4D( BROWN ) );
CLR( "board.via_hole", LAYER_VIAS_HOLES, COLOR4D( WHITE ) ); CLR( "board.via_hole", LAYER_VIAS_HOLES, COLOR4D( WHITE ) );

View File

@ -243,36 +243,43 @@ void EDIT_POINTS::ViewDraw( int aLayer, KIGFX::VIEW* aView ) const
{ {
auto gal = aView->GetGAL(); auto gal = aView->GetGAL();
KIGFX::COLOR4D drawColor = aView->GetPainter()->GetSettings()->GetLayerColor( LAYER_AUX_ITEMS ); KIGFX::RENDER_SETTINGS* settings = aView->GetPainter()->GetSettings();
KIGFX::COLOR4D highlightColor = KIGFX::COLOR4D drawColor = settings->GetLayerColor( LAYER_AUX_ITEMS );
aView->GetPainter()->GetSettings()->GetLayerColor( LAYER_SELECT_OVERLAY ); KIGFX::COLOR4D bgColor = drawColor.Darkened( 0.3 ).WithAlpha( 0.8 );
KIGFX::COLOR4D highlightColor = settings->GetLayerColor( LAYER_SELECT_OVERLAY );
gal->SetFillColor( drawColor ); gal->SetFillColor( drawColor );
gal->SetStrokeColor( bgColor );
gal->SetIsFill( true ); gal->SetIsFill( true );
gal->SetIsStroke( false ); gal->SetIsStroke( true );
gal->PushDepth(); gal->PushDepth();
gal->SetLayerDepth( gal->GetMinDepth() ); gal->SetLayerDepth( gal->GetMinDepth() );
float size = aView->ToWorld( EDIT_POINT::POINT_SIZE ); double size = aView->ToWorld( EDIT_POINT::POINT_SIZE ) / 2.0;
float shadowSize = aView->ToWorld( EDIT_POINT::POINT_SIZE * 1.5 ); double borderSize = aView->ToWorld( EDIT_POINT::BORDER_SIZE );
double hoverSize = aView->ToWorld( EDIT_POINT::HOVER_SIZE );
for( const EDIT_POINT& point : m_points ) for( const EDIT_POINT& point : m_points )
{ {
if( point.IsActive() ) if( point.IsHover() || point.IsActive() )
{ {
gal->SetFillColor( highlightColor ); gal->SetStrokeColor( highlightColor );
gal->DrawRectangle( point.GetPosition() - shadowSize / 2, gal->SetLineWidth( hoverSize );
point.GetPosition() + shadowSize / 2 ); }
gal->SetFillColor( drawColor ); 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 ) for( const EDIT_LINE& line : m_lines )
{ {
gal->DrawCircle( line.GetPosition(), size / 2 ); gal->DrawCircle( line.GetPosition(), size );
} }
gal->PopDepth(); gal->PopDepth();

View File

@ -54,7 +54,8 @@ public:
EDIT_POINT( const VECTOR2I& aPoint, EDA_ITEM* aConnection = nullptr ) : EDIT_POINT( const VECTOR2I& aPoint, EDA_ITEM* aConnection = nullptr ) :
m_position( aPoint ), m_position( aPoint ),
m_connection( aConnection ), m_connection( aConnection ),
m_isActive( false ) m_isActive( false ),
m_isHover( false )
{ {
} }
@ -177,15 +178,11 @@ public:
m_constraint->Apply(); m_constraint->Apply();
} }
inline bool IsActive() const bool IsActive() const { return m_isActive; }
{ void SetActive( bool aActive = true ) { m_isActive = aActive; }
return m_isActive;
}
inline void SetActive( bool aActive = true ) bool IsHover() const { return m_isHover; }
{ void SetHover( bool aHover = true ) { m_isHover = aHover; }
m_isActive = aActive;
}
bool operator==( const EDIT_POINT& aOther ) const bool operator==( const EDIT_POINT& aOther ) const
{ {
@ -195,6 +192,12 @@ public:
///> Single point size in pixels ///> Single point size in pixels
static const int POINT_SIZE = 10; 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: private:
///> Position of EDIT_POINT ///> Position of EDIT_POINT
VECTOR2I m_position; VECTOR2I m_position;
@ -208,6 +211,9 @@ private:
///> True if this point is being manipulated ///> True if this point is being manipulated
bool m_isActive; bool m_isActive;
///> True if this point is being hovered over
bool m_isHover;
}; };

View File

@ -308,8 +308,9 @@ private:
POINT_EDITOR::POINT_EDITOR() : POINT_EDITOR::POINT_EDITOR() :
PCB_TOOL_BASE( "pcbnew.PointEditor" ), PCB_TOOL_BASE( "pcbnew.PointEditor" ),
m_selectionTool( NULL ), m_selectionTool( nullptr ),
m_editedPoint( NULL ), m_editedPoint( nullptr ),
m_hoveredPoint( nullptr ),
m_original( VECTOR2I( 0, 0 ) ), m_original( VECTOR2I( 0, 0 ) ),
m_altConstrainer( VECTOR2I( 0, 0 ) ), m_altConstrainer( VECTOR2I( 0, 0 ) ),
m_refill( false ), m_refill( false ),
@ -350,10 +351,12 @@ bool POINT_EDITOR::Init()
void POINT_EDITOR::updateEditedPoint( const TOOL_EVENT& aEvent ) void POINT_EDITOR::updateEditedPoint( const TOOL_EVENT& aEvent )
{ {
EDIT_POINT* point; EDIT_POINT* point;
EDIT_POINT* hovered = nullptr;
if( aEvent.IsMotion() ) if( aEvent.IsMotion() )
{ {
point = m_editPoints->FindPoint( aEvent.Position(), getView() ); point = m_editPoints->FindPoint( aEvent.Position(), getView() );
hovered = point;
} }
else if( aEvent.IsDrag( BUT_LEFT ) ) 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() ); 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 ) if( m_editedPoint != point )
setEditedPoint( point ); setEditedPoint( point );
} }
@ -421,9 +441,14 @@ int POINT_EDITOR::OnSelectionChange( const TOOL_EVENT& aEvent )
if( !m_editPoints || evt->IsSelectionEvent() ) if( !m_editPoints || evt->IsSelectionEvent() )
break; break;
if ( !inDrag ) EDIT_POINT* prevHover = m_hoveredPoint;
if( !inDrag )
updateEditedPoint( *evt ); updateEditedPoint( *evt );
if( prevHover != m_hoveredPoint )
getView()->Update( m_editPoints.get() );
if( evt->IsDrag( BUT_LEFT ) && m_editedPoint ) if( evt->IsDrag( BUT_LEFT ) && m_editedPoint )
{ {
if( !inDrag ) if( !inDrag )
@ -459,7 +484,11 @@ int POINT_EDITOR::OnSelectionChange( const TOOL_EVENT& aEvent )
updateItem(); updateItem();
updatePoints(); 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 ) ) else if( inDrag && evt->IsMouseUp( BUT_LEFT ) )
{ {
if( m_editedPoint ) if( m_editedPoint )

View File

@ -74,6 +74,8 @@ private:
///> Currently edited point, NULL if there is none. ///> Currently edited point, NULL if there is none.
EDIT_POINT* m_editedPoint; EDIT_POINT* m_editedPoint;
EDIT_POINT* m_hoveredPoint;
///> Original position for the current drag point. ///> Original position for the current drag point.
EDIT_POINT m_original; EDIT_POINT m_original;