Changeset View
Changeset View
Standalone View
Standalone View
src/scenegraph/shadowedrectanglematerial.h
- This file was added.
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 <QSGMaterial> | ||||
10 | #include <QSGMaterialShader> | ||||
11 | | ||||
12 | /** | ||||
13 | * A material rendering a rectangle with a shadow. | ||||
14 | * | ||||
15 | * This material uses a distance field shader to render a rectangle with a | ||||
16 | * shadow below it, optionally with rounded corners. | ||||
17 | */ | ||||
18 | class ShadowedRectangleMaterial : public QSGMaterial | ||||
19 | { | ||||
20 | public: | ||||
21 | ShadowedRectangleMaterial(); | ||||
22 | | ||||
23 | QSGMaterialShader* createShader() const override; | ||||
24 | QSGMaterialType* type() const override; | ||||
25 | int compare(const QSGMaterial* other) const override; | ||||
26 | | ||||
27 | QVector2D aspect = QVector2D{1.0, 1.0}; | ||||
28 | float size = 0.0; | ||||
29 | float radius = 0.0; | ||||
30 | QColor color = Qt::white; | ||||
31 | QColor shadowColor = Qt::black; | ||||
32 | QVector2D offset; | ||||
33 | | ||||
34 | static QSGMaterialType staticType; | ||||
35 | }; | ||||
36 | | ||||
37 | class ShadowedRectangleShader : public QSGMaterialShader | ||||
38 | { | ||||
39 | public: | ||||
40 | ShadowedRectangleShader(); | ||||
41 | | ||||
42 | char const *const *attributeNames() const override; | ||||
43 | | ||||
44 | void initialize() override; | ||||
45 | void updateState(const QSGMaterialShader::RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override; | ||||
46 | | ||||
47 | private: | ||||
48 | int m_matrixLocation = -1; | ||||
49 | int m_opacityLocation = -1; | ||||
50 | int m_aspectLocation = -1; | ||||
51 | int m_sizeLocation = -1; | ||||
52 | int m_radiusLocation = -1; | ||||
53 | int m_colorLocation = -1; | ||||
54 | int m_shadowColorLocation = -1; | ||||
55 | int m_offsetLocation = -1; | ||||
56 | }; |