Qt 6.x
The Qt SDK
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
qquickshapecurvenode_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 QQUICKSHAPECURVENODE_P_H
5#define QQUICKSHAPECURVENODE_P_H
6
7#include <QtQuick/qsgnode.h>
8
10
11//
12// W A R N I N G
13// -------------
14//
15// This file is not part of the Qt API. It exists for the convenience
16// of a number of Qt sources files. This header file may change from
17// version to version without notice, or even be removed.
18//
19// We mean it.
20//
21
23
25{
26public:
28
29 void setColor(QColor col)
30 {
31 m_color = col;
32 }
33
34 QColor color() const
35 {
36 return m_color;
37 }
38
40 {
41 const bool hadStroke = hasStroke();
42 m_strokeColor = col;
43 if (hadStroke != hasStroke())
44 updateMaterial();
45 }
46
48 {
49 return m_strokeColor;
50 }
51
53 {
54 const bool hadStroke = hasStroke();
55 m_strokeWidth = width;
56 if (hadStroke != hasStroke())
57 updateMaterial();
58 }
59
60 float strokeWidth() const
61 {
62 return m_strokeWidth;
63 }
64
66 {
67 m_fillGradient = fillGradient;
68 }
69
71 {
72 return m_fillGradient;
73 }
74
76 {
77 if (m_gradientType != type) {
78 m_gradientType = type;
79 updateMaterial();
80 }
81 }
82
84 {
85 return m_gradientType;
86 }
87
88 bool hasStroke() const
89 {
90 return m_strokeWidth > 0.0f && m_strokeColor.alpha() > 0;
91 }
92
94 const QVector2D &v2,
95 const QVector2D &v3,
96 std::function<QVector3D(QVector2D)> uvForPoint,
97 QVector4D debugColor1,
98 QVector4D debugColor2,
99 QVector4D debugColor3)
100 {
101 QVector3D uv1 = uvForPoint(v1);
102 QVector3D uv2 = uvForPoint(v2);
103 QVector3D uv3 = uvForPoint(v3);
104
105 QVector2D duvdx = QVector2D(uvForPoint(v1 + QVector2D(1, 0))) - QVector2D(uv1);
106 QVector2D duvdy = QVector2D(uvForPoint(v1 + QVector2D(0, 1))) - QVector2D(uv1);
107
108 m_uncookedIndexes.append(m_uncookedVertexes.size());
109 m_uncookedVertexes.append( { v1.x(), v1.y(),
110 uv1.x(), uv1.y(), uv1.z(),
111 debugColor1.x(), debugColor1.y(), debugColor1.z(), debugColor1.w(),
112 duvdx.x(), duvdx.y(),
113 duvdy.x(), duvdy.y()
114 });
115
116 m_uncookedIndexes.append(m_uncookedVertexes.size());
117 m_uncookedVertexes.append( { v2.x(), v2.y(),
118 uv2.x(), uv2.y(), uv2.z(),
119 debugColor2.x(), debugColor2.y(), debugColor2.z(), debugColor2.w(),
120 duvdx.x(), duvdx.y(),
121 duvdy.x(), duvdy.y()
122 });
123
124 m_uncookedIndexes.append(m_uncookedVertexes.size());
125 m_uncookedVertexes.append( { v3.x(), v3.y(),
126 uv3.x(), uv3.y(), uv3.z(),
127 debugColor3.x(), debugColor3.y(), debugColor3.z(), debugColor3.w(),
128 duvdx.x(), duvdx.y(),
129 duvdy.x(), duvdy.y()
130 });
131 }
132
133 void appendVertex(const QVector2D &vertex,
134 std::function<QVector3D(QVector2D)> uvForPoint,
135 const QVector4D &debugColor)
136 {
137 QVector3D uv = uvForPoint(vertex);
138
139 QVector2D duvdx = QVector2D(uvForPoint(vertex + QVector2D(1, 0))) - QVector2D(uv);
140 QVector2D duvdy = QVector2D(uvForPoint(vertex + QVector2D(0, 1))) - QVector2D(uv);
141
142 m_uncookedVertexes.append( { vertex.x(), vertex.y(),
143 uv.x(), uv.y(), uv.z(),
144 debugColor.x(), debugColor.y(), debugColor.z(), debugColor.w(),
145 duvdx.x(), duvdx.y(),
146 duvdy.x(), duvdy.y()
147 }
148 );
149 }
150
152 {
153 m_uncookedIndexes.append(index);
154 }
155
157 {
158 m_uncookedIndexes.append(indexes);
159 }
160
162 {
163 return m_uncookedIndexes;
164 }
165
166 void cookGeometry();
167
168private:
169 struct CurveNodeVertex
170 {
171 float x, y, u, v, w;
172 float r, g, b, a; // Debug color, mixed in proportion to a
173 float dudx, dvdx, dudy, dvdy; // Size of pixel in curve space (must be same for all vertices in triangle)
174 };
175
176 void updateMaterial();
177 static const QSGGeometry::AttributeSet &attributes();
178
179 QColor m_color = Qt::white;
180 QColor m_strokeColor = Qt::transparent;
181 float m_strokeWidth = 0.0f;
184
186
187 QVector<CurveNodeVertex> m_uncookedVertexes;
188 QVector<quint32> m_uncookedIndexes;
189};
190
192
193#endif // QQUICKSHAPECURVENODE_P_H
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition qcolor.h:31
int alpha() const noexcept
Returns the alpha color component of this color.
Definition qcolor.cpp:1466
Definition qlist.h:74
void setFillGradient(const QQuickAbstractPathRenderer::GradientDesc &fillGradient)
void appendVertex(const QVector2D &vertex, std::function< QVector3D(QVector2D)> uvForPoint, const QVector4D &debugColor)
QVector< quint32 > uncookedIndexes() const
void setStrokeColor(QColor col)
QQuickAbstractPathRenderer::FillGradientType gradientType() const
void appendTriangle(const QVector2D &v1, const QVector2D &v2, const QVector2D &v3, std::function< QVector3D(QVector2D)> uvForPoint, QVector4D debugColor1, QVector4D debugColor2, QVector4D debugColor3)
QQuickAbstractPathRenderer::GradientDesc fillGradient() const
void appendIndexes(QVector< quint32 > indexes)
void appendIndex(quint32 index)
void setGradientType(QQuickAbstractPathRenderer::FillGradientType type)
void setStrokeWidth(float width)
The QSGGeometryNode class is used for all rendered content in the scene graph.
Definition qsgnode.h:191
NodeType type() const
Returns the type of this node.
Definition qsgnode.h:110
\inmodule QtCore
The QVector2D class represents a vector or vertex in 2D space.
Definition qvectornd.h:31
constexpr float y() const noexcept
Returns the y coordinate of this point.
Definition qvectornd.h:502
constexpr float x() const noexcept
Returns the x coordinate of this point.
Definition qvectornd.h:501
The QVector3D class represents a vector or vertex in 3D space.
Definition qvectornd.h:171
constexpr float y() const noexcept
Returns the y coordinate of this point.
Definition qvectornd.h:671
constexpr float x() const noexcept
Returns the x coordinate of this point.
Definition qvectornd.h:670
constexpr float z() const noexcept
Returns the z coordinate of this point.
Definition qvectornd.h:672
The QVector4D class represents a vector or vertex in 4D space.
Definition qvectornd.h:330
constexpr float x() const noexcept
Returns the x coordinate of this point.
Definition qvectornd.h:878
constexpr float w() const noexcept
Returns the w coordinate of this point.
Definition qvectornd.h:881
constexpr float y() const noexcept
Returns the y coordinate of this point.
Definition qvectornd.h:879
constexpr float z() const noexcept
Returns the z coordinate of this point.
Definition qvectornd.h:880
Combined button and popup list for selecting options.
@ white
Definition qnamespace.h:30
@ transparent
Definition qnamespace.h:46
GLint GLfloat GLfloat GLfloat v2
GLboolean GLboolean GLboolean b
GLsizei const GLfloat * v
[13]
GLint GLint GLint GLint GLint x
[0]
GLfloat GLfloat GLfloat w
[0]
GLboolean GLboolean GLboolean GLboolean a
[7]
GLuint index
[2]
GLboolean r
[2]
GLint GLsizei width
GLenum type
GLint GLfloat GLfloat v1
GLboolean GLboolean g
GLint GLfloat GLfloat GLfloat GLfloat v3
GLint y
static QVector2D uvForPoint(QVector2D v1, QVector2D v2, QVector2D p)
unsigned int quint32
Definition qtypes.h:45
The QSGGeometry::AttributeSet describes how the vertices in a QSGGeometry are built up.
Definition qsggeometry.h:73