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 QQuickV8PARTICLEDATA_H |
5 | #define QQuickV8PARTICLEDATA_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 <private/qquickparticlesystem_p.h> |
19 | #include <QtQml/qqml.h> |
20 | |
21 | QT_BEGIN_NAMESPACE |
22 | |
23 | class QQuickV4ParticleData |
24 | { |
25 | Q_GADGET |
26 | QML_VALUE_TYPE(particle) |
27 | QML_ADDED_IN_VERSION(6, 7) |
28 | |
29 | #define Q_QUICK_PARTICLE_ACCESSOR(TYPE, VARIABLE, NAME) \ |
30 | Q_PROPERTY(TYPE NAME READ NAME WRITE set_ ## NAME FINAL) \ |
31 | TYPE NAME() const { return datum ? datum->VARIABLE : TYPE(); } \ |
32 | void set_ ## NAME(TYPE a) { if (datum) datum->VARIABLE = a; } |
33 | |
34 | Q_QUICK_PARTICLE_ACCESSOR(float, x, initialX) |
35 | Q_QUICK_PARTICLE_ACCESSOR(float, vx, initialVX) |
36 | Q_QUICK_PARTICLE_ACCESSOR(float, ax, initialAX) |
37 | Q_QUICK_PARTICLE_ACCESSOR(float, y, initialY) |
38 | Q_QUICK_PARTICLE_ACCESSOR(float, vy, initialVY) |
39 | Q_QUICK_PARTICLE_ACCESSOR(float, ay, initialAY) |
40 | Q_QUICK_PARTICLE_ACCESSOR(float, t, t) |
41 | Q_QUICK_PARTICLE_ACCESSOR(float, size, startSize) |
42 | Q_QUICK_PARTICLE_ACCESSOR(float, endSize, endSize) |
43 | Q_QUICK_PARTICLE_ACCESSOR(float, lifeSpan, lifeSpan) |
44 | Q_QUICK_PARTICLE_ACCESSOR(float, rotation, rotation) |
45 | Q_QUICK_PARTICLE_ACCESSOR(float, rotationVelocity, rotationVelocity) |
46 | Q_QUICK_PARTICLE_ACCESSOR(bool, autoRotate, autoRotate) |
47 | Q_QUICK_PARTICLE_ACCESSOR(bool, update, update) |
48 | Q_QUICK_PARTICLE_ACCESSOR(float, xx, xDeformationVectorX) |
49 | Q_QUICK_PARTICLE_ACCESSOR(float, yx, yDeformationVectorX) |
50 | Q_QUICK_PARTICLE_ACCESSOR(float, xy, xDeformationVectorY) |
51 | Q_QUICK_PARTICLE_ACCESSOR(float, yy, yDeformationVectorY) |
52 | |
53 | // Undocumented? |
54 | Q_QUICK_PARTICLE_ACCESSOR(float, animIdx, animationIndex) |
55 | Q_QUICK_PARTICLE_ACCESSOR(float, frameDuration, frameDuration) |
56 | Q_QUICK_PARTICLE_ACCESSOR(float, frameAt, frameAt) |
57 | Q_QUICK_PARTICLE_ACCESSOR(float, frameCount, frameCount) |
58 | Q_QUICK_PARTICLE_ACCESSOR(float, animT, animationT) |
59 | |
60 | #undef Q_QUICK_PARTICLE_ACCESSOR |
61 | |
62 | #define Q_QUICK_PARTICLE_SYSTEM_ACCESSOR(GETTER, SETTER, NAME) \ |
63 | Q_PROPERTY(float NAME READ NAME WRITE set_ ## NAME) \ |
64 | float NAME() const { return (datum && particleSystem) ? datum->GETTER(particleSystem) : 0; } \ |
65 | void set_ ## NAME(float a) { if (datum && particleSystem) datum->SETTER(a, particleSystem); } |
66 | |
67 | Q_QUICK_PARTICLE_SYSTEM_ACCESSOR(curX, setInstantaneousX, x) |
68 | Q_QUICK_PARTICLE_SYSTEM_ACCESSOR(curVX, setInstantaneousVX, vx) |
69 | Q_QUICK_PARTICLE_SYSTEM_ACCESSOR(curAX, setInstantaneousAX, ax) |
70 | Q_QUICK_PARTICLE_SYSTEM_ACCESSOR(curY, setInstantaneousY, y) |
71 | Q_QUICK_PARTICLE_SYSTEM_ACCESSOR(curVY, setInstantaneousVY, vy) |
72 | Q_QUICK_PARTICLE_SYSTEM_ACCESSOR(curAY, setInstantaneousAY, ay) |
73 | |
74 | #undef Q_QUICK_PARTICLE_SYSTEM_ACCESSOR |
75 | |
76 | #define Q_QUICK_PARTICLE_COLOR_ACCESSOR(VAR, NAME) \ |
77 | Q_PROPERTY(float NAME READ NAME WRITE set_ ## NAME) \ |
78 | float NAME() const { return datum ? datum->color.VAR / 255.0 : 0.0; } \ |
79 | void set_ ## NAME(float a)\ |
80 | {\ |
81 | if (datum)\ |
82 | datum->color.VAR = qMin(255, qMax(0, (int)::floor(a * 255.0)));\ |
83 | } |
84 | |
85 | Q_QUICK_PARTICLE_COLOR_ACCESSOR(r, red) |
86 | Q_QUICK_PARTICLE_COLOR_ACCESSOR(g, green) |
87 | Q_QUICK_PARTICLE_COLOR_ACCESSOR(b, blue) |
88 | Q_QUICK_PARTICLE_COLOR_ACCESSOR(a, alpha) |
89 | |
90 | #undef Q_QUICK_PARTICLE_COLOR_ACCESSOR |
91 | |
92 | Q_PROPERTY(float lifeLeft READ lifeLeft) |
93 | Q_PROPERTY(float currentSize READ currentSize) |
94 | |
95 | public: |
96 | QQuickV4ParticleData() = default; |
97 | QQuickV4ParticleData(QQuickParticleData *datum, QQuickParticleSystem *system) |
98 | : datum(datum) |
99 | , particleSystem(system) |
100 | {} |
101 | |
102 | Q_INVOKABLE void discard() |
103 | { |
104 | if (datum) |
105 | datum->lifeSpan = 0; |
106 | } |
107 | |
108 | float lifeLeft() const |
109 | { |
110 | return (datum && particleSystem) ? datum->lifeLeft(particleSystem) : 0.0; |
111 | } |
112 | |
113 | float currentSize() const |
114 | { |
115 | return (datum && particleSystem) ? datum->curSize(particleSystem) : 0.0; |
116 | } |
117 | |
118 | private: |
119 | QQuickParticleData *datum = nullptr; |
120 | QQuickParticleSystem *particleSystem = nullptr; |
121 | }; |
122 | |
123 | |
124 | QT_END_NAMESPACE |
125 | |
126 | |
127 | #endif |
128 |
Definitions
- QQuickV4ParticleData
- initialX
- initialVX
- initialAX
- initialY
- initialVY
- initialAY
- t
- startSize
- endSize
- lifeSpan
- rotation
- rotationVelocity
- autoRotate
- update
- xDeformationVectorX
- yDeformationVectorX
- xDeformationVectorY
- yDeformationVectorY
- animationIndex
- frameDuration
- frameAt
- frameCount
- animationT
- x
- vx
- ax
- y
- vy
- ay
- red
- green
- blue
- alpha
- QQuickV4ParticleData
- QQuickV4ParticleData
- discard
- lifeLeft
Start learning QML with our Intro Training
Find out more