| 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 ATTRACTORAFFECTOR_H |
| 5 | #define ATTRACTORAFFECTOR_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 | |
| 19 | QT_BEGIN_NAMESPACE |
| 20 | |
| 21 | class Q_QUICKPARTICLES_EXPORT QQuickAttractorAffector : public QQuickParticleAffector |
| 22 | { |
| 23 | Q_OBJECT |
| 24 | Q_PROPERTY(qreal strength READ strength WRITE setStrength NOTIFY strengthChanged) |
| 25 | Q_PROPERTY(qreal pointX READ pointX WRITE setPointX NOTIFY pointXChanged) |
| 26 | Q_PROPERTY(qreal pointY READ pointY WRITE setPointY NOTIFY pointYChanged) |
| 27 | Q_PROPERTY(AffectableParameters affectedParameter READ affectedParameter WRITE setAffectedParameter NOTIFY affectedParameterChanged) |
| 28 | Q_PROPERTY(Proportion proportionalToDistance READ proportionalToDistance WRITE setProportionalToDistance NOTIFY proportionalToDistanceChanged) |
| 29 | QML_NAMED_ELEMENT(Attractor) |
| 30 | QML_ADDED_IN_VERSION(2, 0) |
| 31 | |
| 32 | public: |
| 33 | enum Proportion{ |
| 34 | Constant, |
| 35 | Linear, |
| 36 | Quadratic, |
| 37 | InverseLinear, |
| 38 | InverseQuadratic |
| 39 | }; |
| 40 | Q_ENUM(Proportion) |
| 41 | |
| 42 | enum AffectableParameters { |
| 43 | Position, |
| 44 | Velocity, |
| 45 | Acceleration |
| 46 | }; |
| 47 | Q_ENUM(AffectableParameters) |
| 48 | |
| 49 | explicit QQuickAttractorAffector(QQuickItem *parent = nullptr); |
| 50 | |
| 51 | qreal strength() const |
| 52 | { |
| 53 | return m_strength; |
| 54 | } |
| 55 | |
| 56 | qreal pointX() const |
| 57 | { |
| 58 | return m_x; |
| 59 | } |
| 60 | |
| 61 | qreal pointY() const |
| 62 | { |
| 63 | return m_y; |
| 64 | } |
| 65 | |
| 66 | AffectableParameters affectedParameter() const |
| 67 | { |
| 68 | return m_physics; |
| 69 | } |
| 70 | |
| 71 | Proportion proportionalToDistance() const |
| 72 | { |
| 73 | return m_proportionalToDistance; |
| 74 | } |
| 75 | |
| 76 | Q_SIGNALS: |
| 77 | |
| 78 | void strengthChanged(qreal arg); |
| 79 | |
| 80 | void pointXChanged(qreal arg); |
| 81 | |
| 82 | void pointYChanged(qreal arg); |
| 83 | |
| 84 | void affectedParameterChanged(AffectableParameters arg); |
| 85 | |
| 86 | void proportionalToDistanceChanged(Proportion arg); |
| 87 | |
| 88 | public Q_SLOTS: |
| 89 | void setStrength(qreal arg) |
| 90 | { |
| 91 | if (m_strength != arg) { |
| 92 | m_strength = arg; |
| 93 | Q_EMIT strengthChanged(arg); |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | void setPointX(qreal arg) |
| 98 | { |
| 99 | if (m_x != arg) { |
| 100 | m_x = arg; |
| 101 | Q_EMIT pointXChanged(arg); |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | void setPointY(qreal arg) |
| 106 | { |
| 107 | if (m_y != arg) { |
| 108 | m_y = arg; |
| 109 | Q_EMIT pointYChanged(arg); |
| 110 | } |
| 111 | } |
| 112 | void setAffectedParameter(AffectableParameters arg) |
| 113 | { |
| 114 | if (m_physics != arg) { |
| 115 | m_physics = arg; |
| 116 | Q_EMIT affectedParameterChanged(arg); |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | void setProportionalToDistance(Proportion arg) |
| 121 | { |
| 122 | if (m_proportionalToDistance != arg) { |
| 123 | m_proportionalToDistance = arg; |
| 124 | Q_EMIT proportionalToDistanceChanged(arg); |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | protected: |
| 129 | bool affectParticle(QQuickParticleData *d, qreal dt) override; |
| 130 | |
| 131 | private: |
| 132 | qreal m_strength; |
| 133 | qreal m_x; |
| 134 | qreal m_y; |
| 135 | AffectableParameters m_physics; |
| 136 | Proportion m_proportionalToDistance; |
| 137 | }; |
| 138 | |
| 139 | QT_END_NAMESPACE |
| 140 | #endif // ATTRACTORAFFECTOR_H |
| 141 |
