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