From 684d15895cdefc4b316308798b46ae9f97029dd9 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Wed, 15 Sep 2021 21:15:55 +0100 Subject: [PATCH] Box highlighting of selected text was never finished. In particular, pin numbers and names weren't done. --- eeschema/sch_painter.cpp | 179 +++++++++++++++++++++++++-------------- eeschema/sch_painter.h | 2 + 2 files changed, 118 insertions(+), 63 deletions(-) diff --git a/eeschema/sch_painter.cpp b/eeschema/sch_painter.cpp index 93b69bf7e3..a3e1e40c90 100644 --- a/eeschema/sch_painter.cpp +++ b/eeschema/sch_painter.cpp @@ -26,7 +26,7 @@ #include - +#include #include #include #include @@ -205,8 +205,8 @@ bool SCH_PAINTER::Draw( const VIEW_ITEM *aItem, int aLayer ) m_gal->SetIsFill( false ); m_gal->SetIsStroke( true ); - m_gal->SetStrokeColor( item->IsSelected() ? COLOR4D( 1.0, 0.2, 0.2, 1 ) : - COLOR4D( 0.2, 0.2, 0.2, 1 ) ); + m_gal->SetStrokeColor( item->IsSelected() ? COLOR4D( 1.0, 0.2, 0.2, 1 ) + : COLOR4D( 0.2, 0.2, 0.2, 1 ) ); m_gal->SetLineWidth( Mils2iu( 3 ) ); m_gal->DrawRectangle( box.GetOrigin(), box.GetEnd() ); } @@ -409,9 +409,46 @@ float SCH_PAINTER::getTextThickness( const LIB_TEXT* aItem, bool aDrawingShadows } +static VECTOR2D mapCoords( const wxPoint& aCoord ) +{ + return VECTOR2D( aCoord.x, -aCoord.y ); +} + + void SCH_PAINTER::strokeText( const wxString& aText, const VECTOR2D& aPosition, double aAngle ) { - m_gal->StrokeText( aText, aPosition, aAngle ); + m_gal->StrokeText( aText, VECTOR2D( aPosition.x, aPosition.y ), aAngle ); +} + + +void SCH_PAINTER::boxText( const wxString& aText, const VECTOR2D& aPosition, double aAngle ) +{ + const STROKE_FONT& font = m_gal->GetStrokeFont(); + VECTOR2D extents = font.ComputeStringBoundaryLimits( aText, m_gal->GetGlyphSize(), + m_gal->GetLineWidth() ); + EDA_RECT box( (wxPoint) aPosition, wxSize( extents.x, extents.y ) ); + + if( m_gal->GetHorizontalJustify() == GR_TEXT_HJUSTIFY_CENTER ) + box.SetX( box.GetX() - ( box.GetWidth() / 2) ); + else if( m_gal->GetHorizontalJustify() == GR_TEXT_HJUSTIFY_RIGHT ) + box.SetX( box.GetX() - box.GetWidth() ); + + if( m_gal->GetVerticalJustify() == GR_TEXT_VJUSTIFY_CENTER ) + box.SetY( box.GetY() - ( box.GetHeight() / 2) ); + else if( m_gal->GetVerticalJustify() == GR_TEXT_VJUSTIFY_BOTTOM ) + box.SetY( box.GetY() - box.GetHeight() ); + + box.Normalize(); // Make h and v sizes always >= 0 + box = box.GetBoundingBoxRotated((wxPoint) aPosition, RAD2DECIDEG( aAngle ) ); + box.RevertYAxis(); + m_gal->DrawRectangle( mapCoords( box.GetOrigin() ), mapCoords( box.GetEnd() ) ); +} + + +void SCH_PAINTER::triLine( const VECTOR2D &a, const VECTOR2D &b, const VECTOR2D &c ) +{ + m_gal->DrawLine( a, b ); + m_gal->DrawLine( b, c ); } @@ -448,19 +485,6 @@ void SCH_PAINTER::draw( const LIB_SYMBOL *aSymbol, int aLayer, bool aDrawFields, } -static VECTOR2D mapCoords( const wxPoint& aCoord ) -{ - return VECTOR2D( aCoord.x, -aCoord.y ); -} - - -void SCH_PAINTER::triLine( const VECTOR2D &a, const VECTOR2D &b, const VECTOR2D &c ) -{ - m_gal->DrawLine( a, b ); - m_gal->DrawLine( b, c ); -} - - bool SCH_PAINTER::setDeviceColors( const LIB_ITEM* aItem, int aLayer ) { switch( aLayer ) @@ -1013,150 +1037,175 @@ void SCH_PAINTER::draw( LIB_PIN *aPin, int aLayer ) c = getRenderColor( aPin, LAYER_HIDDEN, drawingShadows ); } - int insideOffset = textOffset; - int outsideOffset = 2 * Mils2iu( PIN_TEXT_MARGIN ) + ( dangling ? TARGET_PIN_RADIUS / 2 : 0 ); - float lineThickness = (float) m_schSettings.GetDefaultPenWidth(); - float aboveOffset = Mils2iu( PIN_TEXT_MARGIN ) + ( thickness[ABOVE] + lineThickness ) / 2.0; - float belowOffset = Mils2iu( PIN_TEXT_MARGIN ) + ( thickness[BELOW] + lineThickness ) / 2.0; + int insideOffset = textOffset; + int outsideOffset = 2 * Mils2iu( PIN_TEXT_MARGIN ) + ( dangling ? TARGET_PIN_RADIUS / 2 : 0 ); + int aboveOffset = Mils2iu( PIN_TEXT_MARGIN ) + m_schSettings.GetDefaultPenWidth() / 2; + int belowOffset = Mils2iu( PIN_TEXT_MARGIN ) + m_schSettings.GetDefaultPenWidth() / 2; if( drawingShadows ) { - for( float& t : thickness ) - t += getShadowWidth(); + float shadowWidth = getShadowWidth(); - insideOffset -= KiROUND( getShadowWidth() / 2 ); - outsideOffset -= KiROUND( getShadowWidth() / 2 ); + if( !eeconfig()->m_Selection.text_as_box ) + { + aboveOffset += thickness[ABOVE] / 2; + belowOffset += thickness[BELOW] / 2; + } + + for( float& t : thickness ) + t += shadowWidth; + + insideOffset -= KiROUND( shadowWidth / 2.0 ); + outsideOffset -= KiROUND( shadowWidth / 2.0 ); } - #define SET_DC( i ) \ - m_gal->SetGlyphSize( VECTOR2D( size[i], size[i] ) ); \ - m_gal->SetLineWidth( thickness[i] ); \ - m_gal->SetStrokeColor( colour[i] ) + auto setupDC = + [&]( int i ) + { + m_gal->SetGlyphSize( VECTOR2D( size[i], size[i] ) ); + m_gal->SetIsStroke( !( drawingShadows && eeconfig()->m_Selection.text_as_box ) ); + m_gal->SetLineWidth( thickness[i] ); + m_gal->SetStrokeColor( colour[i] ); + m_gal->SetIsFill( drawingShadows && eeconfig()->m_Selection.text_as_box ); + m_gal->SetFillColor( colour[i] ); + }; + + auto drawText = + [&]( const wxString& text, const VECTOR2D& pos, double angle ) + { + if( text.IsEmpty() ) + return; + + if( drawingShadows && eeconfig()->m_Selection.text_as_box ) + boxText( text, pos, angle ); + else + strokeText( text, pos, angle ); + }; switch( orient ) { case PIN_LEFT: if( size[INSIDE] ) { - SET_DC( INSIDE ); + setupDC( INSIDE ); m_gal->SetHorizontalJustify( GR_TEXT_HJUSTIFY_RIGHT ); m_gal->SetVerticalJustify( GR_TEXT_VJUSTIFY_CENTER ); - strokeText( text[INSIDE], pos + VECTOR2D( -insideOffset - len, 0 ), 0 ); + drawText( text[INSIDE], pos + VECTOR2D( -insideOffset - len, 0 ), 0 ); } if( size[OUTSIDE] ) { - SET_DC( OUTSIDE ); + setupDC( OUTSIDE ); m_gal->SetHorizontalJustify( GR_TEXT_HJUSTIFY_LEFT ); m_gal->SetVerticalJustify( GR_TEXT_VJUSTIFY_CENTER ); - strokeText( text[OUTSIDE], pos + VECTOR2D( outsideOffset, 0 ), 0 ); + drawText( text[OUTSIDE], pos + VECTOR2D( outsideOffset, 0 ), 0 ); } if( size[ABOVE] ) { - SET_DC( ABOVE ); + setupDC( ABOVE ); m_gal->SetHorizontalJustify( GR_TEXT_HJUSTIFY_CENTER ); m_gal->SetVerticalJustify( GR_TEXT_VJUSTIFY_BOTTOM ); - strokeText( text[ABOVE], pos + VECTOR2D( -len / 2.0, -aboveOffset ), 0 ); + drawText( text[ABOVE], pos + VECTOR2D( -len / 2.0, -aboveOffset ), 0 ); } if( size[BELOW] ) { - SET_DC( BELOW ); + setupDC( BELOW ); m_gal->SetHorizontalJustify( GR_TEXT_HJUSTIFY_CENTER ); m_gal->SetVerticalJustify( GR_TEXT_VJUSTIFY_TOP ); - strokeText( text[BELOW], pos + VECTOR2D( -len / 2.0, belowOffset ), 0 ); + drawText( text[BELOW], pos + VECTOR2D( -len / 2.0, belowOffset ), 0 ); } break; case PIN_RIGHT: if( size[INSIDE] ) { - SET_DC( INSIDE ); + setupDC( INSIDE ); m_gal->SetHorizontalJustify( GR_TEXT_HJUSTIFY_LEFT ); m_gal->SetVerticalJustify( GR_TEXT_VJUSTIFY_CENTER ); m_gal->SetHorizontalJustify( GR_TEXT_HJUSTIFY_LEFT ); - strokeText( text[INSIDE], pos + VECTOR2D( insideOffset + len, 0 ), 0 ); + drawText( text[INSIDE], pos + VECTOR2D( insideOffset + len, 0 ), 0 ); } if( size[OUTSIDE] ) { - SET_DC( OUTSIDE ); + setupDC( OUTSIDE ); m_gal->SetHorizontalJustify( GR_TEXT_HJUSTIFY_RIGHT ); m_gal->SetVerticalJustify( GR_TEXT_VJUSTIFY_CENTER ); - strokeText( text[OUTSIDE], pos + VECTOR2D( -outsideOffset, 0 ), 0 ); + drawText( text[OUTSIDE], pos + VECTOR2D( -outsideOffset, 0 ), 0 ); } if( size[ABOVE] ) { - SET_DC( ABOVE ); + setupDC( ABOVE ); m_gal->SetHorizontalJustify( GR_TEXT_HJUSTIFY_CENTER ); m_gal->SetVerticalJustify( GR_TEXT_VJUSTIFY_BOTTOM ); - strokeText( text[ABOVE], pos + VECTOR2D( len / 2.0, -aboveOffset ), 0 ); + drawText( text[ABOVE], pos + VECTOR2D( len / 2.0, -aboveOffset ), 0 ); } if( size[BELOW] ) { - SET_DC( BELOW ); + setupDC( BELOW ); m_gal->SetHorizontalJustify( GR_TEXT_HJUSTIFY_CENTER ); m_gal->SetVerticalJustify( GR_TEXT_VJUSTIFY_TOP ); - strokeText( text[BELOW], pos + VECTOR2D( len / 2.0, belowOffset ), 0 ); + drawText( text[BELOW], pos + VECTOR2D( len / 2.0, belowOffset ), 0 ); } break; case PIN_DOWN: if( size[INSIDE] ) { - SET_DC( INSIDE ); + setupDC( INSIDE ); m_gal->SetHorizontalJustify( GR_TEXT_HJUSTIFY_RIGHT ); m_gal->SetVerticalJustify( GR_TEXT_VJUSTIFY_CENTER ); - strokeText( text[INSIDE], pos + VECTOR2D( 0, insideOffset + len ), M_PI / 2 ); + drawText( text[INSIDE], pos + VECTOR2D( 0, insideOffset + len ), M_PI / 2 ); } if( size[OUTSIDE] ) { - SET_DC( OUTSIDE ); + setupDC( OUTSIDE ); m_gal->SetHorizontalJustify( GR_TEXT_HJUSTIFY_LEFT ); m_gal->SetVerticalJustify( GR_TEXT_VJUSTIFY_CENTER ); - strokeText( text[OUTSIDE], pos + VECTOR2D( 0, -outsideOffset ), M_PI / 2 ); + drawText( text[OUTSIDE], pos + VECTOR2D( 0, -outsideOffset ), M_PI / 2 ); } if( size[ABOVE] ) { - SET_DC( ABOVE ); + setupDC( ABOVE ); m_gal->SetHorizontalJustify( GR_TEXT_HJUSTIFY_CENTER ); m_gal->SetVerticalJustify( GR_TEXT_VJUSTIFY_BOTTOM ); - strokeText( text[ABOVE], pos + VECTOR2D( -aboveOffset, len / 2.0 ), M_PI / 2 ); + drawText( text[ABOVE], pos + VECTOR2D( -aboveOffset, len / 2.0 ), M_PI / 2 ); } if( size[BELOW] ) { - SET_DC( BELOW ); + setupDC( BELOW ); m_gal->SetHorizontalJustify( GR_TEXT_HJUSTIFY_CENTER ); m_gal->SetVerticalJustify( GR_TEXT_VJUSTIFY_TOP ); - strokeText( text[BELOW], pos + VECTOR2D( belowOffset, len / 2.0 ), M_PI / 2 ); + drawText( text[BELOW], pos + VECTOR2D( belowOffset, len / 2.0 ), M_PI / 2 ); } break; case PIN_UP: if( size[INSIDE] ) { - SET_DC( INSIDE ); + setupDC( INSIDE ); m_gal->SetHorizontalJustify( GR_TEXT_HJUSTIFY_LEFT ); m_gal->SetVerticalJustify( GR_TEXT_VJUSTIFY_CENTER ); - strokeText( text[INSIDE], pos + VECTOR2D( 0, -insideOffset - len ), M_PI / 2 ); + drawText( text[INSIDE], pos + VECTOR2D( 0, -insideOffset - len ), M_PI / 2 ); } if( size[OUTSIDE] ) { - SET_DC( OUTSIDE ); + setupDC( OUTSIDE ); m_gal->SetHorizontalJustify( GR_TEXT_HJUSTIFY_RIGHT ); m_gal->SetVerticalJustify( GR_TEXT_VJUSTIFY_CENTER ); - strokeText( text[OUTSIDE], pos + VECTOR2D( 0, outsideOffset ), M_PI / 2 ); + drawText( text[OUTSIDE], pos + VECTOR2D( 0, outsideOffset ), M_PI / 2 ); } if( size[ABOVE] ) { - SET_DC( ABOVE ); + setupDC( ABOVE ); m_gal->SetHorizontalJustify( GR_TEXT_HJUSTIFY_CENTER ); m_gal->SetVerticalJustify( GR_TEXT_VJUSTIFY_BOTTOM ); - strokeText( text[ABOVE], pos + VECTOR2D( -aboveOffset, -len / 2.0 ), M_PI / 2 ); + drawText( text[ABOVE], pos + VECTOR2D( -aboveOffset, -len / 2.0 ), M_PI / 2 ); } if( size[BELOW] ) { - SET_DC( BELOW ); + setupDC( BELOW ); m_gal->SetHorizontalJustify( GR_TEXT_HJUSTIFY_CENTER ); m_gal->SetVerticalJustify( GR_TEXT_VJUSTIFY_TOP ); - strokeText( text[BELOW], pos + VECTOR2D( belowOffset, -len / 2.0 ), M_PI / 2 ); + drawText( text[BELOW], pos + VECTOR2D( belowOffset, -len / 2.0 ), M_PI / 2 ); } break; @@ -1651,7 +1700,7 @@ void SCH_PAINTER::draw( SCH_HIERLABEL *aLabel, int aLayer ) aLabel->CreateGraphicShape( &m_schSettings, pts, aLabel->GetTextPos() ); - for( auto p : pts ) + for( const wxPoint& p : pts ) pts2.emplace_back( VECTOR2D( p.x, p.y ) ); m_gal->SetIsFill( true ); @@ -1788,12 +1837,16 @@ void SCH_PAINTER::draw( const SCH_BUS_ENTRY_BASE *aEntry, int aLayer ) m_gal->SetLineWidth( drawingShadows ? getShadowWidth() : 1.0F ); if( aEntry->IsDanglingStart() ) + { m_gal->DrawCircle( aEntry->GetPosition(), aEntry->GetPenWidth() + ( TARGET_BUSENTRY_RADIUS / 2 ) ); + } if( aEntry->IsDanglingEnd() ) + { m_gal->DrawCircle( aEntry->GetEnd(), aEntry->GetPenWidth() + ( TARGET_BUSENTRY_RADIUS / 2 ) ); + } } diff --git a/eeschema/sch_painter.h b/eeschema/sch_painter.h index 5bcf980d9a..3ecf231c8e 100644 --- a/eeschema/sch_painter.h +++ b/eeschema/sch_painter.h @@ -196,7 +196,9 @@ private: void triLine ( const VECTOR2D &a, const VECTOR2D &b, const VECTOR2D &c ); void strokeText( const wxString& aText, const VECTOR2D& aPosition, double aRotationAngle ); + void boxText( const wxString& aText, const VECTOR2D& aPosition, double aAngle ); +private: SCH_RENDER_SETTINGS m_schSettings; SCHEMATIC* m_schematic;