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

Provided by KDAB

Privacy Policy
Learn to use CMake with our Intro Training
Find out more

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