aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAlan Alpert <alan.alpert@nokia.com>2011-09-20 12:56:12 +1000
committerQt by Nokia <qt-info@nokia.com>2011-09-20 07:22:35 +0200
commit014fd8c01f305f05eafcee5a7789d6bf74048974 (patch)
tree3c89bebff0aeac0b37135d0a0a37be9c994e2beb /src
parent466f6fc395dc49370dba0f60c8289a57cbc86aa5 (diff)
More ImageParticle sharing
Basic implementation of explicitAnimation, and RESET methods/docs added Change-Id: Ic522153b5287a97ba35e931cc6bddcde5d139fe7 Reviewed-on: http://codereview.qt-project.org/5182 Reviewed-by: Martin Jones <martin.jones@nokia.com>
Diffstat (limited to 'src')
-rw-r--r--src/declarative/particles/qsgimageparticle.cpp82
-rw-r--r--src/declarative/particles/qsgimageparticle_p.h35
2 files changed, 88 insertions, 29 deletions
diff --git a/src/declarative/particles/qsgimageparticle.cpp b/src/declarative/particles/qsgimageparticle.cpp
index a4b1b4750d..d21f5f03c4 100644
--- a/src/declarative/particles/qsgimageparticle.cpp
+++ b/src/declarative/particles/qsgimageparticle.cpp
@@ -460,6 +460,12 @@ void fillUniformArrayFromImage(float* array, const QImage& img, int size)
aspect automatically. This is primarily useful when there is some random variation on
the particle which is supposed to stay with it when switching painters. If both ImageParticles
define how they should appear for that aspect, they diverge and each appears as it is defined.
+
+ This sharing of data happens behind the scenes based off of whether properties were implicitly or explicitly
+ set. One drawback of the current implementation is that it is only possible to reset the capabilities as a whole.
+ So if you explicity set an attribute affecting color, such as redVariation, and then reset it (by setting redVariation
+ to undefined), all color data will be reset and it will begin to have an implicit value of any shared color from
+ other ImageParticles.
*/
/*!
\qmlproperty url QtQuick.Particles2::ImageParticle::source
@@ -638,10 +644,10 @@ QSGImageParticle::QSGImageParticle(QSGItem* parent)
, m_greenVariation(0.0)
, m_blueVariation(0.0)
, m_rotation(0)
- , m_autoRotation(false)
, m_rotationVariation(0)
, m_rotationSpeed(0)
, m_rotationSpeedVariation(0)
+ , m_autoRotation(false)
, m_xVector(0)
, m_yVector(0)
, m_spriteEngine(0)
@@ -880,6 +886,51 @@ void QSGImageParticle::setEntryEffect(EntryEffect arg)
}
}
+void QSGImageParticle::resetColor()
+{
+ m_explicitColor = false;
+ foreach (const QString &str, m_groups)
+ foreach (QSGParticleData* d, m_system->m_groupData[m_system->m_groupIds[str]]->data)
+ if (d->colorOwner == this)
+ d->colorOwner = 0;
+ m_color = QColor();
+ m_color_variation = 0.0f;
+ m_redVariation = 0.0f;
+ m_blueVariation = 0.0f;
+ m_greenVariation = 0.0f;
+ m_alpha = 1.0f;
+ m_alphaVariation = 0.0f;
+}
+
+void QSGImageParticle::resetRotation()
+{
+ m_explicitRotation = false;
+ foreach (const QString &str, m_groups)
+ foreach (QSGParticleData* d, m_system->m_groupData[m_system->m_groupIds[str]]->data)
+ if (d->rotationOwner == this)
+ d->rotationOwner = 0;
+ m_rotation = 0;
+ m_rotationVariation = 0;
+ m_rotationSpeed = 0;
+ m_rotationSpeedVariation = 0;
+ m_autoRotation = false;
+}
+
+void QSGImageParticle::resetDeformation()
+{
+ m_explicitDeformation = false;
+ foreach (const QString &str, m_groups)
+ foreach (QSGParticleData* d, m_system->m_groupData[m_system->m_groupIds[str]]->data)
+ if (d->deformationOwner == this)
+ d->deformationOwner = 0;
+ if (m_xVector)
+ delete m_xVector;
+ if (m_yVector)
+ delete m_yVector;
+ m_xVector = 0;
+ m_yVector = 0;
+}
+
void QSGImageParticle::reset()
{
QSGParticlePainter::reset();
@@ -1273,15 +1324,20 @@ void QSGImageParticle::initialize(int gIdx, int pIdx)
switch (perfLevel){//Fall-through is intended on all of them
case Sprites:
// Initial Sprite State
- datum->animT = datum->t;
- datum->animIdx = 0;
- if (m_spriteEngine){
- m_spriteEngine->start(spriteIdx);
- datum->frameCount = m_spriteEngine->spriteFrames(spriteIdx);
- datum->frameDuration = m_spriteEngine->spriteDuration(spriteIdx);
- }else{
- datum->frameCount = 1;
- datum->frameDuration = 9999;
+ if (m_explicitAnimation){
+ if (!datum->animationOwner)
+ datum->animationOwner = this;
+ QSGParticleData* writeTo = (datum->animationOwner == this ? datum : getShadowDatum(datum));
+ writeTo->animT = writeTo->t;
+ writeTo->animIdx = 0;
+ if (m_spriteEngine){
+ m_spriteEngine->start(spriteIdx);
+ writeTo->frameCount = m_spriteEngine->spriteFrames(spriteIdx);
+ writeTo->frameDuration = m_spriteEngine->spriteDuration(spriteIdx);
+ }else{
+ writeTo->frameCount = 1;
+ writeTo->frameDuration = 9999;
+ }
}
case Tabled:
case Deformable:
@@ -1393,7 +1449,7 @@ void QSGImageParticle::commit(int gIdx, int pIdx)
spriteVertices[i].rotation = shadow->rotation;
spriteVertices[i].rotationSpeed = shadow->rotationSpeed;
spriteVertices[i].autoRotate = shadow->autoRotate;
- } else {
+ } else {
spriteVertices[i].rotation = datum->rotation;
spriteVertices[i].rotationSpeed = datum->rotationSpeed;
spriteVertices[i].autoRotate = datum->autoRotate;
@@ -1404,7 +1460,7 @@ void QSGImageParticle::commit(int gIdx, int pIdx)
spriteVertices[i].frameDuration = shadow->frameDuration;
spriteVertices[i].frameCount = shadow->frameCount;
spriteVertices[i].animT = shadow->animT;
- } else {
+ } else {
spriteVertices[i].animIdx = datum->animIdx;
spriteVertices[i].frameDuration = datum->frameDuration;
spriteVertices[i].frameCount = datum->frameCount;
@@ -1416,7 +1472,7 @@ void QSGImageParticle::commit(int gIdx, int pIdx)
spriteVertices[i].color.g = shadow->color.g;
spriteVertices[i].color.b = shadow->color.b;
spriteVertices[i].color.a = shadow->color.a;
- } else {
+ } else {
spriteVertices[i].color.r = datum->color.r;
spriteVertices[i].color.g = datum->color.g;
spriteVertices[i].color.b = datum->color.b;
diff --git a/src/declarative/particles/qsgimageparticle_p.h b/src/declarative/particles/qsgimageparticle_p.h
index 4225829fb5..ccf5cf7702 100644
--- a/src/declarative/particles/qsgimageparticle_p.h
+++ b/src/declarative/particles/qsgimageparticle_p.h
@@ -153,29 +153,29 @@ class QSGImageParticle : public QSGParticlePainter
Q_PROPERTY(QUrl opacityTable READ opacitytable WRITE setOpacitytable NOTIFY opacitytableChanged)
//###Now just colorize - add a flag for 'solid' color particles(where the img is just a mask?)?
- Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
+ Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged RESET resetColor)
//Stacks (added) with individual colorVariations
- Q_PROPERTY(qreal colorVariation READ colorVariation WRITE setColorVariation NOTIFY colorVariationChanged)
- Q_PROPERTY(qreal redVariation READ redVariation WRITE setRedVariation NOTIFY redVariationChanged)
- Q_PROPERTY(qreal greenVariation READ greenVariation WRITE setGreenVariation NOTIFY greenVariationChanged)
- Q_PROPERTY(qreal blueVariation READ blueVariation WRITE setBlueVariation NOTIFY blueVariationChanged)
+ Q_PROPERTY(qreal colorVariation READ colorVariation WRITE setColorVariation NOTIFY colorVariationChanged RESET resetColor)
+ Q_PROPERTY(qreal redVariation READ redVariation WRITE setRedVariation NOTIFY redVariationChanged RESET resetColor)
+ Q_PROPERTY(qreal greenVariation READ greenVariation WRITE setGreenVariation NOTIFY greenVariationChanged RESET resetColor)
+ Q_PROPERTY(qreal blueVariation READ blueVariation WRITE setBlueVariation NOTIFY blueVariationChanged RESET resetColor)
//Stacks (multiplies) with the Alpha in the color, mostly here so you can use svg color names (which have full alpha)
- Q_PROPERTY(qreal alpha READ alpha WRITE setAlpha NOTIFY alphaChanged)
- Q_PROPERTY(qreal alphaVariation READ alphaVariation WRITE setAlphaVariation NOTIFY alphaVariationChanged)
+ Q_PROPERTY(qreal alpha READ alpha WRITE setAlpha NOTIFY alphaChanged RESET resetColor)
+ Q_PROPERTY(qreal alphaVariation READ alphaVariation WRITE setAlphaVariation NOTIFY alphaVariationChanged RESET resetColor)
- Q_PROPERTY(qreal rotation READ rotation WRITE setRotation NOTIFY rotationChanged)
- Q_PROPERTY(qreal rotationVariation READ rotationVariation WRITE setRotationVariation NOTIFY rotationVariationChanged)
- Q_PROPERTY(qreal rotationSpeed READ rotationSpeed WRITE setRotationSpeed NOTIFY rotationSpeedChanged)
- Q_PROPERTY(qreal rotationSpeedVariation READ rotationSpeedVariation WRITE setRotationSpeedVariation NOTIFY rotationSpeedVariationChanged)
+ Q_PROPERTY(qreal rotation READ rotation WRITE setRotation NOTIFY rotationChanged RESET resetRotation)
+ Q_PROPERTY(qreal rotationVariation READ rotationVariation WRITE setRotationVariation NOTIFY rotationVariationChanged RESET resetRotation)
+ Q_PROPERTY(qreal rotationSpeed READ rotationSpeed WRITE setRotationSpeed NOTIFY rotationSpeedChanged RESET resetRotation)
+ Q_PROPERTY(qreal rotationSpeedVariation READ rotationSpeedVariation WRITE setRotationSpeedVariation NOTIFY rotationSpeedVariationChanged RESET resetRotation)
//If true, then will face the direction of motion. Stacks with rotation, e.g. setting rotation
//to 180 will lead to facing away from the direction of motion
- Q_PROPERTY(bool autoRotation READ autoRotation WRITE setAutoRotation NOTIFY autoRotationChanged)
+ Q_PROPERTY(bool autoRotation READ autoRotation WRITE setAutoRotation NOTIFY autoRotationChanged RESET resetRotation)
//###Call i/j? Makes more sense to those with vector calculus experience, and I could even add the cirumflex in QML?
//xVector is the vector from the top-left point to the top-right point, and is multiplied by current size
- Q_PROPERTY(QSGDirection* xVector READ xVector WRITE setXVector NOTIFY xVectorChanged)
+ Q_PROPERTY(QSGDirection* xVector READ xVector WRITE setXVector NOTIFY xVectorChanged RESET resetDeformation)
//yVector is the same, but top-left to bottom-left. The particle is always a parallelogram.
- Q_PROPERTY(QSGDirection* yVector READ yVector WRITE setYVector NOTIFY yVectorChanged)
+ Q_PROPERTY(QSGDirection* yVector READ yVector WRITE setYVector NOTIFY yVectorChanged RESET resetDeformation)
Q_PROPERTY(QDeclarativeListProperty<QSGSprite> sprites READ sprites)
Q_PROPERTY(EntryEffect entryEffect READ entryEffect WRITE setEntryEffect NOTIFY entryEffectChanged)
@@ -252,6 +252,10 @@ public:
EntryEffect entryEffect() const { return m_entryEffect; }
+ void resetColor();
+ void resetRotation();
+ void resetDeformation();
+
signals:
void imageChanged();
@@ -371,11 +375,10 @@ private:
QList<QSGSprite*> m_sprites;
QSGSpriteEngine* m_spriteEngine;
- //TODO: Reset methods
bool m_explicitColor;
bool m_explicitRotation;
bool m_explicitDeformation;
- bool m_explicitAnimation;//TODO: Implement this
+ bool m_explicitAnimation;
QHash<int, QVector<QSGParticleData*> > m_shadowData;
bool m_shadowInit;
void clearShadows();