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 PARTICLEAFFECTOR_H |
5 | #define PARTICLEAFFECTOR_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 <QSet> |
20 | #include "qquickparticlesystem_p.h" |
21 | #include "qquickparticleextruder_p.h" |
22 | #include "qtquickparticlesglobal_p.h" |
23 | |
24 | QT_BEGIN_NAMESPACE |
25 | |
26 | class Q_QUICKPARTICLES_PRIVATE_EXPORT QQuickParticleAffector : public QQuickItem |
27 | { |
28 | Q_OBJECT |
29 | Q_PROPERTY(QQuickParticleSystem* system READ system WRITE setSystem NOTIFY systemChanged FINAL) |
30 | Q_PROPERTY(QStringList groups READ groups WRITE setGroups NOTIFY groupsChanged FINAL) |
31 | Q_PROPERTY(QStringList whenCollidingWith READ whenCollidingWith WRITE setWhenCollidingWith NOTIFY whenCollidingWithChanged FINAL) |
32 | Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged FINAL) |
33 | Q_PROPERTY(bool once READ onceOff WRITE setOnceOff NOTIFY onceChanged FINAL) |
34 | Q_PROPERTY(QQuickParticleExtruder* shape READ shape WRITE setShape NOTIFY shapeChanged FINAL) |
35 | |
36 | QML_NAMED_ELEMENT(ParticleAffector) |
37 | QML_ADDED_IN_VERSION(2, 0) |
38 | QML_UNCREATABLE("Abstract type. Use one of the inheriting types instead.") |
39 | |
40 | public: |
41 | explicit QQuickParticleAffector(QQuickItem *parent = nullptr); |
42 | virtual void affectSystem(qreal dt); |
43 | virtual void reset(QQuickParticleData*);//As some store their own data per particle? |
44 | QQuickParticleSystem* system() const |
45 | { |
46 | return m_system; |
47 | } |
48 | |
49 | QStringList groups() const |
50 | { |
51 | return m_groups; |
52 | } |
53 | |
54 | bool enabled() const |
55 | { |
56 | return m_enabled; |
57 | } |
58 | |
59 | bool onceOff() const |
60 | { |
61 | return m_onceOff; |
62 | } |
63 | |
64 | QQuickParticleExtruder* shape() const |
65 | { |
66 | return m_shape; |
67 | } |
68 | |
69 | QStringList whenCollidingWith() const |
70 | { |
71 | return m_whenCollidingWith; |
72 | } |
73 | |
74 | Q_SIGNALS: |
75 | |
76 | void systemChanged(QQuickParticleSystem* arg); |
77 | |
78 | void groupsChanged(const QStringList &arg); |
79 | |
80 | void enabledChanged(bool arg); |
81 | |
82 | void onceChanged(bool arg); |
83 | |
84 | void shapeChanged(QQuickParticleExtruder* arg); |
85 | |
86 | void affected(qreal x, qreal y); |
87 | |
88 | void whenCollidingWithChanged(const QStringList &arg); |
89 | |
90 | public Q_SLOTS: |
91 | void setSystem(QQuickParticleSystem* arg) |
92 | { |
93 | if (m_system != arg) { |
94 | m_system = arg; |
95 | if (m_system) |
96 | m_system->registerParticleAffector(a: this); |
97 | Q_EMIT systemChanged(arg); |
98 | } |
99 | } |
100 | |
101 | void setGroups(const QStringList &arg) |
102 | { |
103 | if (m_groups != arg) { |
104 | m_groups = arg; |
105 | m_updateIntSet = true; |
106 | Q_EMIT groupsChanged(arg); |
107 | } |
108 | } |
109 | |
110 | void setEnabled(bool arg) |
111 | { |
112 | if (m_enabled != arg) { |
113 | m_enabled = arg; |
114 | Q_EMIT enabledChanged(arg); |
115 | } |
116 | } |
117 | |
118 | void setOnceOff(bool arg) |
119 | { |
120 | if (m_onceOff != arg) { |
121 | m_onceOff = arg; |
122 | m_needsReset = true; |
123 | Q_EMIT onceChanged(arg); |
124 | } |
125 | } |
126 | |
127 | void setShape(QQuickParticleExtruder* arg) |
128 | { |
129 | if (m_shape != arg) { |
130 | m_shape = arg; |
131 | Q_EMIT shapeChanged(arg); |
132 | } |
133 | } |
134 | |
135 | void setWhenCollidingWith(const QStringList &arg) |
136 | { |
137 | if (m_whenCollidingWith != arg) { |
138 | m_whenCollidingWith = arg; |
139 | Q_EMIT whenCollidingWithChanged(arg); |
140 | } |
141 | } |
142 | public Q_SLOTS: |
143 | void updateOffsets(); |
144 | |
145 | protected: |
146 | friend class QQuickParticleSystem; |
147 | virtual bool affectParticle(QQuickParticleData *d, qreal dt); |
148 | bool m_needsReset:1;//### What is this really saving? |
149 | bool m_ignoresTime:1; |
150 | bool m_onceOff:1; |
151 | bool m_enabled:1; |
152 | |
153 | QQuickParticleSystem* m_system; |
154 | QStringList m_groups; |
155 | bool activeGroup(int g); |
156 | bool shouldAffect(QQuickParticleData* datum);//Call to do the logic on whether it is affecting that datum |
157 | void postAffect(QQuickParticleData* datum);//Call to do the post-affect logic on particles which WERE affected(once off, needs reset, affected signal) |
158 | void componentComplete() override; |
159 | bool isAffectedConnected(); |
160 | static const qreal simulationDelta; |
161 | static const qreal simulationCutoff; |
162 | |
163 | QPointF m_offset; |
164 | QSet<QPair<int, int>> m_onceOffed; |
165 | private: |
166 | QSet<int> m_groupIds; |
167 | bool m_updateIntSet; |
168 | |
169 | QQuickParticleExtruder* m_shape; |
170 | |
171 | QStringList m_whenCollidingWith; |
172 | |
173 | bool isColliding(QQuickParticleData* d) const; |
174 | }; |
175 | |
176 | QT_END_NAMESPACE |
177 | #endif // PARTICLEAFFECTOR_H |
178 |