From: Alan Alpert Date: Tue, 11 Oct 2011 04:16:33 +0000 (+1000) Subject: Allow sizing of TrailEmitter emit area based on particle size X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=576e7ae3360632a981177800e758679ee4105950;p=konrad%2Fqtdeclarative.git Allow sizing of TrailEmitter emit area based on particle size Change-Id: I7ce2ba29459b9a66e62933f9bfb9e066baedaaef Reviewed-by: Martin Jones --- diff --git a/examples/declarative/particles/emitters/trailemitter.qml b/examples/declarative/particles/emitters/trailemitter.qml index e246b66..841c6c9 100644 --- a/examples/declarative/particles/emitters/trailemitter.qml +++ b/examples/declarative/particles/emitters/trailemitter.qml @@ -117,8 +117,9 @@ Rectangle { emitRatePerParticle: 120 lifeSpan: 180 - emitWidth: 8 - emitHeight: 8 + emitWidth: TrailEmitter.ParticleSize + emitHeight: TrailEmitter.ParticleSize + emitShape: EllipseShape{} size: 16 sizeVariation: 4 @@ -134,8 +135,9 @@ Rectangle { emitRatePerParticle: 128 lifeSpan: 2400 - emitWidth: 16 - emitHeight: 16 + emitWidth: TrailEmitter.ParticleSize + emitHeight: TrailEmitter.ParticleSize + emitShape: EllipseShape{} speed: PointDirection {yVariation: 16; xVariation: 16} acceleration: PointDirection {y: -16} @@ -159,7 +161,7 @@ Rectangle { speed: PointDirection {y:-17*4*2; xVariation: 6*6} acceleration: PointDirection {y: 17*2; xVariation: 6*6} - size: 12 + size: 8 sizeVariation: 4 } diff --git a/src/declarative/particles/qsgtrailemitter.cpp b/src/declarative/particles/qsgtrailemitter.cpp index 9fbd13b..4298908 100644 --- a/src/declarative/particles/qsgtrailemitter.cpp +++ b/src/declarative/particles/qsgtrailemitter.cpp @@ -91,13 +91,26 @@ QSGTrailEmitter::QSGTrailEmitter(QSGItem *parent) : \qmlproperty Shape QtQuick.Particles2::TrailEmitter::emitShape As the area of a TrailEmitter is the area it follows, a separate shape can be provided - to be the shape it emits out of. + to be the shape it emits out of. This shape has width and height specified by emitWidth + and emitHeight, and is centered on the followed particle's position. + + The default shape is a filled Rectangle. */ /*! \qmlproperty real QtQuick.Particles2::TrailEmitter::emitWidth + + The width in pixels the emitShape is scaled to. If set to TrailEmitter.ParticleSize, + the width will be the current size of the particle being followed. + + Default is 0. */ /*! \qmlproperty real QtQuick.Particles2::TrailEmitter::emitHeight + + The height in pixels the emitShape is scaled to. If set to TrailEmitter.ParticleSize, + the height will be the current size of the particle being followed. + + Default is 0. */ /*! \qmlproperty real QtQuick.Particles2::TrailEmitter::emitRatePerParticle @@ -202,17 +215,12 @@ void QSGTrailEmitter::emitWindow(int timeStamp) // Note that burst location doesn't get used for follow emitter qreal followT = pt - d->t; qreal followT2 = followT * followT * 0.5; - //qreal sizeOffset = d->size/2;//TODO: Current size? As an option - //TODO: Set variations + qreal eW = m_emitterXVariation < 0 ? d->curSize() : m_emitterXVariation; + qreal eH = m_emitterYVariation < 0 ? d->curSize() : m_emitterYVariation; //Subtract offset, because PS expects this in emitter coordinates - QRectF boundsRect(d->x - offset.x() + d->vx * followT + d->ax * followT2 - m_emitterXVariation/2, - d->y - offset.y() + d->vy * followT + d->ay * followT2 - m_emitterYVariation/2, - m_emitterXVariation, - m_emitterYVariation); - // QRectF boundsRect(d->x + d->vx * followT + d->ax * followT2 + offset.x() - sizeOffset, - // d->y + d->vy * followT + d->ay * followT2 + offset.y() - sizeOffset, - // sizeOffset*2, - // sizeOffset*2); + QRectF boundsRect(d->x - offset.x() + d->vx * followT + d->ax * followT2 - eW/2, + d->y - offset.y() + d->vy * followT + d->ay * followT2 - eH/2, + eW, eH); QSGParticleExtruder* effectiveEmissionExtruder = m_emissionExtruder ? m_emissionExtruder : m_defaultEmissionExtruder; const QPointF &newPos = effectiveEmissionExtruder->extrude(boundsRect); diff --git a/src/declarative/particles/qsgtrailemitter_p.h b/src/declarative/particles/qsgtrailemitter_p.h index e0103af..255dd85 100644 --- a/src/declarative/particles/qsgtrailemitter_p.h +++ b/src/declarative/particles/qsgtrailemitter_p.h @@ -57,13 +57,15 @@ class QSGTrailEmitter : public QSGParticleEmitter Q_PROPERTY(QString follow READ follow WRITE setFollow NOTIFY followChanged) Q_PROPERTY(int emitRatePerParticle READ particlesPerParticlePerSecond WRITE setParticlesPerParticlePerSecond NOTIFY particlesPerParticlePerSecondChanged) - //TODO: Document that TrailEmitter's box is where it follows. It emits in a rect centered on the followed particle - //TODO: A set of properties that can involve the particle size of the followed Q_PROPERTY(QSGParticleExtruder* emitShape READ emissonShape WRITE setEmissionShape NOTIFY emissionShapeChanged) Q_PROPERTY(qreal emitHeight READ emitterYVariation WRITE setEmitterYVariation NOTIFY emitterYVariationChanged) Q_PROPERTY(qreal emitWidth READ emitterXVariation WRITE setEmitterXVariation NOTIFY emitterXVariationChanged) + Q_ENUMS(EmitSize) public: + enum EmitSize { + ParticleSize = -2//Anything less than 0 will do + }; explicit QSGTrailEmitter(QSGItem *parent = 0); virtual void emitWindow(int timeStamp); virtual void reset();