File indexing completed on 2024-05-05 03:56:28
0001 /* 0002 * SPDX-FileCopyrightText: 2020 Arjen Hiemstra <ahiemstra@heimr.nl> 0003 * 0004 * SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include <QColor> 0010 #include <QSGMaterial> 0011 #include <QSGMaterialShader> 0012 0013 /** 0014 * A material rendering a rectangle with a shadow. 0015 * 0016 * This material uses a distance field shader to render a rectangle with a 0017 * shadow below it, optionally with rounded corners. 0018 */ 0019 class ShadowedRectangleMaterial : public QSGMaterial 0020 { 0021 public: 0022 enum class ShaderType { 0023 Standard, 0024 LowPower, 0025 }; 0026 0027 ShadowedRectangleMaterial(); 0028 0029 QSGMaterialShader *createShader(QSGRendererInterface::RenderMode) const override; 0030 QSGMaterialType *type() const override; 0031 int compare(const QSGMaterial *other) const override; 0032 0033 QVector2D aspect = QVector2D{1.0, 1.0}; 0034 float size = 0.0; 0035 QVector4D radius = QVector4D{0.0, 0.0, 0.0, 0.0}; 0036 QColor color = Qt::white; 0037 QColor shadowColor = Qt::black; 0038 QVector2D offset; 0039 ShaderType shaderType = ShaderType::Standard; 0040 0041 static QSGMaterialType staticType; 0042 }; 0043 0044 class ShadowedRectangleShader : public QSGMaterialShader 0045 { 0046 public: 0047 ShadowedRectangleShader(ShadowedRectangleMaterial::ShaderType shaderType); 0048 0049 bool updateUniformData(QSGMaterialShader::RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override; 0050 0051 protected: 0052 void setShader(ShadowedRectangleMaterial::ShaderType shaderType, const QString &shader); 0053 };