File indexing completed on 2024-05-12 15:42:39

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 "shadowedrectanglematerial.h"
0010 
0011 /**
0012  * A material rendering a rectangle with a shadow and a border.
0013  *
0014  * This material uses a distance field shader to render a rectangle with a
0015  * shadow below it, optionally with rounded corners and a border.
0016  */
0017 class ShadowedBorderRectangleMaterial : public ShadowedRectangleMaterial
0018 {
0019 public:
0020     ShadowedBorderRectangleMaterial();
0021 
0022 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
0023     QSGMaterialShader *createShader() const override;
0024 #else
0025     QSGMaterialShader *createShader(QSGRendererInterface::RenderMode) const override;
0026 #endif
0027     QSGMaterialType *type() const override;
0028     int compare(const QSGMaterial *other) const override;
0029 
0030     float borderWidth = 0.0;
0031     QColor borderColor = Qt::black;
0032 
0033     static QSGMaterialType staticType;
0034 };
0035 
0036 class ShadowedBorderRectangleShader : public ShadowedRectangleShader
0037 {
0038 public:
0039     ShadowedBorderRectangleShader(ShadowedRectangleMaterial::ShaderType shaderType);
0040 
0041 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
0042     void initialize() override;
0043     void updateState(const QSGMaterialShader::RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override;
0044 
0045 private:
0046     int m_borderWidthLocation = -1;
0047     int m_borderColorLocation = -1;
0048 #else
0049     bool updateUniformData(QSGMaterialShader::RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override;
0050 #endif
0051 };