| 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 TURBULENCEAFFECTOR_H |
| 5 | #define TURBULENCEAFFECTOR_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 | #include "qquickparticleaffector_p.h" |
| 18 | #include <QQmlListProperty> |
| 19 | |
| 20 | QT_BEGIN_NAMESPACE |
| 21 | |
| 22 | class QQuickParticlePainter; |
| 23 | |
| 24 | class Q_QUICKPARTICLES_EXPORT QQuickTurbulenceAffector : public QQuickParticleAffector |
| 25 | { |
| 26 | Q_OBJECT |
| 27 | Q_PROPERTY(qreal strength READ strength WRITE setStrength NOTIFY strengthChanged) |
| 28 | Q_PROPERTY(QUrl noiseSource READ noiseSource WRITE setNoiseSource NOTIFY noiseSourceChanged) |
| 29 | QML_NAMED_ELEMENT(Turbulence) |
| 30 | QML_ADDED_IN_VERSION(2, 0) |
| 31 | |
| 32 | public: |
| 33 | explicit QQuickTurbulenceAffector(QQuickItem *parent = nullptr); |
| 34 | ~QQuickTurbulenceAffector(); |
| 35 | void affectSystem(qreal dt) override; |
| 36 | |
| 37 | qreal strength() const |
| 38 | { |
| 39 | return m_strength; |
| 40 | } |
| 41 | |
| 42 | QUrl noiseSource() const |
| 43 | { |
| 44 | return m_noiseSource; |
| 45 | } |
| 46 | Q_SIGNALS: |
| 47 | |
| 48 | void strengthChanged(qreal arg); |
| 49 | |
| 50 | void noiseSourceChanged(const QUrl &arg); |
| 51 | |
| 52 | public Q_SLOTS: |
| 53 | |
| 54 | void setStrength(qreal arg) |
| 55 | { |
| 56 | if (m_strength != arg) { |
| 57 | m_strength = arg; |
| 58 | Q_EMIT strengthChanged(arg); |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | void setNoiseSource(const QUrl &arg) |
| 63 | { |
| 64 | if (m_noiseSource != arg) { |
| 65 | m_noiseSource = arg; |
| 66 | Q_EMIT noiseSourceChanged(arg); |
| 67 | initializeGrid(); |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | protected: |
| 72 | void geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) override; |
| 73 | private: |
| 74 | void ensureInit(); |
| 75 | void mapUpdate(); |
| 76 | void initializeGrid(); |
| 77 | qreal boundsRespectingField(int x, int y); |
| 78 | qreal m_strength; |
| 79 | int m_gridSize; |
| 80 | qreal** m_field; |
| 81 | QPointF** m_vectorField; |
| 82 | bool m_inited; |
| 83 | QUrl m_noiseSource; |
| 84 | }; |
| 85 | |
| 86 | QT_END_NAMESPACE |
| 87 | #endif // TURBULENCEAFFECTOR_H |
| 88 |
