QmlMaterial 0.1.0
Loading...
Searching...
No Matches
shimmer_material_p.hpp
1#pragma once
2
3#include "../item/shimmer_geometry_p.hpp"
4#include <QColor>
5#include <QPointer>
6#include <QSGGeometryNode>
7#include <QSGMaterial>
8#include <QSGTextureProvider>
9#include <QSGTransformNode>
10#include <functional>
11
12QT_BEGIN_NAMESPACE
13class QSGImageNode;
14QT_END_NAMESPACE
15
16namespace qml_material::sg
17{
18class ShimmerMaterial : public QSGMaterial {
19public:
20 explicit ShimmerMaterial(bool textured = false);
21 QSGMaterialType* type() const override;
22 QSGMaterialShader* createShader(QSGRendererInterface::RenderMode) const override;
23 int compare(const QSGMaterial*) const override;
24 shimmer::Frame frame;
25 QSGTexture* texture = nullptr;
26
27private:
28 bool m_textured;
29};
30class SkeletonNode : public QSGGeometryNode {
31public:
32 SkeletonNode();
33 void setData(QSizeF, QColor, qreal radius, const shimmer::Area&, const shimmer::Frame&);
34
35private:
36 QSizeF m_size;
37 QColor m_color;
38 qreal m_radius = -1;
39 shimmer::Area m_area;
40};
41class ShimmerTextureNode : public QObject, public QSGTransformNode {
42public:
43 ShimmerTextureNode(QQuickWindow*, QSGTextureProvider*, quint64 revision,
44 std::function<void(bool)> ready);
45 ~ShimmerTextureNode() override;
46 quint64 revision() const { return m_revision; }
47 QSGTextureProvider* provider() const { return m_provider; }
48 void setData(QSizeF, const shimmer::Area&, const shimmer::Frame&);
49 void preprocess() override;
50
51private:
52 void updateGeometry();
53 QPointer<QSGTextureProvider> m_provider;
54 QSGNode* m_draw;
55 QSGImageNode* m_image = nullptr;
56 QSGGeometryNode* m_geometry = nullptr;
57 ShimmerMaterial* m_material = nullptr;
58 QSGTexture* m_texture = nullptr;
59 QList<QMetaObject::Connection> m_connections;
60 std::function<void(bool)> m_onReady;
61 QSizeF m_size;
62 QRectF m_uv;
63 shimmer::Area m_area;
64 quint64 m_revision;
65 bool m_ready = false;
66};
67} // namespace qml_material::sg