summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Alpert <alan.alpert@nokia.com>2011-08-23 20:37:39 +1000
committerQt by Nokia <qt-info@nokia.com>2011-08-25 06:39:54 +0200
commit970112dfe70ad020596477c0dcf43376171aba6e (patch)
treeab961ecaee579edbf28e58cae938f5b5365228c6
parent71f6f5625d3675fa166c81799bc6872d6cb95700 (diff)
Add custom emission capability to FollowEmitter
Also implement speedFromMovement (a convenience now) and fix a bug in QSGParticleData::curSize() Change-Id: I831494f24f4b4afaee47524e4a4060f06fefdb0a Reviewed-on: http://codereview.qt.nokia.com/3396 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Martin Jones <martin.jones@nokia.com>
-rw-r--r--src/declarative/particles/qsgfollowemitter.cpp23
-rw-r--r--src/declarative/particles/qsgfollowemitter_p.h2
-rw-r--r--src/declarative/particles/qsgparticleemitter.cpp2
-rw-r--r--src/declarative/particles/qsgparticlesystem.cpp2
4 files changed, 26 insertions, 3 deletions
diff --git a/src/declarative/particles/qsgfollowemitter.cpp b/src/declarative/particles/qsgfollowemitter.cpp
index 0ee4a00f00..68f0f6bf75 100644
--- a/src/declarative/particles/qsgfollowemitter.cpp
+++ b/src/declarative/particles/qsgfollowemitter.cpp
@@ -93,7 +93,21 @@ QSGFollowEmitter::QSGFollowEmitter(QSGItem *parent) :
/*!
\qmlproperty real QtQuick.Particles2::FollowEmitter::emitRatePerParticle
*/
+/*!
+ \qmlsignal QtQuick.Particles2::FollowEmitter::emitFollowParticle(particle, followed)
+
+ This handler is called when a particle is emitted. You can modify particle
+ attributes from within the handler. followed is the particle that this is being
+ emitted off of.
+ If you use this signal handler, emitParticle will not be emitted.
+*/
+
+bool QSGFollowEmitter::isEmitFollowConnected()
+{
+ static int idx = QObjectPrivate::get(this)->signalIndex("emitFollowParticle(QDeclarativeV8Handle,QDeclarativeV8Handle)");
+ return QObjectPrivate::get(this)->isSignalConnected(idx);
+}
void QSGFollowEmitter::recalcParticlesPerSecond(){
if (!m_system)
@@ -193,8 +207,10 @@ void QSGFollowEmitter::emitWindow(int timeStamp)
// Particle speed
const QPointF &speed = m_speed->sample(newPos);
- datum->vx = speed.x();
+ datum->vx = speed.x()
+ + m_speed_from_movement * d->vx;
datum->vy = speed.y();
+ + m_speed_from_movement * d->vy;
// Particle acceleration
const QPointF &accel = m_acceleration->sample(newPos);
@@ -211,6 +227,11 @@ void QSGFollowEmitter::emitWindow(int timeStamp)
datum->size = size * float(m_emitting);
datum->endSize = endSize * float(m_emitting);
+ if (isEmitFollowConnected())
+ emitFollowParticle(datum->v8Value(), d->v8Value());//A chance for many arbitrary JS changes
+ else if (isEmitConnected())
+ emitParticle(datum->v8Value());//A chance for arbitrary JS changes
+
m_system->emitParticle(datum);
}
if (!m_burstQueue.isEmpty()){
diff --git a/src/declarative/particles/qsgfollowemitter_p.h b/src/declarative/particles/qsgfollowemitter_p.h
index 3fd5f1c2f8..d26435df6a 100644
--- a/src/declarative/particles/qsgfollowemitter_p.h
+++ b/src/declarative/particles/qsgfollowemitter_p.h
@@ -95,6 +95,7 @@ public:
}
signals:
+ void emitFollowParticle(QDeclarativeV8Handle particle, QDeclarativeV8Handle followed);
void particlesPerParticlePerSecondChanged(int arg);
@@ -161,6 +162,7 @@ private:
int m_followCount;
QSGParticleExtruder* m_emissionExtruder;
QSGParticleExtruder* m_defaultEmissionExtruder;
+ bool isEmitFollowConnected();
};
QT_END_NAMESPACE
diff --git a/src/declarative/particles/qsgparticleemitter.cpp b/src/declarative/particles/qsgparticleemitter.cpp
index 6155fd5009..bf4f5701e5 100644
--- a/src/declarative/particles/qsgparticleemitter.cpp
+++ b/src/declarative/particles/qsgparticleemitter.cpp
@@ -181,7 +181,7 @@ QT_BEGIN_NAMESPACE
*/
//TODO: Document particle 'type'
/*!
- \qmlsignal QtQuick.Particles2::Emitter::emitting(particle)
+ \qmlsignal QtQuick.Particles2::Emitter::emitParticle(particle)
This handler is called when a particle is emitted. You can modify particle
attributes from within the handler.
diff --git a/src/declarative/particles/qsgparticlesystem.cpp b/src/declarative/particles/qsgparticlesystem.cpp
index a08495b8e2..efd6c22bd9 100644
--- a/src/declarative/particles/qsgparticlesystem.cpp
+++ b/src/declarative/particles/qsgparticlesystem.cpp
@@ -477,7 +477,7 @@ float QSGParticleData::curSize()
{
if (!system || !lifeSpan)
return 0.0f;
- return size + (endSize - size) * (lifeLeft() / lifeSpan);
+ return size + (endSize - size) * (1 - (lifeLeft() / lifeSpan));
}
float QSGParticleData::lifeLeft()