1 | // Copyright (C) 2016 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #ifndef PARTICLE_H |
5 | #define PARTICLE_H |
6 | |
7 | // |
8 | // W A R N I N G |
9 | // ------------- |
10 | // |
11 | // This file is not part of the Qt API. It exists purely as an |
12 | // implementation detail. This header file may change from version to |
13 | // version without notice, or even be removed. |
14 | // |
15 | // We mean it. |
16 | // |
17 | |
18 | #include <QObject> |
19 | #include <QDebug> |
20 | #include <QPair> |
21 | #include "qquickparticlesystem_p.h" |
22 | |
23 | QT_BEGIN_NAMESPACE |
24 | |
25 | class Q_QUICKPARTICLES_PRIVATE_EXPORT QQuickParticlePainter : public QQuickItem |
26 | { |
27 | Q_OBJECT |
28 | Q_PROPERTY(QQuickParticleSystem* system READ system WRITE setSystem NOTIFY systemChanged FINAL) |
29 | Q_PROPERTY(QStringList groups READ groups WRITE setGroups NOTIFY groupsChanged FINAL) |
30 | |
31 | QML_NAMED_ELEMENT(ParticlePainter) |
32 | QML_ADDED_IN_VERSION(2, 0) |
33 | QML_UNCREATABLE("Abstract type. Use one of the inheriting types instead." ) |
34 | |
35 | public: // data |
36 | typedef QQuickParticleVarLengthArray<QQuickParticleGroupData::ID, 4> GroupIDs; |
37 | |
38 | public: |
39 | explicit QQuickParticlePainter(QQuickItem *parent = nullptr); |
40 | //Data Interface to system |
41 | void load(QQuickParticleData*); |
42 | void reload(QQuickParticleData*); |
43 | void setCount(int c); |
44 | |
45 | int count() const |
46 | { |
47 | return m_count; |
48 | } |
49 | |
50 | void performPendingCommits();//Called from updatePaintNode |
51 | QQuickParticleSystem* system() const |
52 | { |
53 | return m_system; |
54 | } |
55 | |
56 | QStringList groups() const |
57 | { |
58 | return m_groups; |
59 | } |
60 | |
61 | const GroupIDs &groupIds() const |
62 | { |
63 | if (m_groupIdsNeedRecalculation) { |
64 | recalculateGroupIds(); |
65 | } |
66 | return m_groupIds; |
67 | } |
68 | |
69 | void itemChange(ItemChange, const ItemChangeData &) override; |
70 | |
71 | Q_SIGNALS: |
72 | void countChanged(); |
73 | void systemChanged(QQuickParticleSystem* arg); |
74 | |
75 | void groupsChanged(const QStringList &arg); |
76 | |
77 | public Q_SLOTS: |
78 | void setSystem(QQuickParticleSystem* arg); |
79 | |
80 | void setGroups(const QStringList &arg); |
81 | |
82 | void calcSystemOffset(bool resetPending = false); |
83 | |
84 | private Q_SLOTS: |
85 | virtual void sceneGraphInvalidated() {} |
86 | |
87 | protected: |
88 | /* Reset resets all your internal data structures. But anything attached to a particle should |
89 | be in attached data. So reset + reloads should have no visible effect. |
90 | ###Hunt down all cases where we do a complete reset for convenience and be more targeted |
91 | */ |
92 | virtual void reset(); |
93 | |
94 | void componentComplete() override; |
95 | virtual void initialize(int gIdx, int pIdx){//Called from main thread |
96 | Q_UNUSED(gIdx); |
97 | Q_UNUSED(pIdx); |
98 | } |
99 | virtual void commit(int gIdx, int pIdx){//Called in Render Thread |
100 | //###If you need to do something on size changed, check m_data size in this? Or we reset you every time? |
101 | Q_UNUSED(gIdx); |
102 | Q_UNUSED(pIdx); |
103 | } |
104 | |
105 | QQuickParticleSystem* m_system; |
106 | friend class QQuickParticleSystem; |
107 | int m_count; |
108 | bool m_pleaseReset;//Used by subclasses, but it's a nice optimization to know when stuff isn't going to matter. |
109 | QPointF m_systemOffset; |
110 | |
111 | QQuickWindow *m_window; |
112 | bool m_windowChanged; |
113 | |
114 | private: // methods |
115 | void recalculateGroupIds() const; |
116 | |
117 | private: // data |
118 | QStringList m_groups; |
119 | QSet<QPair<int,int> > m_pendingCommits; |
120 | mutable GroupIDs m_groupIds; |
121 | mutable bool m_groupIdsNeedRecalculation; |
122 | }; |
123 | |
124 | QT_END_NAMESPACE |
125 | #endif // PARTICLE_H |
126 | |