1// Copyright (C) 2022 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QQUICKSHAPECURVERENDERER_P_H
5#define QQUICKSHAPECURVERENDERER_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists for the convenience
12// of a number of Qt sources files. This header file may change from
13// version to version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtQuickShapes/private/qquickshapesglobal_p.h>
19#include <QtQuickShapes/private/qquickshape_p_p.h>
20#include <QtQuickShapes/private/qquadpath_p.h>
21#include <qsgnode.h>
22#include <qsggeometry.h>
23#include <qsgmaterial.h>
24#include <qsgrendererinterface.h>
25#include <qsgtexture.h>
26#include <QtCore/qrunnable.h>
27
28#include <QtGui/private/qtriangulator_p.h>
29
30QT_BEGIN_NAMESPACE
31
32class QQuickShapeCurveRenderer : public QQuickAbstractPathRenderer
33{
34public:
35 QQuickShapeCurveRenderer(QQuickItem *)
36 : m_rootNode(nullptr)
37 { }
38 ~QQuickShapeCurveRenderer() override;
39
40 void beginSync(int totalCount, bool *countChanged) override;
41 void setPath(int index, const QQuickPath *path) override;
42 void setStrokeColor(int index, const QColor &color) override;
43 void setStrokeWidth(int index, qreal w) override;
44 void setFillColor(int index, const QColor &color) override;
45 void setFillRule(int index, QQuickShapePath::FillRule fillRule) override;
46 void setJoinStyle(int index, QQuickShapePath::JoinStyle joinStyle, int miterLimit) override;
47 void setCapStyle(int index, QQuickShapePath::CapStyle capStyle) override;
48 void setStrokeStyle(int index, QQuickShapePath::StrokeStyle strokeStyle,
49 qreal dashOffset, const QVector<qreal> &dashPattern) override;
50 void setFillGradient(int index, QQuickShapeGradient *gradient) override;
51 void endSync(bool async) override;
52 void setAsyncCallback(void (*)(void *), void *) override;
53 Flags flags() const override { return Flags{}; }
54
55 void updateNode() override;
56
57 void setRootNode(QSGNode *node);
58
59 using NodeList = QVector<QSGGeometryNode *>;
60
61 enum DirtyFlag
62 {
63 PathDirty = 0x01,
64 FillDirty = 0x02,
65 StrokeDirty = 0x04,
66 UniformsDirty = 0x08
67 };
68
69 enum DebugVisualizationOption {
70 NoDebug = 0,
71 DebugCurves = 0x01,
72 DebugWireframe = 0x02
73 };
74
75 Q_QUICKSHAPES_PRIVATE_EXPORT static int debugVisualization();
76 Q_QUICKSHAPES_PRIVATE_EXPORT static void setDebugVisualization(int options);
77
78private:
79 struct PathData {
80
81 bool isFillVisible() const { return fillColor.alpha() > 0 || gradientType != NoGradient; }
82
83 bool isStrokeVisible() const
84 {
85 return validPenWidth && pen.color().alpha() > 0 && pen.style() != Qt::NoPen;
86 }
87
88 FillGradientType gradientType = NoGradient;
89 GradientDesc gradient;
90 QPainterPath originalPath;
91 QQuadPath path;
92 QQuadPath fillPath;
93 QQuadPath strokePath;
94 QColor fillColor;
95 Qt::FillRule fillRule = Qt::OddEvenFill;
96 QPen pen;
97 int m_dirty = 0;
98 bool validPenWidth = true;
99 bool convexConcaveResolved = false;
100
101 NodeList fillNodes;
102 NodeList fillDebugNodes;
103 NodeList strokeNodes;
104 NodeList strokeDebugNodes;
105 };
106
107 void deleteAndClear(NodeList *nodeList);
108
109 QVector<QSGGeometryNode *> addFillNodes(const PathData &pathData, NodeList *debugNodes);
110 QVector<QSGGeometryNode *> addTriangulatingStrokerNodes(const PathData &pathData, NodeList *debugNodes);
111 QVector<QSGGeometryNode *> addCurveStrokeNodes(const PathData &pathData, NodeList *debugNodes);
112
113 void solveOverlaps(QQuadPath &path);
114
115 QSGNode *m_rootNode;
116 QVector<PathData> m_paths;
117 static int debugVisualizationFlags;
118};
119
120QT_END_NAMESPACE
121
122#endif // QQUICKSHAPECURVERENDERER_P_H
123

source code of qtdeclarative/src/quickshapes/qquickshapecurverenderer_p.h