From: Alan Alpert Date: Thu, 11 Aug 2011 09:59:05 +0000 (+1000) Subject: Add noCap and startTime properties to Emitter X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=5781598747ac8342a05e9a8f48ea09a7e0444467;p=konrad%2Fqtdeclarative.git Add noCap and startTime properties to Emitter Change-Id: I8498b2e574a32bfbab9f139e718424572b1258a0 Reviewed-on: http://codereview.qt.nokia.com/2855 Reviewed-by: Alan Alpert Reviewed-by: Qt Sanity Bot --- diff --git a/examples/declarative/particles/trails/overburst.qml b/examples/declarative/particles/trails/overburst.qml index c3129a1..ca6bc6d 100644 --- a/examples/declarative/particles/trails/overburst.qml +++ b/examples/declarative/particles/trails/overburst.qml @@ -61,7 +61,6 @@ Rectangle{ x: ma.mouseX y: ma.mouseY emitRate: 16000 - lifeSpan: 1000 emitCap: 4000 acceleration: AngledDirection{angleVariation: 360; magnitude: 360; } size: 8 @@ -75,7 +74,7 @@ Rectangle{ MouseArea{ width: 100 height: 100 - onClicked: sys.overwrite = !sys.overwrite + onClicked: bursty.noCap = true; id: ma2 Rectangle{ anchors.fill: parent diff --git a/src/declarative/particles/qsgfollowemitter.cpp b/src/declarative/particles/qsgfollowemitter.cpp index 54daec7..0ee4a00 100644 --- a/src/declarative/particles/qsgfollowemitter.cpp +++ b/src/declarative/particles/qsgfollowemitter.cpp @@ -134,6 +134,7 @@ void QSGFollowEmitter::emitWindow(int timeStamp) } } + //TODO: Implement startTime and speedFromMovement qreal time = timeStamp / 1000.; qreal particleRatio = 1. / m_particlesPerParticlePerSecond; qreal pt; @@ -158,7 +159,7 @@ void QSGFollowEmitter::emitWindow(int timeStamp) continue; } while (pt < time || !m_burstQueue.isEmpty()){ - QSGParticleData* datum = m_system->newDatum(gId2); + QSGParticleData* datum = m_system->newDatum(gId2, !m_overwrite); if (datum){//else, skip this emission datum->e = this;//###useful? diff --git a/src/declarative/particles/qsgparticleemitter.cpp b/src/declarative/particles/qsgparticleemitter.cpp index 4c08ef5..0daf274 100644 --- a/src/declarative/particles/qsgparticleemitter.cpp +++ b/src/declarative/particles/qsgparticleemitter.cpp @@ -110,6 +110,7 @@ QT_BEGIN_NAMESPACE Default value is 0. */ + /*! \qmlproperty int QtQuick.Particles2::Emitter::emitCap @@ -120,6 +121,21 @@ QT_BEGIN_NAMESPACE is the number of particles that would be alive at any one time given the default settings. */ /*! + \qmlproperty bool QtQuick.Particles2::Emitter::noCap + + If set to true, the emitCap will be ignored and this emitter will never skip emitting + a particle based on how many it has alive. + + Default value is false. +*/ +/*! + \qmlproperty int QtQuick.Particles2::Emitter::startTime + + If this value is set when the emitter is loaded, then it will emit particles from the + past, up to startTime milliseconds ago. These will simulate as if they were emitted then, + but will not have any affectors applied to them. Affectors will take effect from the present time. +*/ +/*! \qmlproperty real QtQuick.Particles2::Emitter::size The size in pixels of the particles at the start of their life. @@ -184,8 +200,10 @@ QSGParticleEmitter::QSGParticleEmitter(QSGItem *parent) : , m_speed_from_movement(0) , m_particle_count(0) , m_reset_last(true) - , m_last_timestamp(0) + , m_last_timestamp(-1) , m_last_emission(0) + , m_startTime(0) + , m_overwrite(false) { //TODO: Reset speed/acc back to null vector? Or allow null pointer? @@ -297,7 +315,10 @@ void QSGParticleEmitter::emitWindow(int timeStamp) if (m_reset_last) { m_last_emitter = m_last_last_emitter = QPointF(x(), y()); - m_last_timestamp = timeStamp/1000.; + if (m_last_timestamp == -1) + m_last_timestamp = timeStamp/1000. - m_startTime; + else + m_last_timestamp = timeStamp/1000.; m_last_emission = m_last_timestamp; m_reset_last = false; } @@ -339,7 +360,7 @@ void QSGParticleEmitter::emitWindow(int timeStamp) pt = time; while (pt < time || !m_burstQueue.isEmpty()) { //int pos = m_last_particle % m_particle_count; - QSGParticleData* datum = m_system->newDatum(m_system->m_groupIds[m_particle]); + QSGParticleData* datum = m_system->newDatum(m_system->m_groupIds[m_particle], !m_overwrite); if (datum){//actually emit(otherwise we've been asked to skip this one) datum->e = this;//###useful? qreal t = 1 - (pt - opt) / dt; diff --git a/src/declarative/particles/qsgparticleemitter_p.h b/src/declarative/particles/qsgparticleemitter_p.h index 0b0fe91..d3c9327 100644 --- a/src/declarative/particles/qsgparticleemitter_p.h +++ b/src/declarative/particles/qsgparticleemitter_p.h @@ -64,6 +64,8 @@ class QSGParticleEmitter : public QSGItem Q_PROPERTY(QString particle READ particle WRITE setParticle NOTIFY particleChanged) Q_PROPERTY(QSGParticleExtruder* shape READ extruder WRITE setExtruder NOTIFY extruderChanged) Q_PROPERTY(bool emitting READ emitting WRITE setEmitting NOTIFY emittingChanged) + Q_PROPERTY(int startTime READ startTime WRITE setStartTime NOTIFY startTimeChanged) + Q_PROPERTY(bool noCap READ overwrite WRITE setOverWrite NOTIFY overwriteChanged) Q_PROPERTY(qreal emitRate READ particlesPerSecond WRITE setParticlesPerSecond NOTIFY particlesPerSecondChanged) Q_PROPERTY(int lifeSpan READ particleDuration WRITE setParticleDuration NOTIFY particleDurationChanged) @@ -144,6 +146,10 @@ signals: void speedFromMovementChanged(); + void startTimeChanged(int arg); + + void overwriteChanged(bool arg); + public slots: void pulse(qreal seconds); void burst(int num); @@ -241,6 +247,22 @@ public slots: void setMaxParticleCount(int arg); + void setStartTime(int arg) + { + if (m_startTime != arg) { + m_startTime = arg; + emit startTimeChanged(arg); + } + } + + void setOverWrite(bool arg) +{ + if (m_overwrite != arg) { + m_overwrite = arg; +emit overwriteChanged(arg); +} +} + public: int particleCount() const; @@ -280,6 +302,16 @@ public: return m_maxParticleCount; } + int startTime() const + { + return m_startTime; + } + + bool overwrite() const + { + return m_overwrite; + } + protected: qreal m_particlesPerSecond; int m_particleDuration; @@ -296,6 +328,10 @@ protected: qreal m_particleEndSize; qreal m_particleSizeVariation; + qreal m_speedFromMovement; + int m_startTime; + bool m_overwrite; + int m_burstLeft;//TODO: Rename to pulse QList > m_burstQueue; int m_maxParticleCount; @@ -314,7 +350,7 @@ protected: private: QSGStochasticDirection m_nullVector; - qreal m_speedFromMovement; + }; QT_END_NAMESPACE