6#include "QskStippledLineRenderer.h"
9#include <private/qstroker_p.h>
20 class DashStroker :
public QDashStroker
24 : QDashStroker( nullptr )
25 , m_renderer( renderer )
27 setDashOffset( renderer->metrics().offset() );
28 setDashPattern( renderer->metrics().pattern() );
30 m_elements.reserve( 2 );
33 void renderDashes( qreal x1, qreal y1, qreal x2, qreal y2 )
35 if ( ( x1 == x2 ) && ( y1 == y2 ) )
38 setMoveToHook( moveTo );
39 setLineToHook( lineTo );
43 m_elements.add( { QPainterPath::MoveToElement, x1, y1 } );
44 m_elements.add( { QPainterPath::LineToElement, x2, y2 } );
46 processCurrentSubpath();
51 qsizetype dashCount( qreal x1, qreal y1, qreal x2, qreal y2 )
53 if ( ( x1 == x2 ) && ( y1 == y2 ) )
60 setMoveToHook( countMoveTo );
61 setLineToHook( countLineTo );
67 m_elements.add( { QPainterPath::MoveToElement, x1, y1 } );
68 m_elements.add( { QPainterPath::LineToElement, x2, y2 } );
70 processCurrentSubpath();
78 static void moveTo( qfixed x, qfixed y,
void* data )
80 auto stroker =
reinterpret_cast< DashStroker*
>( data );
86 static void lineTo( qfixed x, qfixed y,
void* data )
88 auto stroker =
reinterpret_cast< DashStroker*
>( data );
89 stroker->m_renderer->renderDash( stroker->m_x, stroker->m_y, x, y );
92 static void countMoveTo( qfixed, qfixed,
void* )
96 static void countLineTo( qfixed, qfixed,
void* data )
98 auto stroker =
reinterpret_cast< DashStroker*
>( data );
104 qsizetype m_count = 0;
109QskStippledLineRenderer::QskStippledLineRenderer(
const QskStippleMetrics& metrics )
110 : m_metrics( metrics )
114QskStippledLineRenderer::~QskStippledLineRenderer()
118qsizetype QskStippledLineRenderer::dashCount(
119 const QPointF& p1,
const QPointF& p2 )
const
121 return dashCount( p1.x(), p1.y(), p2.x(), p2.y() );
124qsizetype QskStippledLineRenderer::dashCount(
const QLineF& line )
const
126 return dashCount( line.x1(), line.y1(), line.x2(), line.y2() );
129qsizetype QskStippledLineRenderer::dashCount(
130 qreal x1, qreal y1, qreal x2, qreal y2 )
const
133 return DashStroker( that ).dashCount( x1, y1, x2, y2 );
136void QskStippledLineRenderer::renderLine(
const QPointF& p1,
const QPointF& p2 )
138 renderLine( p1.x(), p1.y(), p2.x(), p2.y() );
141void QskStippledLineRenderer::renderLine(
const QLineF& line )
143 renderLine( line.x1(), line.y1(), line.x2(), line.y2() );
146void QskStippledLineRenderer::renderLine( qreal x1, qreal y1, qreal x2, qreal y2 )
148 DashStroker(
this ).renderDashes( x1, y1, x2, y2 );
151void QskStippledLineRenderer::renderDash( qreal, qreal, qreal, qreal )