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 QVector<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
109private:
110
111 struct StrokeVertex
112 {
113 float x, y;
114 float ax, ay;
115 float bx, by;
116 float cx, cy;
117 float nx, ny; // normal vector: direction to move vertex to account for AA
118 float extrusion; // stroke width multiplier (* uniform strokeWidth)
119 };
120
121 void updateMaterial();
122
123 static std::array<QVector2D, 3> curveABC(const std::array<QVector2D, 3> &p);
124
125 static const bool envStrokeExpanding;
126 QColor m_color;
127 ushort m_cosmetic = false; // packs alongside QColor; could be turned into flags if needed
128 float m_strokeWidth = 0.0f;
129 float m_debug = 0.0f;
130 float m_localScale = 1.0f;
131
132protected:
133 QScopedPointer<QSGCurveStrokeMaterial> m_material;
134
135 QVector<StrokeVertex> m_uncookedVertexes;
136 QVector<quint32> m_uncookedIndexes;
137};
138
139Q_DECLARE_OPERATORS_FOR_FLAGS(QSGCurveStrokeNode::TriangleFlags)
140
141QT_END_NAMESPACE
142
143#endif // QSGCURVESTROKENODE_P_H