4#include <QtCore/qtconfigmacros.h>
9#include <private/qqmlglobal_p.h>
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
39
40
41
42
43
45
46
47
48
49
51
52
53
54
55
56
57
58
59
60
61
62
63
65
66
67
68
69
70
71
73
74
75
76
77
78
79
80
82
83
84
85
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101QQuickParticleAffector::QQuickParticleAffector(QQuickItem *parent) :
102 QQuickItem(parent), m_needsReset(
false), m_ignoresTime(
false), m_onceOff(
false), m_enabled(
true)
103 , m_system(
nullptr), m_updateIntSet(
false), m_shape(
new QQuickParticleExtruder(
this))
107bool QQuickParticleAffector::isAffectedConnected()
109 IS_SIGNAL_CONNECTED(
this, QQuickParticleAffector, affected, (qreal,qreal));
113void QQuickParticleAffector::componentComplete()
115 if (!m_system && qobject_cast<QQuickParticleSystem*>(parentItem()))
116 setSystem(qobject_cast<QQuickParticleSystem*>(parentItem()));
117 QQuickItem::componentComplete();
120bool QQuickParticleAffector::activeGroup(
int g) {
126 foreach (
const QString &p, m_groups)
127 m_groupIds << m_system->groupIds[p];
128 m_updateIntSet =
false;
130 return m_groupIds.isEmpty() || m_groupIds.contains(g);
133bool QQuickParticleAffector::shouldAffect(QQuickParticleData* d)
140 if (activeGroup(d->groupId)){
141 if ((m_onceOff && m_onceOffed.contains(std::make_pair(d->groupId, d->index)))
142 || !d->stillAlive(m_system))
145 if (width() == 0 || height() == 0
146 || m_shape->contains(QRectF(m_offset.x(), m_offset.y(), width(), height()), QPointF(d->curX(m_system), d->curY(m_system)))){
147 if (m_whenCollidingWith.isEmpty() || isColliding(d)){
156void QQuickParticleAffector::postAffect(QQuickParticleData* d)
161 m_system->needsReset << d;
163 m_onceOffed << std::make_pair(d->groupId, d->index);
164 if (isAffectedConnected())
165 emit affected(d->curX(m_system), d->curY(m_system));
168const qreal QQuickParticleAffector::simulationDelta = 0.020;
169const qreal QQuickParticleAffector::simulationCutoff = 1.000;
171void QQuickParticleAffector::affectSystem(qreal dt)
183 for (QQuickParticleGroupData* gd : std::as_const(m_system->groupData)) {
184 if (activeGroup(gd->index)) {
185 for (QQuickParticleData* d : std::as_const(gd->data)) {
186 if (shouldAffect(d)) {
187 bool affected =
false;
189 if (!m_ignoresTime && myDt < simulationCutoff) {
190 int realTime = m_system->timeInt;
191 m_system->timeInt -= myDt * 1000.0;
192 while (myDt > simulationDelta) {
193 m_system->timeInt += simulationDelta * 1000.0;
194 if (d->alive(m_system))
195 affected = affectParticle(d, simulationDelta) || affected;
196 myDt -= simulationDelta;
198 m_system->timeInt = realTime;
201 affected = affectParticle(d, myDt) || affected;
210bool QQuickParticleAffector::affectParticle(QQuickParticleData *, qreal )
215void QQuickParticleAffector::reset(QQuickParticleData* pd)
218 if (activeGroup(pd->groupId))
219 m_onceOffed.remove(std::make_pair(pd->groupId, pd->index));
222void QQuickParticleAffector::updateOffsets()
225 m_offset = m_system->mapFromItem(
this, QPointF(0, 0));
228bool QQuickParticleAffector::isColliding(QQuickParticleData *d)
const
233 qreal myCurX = d->curX(m_system);
234 qreal myCurY = d->curY(m_system);
235 qreal myCurSize = d->curSize(m_system) / 2;
236 foreach (
const QString &group, m_whenCollidingWith){
237 foreach (QQuickParticleData* other, m_system->groupData[m_system->groupIds[group]]->data){
238 if (!other->stillAlive(m_system))
240 qreal otherCurX = other->curX(m_system);
241 qreal otherCurY = other->curY(m_system);
242 qreal otherCurSize = other->curSize(m_system) / 2;
243 if ((myCurX + myCurSize > otherCurX - otherCurSize
244 && myCurX - myCurSize < otherCurX + otherCurSize)
245 && (myCurY + myCurSize > otherCurY - otherCurSize
246 && myCurY - myCurSize < otherCurY + otherCurSize))
255#include "moc_qquickparticleaffector_p.cpp"
Combined button and popup list for selecting options.