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
4#ifndef QSGCURVESTROKENODE_P_H
5#define QSGCURVESTROKENODE_P_H
6
7#include <QtQuick/qtquickexports.h>
8#include <QtQuick/qsgnode.h>
9
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
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(DirtyMaterial);
35 }
36
37 QColor color() const
38 {
39 return m_color;
40 }
41
42 void setCosmeticStroke(bool c)
43 {
44 m_cosmetic = c;
45 markDirty(DirtyMaterial);
46 }
47
48 void setStrokeWidth(float width)
49 {
50 m_strokeWidth = width;
51 markDirty(DirtyMaterial);
52 }
53
54 float strokeWidth() const
55 {
56 // Negative stroke width would not normally mean anything;
57 // here we use it to mean that the stroke is cosmetic.
58 return (m_cosmetic ? -1.0 : 1.0) * qAbs(m_strokeWidth);
59 }
60
61 enum class TriangleFlag {
62 None = 0,
63 Line = 1 << 0,
64 };
65 Q_DECLARE_FLAGS(TriangleFlags, TriangleFlag)
66
67 static constexpr std::array<float, 3> defaultExtrusions() { return {1.0f, 1.0f, 1.0f}; }
68
69 void appendTriangle(const std::array<QVector2D, 3> &vtx, // triangle vertices
70 const std::array<QVector2D, 3> &ctl, // curve points
71 const std::array<QVector2D, 3> &normal, // vertex normals
72 const std::array<float, 3> &extrusions = defaultExtrusions());
73 void appendTriangle(const std::array<QVector2D, 3> &vtx, // triangle vertices
74 const std::array<QVector2D, 2> &ctl, // line points
75 const std::array<QVector2D, 3> &normal, // vertex normals
76 const std::array<float, 3> &extrusions = defaultExtrusions());
77
78 void cookGeometry() override;
79
80 static const QSGGeometry::AttributeSet &attributes();
81
82 static bool expandingStrokeEnabled();
83
84 QList<quint32> uncookedIndexes() const
85 {
86 return m_uncookedIndexes;
87 }
88
89 float debug() const
90 {
91 return m_debug;
92 }
93
94 void setDebug(float newDebug)
95 {
96 m_debug = newDebug;
97 }
98
99 void setLocalScale(float scale)
100 {
101 m_localScale = scale;
102 }
103
104 float localScale() const
105 {
106 return m_localScale;
107 }
108
109 bool useStandardDerivatives() const
110 {
111 return m_useStandardDerivatives;
112 }
113
114 void setUseStandardDerivatives(bool useStandardDerivatives) override
115 {
116 m_useStandardDerivatives = useStandardDerivatives;
117 }
118
119private:
120
121 struct StrokeVertex
122 {
123 float x, y;
124 float ax, ay;
125 float bx, by;
126 float cx, cy;
127 float nx, ny; // normal vector: direction to move vertex to account for AA
128 float extrusion; // stroke width multiplier (* uniform strokeWidth)
129 };
130
131 void updateMaterial();
132
133 static std::array<QVector2D, 3> curveABC(const std::array<QVector2D, 3> &p);
134
135 static const bool envStrokeExpanding;
136 QColor m_color;
137 ushort m_cosmetic = false; // packs alongside QColor; could be turned into flags if needed
138 float m_strokeWidth = 0.0f;
139 float m_debug = 0.0f;
140 float m_localScale = 1.0f;
141 bool m_useStandardDerivatives = false;
142
143protected:
144 QScopedPointer<QSGCurveStrokeMaterial> m_material;
145
146 QList<StrokeVertex> m_uncookedVertexes;
147 QList<quint32> m_uncookedIndexes;
148};
149
150Q_DECLARE_OPERATORS_FOR_FLAGS(QSGCurveStrokeNode::TriangleFlags)
151
152QT_END_NAMESPACE
153
154#endif // QSGCURVESTROKENODE_P_H
Combined button and popup list for selecting options.