6#include "QskStrokeNode.h"
8#include "QskGradient.h"
9#include "QskRgbValue.h"
11#include <qpainterpath.h>
14#include <private/qtriangulatingstroker_p.h>
17static inline bool qskIsPenVisible(
const QPen& pen )
19 if ( pen.style() == Qt::NoPen )
22 if ( pen.brush().gradient() )
28 if ( !QskRgb::isVisible( pen.color() ) )
35QskStrokeNode::QskStrokeNode()
39QskStrokeNode::~QskStrokeNode() =
default;
41void QskStrokeNode::updatePath(
const QPainterPath& path,
const QPen& pen )
43 updatePath( path, QTransform(), pen );
46void QskStrokeNode::updatePath(
47 const QPainterPath& path,
const QTransform& transform,
const QPen& pen )
49 if ( path.isEmpty() || !qskIsPenVisible( pen ) )
55 if (
auto qGradient = pen.brush().gradient() )
57 const auto r = transform.mapRect( path.boundingRect() );
60 gradient.setStretchMode( QskGradient::StretchToSize );
62 setColoring( r, gradient );
65 setColoring( pen.color() );
73 const auto scaledPath = transform.map( path );
75 auto effectivePen = pen;
77 if ( !effectivePen.isCosmetic() )
79 const auto scaleFactor = qMin( transform.m11(), transform.m22() );
80 if ( scaleFactor != 1.0 )
82 effectivePen.setWidth( effectivePen.widthF() * scaleFactor );
83 effectivePen.setCosmetic(
false );
87 QTriangulatingStroker stroker;
89 if ( pen.style() == Qt::SolidLine )
92 stroker.process( qtVectorPathForPath( scaledPath ), effectivePen, {}, {} );
96 constexpr QRectF clipRect;
98 QDashedStrokeProcessor dashStroker;
99 dashStroker.process( qtVectorPathForPath( scaledPath ),
100 effectivePen, clipRect, {} );
102 const QVectorPath dashedVectorPath( dashStroker.points(),
103 dashStroker.elementCount(), dashStroker.elementTypes(), 0 );
105 stroker.process( dashedVectorPath, effectivePen, {}, {} );
108 auto& geometry = *this->geometry();
111 geometry.setDrawingMode( QSGGeometry::DrawTriangleStrip );
112 geometry.allocate( stroker.vertexCount() / 2 );
114 if ( isGeometryColored() )
118 const auto v = stroker.vertices();
119 auto points = geometry.vertexDataAsColoredPoint2D();
121 for (
int i = 0; i < geometry.vertexCount(); i++ )
123 const auto j = 2 * i;
124 points[i].set( v[j], v[j + 1], c.r, c.g, c.b, c.a );
129 memcpy( geometry.vertexData(), stroker.vertices(),
130 stroker.vertexCount() *
sizeof(
float ) );
133 geometry.markVertexDataDirty();
134 markDirty( QSGNode::DirtyGeometry );