1 | /* |
2 | * SPDX-FileCopyrightText: 2020 Arjen Hiemstra <ahiemstra@heimr.nl> |
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 | */ |
19 | class ShadowedRectangleMaterial : public QSGMaterial |
20 | { |
21 | public: |
22 | enum class ShaderType { |
23 | Standard, |
24 | LowPower, |
25 | }; |
26 | |
27 | ShadowedRectangleMaterial(); |
28 | |
29 | QSGMaterialShader *createShader(QSGRendererInterface::RenderMode) const override; |
30 | QSGMaterialType *type() const override; |
31 | int compare(const QSGMaterial *other) const override; |
32 | |
33 | QVector2D aspect = QVector2D{1.0, 1.0}; |
34 | float size = 0.0; |
35 | QVector4D radius = QVector4D{0.0, 0.0, 0.0, 0.0}; |
36 | QColor color = Qt::white; |
37 | QColor shadowColor = Qt::black; |
38 | QVector2D offset; |
39 | ShaderType shaderType = ShaderType::Standard; |
40 | |
41 | static QSGMaterialType staticType; |
42 | }; |
43 | |
44 | class ShadowedRectangleShader : public QSGMaterialShader |
45 | { |
46 | public: |
47 | ShadowedRectangleShader(ShadowedRectangleMaterial::ShaderType shaderType); |
48 | |
49 | bool updateUniformData(QSGMaterialShader::RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override; |
50 | |
51 | protected: |
52 | void setShader(ShadowedRectangleMaterial::ShaderType shaderType, const QString &shader); |
53 | }; |
54 | |