1// Copyright (C) 2023 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 QSGCURVESTROKENODE_P_H
5#define QSGCURVESTROKENODE_P_H
6
7#include <QtQuick/qtquickexports.h>
8#include <QtQuick/qsgnode.h>
9
10#include "qsgcurveabstractnode_p.h"
11#include "qsgcurvestrokenode_p_p.h"
12
13//
14// W A R N I N G
15// -------------
16//
17// This file is not part of the Qt API. It exists for the convenience
18// of a number of Qt sources files. This header file may change from
19// version to version without notice, or even be removed.
20//
21// We mean it.
22//
23
24QT_BEGIN_NAMESPACE
25
26class Q_QUICK_EXPORT QSGCurveStrokeNode : public QSGCurveAbstractNode
27{
28public:
29 QSGCurveStrokeNode();
30
31 void setColor(QColor col) override
32 {
33 m_color = col;
34 markDirty(bits: DirtyMaterial);
35 }
36
37 QColor color() const
38 {
39 return m_color;
40 }
41
42 void setStrokeWidth(float width)
43 {
44 m_strokeWidth = width;
45 markDirty(bits: DirtyMaterial);
46 }
47
48 float strokeWidth() const
49 {
50 return m_strokeWidth;
51 }
52
53 enum class TriangleFlag {
54 Line = 1 << 0,
55 };
56 Q_DECLARE_FLAGS(TriangleFlags, TriangleFlag)
57
58 void appendTriangle(const std::array<QVector2D, 3> &v, // triangle vertices
59 const std::array<QVector2D, 3> &p, // curve points
60 const std::array<QVector2D, 3> &n); // vertex normals
61 void appendTriangle(const std::array<QVector2D, 3> &v, // triangle vertices
62 const std::array<QVector2D, 2> &p, // line points
63 const std::array<QVector2D, 3> &n, // vertex normals
64 QSGCurveStrokeNode::TriangleFlags = {});
65
66 void cookGeometry() override;
67
68 static const QSGGeometry::AttributeSet &attributes();
69
70 QVector<quint32> uncookedIndexes() const
71 {
72 return m_uncookedIndexes;
73 }
74
75 float debug() const
76 {
77 return m_debug;
78 }
79
80 void setDebug(float newDebug)
81 {
82 m_debug = newDebug;
83 }
84
85 void setLocalScale(float scale)
86 {
87 m_localScale = scale;
88 }
89
90 float localScale() const
91 {
92 return m_localScale;
93 }
94
95private:
96
97 struct StrokeVertex
98 {
99 float x, y;
100 float ax, ay;
101 float bx, by;
102 float cx, cy;
103 float nx, ny; //normal vector: direction to move vertext to account for AA
104 };
105
106 void updateMaterial();
107
108 static std::array<QVector2D, 3> curveABC(const std::array<QVector2D, 3> &p);
109
110 QColor m_color;
111 float m_strokeWidth = 0.0f;
112 float m_debug = 0.0f;
113 float m_localScale = 1.0f;
114
115protected:
116 QScopedPointer<QSGCurveStrokeMaterial> m_material;
117
118 QVector<StrokeVertex> m_uncookedVertexes;
119 QVector<quint32> m_uncookedIndexes;
120};
121
122Q_DECLARE_OPERATORS_FOR_FLAGS(QSGCurveStrokeNode::TriangleFlags)
123
124QT_END_NAMESPACE
125
126#endif // QSGCURVESTROKENODE_P_H
127

source code of qtdeclarative/src/quick/scenegraph/qsgcurvestrokenode_p.h