Add custom emission capability to FollowEmitter
authorAlan Alpert <alan.alpert@nokia.com>
Tue, 23 Aug 2011 10:37:39 +0000 (20:37 +1000)
committerQt by Nokia <qt-info@nokia.com>
Thu, 25 Aug 2011 04:39:54 +0000 (06:39 +0200)
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>
src/declarative/particles/qsgfollowemitter.cpp
src/declarative/particles/qsgfollowemitter_p.h
src/declarative/particles/qsgparticleemitter.cpp
src/declarative/particles/qsgparticlesystem.cpp

index 0ee4a00..68f0f6b 100644 (file)
@@ -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()){
index 3fd5f1c..d26435d 100644 (file)
@@ -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
index 6155fd5..bf4f570 100644 (file)
@@ -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.
index a08495b..efd6c22 100644 (file)
@@ -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()