1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the Declarative module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** No Commercial Usage
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU Lesser
18 ** General Public License version 2.1 as published by the Free Software
19 ** Foundation and appearing in the file LICENSE.LGPL included in the
20 ** packaging of this file. Please review the following information to
21 ** ensure the GNU Lesser General Public License version 2.1 requirements
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 ** In addition, as a special exception, Nokia gives you certain additional
25 ** rights. These rights are described in the Nokia Qt LGPL Exception
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
40 ****************************************************************************/
42 #ifndef ULTRAPARTICLE_H
43 #define ULTRAPARTICLE_H
45 #include "varyingvector.h"
46 #include <QDeclarativeListProperty>
48 #include "coloredparticle.h"
54 QT_MODULE(Declarative)
57 class QSGGeometryNode;
62 /*struct Color4ub {//in coloredparticle
84 struct SimpleVertices {
111 float autoRotate;//Assume that GPUs prefer floats to bools
118 struct UltraVertices {
125 struct IntermediateVertices {
132 class UltraParticle : public ParticleType
135 Q_PROPERTY(QUrl image READ image WRITE setImage NOTIFY imageChanged)
136 Q_PROPERTY(QUrl colorTable READ colortable WRITE setColortable NOTIFY colortableChanged)
137 Q_PROPERTY(QUrl sizeTable READ sizetable WRITE setSizetable NOTIFY sizetableChanged)
138 Q_PROPERTY(QUrl opacityTable READ opacitytable WRITE setOpacitytable NOTIFY opacitytableChanged)
140 //###Now just colorize - add a flag for 'solid' color particles(where the img is just a mask?)?
141 Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
142 //Stacks (added) with individual colorVariations
143 Q_PROPERTY(qreal colorVariation READ colorVariation WRITE setColorVariation NOTIFY colorVariationChanged)
144 Q_PROPERTY(qreal redVariation READ redVariation WRITE setRedVariation NOTIFY redVariationChanged)
145 Q_PROPERTY(qreal greenVariation READ greenVariation WRITE setGreenVariation NOTIFY greenVariationChanged)
146 Q_PROPERTY(qreal blueVariation READ blueVariation WRITE setBlueVariation NOTIFY blueVariationChanged)
147 //Stacks (multiplies) with the Alpha in the color, mostly here so you can use svg color names (which have full alpha)
148 Q_PROPERTY(qreal alpha READ alpha WRITE setAlpha NOTIFY alphaChanged)
149 Q_PROPERTY(qreal alphaVariation READ alphaVariation WRITE setAlphaVariation NOTIFY alphaVariationChanged)
151 Q_PROPERTY(qreal rotation READ rotation WRITE setRotation NOTIFY rotationChanged)
152 Q_PROPERTY(qreal rotationVariation READ rotationVariation WRITE setRotationVariation NOTIFY rotationVariationChanged)
153 Q_PROPERTY(qreal rotationSpeed READ rotationSpeed WRITE setRotationSpeed NOTIFY rotationSpeedChanged)
154 Q_PROPERTY(qreal rotationSpeedVariation READ rotationSpeedVariation WRITE setRotationSpeedVariation NOTIFY rotationSpeedVariationChanged)
155 //If true, then will face the direction of motion. Stacks with rotation, e.g. setting rotation
156 //to 180 will lead to facing away from the direction of motion
157 Q_PROPERTY(bool autoRotation READ autoRotation WRITE autoRotation NOTIFY autoRotationChanged)
159 //###Call i/j? Makes more sense to those with vector calculus experience, and I could even add the cirumflex in QML?
160 //xVector is the vector from the top-left point to the top-right point, and is multiplied by current size
161 Q_PROPERTY(VaryingVector* xVector READ xVector WRITE setXVector NOTIFY xVectorChanged)
162 //yVector is the same, but top-left to bottom-left. The particle is always a parallelogram.
163 Q_PROPERTY(VaryingVector* yVector READ yVector WRITE setYVector NOTIFY yVectorChanged)
164 Q_PROPERTY(QDeclarativeListProperty<SpriteState> sprites READ sprites)
165 Q_PROPERTY(bool bloat READ bloat WRITE setBloat NOTIFY bloatChanged)//Just a debugging property to bypass optimizations
167 explicit UltraParticle(QSGItem *parent = 0);
168 virtual ~UltraParticle(){}
170 virtual void load(ParticleData*);
171 virtual void reload(ParticleData*);
172 virtual void setCount(int c);
174 QDeclarativeListProperty<SpriteState> sprites();
175 SpriteEngine* spriteEngine() {return m_spriteEngine;}
177 enum PerformanceLevel{//TODO: Expose?
186 QUrl image() const { return m_image_name; }
187 void setImage(const QUrl &image);
189 QUrl colortable() const { return m_colortable_name; }
190 void setColortable(const QUrl &table);
192 QUrl sizetable() const { return m_sizetable_name; }
193 void setSizetable (const QUrl &table);
195 QUrl opacitytable() const { return m_opacitytable_name; }
196 void setOpacitytable(const QUrl &table);
198 QColor color() const { return m_color; }
199 void setColor(const QColor &color);
201 qreal colorVariation() const { return m_color_variation; }
202 void setColorVariation(qreal var);
204 qreal renderOpacity() const { return m_render_opacity; }
206 qreal alphaVariation() const
208 return m_alphaVariation;
216 qreal redVariation() const
218 return m_redVariation;
221 qreal greenVariation() const
223 return m_greenVariation;
226 qreal blueVariation() const
228 return m_blueVariation;
231 qreal rotation() const
236 qreal rotationVariation() const
238 return m_rotationVariation;
241 qreal rotationSpeed() const
243 return m_rotationSpeed;
246 qreal rotationSpeedVariation() const
248 return m_rotationSpeedVariation;
251 bool autoRotation() const
253 return m_autoRotation;
256 VaryingVector* xVector() const
261 VaryingVector* yVector() const
274 void colortableChanged();
275 void sizetableChanged();
276 void opacitytableChanged();
279 void colorVariationChanged();
281 void particleDurationChanged();
282 void alphaVariationChanged(qreal arg);
284 void alphaChanged(qreal arg);
286 void redVariationChanged(qreal arg);
288 void greenVariationChanged(qreal arg);
290 void blueVariationChanged(qreal arg);
292 void rotationChanged(qreal arg);
294 void rotationVariationChanged(qreal arg);
296 void rotationSpeedChanged(qreal arg);
298 void rotationSpeedVariationChanged(qreal arg);
300 void autoRotationChanged(bool arg);
302 void xVectorChanged(VaryingVector* arg);
304 void yVectorChanged(VaryingVector* arg);
306 void bloatChanged(bool arg);
309 void setAlphaVariation(qreal arg)
311 if (m_alphaVariation != arg) {
312 m_alphaVariation = arg;
313 emit alphaVariationChanged(arg);
317 void setAlpha(qreal arg)
319 if (m_alpha != arg) {
321 emit alphaChanged(arg);
325 void setRedVariation(qreal arg)
327 if (m_redVariation != arg) {
328 m_redVariation = arg;
329 emit redVariationChanged(arg);
333 void setGreenVariation(qreal arg)
335 if (m_greenVariation != arg) {
336 m_greenVariation = arg;
337 emit greenVariationChanged(arg);
341 void setBlueVariation(qreal arg)
343 if (m_blueVariation != arg) {
344 m_blueVariation = arg;
345 emit blueVariationChanged(arg);
349 void reloadColor(const Color4ub &c, ParticleData* d);
350 void setRotation(qreal arg)
352 if (m_rotation != arg) {
354 emit rotationChanged(arg);
358 void setRotationVariation(qreal arg)
360 if (m_rotationVariation != arg) {
361 m_rotationVariation = arg;
362 emit rotationVariationChanged(arg);
366 void setRotationSpeed(qreal arg)
368 if (m_rotationSpeed != arg) {
369 m_rotationSpeed = arg;
370 emit rotationSpeedChanged(arg);
374 void setRotationSpeedVariation(qreal arg)
376 if (m_rotationSpeedVariation != arg) {
377 m_rotationSpeedVariation = arg;
378 emit rotationSpeedVariationChanged(arg);
382 void autoRotation(bool arg)
384 if (m_autoRotation != arg) {
385 m_autoRotation = arg;
386 emit autoRotationChanged(arg);
390 void setXVector(VaryingVector* arg)
392 if (m_xVector != arg) {
394 emit xVectorChanged(arg);
398 void setYVector(VaryingVector* arg)
400 if (m_yVector != arg) {
402 emit yVectorChanged(arg);
406 void setBloat(bool arg)
408 if (m_bloat != arg) {
410 emit bloatChanged(arg);
415 QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *);
417 void prepareNextFrame();
418 QSGGeometryNode* buildParticleNode();
419 QSGGeometryNode* buildSimpleParticleNode();
422 void createEngine(); //### method invoked by sprite list changing (in engine.h) - pretty nasty
425 //void vertexCopy(UltraVertex &b,const ParticleVertex& a);
426 IntermediateVertices* fetchIntermediateVertices(int pos);
430 QUrl m_colortable_name;
431 QUrl m_sizetable_name;
432 QUrl m_opacitytable_name;
436 qreal m_color_variation;
437 qreal m_particleDuration;
439 QSGGeometryNode *m_node;
440 UltraMaterial *m_material;
445 qreal m_render_opacity;
446 qreal m_alphaVariation;
448 qreal m_redVariation;
449 qreal m_greenVariation;
450 qreal m_blueVariation;
452 qreal m_rotationVariation;
453 qreal m_rotationSpeed;
454 qreal m_rotationSpeedVariation;
456 VaryingVector* m_xVector;
457 VaryingVector* m_yVector;
459 QList<SpriteState*> m_sprites;
460 SpriteEngine* m_spriteEngine;
463 PerformanceLevel perfLevel;
468 #endif // ULTRAPARTICLE_H