Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qsgcurvestrokenode_p.h
Go to the documentation of this file.
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// Qt-Security score:significant reason:default
4
5#ifndef QSGCURVESTROKENODE_P_H
6#define QSGCURVESTROKENODE_P_H
7
8#include <QtQuick/qtquickexports.h>
9#include <QtQuick/qsgnode.h>
10
11#include <QtQuick/private/qsggradientcache_p.h>
12
15
16//
17// W A R N I N G
18// -------------
19//
20// This file is not part of the Qt API. It exists for the convenience
21// of a number of Qt sources files. This header file may change from
22// version to version without notice, or even be removed.
23//
24// We mean it.
25//
26
28
29class Q_QUICK_EXPORT QSGCurveStrokeNode : public QSGCurveAbstractNode
30{
31public:
32 QSGCurveStrokeNode();
33
34 void setColor(QColor col) override
35 {
36 m_color = col;
37 markDirty(DirtyMaterial);
38 }
39
40 QColor color() const
41 {
42 return m_color;
43 }
44
45 void setCosmeticStroke(bool c)
46 {
47 m_cosmetic = c;
48 markDirty(DirtyMaterial);
49 }
50
51 void setStrokeWidth(float width)
52 {
53 m_strokeWidth = width;
54 markDirty(DirtyMaterial);
55 }
56
57 QGradient::Type gradientType() const
58 {
59 return m_gradientType;
60 }
61
62 void setGradientType(QGradient::Type type)
63 {
64 m_gradientType = type;
65 markDirty(DirtyMaterial);
66 }
67
68 const QSGGradientCache::GradientDesc *strokeGradient() const
69 {
70 return &m_strokeGradient;
71 }
72
73 void setStrokeGradient(const QSGGradientCache::GradientDesc &strokeGradient)
74 {
75 m_strokeGradient = strokeGradient;
76 markDirty(DirtyMaterial);
77 }
78
79 float strokeWidth() const
80 {
81 // Negative stroke width would not normally mean anything;
82 // here we use it to mean that the stroke is cosmetic.
83 return (m_cosmetic ? -1.0 : 1.0) * qAbs(m_strokeWidth);
84 }
85
86 enum class TriangleFlag {
87 None = 0,
88 Line = 1 << 0,
89 };
90 Q_DECLARE_FLAGS(TriangleFlags, TriangleFlag)
91
92 static constexpr std::array<float, 3> defaultExtrusions() { return {1.0f, 1.0f, 1.0f}; }
93
94 void appendTriangle(const std::array<QVector2D, 3> &vtx, // triangle vertices
95 const std::array<QVector2D, 3> &ctl, // curve points
96 const std::array<QVector2D, 3> &normal, // vertex normals
97 const std::array<float, 3> &extrusions = defaultExtrusions());
98 void appendTriangle(const std::array<QVector2D, 3> &vtx, // triangle vertices
99 const std::array<QVector2D, 2> &ctl, // line points
100 const std::array<QVector2D, 3> &normal, // vertex normals
101 const std::array<float, 3> &extrusions = defaultExtrusions());
102
103 void cookGeometry() override;
104
105 static const QSGGeometry::AttributeSet &attributes();
106
107 static bool expandingStrokeEnabled();
108
109 QList<quint32> uncookedIndexes() const
110 {
111 return m_uncookedIndexes;
112 }
113
114 float debug() const
115 {
116 return m_debug;
117 }
118
119 void setDebug(float newDebug)
120 {
121 m_debug = newDebug;
122 }
123
124 void setLocalScale(float scale)
125 {
126 m_localScale = scale;
127 }
128
129 float localScale() const
130 {
131 return m_localScale;
132 }
133
134 bool useStandardDerivatives() const
135 {
136 return m_useStandardDerivatives;
137 }
138
139 void setUseStandardDerivatives(bool useStandardDerivatives) override
140 {
141 m_useStandardDerivatives = useStandardDerivatives;
142 }
143
144private:
145
146 struct StrokeVertex
147 {
148 float x, y;
149 float ax, ay;
150 float bx, by;
151 float cx, cy;
152 float nx, ny; // normal vector: direction to move vertex to account for AA
153 float extrusion; // stroke width multiplier (* uniform strokeWidth)
154 };
155
156 void updateMaterial();
157
158 static std::array<QVector2D, 3> curveABC(const std::array<QVector2D, 3> &p);
159
160 static const bool envStrokeExpanding;
161 QColor m_color;
162 ushort m_cosmetic = false; // packs alongside QColor; could be turned into flags if needed
163 float m_strokeWidth = 0.0f;
164 float m_debug = 0.0f;
165 float m_localScale = 1.0f;
166 bool m_useStandardDerivatives = false;
167 QSGGradientCache::GradientDesc m_strokeGradient;
168 QGradient::Type m_gradientType = QGradient::NoGradient;
169
170protected:
171 QScopedPointer<QSGCurveStrokeMaterial> m_material;
172
173 QList<StrokeVertex> m_uncookedVertexes;
174 QList<quint32> m_uncookedIndexes;
175};
176
177Q_DECLARE_OPERATORS_FOR_FLAGS(QSGCurveStrokeNode::TriangleFlags)
178
179QT_END_NAMESPACE
180
181#endif // QSGCURVESTROKENODE_P_H
Combined button and popup list for selecting options.