| 1 | /* |
| 2 | * This file is part of KQuickCharts |
| 3 | * SPDX-FileCopyrightText: 2019 Arjen Hiemstra <ahiemstra@heimr.nl> |
| 4 | * |
| 5 | * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL |
| 6 | */ |
| 7 | |
| 8 | #ifndef PIECHARTMATERIAL_H |
| 9 | #define PIECHARTMATERIAL_H |
| 10 | |
| 11 | #include <QColor> |
| 12 | #include <QSGMaterial> |
| 13 | #include <QSGMaterialShader> |
| 14 | |
| 15 | #include "SDFShader.h" |
| 16 | |
| 17 | class PieChartMaterial : public QSGMaterial |
| 18 | { |
| 19 | public: |
| 20 | PieChartMaterial(); |
| 21 | ~PieChartMaterial(); |
| 22 | |
| 23 | QSGMaterialType *type() const override; |
| 24 | QSGMaterialShader *createShader(QSGRendererInterface::RenderMode) const override; |
| 25 | |
| 26 | QVector2D aspectRatio() const; |
| 27 | float innerRadius() const; |
| 28 | float outerRadius() const; |
| 29 | QColor backgroundColor() const; |
| 30 | bool smoothEnds() const; |
| 31 | float fromAngle() const; |
| 32 | float toAngle() const; |
| 33 | |
| 34 | QList<QVector2D> segments() const; |
| 35 | QList<QVector4D> colors() const; |
| 36 | |
| 37 | void setAspectRatio(const QVector2D &aspect); |
| 38 | void setInnerRadius(float radius); |
| 39 | void setOuterRadius(float radius); |
| 40 | void setBackgroundColor(const QColor &color); |
| 41 | void setSmoothEnds(bool smooth); |
| 42 | void setFromAngle(float angle); |
| 43 | void setToAngle(float angle); |
| 44 | |
| 45 | void setSegments(const QList<QVector2D> &triangles); |
| 46 | void setColors(const QList<QVector4D> &colors); |
| 47 | |
| 48 | private: |
| 49 | QVector2D m_aspectRatio; |
| 50 | float m_innerRadius = 0.0f; |
| 51 | float m_outerRadius = 0.0f; |
| 52 | QColor m_backgroundColor; |
| 53 | bool m_smoothEnds = false; |
| 54 | float m_fromAngle = 0.0; |
| 55 | float m_toAngle = 6.28318; // 2 * pi |
| 56 | |
| 57 | QList<QVector2D> m_segments; |
| 58 | QList<QVector4D> m_colors; |
| 59 | }; |
| 60 | |
| 61 | class PieChartShader : public SDFShader |
| 62 | { |
| 63 | public: |
| 64 | PieChartShader(); |
| 65 | ~PieChartShader(); |
| 66 | |
| 67 | bool updateUniformData(QSGMaterialShader::RenderState &state, QSGMaterial *newMaterial, QSGMaterial *oldMaterial) override; |
| 68 | }; |
| 69 | |
| 70 | #endif // PIECHARTMATERIAL_H |
| 71 | |