6#include "QskStippledLineRenderer.h"
7#include "QskInternalMacros.h"
10#include <private/qstroker_p.h>
21 class DashStroker :
public QDashStroker
25 : QDashStroker( nullptr )
26 , m_renderer( renderer )
28 setDashOffset( renderer->metrics().offset() );
29 setDashPattern( renderer->metrics().pattern() );
31 m_elements.reserve( 2 );
34 void renderDashes( qreal x1, qreal y1, qreal x2, qreal y2 )
36 if ( ( x1 == x2 ) && ( y1 == y2 ) )
39 setMoveToHook( moveTo );
40 setLineToHook( lineTo );
44 m_elements.add( { QPainterPath::MoveToElement, x1, y1 } );
45 m_elements.add( { QPainterPath::LineToElement, x2, y2 } );
47 processCurrentSubpath();
52 qsizetype dashCount( qreal x1, qreal y1, qreal x2, qreal y2 )
54 if ( ( x1 == x2 ) && ( y1 == y2 ) )
61 setMoveToHook( countMoveTo );
62 setLineToHook( countLineTo );
68 m_elements.add( { QPainterPath::MoveToElement, x1, y1 } );
69 m_elements.add( { QPainterPath::LineToElement, x2, y2 } );
71 processCurrentSubpath();
79 static void moveTo( qfixed x, qfixed y,
void* data )
81 auto stroker =
reinterpret_cast< DashStroker*
>( data );
87 static void lineTo( qfixed x, qfixed y,
void* data )
89 auto stroker =
reinterpret_cast< DashStroker*
>( data );
90 stroker->m_renderer->renderDash( stroker->m_x, stroker->m_y, x, y );
93 static void countMoveTo( qfixed, qfixed,
void* )
97 static void countLineTo( qfixed, qfixed,
void* data )
99 auto stroker =
reinterpret_cast< DashStroker*
>( data );
105 qsizetype m_count = 0;
110QskStippledLineRenderer::QskStippledLineRenderer(
const QskStippleMetrics& metrics )
111 : m_metrics( metrics )
115QskStippledLineRenderer::~QskStippledLineRenderer()
119qsizetype QskStippledLineRenderer::dashCount(
120 const QPointF& p1,
const QPointF& p2 )
const
122 return dashCount( p1.x(), p1.y(), p2.x(), p2.y() );
125qsizetype QskStippledLineRenderer::dashCount(
const QLineF& line )
const
127 return dashCount( line.x1(), line.y1(), line.x2(), line.y2() );
130qsizetype QskStippledLineRenderer::dashCount(
131 qreal x1, qreal y1, qreal x2, qreal y2 )
const
134 return DashStroker( that ).dashCount( x1, y1, x2, y2 );
137void QskStippledLineRenderer::renderLine(
const QPointF& p1,
const QPointF& p2 )
139 renderLine( p1.x(), p1.y(), p2.x(), p2.y() );
142void QskStippledLineRenderer::renderLine(
const QLineF& line )
144 renderLine( line.x1(), line.y1(), line.x2(), line.y2() );
147void QskStippledLineRenderer::renderLine( qreal x1, qreal y1, qreal x2, qreal y2 )
149 DashStroker(
this ).renderDashes( x1, y1, x2, y2 );
152void QskStippledLineRenderer::renderDash( qreal, qreal, qreal, qreal )