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 QQUICKSHAPESTROKENODE_P_H |
5 | #define QQUICKSHAPESTROKENODE_P_H |
6 | |
7 | #include <QtQuick/qsgnode.h> |
8 | |
9 | #include "qquickshapegenericrenderer_p.h" |
10 | #include "qquickshapestrokenode_p_p.h" |
11 | |
12 | // |
13 | // W A R N I N G |
14 | // ------------- |
15 | // |
16 | // This file is not part of the Qt API. It exists for the convenience |
17 | // of a number of Qt sources files. This header file may change from |
18 | // version to version without notice, or even be removed. |
19 | // |
20 | // We mean it. |
21 | // |
22 | |
23 | QT_BEGIN_NAMESPACE |
24 | |
25 | class QQuickShapeStrokeNode : public QSGGeometryNode |
26 | { |
27 | public: |
28 | QQuickShapeStrokeNode(); |
29 | |
30 | void setColor(QColor col) |
31 | { |
32 | m_color = col; |
33 | } |
34 | |
35 | QColor color() const |
36 | { |
37 | return m_color; |
38 | } |
39 | |
40 | void setStrokeWidth(float width) |
41 | { |
42 | m_strokeWidth = width; |
43 | } |
44 | |
45 | float strokeWidth() const |
46 | { |
47 | return m_strokeWidth; |
48 | } |
49 | |
50 | void appendTriangle(const std::array<QVector2D, 3> &v, // triangle vertices |
51 | const std::array<QVector2D, 3> &p, // curve points |
52 | const std::array<QVector2D, 3> &n); // vertex normals |
53 | void appendTriangle(const std::array<QVector2D, 3> &v, // triangle vertices |
54 | const std::array<QVector2D, 2> &p, // line points |
55 | const std::array<QVector2D, 3> &n); // vertex normals |
56 | |
57 | void cookGeometry(); |
58 | |
59 | static const QSGGeometry::AttributeSet &attributes(); |
60 | |
61 | QVector<quint32> uncookedIndexes() const |
62 | { |
63 | return m_uncookedIndexes; |
64 | } |
65 | |
66 | float debug() const |
67 | { |
68 | return m_debug; |
69 | } |
70 | |
71 | void setDebug(float newDebug) |
72 | { |
73 | m_debug = newDebug; |
74 | } |
75 | |
76 | private: |
77 | |
78 | struct StrokeVertex |
79 | { |
80 | float x, y; |
81 | float ax, ay; |
82 | float bx, by; |
83 | float cx, cy; |
84 | float nx, ny; //normal vector: direction to move vertext to account for AA |
85 | }; |
86 | |
87 | void updateMaterial(); |
88 | |
89 | static std::array<QVector2D, 3> curveABC(const std::array<QVector2D, 3> &p); |
90 | |
91 | QColor m_color; |
92 | float m_strokeWidth = 0.0f; |
93 | float m_debug = 0.0f; |
94 | |
95 | protected: |
96 | QScopedPointer<QQuickShapeStrokeMaterial> m_material; |
97 | |
98 | QVector<StrokeVertex> m_uncookedVertexes; |
99 | QVector<quint32> m_uncookedIndexes; |
100 | }; |
101 | |
102 | QT_END_NAMESPACE |
103 | |
104 | #endif // QQUICKSHAPESTROKENODE_P_H |
105 | |