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
10#include "qsgcurveabstractnode_p.h"
11#include "qsgcurvestrokenode_p_p.h"
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
24QT_BEGIN_NAMESPACE
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(bits: DirtyMaterial);
35 }
36
37 QColor color() const
38 {
39 return m_color;
40 }
41
42 void setStrokeWidth(float width)
43 {
44 m_strokeWidth = width;
45 markDirty(bits: DirtyMaterial);
46 }
47
48 float strokeWidth() const
49 {
50 return m_strokeWidth;
51 }
52
53 void appendTriangle(const std::array<QVector2D, 3> &v, // triangle vertices
54 const std::array<QVector2D, 3> &p, // curve points
55 const std::array<QVector2D, 3> &n); // vertex normals
56 void appendTriangle(const std::array<QVector2D, 3> &v, // triangle vertices
57 const std::array<QVector2D, 2> &p, // line points
58 const std::array<QVector2D, 3> &n); // vertex normals
59
60 void cookGeometry() override;
61
62 static const QSGGeometry::AttributeSet &attributes();
63
64 QVector<quint32> uncookedIndexes() const
65 {
66 return m_uncookedIndexes;
67 }
68
69 float debug() const
70 {
71 return m_debug;
72 }
73
74 void setDebug(float newDebug)
75 {
76 m_debug = newDebug;
77 }
78
79 void setLocalScale(float scale)
80 {
81 m_localScale = scale;
82 }
83
84 float localScale() const
85 {
86 return m_localScale;
87 }
88
89private:
90
91 struct StrokeVertex
92 {
93 float x, y;
94 float ax, ay;
95 float bx, by;
96 float cx, cy;
97 float nx, ny; //normal vector: direction to move vertext to account for AA
98 };
99
100 void updateMaterial();
101
102 static std::array<QVector2D, 3> curveABC(const std::array<QVector2D, 3> &p);
103
104 QColor m_color;
105 float m_strokeWidth = 0.0f;
106 float m_debug = 0.0f;
107 float m_localScale = 1.0f;
108
109protected:
110 QScopedPointer<QSGCurveStrokeMaterial> m_material;
111
112 QVector<StrokeVertex> m_uncookedVertexes;
113 QVector<quint32> m_uncookedIndexes;
114};
115
116QT_END_NAMESPACE
117
118#endif // QSGCURVESTROKENODE_P_H
119

source code of qtdeclarative/src/quick/scenegraph/qsgcurvestrokenode_p.h