diff --git a/common/view/view_overlay.cpp b/common/view/view_overlay.cpp index 4992288671..c372e49c6b 100644 --- a/common/view/view_overlay.cpp +++ b/common/view/view_overlay.cpp @@ -57,6 +57,22 @@ struct VIEW_OVERLAY::COMMAND_LINE : public VIEW_OVERLAY::COMMAND }; +struct VIEW_OVERLAY::COMMAND_RECTANGLE : public VIEW_OVERLAY::COMMAND +{ + COMMAND_RECTANGLE( const VECTOR2D& aP0, const VECTOR2D& aP1 ) : + m_p0( aP0 ), m_p1( aP1 ) + {} + + virtual void Execute( VIEW* aView ) const override + { + aView->GetGAL()->DrawRectangle( m_p0, m_p1 ); + } + + VECTOR2D m_p0; + VECTOR2D m_p1; +}; + + struct VIEW_OVERLAY::COMMAND_CIRCLE : public VIEW_OVERLAY::COMMAND { COMMAND_CIRCLE( const VECTOR2D& aCenter, double aRadius ) : @@ -94,6 +110,100 @@ struct VIEW_OVERLAY::COMMAND_ARC : public VIEW_OVERLAY::COMMAND }; +struct VIEW_OVERLAY::COMMAND_POLYLINE : public VIEW_OVERLAY::COMMAND +{ + COMMAND_POLYLINE( const std::deque& aPointList ) : + m_pointList( aPointList ) {} + + virtual void Execute( VIEW* aView ) const override + { + aView->GetGAL()->DrawPolyline( m_pointList ); + } + + std::deque m_pointList; +}; + + +struct VIEW_OVERLAY::COMMAND_POLY_POLYLINE : public VIEW_OVERLAY::COMMAND +{ + COMMAND_POLY_POLYLINE( const SHAPE_LINE_CHAIN& aLineChain ) : + m_polyLine( aLineChain ) {} + + virtual void Execute( VIEW* aView ) const override + { + aView->GetGAL()->DrawPolyline( m_polyLine ); + } + + SHAPE_LINE_CHAIN m_polyLine; +}; + + +struct VIEW_OVERLAY::COMMAND_POINT_POLYLINE : public VIEW_OVERLAY::COMMAND +{ + COMMAND_POINT_POLYLINE( const VECTOR2D aPointList[], int aListSize ) + { + m_pointList.reserve( aListSize ); + + for( int ii = 0; ii < aListSize; ii++ ) + m_pointList.push_back( aPointList[ii] ); + } + + virtual void Execute( VIEW* aView ) const override + { + aView->GetGAL()->DrawPolyline( &m_pointList[0], (int)m_pointList.size() ); + } + + std::vector m_pointList; +}; + + +struct VIEW_OVERLAY::COMMAND_POLYGON : public VIEW_OVERLAY::COMMAND +{ + COMMAND_POLYGON( const std::deque& aPointList ) : + m_pointList( aPointList ) {} + + virtual void Execute( VIEW* aView ) const override + { + aView->GetGAL()->DrawPolygon( m_pointList ); + } + + std::deque m_pointList; +}; + + +struct VIEW_OVERLAY::COMMAND_POLY_POLYGON : public VIEW_OVERLAY::COMMAND +{ + COMMAND_POLY_POLYGON( const SHAPE_POLY_SET& aPolySet ) : + m_polySet( aPolySet ) {} + + virtual void Execute( VIEW* aView ) const override + { + aView->GetGAL()->DrawPolygon( m_polySet ); + } + + SHAPE_POLY_SET m_polySet; +}; + + +struct VIEW_OVERLAY::COMMAND_POINT_POLYGON : public VIEW_OVERLAY::COMMAND +{ + COMMAND_POINT_POLYGON( const VECTOR2D aPointList[], int aListSize ) + { + m_pointList.reserve( aListSize ); + + for( int ii = 0; ii < aListSize; ii++ ) + m_pointList.push_back( aPointList[ii] ); + } + + virtual void Execute( VIEW* aView ) const override + { + aView->GetGAL()->DrawPolygon( &m_pointList[0], (int)m_pointList.size() ); + } + + std::vector m_pointList; +}; + + struct VIEW_OVERLAY::COMMAND_SET_STROKE : public VIEW_OVERLAY::COMMAND { COMMAND_SET_STROKE( bool aIsStroke ) : @@ -218,6 +328,8 @@ void VIEW_OVERLAY::Line( const SEG& aSeg ) void VIEW_OVERLAY::Segment( const VECTOR2D& aStartPoint, const VECTOR2D& aEndPoint, double aWidth ) { + SetLineWidth( aWidth ); + Line( aStartPoint, aEndPoint ); } @@ -226,6 +338,34 @@ void VIEW_OVERLAY::Polyline( std::deque& aPointList ) } +void VIEW_OVERLAY::Polyline( const VECTOR2D aPointList[], int aListSize ) +{ +} + + +void VIEW_OVERLAY::Polyline( const SHAPE_LINE_CHAIN& aLineChain ) +{ +} + + +void VIEW_OVERLAY::Polygon( const SHAPE_POLY_SET& aPolySet ) +{ + m_commands.push_back( new COMMAND_POLY_POLYGON( aPolySet ) ); +} + + +void VIEW_OVERLAY::Polygon( const std::deque& aPointList ) +{ + m_commands.push_back( new COMMAND_POLYGON( aPointList ) ); +} + + +void VIEW_OVERLAY::Polygon( const VECTOR2D aPointList[], int aListSize ) +{ + m_commands.push_back( new COMMAND_POINT_POLYGON( aPointList, aListSize ) ); +} + + void VIEW_OVERLAY::Circle( const VECTOR2D& aCenterPoint, double aRadius ) { m_commands.push_back( new COMMAND_CIRCLE( aCenterPoint, aRadius ) ); @@ -233,9 +373,7 @@ void VIEW_OVERLAY::Circle( const VECTOR2D& aCenterPoint, double aRadius ) void VIEW_OVERLAY::Arc( const VECTOR2D& aCenterPoint, - double aRadius, - double aStartAngle, - double aEndAngle ) + double aRadius, double aStartAngle, double aEndAngle ) { m_commands.push_back( new COMMAND_ARC( aCenterPoint, aRadius, aStartAngle, aEndAngle ) ); } @@ -243,11 +381,7 @@ void VIEW_OVERLAY::Arc( const VECTOR2D& aCenterPoint, void VIEW_OVERLAY::Rectangle( const VECTOR2D& aStartPoint, const VECTOR2D& aEndPoint ) { -} - - -void VIEW_OVERLAY::Polygon( const std::deque& aPointList ) -{ + m_commands.push_back( new COMMAND_RECTANGLE( aStartPoint, aEndPoint ) ); } diff --git a/include/view/view_overlay.h b/include/view/view_overlay.h index 7501041f9f..753e0c3178 100644 --- a/include/view/view_overlay.h +++ b/include/view/view_overlay.h @@ -32,6 +32,8 @@ #include #include +#include + class SEG; namespace KIGFX @@ -49,25 +51,46 @@ public: struct COMMAND_ARC; struct COMMAND_LINE; struct COMMAND_CIRCLE; + struct COMMAND_RECTANGLE; + struct COMMAND_SET_STROKE; struct COMMAND_SET_FILL; struct COMMAND_SET_COLOR; struct COMMAND_SET_WIDTH; + struct COMMAND_POLYGON; + struct COMMAND_POINT_POLYGON; + struct COMMAND_POLY_POLYGON; + + struct COMMAND_POLYLINE; + struct COMMAND_POINT_POLYLINE; + struct COMMAND_POLY_POLYLINE; + void Clear(); virtual const BOX2I ViewBBox() const override; virtual void ViewDraw( int aLayer, VIEW *aView ) const override; virtual void ViewGetLayers( int aLayers[], int& aCount ) const override; + // Basic shape primitives void Line( const VECTOR2D& aStartPoint, const VECTOR2D& aEndPoint ); void Line( const SEG& aSeg ); void Segment( const VECTOR2D& aStartPoint, const VECTOR2D& aEndPoint, double aWidth ); - void Polyline( std::deque& aPointList ); void Circle( const VECTOR2D& aCenterPoint, double aRadius ); void Arc( const VECTOR2D& aCenterPoint, double aRadius, double aStartAngle, double aEndAngle ); void Rectangle( const VECTOR2D& aStartPoint, const VECTOR2D& aEndPoint ); + + // Polyline primitives + void Polyline( std::deque& aPointList ); + void Polyline( const VECTOR2D aPointList[], int aListSize ); + void Polyline( const SHAPE_LINE_CHAIN& aLineChain ); + + // polygon primitives void Polygon( const std::deque& aPointList ); + void Polygon( const SHAPE_POLY_SET& aPolySet ); + void Polygon( const VECTOR2D aPointList[], int aListSize ); + + // Draw settings void SetIsFill( bool aIsFillEnabled ); void SetIsStroke( bool aIsStrokeEnabled ); void SetFillColor( const COLOR4D& aColor );