Doc: Grouped Qt Quick types into several groups
[profile/ivi/qtdeclarative.git] / src / particles / qquickage.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the QtQuick module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
16 **
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
20 **
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
28 **
29 ** Other Usage
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #include "qquickage_p.h"
43 #include "qquickparticleemitter_p.h"
44 QT_BEGIN_NAMESPACE
45 /*!
46     \qmlclass Age QQuickAgeAffector
47     \inqmlmodule QtQuick.Particles 2
48     \inherits Affector
49     \brief For altering particle ages
50     \ingroup qtquick-particles
51
52     The Age affector allows you to alter where the particle is in its lifecycle. Common uses
53     are to expire particles prematurely, possibly giving them time to animate out.
54
55     The Age affector only applies to particles which are still alive.
56 */
57 /*!
58     \qmlproperty int QtQuick.Particles2::Age::lifeLeft
59
60     The amount of life to set the particle to have. Affected particles
61     will advance to a point in their life where they will have this many
62     milliseconds left to live.
63 */
64
65 /*!
66     \qmlproperty bool QtQuick.Particles2::Age::advancePosition
67
68     advancePosition determines whether position, veclocity and acceleration are included in
69     the simulated aging done by the affector. If advancePosition is false,
70     then the position, velocity and acceleration will remain the same and only
71     other attributes (such as opacity) will advance in the simulation to where
72     it would normally be for that point in the particle's life. With advancePosition set to
73     true the position, velocity and acceleration will also advance to where it would
74     normally be by that point in the particle's life, making it advance its position
75     on screen.
76
77     Default value is true.
78 */
79
80 QQuickAgeAffector::QQuickAgeAffector(QQuickItem *parent) :
81     QQuickParticleAffector(parent), m_lifeLeft(0), m_advancePosition(true)
82 {
83 }
84
85
86 bool QQuickAgeAffector::affectParticle(QQuickParticleData *d, qreal dt)
87 {
88     Q_UNUSED(dt);
89     if (d->stillAlive()){
90         qreal curT = (qreal)m_system->timeInt/1000.0;
91         qreal ttl = (qreal)m_lifeLeft/1000.0;
92         if (!m_advancePosition && ttl > 0){
93             qreal x = d->curX();
94             qreal vx = d->curVX();
95             qreal ax = d->curAX();
96             qreal y = d->curY();
97             qreal vy = d->curVY();
98             qreal ay = d->curAY();
99             d->t = curT - (d->lifeSpan - ttl);
100             d->setInstantaneousX(x);
101             d->setInstantaneousVX(vx);
102             d->setInstantaneousAX(ax);
103             d->setInstantaneousY(y);
104             d->setInstantaneousVY(vy);
105             d->setInstantaneousAY(ay);
106         } else {
107             d->t = curT - (d->lifeSpan - ttl);
108         }
109         return true;
110     }
111     return false;
112 }
113 QT_END_NAMESPACE