aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAlan Alpert <alan.alpert@nokia.com>2011-10-04 14:39:21 +1000
committerQt by Nokia <qt-info@nokia.com>2011-10-05 07:33:29 +0200
commite225ee5a6a50400fc02536e511b1e10f3d53f110 (patch)
treec58033dd8fc3032838952ed8e592c5bec500bce8 /src
parenta274134dc511263a3ccd086205829e911ecd3aae (diff)
Split GroupGoal out of SpriteGoal
Leaving SpriteGoal alone for a few weeks with a deprecation message, but a functioning GroupGoal has been added. Change-Id: I395046c00526e7caa38bdbc499a8191308c476fa Reviewed-on: http://codereview.qt-project.org/5950 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Martin Jones <martin.jones@nokia.com>
Diffstat (limited to 'src')
-rw-r--r--src/declarative/items/qsgspriteengine_p.h4
-rw-r--r--src/declarative/particles/particles.pri6
-rw-r--r--src/declarative/particles/qsggroupgoal.cpp111
-rw-r--r--src/declarative/particles/qsggroupgoal_p.h102
-rw-r--r--src/declarative/particles/qsgparticlesmodule.cpp2
-rw-r--r--src/declarative/particles/qsgspritegoal.cpp18
-rw-r--r--src/declarative/particles/qsgspritegoal_p.h4
7 files changed, 240 insertions, 7 deletions
diff --git a/src/declarative/items/qsgspriteengine_p.h b/src/declarative/items/qsgspriteengine_p.h
index b2a06f2c87..0561849da8 100644
--- a/src/declarative/items/qsgspriteengine_p.h
+++ b/src/declarative/items/qsgspriteengine_p.h
@@ -58,7 +58,7 @@ QT_BEGIN_NAMESPACE
QT_MODULE(Declarative)
class QSGSprite;
-class QSGStochasticState : public QObject //For internal use
+class Q_AUTOTEST_EXPORT QSGStochasticState : public QObject //For internal use
{
Q_OBJECT
Q_PROPERTY(int duration READ duration WRITE setDuration NOTIFY durationChanged)
@@ -188,7 +188,7 @@ private:
friend class QSGStochasticEngine;
};
-class QSGStochasticEngine : public QObject
+class Q_AUTOTEST_EXPORT QSGStochasticEngine : public QObject
{
Q_OBJECT
//TODO: Optimize single state case?
diff --git a/src/declarative/particles/particles.pri b/src/declarative/particles/particles.pri
index 8676e52172..bfe1062338 100644
--- a/src/declarative/particles/particles.pri
+++ b/src/declarative/particles/particles.pri
@@ -30,7 +30,8 @@ HEADERS += \
$$PWD/qsgcumulativedirection_p.h \
$$PWD/qsgv8particledata_p.h \
$$PWD/qsgrectangleextruder_p.h \
- $$PWD/qsgparticlegroup_p.h
+ $$PWD/qsgparticlegroup_p.h \
+ $$PWD/qsggroupgoal_p.h
SOURCES += \
$$PWD/qsgangledirection.cpp \
@@ -62,7 +63,8 @@ SOURCES += \
$$PWD/qsgcumulativedirection.cpp \
$$PWD/qsgv8particledata.cpp \
$$PWD/qsgrectangleextruder.cpp \
- $$PWD/qsgparticlegroup.cpp
+ $$PWD/qsgparticlegroup.cpp \
+ $$PWD/qsggroupgoal.cpp
RESOURCES += \
$$PWD/particles.qrc
diff --git a/src/declarative/particles/qsggroupgoal.cpp b/src/declarative/particles/qsggroupgoal.cpp
new file mode 100644
index 0000000000..7f0b938987
--- /dev/null
+++ b/src/declarative/particles/qsggroupgoal.cpp
@@ -0,0 +1,111 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Declarative module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qsggroupgoal_p.h"
+#include "private/qsgspriteengine_p.h"
+#include "private/qsgsprite_p.h"
+#include "qsgimageparticle_p.h"
+#include <QDebug>
+
+QT_BEGIN_NAMESPACE
+
+/*!
+ \qmlclass GroupGoal QSGGroupGoalAffector
+ \inqmlmodule QtQuick.Particles 2
+ \inherits Affector
+ \brief The GroupGoal Affector allows you to change the state of a group of a particle.
+
+*/
+/*!
+ \qmlproperty string QtQuick.Particles2::GroupGoal::goalState
+
+ The name of the group which the affected particles should move to.
+
+ Groups can have defined durations and transitions between them, setting goalState
+ will cause it to disregard any path weightings (including 0) and head down the path
+ which will reach the goalState quickest. It will pass through intermediate groups
+ on that path for their respective durations.
+*/
+/*!
+ \qmlproperty bool QtQuick.Particles2::GroupGoal::jump
+
+ If true, affected particles will jump directly to the target group instead of taking the
+ the shortest valid path to get there. They will also not finish their current state,
+ but immediately move to the beginning of the goal state.
+
+ Default is false.
+*/
+
+QSGGroupGoalAffector::QSGGroupGoalAffector(QSGItem *parent) :
+ QSGParticleAffector(parent), m_jump(false)
+{
+}
+
+void QSGGroupGoalAffector::setGoalState(QString arg)
+{
+ if (m_goalState != arg) {
+ m_goalState = arg;
+ emit goalStateChanged(arg);
+ }
+}
+
+bool QSGGroupGoalAffector::affectParticle(QSGParticleData *d, qreal dt)
+{
+ Q_UNUSED(dt);
+ QSGStochasticEngine *engine = m_system->stateEngine;
+ bool notUsingEngine = false;
+ if (!engine)
+ notUsingEngine = true;
+
+ int index = d->systemIndex;
+ int goalIdx = m_system->groupIds[m_goalState];
+ if (notUsingEngine){//no stochastic states defined. So cut out the engine
+ //TODO: It's possible to move to a group that is intermediate and not used by painters or emitters - but right now that will redirect to the default group
+ m_system->moveGroups(d, goalIdx);
+ return true;
+ }else if (engine->curState(index) != goalIdx){
+ engine->setGoal(goalIdx, index, m_jump);
+ return true;
+ }
+ return false;
+}
+
+QT_END_NAMESPACE
diff --git a/src/declarative/particles/qsggroupgoal_p.h b/src/declarative/particles/qsggroupgoal_p.h
new file mode 100644
index 0000000000..6357c3f13a
--- /dev/null
+++ b/src/declarative/particles/qsggroupgoal_p.h
@@ -0,0 +1,102 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the Declarative module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef GROUPGOALAFFECTOR_H
+#define GROUPGOALAFFECTOR_H
+#include "qsgparticleaffector_p.h"
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+QT_MODULE(Declarative)
+
+class QSGStochasticEngine;
+
+class QSGGroupGoalAffector : public QSGParticleAffector
+{
+ Q_OBJECT
+ Q_PROPERTY(QString goalState READ goalState WRITE setGoalState NOTIFY goalStateChanged)
+ Q_PROPERTY(bool jump READ jump WRITE setJump NOTIFY jumpChanged)
+public:
+ explicit QSGGroupGoalAffector(QSGItem *parent = 0);
+
+ QString goalState() const
+ {
+ return m_goalState;
+ }
+
+ bool jump() const
+ {
+ return m_jump;
+ }
+
+protected:
+ virtual bool affectParticle(QSGParticleData *d, qreal dt);
+
+signals:
+
+ void goalStateChanged(QString arg);
+
+ void jumpChanged(bool arg);
+
+public slots:
+
+ void setGoalState(QString arg);
+
+ void setJump(bool arg)
+ {
+ if (m_jump != arg) {
+ m_jump = arg;
+ emit jumpChanged(arg);
+ }
+ }
+
+private:
+ QString m_goalState;
+ bool m_jump;
+};
+
+QT_END_NAMESPACE
+
+QT_END_HEADER
+
+#endif // GROUPGOALAFFECTOR_H
diff --git a/src/declarative/particles/qsgparticlesmodule.cpp b/src/declarative/particles/qsgparticlesmodule.cpp
index 362a361c66..e5b5680435 100644
--- a/src/declarative/particles/qsgparticlesmodule.cpp
+++ b/src/declarative/particles/qsgparticlesmodule.cpp
@@ -68,6 +68,7 @@
#include "qsgcustomaffector_p.h"
#include "qsgrectangleextruder_p.h"
#include "qsgparticlegroup_p.h"
+#include "qsggroupgoal_p.h"
QT_BEGIN_NAMESPACE
@@ -102,6 +103,7 @@ void QSGParticlesModule::defineModule()
qmlRegisterType<QSGGravityAffector>(uri, 2, 0, "Gravity");
qmlRegisterType<QSGAgeAffector>(uri, 2, 0, "Age");
qmlRegisterType<QSGSpriteGoalAffector>(uri, 2, 0, "SpriteGoal");
+ qmlRegisterType<QSGGroupGoalAffector>(uri, 2, 0, "GroupGoal");
qmlRegisterType<QSGTurbulenceAffector>(uri, 2, 0 , "Turbulence");
qmlRegisterType<QSGTargetAffector>(uri, 2, 0 , "Target");
diff --git a/src/declarative/particles/qsgspritegoal.cpp b/src/declarative/particles/qsgspritegoal.cpp
index fd919e8aaf..1e8feec672 100644
--- a/src/declarative/particles/qsgspritegoal.cpp
+++ b/src/declarative/particles/qsgspritegoal.cpp
@@ -51,17 +51,32 @@ QT_BEGIN_NAMESPACE
\qmlclass SpriteGoal QSGSpriteGoalAffector
\inqmlmodule QtQuick.Particles 2
\inherits Affector
- \brief The SpriteGoal Affector allows you to change the state of a sprite or group of a particle.
+ \brief The SpriteGoal Affector allows you to change the state of a sprite particle.
*/
/*!
\qmlproperty string QtQuick.Particles2::SpriteGoal::goalState
+
+ The name of the Sprite which the affected particles should move to.
+
+ Sprite states have defined durations and transitions between them, setting goalState
+ will cause it to disregard any path weightings (including 0) and head down the path
+ which will reach the goalState quickest. It will pass through intermediate states
+ on that path.
*/
/*!
\qmlproperty bool QtQuick.Particles2::SpriteGoal::jump
+
+ If true, affected sprites will jump directly to the goal state instead of taking the
+ the shortest valid path to get there. They will also not finish their current state,
+ but immediately move to the beginning of the goal state.
+
+ Default is false.
*/
/*!
\qmlproperty bool QtQuick.Particles2::SpriteGoal::systemStates
+
+ deprecated, use GroupGoal instead
*/
QSGSpriteGoalAffector::QSGSpriteGoalAffector(QSGItem *parent) :
@@ -124,7 +139,6 @@ bool QSGSpriteGoalAffector::affectParticle(QSGParticleData *d, qreal dt)
m_system->moveGroups(d, m_goalIdx);
}else if (engine->curState(index) != m_goalIdx){
engine->setGoal(m_goalIdx, index, m_jump);
- emit affected(QPointF(d->curX(), d->curY()));//###Expensive if unconnected? Move to Affector?
return true; //Doesn't affect particle data, but necessary for onceOff
}
return false;
diff --git a/src/declarative/particles/qsgspritegoal_p.h b/src/declarative/particles/qsgspritegoal_p.h
index 043970b90b..7f20b1ed8a 100644
--- a/src/declarative/particles/qsgspritegoal_p.h
+++ b/src/declarative/particles/qsgspritegoal_p.h
@@ -42,6 +42,7 @@
#ifndef SPRITEGOALAFFECTOR_H
#define SPRITEGOALAFFECTOR_H
#include "qsgparticleaffector_p.h"
+#include <QtDeclarative/qdeclarativeinfo.h>
QT_BEGIN_HEADER
@@ -82,7 +83,6 @@ signals:
void jumpChanged(bool arg);
- void affected(const QPointF &pos);
void systemStatesChanged(bool arg);
public slots:
@@ -100,6 +100,8 @@ void setJump(bool arg)
void setSystemStates(bool arg)
{
if (m_systemStates != arg) {
+ //TODO: GroupGoal was added (and this deprecated) Oct 4 - remove it in a few weeks.
+ qmlInfo(this) << "systemStates is deprecated and will be removed soon. Use GroupGoal instead.";
m_systemStates = arg;
emit systemStatesChanged(arg);
}