DtkDeclarative
DTK Declarative module
载入中...
搜索中...
未找到
drectanglenode_p.h
1// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd.
2//
3// SPDX-License-Identifier: LGPL-3.0-or-later
4
5#ifndef DRECTANGLENODE_P_H
6#define DRECTANGLENODE_P_H
7
8#include "dquickrectangle_p.h"
9
10#include <dtkdeclarative_global.h>
11
12#include <private/qsgtexturematerial_p.h>
13#include <private/qsgrendernode_p.h>
14
15#include <QSGMaterial>
16#include <QSGGeometry>
17#include <QSGTextureMaterial>
18#include <QSGRectangleNode>
19#include <QSGVertexColorMaterial>
20
21DQUICK_BEGIN_NAMESPACE
22
23#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
24class CornerColorShader : public QSGOpaqueTextureMaterialShader
25{
26public:
27 const char *vertexShader() const override;
28 const char *fragmentShader() const override;
29 char const *const *attributeNames() const override;
30 void updateState(const RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override;
31 void initialize() override;
32
33private:
34 int m_idQtOpacity = -1;
35};
36#else
37class CornerColorShader : public QSGOpaqueTextureMaterialRhiShader
38{
39public:
41 bool updateUniformData(RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial);
42};
43#endif
44
45class CornerColorMaterial : public QSGOpaqueTextureMaterial
46{
47public:
49
50 void setRadius(qreal radius) { m_radius = radius; }
51
52 QColor color() const { return m_color; }
53 void setColor(const QColor &color) { m_color = color; }
54
55 QSGMaterialType *type() const override;
56#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
57 QSGMaterialShader *createShader() const override;
58#else
59 QSGMaterialShader *createShader(QSGRendererInterface::RenderMode renderMode) const override;
60#endif
61
62 int compare(const QSGMaterial *other) const override;
63
64private:
65 qreal m_radius;
66 QColor m_color;
67};
68
70{
71 float m_x;
72 float m_y;
73 float m_tx;
74 float m_ty;
75 unsigned char r, g, b, a;
76 void set(float x, float y, float tx, float ty, uchar nr, uchar ng, uchar nb, uchar na)
77 {
78 m_x = x; m_y = y;
79 m_tx = tx; m_ty = ty;
80 r = nr; g = ng; b = nb; a = na;
81 }
82};
83
84class DRectangleNode : public QSGRectangleNode
85{
86public:
88
89 void setRect(const QRectF &) override;
90 QRectF rect() const override { return m_rect; }
91 void setRadius(qreal radius);
92 void setColor(const QColor &color) override;
93 QColor color() const override { return m_color; }
94 void setMakTexture(QSGTexture *texture);
95 void setCorners(DQuickRectangle::Corners);
96 void update();
97
98protected:
99 void updateGeometry();
100
101private:
102 const QSGGeometry::AttributeSet &ColoredCornerAttributes()
103 {
104 static QSGGeometry::Attribute data[] = {
105 QSGGeometry::Attribute::create(0, 2, GL_FLOAT, true),
106 QSGGeometry::Attribute::create(1, 2, GL_FLOAT),
107 QSGGeometry::Attribute::create(2, 4, GL_UNSIGNED_BYTE)
108 };
109 static QSGGeometry::AttributeSet attributes = { 3, sizeof(ColoredCornerPoint2D), data };
110 return attributes;
111 }
112
113private:
114 QSGVertexColorMaterial m_material;
115 QSGGeometry m_geometry;
116
117 CornerColorMaterial m_cornerMaterial;
118 QSGGeometry m_cornerGeometry { ColoredCornerAttributes(), 0 };
119 QSGGeometryNode m_cornerNode;
120
121 QRectF m_rect;
122 bool m_geometryChanged = false;
123 DQuickRectangle::Corners m_coners = DQuickRectangle::NoneCorner;
124 qreal m_radius = 0;
125 QColor m_color = QColor::Invalid;
126 QSGTexture *m_maskTexture = nullptr;
127};
128
129class DSoftRectangleNode : public QSGRenderNode
130{
131public:
132 DSoftRectangleNode(QQuickItem *owner);
133
134 StateFlags changedStates() const override;
135 void render(const RenderState *state) override;
136 RenderingFlags flags() const override;
137 QRectF rect() const override;
138
139 void setRadius(qreal radius);
140 void setColor(const QColor &color);
141 void setCorners(DQuickRectangle::Corners);
142
143private:
144 QQuickItem *m_item = nullptr;
145 qreal m_radius = 0;
146 QColor m_color = QColor::Invalid;
147 DQuickRectangle::Corners m_coners = DQuickRectangle::NoneCorner;
148 QQuickWindow *m_window = nullptr;
149};
150
151DQUICK_END_NAMESPACE
152
153#endif // DRECTANGLENODE_P_H
Definition drectanglenode_p.h:46
Definition drectanglenode_p.h:38
Definition drectanglenode_p.h:85
Definition drectanglenode_p.h:130
Definition drectanglenode_p.h:70