Kirigami2

shadowedrectanglematerial.h
1 /*
2  * SPDX-FileCopyrightText: 2020 Arjen Hiemstra <[email protected]>
3  *
4  * SPDX-License-Identifier: LGPL-2.0-or-later
5  */
6 
7 #pragma once
8 
9 #include <QColor>
10 #include <QSGMaterial>
11 #include <QSGMaterialShader>
12 
13 /**
14  * A material rendering a rectangle with a shadow.
15  *
16  * This material uses a distance field shader to render a rectangle with a
17  * shadow below it, optionally with rounded corners.
18  */
20 {
21 public:
22  enum class ShaderType {
23  Standard,
24  LowPower,
25  };
26 
28 
29 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
30  QSGMaterialShader *createShader() const override;
31 #else
32  QSGMaterialShader *createShader(QSGRendererInterface::RenderMode) const override;
33 #endif
34  QSGMaterialType *type() const override;
35  int compare(const QSGMaterial *other) const override;
36 
37  QVector2D aspect = QVector2D{1.0, 1.0};
38  float size = 0.0;
39  QVector4D radius = QVector4D{0.0, 0.0, 0.0, 0.0};
40  QColor color = Qt::white;
41  QColor shadowColor = Qt::black;
42  QVector2D offset;
43  ShaderType shaderType = ShaderType::Standard;
44 
45  static QSGMaterialType staticType;
46 };
47 
48 class ShadowedRectangleShader : public QSGMaterialShader
49 {
50 public:
51  ShadowedRectangleShader(ShadowedRectangleMaterial::ShaderType shaderType);
52 
53 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
54  char const *const *attributeNames() const override;
55 
56  void initialize() override;
57  void updateState(const QSGMaterialShader::RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override;
58 #else
59  bool updateUniformData(QSGMaterialShader::RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override;
60 #endif
61 
62 protected:
63  void setShader(ShadowedRectangleMaterial::ShaderType shaderType, const QString &shader);
64 
65 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
66 private:
67  int m_matrixLocation = -1;
68  int m_opacityLocation = -1;
69  int m_aspectLocation = -1;
70  int m_sizeLocation = -1;
71  int m_radiusLocation = -1;
72  int m_colorLocation = -1;
73  int m_shadowColorLocation = -1;
74  int m_offsetLocation = -1;
75 #endif
76 };
virtual void initialize()
virtual const char *const * attributeNames() const const=0
virtual QSGMaterialShader * createShader() const const=0
virtual void updateState(const QSGMaterialShader::RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial)
A material rendering a rectangle with a shadow.
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Tue Feb 7 2023 04:14:24 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.