From 970112dfe70ad020596477c0dcf43376171aba6e Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Tue, 23 Aug 2011 20:37:39 +1000 Subject: 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 Reviewed-by: Martin Jones --- src/declarative/particles/qsgfollowemitter.cpp | 23 ++++++++++++++++++++++- src/declarative/particles/qsgfollowemitter_p.h | 2 ++ src/declarative/particles/qsgparticleemitter.cpp | 2 +- src/declarative/particles/qsgparticlesystem.cpp | 2 +- 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() -- cgit v1.2.3