aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAlan Alpert <alan.alpert@nokia.com>2011-09-14 18:15:17 +1000
committerQt by Nokia <qt-info@nokia.com>2011-09-16 06:37:43 +0200
commitd546b8b948ca1b7b6ac6a1a26a5fbd4972360ce8 (patch)
treefc9ee5bb9398acf12b074a41575131a6e8ded997 /src
parent41c645fb0078923cc93e98545091453d8f4b8277 (diff)
Add Age example
Also added advancePosition property to Age, as it was needed for even this simple example. Change-Id: I614a719280efc1bc5140d07ab91ec0f1bc345788 Reviewed-on: http://codereview.qt-project.org/4871 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Martin Jones <martin.jones@nokia.com>
Diffstat (limited to 'src')
-rw-r--r--src/declarative/particles/qsgage.cpp37
-rw-r--r--src/declarative/particles/qsgage_p.h19
2 files changed, 51 insertions, 5 deletions
diff --git a/src/declarative/particles/qsgage.cpp b/src/declarative/particles/qsgage.cpp
index 2c0678fd0e..0caa8be99c 100644
--- a/src/declarative/particles/qsgage.cpp
+++ b/src/declarative/particles/qsgage.cpp
@@ -57,12 +57,27 @@ QT_BEGIN_NAMESPACE
\qmlproperty int QtQuick.Particles2::Age::lifeLeft
The amount of life to set the particle to have. Affected particles
- will jump to a point in their life where they will have this many
+ will advance to a point in their life where they will have this many
milliseconds left to live.
*/
+/*!
+ \qmlproperty bool QtQuick.Particles2::Age::advancePosition
+
+ advancePosition determines whether position, veclocity and acceleration are included in
+ the simulated aging done by the affector. If advancePosition is false,
+ then the position, velocity and acceleration will remain the same and only
+ other attributes (such as opacity) will advance in the simulation to where
+ it would normally be for that point in the particle's life. With advancePosition set to
+ true the position, velocity and acceleration will also advance to where it would
+ normally be by that point in the particle's life, making it advance its position
+ on screen.
+
+ Default value is true.
+*/
+
QSGAgeAffector::QSGAgeAffector(QSGItem *parent) :
- QSGParticleAffector(parent), m_lifeLeft(0)
+ QSGParticleAffector(parent), m_lifeLeft(0), m_advancePosition(true)
{
}
@@ -73,7 +88,23 @@ bool QSGAgeAffector::affectParticle(QSGParticleData *d, qreal dt)
if (d->stillAlive()){
qreal curT = (qreal)m_system->m_timeInt/1000.0;
qreal ttl = (qreal)m_lifeLeft/1000.0;
- d->t = curT - (d->lifeSpan - ttl) + 1;
+ if (!m_advancePosition && ttl > 0){
+ qreal x = d->curX();
+ qreal vx = d->curVX();
+ qreal ax = d->curAX();
+ qreal y = d->curY();
+ qreal vy = d->curVY();
+ qreal ay = d->curAY();
+ d->t = curT - (d->lifeSpan - ttl);
+ d->setInstantaneousX(x);
+ d->setInstantaneousVX(vx);
+ d->setInstantaneousAX(ax);
+ d->setInstantaneousY(y);
+ d->setInstantaneousVY(vy);
+ d->setInstantaneousAY(ay);
+ } else {
+ d->t = curT - (d->lifeSpan - ttl);
+ }
return true;
}
return false;
diff --git a/src/declarative/particles/qsgage_p.h b/src/declarative/particles/qsgage_p.h
index c4c9929ad8..676122086c 100644
--- a/src/declarative/particles/qsgage_p.h
+++ b/src/declarative/particles/qsgage_p.h
@@ -54,6 +54,7 @@ class QSGAgeAffector : public QSGParticleAffector
{
Q_OBJECT
Q_PROPERTY(int lifeLeft READ lifeLeft WRITE setLifeLeft NOTIFY lifeLeftChanged)
+ Q_PROPERTY(bool advancePosition READ advancePosition WRITE setAdvancePosition NOTIFY advancePositionChanged)
public:
explicit QSGAgeAffector(QSGItem *parent = 0);
@@ -63,10 +64,16 @@ public:
return m_lifeLeft;
}
+ bool advancePosition() const
+ {
+ return m_advancePosition;
+ }
+
protected:
virtual bool affectParticle(QSGParticleData *d, qreal dt);
signals:
void lifeLeftChanged(int arg);
+ void advancePositionChanged(bool arg);
public slots:
void setLifeLeft(int arg)
@@ -77,9 +84,17 @@ public slots:
}
}
-private:
+ void setAdvancePosition(bool arg)
+ {
+ if (m_advancePosition != arg) {
+ m_advancePosition = arg;
+ emit advancePositionChanged(arg);
+ }
+ }
-int m_lifeLeft;
+private:
+ int m_lifeLeft;
+ bool m_advancePosition;
};
QT_END_NAMESPACE