aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick3dparticles/qquick3dparticledynamicburst.cpp
blob: 75575f57cebc75f69e9ee73639e9d2670c892bca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
// Copyright (C) 2022 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only

#include "qquick3dparticledynamicburst_p.h"

QT_BEGIN_NAMESPACE

/*!
    \qmltype DynamicBurst3D
    \inherits EmitBurst3D
    \inqmlmodule QtQuick3D.Particles3D
    \brief Dynamic emitter bursts.
    \since 6.3

    This element defines particle bursts in the \l ParticleEmitter3D. These bursts are
    dynamic, meaning that they are evaluated while the particlesystem runs. Use these
    instead of \l EmitBurst3D for example when the emitter moves, so that emitting
    happens at the correct position.

    For example, to emit 100 particles at 1 second time and 200 particles at 2 second:

    \qml
    ParticleEmitter3D {
        ...
        emitBursts: [
            DynamicBurst3D {
                time: 1000
                amount: 100
            },
            DynamicBurst3D {
                time: 2000
                amount: 200
            }
        ]
    }
    \endqml
*/

QQuick3DParticleDynamicBurst::QQuick3DParticleDynamicBurst(QObject *parent)
    : QQuick3DParticleEmitBurst(parent)
{

}

/*!
    \qmlproperty bool DynamicBurst3D::enabled

    If enabled is set to \c false, this burst will not emit any particles.

    The default value is \c true.
*/
bool QQuick3DParticleDynamicBurst::enabled() const
{
    return m_enabled;
}

/*!
    \qmlproperty int DynamicBurst3D::amountVariation

    This property defines the random variation in particle emit amount.

    For example, to have a random range between 0 and 10
    \qml
    DynamicBurst3D {
        time: 1000
        amount: 5
        amountVariation: 5
    }
    \endqml

    The default value is \c 0.
*/
int QQuick3DParticleDynamicBurst::amountVariation() const
{
    return m_amountVariation;
}

/*!
    \qmlproperty ShapeType DynamicBurst3D::triggerMode

    This property defines the emitting mode.

    The default value is \c TriggerMode.TriggerTime.
*/

/*!
    \qmlproperty enumeration DynamicBurst3D::TriggerMode

    Defines the mode of the bursting.

    \value DynamicBurst3D.TriggerTime
        The particles are emitted when the burst \l {EmitBurst3D::time}{time} is due.
    \value DynamicBurst3D.TriggerStart
        The particles are emitted when the followed particle is emitted.
        \note This property is restricted to only work with trail emitters.
        \note In this mode, \c time and \c duration properties don't have an effect.
    \value DynamicBurst3D.TriggerEnd
        The particles are emitted when the followed particle \c lifeSpan ends.
        \note This property is restricted to only work with trail emitters.
        \note In this mode, \c time and \c duration properties don't have an effect.
*/

QQuick3DParticleDynamicBurst::TriggerMode QQuick3DParticleDynamicBurst::triggerMode() const
{
    return m_triggerMode;
}

void QQuick3DParticleDynamicBurst::setEnabled(bool enabled)
{
    if (m_enabled == enabled)
        return;

    m_enabled = enabled;
    Q_EMIT enabledChanged();
}

void QQuick3DParticleDynamicBurst::setAmountVariation(int value)
{
    if (m_amountVariation == value)
        return;

    if (value < 0) {
        qWarning () << "DynamicBurst3D: Amount variation must be positive.";
        return;
    }
    m_amountVariation = value;
    Q_EMIT amountVariationChanged();
}

void QQuick3DParticleDynamicBurst::setTriggerMode(TriggerMode mode)
{
    if (m_triggerMode == mode)
        return;

    m_triggerMode = mode;
    Q_EMIT triggerModeChanged();
}

QT_END_NAMESPACE