| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
| 4 | ** Contact: https://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the QtQuick module of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ |
| 9 | ** Commercial License Usage |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 11 | ** accordance with the commercial license agreement provided with the |
| 12 | ** Software or, alternatively, in accordance with the terms contained in |
| 13 | ** a written agreement between you and The Qt Company. For licensing terms |
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at https://www.qt.io/contact-us. |
| 16 | ** |
| 17 | ** GNU Lesser General Public License Usage |
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
| 19 | ** General Public License version 3 as published by the Free Software |
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
| 21 | ** packaging of this file. Please review the following information to |
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements |
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
| 24 | ** |
| 25 | ** GNU General Public License Usage |
| 26 | ** Alternatively, this file may be used under the terms of the GNU |
| 27 | ** General Public License version 2.0 or (at your option) the GNU General |
| 28 | ** Public license version 3 or any later version approved by the KDE Free |
| 29 | ** Qt Foundation. The licenses are as published by the Free Software |
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
| 31 | ** included in the packaging of this file. Please review the following |
| 32 | ** information to ensure the GNU General Public License requirements will |
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
| 35 | ** |
| 36 | ** $QT_END_LICENSE$ |
| 37 | ** |
| 38 | ****************************************************************************/ |
| 39 | |
| 40 | #ifndef PARTICLEAFFECTOR_H |
| 41 | #define PARTICLEAFFECTOR_H |
| 42 | |
| 43 | // |
| 44 | // W A R N I N G |
| 45 | // ------------- |
| 46 | // |
| 47 | // This file is not part of the Qt API. It exists purely as an |
| 48 | // implementation detail. This header file may change from version to |
| 49 | // version without notice, or even be removed. |
| 50 | // |
| 51 | // We mean it. |
| 52 | // |
| 53 | |
| 54 | #include <QObject> |
| 55 | #include "qquickparticlesystem_p.h" |
| 56 | #include "qquickparticleextruder_p.h" |
| 57 | #include "qtquickparticlesglobal_p.h" |
| 58 | #include "qquickparticleflatset_p.h" |
| 59 | |
| 60 | QT_BEGIN_NAMESPACE |
| 61 | |
| 62 | class Q_QUICKPARTICLES_PRIVATE_EXPORT QQuickParticleAffector : public QQuickItem |
| 63 | { |
| 64 | Q_OBJECT |
| 65 | Q_PROPERTY(QQuickParticleSystem* system READ system WRITE setSystem NOTIFY systemChanged) |
| 66 | Q_PROPERTY(QStringList groups READ groups WRITE setGroups NOTIFY groupsChanged) |
| 67 | Q_PROPERTY(QStringList whenCollidingWith READ whenCollidingWith WRITE setWhenCollidingWith NOTIFY whenCollidingWithChanged) |
| 68 | Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged) |
| 69 | Q_PROPERTY(bool once READ onceOff WRITE setOnceOff NOTIFY onceChanged) |
| 70 | Q_PROPERTY(QQuickParticleExtruder* shape READ shape WRITE setShape NOTIFY shapeChanged) |
| 71 | |
| 72 | QML_NAMED_ELEMENT(ParticleAffector) |
| 73 | QML_UNCREATABLE("Abstract type. Use one of the inheriting types instead." ) |
| 74 | |
| 75 | public: |
| 76 | explicit QQuickParticleAffector(QQuickItem *parent = 0); |
| 77 | virtual void affectSystem(qreal dt); |
| 78 | virtual void reset(QQuickParticleData*);//As some store their own data per particle? |
| 79 | QQuickParticleSystem* system() const |
| 80 | { |
| 81 | return m_system; |
| 82 | } |
| 83 | |
| 84 | QStringList groups() const |
| 85 | { |
| 86 | return m_groups; |
| 87 | } |
| 88 | |
| 89 | bool enabled() const |
| 90 | { |
| 91 | return m_enabled; |
| 92 | } |
| 93 | |
| 94 | bool onceOff() const |
| 95 | { |
| 96 | return m_onceOff; |
| 97 | } |
| 98 | |
| 99 | QQuickParticleExtruder* shape() const |
| 100 | { |
| 101 | return m_shape; |
| 102 | } |
| 103 | |
| 104 | QStringList whenCollidingWith() const |
| 105 | { |
| 106 | return m_whenCollidingWith; |
| 107 | } |
| 108 | |
| 109 | Q_SIGNALS: |
| 110 | |
| 111 | void systemChanged(QQuickParticleSystem* arg); |
| 112 | |
| 113 | void groupsChanged(const QStringList &arg); |
| 114 | |
| 115 | void enabledChanged(bool arg); |
| 116 | |
| 117 | void onceChanged(bool arg); |
| 118 | |
| 119 | void shapeChanged(QQuickParticleExtruder* arg); |
| 120 | |
| 121 | void affected(qreal x, qreal y); |
| 122 | |
| 123 | void whenCollidingWithChanged(const QStringList &arg); |
| 124 | |
| 125 | public Q_SLOTS: |
| 126 | void setSystem(QQuickParticleSystem* arg) |
| 127 | { |
| 128 | if (m_system != arg) { |
| 129 | m_system = arg; |
| 130 | m_system->registerParticleAffector(a: this); |
| 131 | Q_EMIT systemChanged(arg); |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | void setGroups(const QStringList &arg) |
| 136 | { |
| 137 | if (m_groups != arg) { |
| 138 | m_groups = arg; |
| 139 | m_updateIntSet = true; |
| 140 | Q_EMIT groupsChanged(arg); |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | void setEnabled(bool arg) |
| 145 | { |
| 146 | if (m_enabled != arg) { |
| 147 | m_enabled = arg; |
| 148 | Q_EMIT enabledChanged(arg); |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | void setOnceOff(bool arg) |
| 153 | { |
| 154 | if (m_onceOff != arg) { |
| 155 | m_onceOff = arg; |
| 156 | m_needsReset = true; |
| 157 | Q_EMIT onceChanged(arg); |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | void setShape(QQuickParticleExtruder* arg) |
| 162 | { |
| 163 | if (m_shape != arg) { |
| 164 | m_shape = arg; |
| 165 | Q_EMIT shapeChanged(arg); |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | void setWhenCollidingWith(const QStringList &arg) |
| 170 | { |
| 171 | if (m_whenCollidingWith != arg) { |
| 172 | m_whenCollidingWith = arg; |
| 173 | Q_EMIT whenCollidingWithChanged(arg); |
| 174 | } |
| 175 | } |
| 176 | public Q_SLOTS: |
| 177 | void updateOffsets(); |
| 178 | |
| 179 | protected: |
| 180 | friend class QQuickParticleSystem; |
| 181 | virtual bool affectParticle(QQuickParticleData *d, qreal dt); |
| 182 | bool m_needsReset:1;//### What is this really saving? |
| 183 | bool m_ignoresTime:1; |
| 184 | bool m_onceOff:1; |
| 185 | bool m_enabled:1; |
| 186 | |
| 187 | QQuickParticleSystem* m_system; |
| 188 | QStringList m_groups; |
| 189 | bool activeGroup(int g); |
| 190 | bool shouldAffect(QQuickParticleData* datum);//Call to do the logic on whether it is affecting that datum |
| 191 | void postAffect(QQuickParticleData* datum);//Call to do the post-affect logic on particles which WERE affected(once off, needs reset, affected signal) |
| 192 | void componentComplete() override; |
| 193 | bool isAffectedConnected(); |
| 194 | static const qreal simulationDelta; |
| 195 | static const qreal simulationCutoff; |
| 196 | |
| 197 | QPointF m_offset; |
| 198 | QtQuickParticlesPrivate::QFlatSet<QPair<int, int>> m_onceOffed; |
| 199 | private: |
| 200 | QSet<int> m_groupIds; |
| 201 | bool m_updateIntSet; |
| 202 | |
| 203 | QQuickParticleExtruder* m_shape; |
| 204 | |
| 205 | QStringList m_whenCollidingWith; |
| 206 | |
| 207 | bool isColliding(QQuickParticleData* d) const; |
| 208 | }; |
| 209 | |
| 210 | QT_END_NAMESPACE |
| 211 | #endif // PARTICLEAFFECTOR_H |
| 212 | |