6#include "QskShapeNode.h"
7#include "QskGradient.h"
8#include "QskGradientDirection.h"
10#include "QskFillNodePrivate.h"
13#include <private/qvectorpath_p.h>
14#include <private/qtriangulator_p.h>
20static void qskUpdateGeometry(
const QPainterPath& path,
21 const QTransform& transform,
const QColor&, QSGGeometry& geometry )
23 const auto ts = qTriangulate( path, transform, 1,
false );
25 geometry.allocate( ts.vertices.size(), ts.indices.size() );
27 auto vertexData =
reinterpret_cast< float*
>( geometry.vertexData() );
28 const auto points = ts.vertices.constData();
30 for (
int i = 0; i < ts.vertices.count(); i++ )
31 vertexData[i] = points[i];
33 memcpy( geometry.indexData(), ts.indices.data(),
34 ts.indices.size() *
sizeof( quint16 ) );
39static void qskUpdateGeometry(
const QPainterPath& path,
40 const QTransform& transform,
const QColor& color, QSGGeometry& geometry )
42 const auto ts = qTriangulate( path, transform, 1,
false );
59 const auto points = ts.vertices.constData();
60 const auto indices =
reinterpret_cast< const quint16*
>( ts.indices.data() );
62 geometry.allocate( ts.indices.size() );
64 if ( color.isValid() )
68 auto vertexData = geometry.vertexDataAsColoredPoint2D();
69 for (
int i = 0; i < ts.indices.size(); i++ )
71 const int j = 2 * indices[i];
72 vertexData[i].set( points[j], points[j + 1], c.r, c.g, c.b, c.a );
77 auto vertexData = geometry.vertexDataAsPoint2D();
78 for (
int i = 0; i < ts.indices.size(); i++ )
80 const int j = 2 * indices[i];
81 vertexData[i].set( points[j], points[j + 1] );
88class QskShapeNodePrivate final :
public QskFillNodePrivate
99QskShapeNode::QskShapeNode()
108 setColoring( Monochrome );
111 geometry()->setDrawingMode( QSGGeometry::DrawTriangles );
114QskShapeNode::~QskShapeNode()
118void QskShapeNode::updatePath(
const QPainterPath& path,
119 const QTransform& transform,
const QRectF& rect,
const QskGradient& gradient )
123 if ( path.isEmpty() || !gradient.isVisible() )
125 d->path = QPainterPath();
126 d->transform = QTransform();
134 if ( gradient.isMonochrome() && hasHint( PreferColoredGeometry ) )
135 c = gradient.startColor();
137 const bool isDirty = ( isGeometryColored() != c.isValid() );
140 setColoring( QskFillNode::Polychrome );
142 setColoring( rect, gradient );
144 if ( isDirty || ( transform != d->transform ) || ( path != d->path ) )
147 d->transform = transform;
149 qskUpdateGeometry( path, transform, c, *geometry() );
151 geometry()->markVertexDataDirty();
152 markDirty( QSGNode::DirtyGeometry );