aboutsummaryrefslogtreecommitdiffstats
path: root/src/particles/qquickv4particledata_p.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/particles/qquickv4particledata_p.h')
-rw-r--r--src/particles/qquickv4particledata_p.h147
1 files changed, 100 insertions, 47 deletions
diff --git a/src/particles/qquickv4particledata_p.h b/src/particles/qquickv4particledata_p.h
index e41700f7c2..d51c4871e8 100644
--- a/src/particles/qquickv4particledata_p.h
+++ b/src/particles/qquickv4particledata_p.h
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtQuick module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QQuickV8PARTICLEDATA_H
#define QQuickV8PARTICLEDATA_H
@@ -51,20 +15,109 @@
// We mean it.
//
-#include <private/qv4persistent_p.h>
-#include <private/qv4value_p.h>
+#include <private/qquickparticlesystem_p.h>
+#include <QtQml/qqml.h>
QT_BEGIN_NAMESPACE
-class QQuickParticleData;
-class QQuickParticleSystem;
-class QQuickV4ParticleData {
+class QQuickV4ParticleData
+{
+ Q_GADGET
+ QML_VALUE_TYPE(particle)
+ QML_ADDED_IN_VERSION(6, 7)
+
+#define Q_QUICK_PARTICLE_ACCESSOR(TYPE, VARIABLE, NAME) \
+ Q_PROPERTY(TYPE NAME READ NAME WRITE set_ ## NAME FINAL) \
+ TYPE NAME() const { return datum ? datum->VARIABLE : TYPE(); } \
+ void set_ ## NAME(TYPE a) { if (datum) datum->VARIABLE = a; }
+
+ Q_QUICK_PARTICLE_ACCESSOR(float, x, initialX)
+ Q_QUICK_PARTICLE_ACCESSOR(float, vx, initialVX)
+ Q_QUICK_PARTICLE_ACCESSOR(float, ax, initialAX)
+ Q_QUICK_PARTICLE_ACCESSOR(float, y, initialY)
+ Q_QUICK_PARTICLE_ACCESSOR(float, vy, initialVY)
+ Q_QUICK_PARTICLE_ACCESSOR(float, ay, initialAY)
+ Q_QUICK_PARTICLE_ACCESSOR(float, t, t)
+ Q_QUICK_PARTICLE_ACCESSOR(float, size, startSize)
+ Q_QUICK_PARTICLE_ACCESSOR(float, endSize, endSize)
+ Q_QUICK_PARTICLE_ACCESSOR(float, lifeSpan, lifeSpan)
+ Q_QUICK_PARTICLE_ACCESSOR(float, rotation, rotation)
+ Q_QUICK_PARTICLE_ACCESSOR(float, rotationVelocity, rotationVelocity)
+ Q_QUICK_PARTICLE_ACCESSOR(bool, autoRotate, autoRotate)
+ Q_QUICK_PARTICLE_ACCESSOR(bool, update, update)
+ Q_QUICK_PARTICLE_ACCESSOR(float, xx, xDeformationVectorX)
+ Q_QUICK_PARTICLE_ACCESSOR(float, yx, yDeformationVectorX)
+ Q_QUICK_PARTICLE_ACCESSOR(float, xy, xDeformationVectorY)
+ Q_QUICK_PARTICLE_ACCESSOR(float, yy, yDeformationVectorY)
+
+ // Undocumented?
+ Q_QUICK_PARTICLE_ACCESSOR(float, animIdx, animationIndex)
+ Q_QUICK_PARTICLE_ACCESSOR(float, frameDuration, frameDuration)
+ Q_QUICK_PARTICLE_ACCESSOR(float, frameAt, frameAt)
+ Q_QUICK_PARTICLE_ACCESSOR(float, frameCount, frameCount)
+ Q_QUICK_PARTICLE_ACCESSOR(float, animT, animationT)
+
+#undef Q_QUICK_PARTICLE_ACCESSOR
+
+#define Q_QUICK_PARTICLE_SYSTEM_ACCESSOR(GETTER, SETTER, NAME) \
+ Q_PROPERTY(float NAME READ NAME WRITE set_ ## NAME) \
+ float NAME() const { return (datum && particleSystem) ? datum->GETTER(particleSystem) : 0; } \
+ void set_ ## NAME(float a) { if (datum && particleSystem) datum->SETTER(a, particleSystem); }
+
+ Q_QUICK_PARTICLE_SYSTEM_ACCESSOR(curX, setInstantaneousX, x)
+ Q_QUICK_PARTICLE_SYSTEM_ACCESSOR(curVX, setInstantaneousVX, vx)
+ Q_QUICK_PARTICLE_SYSTEM_ACCESSOR(curAX, setInstantaneousAX, ax)
+ Q_QUICK_PARTICLE_SYSTEM_ACCESSOR(curY, setInstantaneousY, y)
+ Q_QUICK_PARTICLE_SYSTEM_ACCESSOR(curVY, setInstantaneousVY, vy)
+ Q_QUICK_PARTICLE_SYSTEM_ACCESSOR(curAY, setInstantaneousAY, ay)
+
+#undef Q_QUICK_PARTICLE_SYSTEM_ACCESSOR
+
+#define Q_QUICK_PARTICLE_COLOR_ACCESSOR(VAR, NAME) \
+ Q_PROPERTY(float NAME READ NAME WRITE set_ ## NAME) \
+ float NAME() const { return datum ? datum->color.VAR / 255.0 : 0.0; } \
+ void set_ ## NAME(float a)\
+ {\
+ if (datum)\
+ datum->color.VAR = qMin(255, qMax(0, (int)::floor(a * 255.0)));\
+ }
+
+ Q_QUICK_PARTICLE_COLOR_ACCESSOR(r, red)
+ Q_QUICK_PARTICLE_COLOR_ACCESSOR(g, green)
+ Q_QUICK_PARTICLE_COLOR_ACCESSOR(b, blue)
+ Q_QUICK_PARTICLE_COLOR_ACCESSOR(a, alpha)
+
+#undef Q_QUICK_PARTICLE_COLOR_ACCESSOR
+
+ Q_PROPERTY(float lifeLeft READ lifeLeft)
+ Q_PROPERTY(float currentSize READ currentSize)
+
public:
- QQuickV4ParticleData(QV4::ExecutionEngine*, QQuickParticleData*, QQuickParticleSystem *system);
- ~QQuickV4ParticleData();
- QV4::ReturnedValue v4Value() const;
+ QQuickV4ParticleData() = default;
+ QQuickV4ParticleData(QQuickParticleData *datum, QQuickParticleSystem *system)
+ : datum(datum)
+ , particleSystem(system)
+ {}
+
+ Q_INVOKABLE void discard()
+ {
+ if (datum)
+ datum->lifeSpan = 0;
+ }
+
+ float lifeLeft() const
+ {
+ return (datum && particleSystem) ? datum->lifeLeft(particleSystem) : 0.0;
+ }
+
+ float currentSize() const
+ {
+ return (datum && particleSystem) ? datum->curSize(particleSystem) : 0.0;
+ }
+
private:
- QV4::PersistentValue m_v4Value;
+ QQuickParticleData *datum = nullptr;
+ QQuickParticleSystem *particleSystem = nullptr;
};