File indexing completed on 2024-05-05 16:16:42
0001 /* 0002 * SPDX-FileCopyrightText: 2021 Arjen Hiemstra <ahiemstra@heimr.nl> 0003 * 0004 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0005 */ 0006 0007 #ifndef PIECHARTMATERIAL_H 0008 #define PIECHARTMATERIAL_H 0009 0010 #include <QColor> 0011 #include <QSGMaterial> 0012 #include <QSGMaterialShader> 0013 0014 #include "SDFShader.h" 0015 0016 class BarChartMaterial : public QSGMaterial 0017 { 0018 public: 0019 BarChartMaterial(); 0020 ~BarChartMaterial(); 0021 0022 QSGMaterialType *type() const override; 0023 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) 0024 QSGMaterialShader *createShader() const override; 0025 #else 0026 QSGMaterialShader *createShader(QSGRendererInterface::RenderMode) const override; 0027 #endif 0028 int compare(const QSGMaterial *other) const override; 0029 0030 QVector2D aspect = QVector2D{1.0, 1.0}; 0031 float radius = 0.0; 0032 QColor backgroundColor = Qt::transparent; 0033 }; 0034 0035 class BarChartShader : public SDFShader 0036 { 0037 public: 0038 BarChartShader(); 0039 ~BarChartShader(); 0040 0041 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) 0042 char const *const *attributeNames() const override; 0043 0044 void initialize() override; 0045 void updateState(const RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override; 0046 0047 private: 0048 int m_matrixLocation = 0; 0049 int m_opacityLocation = 0; 0050 int m_aspectLocation = 0; 0051 int m_backgroundColorLocation = 0; 0052 int m_radiusLocation = 0; 0053 #else 0054 bool updateUniformData(QSGMaterialShader::RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override; 0055 #endif 0056 }; 0057 0058 #endif // PIECHARTMATERIAL_H