DtkDeclarative
DTK Declarative module
载入中...
搜索中...
未找到
dshadownode_p.h
1// SPDX-FileCopyrightText: 2021 - 2022 UnionTech Software Technology Co., Ltd.
2//
3// SPDX-License-Identifier: LGPL-3.0-or-later
4
5#ifndef DSHADOWNODE_P_H
6#define DSHADOWNODE_P_H
7
8#include <dtkdeclarative_global.h>
9
10#include <private/qsgadaptationlayer_p.h>
11
12#include <QSGVertexColorMaterial>
13#include <QSGGeometry>
14
15DQUICK_BEGIN_NAMESPACE
16
17class ShadowMaterial : public QSGVertexColorMaterial
18{
19public:
21
22 QColor color() const { return m_color; }
23 void setColor(const QColor &color) { m_color = color; }
24
25 qreal relativeSizeX() const { return m_relativeSizeX; }
26 void setRelativeSizeX(qreal x) { m_relativeSizeX = x; }
27
28 qreal relativeSizeY() const { return m_relativeSizeY; }
29 void setRelativeSizeY(qreal y) { m_relativeSizeY = y; }
30
31 qreal spread() const { return m_spread; }
32 void setSpread(qreal spread) { m_spread = spread; }
33
34 QSGMaterialType *type() const override;
35#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
36 QSGMaterialShader *createShader() const override;
37#else
38 QSGMaterialShader *createShader(QSGRendererInterface::RenderMode renderMode) const override;
39#endif
40
41 int compare(const QSGMaterial *) const override;
42
43private:
44 QColor m_color;
45 qreal m_relativeSizeX;
46 qreal m_relativeSizeY;
47 qreal m_spread;
48};
49
51{
52 float m_x;
53 float m_y;
54 float m_tx;
55 float m_ty;
56
57 void set(float x, float y, float tx, float ty)
58 {
59 m_x = x; m_y = y; m_tx = tx; m_ty = ty;
60 }
61};
62
63class ShadowNode : public QSGVisitableNode
64{
65public:
66 ShadowNode();
67
68 void setRect(const QRectF &);
69 void setColor(const QColor &color);
70 void setGlowRadius(qreal radius);
71 void setRelativeSizeX(qreal x);
72 void setRelativeSizeY(qreal y);
73 void setSpread(qreal spread);
74 void setFill(bool);
75 void update();
76 void updateGeometry();
77 bool geometryIsDirty() const { return m_geometryChanged; }
78 void accept(QSGNodeVisitorEx *visitor) override { if (visitor->visit(this)) visitor->visitChildren(this); visitor->endVisit(this); }
79private:
80 static const QSGGeometry::AttributeSet &shadowAttributes()
81 {
82 static QSGGeometry::Attribute data[] = {
83 QSGGeometry::Attribute::create(0, 2, GL_FLOAT, true),
84 QSGGeometry::Attribute::create(1, 2, GL_FLOAT)
85 };
86 static QSGGeometry::AttributeSet attributes = { 2, sizeof(ShadowVertex), data };
87 return attributes;
88 }
89
90private:
91 ShadowMaterial m_material;
92 QSGGeometry m_geometry { shadowAttributes(), 0 };
93
94 QRectF m_rect;
95 bool m_geometryChanged = true;
96 qreal m_glowRadius;
97 bool m_fill;
98};
99
100DQUICK_END_NAMESPACE
101
102#endif // DSHADOWNODE_P_H
Definition dshadownode_p.h:18
Definition dshadownode_p.h:64
Definition dshadownode_p.h:51