From d6cc95cee7c42803793a70988d85e2d3164b17f7 Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Tue, 25 Oct 2011 07:57:54 +1000 Subject: Rename QSG* to QQuick* in particles folder Change-Id: I793eaf16f3810df0cb0f9f8482ac0b9d6137595d Reviewed-by: Alan Alpert --- src/declarative/items/qquickspriteengine_p.h | 2 +- src/declarative/particles/particles.pri | 120 +- src/declarative/particles/qquickage.cpp | 112 ++ src/declarative/particles/qquickage_p.h | 102 ++ src/declarative/particles/qquickangledirection.cpp | 116 ++ src/declarative/particles/qquickangledirection_p.h | 133 ++ .../particles/qquickcumulativedirection.cpp | 70 + .../particles/qquickcumulativedirection_p.h | 69 + src/declarative/particles/qquickcustomaffector.cpp | 211 +++ src/declarative/particles/qquickcustomaffector_p.h | 164 ++ src/declarative/particles/qquickcustomparticle.cpp | 596 +++++++ src/declarative/particles/qquickcustomparticle_p.h | 121 ++ src/declarative/particles/qquickdirection.cpp | 64 + src/declarative/particles/qquickdirection_p.h | 71 + .../particles/qquickellipseextruder.cpp | 80 + .../particles/qquickellipseextruder_p.h | 86 + src/declarative/particles/qquickfriction.cpp | 111 ++ src/declarative/particles/qquickfriction_p.h | 104 ++ src/declarative/particles/qquickgravity.cpp | 104 ++ src/declarative/particles/qquickgravity_p.h | 106 ++ src/declarative/particles/qquickgroupgoal.cpp | 112 ++ src/declarative/particles/qquickgroupgoal_p.h | 102 ++ src/declarative/particles/qquickimageparticle.cpp | 1773 ++++++++++++++++++++ src/declarative/particles/qquickimageparticle_p.h | 432 +++++ src/declarative/particles/qquickitemparticle.cpp | 268 +++ src/declarative/particles/qquickitemparticle_p.h | 138 ++ src/declarative/particles/qquicklineextruder.cpp | 84 + src/declarative/particles/qquicklineextruder_p.h | 77 + src/declarative/particles/qquickmaskextruder.cpp | 113 ++ src/declarative/particles/qquickmaskextruder_p.h | 97 ++ .../particles/qquickparticleaffector.cpp | 278 +++ .../particles/qquickparticleaffector_p.h | 201 +++ .../particles/qquickparticleemitter.cpp | 501 ++++++ .../particles/qquickparticleemitter_p.h | 351 ++++ .../particles/qquickparticleextruder.cpp | 70 + .../particles/qquickparticleextruder_p.h | 73 + src/declarative/particles/qquickparticlegroup.cpp | 143 ++ src/declarative/particles/qquickparticlegroup_p.h | 112 ++ .../particles/qquickparticlepainter.cpp | 150 ++ .../particles/qquickparticlepainter_p.h | 134 ++ .../particles/qquickparticlesmodule.cpp | 120 ++ .../particles/qquickparticlesmodule_p.h | 63 + src/declarative/particles/qquickparticlesystem.cpp | 1084 ++++++++++++ src/declarative/particles/qquickparticlesystem_p.h | 378 +++++ src/declarative/particles/qquickpointattractor.cpp | 162 ++ src/declarative/particles/qquickpointattractor_p.h | 169 ++ src/declarative/particles/qquickpointdirection.cpp | 85 + src/declarative/particles/qquickpointdirection_p.h | 135 ++ .../particles/qquickrectangleextruder.cpp | 86 + .../particles/qquickrectangleextruder_p.h | 88 + src/declarative/particles/qquickspritegoal.cpp | 153 ++ src/declarative/particles/qquickspritegoal_p.h | 125 ++ .../particles/qquicktargetdirection.cpp | 131 ++ .../particles/qquicktargetdirection_p.h | 191 +++ src/declarative/particles/qquicktrailemitter.cpp | 284 ++++ src/declarative/particles/qquicktrailemitter_p.h | 171 ++ src/declarative/particles/qquickturbulence.cpp | 210 +++ src/declarative/particles/qquickturbulence_p.h | 119 ++ src/declarative/particles/qquickv8particledata.cpp | 384 +++++ src/declarative/particles/qquickv8particledata_p.h | 69 + src/declarative/particles/qquickwander.cpp | 180 ++ src/declarative/particles/qquickwander_p.h | 161 ++ src/declarative/particles/qsgage.cpp | 112 -- src/declarative/particles/qsgage_p.h | 102 -- src/declarative/particles/qsgangledirection.cpp | 116 -- src/declarative/particles/qsgangledirection_p.h | 133 -- .../particles/qsgcumulativedirection.cpp | 70 - .../particles/qsgcumulativedirection_p.h | 69 - src/declarative/particles/qsgcustomaffector.cpp | 211 --- src/declarative/particles/qsgcustomaffector_p.h | 164 -- src/declarative/particles/qsgcustomparticle.cpp | 596 ------- src/declarative/particles/qsgcustomparticle_p.h | 121 -- src/declarative/particles/qsgdirection.cpp | 64 - src/declarative/particles/qsgdirection_p.h | 71 - src/declarative/particles/qsgellipseextruder.cpp | 80 - src/declarative/particles/qsgellipseextruder_p.h | 86 - src/declarative/particles/qsgfriction.cpp | 111 -- src/declarative/particles/qsgfriction_p.h | 104 -- src/declarative/particles/qsggravity.cpp | 104 -- src/declarative/particles/qsggravity_p.h | 106 -- src/declarative/particles/qsggroupgoal.cpp | 112 -- src/declarative/particles/qsggroupgoal_p.h | 102 -- src/declarative/particles/qsgimageparticle.cpp | 1773 -------------------- src/declarative/particles/qsgimageparticle_p.h | 432 ----- src/declarative/particles/qsgitemparticle.cpp | 268 --- src/declarative/particles/qsgitemparticle_p.h | 138 -- src/declarative/particles/qsglineextruder.cpp | 84 - src/declarative/particles/qsglineextruder_p.h | 77 - src/declarative/particles/qsgmaskextruder.cpp | 113 -- src/declarative/particles/qsgmaskextruder_p.h | 97 -- src/declarative/particles/qsgparticleaffector.cpp | 278 --- src/declarative/particles/qsgparticleaffector_p.h | 201 --- src/declarative/particles/qsgparticleemitter.cpp | 501 ------ src/declarative/particles/qsgparticleemitter_p.h | 351 ---- src/declarative/particles/qsgparticleextruder.cpp | 70 - src/declarative/particles/qsgparticleextruder_p.h | 73 - src/declarative/particles/qsgparticlegroup.cpp | 143 -- src/declarative/particles/qsgparticlegroup_p.h | 112 -- src/declarative/particles/qsgparticlepainter.cpp | 150 -- src/declarative/particles/qsgparticlepainter_p.h | 134 -- src/declarative/particles/qsgparticlesmodule.cpp | 120 -- src/declarative/particles/qsgparticlesmodule_p.h | 63 - src/declarative/particles/qsgparticlesystem.cpp | 1084 ------------ src/declarative/particles/qsgparticlesystem_p.h | 378 ----- src/declarative/particles/qsgpointattractor.cpp | 162 -- src/declarative/particles/qsgpointattractor_p.h | 169 -- src/declarative/particles/qsgpointdirection.cpp | 85 - src/declarative/particles/qsgpointdirection_p.h | 135 -- src/declarative/particles/qsgrectangleextruder.cpp | 86 - src/declarative/particles/qsgrectangleextruder_p.h | 88 - src/declarative/particles/qsgspritegoal.cpp | 153 -- src/declarative/particles/qsgspritegoal_p.h | 125 -- src/declarative/particles/qsgtargetdirection.cpp | 131 -- src/declarative/particles/qsgtargetdirection_p.h | 191 --- src/declarative/particles/qsgtrailemitter.cpp | 284 ---- src/declarative/particles/qsgtrailemitter_p.h | 171 -- src/declarative/particles/qsgturbulence.cpp | 210 --- src/declarative/particles/qsgturbulence_p.h | 119 -- src/declarative/particles/qsgv8particledata.cpp | 384 ----- src/declarative/particles/qsgv8particledata_p.h | 69 - src/declarative/particles/qsgwander.cpp | 180 -- src/declarative/particles/qsgwander_p.h | 161 -- src/declarative/qml/qdeclarativeengine.cpp | 4 +- tests/auto/particles/particles.pro | 42 +- tests/auto/particles/qquickage/data/jump.qml | 70 + tests/auto/particles/qquickage/data/kill.qml | 66 + tests/auto/particles/qquickage/data/onceoff.qml | 69 + tests/auto/particles/qquickage/data/sustained.qml | 69 + tests/auto/particles/qquickage/qquickage.pro | 13 + tests/auto/particles/qquickage/tst_qquickage.cpp | 165 ++ .../particles/qquickangleddirection/data/basic.qml | 68 + .../qquickangleddirection.pro | 11 + .../tst_qquickangleddirection.cpp | 92 + .../qquickcumulativedirection/data/basic.qml | 74 + .../qquickcumulativedirection.pro | 11 + .../tst_qquickcumulativedirection.cpp | 88 + .../particles/qquickcustomaffector/data/basic.qml | 82 + .../particles/qquickcustomaffector/data/move.qml | 74 + .../qquickcustomaffector/qquickcustomaffector.pro | 11 + .../tst_qquickcustomaffector.cpp | 115 ++ .../particles/qquickcustomparticle/data/basic.qml | 71 + .../qquickcustomparticle/qquickcustomparticle.pro | 11 + .../tst_qquickcustomparticle.cpp | 94 ++ .../particles/qquickellipseextruder/data/basic.qml | 77 + .../qquickellipseextruder.pro | 11 + .../tst_qquickellipseextruder.cpp | 120 ++ tests/auto/particles/qquickfriction/data/basic.qml | 87 + .../particles/qquickfriction/data/threshold.qml | 73 + .../particles/qquickfriction/qquickfriction.pro | 11 + .../qquickfriction/tst_qquickfriction.cpp | 134 ++ tests/auto/particles/qquickgravity/data/basic.qml | 70 + .../auto/particles/qquickgravity/qquickgravity.pro | 11 + .../particles/qquickgravity/tst_qquickgravity.cpp | 84 + .../particles/qquickimageparticle/data/basic.qml | 66 + .../particles/qquickimageparticle/data/colored.qml | 68 + .../qquickimageparticle/data/deformed.qml | 71 + .../particles/qquickimageparticle/data/sprite.qml | 71 + .../particles/qquickimageparticle/data/tabled.qml | 69 + .../qquickimageparticle/qquickimageparticle.pro | 11 + .../tst_qquickimageparticle.cpp | 285 ++++ .../particles/qquickitemparticle/data/basic.qml | 66 + .../qquickitemparticle/qquickitemparticle.pro | 11 + .../qquickitemparticle/tst_qquickitemparticle.cpp | 95 ++ .../particles/qquicklineextruder/data/basic.qml | 76 + .../qquicklineextruder/qquicklineextruder.pro | 11 + .../qquicklineextruder/tst_qquicklineextruder.cpp | 103 ++ .../particles/qquickmaskextruder/data/basic.qml | 68 + .../qquickmaskextruder/data/smallmask.png | Bin 0 -> 719 bytes .../qquickmaskextruder/qquickmaskextruder.pro | 11 + .../qquickmaskextruder/tst_qquickmaskextruder.cpp | 88 + .../particles/qquickparticlegroup/data/basic.qml | 73 + .../qquickparticlegroup/qquickparticlegroup.pro | 11 + .../tst_qquickparticlegroup.cpp | 89 + .../particles/qquickparticlesystem/data/basic.qml | 66 + .../qquickparticlesystem/qquickparticlesystem.pro | 11 + .../tst_qquickparticlesystem.cpp | 92 + .../particles/qquickpointattractor/data/basic.qml | 73 + .../qquickpointattractor/qquickpointattractor.pro | 11 + .../tst_qquickpointattractor.cpp | 89 + .../particles/qquickpointdirection/data/basic.qml | 68 + .../qquickpointdirection/qquickpointdirection.pro | 11 + .../tst_qquickpointdirection.cpp | 90 + .../qquickrectangleextruder/data/basic.qml | 78 + .../qquickrectangleextruder.pro | 11 + .../tst_qquickrectangleextruder.cpp | 113 ++ .../particles/qquicktargetdirection/data/basic.qml | 67 + .../qquicktargetdirection.pro | 11 + .../tst_qquicktargetdirection.cpp | 88 + .../particles/qquicktrailemitter/data/basic.qml | 77 + .../qquicktrailemitter/qquicktrailemitter.pro | 11 + .../qquicktrailemitter/tst_qquicktrailemitter.cpp | 105 ++ .../auto/particles/qquickturbulence/data/basic.qml | 73 + .../qquickturbulence/qquickturbulence.pro | 11 + .../qquickturbulence/tst_qquickturbulence.cpp | 86 + tests/auto/particles/qquickwander/data/basic.qml | 72 + tests/auto/particles/qquickwander/qquickwander.pro | 11 + .../particles/qquickwander/tst_qquickwander.cpp | 94 ++ tests/auto/particles/qsgage/data/jump.qml | 70 - tests/auto/particles/qsgage/data/kill.qml | 66 - tests/auto/particles/qsgage/data/onceoff.qml | 69 - tests/auto/particles/qsgage/data/sustained.qml | 69 - tests/auto/particles/qsgage/qsgage.pro | 13 - tests/auto/particles/qsgage/tst_qsgage.cpp | 165 -- .../particles/qsgangleddirection/data/basic.qml | 68 - .../qsgangleddirection/qsgangleddirection.pro | 11 - .../qsgangleddirection/tst_qsgangleddirection.cpp | 92 - .../qsgcumulativedirection/data/basic.qml | 74 - .../qsgcumulativedirection.pro | 11 - .../tst_qsgcumulativedirection.cpp | 88 - .../particles/qsgcustomaffector/data/basic.qml | 82 - .../auto/particles/qsgcustomaffector/data/move.qml | 74 - .../qsgcustomaffector/qsgcustomaffector.pro | 11 - .../qsgcustomaffector/tst_qsgcustomaffector.cpp | 115 -- .../particles/qsgcustomparticle/data/basic.qml | 71 - .../qsgcustomparticle/qsgcustomparticle.pro | 11 - .../qsgcustomparticle/tst_qsgcustomparticle.cpp | 94 -- .../particles/qsgellipseextruder/data/basic.qml | 77 - .../qsgellipseextruder/qsgellipseextruder.pro | 11 - .../qsgellipseextruder/tst_qsgellipseextruder.cpp | 120 -- tests/auto/particles/qsgfriction/data/basic.qml | 87 - .../auto/particles/qsgfriction/data/threshold.qml | 73 - tests/auto/particles/qsgfriction/qsgfriction.pro | 11 - .../auto/particles/qsgfriction/tst_qsgfriction.cpp | 134 -- tests/auto/particles/qsggravity/data/basic.qml | 70 - tests/auto/particles/qsggravity/qsggravity.pro | 11 - tests/auto/particles/qsggravity/tst_qsggravity.cpp | 84 - .../auto/particles/qsgimageparticle/data/basic.qml | 66 - .../particles/qsgimageparticle/data/colored.qml | 68 - .../particles/qsgimageparticle/data/deformed.qml | 71 - .../particles/qsgimageparticle/data/sprite.qml | 71 - .../particles/qsgimageparticle/data/tabled.qml | 69 - .../qsgimageparticle/qsgimageparticle.pro | 11 - .../qsgimageparticle/tst_qsgimageparticle.cpp | 285 ---- .../auto/particles/qsgitemparticle/data/basic.qml | 66 - .../particles/qsgitemparticle/qsgitemparticle.pro | 11 - .../qsgitemparticle/tst_qsgitemparticle.cpp | 95 -- .../auto/particles/qsglineextruder/data/basic.qml | 76 - .../particles/qsglineextruder/qsglineextruder.pro | 11 - .../qsglineextruder/tst_qsglineextruder.cpp | 103 -- .../auto/particles/qsgmaskextruder/data/basic.qml | 68 - .../particles/qsgmaskextruder/data/smallmask.png | Bin 719 -> 0 bytes .../particles/qsgmaskextruder/qsgmaskextruder.pro | 11 - .../qsgmaskextruder/tst_qsgmaskextruder.cpp | 88 - .../auto/particles/qsgparticlegroup/data/basic.qml | 73 - .../qsgparticlegroup/qsgparticlegroup.pro | 11 - .../qsgparticlegroup/tst_qsgparticlegroup.cpp | 89 - .../particles/qsgparticlesystem/data/basic.qml | 66 - .../qsgparticlesystem/qsgparticlesystem.pro | 11 - .../qsgparticlesystem/tst_qsgparticlesystem.cpp | 92 - .../particles/qsgpointattractor/data/basic.qml | 73 - .../qsgpointattractor/qsgpointattractor.pro | 11 - .../qsgpointattractor/tst_qsgpointattractor.cpp | 89 - .../particles/qsgpointdirection/data/basic.qml | 68 - .../qsgpointdirection/qsgpointdirection.pro | 11 - .../qsgpointdirection/tst_qsgpointdirection.cpp | 90 - .../particles/qsgrectangleextruder/data/basic.qml | 78 - .../qsgrectangleextruder/qsgrectangleextruder.pro | 11 - .../tst_qsgrectangleextruder.cpp | 113 -- .../particles/qsgtargetdirection/data/basic.qml | 67 - .../qsgtargetdirection/qsgtargetdirection.pro | 11 - .../qsgtargetdirection/tst_qsgtargetdirection.cpp | 88 - .../auto/particles/qsgtrailemitter/data/basic.qml | 77 - .../particles/qsgtrailemitter/qsgtrailemitter.pro | 11 - .../qsgtrailemitter/tst_qsgtrailemitter.cpp | 105 -- tests/auto/particles/qsgturbulence/data/basic.qml | 73 - .../auto/particles/qsgturbulence/qsgturbulence.pro | 11 - .../particles/qsgturbulence/tst_qsgturbulence.cpp | 86 - tests/auto/particles/qsgwander/data/basic.qml | 72 - tests/auto/particles/qsgwander/qsgwander.pro | 11 - tests/auto/particles/qsgwander/tst_qsgwander.cpp | 94 -- .../particles/affectors/tst_affectors.cpp | 8 +- .../benchmarks/particles/emission/tst_emission.cpp | 4 +- 272 files changed, 16961 insertions(+), 16961 deletions(-) create mode 100644 src/declarative/particles/qquickage.cpp create mode 100644 src/declarative/particles/qquickage_p.h create mode 100644 src/declarative/particles/qquickangledirection.cpp create mode 100644 src/declarative/particles/qquickangledirection_p.h create mode 100644 src/declarative/particles/qquickcumulativedirection.cpp create mode 100644 src/declarative/particles/qquickcumulativedirection_p.h create mode 100644 src/declarative/particles/qquickcustomaffector.cpp create mode 100644 src/declarative/particles/qquickcustomaffector_p.h create mode 100644 src/declarative/particles/qquickcustomparticle.cpp create mode 100644 src/declarative/particles/qquickcustomparticle_p.h create mode 100644 src/declarative/particles/qquickdirection.cpp create mode 100644 src/declarative/particles/qquickdirection_p.h create mode 100644 src/declarative/particles/qquickellipseextruder.cpp create mode 100644 src/declarative/particles/qquickellipseextruder_p.h create mode 100644 src/declarative/particles/qquickfriction.cpp create mode 100644 src/declarative/particles/qquickfriction_p.h create mode 100644 src/declarative/particles/qquickgravity.cpp create mode 100644 src/declarative/particles/qquickgravity_p.h create mode 100644 src/declarative/particles/qquickgroupgoal.cpp create mode 100644 src/declarative/particles/qquickgroupgoal_p.h create mode 100644 src/declarative/particles/qquickimageparticle.cpp create mode 100644 src/declarative/particles/qquickimageparticle_p.h create mode 100644 src/declarative/particles/qquickitemparticle.cpp create mode 100644 src/declarative/particles/qquickitemparticle_p.h create mode 100644 src/declarative/particles/qquicklineextruder.cpp create mode 100644 src/declarative/particles/qquicklineextruder_p.h create mode 100644 src/declarative/particles/qquickmaskextruder.cpp create mode 100644 src/declarative/particles/qquickmaskextruder_p.h create mode 100644 src/declarative/particles/qquickparticleaffector.cpp create mode 100644 src/declarative/particles/qquickparticleaffector_p.h create mode 100644 src/declarative/particles/qquickparticleemitter.cpp create mode 100644 src/declarative/particles/qquickparticleemitter_p.h create mode 100644 src/declarative/particles/qquickparticleextruder.cpp create mode 100644 src/declarative/particles/qquickparticleextruder_p.h create mode 100644 src/declarative/particles/qquickparticlegroup.cpp create mode 100644 src/declarative/particles/qquickparticlegroup_p.h create mode 100644 src/declarative/particles/qquickparticlepainter.cpp create mode 100644 src/declarative/particles/qquickparticlepainter_p.h create mode 100644 src/declarative/particles/qquickparticlesmodule.cpp create mode 100644 src/declarative/particles/qquickparticlesmodule_p.h create mode 100644 src/declarative/particles/qquickparticlesystem.cpp create mode 100644 src/declarative/particles/qquickparticlesystem_p.h create mode 100644 src/declarative/particles/qquickpointattractor.cpp create mode 100644 src/declarative/particles/qquickpointattractor_p.h create mode 100644 src/declarative/particles/qquickpointdirection.cpp create mode 100644 src/declarative/particles/qquickpointdirection_p.h create mode 100644 src/declarative/particles/qquickrectangleextruder.cpp create mode 100644 src/declarative/particles/qquickrectangleextruder_p.h create mode 100644 src/declarative/particles/qquickspritegoal.cpp create mode 100644 src/declarative/particles/qquickspritegoal_p.h create mode 100644 src/declarative/particles/qquicktargetdirection.cpp create mode 100644 src/declarative/particles/qquicktargetdirection_p.h create mode 100644 src/declarative/particles/qquicktrailemitter.cpp create mode 100644 src/declarative/particles/qquicktrailemitter_p.h create mode 100644 src/declarative/particles/qquickturbulence.cpp create mode 100644 src/declarative/particles/qquickturbulence_p.h create mode 100644 src/declarative/particles/qquickv8particledata.cpp create mode 100644 src/declarative/particles/qquickv8particledata_p.h create mode 100644 src/declarative/particles/qquickwander.cpp create mode 100644 src/declarative/particles/qquickwander_p.h delete mode 100644 src/declarative/particles/qsgage.cpp delete mode 100644 src/declarative/particles/qsgage_p.h delete mode 100644 src/declarative/particles/qsgangledirection.cpp delete mode 100644 src/declarative/particles/qsgangledirection_p.h delete mode 100644 src/declarative/particles/qsgcumulativedirection.cpp delete mode 100644 src/declarative/particles/qsgcumulativedirection_p.h delete mode 100644 src/declarative/particles/qsgcustomaffector.cpp delete mode 100644 src/declarative/particles/qsgcustomaffector_p.h delete mode 100644 src/declarative/particles/qsgcustomparticle.cpp delete mode 100644 src/declarative/particles/qsgcustomparticle_p.h delete mode 100644 src/declarative/particles/qsgdirection.cpp delete mode 100644 src/declarative/particles/qsgdirection_p.h delete mode 100644 src/declarative/particles/qsgellipseextruder.cpp delete mode 100644 src/declarative/particles/qsgellipseextruder_p.h delete mode 100644 src/declarative/particles/qsgfriction.cpp delete mode 100644 src/declarative/particles/qsgfriction_p.h delete mode 100644 src/declarative/particles/qsggravity.cpp delete mode 100644 src/declarative/particles/qsggravity_p.h delete mode 100644 src/declarative/particles/qsggroupgoal.cpp delete mode 100644 src/declarative/particles/qsggroupgoal_p.h delete mode 100644 src/declarative/particles/qsgimageparticle.cpp delete mode 100644 src/declarative/particles/qsgimageparticle_p.h delete mode 100644 src/declarative/particles/qsgitemparticle.cpp delete mode 100644 src/declarative/particles/qsgitemparticle_p.h delete mode 100644 src/declarative/particles/qsglineextruder.cpp delete mode 100644 src/declarative/particles/qsglineextruder_p.h delete mode 100644 src/declarative/particles/qsgmaskextruder.cpp delete mode 100644 src/declarative/particles/qsgmaskextruder_p.h delete mode 100644 src/declarative/particles/qsgparticleaffector.cpp delete mode 100644 src/declarative/particles/qsgparticleaffector_p.h delete mode 100644 src/declarative/particles/qsgparticleemitter.cpp delete mode 100644 src/declarative/particles/qsgparticleemitter_p.h delete mode 100644 src/declarative/particles/qsgparticleextruder.cpp delete mode 100644 src/declarative/particles/qsgparticleextruder_p.h delete mode 100644 src/declarative/particles/qsgparticlegroup.cpp delete mode 100644 src/declarative/particles/qsgparticlegroup_p.h delete mode 100644 src/declarative/particles/qsgparticlepainter.cpp delete mode 100644 src/declarative/particles/qsgparticlepainter_p.h delete mode 100644 src/declarative/particles/qsgparticlesmodule.cpp delete mode 100644 src/declarative/particles/qsgparticlesmodule_p.h delete mode 100644 src/declarative/particles/qsgparticlesystem.cpp delete mode 100644 src/declarative/particles/qsgparticlesystem_p.h delete mode 100644 src/declarative/particles/qsgpointattractor.cpp delete mode 100644 src/declarative/particles/qsgpointattractor_p.h delete mode 100644 src/declarative/particles/qsgpointdirection.cpp delete mode 100644 src/declarative/particles/qsgpointdirection_p.h delete mode 100644 src/declarative/particles/qsgrectangleextruder.cpp delete mode 100644 src/declarative/particles/qsgrectangleextruder_p.h delete mode 100644 src/declarative/particles/qsgspritegoal.cpp delete mode 100644 src/declarative/particles/qsgspritegoal_p.h delete mode 100644 src/declarative/particles/qsgtargetdirection.cpp delete mode 100644 src/declarative/particles/qsgtargetdirection_p.h delete mode 100644 src/declarative/particles/qsgtrailemitter.cpp delete mode 100644 src/declarative/particles/qsgtrailemitter_p.h delete mode 100644 src/declarative/particles/qsgturbulence.cpp delete mode 100644 src/declarative/particles/qsgturbulence_p.h delete mode 100644 src/declarative/particles/qsgv8particledata.cpp delete mode 100644 src/declarative/particles/qsgv8particledata_p.h delete mode 100644 src/declarative/particles/qsgwander.cpp delete mode 100644 src/declarative/particles/qsgwander_p.h create mode 100644 tests/auto/particles/qquickage/data/jump.qml create mode 100644 tests/auto/particles/qquickage/data/kill.qml create mode 100644 tests/auto/particles/qquickage/data/onceoff.qml create mode 100644 tests/auto/particles/qquickage/data/sustained.qml create mode 100644 tests/auto/particles/qquickage/qquickage.pro create mode 100644 tests/auto/particles/qquickage/tst_qquickage.cpp create mode 100644 tests/auto/particles/qquickangleddirection/data/basic.qml create mode 100644 tests/auto/particles/qquickangleddirection/qquickangleddirection.pro create mode 100644 tests/auto/particles/qquickangleddirection/tst_qquickangleddirection.cpp create mode 100644 tests/auto/particles/qquickcumulativedirection/data/basic.qml create mode 100644 tests/auto/particles/qquickcumulativedirection/qquickcumulativedirection.pro create mode 100644 tests/auto/particles/qquickcumulativedirection/tst_qquickcumulativedirection.cpp create mode 100644 tests/auto/particles/qquickcustomaffector/data/basic.qml create mode 100644 tests/auto/particles/qquickcustomaffector/data/move.qml create mode 100644 tests/auto/particles/qquickcustomaffector/qquickcustomaffector.pro create mode 100644 tests/auto/particles/qquickcustomaffector/tst_qquickcustomaffector.cpp create mode 100644 tests/auto/particles/qquickcustomparticle/data/basic.qml create mode 100644 tests/auto/particles/qquickcustomparticle/qquickcustomparticle.pro create mode 100644 tests/auto/particles/qquickcustomparticle/tst_qquickcustomparticle.cpp create mode 100644 tests/auto/particles/qquickellipseextruder/data/basic.qml create mode 100644 tests/auto/particles/qquickellipseextruder/qquickellipseextruder.pro create mode 100644 tests/auto/particles/qquickellipseextruder/tst_qquickellipseextruder.cpp create mode 100644 tests/auto/particles/qquickfriction/data/basic.qml create mode 100644 tests/auto/particles/qquickfriction/data/threshold.qml create mode 100644 tests/auto/particles/qquickfriction/qquickfriction.pro create mode 100644 tests/auto/particles/qquickfriction/tst_qquickfriction.cpp create mode 100644 tests/auto/particles/qquickgravity/data/basic.qml create mode 100644 tests/auto/particles/qquickgravity/qquickgravity.pro create mode 100644 tests/auto/particles/qquickgravity/tst_qquickgravity.cpp create mode 100644 tests/auto/particles/qquickimageparticle/data/basic.qml create mode 100644 tests/auto/particles/qquickimageparticle/data/colored.qml create mode 100644 tests/auto/particles/qquickimageparticle/data/deformed.qml create mode 100644 tests/auto/particles/qquickimageparticle/data/sprite.qml create mode 100644 tests/auto/particles/qquickimageparticle/data/tabled.qml create mode 100644 tests/auto/particles/qquickimageparticle/qquickimageparticle.pro create mode 100644 tests/auto/particles/qquickimageparticle/tst_qquickimageparticle.cpp create mode 100644 tests/auto/particles/qquickitemparticle/data/basic.qml create mode 100644 tests/auto/particles/qquickitemparticle/qquickitemparticle.pro create mode 100644 tests/auto/particles/qquickitemparticle/tst_qquickitemparticle.cpp create mode 100644 tests/auto/particles/qquicklineextruder/data/basic.qml create mode 100644 tests/auto/particles/qquicklineextruder/qquicklineextruder.pro create mode 100644 tests/auto/particles/qquicklineextruder/tst_qquicklineextruder.cpp create mode 100644 tests/auto/particles/qquickmaskextruder/data/basic.qml create mode 100644 tests/auto/particles/qquickmaskextruder/data/smallmask.png create mode 100644 tests/auto/particles/qquickmaskextruder/qquickmaskextruder.pro create mode 100644 tests/auto/particles/qquickmaskextruder/tst_qquickmaskextruder.cpp create mode 100644 tests/auto/particles/qquickparticlegroup/data/basic.qml create mode 100644 tests/auto/particles/qquickparticlegroup/qquickparticlegroup.pro create mode 100644 tests/auto/particles/qquickparticlegroup/tst_qquickparticlegroup.cpp create mode 100644 tests/auto/particles/qquickparticlesystem/data/basic.qml create mode 100644 tests/auto/particles/qquickparticlesystem/qquickparticlesystem.pro create mode 100644 tests/auto/particles/qquickparticlesystem/tst_qquickparticlesystem.cpp create mode 100644 tests/auto/particles/qquickpointattractor/data/basic.qml create mode 100644 tests/auto/particles/qquickpointattractor/qquickpointattractor.pro create mode 100644 tests/auto/particles/qquickpointattractor/tst_qquickpointattractor.cpp create mode 100644 tests/auto/particles/qquickpointdirection/data/basic.qml create mode 100644 tests/auto/particles/qquickpointdirection/qquickpointdirection.pro create mode 100644 tests/auto/particles/qquickpointdirection/tst_qquickpointdirection.cpp create mode 100644 tests/auto/particles/qquickrectangleextruder/data/basic.qml create mode 100644 tests/auto/particles/qquickrectangleextruder/qquickrectangleextruder.pro create mode 100644 tests/auto/particles/qquickrectangleextruder/tst_qquickrectangleextruder.cpp create mode 100644 tests/auto/particles/qquicktargetdirection/data/basic.qml create mode 100644 tests/auto/particles/qquicktargetdirection/qquicktargetdirection.pro create mode 100644 tests/auto/particles/qquicktargetdirection/tst_qquicktargetdirection.cpp create mode 100644 tests/auto/particles/qquicktrailemitter/data/basic.qml create mode 100644 tests/auto/particles/qquicktrailemitter/qquicktrailemitter.pro create mode 100644 tests/auto/particles/qquicktrailemitter/tst_qquicktrailemitter.cpp create mode 100644 tests/auto/particles/qquickturbulence/data/basic.qml create mode 100644 tests/auto/particles/qquickturbulence/qquickturbulence.pro create mode 100644 tests/auto/particles/qquickturbulence/tst_qquickturbulence.cpp create mode 100644 tests/auto/particles/qquickwander/data/basic.qml create mode 100644 tests/auto/particles/qquickwander/qquickwander.pro create mode 100644 tests/auto/particles/qquickwander/tst_qquickwander.cpp delete mode 100644 tests/auto/particles/qsgage/data/jump.qml delete mode 100644 tests/auto/particles/qsgage/data/kill.qml delete mode 100644 tests/auto/particles/qsgage/data/onceoff.qml delete mode 100644 tests/auto/particles/qsgage/data/sustained.qml delete mode 100644 tests/auto/particles/qsgage/qsgage.pro delete mode 100644 tests/auto/particles/qsgage/tst_qsgage.cpp delete mode 100644 tests/auto/particles/qsgangleddirection/data/basic.qml delete mode 100644 tests/auto/particles/qsgangleddirection/qsgangleddirection.pro delete mode 100644 tests/auto/particles/qsgangleddirection/tst_qsgangleddirection.cpp delete mode 100644 tests/auto/particles/qsgcumulativedirection/data/basic.qml delete mode 100644 tests/auto/particles/qsgcumulativedirection/qsgcumulativedirection.pro delete mode 100644 tests/auto/particles/qsgcumulativedirection/tst_qsgcumulativedirection.cpp delete mode 100644 tests/auto/particles/qsgcustomaffector/data/basic.qml delete mode 100644 tests/auto/particles/qsgcustomaffector/data/move.qml delete mode 100644 tests/auto/particles/qsgcustomaffector/qsgcustomaffector.pro delete mode 100644 tests/auto/particles/qsgcustomaffector/tst_qsgcustomaffector.cpp delete mode 100644 tests/auto/particles/qsgcustomparticle/data/basic.qml delete mode 100644 tests/auto/particles/qsgcustomparticle/qsgcustomparticle.pro delete mode 100644 tests/auto/particles/qsgcustomparticle/tst_qsgcustomparticle.cpp delete mode 100644 tests/auto/particles/qsgellipseextruder/data/basic.qml delete mode 100644 tests/auto/particles/qsgellipseextruder/qsgellipseextruder.pro delete mode 100644 tests/auto/particles/qsgellipseextruder/tst_qsgellipseextruder.cpp delete mode 100644 tests/auto/particles/qsgfriction/data/basic.qml delete mode 100644 tests/auto/particles/qsgfriction/data/threshold.qml delete mode 100644 tests/auto/particles/qsgfriction/qsgfriction.pro delete mode 100644 tests/auto/particles/qsgfriction/tst_qsgfriction.cpp delete mode 100644 tests/auto/particles/qsggravity/data/basic.qml delete mode 100644 tests/auto/particles/qsggravity/qsggravity.pro delete mode 100644 tests/auto/particles/qsggravity/tst_qsggravity.cpp delete mode 100644 tests/auto/particles/qsgimageparticle/data/basic.qml delete mode 100644 tests/auto/particles/qsgimageparticle/data/colored.qml delete mode 100644 tests/auto/particles/qsgimageparticle/data/deformed.qml delete mode 100644 tests/auto/particles/qsgimageparticle/data/sprite.qml delete mode 100644 tests/auto/particles/qsgimageparticle/data/tabled.qml delete mode 100644 tests/auto/particles/qsgimageparticle/qsgimageparticle.pro delete mode 100644 tests/auto/particles/qsgimageparticle/tst_qsgimageparticle.cpp delete mode 100644 tests/auto/particles/qsgitemparticle/data/basic.qml delete mode 100644 tests/auto/particles/qsgitemparticle/qsgitemparticle.pro delete mode 100644 tests/auto/particles/qsgitemparticle/tst_qsgitemparticle.cpp delete mode 100644 tests/auto/particles/qsglineextruder/data/basic.qml delete mode 100644 tests/auto/particles/qsglineextruder/qsglineextruder.pro delete mode 100644 tests/auto/particles/qsglineextruder/tst_qsglineextruder.cpp delete mode 100644 tests/auto/particles/qsgmaskextruder/data/basic.qml delete mode 100644 tests/auto/particles/qsgmaskextruder/data/smallmask.png delete mode 100644 tests/auto/particles/qsgmaskextruder/qsgmaskextruder.pro delete mode 100644 tests/auto/particles/qsgmaskextruder/tst_qsgmaskextruder.cpp delete mode 100644 tests/auto/particles/qsgparticlegroup/data/basic.qml delete mode 100644 tests/auto/particles/qsgparticlegroup/qsgparticlegroup.pro delete mode 100644 tests/auto/particles/qsgparticlegroup/tst_qsgparticlegroup.cpp delete mode 100644 tests/auto/particles/qsgparticlesystem/data/basic.qml delete mode 100644 tests/auto/particles/qsgparticlesystem/qsgparticlesystem.pro delete mode 100644 tests/auto/particles/qsgparticlesystem/tst_qsgparticlesystem.cpp delete mode 100644 tests/auto/particles/qsgpointattractor/data/basic.qml delete mode 100644 tests/auto/particles/qsgpointattractor/qsgpointattractor.pro delete mode 100644 tests/auto/particles/qsgpointattractor/tst_qsgpointattractor.cpp delete mode 100644 tests/auto/particles/qsgpointdirection/data/basic.qml delete mode 100644 tests/auto/particles/qsgpointdirection/qsgpointdirection.pro delete mode 100644 tests/auto/particles/qsgpointdirection/tst_qsgpointdirection.cpp delete mode 100644 tests/auto/particles/qsgrectangleextruder/data/basic.qml delete mode 100644 tests/auto/particles/qsgrectangleextruder/qsgrectangleextruder.pro delete mode 100644 tests/auto/particles/qsgrectangleextruder/tst_qsgrectangleextruder.cpp delete mode 100644 tests/auto/particles/qsgtargetdirection/data/basic.qml delete mode 100644 tests/auto/particles/qsgtargetdirection/qsgtargetdirection.pro delete mode 100644 tests/auto/particles/qsgtargetdirection/tst_qsgtargetdirection.cpp delete mode 100644 tests/auto/particles/qsgtrailemitter/data/basic.qml delete mode 100644 tests/auto/particles/qsgtrailemitter/qsgtrailemitter.pro delete mode 100644 tests/auto/particles/qsgtrailemitter/tst_qsgtrailemitter.cpp delete mode 100644 tests/auto/particles/qsgturbulence/data/basic.qml delete mode 100644 tests/auto/particles/qsgturbulence/qsgturbulence.pro delete mode 100644 tests/auto/particles/qsgturbulence/tst_qsgturbulence.cpp delete mode 100644 tests/auto/particles/qsgwander/data/basic.qml delete mode 100644 tests/auto/particles/qsgwander/qsgwander.pro delete mode 100644 tests/auto/particles/qsgwander/tst_qsgwander.cpp diff --git a/src/declarative/items/qquickspriteengine_p.h b/src/declarative/items/qquickspriteengine_p.h index 6d527d12dc..44f82044da 100644 --- a/src/declarative/items/qquickspriteengine_p.h +++ b/src/declarative/items/qquickspriteengine_p.h @@ -240,7 +240,7 @@ public slots: uint updateSprites(uint time); protected: - friend class QSGParticleSystem; + friend class QQuickParticleSystem; void restart(int index); void addToUpdateList(uint t, int idx); int goalSeek(int curState, int idx, int dist=-1); diff --git a/src/declarative/particles/particles.pri b/src/declarative/particles/particles.pri index b35cb8a614..3a40a3b911 100644 --- a/src/declarative/particles/particles.pri +++ b/src/declarative/particles/particles.pri @@ -1,66 +1,66 @@ HEADERS += \ - $$PWD/qsgangledirection_p.h \ - $$PWD/qsgcustomparticle_p.h \ - $$PWD/qsgcustomaffector_p.h \ - $$PWD/qsgellipseextruder_p.h \ - $$PWD/qsgtrailemitter_p.h \ - $$PWD/qsgfriction_p.h \ - $$PWD/qsggravity_p.h \ - $$PWD/qsgimageparticle_p.h \ - $$PWD/qsgitemparticle_p.h \ - $$PWD/qsgage_p.h \ - $$PWD/qsglineextruder_p.h \ - $$PWD/qsgmaskextruder_p.h \ - $$PWD/qsgparticleaffector_p.h \ - $$PWD/qsgparticleemitter_p.h \ - $$PWD/qsgparticleextruder_p.h \ - $$PWD/qsgparticlepainter_p.h \ - $$PWD/qsgparticlesmodule_p.h \ - $$PWD/qsgparticlesystem_p.h \ - $$PWD/qsgpointattractor_p.h \ - $$PWD/qsgpointdirection_p.h \ - $$PWD/qsgspritegoal_p.h \ - $$PWD/qsgdirection_p.h \ - $$PWD/qsgtargetdirection_p.h \ - $$PWD/qsgturbulence_p.h \ - $$PWD/qsgwander_p.h \ - $$PWD/qsgcumulativedirection_p.h \ - $$PWD/qsgv8particledata_p.h \ - $$PWD/qsgrectangleextruder_p.h \ - $$PWD/qsgparticlegroup_p.h \ - $$PWD/qsggroupgoal_p.h + $$PWD/qquickangledirection_p.h \ + $$PWD/qquickcustomparticle_p.h \ + $$PWD/qquickcustomaffector_p.h \ + $$PWD/qquickellipseextruder_p.h \ + $$PWD/qquicktrailemitter_p.h \ + $$PWD/qquickfriction_p.h \ + $$PWD/qquickgravity_p.h \ + $$PWD/qquickimageparticle_p.h \ + $$PWD/qquickitemparticle_p.h \ + $$PWD/qquickage_p.h \ + $$PWD/qquicklineextruder_p.h \ + $$PWD/qquickmaskextruder_p.h \ + $$PWD/qquickparticleaffector_p.h \ + $$PWD/qquickparticleemitter_p.h \ + $$PWD/qquickparticleextruder_p.h \ + $$PWD/qquickparticlepainter_p.h \ + $$PWD/qquickparticlesmodule_p.h \ + $$PWD/qquickparticlesystem_p.h \ + $$PWD/qquickpointattractor_p.h \ + $$PWD/qquickpointdirection_p.h \ + $$PWD/qquickspritegoal_p.h \ + $$PWD/qquickdirection_p.h \ + $$PWD/qquicktargetdirection_p.h \ + $$PWD/qquickturbulence_p.h \ + $$PWD/qquickwander_p.h \ + $$PWD/qquickcumulativedirection_p.h \ + $$PWD/qquickv8particledata_p.h \ + $$PWD/qquickrectangleextruder_p.h \ + $$PWD/qquickparticlegroup_p.h \ + $$PWD/qquickgroupgoal_p.h SOURCES += \ - $$PWD/qsgangledirection.cpp \ - $$PWD/qsgcustomparticle.cpp \ - $$PWD/qsgcustomaffector.cpp \ - $$PWD/qsgellipseextruder.cpp \ - $$PWD/qsgtrailemitter.cpp \ - $$PWD/qsgfriction.cpp \ - $$PWD/qsggravity.cpp \ - $$PWD/qsgimageparticle.cpp \ - $$PWD/qsgitemparticle.cpp \ - $$PWD/qsgage.cpp \ - $$PWD/qsglineextruder.cpp \ - $$PWD/qsgmaskextruder.cpp \ - $$PWD/qsgparticleaffector.cpp \ - $$PWD/qsgparticleemitter.cpp \ - $$PWD/qsgparticleextruder.cpp \ - $$PWD/qsgparticlepainter.cpp \ - $$PWD/qsgparticlesmodule.cpp \ - $$PWD/qsgparticlesystem.cpp \ - $$PWD/qsgpointattractor.cpp \ - $$PWD/qsgpointdirection.cpp \ - $$PWD/qsgspritegoal.cpp \ - $$PWD/qsgdirection.cpp \ - $$PWD/qsgtargetdirection.cpp \ - $$PWD/qsgturbulence.cpp \ - $$PWD/qsgwander.cpp \ - $$PWD/qsgcumulativedirection.cpp \ - $$PWD/qsgv8particledata.cpp \ - $$PWD/qsgrectangleextruder.cpp \ - $$PWD/qsgparticlegroup.cpp \ - $$PWD/qsggroupgoal.cpp + $$PWD/qquickangledirection.cpp \ + $$PWD/qquickcustomparticle.cpp \ + $$PWD/qquickcustomaffector.cpp \ + $$PWD/qquickellipseextruder.cpp \ + $$PWD/qquicktrailemitter.cpp \ + $$PWD/qquickfriction.cpp \ + $$PWD/qquickgravity.cpp \ + $$PWD/qquickimageparticle.cpp \ + $$PWD/qquickitemparticle.cpp \ + $$PWD/qquickage.cpp \ + $$PWD/qquicklineextruder.cpp \ + $$PWD/qquickmaskextruder.cpp \ + $$PWD/qquickparticleaffector.cpp \ + $$PWD/qquickparticleemitter.cpp \ + $$PWD/qquickparticleextruder.cpp \ + $$PWD/qquickparticlepainter.cpp \ + $$PWD/qquickparticlesmodule.cpp \ + $$PWD/qquickparticlesystem.cpp \ + $$PWD/qquickpointattractor.cpp \ + $$PWD/qquickpointdirection.cpp \ + $$PWD/qquickspritegoal.cpp \ + $$PWD/qquickdirection.cpp \ + $$PWD/qquicktargetdirection.cpp \ + $$PWD/qquickturbulence.cpp \ + $$PWD/qquickwander.cpp \ + $$PWD/qquickcumulativedirection.cpp \ + $$PWD/qquickv8particledata.cpp \ + $$PWD/qquickrectangleextruder.cpp \ + $$PWD/qquickparticlegroup.cpp \ + $$PWD/qquickgroupgoal.cpp RESOURCES += \ $$PWD/particles.qrc diff --git a/src/declarative/particles/qquickage.cpp b/src/declarative/particles/qquickage.cpp new file mode 100644 index 0000000000..a71b9e2088 --- /dev/null +++ b/src/declarative/particles/qquickage.cpp @@ -0,0 +1,112 @@ +/**************************************************************************** +** +** 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 "qquickage_p.h" +#include "qquickparticleemitter_p.h" +QT_BEGIN_NAMESPACE +/*! + \qmlclass Age QQuickAgeAffector + \inqmlmodule QtQuick.Particles 2 + \inherits Affector + \brief The Age affector allows you to prematurely age particles + + The Age affector allows you to alter where the particle is in its lifecycle. Common uses + are to expire particles prematurely, possibly giving them time to animate out. + + The Age affector only applies to particles which are still alive. +*/ +/*! + \qmlproperty int QtQuick.Particles2::Age::lifeLeft + + The amount of life to set the particle to have. Affected particles + will advance to a point in their life where they will have this many + milliseconds left to live. +*/ + +/*! + \qmlproperty bool QtQuick.Particles2::Age::advancePosition + + advancePosition determines whether position, veclocity and acceleration are included in + the simulated aging done by the affector. If advancePosition is false, + then the position, velocity and acceleration will remain the same and only + other attributes (such as opacity) will advance in the simulation to where + it would normally be for that point in the particle's life. With advancePosition set to + true the position, velocity and acceleration will also advance to where it would + normally be by that point in the particle's life, making it advance its position + on screen. + + Default value is true. +*/ + +QQuickAgeAffector::QQuickAgeAffector(QQuickItem *parent) : + QQuickParticleAffector(parent), m_lifeLeft(0), m_advancePosition(true) +{ +} + + +bool QQuickAgeAffector::affectParticle(QQuickParticleData *d, qreal dt) +{ + Q_UNUSED(dt); + if (d->stillAlive()){ + qreal curT = (qreal)m_system->timeInt/1000.0; + qreal ttl = (qreal)m_lifeLeft/1000.0; + if (!m_advancePosition && ttl > 0){ + qreal x = d->curX(); + qreal vx = d->curVX(); + qreal ax = d->curAX(); + qreal y = d->curY(); + qreal vy = d->curVY(); + qreal ay = d->curAY(); + d->t = curT - (d->lifeSpan - ttl); + d->setInstantaneousX(x); + d->setInstantaneousVX(vx); + d->setInstantaneousAX(ax); + d->setInstantaneousY(y); + d->setInstantaneousVY(vy); + d->setInstantaneousAY(ay); + } else { + d->t = curT - (d->lifeSpan - ttl); + } + return true; + } + return false; +} +QT_END_NAMESPACE diff --git a/src/declarative/particles/qquickage_p.h b/src/declarative/particles/qquickage_p.h new file mode 100644 index 0000000000..0adbddabe9 --- /dev/null +++ b/src/declarative/particles/qquickage_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 KILLAFFECTOR_H +#define KILLAFFECTOR_H +#include "qquickparticleaffector_p.h" + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + + +class QQuickAgeAffector : public QQuickParticleAffector +{ + Q_OBJECT + Q_PROPERTY(int lifeLeft READ lifeLeft WRITE setLifeLeft NOTIFY lifeLeftChanged) + Q_PROPERTY(bool advancePosition READ advancePosition WRITE setAdvancePosition NOTIFY advancePositionChanged) + +public: + explicit QQuickAgeAffector(QQuickItem *parent = 0); + + int lifeLeft() const + { + return m_lifeLeft; + } + + bool advancePosition() const + { + return m_advancePosition; + } + +protected: + virtual bool affectParticle(QQuickParticleData *d, qreal dt); +signals: + void lifeLeftChanged(int arg); + void advancePositionChanged(bool arg); + +public slots: + void setLifeLeft(int arg) + { + if (m_lifeLeft != arg) { + m_lifeLeft = arg; + emit lifeLeftChanged(arg); + } + } + + void setAdvancePosition(bool arg) + { + if (m_advancePosition != arg) { + m_advancePosition = arg; + emit advancePositionChanged(arg); + } + } + +private: + int m_lifeLeft; + bool m_advancePosition; +}; + +QT_END_NAMESPACE +QT_END_HEADER +#endif // KILLAFFECTOR_H diff --git a/src/declarative/particles/qquickangledirection.cpp b/src/declarative/particles/qquickangledirection.cpp new file mode 100644 index 0000000000..9ce422e8d1 --- /dev/null +++ b/src/declarative/particles/qquickangledirection.cpp @@ -0,0 +1,116 @@ +/**************************************************************************** +** +** 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 "qquickangledirection_p.h" +#include +QT_BEGIN_NAMESPACE +const qreal CONV = 0.017453292519943295; +/*! + \qmlclass AngleDirection QQuickAngleDirection + \inqmlmodule QtQuick.Particles 2 + \inherits Direction + \brief The AngleDirection element allows you to specify a direction that varies in angle + + The AngledDirection element allows both the specification of a direction by angle and magnitude, + as well as varying the parameters by angle or magnitude. +*/ +/*! + \qmlproperty real QtQuick.Particles2::AngleDirection::angle + This property specifies the base angle for the direction. + The angle of this direction will vary by no more than angleVariation + from this angle. + + Angle is specified by degrees clockwise from straight right. + + The default value is zero. +*/ +/*! + \qmlproperty real QtQuick.Particles2::AngleDirection::magnitude + This property specifies the base magnitude for the direction. + The magnitude of this direction will vary by no more than magnitudeVariation + from this magnitude. + + Magnitude is specified in units of pixels per second. + + The default value is zero. +*/ +/*! + \qmlproperty real QtQuick.Particles2::AngleDirection::angleVariation + This property specifies the maximum angle variation for the direction. + The angle of the direction will vary by up to angleVariation clockwise + and anticlockwise from the value specified in angle. + + Angle is specified by degrees clockwise from straight right. + + The default value is zero. +*/ +/*! + \qmlproperty real QtQuick.Particles2::AngleDirection::magnitudeVariation + This property specifies the base magnitude for the direction. + The magnitude of this direction will vary by no more than magnitudeVariation + from the base magnitude. + + Magnitude is specified in units of pixels per second. + + The default value is zero. +*/ +QQuickAngleDirection::QQuickAngleDirection(QObject *parent) : + QQuickDirection(parent) + , m_angle(0) + , m_magnitude(0) + , m_angleVariation(0) + , m_magnitudeVariation(0) +{ + +} + +const QPointF QQuickAngleDirection::sample(const QPointF &from) +{ + Q_UNUSED(from); + QPointF ret; + qreal theta = m_angle*CONV - m_angleVariation*CONV + rand()/float(RAND_MAX) * m_angleVariation*CONV * 2; + qreal mag = m_magnitude- m_magnitudeVariation + rand()/float(RAND_MAX) * m_magnitudeVariation * 2; + ret.setX(mag * cos(theta)); + ret.setY(mag * sin(theta)); + return ret; +} + +QT_END_NAMESPACE diff --git a/src/declarative/particles/qquickangledirection_p.h b/src/declarative/particles/qquickangledirection_p.h new file mode 100644 index 0000000000..7baf1a6c60 --- /dev/null +++ b/src/declarative/particles/qquickangledirection_p.h @@ -0,0 +1,133 @@ +/**************************************************************************** +** +** 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 QQuickANGLEDDIRECTION_H +#define QQuickANGLEDDIRECTION_H +#include "qquickdirection_p.h" +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QQuickAngleDirection : public QQuickDirection +{ + Q_OBJECT + Q_PROPERTY(qreal angle READ angle WRITE setAngle NOTIFY angleChanged) + Q_PROPERTY(qreal magnitude READ magnitude WRITE setMagnitude NOTIFY magnitudeChanged) + Q_PROPERTY(qreal angleVariation READ angleVariation WRITE setAngleVariation NOTIFY angleVariationChanged) + Q_PROPERTY(qreal magnitudeVariation READ magnitudeVariation WRITE setMagnitudeVariation NOTIFY magnitudeVariationChanged) +public: + explicit QQuickAngleDirection(QObject *parent = 0); + const QPointF sample(const QPointF &from); + qreal angle() const + { + return m_angle; + } + + qreal magnitude() const + { + return m_magnitude; + } + + qreal angleVariation() const + { + return m_angleVariation; + } + + qreal magnitudeVariation() const + { + return m_magnitudeVariation; + } + +signals: + + void angleChanged(qreal arg); + + void magnitudeChanged(qreal arg); + + void angleVariationChanged(qreal arg); + + void magnitudeVariationChanged(qreal arg); + +public slots: +void setAngle(qreal arg) +{ + if (m_angle != arg) { + m_angle = arg; + emit angleChanged(arg); + } +} + +void setMagnitude(qreal arg) +{ + if (m_magnitude != arg) { + m_magnitude = arg; + emit magnitudeChanged(arg); + } +} + +void setAngleVariation(qreal arg) +{ + if (m_angleVariation != arg) { + m_angleVariation = arg; + emit angleVariationChanged(arg); + } +} + +void setMagnitudeVariation(qreal arg) +{ + if (m_magnitudeVariation != arg) { + m_magnitudeVariation = arg; + emit magnitudeVariationChanged(arg); + } +} + +private: +qreal m_angle; +qreal m_magnitude; +qreal m_angleVariation; +qreal m_magnitudeVariation; +}; + +QT_END_NAMESPACE +QT_END_HEADER +#endif // QQuickANGLEDDIRECTION_H diff --git a/src/declarative/particles/qquickcumulativedirection.cpp b/src/declarative/particles/qquickcumulativedirection.cpp new file mode 100644 index 0000000000..2f09ea4505 --- /dev/null +++ b/src/declarative/particles/qquickcumulativedirection.cpp @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** 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 "qquickcumulativedirection_p.h" +QT_BEGIN_NAMESPACE + +/*! + \qmlclass CumulativeDirection QQuickCumulativeDirection + \inqmlmodule QtQuick.Particles 2 + \inherits Direction + \brief The CumulativeDirection element allows you to specify a direction made of other directions + + The CumulativeDirection element will act as a direction that sums the directions within it. +*/ +QQuickCumulativeDirection::QQuickCumulativeDirection(QObject *parent):QQuickDirection(parent) +{ +} + +QDeclarativeListProperty QQuickCumulativeDirection::directions() +{ + return QDeclarativeListProperty(this, m_directions);//TODO: Proper list property +} + +const QPointF QQuickCumulativeDirection::sample(const QPointF &from) +{ + QPointF ret; + foreach (QQuickDirection* dir, m_directions) + ret += dir->sample(from); + return ret; +} + +QT_END_NAMESPACE diff --git a/src/declarative/particles/qquickcumulativedirection_p.h b/src/declarative/particles/qquickcumulativedirection_p.h new file mode 100644 index 0000000000..af657821c2 --- /dev/null +++ b/src/declarative/particles/qquickcumulativedirection_p.h @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** 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 QQuickCUMULATIVEDIRECTION_P_H +#define QQuickCUMULATIVEDIRECTION_P_H +#include "qquickdirection_p.h" +#include +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QQuickCumulativeDirection : public QQuickDirection +{ + Q_OBJECT + Q_PROPERTY(QDeclarativeListProperty directions READ directions) + Q_CLASSINFO("DefaultProperty", "directions") +public: + explicit QQuickCumulativeDirection(QObject *parent = 0); + QDeclarativeListProperty directions(); + const QPointF sample(const QPointF &from); +private: + QList m_directions; +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // QQuickCUMULATIVEDIRECTION_P_H diff --git a/src/declarative/particles/qquickcustomaffector.cpp b/src/declarative/particles/qquickcustomaffector.cpp new file mode 100644 index 0000000000..80e2eaf268 --- /dev/null +++ b/src/declarative/particles/qquickcustomaffector.cpp @@ -0,0 +1,211 @@ +/**************************************************************************** +** +** 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 "qquickcustomaffector_p.h" +#include +#include +#include +#include +QT_BEGIN_NAMESPACE + +//TODO: Move docs (and inheritence) to real base when docs can propagate. Currently this pretends to be the base class! +/*! + \qmlsignal QtQuick.Particles2::Affector::affectParticles(Array particles, real dt) + + This handler is called when particles are selected to be affected. particles contains + an array of particle objects which can be directly manipulated. + + dt is the time since the last time it was affected. Use dt to normalize + trajectory manipulations to real time. + + Note that JS is slower to execute, so it is not recommended to use this in + high-volume particle systems. +*/ + +/*! + \qmlproperty StochasticDirection QtQuick.Particles2::Affector::position + + Affected particles will have their position set to this direction, + relative to the ParticleSystem. When interpreting directions as points, + imagine it as an arrow with the base at the 0,0 of the ParticleSystem and the + tip at where the specified position will be. +*/ + +/*! + \qmlproperty StochasticDirection QtQuick.Particles2::Affector::speed + + Affected particles will have their speed set to this direction. +*/ + + +/*! + \qmlproperty StochasticDirection QtQuick.Particles2::Affector::acceleration + + Affected particles will have their acceleration set to this direction. +*/ + + +/*! + \qmlproperty bool QtQuick.Particles2::Affector::relative + + Whether the affected particles have their existing position/speed/acceleration added + to the new one. + + Default is true. +*/ +QQuickCustomAffector::QQuickCustomAffector(QQuickItem *parent) : + QQuickParticleAffector(parent) + , m_position(&m_nullVector) + , m_speed(&m_nullVector) + , m_acceleration(&m_nullVector) + , m_relative(true) +{ +} + +bool QQuickCustomAffector::isAffectConnected() +{ + static int idx = QObjectPrivate::get(this)->signalIndex("affectParticles(QDeclarativeV8Handle,qreal)"); + return QObjectPrivate::get(this)->isSignalConnected(idx); +} + +void QQuickCustomAffector::affectSystem(qreal dt) +{ + if (!isAffectConnected()) { + QQuickParticleAffector::affectSystem(dt); + return; + } + if (!m_enabled) + return; + updateOffsets(); + + QList toAffect; + foreach (QQuickParticleGroupData* gd, m_system->groupData) + if (activeGroup(m_system->groupData.key(gd))) + foreach (QQuickParticleData* d, gd->data) + if (shouldAffect(d)) + toAffect << d; + + if (toAffect.isEmpty()) + return; + + if (m_onceOff) + dt = 1.0; + + v8::HandleScope handle_scope; + v8::Context::Scope scope(QDeclarativeEnginePrivate::getV8Engine(qmlEngine(this))->context()); + v8::Handle array = v8::Array::New(toAffect.size()); + for (int i=0; iSet(i, toAffect[i]->v8Value().toHandle()); + + if (dt >= simulationCutoff || dt <= simulationDelta) { + affectProperties(toAffect, dt); + emit affectParticles(QDeclarativeV8Handle::fromHandle(array), dt); + } else { + int realTime = m_system->timeInt; + m_system->timeInt -= dt * 1000.0; + while (dt > simulationDelta) { + m_system->timeInt += simulationDelta * 1000.0; + dt -= simulationDelta; + affectProperties(toAffect, simulationDelta); + emit affectParticles(QDeclarativeV8Handle::fromHandle(array), simulationDelta); + } + m_system->timeInt = realTime; + if (dt > 0.0) { + affectProperties(toAffect, dt); + emit affectParticles(QDeclarativeV8Handle::fromHandle(array), dt); + } + } + + foreach (QQuickParticleData* d, toAffect) + if (d->update == 1.0) + postAffect(d); +} + +bool QQuickCustomAffector::affectParticle(QQuickParticleData *d, qreal dt) +{ + //This does the property based affecting, called by superclass if signal isn't hooked up. + bool changed = false; + QPointF curPos(d->curX(), d->curY()); + + if (m_acceleration != &m_nullVector){ + QPointF pos = m_acceleration->sample(curPos); + if (m_relative) { + pos *= dt; + pos += QPointF(d->curAX(), d->curAY()); + } + d->setInstantaneousAX(pos.x()); + d->setInstantaneousAY(pos.y()); + changed = true; + } + + if (m_speed != &m_nullVector){ + QPointF pos = m_speed->sample(curPos); + if (m_relative) { + pos *= dt; + pos += QPointF(d->curVX(), d->curVY()); + } + d->setInstantaneousVX(pos.x()); + d->setInstantaneousVY(pos.y()); + changed = true; + } + + if (m_position != &m_nullVector){ + QPointF pos = m_position->sample(curPos); + if (m_relative) { + pos *= dt; + pos += curPos; + } + d->setInstantaneousX(pos.x()); + d->setInstantaneousY(pos.y()); + changed = true; + } + + return changed; +} + +void QQuickCustomAffector::affectProperties(const QList particles, qreal dt) +{ + foreach (QQuickParticleData* d, particles) + if ( affectParticle(d, dt) ) + d->update = 1.0; +} + +QT_END_NAMESPACE diff --git a/src/declarative/particles/qquickcustomaffector_p.h b/src/declarative/particles/qquickcustomaffector_p.h new file mode 100644 index 0000000000..e347107f50 --- /dev/null +++ b/src/declarative/particles/qquickcustomaffector_p.h @@ -0,0 +1,164 @@ +/**************************************************************************** +** +** 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 CUSTOMAFFECTOR_H +#define CUSTOMAFFECTOR_H + +#include +#include "qquickparticlesystem_p.h" +#include "qquickparticleextruder_p.h" +#include "qquickparticleaffector_p.h" +#include "qquickdirection_p.h" + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QQuickCustomAffector : public QQuickParticleAffector +{ + Q_OBJECT + Q_PROPERTY(bool relative READ relative WRITE setRelative NOTIFY relativeChanged) + Q_PROPERTY(QQuickDirection *position READ position WRITE setPosition NOTIFY positionChanged RESET positionReset) + Q_PROPERTY(QQuickDirection *speed READ speed WRITE setSpeed NOTIFY speedChanged RESET speedReset) + Q_PROPERTY(QQuickDirection *acceleration READ acceleration WRITE setAcceleration NOTIFY accelerationChanged RESET accelerationReset) + +public: + explicit QQuickCustomAffector(QQuickItem *parent = 0); + virtual void affectSystem(qreal dt); + + QQuickDirection * position() const + { + return m_position; + } + + QQuickDirection * speed() const + { + return m_speed; + } + + QQuickDirection * acceleration() const + { + return m_acceleration; + } + + void positionReset() + { + m_position = &m_nullVector; + } + + void speedReset() + { + m_speed = &m_nullVector; + } + + void accelerationReset() + { + m_acceleration = &m_nullVector; + } + + bool relative() const + { + return m_relative; + } + + +signals: + void affectParticles(QDeclarativeV8Handle particles, qreal dt); + + void positionChanged(QQuickDirection * arg); + + void speedChanged(QQuickDirection * arg); + + void accelerationChanged(QQuickDirection * arg); + + void relativeChanged(bool arg); + +public slots: + void setPosition(QQuickDirection * arg) + { + if (m_position != arg) { + m_position = arg; + emit positionChanged(arg); + } + } + + void setSpeed(QQuickDirection * arg) + { + if (m_speed != arg) { + m_speed = arg; + emit speedChanged(arg); + } + } + + void setAcceleration(QQuickDirection * arg) + { + if (m_acceleration != arg) { + m_acceleration = arg; + emit accelerationChanged(arg); + } + } + + void setRelative(bool arg) + { + if (m_relative != arg) { + m_relative = arg; + emit relativeChanged(arg); + } + } + +protected: + bool isAffectConnected(); + virtual bool affectParticle(QQuickParticleData *d, qreal dt); +private: + void affectProperties(const QList particles, qreal dt); + QQuickDirection * m_position; + QQuickDirection * m_speed; + QQuickDirection * m_acceleration; + + QQuickDirection m_nullVector; + bool m_relative; +}; + +QT_END_NAMESPACE +QT_END_HEADER +#endif // CUSTOMAFFECTOR_H diff --git a/src/declarative/particles/qquickcustomparticle.cpp b/src/declarative/particles/qquickcustomparticle.cpp new file mode 100644 index 0000000000..153dd273b6 --- /dev/null +++ b/src/declarative/particles/qquickcustomparticle.cpp @@ -0,0 +1,596 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative 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 "qquickcustomparticle_p.h" +#include +#include + +QT_BEGIN_NAMESPACE + +//Includes comments because the code isn't self explanatory +static const char qt_particles_template_vertex_code[] = + "attribute highp vec2 qt_ParticlePos;\n" + "attribute highp vec2 qt_ParticleTex;\n" + "attribute highp vec4 qt_ParticleData; // x = time, y = lifeSpan, z = size, w = endSize\n" + "attribute highp vec4 qt_ParticleVec; // x,y = constant speed, z,w = acceleration\n" + "attribute highp float qt_ParticleR;\n" + "uniform highp mat4 qt_Matrix;\n" + "uniform highp float qt_Timestamp;\n" + "varying highp vec2 qt_TexCoord0;\n" + "void defaultMain() {\n" + " qt_TexCoord0 = qt_ParticleTex;\n" + " highp float size = qt_ParticleData.z;\n" + " highp float endSize = qt_ParticleData.w;\n" + " highp float t = (qt_Timestamp - qt_ParticleData.x) / qt_ParticleData.y;\n" + " highp float currentSize = mix(size, endSize, t * t);\n" + " if (t < 0. || t > 1.)\n" + " currentSize = 0.;\n" + " highp vec2 pos = qt_ParticlePos\n" + " - currentSize / 2. + currentSize * qt_ParticleTex // adjust size\n" + " + qt_ParticleVec.xy * t * qt_ParticleData.y // apply speed vector..\n" + " + 0.5 * qt_ParticleVec.zw * pow(t * qt_ParticleData.y, 2.);\n" + " gl_Position = qt_Matrix * vec4(pos.x, pos.y, 0, 1);\n" + "}"; +static const char qt_particles_default_vertex_code[] = + "void main() { \n" + " defaultMain(); \n" + "}"; + +static const char qt_particles_default_fragment_code[] = + "uniform sampler2D source; \n" + "varying highp vec2 qt_TexCoord0; \n" + "uniform lowp float qt_Opacity; \n" + "void main() { \n" + " gl_FragColor = texture2D(source, qt_TexCoord0) * qt_Opacity; \n" + "}"; + +static QSGGeometry::Attribute PlainParticle_Attributes[] = { + QSGGeometry::Attribute::create(0, 2, GL_FLOAT, true), // Position + QSGGeometry::Attribute::create(1, 2, GL_FLOAT), // TexCoord + QSGGeometry::Attribute::create(2, 4, GL_FLOAT), // Data + QSGGeometry::Attribute::create(3, 4, GL_FLOAT), // Vectors + QSGGeometry::Attribute::create(4, 1, GL_FLOAT) // r +}; + +static QSGGeometry::AttributeSet PlainParticle_AttributeSet = +{ + 5, // Attribute Count + (2 + 2 + 4 + 4 + 1) * sizeof(float), + PlainParticle_Attributes +}; + +struct PlainVertex { + float x; + float y; + float tx; + float ty; + float t; + float lifeSpan; + float size; + float endSize; + float vx; + float vy; + float ax; + float ay; + float r; +}; + +struct PlainVertices { + PlainVertex v1; + PlainVertex v2; + PlainVertex v3; + PlainVertex v4; +}; + +/*! + \qmlclass CustomParticle QQuickCustomParticle + \inqmlmodule QtQuick.Particles 2 + \inherits ParticlePainter + \brief The CustomParticle element allows you to specify your own shader to paint particles. + +*/ + +QQuickCustomParticle::QQuickCustomParticle(QQuickItem* parent) + : QQuickParticlePainter(parent) + , m_dirtyData(true) + , m_material(0) + , m_rootNode(0) +{ + setFlag(QQuickItem::ItemHasContents); +} + +class QQuickShaderEffectMaterialObject : public QObject, public QQuickShaderEffectMaterial { }; + +QQuickCustomParticle::~QQuickCustomParticle() +{ + if (m_material) + m_material->deleteLater(); +} + +void QQuickCustomParticle::componentComplete() +{ + reset(); + QQuickParticlePainter::componentComplete(); +} + + +//Trying to keep the shader conventions the same as in qsgshadereffectitem +/*! + \qmlproperty string QtQuick.Particles2::CustomParticle::fragmentShader + + This property holds the fragment shader's GLSL source code. + The default shader expects the texture coordinate to be passed from the + vertex shader as "varying highp vec2 qt_TexCoord0", and it samples from a + sampler2D named "source". +*/ + +void QQuickCustomParticle::setFragmentShader(const QByteArray &code) +{ + if (m_source.fragmentCode.constData() == code.constData()) + return; + m_source.fragmentCode = code; + if (isComponentComplete()) { + reset(); + } + emit fragmentShaderChanged(); +} + +/*! + \qmlproperty string QtQuick.Particles2::CustomParticle::vertexShader + + This property holds the vertex shader's GLSL source code. + + The default shader passes the texture coordinate along to the fragment + shader as "varying highp vec2 qt_TexCoord0". + + To aid writing a particle vertex shader, the following GLSL code is prepended + to your vertex shader: + \code + attribute highp vec2 qt_ParticlePos; + attribute highp vec2 qt_ParticleTex; + attribute highp vec4 qt_ParticleData; // x = time, y = lifeSpan, z = size, w = endSize + attribute highp vec4 qt_ParticleVec; // x,y = constant speed, z,w = acceleration + attribute highp float qt_ParticleR; + uniform highp mat4 qt_Matrix; + uniform highp float qt_Timestamp; + varying highp vec2 qt_TexCoord0; + void defaultMain() { + qt_TexCoord0 = qt_ParticleTex; + highp float size = qt_ParticleData.z; + highp float endSize = qt_ParticleData.w; + highp float t = (qt_Timestamp - qt_ParticleData.x) / qt_ParticleData.y; + highp float currentSize = mix(size, endSize, t * t); + if (t < 0. || t > 1.) + currentSize = 0.; + highp vec2 pos = qt_ParticlePos + - currentSize / 2. + currentSize * qt_ParticleTex // adjust size + + qt_ParticleVec.xy * t * qt_ParticleData.y // apply speed vector.. + + 0.5 * qt_ParticleVec.zw * pow(t * qt_ParticleData.y, 2.); + gl_Position = qt_Matrix * vec4(pos.x, pos.y, 0, 1); + } + \endcode + + defaultMain() is the same code as in the default shader, you can call this for basic + particle functions and then add additional variables for custom effects. Note that + the vertex shader for particles is responsible for simulating the movement of particles + over time, the particle data itself only has the starting position and spawn time. +*/ + +void QQuickCustomParticle::setVertexShader(const QByteArray &code) +{ + if (m_source.vertexCode.constData() == code.constData()) + return; + m_source.vertexCode = code; + if (isComponentComplete()) { + reset(); + } + emit vertexShaderChanged(); +} + +void QQuickCustomParticle::reset() +{ + disconnectPropertySignals(); + + m_source.attributeNames.clear(); + m_source.uniformNames.clear(); + m_source.respectsOpacity = false; + m_source.respectsMatrix = false; + m_source.className = metaObject()->className(); + + for (int i = 0; i < m_sources.size(); ++i) { + const SourceData &source = m_sources.at(i); + delete source.mapper; + if (source.item && source.item->parentItem() == this) + source.item->setParentItem(0); + } + m_sources.clear(); + + QQuickParticlePainter::reset(); + m_pleaseReset = true; + update(); +} + + +void QQuickCustomParticle::changeSource(int index) +{ + Q_ASSERT(index >= 0 && index < m_sources.size()); + QVariant v = property(m_sources.at(index).name.constData()); + setSource(v, index); +} + +void QQuickCustomParticle::updateData() +{ + m_dirtyData = true; + update(); +} + +void QQuickCustomParticle::setSource(const QVariant &var, int index) +{ + Q_ASSERT(index >= 0 && index < m_sources.size()); + + SourceData &source = m_sources[index]; + + source.item = 0; + if (var.isNull()) { + return; + } else if (!qVariantCanConvert(var)) { + qWarning("Could not assign source of type '%s' to property '%s'.", var.typeName(), source.name.constData()); + return; + } + + QObject *obj = qVariantValue(var); + source.item = qobject_cast(obj); + if (!source.item || !source.item->isTextureProvider()) { + qWarning("ShaderEffect: source uniform [%s] is not assigned a valid texture provider: %s [%s]", + source.name.constData(), qPrintable(obj->objectName()), obj->metaObject()->className()); + return; + } + + // TODO: Copy better solution in QQuickShaderEffect when they find it. + // 'source.item' needs a canvas to get a scenegraph node. + // The easiest way to make sure it gets a canvas is to + // make it a part of the same item tree as 'this'. + if (source.item && source.item->parentItem() == 0) { + source.item->setParentItem(this); + source.item->setVisible(false); + } +} + +void QQuickCustomParticle::disconnectPropertySignals() +{ + disconnect(this, 0, this, SLOT(updateData())); + for (int i = 0; i < m_sources.size(); ++i) { + SourceData &source = m_sources[i]; + disconnect(this, 0, source.mapper, 0); + disconnect(source.mapper, 0, this, 0); + } +} + +void QQuickCustomParticle::connectPropertySignals() +{ + QSet::const_iterator it; + for (it = m_source.uniformNames.begin(); it != m_source.uniformNames.end(); ++it) { + int pi = metaObject()->indexOfProperty(it->constData()); + if (pi >= 0) { + QMetaProperty mp = metaObject()->property(pi); + if (!mp.hasNotifySignal()) + qWarning("QQuickCustomParticle: property '%s' does not have notification method!", it->constData()); + QByteArray signalName("2"); + signalName.append(mp.notifySignal().signature()); + connect(this, signalName, this, SLOT(updateData())); + } else { + qWarning("QQuickCustomParticle: '%s' does not have a matching property!", it->constData()); + } + } + for (int i = 0; i < m_sources.size(); ++i) { + SourceData &source = m_sources[i]; + int pi = metaObject()->indexOfProperty(source.name.constData()); + if (pi >= 0) { + QMetaProperty mp = metaObject()->property(pi); + QByteArray signalName("2"); + signalName.append(mp.notifySignal().signature()); + connect(this, signalName, source.mapper, SLOT(map())); + source.mapper->setMapping(this, i); + connect(source.mapper, SIGNAL(mapped(int)), this, SLOT(changeSource(int))); + } else { + qWarning("QQuickCustomParticle: '%s' does not have a matching source!", source.name.constData()); + } + } +} + +void QQuickCustomParticle::updateProperties() +{ + QByteArray vertexCode = m_source.vertexCode; + QByteArray fragmentCode = m_source.fragmentCode; + if (vertexCode.isEmpty()) + vertexCode = qt_particles_default_vertex_code; + if (fragmentCode.isEmpty()) + fragmentCode = qt_particles_default_fragment_code; + vertexCode = qt_particles_template_vertex_code + vertexCode; + + m_source.attributeNames.clear(); + m_source.attributeNames << "qt_ParticlePos" + << "qt_ParticleTex" + << "qt_ParticleData" + << "qt_ParticleVec" + << "qt_ParticleR"; + + lookThroughShaderCode(vertexCode); + lookThroughShaderCode(fragmentCode); + + if (!m_source.respectsMatrix) + qWarning("QQuickCustomParticle: Missing reference to \'qt_Matrix\'."); + if (!m_source.respectsOpacity) + qWarning("QQuickCustomParticle: Missing reference to \'qt_Opacity\'."); + + for (int i = 0; i < m_sources.size(); ++i) { + QVariant v = property(m_sources.at(i).name); + setSource(v, i); + } + + connectPropertySignals(); +} + +void QQuickCustomParticle::lookThroughShaderCode(const QByteArray &code) +{ + // Regexp for matching attributes and uniforms. + // In human readable form: attribute|uniform [lowp|mediump|highp] + static QRegExp re(QLatin1String("\\b(attribute|uniform)\\b\\s*\\b(?:lowp|mediump|highp)?\\b\\s*\\b(\\w+)\\b\\s*\\b(\\w+)")); + Q_ASSERT(re.isValid()); + + int pos = -1; + + QString wideCode = QString::fromLatin1(code.constData(), code.size()); + + while ((pos = re.indexIn(wideCode, pos + 1)) != -1) { + QByteArray decl = re.cap(1).toLatin1(); // uniform or attribute + QByteArray type = re.cap(2).toLatin1(); // type + QByteArray name = re.cap(3).toLatin1(); // variable name + + if (decl == "attribute") { + if (!m_source.attributeNames.contains(name)) + qWarning() << "Custom Particle: Unknown attribute " << name; + } else { + Q_ASSERT(decl == "uniform");//TODO: Shouldn't assert + + if (name == "qt_Matrix") { + m_source.respectsMatrix = true; + } else if (name == "qt_Opacity") { + m_source.respectsOpacity = true; + } else if (name == "qt_Timestamp") { + //Not strictly necessary + } else { + m_source.uniformNames.insert(name); + if (type == "sampler2D") { + SourceData d; + d.mapper = new QSignalMapper; + d.name = name; + d.item = 0; + m_sources.append(d); + } + } + } + } +} + +QSGNode *QQuickCustomParticle::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) +{ + Q_UNUSED(oldNode); + if (m_pleaseReset){ + + //delete m_material;//Shader effect item doesn't regen material? + + delete m_rootNode;//Automatically deletes children + m_rootNode = 0; + m_nodes.clear(); + m_pleaseReset = false; + m_dirtyData = false; + } + + if (m_system && m_system->isRunning() && !m_system->isPaused()){ + prepareNextFrame(); + if (m_rootNode) { + update(); + foreach (QSGGeometryNode* node, m_nodes) + node->markDirty(QSGNode::DirtyGeometry);//done in buildData? + } + } + + return m_rootNode; +} + +void QQuickCustomParticle::prepareNextFrame(){ + if (!m_rootNode) + m_rootNode = buildCustomNodes(); + if (!m_rootNode) + return; + + m_lastTime = m_system->systemSync(this) / 1000.; + if (m_dirtyData || true)//Currently this is how we update timestamp... potentially over expensive. + buildData(); +} + +QQuickShaderEffectNode* QQuickCustomParticle::buildCustomNodes() +{ +#ifdef QT_OPENGL_ES_2 + if (m_count * 4 > 0xffff) { + printf("CustomParticle: Too many particles... \n"); + return 0; + } +#endif + + if (m_count <= 0) { + printf("CustomParticle: Too few particles... \n"); + return 0; + } + + updateProperties(); + + QQuickShaderEffectProgram s = m_source; + if (s.fragmentCode.isEmpty()) + s.fragmentCode = qt_particles_default_fragment_code; + if (s.vertexCode.isEmpty()) + s.vertexCode = qt_particles_default_vertex_code; + + if (!m_material) { + m_material = new QQuickShaderEffectMaterialObject; + } + + s.vertexCode = qt_particles_template_vertex_code + s.vertexCode; + m_material->setProgramSource(s); + foreach (const QString &str, m_groups){ + int gIdx = m_system->groupIds[str]; + int count = m_system->groupData[gIdx]->size(); + + QQuickShaderEffectNode* node = new QQuickShaderEffectNode(); + m_nodes.insert(gIdx, node); + + node->setMaterial(m_material); + node->markDirty(QSGNode::DirtyMaterial); + + //Create Particle Geometry + int vCount = count * 4; + int iCount = count * 6; + QSGGeometry *g = new QSGGeometry(PlainParticle_AttributeSet, vCount, iCount); + g->setDrawingMode(GL_TRIANGLES); + node->setGeometry(g); + PlainVertex *vertices = (PlainVertex *) g->vertexData(); + for (int p=0; p < count; ++p) { + commit(gIdx, p); + vertices[0].tx = 0; + vertices[0].ty = 0; + + vertices[1].tx = 1; + vertices[1].ty = 0; + + vertices[2].tx = 0; + vertices[2].ty = 1; + + vertices[3].tx = 1; + vertices[3].ty = 1; + vertices += 4; + } + quint16 *indices = g->indexDataAsUShort(); + for (int i=0; i < count; ++i) { + int o = i * 4; + indices[0] = o; + indices[1] = o + 1; + indices[2] = o + 2; + indices[3] = o + 1; + indices[4] = o + 3; + indices[5] = o + 2; + indices += 6; + } + } + foreach (QQuickShaderEffectNode* node, m_nodes){ + if (node == *(m_nodes.begin())) + continue; + (*(m_nodes.begin()))->appendChildNode(node); + } + + return *(m_nodes.begin()); +} + + +void QQuickCustomParticle::buildData() +{ + if (!m_rootNode) + return; + const QByteArray timestampName("qt_Timestamp"); + QVector > values; + QVector > textures; + const QVector > &oldTextures = m_material->textureProviders(); + for (int i = 0; i < oldTextures.size(); ++i) { + QSGTextureProvider *t = oldTextures.at(i).second; + if (t) + foreach (QQuickShaderEffectNode* node, m_nodes) + disconnect(t, SIGNAL(textureChanged()), node, SLOT(markDirtyTexture())); + } + for (int i = 0; i < m_sources.size(); ++i) { + const SourceData &source = m_sources.at(i); + QSGTextureProvider *t = source.item->textureProvider(); + textures.append(qMakePair(source.name, t)); + if (t) + foreach (QQuickShaderEffectNode* node, m_nodes) + connect(t, SIGNAL(textureChanged()), node, SLOT(markDirtyTexture()), Qt::DirectConnection); + } + for (QSet::const_iterator it = m_source.uniformNames.begin(); + it != m_source.uniformNames.end(); ++it) { + values.append(qMakePair(*it, property(*it))); + } + values.append(qMakePair(timestampName, QVariant(m_lastTime))); + m_material->setUniforms(values); + m_material->setTextureProviders(textures); + m_dirtyData = false; + foreach (QQuickShaderEffectNode* node, m_nodes) + node->markDirty(QSGNode::DirtyMaterial); +} + +void QQuickCustomParticle::initialize(int gIdx, int pIdx) +{ + QQuickParticleData* datum = m_system->groupData[gIdx]->data[pIdx]; + datum->r = rand()/(qreal)RAND_MAX; +} + +void QQuickCustomParticle::commit(int gIdx, int pIdx) +{ + if (m_nodes[gIdx] == 0) + return; + + QQuickParticleData* datum = m_system->groupData[gIdx]->data[pIdx]; + PlainVertices *particles = (PlainVertices *) m_nodes[gIdx]->geometry()->vertexData(); + PlainVertex *vertices = (PlainVertex *)&particles[pIdx]; + for (int i=0; i<4; ++i) { + vertices[i].x = datum->x - m_systemOffset.x(); + vertices[i].y = datum->y - m_systemOffset.y(); + vertices[i].t = datum->t; + vertices[i].lifeSpan = datum->lifeSpan; + vertices[i].size = datum->size; + vertices[i].endSize = datum->endSize; + vertices[i].vx = datum->vx; + vertices[i].vy = datum->vy; + vertices[i].ax = datum->ax; + vertices[i].ay = datum->ay; + vertices[i].r = datum->r; + } +} + +QT_END_NAMESPACE diff --git a/src/declarative/particles/qquickcustomparticle_p.h b/src/declarative/particles/qquickcustomparticle_p.h new file mode 100644 index 0000000000..b3cf6d3e42 --- /dev/null +++ b/src/declarative/particles/qquickcustomparticle_p.h @@ -0,0 +1,121 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative 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 CUSTOM_PARTICLE_H +#define CUSTOM_PARTICLE_H +#include "qquickparticlepainter_p.h" +#include +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QSGNode; +struct PlainVertices; + +class QQuickShaderEffectMaterialObject; + +//Genealogy: Hybrid of UltraParticle and ShaderEffect +class QQuickCustomParticle : public QQuickParticlePainter +{ + Q_OBJECT + Q_PROPERTY(QByteArray fragmentShader READ fragmentShader WRITE setFragmentShader NOTIFY fragmentShaderChanged) + Q_PROPERTY(QByteArray vertexShader READ vertexShader WRITE setVertexShader NOTIFY vertexShaderChanged) + +public: + explicit QQuickCustomParticle(QQuickItem* parent=0); + ~QQuickCustomParticle(); + + QByteArray fragmentShader() const { return m_source.fragmentCode; } + void setFragmentShader(const QByteArray &code); + + QByteArray vertexShader() const { return m_source.vertexCode; } + void setVertexShader(const QByteArray &code); +public Q_SLOTS: + void updateData(); + void changeSource(int); +Q_SIGNALS: + void fragmentShaderChanged(); + void vertexShaderChanged(); +protected: + virtual void initialize(int gIdx, int pIdx); + virtual void commit(int gIdx, int pIdx); + + QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *); + void prepareNextFrame(); + void setSource(const QVariant &var, int index); + void disconnectPropertySignals(); + void connectPropertySignals(); + void reset(); + void resize(int oldCount, int newCount); + void updateProperties(); + void lookThroughShaderCode(const QByteArray &code); + virtual void componentComplete(); + QQuickShaderEffectNode *buildCustomNodes(); + void performPendingResize(); + +private: + void buildData(); + + bool m_dirtyData; + QQuickShaderEffectProgram m_source; + struct SourceData + { + QSignalMapper *mapper; + QPointer item; + QByteArray name; + }; + QVector m_sources; + QQuickShaderEffectMaterialObject *m_material; + QQuickShaderEffectNode* m_rootNode; + QHash m_nodes; + qreal m_lastTime; + +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif //HEADER_GUARD diff --git a/src/declarative/particles/qquickdirection.cpp b/src/declarative/particles/qquickdirection.cpp new file mode 100644 index 0000000000..babd35de9f --- /dev/null +++ b/src/declarative/particles/qquickdirection.cpp @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** 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 "qquickdirection_p.h" + +QT_BEGIN_NAMESPACE +/*! + \qmlclass Direction QQuickDirection + \inqmlmodule QtQuick.Particles 2 + \brief The Direction elements allow you to specify a vector space. + +*/ + + +QQuickDirection::QQuickDirection(QObject *parent) : + QObject(parent) +{ +} + +const QPointF QQuickDirection::sample(const QPointF &from) +{ + Q_UNUSED(from); + return QPointF(); +} + +QT_END_NAMESPACE diff --git a/src/declarative/particles/qquickdirection_p.h b/src/declarative/particles/qquickdirection_p.h new file mode 100644 index 0000000000..ac2ecdf9c1 --- /dev/null +++ b/src/declarative/particles/qquickdirection_p.h @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** 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 VARYINGVECTOR_H +#define VARYINGVECTOR_H + +#include +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + + +class QQuickDirection : public QObject +{ + Q_OBJECT +public: + explicit QQuickDirection(QObject *parent = 0); + + virtual const QPointF sample(const QPointF &from); +signals: + +public slots: + +protected: +}; + +QT_END_NAMESPACE +QT_END_HEADER +#endif // VARYINGVECTOR_H diff --git a/src/declarative/particles/qquickellipseextruder.cpp b/src/declarative/particles/qquickellipseextruder.cpp new file mode 100644 index 0000000000..479bbb4aa7 --- /dev/null +++ b/src/declarative/particles/qquickellipseextruder.cpp @@ -0,0 +1,80 @@ +/**************************************************************************** +** +** 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 "qquickellipseextruder_p.h" +#include +QT_BEGIN_NAMESPACE +/*! + \qmlclass EllipseShape QQuickEllipseExtruder + \inqmlmodule QtQuick.Particles 2 + \inherits Shape + \brief The EllipseShape represents an ellipse to other particle system elements + + This shape can be used by Emitter subclasses and Affector subclasses to have + them act upon an ellipse shaped area. +*/ +QQuickEllipseExtruder::QQuickEllipseExtruder(QObject *parent) : + QQuickParticleExtruder(parent) + , m_fill(true) +{ +} + +/*! + \qmlproperty bool QtQuick.Particles2::EllipseShape::fill + If fill is true the ellipse is filled; otherwise it is just a border. + + Default is true. +*/ + +QPointF QQuickEllipseExtruder::extrude(const QRectF & r) +{ + qreal theta = ((qreal)rand()/RAND_MAX) * 6.2831853071795862; + qreal mag = m_fill ? ((qreal)rand()/RAND_MAX) : 1; + return QPointF(r.x() + r.width()/2 + mag * (r.width()/2) * cos(theta), + r.y() + r.height()/2 + mag * (r.height()/2) * sin(theta)); +} + +bool QQuickEllipseExtruder::contains(const QRectF &bounds, const QPointF &point) +{ + return bounds.contains(point);//TODO: Ellipse +} + +QT_END_NAMESPACE diff --git a/src/declarative/particles/qquickellipseextruder_p.h b/src/declarative/particles/qquickellipseextruder_p.h new file mode 100644 index 0000000000..08e7e73d18 --- /dev/null +++ b/src/declarative/particles/qquickellipseextruder_p.h @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** 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 ELLIPSEEXTRUDER_H +#define ELLIPSEEXTRUDER_H +#include "qquickparticleextruder_p.h" + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + + +class QQuickEllipseExtruder : public QQuickParticleExtruder +{ + Q_OBJECT + Q_PROPERTY(bool fill READ fill WRITE setFill NOTIFY fillChanged)//###Use base class? If it's still box +public: + explicit QQuickEllipseExtruder(QObject *parent = 0); + virtual QPointF extrude(const QRectF &); + virtual bool contains(const QRectF &bounds, const QPointF &point); + + bool fill() const + { + return m_fill; + } + +signals: + + void fillChanged(bool arg); + +public slots: + + void setFill(bool arg) + { + if (m_fill != arg) { + m_fill = arg; + emit fillChanged(arg); + } + } +private: + bool m_fill; +}; + +QT_END_NAMESPACE +QT_END_HEADER +#endif // ELLIPSEEXTRUDER_H diff --git a/src/declarative/particles/qquickfriction.cpp b/src/declarative/particles/qquickfriction.cpp new file mode 100644 index 0000000000..c060deb95f --- /dev/null +++ b/src/declarative/particles/qquickfriction.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 "qquickfriction_p.h" +QT_BEGIN_NAMESPACE +/*! + \qmlclass Friction QQuickFrictionAffector + \inqmlmodule QtQuick.Particles 2 + \inherits Affector + \brief The Friction affector slows down movement proportional to the particle's current speed. + +*/ + +/*! + \qmlproperty real QtQuick.Particles2::Friction::factor + + A drag will be applied to moving objects which is this factor of their current velocity. +*/ +/*! + \qmlproperty real QtQuick.Particles2::Friction::threshold + + The drag will only be applied to objects with a velocity above the threshold velocity. The + drag applied will bring objects down to the threshold velocity, but no further. + + The default threshold is 0 +*/ +static qreal sign(qreal a) +{ + return a >= 0 ? 1 : -1; +} + +static const qreal epsilon = 0.00001; + +QQuickFrictionAffector::QQuickFrictionAffector(QQuickItem *parent) : + QQuickParticleAffector(parent), m_factor(0.0), m_threshold(0.0) +{ +} + +bool QQuickFrictionAffector::affectParticle(QQuickParticleData *d, qreal dt) +{ + if (!m_factor) + return false; + qreal curVX = d->curVX(); + qreal curVY = d->curVY(); + if (!curVX && !curVY) + return false; + qreal newVX = curVX + (curVX * m_factor * -1 * dt); + qreal newVY = curVY + (curVY * m_factor * -1 * dt); + + if (!m_threshold) { + if (sign(curVX) != sign(newVX)) + newVX = 0; + if (sign(curVY) != sign(newVY)) + newVY = 0; + } else { + qreal curMag = sqrt(curVX*curVX + curVY*curVY); + if (curMag <= m_threshold + epsilon) + return false; + qreal newMag = sqrt(newVX*newVX + newVY*newVY); + if (newMag <= m_threshold + epsilon || //went past the threshold, stop there instead + sign(curVX) != sign(newVX) || //went so far past maybe it came out the other side! + sign(curVY) != sign(newVY)) { + qreal theta = atan2(curVY, curVX); + newVX = m_threshold * cos(theta); + newVY = m_threshold * sin(theta); + } + } + + d->setInstantaneousVX(newVX); + d->setInstantaneousVY(newVY); + return true; +} +QT_END_NAMESPACE diff --git a/src/declarative/particles/qquickfriction_p.h b/src/declarative/particles/qquickfriction_p.h new file mode 100644 index 0000000000..c2f227692c --- /dev/null +++ b/src/declarative/particles/qquickfriction_p.h @@ -0,0 +1,104 @@ +/**************************************************************************** +** +** 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 FRICTIONAFFECTOR_H +#define FRICTIONAFFECTOR_H +#include "qquickparticleaffector_p.h" + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + + +class QQuickFrictionAffector : public QQuickParticleAffector +{ + Q_OBJECT + Q_PROPERTY(qreal factor READ factor WRITE setFactor NOTIFY factorChanged) + Q_PROPERTY(qreal threshold READ threshold WRITE setThreshold NOTIFY thresholdChanged) +public: + explicit QQuickFrictionAffector(QQuickItem *parent = 0); + + qreal factor() const + { + return m_factor; + } + + qreal threshold() const + { + return m_threshold; + } + +protected: + virtual bool affectParticle(QQuickParticleData *d, qreal dt); + +signals: + + void factorChanged(qreal arg); + void thresholdChanged(qreal arg); + +public slots: + + void setFactor(qreal arg) + { + if (m_factor != arg) { + m_factor = arg; + emit factorChanged(arg); + } + } + + void setThreshold(qreal arg) + { + if (m_threshold != arg) { + m_threshold = arg; + emit thresholdChanged(arg); + } + } + +private: + qreal m_factor; + qreal m_threshold; +}; + +QT_END_NAMESPACE +QT_END_HEADER +#endif // FRICTIONAFFECTOR_H diff --git a/src/declarative/particles/qquickgravity.cpp b/src/declarative/particles/qquickgravity.cpp new file mode 100644 index 0000000000..010fcb8d44 --- /dev/null +++ b/src/declarative/particles/qquickgravity.cpp @@ -0,0 +1,104 @@ +/**************************************************************************** +** +** 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 "qquickgravity_p.h" +#include +QT_BEGIN_NAMESPACE +const qreal CONV = 0.017453292520444443; +/*! + \qmlclass Gravity QQuickGravityAffector + \inqmlmodule QtQuick.Particles 2 + \inherits Affector + \brief The Gravity element allows you to set a constant accleration in an angle + + This element will set the acceleration of all affected particles to a vector of + the specified magnitude in the specified angle. If the angle or acceleration is + not varying, it is more efficient to set the specified acceleration on the Emitter. + + This element models the gravity of a massive object whose center of + gravity is far away (and thus the gravitational pull is effectively constant + across the scene). To model the gravity of an object near or inside the scene, + use PointAttractor. +*/ + +/*! + \qmlproperty real QtQuick.Particles2::Gravity::acceleration + + Pixels per second that objects will be accelerated by. +*/ +/*! + \qmlproperty real QtQuick.Particles2::Gravity::angle + + Angle of acceleration. +*/ + +QQuickGravityAffector::QQuickGravityAffector(QQuickItem *parent) : + QQuickParticleAffector(parent), m_acceleration(-10), m_angle(90), m_xAcc(0), m_yAcc(0) +{ + connect(this, SIGNAL(accelerationChanged(qreal)), + this, SLOT(recalc())); + connect(this, SIGNAL(angleChanged(qreal)), + this, SLOT(recalc())); + recalc(); +} + +void QQuickGravityAffector::recalc() +{ + qreal theta = m_angle * CONV; + m_xAcc = m_acceleration * cos(theta); + m_yAcc = m_acceleration * sin(theta); +} + +bool QQuickGravityAffector::affectParticle(QQuickParticleData *d, qreal dt) +{ + Q_UNUSED(dt); + bool changed = false; + if (d->ax != m_xAcc){ + d->setInstantaneousAX(m_xAcc); + changed = true; + } + if (d->ay != m_yAcc){ + d->setInstantaneousAY(m_yAcc); + changed = true; + } + return changed; +} +QT_END_NAMESPACE diff --git a/src/declarative/particles/qquickgravity_p.h b/src/declarative/particles/qquickgravity_p.h new file mode 100644 index 0000000000..b02eb49a7c --- /dev/null +++ b/src/declarative/particles/qquickgravity_p.h @@ -0,0 +1,106 @@ +/**************************************************************************** +** +** 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 GRAVITYAFFECTOR_H +#define GRAVITYAFFECTOR_H +#include "qquickparticleaffector_p.h" + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + + +class QQuickGravityAffector : public QQuickParticleAffector +{ + Q_OBJECT + Q_PROPERTY(qreal acceleration READ acceleration WRITE setAcceleration NOTIFY accelerationChanged) + Q_PROPERTY(qreal angle READ angle WRITE setAngle NOTIFY angleChanged) +public: + explicit QQuickGravityAffector(QQuickItem *parent = 0); + qreal acceleration() const + { + return m_acceleration; + } + + qreal angle() const + { + return m_angle; + } +protected: + virtual bool affectParticle(QQuickParticleData *d, qreal dt); +signals: + + void accelerationChanged(qreal arg); + + void angleChanged(qreal arg); + +public slots: +void setAcceleration(qreal arg) +{ + if (m_acceleration != arg) { + m_acceleration = arg; + emit accelerationChanged(arg); + } +} + +void setAngle(qreal arg) +{ + if (m_angle != arg) { + m_angle = arg; + emit angleChanged(arg); + } +} + +private slots: + void recalc(); +private: + qreal m_acceleration; + qreal m_angle; + + qreal m_xAcc; + qreal m_yAcc; +}; + +QT_END_NAMESPACE +QT_END_HEADER +#endif // GRAVITYAFFECTOR_H diff --git a/src/declarative/particles/qquickgroupgoal.cpp b/src/declarative/particles/qquickgroupgoal.cpp new file mode 100644 index 0000000000..1d8a3d980c --- /dev/null +++ b/src/declarative/particles/qquickgroupgoal.cpp @@ -0,0 +1,112 @@ +/**************************************************************************** +** +** 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 "qquickgroupgoal_p.h" +#include +#include +#include "qquickimageparticle_p.h" +#include + +QT_BEGIN_NAMESPACE + +/*! + \qmlclass GroupGoal QQuickGroupGoalAffector + \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. +*/ + +QQuickGroupGoalAffector::QQuickGroupGoalAffector(QQuickItem *parent) : + QQuickParticleAffector(parent), m_jump(false) +{ + m_ignoresTime = true; +} + +void QQuickGroupGoalAffector::setGoalState(QString arg) +{ + if (m_goalState != arg) { + m_goalState = arg; + emit goalStateChanged(arg); + } +} + +bool QQuickGroupGoalAffector::affectParticle(QQuickParticleData *d, qreal dt) +{ + Q_UNUSED(dt); + QQuickStochasticEngine *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/qquickgroupgoal_p.h b/src/declarative/particles/qquickgroupgoal_p.h new file mode 100644 index 0000000000..51ce1ff24e --- /dev/null +++ b/src/declarative/particles/qquickgroupgoal_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 "qquickparticleaffector_p.h" + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QQuickStochasticEngine; + +class QQuickGroupGoalAffector : public QQuickParticleAffector +{ + Q_OBJECT + Q_PROPERTY(QString goalState READ goalState WRITE setGoalState NOTIFY goalStateChanged) + Q_PROPERTY(bool jump READ jump WRITE setJump NOTIFY jumpChanged) +public: + explicit QQuickGroupGoalAffector(QQuickItem *parent = 0); + + QString goalState() const + { + return m_goalState; + } + + bool jump() const + { + return m_jump; + } + +protected: + virtual bool affectParticle(QQuickParticleData *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/qquickimageparticle.cpp b/src/declarative/particles/qquickimageparticle.cpp new file mode 100644 index 0000000000..4c9e2662a1 --- /dev/null +++ b/src/declarative/particles/qquickimageparticle.cpp @@ -0,0 +1,1773 @@ +/**************************************************************************** +** +** 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 +#include +#include +#include +#include +#include +#include "qquickimageparticle_p.h" +#include "qquickparticleemitter_p.h" +#include +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE +//###Switch to define later, for now user-friendly (no compilation) debugging is worth it +DEFINE_BOOL_CONFIG_OPTION(qmlParticlesDebug, QML_PARTICLES_DEBUG) + +#ifndef QT_OPENGL_ES_2 +#define SHADER_DEFINES "#version 120\n" +#else +#define SHADER_DEFINES "" +#endif + +//TODO: Make it larger on desktop? Requires fixing up shader code with the same define +#define UNIFORM_ARRAY_SIZE 64 + +static const char vertexShaderCode[] = + "attribute highp vec2 vPos;\n" + "attribute highp vec4 vData; // x = time, y = lifeSpan, z = size, w = endSize\n" + "attribute highp vec4 vVec; // x,y = constant speed, z,w = acceleration\n" + "uniform highp float entry;\n" + "#ifdef COLOR\n" + "attribute lowp vec4 vColor;\n" + "#endif\n" + "#ifdef DEFORM\n" + "attribute highp vec2 vTex;\n" + "attribute highp vec4 vDeformVec; //x,y x unit vector; z,w = y unit vector\n" + "attribute highp vec3 vRotation; //x = radians of rotation, y=rotation speed, z= bool autoRotate\n" + "#endif\n" + "#ifdef SPRITE\n" + "attribute highp vec4 vAnimData;// interpolate(bool), duration, frameCount (this anim), timestamp (this anim)\n" + "attribute highp vec4 vAnimPos;//sheet x,y, width/height of this anim\n" + "uniform highp vec2 animSheetSize; //width/height of whole sheet\n" + "#endif\n" + "\n" + "uniform highp mat4 qt_Matrix;\n" + "uniform highp float timestamp;\n" + "#ifdef TABLE\n" + "varying lowp vec2 tt;//y is progress if Sprite mode\n" + "uniform highp float sizetable[64];\n" + "uniform highp float opacitytable[64];\n" + "#endif\n" + "#ifdef SPRITE\n" + "varying highp vec4 fTexS;\n" + "#else\n" + "#ifdef DEFORM\n" + "varying highp vec2 fTex;\n" + "#endif\n" + "#endif\n" + "#ifdef COLOR\n" + "varying lowp vec4 fColor;\n" + "#else\n" + "varying lowp float fFade;\n" + "#endif\n" + "\n" + "\n" + "void main() {\n" + "\n" + " highp float t = (timestamp - vData.x) / vData.y;\n" + " if (t < 0. || t > 1.){\n" + "#ifdef DEFORM //Not point sprites\n" + " gl_Position = qt_Matrix * vec4(vPos.x, vPos.y, 0., 1.);\n" + "#else\n" + " gl_PointSize = 0.;\n" + "#endif\n" + " return;\n" + " }\n" + "#ifdef SPRITE\n" + " //Calculate frame location in texture\n" + " highp float frameIndex = mod((((timestamp - vAnimData.w)*1000.)/vAnimData.y),vAnimData.z);\n" + " tt.y = mod((timestamp - vAnimData.w)*1000., vAnimData.y) / vAnimData.y;\n" + "\n" + " frameIndex = floor(frameIndex);\n" + " fTexS.xy = vec2(((frameIndex + vTex.x) * vAnimPos.z / animSheetSize.x), ((vAnimPos.y + vTex.y * vAnimPos.w) / animSheetSize.y));\n" + "\n" + " //Next frame is also passed, for interpolation\n" + " //### Should the next anim be precalculated to allow for interpolation there?\n" + " if (vAnimData.x == 1.0 && frameIndex != vAnimData.z - 1.)//Can't do it for the last frame though, this anim may not loop\n" + " frameIndex = mod(frameIndex+1., vAnimData.z);\n" + " fTexS.zw = vec2(((frameIndex + vTex.x) * vAnimPos.z / animSheetSize.x), ((vAnimPos.y + vTex.y * vAnimPos.w) / animSheetSize.y));\n" + "#else\n" + "#ifdef DEFORM\n" + " fTex = vTex;\n" + "#endif\n" + "#endif\n" + " highp float currentSize = mix(vData.z, vData.w, t * t);\n" + " lowp float fade = 1.;\n" + " highp float fadeIn = min(t * 10., 1.);\n" + " highp float fadeOut = 1. - clamp((t - 0.75) * 4.,0., 1.);\n" + "\n" + "#ifdef TABLE\n" + " currentSize = currentSize * sizetable[int(floor(t*64.))];\n" + " fade = fade * opacitytable[int(floor(t*64.))];\n" + "#endif\n" + "\n" + " if (entry == 1.)\n" + " fade = fade * fadeIn * fadeOut;\n" + " else if (entry == 2.)\n" + " currentSize = currentSize * fadeIn * fadeOut;\n" + "\n" + " if (currentSize <= 0)//Sizes too small look jittery as they move\n" + " currentSize = 0;\n" + " else if (currentSize < 3)\n" + " currentSize = 3;\n" + "\n" + " highp vec2 pos;\n" + "#ifdef DEFORM\n" + " highp float rotation = vRotation.x + vRotation.y * t * vData.y;\n" + " if (vRotation.z == 1.0){\n" + " highp vec2 curVel = vVec.zw * t * vData.y + vVec.xy;\n" + " rotation += atan(curVel.y, curVel.x);\n" + " }\n" + " highp vec2 trigCalcs = vec2(cos(rotation), sin(rotation));\n" + " highp vec4 deform = vDeformVec * currentSize * (vTex.xxyy - 0.5);\n" + " highp vec4 rotatedDeform = deform.xxzz * trigCalcs.xyxy;\n" + " rotatedDeform = rotatedDeform + (deform.yyww * trigCalcs.yxyx * vec4(-1.,1.,-1.,1.));\n" + " /* The readable version:\n" + " highp vec2 xDeform = vDeformVec.xy * currentSize * (vTex.x-0.5);\n" + " highp vec2 yDeform = vDeformVec.zw * currentSize * (vTex.y-0.5);\n" + " highp vec2 xRotatedDeform;\n" + " xRotatedDeform.x = trigCalcs.x*xDeform.x - trigCalcs.y*xDeform.y;\n" + " xRotatedDeform.y = trigCalcs.y*xDeform.x + trigCalcs.x*xDeform.y;\n" + " highp vec2 yRotatedDeform;\n" + " yRotatedDeform.x = trigCalcs.x*yDeform.x - trigCalcs.y*yDeform.y;\n" + " yRotatedDeform.y = trigCalcs.y*yDeform.x + trigCalcs.x*yDeform.y;\n" + " */\n" + " pos = vPos\n" + " + rotatedDeform.xy\n" + " + rotatedDeform.zw\n" + " + vVec.xy * t * vData.y // apply speed\n" + " + 0.5 * vVec.zw * pow(t * vData.y, 2.); // apply acceleration\n" + "#else\n" + " pos = vPos\n" + " + vVec.xy * t * vData.y // apply speed vector..\n" + " + 0.5 * vVec.zw * pow(t * vData.y, 2.);\n" + " gl_PointSize = currentSize;\n" + "#endif\n" + " gl_Position = qt_Matrix * vec4(pos.x, pos.y, 0, 1);\n" + "\n" + "#ifdef COLOR\n" + " fColor = vColor * fade;\n" + "#else\n" + " fFade = fade;\n" + "#endif\n" + "#ifdef TABLE\n" + " tt.x = t;\n" + "#endif\n" + "}\n"; + +static const char fragmentShaderCode[] = + "uniform sampler2D texture;\n" + "uniform lowp float qt_Opacity;\n" + "\n" + "#ifdef SPRITE\n" + "varying highp vec4 fTexS;\n" + "#else\n" + "#ifdef DEFORM //First non-pointsprite\n" + "varying highp vec2 fTex;\n" + "#endif\n" + "#endif\n" + "#ifdef COLOR\n" + "varying lowp vec4 fColor;\n" + "#else\n" + "varying lowp float fFade;\n" + "#endif\n" + "#ifdef TABLE\n" + "varying lowp vec2 tt;\n" + "uniform sampler2D colortable;\n" + "#endif\n" + "\n" + "void main() {\n" + "#ifdef SPRITE\n" + " gl_FragColor = mix(texture2D(texture, fTexS.xy), texture2D(texture, fTexS.zw), tt.y)\n" + " * fColor\n" + " * texture2D(colortable, tt)\n" + " * qt_Opacity;\n" + "#else\n" + "#ifdef TABLE\n" + " gl_FragColor = texture2D(texture, fTex)\n" + " * fColor\n" + " * texture2D(colortable, tt)\n" + " * qt_Opacity;\n" + "#else\n" + "#ifdef DEFORM\n" + " gl_FragColor = (texture2D(texture, fTex)) * fColor * qt_Opacity;\n" + "#else\n" + "#ifdef COLOR\n" + " gl_FragColor = (texture2D(texture, gl_PointCoord)) * fColor * qt_Opacity;\n" + "#else\n" + " gl_FragColor = texture2D(texture, gl_PointCoord) * (fFade * qt_Opacity);\n" + "#endif //COLOR\n" + "#endif //DEFORM\n" + "#endif //TABLE\n" + "#endif //SPRITE\n" + "}\n"; + +const qreal CONV = 0.017453292519943295; +class ImageMaterialData +{ + public: + ImageMaterialData() + : texture(0), colorTable(0) + {} + + ~ImageMaterialData(){ + delete texture; + delete colorTable; + } + + QSGTexture *texture; + QSGTexture *colorTable; + float sizeTable[UNIFORM_ARRAY_SIZE]; + float opacityTable[UNIFORM_ARRAY_SIZE]; + + qreal timestamp; + qreal entry; + QSizeF animSheetSize; +}; + +class TabledMaterialData : public ImageMaterialData {}; +class TabledMaterial : public QSGSimpleMaterialShader +{ + QSG_DECLARE_SIMPLE_SHADER(TabledMaterial, TabledMaterialData) + +public: + TabledMaterial() + { + m_vertex_code = QByteArray(SHADER_DEFINES) + + QByteArray("#define TABLE\n#define DEFORM\n#define COLOR\n") + + vertexShaderCode; + + m_fragment_code = QByteArray(SHADER_DEFINES) + + QByteArray("#define TABLE\n#define DEFORM\n#define COLOR\n") + + fragmentShaderCode; + + Q_ASSERT(!m_vertex_code.isNull()); + Q_ASSERT(!m_fragment_code.isNull()); + } + + const char *vertexShader() const { return m_vertex_code.constData(); } + const char *fragmentShader() const { return m_fragment_code.constData(); } + + QList attributes() const { + return QList() << "vPos" << "vTex" << "vData" << "vVec" + << "vColor" << "vDeformVec" << "vRotation"; + }; + + void initialize() { + QSGSimpleMaterialShader::initialize(); + program()->bind(); + program()->setUniformValue("texture", 0); + program()->setUniformValue("colortable", 1); + glFuncs = QOpenGLContext::currentContext()->functions(); + m_timestamp_id = program()->uniformLocation("timestamp"); + m_entry_id = program()->uniformLocation("entry"); + m_sizetable_id = program()->uniformLocation("sizetable"); + m_opacitytable_id = program()->uniformLocation("opacitytable"); + } + + void updateState(const TabledMaterialData* d, const TabledMaterialData*) { + glFuncs->glActiveTexture(GL_TEXTURE1); + d->colorTable->bind(); + + glFuncs->glActiveTexture(GL_TEXTURE0); + d->texture->bind(); + + program()->setUniformValue(m_timestamp_id, (float) d->timestamp); + program()->setUniformValue(m_entry_id, (float) d->entry); + program()->setUniformValueArray(m_sizetable_id, (float*) d->sizeTable, UNIFORM_ARRAY_SIZE, 1); + program()->setUniformValueArray(m_opacitytable_id, (float*) d->opacityTable, UNIFORM_ARRAY_SIZE, 1); + } + + int m_entry_id; + int m_timestamp_id; + int m_sizetable_id; + int m_opacitytable_id; + QByteArray m_vertex_code; + QByteArray m_fragment_code; + QOpenGLFunctions* glFuncs; +}; + +class DeformableMaterialData : public ImageMaterialData {}; +class DeformableMaterial : public QSGSimpleMaterialShader +{ + QSG_DECLARE_SIMPLE_SHADER(DeformableMaterial, DeformableMaterialData) + +public: + DeformableMaterial() + { + m_vertex_code = QByteArray(SHADER_DEFINES) + + QByteArray("#define DEFORM\n#define COLOR\n") + + vertexShaderCode; + + m_fragment_code = QByteArray(SHADER_DEFINES) + + QByteArray("#define DEFORM\n#define COLOR\n") + + fragmentShaderCode; + + Q_ASSERT(!m_vertex_code.isNull()); + Q_ASSERT(!m_fragment_code.isNull()); + } + + const char *vertexShader() const { return m_vertex_code.constData(); } + const char *fragmentShader() const { return m_fragment_code.constData(); } + + QList attributes() const { + return QList() << "vPos" << "vTex" << "vData" << "vVec" + << "vColor" << "vDeformVec" << "vRotation"; + }; + + void initialize() { + QSGSimpleMaterialShader::initialize(); + program()->bind(); + program()->setUniformValue("texture", 0); + glFuncs = QOpenGLContext::currentContext()->functions(); + m_timestamp_id = program()->uniformLocation("timestamp"); + m_entry_id = program()->uniformLocation("entry"); + } + + void updateState(const DeformableMaterialData* d, const DeformableMaterialData*) { + glFuncs->glActiveTexture(GL_TEXTURE0); + d->texture->bind(); + + program()->setUniformValue(m_timestamp_id, (float) d->timestamp); + program()->setUniformValue(m_entry_id, (float) d->entry); + } + + int m_entry_id; + int m_timestamp_id; + QByteArray m_vertex_code; + QByteArray m_fragment_code; + QOpenGLFunctions* glFuncs; +}; + +class SpriteMaterialData : public ImageMaterialData {}; +class SpriteMaterial : public QSGSimpleMaterialShader +{ + QSG_DECLARE_SIMPLE_SHADER(SpriteMaterial, SpriteMaterialData) + +public: + SpriteMaterial() + { + m_vertex_code = QByteArray(SHADER_DEFINES) + + QByteArray("#define SPRITE\n#define TABLE\n#define DEFORM\n#define COLOR\n") + + vertexShaderCode; + + m_fragment_code = QByteArray(SHADER_DEFINES) + + QByteArray("#define SPRITE\n#define TABLE\n#define DEFORM\n#define COLOR\n") + + fragmentShaderCode; + + Q_ASSERT(!m_vertex_code.isNull()); + Q_ASSERT(!m_fragment_code.isNull()); + } + + const char *vertexShader() const { return m_vertex_code.constData(); } + const char *fragmentShader() const { return m_fragment_code.constData(); } + + QList attributes() const { + return QList() << "vPos" << "vTex" << "vData" << "vVec" + << "vColor" << "vDeformVec" << "vRotation" << "vAnimData" << "vAnimPos"; + }; + + void initialize() { + QSGSimpleMaterialShader::initialize(); + program()->bind(); + program()->setUniformValue("texture", 0); + program()->setUniformValue("colortable", 1); + glFuncs = QOpenGLContext::currentContext()->functions(); + m_timestamp_id = program()->uniformLocation("timestamp"); + m_animsize_id = program()->uniformLocation("animSheetSize"); + m_entry_id = program()->uniformLocation("entry"); + m_sizetable_id = program()->uniformLocation("sizetable"); + m_opacitytable_id = program()->uniformLocation("opacitytable"); + } + + void updateState(const SpriteMaterialData* d, const SpriteMaterialData*) { + glFuncs->glActiveTexture(GL_TEXTURE1); + d->colorTable->bind(); + + // make sure we end by setting GL_TEXTURE0 as active texture + glFuncs->glActiveTexture(GL_TEXTURE0); + d->texture->bind(); + + program()->setUniformValue(m_timestamp_id, (float) d->timestamp); + program()->setUniformValue(m_animsize_id, d->animSheetSize); + program()->setUniformValue(m_entry_id, (float) d->entry); + program()->setUniformValueArray(m_sizetable_id, (float*) d->sizeTable, 64, 1); + program()->setUniformValueArray(m_opacitytable_id, (float*) d->opacityTable, UNIFORM_ARRAY_SIZE, 1); + } + + int m_timestamp_id; + int m_animsize_id; + int m_entry_id; + int m_sizetable_id; + int m_opacitytable_id; + QByteArray m_vertex_code; + QByteArray m_fragment_code; + QOpenGLFunctions* glFuncs; +}; + +class ColoredMaterialData : public ImageMaterialData {}; +class ColoredMaterial : public QSGSimpleMaterialShader +{ + QSG_DECLARE_SIMPLE_SHADER(ColoredMaterial, ColoredMaterialData) + +public: + ColoredMaterial() + { + m_vertex_code = QByteArray(SHADER_DEFINES) + + QByteArray("#define COLOR\n") + + vertexShaderCode; + + m_fragment_code = QByteArray(SHADER_DEFINES) + + QByteArray("#define COLOR\n") + + fragmentShaderCode; + + Q_ASSERT(!m_vertex_code.isNull()); + Q_ASSERT(!m_fragment_code.isNull()); + } + + const char *vertexShader() const { return m_vertex_code.constData(); } + const char *fragmentShader() const { return m_fragment_code.constData(); } + + void activate() { + QSGSimpleMaterialShader::activate(); +#if !defined(QT_OPENGL_ES_2) && !defined(Q_OS_WIN) + glEnable(GL_POINT_SPRITE); + glEnable(GL_VERTEX_PROGRAM_POINT_SIZE); +#endif + } + + void deactivate() { + QSGSimpleMaterialShader::deactivate(); +#if !defined(QT_OPENGL_ES_2) && !defined(Q_OS_WIN) + glDisable(GL_POINT_SPRITE); + glDisable(GL_VERTEX_PROGRAM_POINT_SIZE); +#endif + } + + QList attributes() const { + return QList() << "vPos" << "vData" << "vVec" << "vColor"; + } + + void initialize() { + QSGSimpleMaterialShader::initialize(); + program()->bind(); + program()->setUniformValue("texture", 0); + glFuncs = QOpenGLContext::currentContext()->functions(); + m_timestamp_id = program()->uniformLocation("timestamp"); + m_entry_id = program()->uniformLocation("entry"); + } + + void updateState(const ColoredMaterialData* d, const ColoredMaterialData*) { + glFuncs->glActiveTexture(GL_TEXTURE0); + d->texture->bind(); + + program()->setUniformValue(m_timestamp_id, (float) d->timestamp); + program()->setUniformValue(m_entry_id, (float) d->entry); + } + + int m_timestamp_id; + int m_entry_id; + QByteArray m_vertex_code; + QByteArray m_fragment_code; + QOpenGLFunctions* glFuncs; +}; + +class SimpleMaterialData : public ImageMaterialData {}; +class SimpleMaterial : public QSGSimpleMaterialShader +{ + QSG_DECLARE_SIMPLE_SHADER(SimpleMaterial, SimpleMaterialData) + +public: + SimpleMaterial() + { + m_vertex_code = QByteArray(SHADER_DEFINES) + + vertexShaderCode; + + m_fragment_code = QByteArray(SHADER_DEFINES) + + fragmentShaderCode; + + Q_ASSERT(!m_vertex_code.isNull()); + Q_ASSERT(!m_fragment_code.isNull()); + } + + const char *vertexShader() const { return m_vertex_code.constData(); } + const char *fragmentShader() const { return m_fragment_code.constData(); } + + void activate() { + QSGSimpleMaterialShader::activate(); +#if !defined(QT_OPENGL_ES_2) && !defined(Q_OS_WIN) + glEnable(GL_POINT_SPRITE); + glEnable(GL_VERTEX_PROGRAM_POINT_SIZE); +#endif + } + + void deactivate() { + QSGSimpleMaterialShader::deactivate(); +#if !defined(QT_OPENGL_ES_2) && !defined(Q_OS_WIN) + glDisable(GL_POINT_SPRITE); + glDisable(GL_VERTEX_PROGRAM_POINT_SIZE); +#endif + } + + QList attributes() const { + return QList() << "vPos" << "vData" << "vVec"; + } + + void initialize() { + QSGSimpleMaterialShader::initialize(); + program()->bind(); + program()->setUniformValue("texture", 0); + glFuncs = QOpenGLContext::currentContext()->functions(); + m_timestamp_id = program()->uniformLocation("timestamp"); + m_entry_id = program()->uniformLocation("entry"); + } + + void updateState(const SimpleMaterialData* d, const SimpleMaterialData*) { + glFuncs->glActiveTexture(GL_TEXTURE0); + d->texture->bind(); + + program()->setUniformValue(m_timestamp_id, (float) d->timestamp); + program()->setUniformValue(m_entry_id, (float) d->entry); + } + + int m_timestamp_id; + int m_entry_id; + QByteArray m_vertex_code; + QByteArray m_fragment_code; + QOpenGLFunctions* glFuncs; +}; + +void fillUniformArrayFromImage(float* array, const QImage& img, int size) +{ + if (img.isNull()){ + for (int i=0; i QtQuick.Particles2::ImageParticle::sprites + + The sprite or sprites used to draw this particle. + + Note that the sprite image will be scaled to a square based on the size of + the particle being rendered. +*/ +/*! + \qmlproperty url QtQuick.Particles2::ImageParticle::colorTable + + An image whose color will be used as a 1D texture to determine color over life. E.g. when + the particle is halfway through its lifetime, it will have the color specified halfway + across the image. + + This color is blended with the color property and the color of the source image. +*/ +/*! + \qmlproperty url QtQuick.Particles2::ImageParticle::sizeTable + + An image whose opacity will be used as a 1D texture to determine size over life. + + This property is expected to be removed shortly, in favor of custom easing curves to determine size over life. +*/ +/*! + \qmlproperty url QtQuick.Particles2::ImageParticle::opacityTable + + An image whose opacity will be used as a 1D texture to determine size over life. + + This property is expected to be removed shortly, in favor of custom easing curves to determine opacity over life. +*/ +/*! + \qmlproperty color QtQuick.Particles2::ImageParticle::color + + If a color is specified, the provided image will be colorized with it. + + Default is white (no change). +*/ +/*! + \qmlproperty real QtQuick.Particles2::ImageParticle::colorVariation + + This number represents the color variation applied to individual particles. + Setting colorVariation is the same as setting redVariation, greenVariation, + and blueVariation to the same number. + + Each channel can vary between particle by up to colorVariation from its usual color. + + Color is measured, per channel, from 0.0 to 1.0. + + Default is 0.0 +*/ +/*! + \qmlproperty real QtQuick.Particles2::ImageParticle::redVariation + The variation in the red color channel between particles. + + Color is measured, per channel, from 0.0 to 1.0. + + Default is 0.0 +*/ +/*! + \qmlproperty real QtQuick.Particles2::ImageParticle::greenVariation + The variation in the green color channel between particles. + + Color is measured, per channel, from 0.0 to 1.0. + + Default is 0.0 +*/ +/*! + \qmlproperty real QtQuick.Particles2::ImageParticle::blueVariation + The variation in the blue color channel between particles. + + Color is measured, per channel, from 0.0 to 1.0. + + Default is 0.0 +*/ +/*! + \qmlproperty real QtQuick.Particles2::ImageParticle::alpha + An alpha to be applied to the image. This value is multiplied by the value in + the image, and the value in the color property. + + Particles have additive blending, so lower alpha on single particles leads + to stronger effects when multiple particles overlap. + + Alpha is measured from 0.0 to 1.0. + + Default is 1.0 +*/ +/*! + \qmlproperty real QtQuick.Particles2::ImageParticle::alphaVariation + The variation in the alpha channel between particles. + + Alpha is measured from 0.0 to 1.0. + + Default is 0.0 +*/ +/*! + \qmlproperty real QtQuick.Particles2::ImageParticle::rotation + + If set the image will be rotated by this many degrees before it is drawn. + + The particle coordinates are not transformed. +*/ +/*! + \qmlproperty real QtQuick.Particles2::ImageParticle::rotationVariation + + If set the rotation of individual particles will vary by up to this much + between particles. + +*/ +/*! + \qmlproperty real QtQuick.Particles2::ImageParticle::rotationSpeed + + If set particles will rotate at this speed in degrees/second. +*/ +/*! + \qmlproperty real QtQuick.Particles2::ImageParticle::rotationSpeedVariation + + If set the rotationSpeed of individual particles will vary by up to this much + between particles. + +*/ +/*! + \qmlproperty bool QtQuick.Particles2::ImageParticle::autoRotation + + If set to true then a rotation will be applied on top of the particles rotation, so + that it faces the direction of travel. So to face away from the direction of travel, + set autoRotation to true and rotation to 180. + + Default is false +*/ +/*! + \qmlproperty StochasticDirection QtQuick.Particles2::ImageParticle::xVector + + Allows you to deform the particle image when drawn. The rectangular image will + be deformed so that the horizontal sides are in the shape of this vector instead + of (1,0). +*/ +/*! + \qmlproperty StochasticDirection QtQuick.Particles2::ImageParticle::yVector + + Allows you to deform the particle image when drawn. The rectangular image will + be deformed so that the vertical sides are in the shape of this vector instead + of (0,1). +*/ +/*! + \qmlproperty EntryEffect QtQuick.Particles2::ImageParticle::entryEffect + + This property provides basic and cheap entrance and exit effects for the particles. + For fine-grained control, see sizeTable and opacityTable. + + Acceptable values are + \list + \o None: Particles just appear and disappear. + \o Fade: Particles fade in from 0 opacity at the start of their life, and fade out to 0 at the end. + \o Scale: Particles scale in from 0 size at the start of their life, and scale back to 0 at the end. + \endlist + + Default value is Fade. +*/ +/*! + \qmlproperty bool QtQuick.Particles2::ImageParticle::spritesInterpolate + + If set to true, sprite particles will interpolate between sprite frames each rendered frame, making + the sprites look smoother. + + Default is true. +*/ + + +QQuickImageParticle::QQuickImageParticle(QQuickItem* parent) + : QQuickParticlePainter(parent) + , m_color_variation(0.0) + , m_rootNode(0) + , m_material(0) + , m_alphaVariation(0.0) + , m_alpha(1.0) + , m_redVariation(0.0) + , m_greenVariation(0.0) + , m_blueVariation(0.0) + , m_rotation(0) + , m_rotationVariation(0) + , m_rotationSpeed(0) + , m_rotationSpeedVariation(0) + , m_autoRotation(false) + , m_xVector(0) + , m_yVector(0) + , m_spriteEngine(0) + , m_spritesInterpolate(true) + , m_explicitColor(false) + , m_explicitRotation(false) + , m_explicitDeformation(false) + , m_explicitAnimation(false) + , m_bloat(false) + , perfLevel(Unknown) + , m_lastLevel(Unknown) + , m_debugMode(false) + , m_entryEffect(Fade) +{ + setFlag(ItemHasContents); + m_debugMode = qmlParticlesDebug(); +} + +QQuickImageParticle::~QQuickImageParticle() +{ +} + +QDeclarativeListProperty QQuickImageParticle::sprites() +{ + return QDeclarativeListProperty(this, &m_sprites, spriteAppend, spriteCount, spriteAt, spriteClear); +} + +void QQuickImageParticle::setImage(const QUrl &image) +{ + if (image == m_image_name) + return; + m_image_name = image; + emit imageChanged(); + reset(); +} + + +void QQuickImageParticle::setColortable(const QUrl &table) +{ + if (table == m_colortable_name) + return; + m_colortable_name = table; + emit colortableChanged(); + reset(); +} + +void QQuickImageParticle::setSizetable(const QUrl &table) +{ + if (table == m_sizetable_name) + return; + m_sizetable_name = table; + emit sizetableChanged(); + reset(); +} + +void QQuickImageParticle::setOpacitytable(const QUrl &table) +{ + if (table == m_opacitytable_name) + return; + m_opacitytable_name = table; + emit opacitytableChanged(); + reset(); +} + +void QQuickImageParticle::setColor(const QColor &color) +{ + if (color == m_color) + return; + m_color = color; + emit colorChanged(); + m_explicitColor = true; + if (perfLevel < Colored) + reset(); +} + +void QQuickImageParticle::setColorVariation(qreal var) +{ + if (var == m_color_variation) + return; + m_color_variation = var; + emit colorVariationChanged(); + m_explicitColor = true; + if (perfLevel < Colored) + reset(); +} + +void QQuickImageParticle::setAlphaVariation(qreal arg) +{ + if (m_alphaVariation != arg) { + m_alphaVariation = arg; + emit alphaVariationChanged(arg); + } + m_explicitColor = true; + if (perfLevel < Colored) + reset(); +} + +void QQuickImageParticle::setAlpha(qreal arg) +{ + if (m_alpha != arg) { + m_alpha = arg; + emit alphaChanged(arg); + } + m_explicitColor = true; + if (perfLevel < Colored) + reset(); +} + +void QQuickImageParticle::setRedVariation(qreal arg) +{ + if (m_redVariation != arg) { + m_redVariation = arg; + emit redVariationChanged(arg); + } + m_explicitColor = true; + if (perfLevel < Colored) + reset(); +} + +void QQuickImageParticle::setGreenVariation(qreal arg) +{ + if (m_greenVariation != arg) { + m_greenVariation = arg; + emit greenVariationChanged(arg); + } + m_explicitColor = true; + if (perfLevel < Colored) + reset(); +} + +void QQuickImageParticle::setBlueVariation(qreal arg) +{ + if (m_blueVariation != arg) { + m_blueVariation = arg; + emit blueVariationChanged(arg); + } + m_explicitColor = true; + if (perfLevel < Colored) + reset(); +} + +void QQuickImageParticle::setRotation(qreal arg) +{ + if (m_rotation != arg) { + m_rotation = arg; + emit rotationChanged(arg); + } + m_explicitRotation = true; + if (perfLevel < Deformable) + reset(); +} + +void QQuickImageParticle::setRotationVariation(qreal arg) +{ + if (m_rotationVariation != arg) { + m_rotationVariation = arg; + emit rotationVariationChanged(arg); + } + m_explicitRotation = true; + if (perfLevel < Deformable) + reset(); +} + +void QQuickImageParticle::setRotationSpeed(qreal arg) +{ + if (m_rotationSpeed != arg) { + m_rotationSpeed = arg; + emit rotationSpeedChanged(arg); + } + m_explicitRotation = true; + if (perfLevel < Deformable) + reset(); +} + +void QQuickImageParticle::setRotationSpeedVariation(qreal arg) +{ + if (m_rotationSpeedVariation != arg) { + m_rotationSpeedVariation = arg; + emit rotationSpeedVariationChanged(arg); + } + m_explicitRotation = true; + if (perfLevel < Deformable) + reset(); +} + +void QQuickImageParticle::setAutoRotation(bool arg) +{ + if (m_autoRotation != arg) { + m_autoRotation = arg; + emit autoRotationChanged(arg); + } + m_explicitRotation = true; + if (perfLevel < Deformable) + reset(); +} + +void QQuickImageParticle::setXVector(QQuickDirection* arg) +{ + if (m_xVector != arg) { + m_xVector = arg; + emit xVectorChanged(arg); + } + m_explicitDeformation = true; + if (perfLevel < Deformable) + reset(); +} + +void QQuickImageParticle::setYVector(QQuickDirection* arg) +{ + if (m_yVector != arg) { + m_yVector = arg; + emit yVectorChanged(arg); + } + m_explicitDeformation = true; + if (perfLevel < Deformable) + reset(); +} + +void QQuickImageParticle::setSpritesInterpolate(bool arg) +{ + if (m_spritesInterpolate != arg) { + m_spritesInterpolate = arg; + emit spritesInterpolateChanged(arg); + } +} + +void QQuickImageParticle::setBloat(bool arg) +{ + if (m_bloat != arg) { + m_bloat = arg; + emit bloatChanged(arg); + } + if (perfLevel < 9999) + reset(); +} + +void QQuickImageParticle::setEntryEffect(EntryEffect arg) +{ + if (m_entryEffect != arg) { + m_entryEffect = arg; + if (m_material) + getState(m_material)->entry = (qreal) m_entryEffect; + emit entryEffectChanged(arg); + } +} + +void QQuickImageParticle::resetColor() +{ + m_explicitColor = false; + foreach (const QString &str, m_groups) + foreach (QQuickParticleData* d, m_system->groupData[m_system->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 QQuickImageParticle::resetRotation() +{ + m_explicitRotation = false; + foreach (const QString &str, m_groups) + foreach (QQuickParticleData* d, m_system->groupData[m_system->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 QQuickImageParticle::resetDeformation() +{ + m_explicitDeformation = false; + foreach (const QString &str, m_groups) + foreach (QQuickParticleData* d, m_system->groupData[m_system->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 QQuickImageParticle::reset() +{ + QQuickParticlePainter::reset(); + m_pleaseReset = true; + update(); +} + +void QQuickImageParticle::createEngine() +{ + if (m_spriteEngine) + delete m_spriteEngine; + if (m_sprites.count()) + m_spriteEngine = new QQuickSpriteEngine(m_sprites, this); + else + m_spriteEngine = 0; + m_explicitAnimation = true; + reset(); +} + +static QSGGeometry::Attribute SimpleParticle_Attributes[] = { + QSGGeometry::Attribute::create(0, 2, GL_FLOAT, true), // Position + QSGGeometry::Attribute::create(1, 4, GL_FLOAT), // Data + QSGGeometry::Attribute::create(2, 4, GL_FLOAT) // Vectors +}; + +static QSGGeometry::AttributeSet SimpleParticle_AttributeSet = +{ + 3, // Attribute Count + ( 2 + 4 + 4 ) * sizeof(float), + SimpleParticle_Attributes +}; + +static QSGGeometry::Attribute ColoredParticle_Attributes[] = { + QSGGeometry::Attribute::create(0, 2, GL_FLOAT, true), // Position + QSGGeometry::Attribute::create(1, 4, GL_FLOAT), // Data + QSGGeometry::Attribute::create(2, 4, GL_FLOAT), // Vectors + QSGGeometry::Attribute::create(3, 4, GL_UNSIGNED_BYTE), // Colors +}; + +static QSGGeometry::AttributeSet ColoredParticle_AttributeSet = +{ + 4, // Attribute Count + ( 2 + 4 + 4 ) * sizeof(float) + 4 * sizeof(uchar), + ColoredParticle_Attributes +}; + +static QSGGeometry::Attribute DeformableParticle_Attributes[] = { + QSGGeometry::Attribute::create(0, 2, GL_FLOAT, true), // Position + QSGGeometry::Attribute::create(1, 2, GL_FLOAT), // TexCoord + QSGGeometry::Attribute::create(2, 4, GL_FLOAT), // Data + QSGGeometry::Attribute::create(3, 4, GL_FLOAT), // Vectors + QSGGeometry::Attribute::create(4, 4, GL_UNSIGNED_BYTE), // Colors + QSGGeometry::Attribute::create(5, 4, GL_FLOAT), // DeformationVectors + QSGGeometry::Attribute::create(6, 3, GL_FLOAT), // Rotation +}; + +static QSGGeometry::AttributeSet DeformableParticle_AttributeSet = +{ + 7, // Attribute Count + (2 + 2 + 4 + 4 + 4 + 3) * sizeof(float) + 4 * sizeof(uchar), + DeformableParticle_Attributes +}; + +static QSGGeometry::Attribute SpriteParticle_Attributes[] = { + QSGGeometry::Attribute::create(0, 2, GL_FLOAT, true), // Position + QSGGeometry::Attribute::create(1, 2, GL_FLOAT), // TexCoord + QSGGeometry::Attribute::create(2, 4, GL_FLOAT), // Data + QSGGeometry::Attribute::create(3, 4, GL_FLOAT), // Vectors + QSGGeometry::Attribute::create(4, 4, GL_UNSIGNED_BYTE), // Colors + QSGGeometry::Attribute::create(5, 4, GL_FLOAT), // DeformationVectors + QSGGeometry::Attribute::create(6, 3, GL_FLOAT), // Rotation + QSGGeometry::Attribute::create(7, 4, GL_FLOAT), // Anim Data + QSGGeometry::Attribute::create(8, 4, GL_FLOAT) // Anim Pos +}; + +static QSGGeometry::AttributeSet SpriteParticle_AttributeSet = +{ + 9, // Attribute Count + (2 + 2 + 4 + 4 + 4 + 4 + 4 + 3) * sizeof(float) + 4 * sizeof(uchar), + SpriteParticle_Attributes +}; + +void QQuickImageParticle::clearShadows() +{ + m_shadowInit = false; + foreach (const QVector data, m_shadowData) + qDeleteAll(data); + m_shadowData.clear(); +} + +//Only call if you need to, may initialize the whole array first time +QQuickParticleData* QQuickImageParticle::getShadowDatum(QQuickParticleData* datum) +{ + QQuickParticleGroupData* gd = m_system->groupData[datum->group]; + if (!m_shadowData.contains(datum->group)) { + QVector data; + for (int i=0; isize(); i++){ + QQuickParticleData* datum = new QQuickParticleData(m_system); + *datum = *(gd->data[i]); + data << datum; + } + m_shadowData.insert(datum->group, data); + } + //### If dynamic resize is added, remember to potentially resize the shadow data on out-of-bounds access request + + return m_shadowData[datum->group][datum->index]; +} + +QSGGeometryNode* QQuickImageParticle::buildParticleNodes() +{ +#ifdef QT_OPENGL_ES_2 + if (m_count * 4 > 0xffff) { + printf("ImageParticle: Too many particles - maximum 16,000 per ImageParticle.\n");//ES 2 vertex count limit is ushort + return 0; + } +#endif + + if (count() <= 0) + return 0; + + if (m_sprites.count() || m_bloat) { + perfLevel = Sprites; + } else if (!m_colortable_name.isEmpty() || !m_sizetable_name.isEmpty() + || !m_opacitytable_name.isEmpty()) { + perfLevel = Tabled; + } else if (m_autoRotation || m_rotation || m_rotationVariation + || m_rotationSpeed || m_rotationSpeedVariation + || m_xVector || m_yVector) { + perfLevel = Deformable; + } else if (m_alphaVariation || m_alpha != 1.0 || m_color.isValid() || m_color_variation + || m_redVariation || m_blueVariation || m_greenVariation) { + perfLevel = Colored; + } else { + perfLevel = Simple; + } + + foreach (const QString &str, m_groups){//For sharing higher levels, need to have highest used so it renders + int gIdx = m_system->groupIds[str]; + foreach (QQuickParticlePainter* p, m_system->groupData[gIdx]->painters){ + QQuickImageParticle* other = qobject_cast(p); + if (other){ + if (other->perfLevel > perfLevel) { + if (other->perfLevel >= Tabled){//Deformable is the highest level needed for this, anything higher isn't shared (or requires your own sprite) + if (perfLevel < Deformable) + perfLevel = Deformable; + } else { + perfLevel = other->perfLevel; + } + } else if (other->perfLevel < perfLevel) { + other->reset(); + } + } + } + } + + if (perfLevel >= Colored && !m_color.isValid()) + m_color = QColor(Qt::white);//Hidden default, but different from unset + + QImage image; + if (perfLevel >= Sprites){ + if (!m_spriteEngine) { + qWarning() << "ImageParticle: No sprite engine..."; + return 0; + } + image = m_spriteEngine->assembledImage(); + if (image.isNull())//Warning is printed in engine + return 0; + } else { + image = QImage(m_image_name.toLocalFile()); + if (image.isNull()) { + printf("ImageParticle: loading image failed '%s'\n", qPrintable(m_image_name.toLocalFile())); + return 0; + } + } + + clearShadows(); + if (m_material) + m_material = 0; + + //Setup material + QImage colortable; + QImage sizetable; + QImage opacitytable; + switch (perfLevel) {//Fallthrough intended + case Sprites: + m_material = SpriteMaterial::createMaterial(); + getState(m_material)->animSheetSize = QSizeF(image.size()); + m_spriteEngine->setCount(m_count); + case Tabled: + if (!m_material) + m_material = TabledMaterial::createMaterial(); + colortable = QImage(m_colortable_name.toLocalFile()); + sizetable = QImage(m_sizetable_name.toLocalFile()); + opacitytable = QImage(m_opacitytable_name.toLocalFile()); + if (colortable.isNull()){ + colortable = QImage(1,1,QImage::Format_ARGB32); + colortable.fill(Qt::white); + } + Q_ASSERT(!colortable.isNull()); + getState(m_material)->colorTable = QSGPlainTexture::fromImage(colortable); + fillUniformArrayFromImage(getState(m_material)->sizeTable, sizetable, UNIFORM_ARRAY_SIZE); + fillUniformArrayFromImage(getState(m_material)->opacityTable, opacitytable, UNIFORM_ARRAY_SIZE); + case Deformable: + if (!m_material) + m_material = DeformableMaterial::createMaterial(); + case Colored: + if (!m_material) + m_material = ColoredMaterial::createMaterial(); + default://Also Simple + if (!m_material) + m_material = SimpleMaterial::createMaterial(); + getState(m_material)->texture = QSGPlainTexture::fromImage(image); + getState(m_material)->texture->setFiltering(QSGTexture::Linear); + getState(m_material)->entry = (qreal) m_entryEffect; + m_material->setFlag(QSGMaterial::Blending); + } + + foreach (const QString &str, m_groups){ + int gIdx = m_system->groupIds[str]; + int count = m_system->groupData[gIdx]->size(); + QSGGeometryNode* node = new QSGGeometryNode(); + node->setMaterial(m_material); + node->markDirty(QSGNode::DirtyMaterial); + + m_nodes.insert(gIdx, node); + m_idxStarts.insert(gIdx, m_lastIdxStart); + m_lastIdxStart += count; + + //Create Particle Geometry + int vCount = count * 4; + int iCount = count * 6; + + QSGGeometry *g; + if (perfLevel == Sprites) + g = new QSGGeometry(SpriteParticle_AttributeSet, vCount, iCount); + else if (perfLevel == Tabled) + g = new QSGGeometry(DeformableParticle_AttributeSet, vCount, iCount); + else if (perfLevel == Deformable) + g = new QSGGeometry(DeformableParticle_AttributeSet, vCount, iCount); + else if (perfLevel == Colored) + g = new QSGGeometry(ColoredParticle_AttributeSet, count, 0); + else //Simple + g = new QSGGeometry(SimpleParticle_AttributeSet, count, 0); + + node->setGeometry(g); + if (perfLevel <= Colored){ + g->setDrawingMode(GL_POINTS); + if (m_debugMode){ + GLfloat pointSizeRange[2]; + glGetFloatv(GL_ALIASED_POINT_SIZE_RANGE, pointSizeRange); + qDebug() << "Using point sprites, GL_ALIASED_POINT_SIZE_RANGE " <setDrawingMode(GL_TRIANGLES); + + for (int p=0; p < count; ++p) + commit(gIdx, p);//commit sets geometry for the node, has its own perfLevel switch + + if (perfLevel == Sprites) + initTexCoords((SpriteVertex*)g->vertexData(), vCount); + else if (perfLevel == Tabled) + initTexCoords((DeformableVertex*)g->vertexData(), vCount); + else if (perfLevel == Deformable) + initTexCoords((DeformableVertex*)g->vertexData(), vCount); + + if (perfLevel > Colored){ + quint16 *indices = g->indexDataAsUShort(); + for (int i=0; i < count; ++i) { + int o = i * 4; + indices[0] = o; + indices[1] = o + 1; + indices[2] = o + 2; + indices[3] = o + 1; + indices[4] = o + 3; + indices[5] = o + 2; + indices += 6; + } + } + + } + + foreach (QSGGeometryNode* node, m_nodes){ + if (node == *(m_nodes.begin())) + node->setFlag(QSGGeometryNode::OwnsMaterial);//Root node owns the material for memory management purposes + else + (*(m_nodes.begin()))->appendChildNode(node); + } + + return *(m_nodes.begin()); +} + +QSGNode *QQuickImageParticle::updatePaintNode(QSGNode *, UpdatePaintNodeData *) +{ + if (m_pleaseReset){ + m_lastLevel = perfLevel; + + delete m_rootNode;//Automatically deletes children, and SG manages material lifetime + m_rootNode = 0; + m_nodes.clear(); + + m_idxStarts.clear(); + m_lastIdxStart = 0; + + m_material = 0; + + m_pleaseReset = false; + } + + if (m_system && m_system->isRunning() && !m_system->isPaused()){ + prepareNextFrame(); + if (m_rootNode) { + update(); + foreach (QSGGeometryNode* node, m_nodes) + node->markDirty(QSGNode::DirtyGeometry); + } + } + + return m_rootNode; +} + +void QQuickImageParticle::prepareNextFrame() +{ + if (m_rootNode == 0){//TODO: Staggered loading (as emitted) + m_rootNode = buildParticleNodes(); + if (m_rootNode == 0) + return; + if(m_debugMode){ + qDebug() << "QQuickImageParticle Feature level: " << perfLevel; + qDebug() << "QQuickImageParticle Nodes: "; + int count = 0; + foreach(int i, m_nodes.keys()){ + qDebug() << "Group " << i << " (" << m_system->groupData[i]->size() << " particles)"; + count += m_system->groupData[i]->size(); + } + qDebug() << "Total count: " << count; + } + } + qint64 timeStamp = m_system->systemSync(this); + + qreal time = timeStamp / 1000.; + + switch (perfLevel){//Fall-through intended + case Sprites: + //Advance State + m_spriteEngine->updateSprites(timeStamp); + foreach (const QString &str, m_groups){ + int gIdx = m_system->groupIds[str]; + int count = m_system->groupData[gIdx]->size(); + + Vertices* particles = (Vertices *) m_nodes[gIdx]->geometry()->vertexData(); + for (int i=0; i < count; i++){ + int spriteIdx = m_idxStarts[gIdx] + i; + Vertices &p = particles[i]; + int curY = m_spriteEngine->spriteY(spriteIdx);//Y is fixed per sprite row, used to distinguish rows here + if (curY != p.v1.animY){ + p.v1.animT = p.v2.animT = p.v3.animT = p.v4.animT = m_spriteEngine->spriteStart(spriteIdx)/1000.0; + p.v1.frameCount = p.v2.frameCount = p.v3.frameCount = p.v4.frameCount = m_spriteEngine->spriteFrames(spriteIdx); + p.v1.frameDuration = p.v2.frameDuration = p.v3.frameDuration = p.v4.frameDuration = m_spriteEngine->spriteDuration(spriteIdx); + p.v1.animX = p.v2.animX = p.v3.animX = p.v4.animX = m_spriteEngine->spriteX(spriteIdx); + p.v1.animY = p.v2.animY = p.v3.animY = p.v4.animY = m_spriteEngine->spriteY(spriteIdx); + p.v1.animWidth = p.v2.animWidth = p.v3.animWidth = p.v4.animWidth = m_spriteEngine->spriteWidth(spriteIdx); + p.v1.animHeight = p.v2.animHeight = p.v3.animHeight = p.v4.animHeight = m_spriteEngine->spriteHeight(spriteIdx); + } + } + } + case Tabled: + case Deformable: + case Colored: + case Simple: + default: //Also Simple + getState(m_material)->timestamp = time; + break; + } + + foreach (QSGGeometryNode* node, m_nodes) + node->markDirty(QSGNode::DirtyMaterial); +} + +void QQuickImageParticle::reloadColor(const Color4ub &c, QQuickParticleData* d) +{ + d->color = c; + //TODO: get index for reload - or make function take an index +} + +void QQuickImageParticle::initialize(int gIdx, int pIdx) +{ + Color4ub color; + QQuickParticleData* datum = m_system->groupData[gIdx]->data[pIdx]; + qreal redVariation = m_color_variation + m_redVariation; + qreal greenVariation = m_color_variation + m_greenVariation; + qreal blueVariation = m_color_variation + m_blueVariation; + int spriteIdx = m_idxStarts[gIdx] + datum->index; + float rotation; + float rotationSpeed; + float autoRotate; + switch (perfLevel){//Fall-through is intended on all of them + case Sprites: + // Initial Sprite State + if (m_explicitAnimation){ + if (!datum->animationOwner) + datum->animationOwner = this; + QQuickParticleData* writeTo = (datum->animationOwner == this ? datum : getShadowDatum(datum)); + writeTo->animT = writeTo->t; + //writeTo->animInterpolate = m_spritesInterpolate; + if (m_spriteEngine){ + m_spriteEngine->start(spriteIdx); + writeTo->frameCount = m_spriteEngine->spriteFrames(spriteIdx); + writeTo->frameDuration = m_spriteEngine->spriteDuration(spriteIdx); + writeTo->animX = m_spriteEngine->spriteX(spriteIdx); + writeTo->animY = m_spriteEngine->spriteY(spriteIdx); + writeTo->animWidth = m_spriteEngine->spriteWidth(spriteIdx); + writeTo->animHeight = m_spriteEngine->spriteHeight(spriteIdx); + }else{ + writeTo->frameCount = 1; + writeTo->frameDuration = 9999; + writeTo->animX = writeTo->animY = writeTo->animWidth = writeTo->animHeight = 0; + } + } + case Tabled: + case Deformable: + //Initial Rotation + if (m_explicitDeformation){ + if (!datum->deformationOwner) + datum->deformationOwner = this; + if (m_xVector){ + const QPointF &ret = m_xVector->sample(QPointF(datum->x, datum->y)); + if (datum->deformationOwner == this) { + datum->xx = ret.x(); + datum->xy = ret.y(); + } else { + getShadowDatum(datum)->xx = ret.x(); + getShadowDatum(datum)->xy = ret.y(); + } + } + if (m_yVector){ + const QPointF &ret = m_yVector->sample(QPointF(datum->x, datum->y)); + if (datum->deformationOwner == this) { + datum->yx = ret.x(); + datum->yy = ret.y(); + } else { + getShadowDatum(datum)->yx = ret.x(); + getShadowDatum(datum)->yy = ret.y(); + } + } + } + + if (m_explicitRotation){ + if (!datum->rotationOwner) + datum->rotationOwner = this; + rotation = + (m_rotation + (m_rotationVariation - 2*((qreal)rand()/RAND_MAX)*m_rotationVariation) ) * CONV; + rotationSpeed = + (m_rotationSpeed + (m_rotationSpeedVariation - 2*((qreal)rand()/RAND_MAX)*m_rotationSpeedVariation) ) * CONV; + autoRotate = m_autoRotation?1.0:0.0; + if (datum->rotationOwner == this) { + datum->rotation = rotation; + datum->rotationSpeed = rotationSpeed; + datum->autoRotate = autoRotate; + } else { + getShadowDatum(datum)->rotation = rotation; + getShadowDatum(datum)->rotationSpeed = rotationSpeed; + getShadowDatum(datum)->autoRotate = autoRotate; + } + } + case Colored: + //Color initialization + // Particle color + if (m_explicitColor) { + if (!datum->colorOwner) + datum->colorOwner = this; + color.r = m_color.red() * (1 - redVariation) + rand() % 256 * redVariation; + color.g = m_color.green() * (1 - greenVariation) + rand() % 256 * greenVariation; + color.b = m_color.blue() * (1 - blueVariation) + rand() % 256 * blueVariation; + color.a = m_alpha * m_color.alpha() * (1 - m_alphaVariation) + rand() % 256 * m_alphaVariation; + if (datum->colorOwner == this) + datum->color = color; + else + getShadowDatum(datum)->color = color; + } + default: + break; + } +} + +void QQuickImageParticle::commit(int gIdx, int pIdx) +{ + if (m_pleaseReset) + return; + QSGGeometryNode *node = m_nodes[gIdx]; + if (!node) + return; + QQuickParticleData* datum = m_system->groupData[gIdx]->data[pIdx]; + node->setFlag(QSGNode::OwnsGeometry, false); + SpriteVertex *spriteVertices = (SpriteVertex *) node->geometry()->vertexData(); + DeformableVertex *deformableVertices = (DeformableVertex *) node->geometry()->vertexData(); + ColoredVertex *coloredVertices = (ColoredVertex *) node->geometry()->vertexData(); + SimpleVertex *simpleVertices = (SimpleVertex *) node->geometry()->vertexData(); + switch (perfLevel){//No automatic fall through intended on this one + case Sprites: + spriteVertices += pIdx*4; + for (int i=0; i<4; i++){ + spriteVertices[i].x = datum->x - m_systemOffset.x(); + spriteVertices[i].y = datum->y - m_systemOffset.y(); + spriteVertices[i].t = datum->t; + spriteVertices[i].lifeSpan = datum->lifeSpan; + spriteVertices[i].size = datum->size; + spriteVertices[i].endSize = datum->endSize; + spriteVertices[i].vx = datum->vx; + spriteVertices[i].vy = datum->vy; + spriteVertices[i].ax = datum->ax; + spriteVertices[i].ay = datum->ay; + if (m_explicitDeformation && datum->deformationOwner != this) { + QQuickParticleData* shadow = getShadowDatum(datum); + spriteVertices[i].xx = shadow->xx; + spriteVertices[i].xy = shadow->xy; + spriteVertices[i].yx = shadow->yx; + spriteVertices[i].yy = shadow->yy; + } else { + spriteVertices[i].xx = datum->xx; + spriteVertices[i].xy = datum->xy; + spriteVertices[i].yx = datum->yx; + spriteVertices[i].yy = datum->yy; + } + if (m_explicitRotation && datum->rotationOwner != this) { + QQuickParticleData* shadow = getShadowDatum(datum); + spriteVertices[i].rotation = shadow->rotation; + spriteVertices[i].rotationSpeed = shadow->rotationSpeed; + spriteVertices[i].autoRotate = shadow->autoRotate; + } else { + spriteVertices[i].rotation = datum->rotation; + spriteVertices[i].rotationSpeed = datum->rotationSpeed; + spriteVertices[i].autoRotate = datum->autoRotate; + } + spriteVertices[i].animInterpolate = m_spritesInterpolate ? 1.0 : 0.0;//### Shadow? In particleData? Or uniform? + if (m_explicitAnimation && datum->animationOwner != this) { + QQuickParticleData* shadow = getShadowDatum(datum); + spriteVertices[i].frameDuration = shadow->frameDuration; + spriteVertices[i].frameCount = shadow->frameCount; + spriteVertices[i].animT = shadow->animT; + spriteVertices[i].animX = shadow->animX; + spriteVertices[i].animY = shadow->animY; + spriteVertices[i].animWidth = shadow->animWidth; + spriteVertices[i].animHeight = shadow->animHeight; + } else { + spriteVertices[i].frameDuration = datum->frameDuration; + spriteVertices[i].frameCount = datum->frameCount; + spriteVertices[i].animT = datum->animT; + spriteVertices[i].animX = datum->animX; + spriteVertices[i].animY = datum->animY; + spriteVertices[i].animWidth = datum->animWidth; + spriteVertices[i].animHeight = datum->animHeight; + } + if (m_explicitColor && datum->colorOwner != this) { + QQuickParticleData* shadow = getShadowDatum(datum); + spriteVertices[i].color.r = shadow->color.r; + spriteVertices[i].color.g = shadow->color.g; + spriteVertices[i].color.b = shadow->color.b; + spriteVertices[i].color.a = shadow->color.a; + } else { + spriteVertices[i].color.r = datum->color.r; + spriteVertices[i].color.g = datum->color.g; + spriteVertices[i].color.b = datum->color.b; + spriteVertices[i].color.a = datum->color.a; + } + } + break; + case Tabled: //Fall through until it has its own vertex class + case Deformable: + deformableVertices += pIdx*4; + for (int i=0; i<4; i++){ + deformableVertices[i].x = datum->x - m_systemOffset.x(); + deformableVertices[i].y = datum->y - m_systemOffset.y(); + deformableVertices[i].t = datum->t; + deformableVertices[i].lifeSpan = datum->lifeSpan; + deformableVertices[i].size = datum->size; + deformableVertices[i].endSize = datum->endSize; + deformableVertices[i].vx = datum->vx; + deformableVertices[i].vy = datum->vy; + deformableVertices[i].ax = datum->ax; + deformableVertices[i].ay = datum->ay; + if (m_explicitDeformation && datum->deformationOwner != this) { + QQuickParticleData* shadow = getShadowDatum(datum); + deformableVertices[i].xx = shadow->xx; + deformableVertices[i].xy = shadow->xy; + deformableVertices[i].yx = shadow->yx; + deformableVertices[i].yy = shadow->yy; + } else { + deformableVertices[i].xx = datum->xx; + deformableVertices[i].xy = datum->xy; + deformableVertices[i].yx = datum->yx; + deformableVertices[i].yy = datum->yy; + } + if (m_explicitRotation && datum->rotationOwner != this) { + QQuickParticleData* shadow = getShadowDatum(datum); + deformableVertices[i].rotation = shadow->rotation; + deformableVertices[i].rotationSpeed = shadow->rotationSpeed; + deformableVertices[i].autoRotate = shadow->autoRotate; + } else { + deformableVertices[i].rotation = datum->rotation; + deformableVertices[i].rotationSpeed = datum->rotationSpeed; + deformableVertices[i].autoRotate = datum->autoRotate; + } + if (m_explicitColor && datum->colorOwner != this) { + QQuickParticleData* shadow = getShadowDatum(datum); + deformableVertices[i].color.r = shadow->color.r; + deformableVertices[i].color.g = shadow->color.g; + deformableVertices[i].color.b = shadow->color.b; + deformableVertices[i].color.a = shadow->color.a; + } else { + deformableVertices[i].color.r = datum->color.r; + deformableVertices[i].color.g = datum->color.g; + deformableVertices[i].color.b = datum->color.b; + deformableVertices[i].color.a = datum->color.a; + } + } + break; + case Colored: + coloredVertices += pIdx*1; + for (int i=0; i<1; i++){ + coloredVertices[i].x = datum->x - m_systemOffset.x(); + coloredVertices[i].y = datum->y - m_systemOffset.y(); + coloredVertices[i].t = datum->t; + coloredVertices[i].lifeSpan = datum->lifeSpan; + coloredVertices[i].size = datum->size; + coloredVertices[i].endSize = datum->endSize; + coloredVertices[i].vx = datum->vx; + coloredVertices[i].vy = datum->vy; + coloredVertices[i].ax = datum->ax; + coloredVertices[i].ay = datum->ay; + if (m_explicitColor && datum->colorOwner != this) { + QQuickParticleData* shadow = getShadowDatum(datum); + coloredVertices[i].color.r = shadow->color.r; + coloredVertices[i].color.g = shadow->color.g; + coloredVertices[i].color.b = shadow->color.b; + coloredVertices[i].color.a = shadow->color.a; + } else { + coloredVertices[i].color.r = datum->color.r; + coloredVertices[i].color.g = datum->color.g; + coloredVertices[i].color.b = datum->color.b; + coloredVertices[i].color.a = datum->color.a; + } + } + break; + case Simple: + simpleVertices += pIdx*1; + for (int i=0; i<1; i++){ + simpleVertices[i].x = datum->x - m_systemOffset.x(); + simpleVertices[i].y = datum->y - m_systemOffset.y(); + simpleVertices[i].t = datum->t; + simpleVertices[i].lifeSpan = datum->lifeSpan; + simpleVertices[i].size = datum->size; + simpleVertices[i].endSize = datum->endSize; + simpleVertices[i].vx = datum->vx; + simpleVertices[i].vy = datum->vy; + simpleVertices[i].ax = datum->ax; + simpleVertices[i].ay = datum->ay; + } + break; + default: + break; + } + + node->setFlag(QSGNode::OwnsGeometry, true); +} + + + +QT_END_NAMESPACE diff --git a/src/declarative/particles/qquickimageparticle_p.h b/src/declarative/particles/qquickimageparticle_p.h new file mode 100644 index 0000000000..760c64af0a --- /dev/null +++ b/src/declarative/particles/qquickimageparticle_p.h @@ -0,0 +1,432 @@ +/**************************************************************************** +** +** 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 ULTRAPARTICLE_H +#define ULTRAPARTICLE_H +#include "qquickparticlepainter_p.h" +#include "qquickdirection_p.h" +#include +#include +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class ImageMaterialData; +class QSGGeometryNode; + +class QQuickSprite; +class QQuickStochasticEngine; + +struct SimpleVertex { + float x; + float y; + float t; + float lifeSpan; + float size; + float endSize; + float vx; + float vy; + float ax; + float ay; +}; + +struct ColoredVertex { + float x; + float y; + float t; + float lifeSpan; + float size; + float endSize; + float vx; + float vy; + float ax; + float ay; + Color4ub color; +}; + +struct DeformableVertex { + float x; + float y; + float tx; + float ty; + float t; + float lifeSpan; + float size; + float endSize; + float vx; + float vy; + float ax; + float ay; + Color4ub color; + float xx; + float xy; + float yx; + float yy; + float rotation; + float rotationSpeed; + float autoRotate;//Assumed that GPUs prefer floats to bools +}; + +struct SpriteVertex { + float x; + float y; + float tx; + float ty; + float t; + float lifeSpan; + float size; + float endSize; + float vx; + float vy; + float ax; + float ay; + Color4ub color; + float xx; + float xy; + float yx; + float yy; + float rotation; + float rotationSpeed; + float autoRotate;//Assumed that GPUs prefer floats to bools + float animInterpolate; + float frameDuration; + float frameCount; + float animT; + float animX; + float animY; + float animWidth; + float animHeight; +}; + +template +struct Vertices { + Vertex v1; + Vertex v2; + Vertex v3; + Vertex v4; +}; + +class QQuickImageParticle : public QQuickParticlePainter +{ + Q_OBJECT + Q_PROPERTY(QUrl source READ image WRITE setImage NOTIFY imageChanged) + Q_PROPERTY(QUrl colorTable READ colortable WRITE setColortable NOTIFY colortableChanged) + Q_PROPERTY(QUrl sizeTable READ sizetable WRITE setSizetable NOTIFY sizetableChanged) + 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 RESET resetColor) + //Stacks (added) with individual colorVariations + 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 RESET resetColor) + Q_PROPERTY(qreal alphaVariation READ alphaVariation WRITE setAlphaVariation NOTIFY alphaVariationChanged RESET resetColor) + + 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 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(QQuickDirection* 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(QQuickDirection* yVector READ yVector WRITE setYVector NOTIFY yVectorChanged RESET resetDeformation) + Q_PROPERTY(QDeclarativeListProperty sprites READ sprites) + Q_PROPERTY(bool spritesInterpolate READ spritesInterpolate WRITE setSpritesInterpolate NOTIFY spritesInterpolateChanged) + + Q_PROPERTY(EntryEffect entryEffect READ entryEffect WRITE setEntryEffect NOTIFY entryEffectChanged) + Q_PROPERTY(bool bloat READ bloat WRITE setBloat NOTIFY bloatChanged)//Just a debugging property to bypass optimizations + Q_ENUMS(EntryEffect) +public: + explicit QQuickImageParticle(QQuickItem *parent = 0); + virtual ~QQuickImageParticle(); + + + QDeclarativeListProperty sprites(); + QQuickStochasticEngine* spriteEngine() {return m_spriteEngine;} + + enum EntryEffect { + None = 0, + Fade = 1, + Scale = 2 + }; + + enum PerformanceLevel{//TODO: Expose? + Unknown = 0, + Simple, + Colored, + Deformable, + Tabled, + Sprites + }; + + QUrl image() const { return m_image_name; } + void setImage(const QUrl &image); + + QUrl colortable() const { return m_colortable_name; } + void setColortable(const QUrl &table); + + QUrl sizetable() const { return m_sizetable_name; } + void setSizetable (const QUrl &table); + + QUrl opacitytable() const { return m_opacitytable_name; } + void setOpacitytable(const QUrl &table); + + QColor color() const { return m_color; } + void setColor(const QColor &color); + + qreal colorVariation() const { return m_color_variation; } + void setColorVariation(qreal var); + + qreal renderOpacity() const { return m_render_opacity; } + + qreal alphaVariation() const { return m_alphaVariation; } + + qreal alpha() const { return m_alpha; } + + qreal redVariation() const { return m_redVariation; } + + qreal greenVariation() const { return m_greenVariation; } + + qreal blueVariation() const { return m_blueVariation; } + + qreal rotation() const { return m_rotation; } + + qreal rotationVariation() const { return m_rotationVariation; } + + qreal rotationSpeed() const { return m_rotationSpeed; } + + qreal rotationSpeedVariation() const { return m_rotationSpeedVariation; } + + bool autoRotation() const { return m_autoRotation; } + + QQuickDirection* xVector() const { return m_xVector; } + + QQuickDirection* yVector() const { return m_yVector; } + + bool spritesInterpolate() const { return m_spritesInterpolate; } + + bool bloat() const { return m_bloat; } + + EntryEffect entryEffect() const { return m_entryEffect; } + + void resetColor(); + void resetRotation(); + void resetDeformation(); + +signals: + + void imageChanged(); + void colortableChanged(); + void sizetableChanged(); + void opacitytableChanged(); + + void colorChanged(); + void colorVariationChanged(); + + void particleDurationChanged(); + void alphaVariationChanged(qreal arg); + + void alphaChanged(qreal arg); + + void redVariationChanged(qreal arg); + + void greenVariationChanged(qreal arg); + + void blueVariationChanged(qreal arg); + + void rotationChanged(qreal arg); + + void rotationVariationChanged(qreal arg); + + void rotationSpeedChanged(qreal arg); + + void rotationSpeedVariationChanged(qreal arg); + + void autoRotationChanged(bool arg); + + void xVectorChanged(QQuickDirection* arg); + + void yVectorChanged(QQuickDirection* arg); + + void spritesInterpolateChanged(bool arg); + + void bloatChanged(bool arg); + + void entryEffectChanged(EntryEffect arg); + +public slots: + void reloadColor(const Color4ub &c, QQuickParticleData* d); + void setAlphaVariation(qreal arg); + + void setAlpha(qreal arg); + + void setRedVariation(qreal arg); + + void setGreenVariation(qreal arg); + + void setBlueVariation(qreal arg); + + void setRotation(qreal arg); + + void setRotationVariation(qreal arg); + + void setRotationSpeed(qreal arg); + + void setRotationSpeedVariation(qreal arg); + + void setAutoRotation(bool arg); + + void setXVector(QQuickDirection* arg); + + void setYVector(QQuickDirection* arg); + + void setSpritesInterpolate(bool arg); + + void setBloat(bool arg); + + void setEntryEffect(EntryEffect arg); + +protected: + void reset(); + virtual void initialize(int gIdx, int pIdx); + virtual void commit(int gIdx, int pIdx); + + QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *); + void prepareNextFrame(); + QSGGeometryNode* buildParticleNodes(); + +private slots: + void createEngine(); //### method invoked by sprite list changing (in engine.h) - pretty nasty + +private: + QUrl m_image_name; + QUrl m_colortable_name; + QUrl m_sizetable_name; + QUrl m_opacitytable_name; + + + QColor m_color; + qreal m_color_variation; + qreal m_particleDuration; + + QSGGeometryNode *m_rootNode; + QHash m_nodes; + QHash m_idxStarts;//TODO: Proper resizing will lead to needing a spriteEngine per particle - do this after sprite engine gains transparent sharing? + int m_lastIdxStart; + QSGMaterial *m_material; + + // derived values... + + qreal m_render_opacity; + qreal m_alphaVariation; + qreal m_alpha; + qreal m_redVariation; + qreal m_greenVariation; + qreal m_blueVariation; + qreal m_rotation; + qreal m_rotationVariation; + qreal m_rotationSpeed; + qreal m_rotationSpeedVariation; + bool m_autoRotation; + QQuickDirection* m_xVector; + QQuickDirection* m_yVector; + + QList m_sprites; + QQuickSpriteEngine* m_spriteEngine; + bool m_spritesInterpolate; + + bool m_explicitColor; + bool m_explicitRotation; + bool m_explicitDeformation; + bool m_explicitAnimation; + QHash > m_shadowData; + bool m_shadowInit; + void clearShadows(); + QQuickParticleData* getShadowDatum(QQuickParticleData* datum); + + bool m_bloat; + PerformanceLevel perfLevel; + + PerformanceLevel m_lastLevel; + bool m_debugMode; + + template + void initTexCoords(Vertex* v, int count){ + Vertex* end = v + count; + while (v < end){ + v[0].tx = 0; + v[0].ty = 0; + + v[1].tx = 1; + v[1].ty = 0; + + v[2].tx = 0; + v[2].ty = 1; + + v[3].tx = 1; + v[3].ty = 1; + + v += 4; + } + } + + template + MaterialData* getState(QSGMaterial* m){ + return static_cast *>(m)->state(); + } + EntryEffect m_entryEffect; +}; + +QT_END_NAMESPACE +QT_END_HEADER +#endif // ULTRAPARTICLE_H diff --git a/src/declarative/particles/qquickitemparticle.cpp b/src/declarative/particles/qquickitemparticle.cpp new file mode 100644 index 0000000000..dd06f26b23 --- /dev/null +++ b/src/declarative/particles/qquickitemparticle.cpp @@ -0,0 +1,268 @@ +/**************************************************************************** +** +** 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 "qquickitemparticle_p.h" +#include +#include +#include +#include +#include + +QT_BEGIN_NAMESPACE + +/*! + \qmlclass ItemParticle QQuickItemParticle + \inqmlmodule QtQuick.Particles 2 + \inherits ParticlePainter + \brief The ItemParticle element allows you to specify your own delegate to paint particles. + +*/ + + +/*! + \qmlmethod void QtQuick.Particles2::ItemParticle::freeze(Item item) + + Suspends the flow of time for the logical particle which item represents, allowing you to control its movement. +*/ + +/*! + \qmlmethod void QtQuick.Particles2::ItemParticle::unfreeze(Item item) + + Restarts the flow of time for the logical particle which item represents, allowing it to be moved by the particle system again. +*/ + +/*! + \qmlmethod void QtQuick.Particles2::ItemParticle::take(Item item, bool prioritize) + + Asks the ItemParticle to take over control of item. It will be emitted when there is a logical particle available. + + By default items form a queue when waiting for a logical particle, but if prioritize is true then it will go immediately to the + head of the queue. +*/ +/*! + \qmlmethod void QtQuick.Particles2::ItemParticle::give(Item item) + + Orders the ItemParticle to give you control of the item. It will cease controlling it and the item will lose its association to the logical particle. +*/ + +/*! + \qmlproperty bool QtQuick.Particles2::ItemParticle::fade + + If true, the item will automatically be faded in and out + at the ends of its lifetime. If false, you will have to + implement any entry effect yourself. + + Default is true. +*/ +/*! + \qmlproperty Component QtQuick.Particles2::ItemParticle::delegate + + An instance of the delegate will be created for every logical + particle, and moved along with it. +*/ + +QQuickItemParticle::QQuickItemParticle(QQuickItem *parent) : + QQuickParticlePainter(parent), m_fade(true), m_delegate(0) +{ + setFlag(QQuickItem::ItemHasContents); + QTimer* manageDelegates = new QTimer(this);//TODO: don't leak + connect(manageDelegates, SIGNAL(timeout()), + this, SLOT(tick())); + manageDelegates->setInterval(16); + manageDelegates->setSingleShot(false); + manageDelegates->start(); +} + + +void QQuickItemParticle::freeze(QQuickItem* item) +{ + m_stasis << item; +} + + +void QQuickItemParticle::unfreeze(QQuickItem* item) +{ + m_stasis.remove(item); +} + +void QQuickItemParticle::take(QQuickItem *item, bool prioritize) +{ + if (prioritize) + m_pendingItems.push_front(item); + else + m_pendingItems.push_back(item); +} + +void QQuickItemParticle::give(QQuickItem *item) +{ + //TODO: This +} + +void QQuickItemParticle::initialize(int gIdx, int pIdx) +{ + m_loadables << m_system->groupData[gIdx]->data[pIdx];//defer to other thread +} + +void QQuickItemParticle::commit(int, int) +{ +} + +void QQuickItemParticle::tick() +{ + foreach (QQuickItem* item, m_deletables){ + if (m_fade) + item->setOpacity(0.); + item->setVisible(false); + QQuickItemParticleAttached* mpa; + if ((mpa = qobject_cast(qmlAttachedPropertiesObject(item)))) + mpa->detach();//reparent as well? + //TODO: Delete iff we created it + m_activeCount--; + } + m_deletables.clear(); + + foreach (QQuickParticleData* d, m_loadables){ + if (m_stasis.contains(d->delegate)) + qWarning() << "Current model particles prefers overwrite:false"; + //remove old item from the particle that is dying to make room for this one + if (d->delegate) + m_deletables << d->delegate; + d->delegate = 0; + if (!m_pendingItems.isEmpty()){ + d->delegate = m_pendingItems.front(); + m_pendingItems.pop_front(); + }else if (m_delegate){ + d->delegate = qobject_cast(m_delegate->create(qmlContext(this))); + } + if (d->delegate && d){//###Data can be zero if creating an item leads to a reset - this screws things up. + d->delegate->setX(d->curX() - d->delegate->width()/2);//TODO: adjust for system? + d->delegate->setY(d->curY() - d->delegate->height()/2); + QQuickItemParticleAttached* mpa = qobject_cast(qmlAttachedPropertiesObject(d->delegate)); + if (mpa){ + mpa->m_mp = this; + mpa->attach(); + } + d->delegate->setParentItem(this); + if (m_fade) + d->delegate->setOpacity(0.); + d->delegate->setVisible(false);//Will be set to true when we prepare the next frame + m_activeCount++; + } + } + m_loadables.clear(); +} + +void QQuickItemParticle::reset() +{ + QQuickParticlePainter::reset(); + //TODO: Cleanup items? + m_loadables.clear(); + //deletables? +} + + +QSGNode* QQuickItemParticle::updatePaintNode(QSGNode* n, UpdatePaintNodeData* d) +{ + //Dummy update just to get painting tick + if (m_pleaseReset){ + m_pleaseReset = false; + reset(); + } + prepareNextFrame(); + + update();//Get called again + if (n) + n->markDirty(QSGNode::DirtyMaterial); + return QQuickItem::updatePaintNode(n,d); +} + +void QQuickItemParticle::prepareNextFrame() +{ + if (!m_system) + return; + qint64 timeStamp = m_system->systemSync(this); + qreal curT = timeStamp/1000.0; + qreal dt = curT - m_lastT; + m_lastT = curT; + if (!m_activeCount) + return; + + //TODO: Size, better fade? + foreach (const QString &str, m_groups){ + int gIdx = m_system->groupIds[str]; + int count = m_system->groupData[gIdx]->size(); + + for (int i=0; igroupData[gIdx]->data[i]; + QQuickItem* item = data->delegate; + if (!item) + continue; + qreal t = ((timeStamp/1000.0) - data->t) / data->lifeSpan; + if (m_stasis.contains(item)) { + data->t += dt;//Stasis effect + continue; + } + if (t >= 1.0){//Usually happens from load + m_deletables << item; + data->delegate = 0; + }else{//Fade + data->delegate->setVisible(true); + if (m_fade){ + qreal o = 1.; + if (t<0.2) + o = t*5; + if (t>0.8) + o = (1-t)*5; + item->setOpacity(o); + } + } + item->setX(data->curX() - item->width()/2 - m_systemOffset.x()); + item->setY(data->curY() - item->height()/2 - m_systemOffset.y()); + } + } +} + +QQuickItemParticleAttached *QQuickItemParticle::qmlAttachedProperties(QObject *object) +{ + return new QQuickItemParticleAttached(object); +} + +QT_END_NAMESPACE diff --git a/src/declarative/particles/qquickitemparticle_p.h b/src/declarative/particles/qquickitemparticle_p.h new file mode 100644 index 0000000000..2e92b9c9ae --- /dev/null +++ b/src/declarative/particles/qquickitemparticle_p.h @@ -0,0 +1,138 @@ +/**************************************************************************** +** +** 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 ITEMPARTICLE_H +#define ITEMPARTICLE_H +#include "qquickparticlepainter_p.h" +#include +#include +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) +class QQuickVisualDataModel; +class QQuickItemParticleAttached; + +class QQuickItemParticle : public QQuickParticlePainter +{ + Q_OBJECT + Q_PROPERTY(bool fade READ fade WRITE setFade NOTIFY fadeChanged) + Q_PROPERTY(QDeclarativeComponent* delegate READ delegate WRITE setDelegate NOTIFY delegateChanged) +public: + explicit QQuickItemParticle(QQuickItem *parent = 0); + + bool fade() const { return m_fade; } + + virtual QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *); + + static QQuickItemParticleAttached *qmlAttachedProperties(QObject *object); + QDeclarativeComponent* delegate() const + { + return m_delegate; + } + +signals: + void fadeChanged(); + + void delegateChanged(QDeclarativeComponent* arg); + +public slots: + //TODO: Add a follow mode, where moving the delegate causes the logical particle to go with it? + void freeze(QQuickItem* item); + void unfreeze(QQuickItem* item); + void take(QQuickItem* item,bool prioritize=false);//take by modelparticle + void give(QQuickItem* item);//give from modelparticle + + void setFade(bool arg){if (arg == m_fade) return; m_fade = arg; emit fadeChanged();} + void setDelegate(QDeclarativeComponent* arg) + { + if (m_delegate != arg) { + m_delegate = arg; + emit delegateChanged(arg); + } + } + +protected: + virtual void reset(); + virtual void commit(int gIdx, int pIdx); + virtual void initialize(int gIdx, int pIdx); + void prepareNextFrame(); +private slots: + void tick(); +private: + QList m_deletables; + QList< QQuickParticleData* > m_loadables; + bool m_fade; + + QList m_pendingItems; + QList m_available; + QSet m_stasis; + qreal m_lastT; + int m_activeCount; + QDeclarativeComponent* m_delegate; +}; + +class QQuickItemParticleAttached : public QObject +{ + Q_OBJECT + Q_PROPERTY(QQuickItemParticle* particle READ particle CONSTANT); +public: + QQuickItemParticleAttached(QObject* parent) + : QObject(parent), m_mp(0) + {;} + QQuickItemParticle* particle() {return m_mp;} + void detach(){emit detached();} + void attach(){emit attached();} +private: + QQuickItemParticle* m_mp; + friend class QQuickItemParticle; +Q_SIGNALS: + void detached(); + void attached(); +}; + +QT_END_NAMESPACE + +QML_DECLARE_TYPEINFO(QQuickItemParticle, QML_HAS_ATTACHED_PROPERTIES) + +QT_END_HEADER +#endif // ITEMPARTICLE_H diff --git a/src/declarative/particles/qquicklineextruder.cpp b/src/declarative/particles/qquicklineextruder.cpp new file mode 100644 index 0000000000..73413537cc --- /dev/null +++ b/src/declarative/particles/qquicklineextruder.cpp @@ -0,0 +1,84 @@ +/**************************************************************************** +** +** 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 "qquicklineextruder_p.h" +#include + +/*! + \qmlclass LineShape QQuickLineExtruder + \inqmlmodule QtQuick.Particles 2 + \inherits Shape + \brief The LineShape represents a line to Affectors and Emitter + +*/ + +/*! + \qmlproperty bool QtQuick.Particles2::LineShape::mirrored + + By default, the line goes from (0,0) to (width, height) of the item that + this shape is being applied to. + + If mirrored is set to true, this will be mirrored along the y axis. + The line will then go from (0,height) to (width, 0). +*/ + +QQuickLineExtruder::QQuickLineExtruder(QObject *parent) : + QQuickParticleExtruder(parent), m_mirrored(false) +{ +} + +QPointF QQuickLineExtruder::extrude(const QRectF &r) +{ + qreal x,y; + if (!r.height()){ + x = r.width() * ((qreal)rand())/RAND_MAX; + y = 0; + }else{ + y = r.height() * ((qreal)rand())/RAND_MAX; + if (!r.width()){ + x = 0; + }else{ + x = r.width()/r.height() * y; + if (m_mirrored) + x = r.width() - x; + } + } + return QPointF(x,y); +} diff --git a/src/declarative/particles/qquicklineextruder_p.h b/src/declarative/particles/qquicklineextruder_p.h new file mode 100644 index 0000000000..8258b26043 --- /dev/null +++ b/src/declarative/particles/qquicklineextruder_p.h @@ -0,0 +1,77 @@ +/**************************************************************************** +** +** 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 LINEEXTRUDER_H +#define LINEEXTRUDER_H +#include "qquickparticleextruder_p.h" + +class QQuickLineExtruder : public QQuickParticleExtruder +{ + Q_OBJECT + //Default is topleft to bottom right. Flipped makes it topright to bottom left + Q_PROPERTY(bool mirrored READ mirrored WRITE setmirrored NOTIFY mirroredChanged) + +public: + explicit QQuickLineExtruder(QObject *parent = 0); + virtual QPointF extrude(const QRectF &); + bool mirrored() const + { + return m_mirrored; + } + +signals: + + void mirroredChanged(bool arg); + +public slots: + + void setmirrored(bool arg) + { + if (m_mirrored != arg) { + m_mirrored = arg; + emit mirroredChanged(arg); + } + } +private: + bool m_mirrored; +}; + +#endif // LINEEXTRUDER_H diff --git a/src/declarative/particles/qquickmaskextruder.cpp b/src/declarative/particles/qquickmaskextruder.cpp new file mode 100644 index 0000000000..f4850712f0 --- /dev/null +++ b/src/declarative/particles/qquickmaskextruder.cpp @@ -0,0 +1,113 @@ +/**************************************************************************** +** +** 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 "qquickmaskextruder_p.h" +#include +#include +QT_BEGIN_NAMESPACE +/*! + \qmlclass MaskShape QQuickMaskExtruder + \inqmlmodule QtQuick.Particles 2 + \inherits Shape + \brief The MaskShape element allows you to represent an image as a shape to affectors and emitters. + +*/ +/*! + \qmlproperty url QtQuick.Particles2::MaskShape::source + + The image to use as the mask. Areas with non-zero opacity + will be considered inside the shape. +*/ + + +QQuickMaskExtruder::QQuickMaskExtruder(QObject *parent) : + QQuickParticleExtruder(parent) + , m_lastWidth(-1) + , m_lastHeight(-1) +{ +} + +QPointF QQuickMaskExtruder::extrude(const QRectF &r) +{ + ensureInitialized(r); + if (!m_mask.count() || m_img.isNull()) + return r.topLeft(); + const QPointF p = m_mask[rand() % m_mask.count()]; + //### Should random sub-pixel positioning be added? + return p + r.topLeft(); +} + +bool QQuickMaskExtruder::contains(const QRectF &bounds, const QPointF &point) +{ + ensureInitialized(bounds);//###Current usage patterns WILL lead to different bounds/r calls. Separate list? + if (m_img.isNull()) + return false; + QPoint p = point.toPoint() - bounds.topLeft().toPoint(); + return m_img.rect().contains(p) && (bool)m_img.pixelIndex(p); +} + +void QQuickMaskExtruder::ensureInitialized(const QRectF &r) +{ + if (m_lastWidth == r.width() && m_lastHeight == r.height()) + return;//Same as before + m_lastWidth = r.width(); + m_lastHeight = r.height(); + + m_img = QImage(); + m_mask.clear(); + if (m_source.isEmpty()) + return; + m_img = QImage(m_source.toLocalFile()); + if (m_img.isNull()){ + qWarning() << "MaskShape: Cannot load" << qPrintable(m_source.toLocalFile()); + return; + } + m_img = m_img.createAlphaMask(); + m_img = m_img.convertToFormat(QImage::Format_Mono);//Else LSB, but I think that's easier + m_img = m_img.scaled(r.size().toSize());//TODO: Do they need aspect ratio stuff? Or tiling? + for (int i=0; i +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QQuickMaskExtruder : public QQuickParticleExtruder +{ + Q_OBJECT + Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged) +public: + explicit QQuickMaskExtruder(QObject *parent = 0); + virtual QPointF extrude(const QRectF &); + virtual bool contains(const QRectF &bounds, const QPointF &point); + + QUrl source() const + { + return m_source; + } + +signals: + + void sourceChanged(QUrl arg); + +public slots: + + void setSource(QUrl arg) + { + if (m_source != arg) { + m_source = arg; + m_lastHeight = -1;//Trigger reset + m_lastWidth = -1; + emit sourceChanged(arg); + } + } +private: + QUrl m_source; + + void ensureInitialized(const QRectF &r); + int m_lastWidth; + int m_lastHeight; + QImage m_img; + QList m_mask;//TODO: More memory efficient datastructures +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // MASKEXTRUDER_H diff --git a/src/declarative/particles/qquickparticleaffector.cpp b/src/declarative/particles/qquickparticleaffector.cpp new file mode 100644 index 0000000000..f50efc55e7 --- /dev/null +++ b/src/declarative/particles/qquickparticleaffector.cpp @@ -0,0 +1,278 @@ +/**************************************************************************** +** +** 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 "qquickparticleaffector_p.h" +#include +QT_BEGIN_NAMESPACE + +/*! + \qmlclass Affector QQuickParticleAffector + \inqmlmodule QtQuick.Particles 2 + \brief Affector elements can alter the attributes of logical particles at any point in their lifetime. + + The base Affector does not alter any attributes, but can be used to emit a signal + when a particle meets certain conditions. + + If an affector has a defined size, then it will only affect particles within its size and position on screen. + + Affectors have different performance characteristics to the other particle system elements. In particular, + they have some simplifications to try to maintain a simulation at real-time or faster. When running a system + with Affectors, irregular frame timings that grow too large ( > one second per frame) will cause the Affectors + to try and cut corners with a faster but less accurate simulation. If the system has multiple affectors the order + in which they are applied is not guaranteed, and when simulating larger time shifts they will simulate the whole + shift each, which can lead to different results compared to smaller time shifts. + + Accurate simulation for large numbers of particles (hundreds) with multiple affectors may be possible on some hardware, + but on less capable hardware you should expect small irregularties in the simulation as simulates with worse granularity. +*/ +/*! + \qmlproperty ParticleSystem QtQuick.Particles2::Affector::system + This is the system which will be affected by the element. + If the Affector is a direct child of a ParticleSystem, it will automatically be associated with it. +*/ +/*! + \qmlproperty list QtQuick.Particles2::Affector::groups + Which logical particle groups will be affected. + + If empty, it will affect all particles. +*/ +/*! + \qmlproperty list QtQuick.Particles2::Affector::whenCollidingWith + If any logical particle groups are specified here, then the affector + will only be triggered if the particle being examined intersects with + a particle of one of these groups. + + This is different from the groups property. The groups property selects which + particles might be examined, and if they meet other criteria (including being + within the bounds of the Affector, modified by shape) then they will be tested + again to see if they intersect with a particles from one of the particle groups + in whenCollidingWith. + + By default, no groups are specified. +*/ +/*! + \qmlproperty bool QtQuick.Particles2::Affector::enabled + If enabled is set to false, this affector will not affect any particles. + + Usually this is used to conditionally turn an affector on or off. + + Default value is true. +*/ +/*! + \qmlproperty bool QtQuick.Particles2::Affector::once + If once is set to true, this affector will only affect each particle + once in their lifetimes. If the affector normally simulates a continuous + effect over time, then it will simulate the effect of one second of time + the one instant it affects the particle. + + Default value is false. +*/ +/*! + \qmlproperty Shape QtQuick.Particles2::Affector::shape + If a size has been defined, the shape property can be used to affect a + non-rectangular area. +*/ +/*! + \qmlsignal QtQuick.Particles2::Affector::onAffected(x, y) + + This signal is emitted each time the affector actually affects a particle. + + x,y are the coordinates of the affected particle, relative to the ParticleSystem. + +*/ + +/*! + \qmlsignal QtQuick.Particles2::Affector::affectParticle(particle particle, real dt) + + This handler is called when particles are selected to be affected. + + dt is the time since the last time it was affected. Use dt to normalize + trajectory manipulations to real time. + + Note that JS is slower to execute, so it is not recommended to use this in + high-volume particle systems. +*/ +/*! + \qmlsignal QtQuick.Particles2::Affector::affected(real x, real y) + + This handler is called when a particle is selected to be affected. It will + only be called if signal is set to true. + + x,y is the particles current position. +*/ +QQuickParticleAffector::QQuickParticleAffector(QQuickItem *parent) : + QQuickItem(parent), m_needsReset(false), m_ignoresTime(false), m_onceOff(false), m_enabled(true) + , m_system(0), m_updateIntSet(false), m_shape(new QQuickParticleExtruder(this)) +{ +} + +bool QQuickParticleAffector::isAffectedConnected() +{ + static int idx = QObjectPrivate::get(this)->signalIndex("affected(qreal,qreal)"); + return QObjectPrivate::get(this)->isSignalConnected(idx); +} + + +void QQuickParticleAffector::componentComplete() +{ + if (!m_system && qobject_cast(parentItem())) + setSystem(qobject_cast(parentItem())); + QQuickItem::componentComplete(); +} + +bool QQuickParticleAffector::activeGroup(int g) { + if (m_updateIntSet){ + m_groupIds.clear(); + foreach (const QString &p, m_groups) + m_groupIds << m_system->groupIds[p];//###Can this occur before group ids are properly assigned? + m_updateIntSet = false; + } + return m_groupIds.isEmpty() || m_groupIds.contains(g); +} + +bool QQuickParticleAffector::shouldAffect(QQuickParticleData* d) +{ + if (!d) + return false; + if (activeGroup(d->group)){ + if ((m_onceOff && m_onceOffed.contains(qMakePair(d->group, d->index))) + || !d->stillAlive()) + return false; + //Need to have previous location for affected anyways + if (width() == 0 || height() == 0 + || m_shape->contains(QRectF(m_offset.x(), m_offset.y(), width(), height()), QPointF(d->curX(), d->curY()))){ + if (m_whenCollidingWith.isEmpty() || isColliding(d)){ + return true; + } + } + } + return false; + +} + +void QQuickParticleAffector::postAffect(QQuickParticleData* d) +{ + m_system->needsReset << d; + if (m_onceOff) + m_onceOffed << qMakePair(d->group, d->index); + if (isAffectedConnected()) + emit affected(d->curX(), d->curY()); +} + +const qreal QQuickParticleAffector::simulationDelta = 0.020; +const qreal QQuickParticleAffector::simulationCutoff = 1.000;//If this goes above 1.0, then m_once behaviour needs special codepath + +void QQuickParticleAffector::affectSystem(qreal dt) +{ + if (!m_enabled) + return; + //If not reimplemented, calls affectParticle per particle + //But only on particles in targeted system/area + updateOffsets();//### Needed if an ancestor is transformed. + if (m_onceOff) + dt = 1.0; + foreach (QQuickParticleGroupData* gd, m_system->groupData) { + if (activeGroup(m_system->groupData.key(gd))) { + foreach (QQuickParticleData* d, gd->data) { + if (shouldAffect(d)) { + bool affected = false; + qreal myDt = dt; + if (!m_ignoresTime && myDt < simulationCutoff) { + int realTime = m_system->timeInt; + m_system->timeInt -= myDt * 1000.0; + while (myDt > simulationDelta) { + m_system->timeInt += simulationDelta * 1000.0; + affected = affectParticle(d, simulationDelta) || affected; + myDt -= simulationDelta; + } + m_system->timeInt = realTime; + } + if (myDt > 0.0) + affected = affectParticle(d, myDt) || affected; + if (affected) + postAffect(d); + } + } + } + } +} + +bool QQuickParticleAffector::affectParticle(QQuickParticleData *, qreal ) +{ + return true; +} + +void QQuickParticleAffector::reset(QQuickParticleData* pd) +{//TODO: This, among other ones, should be restructured so they don't all need to remember to call the superclass + if (m_onceOff) + if (activeGroup(pd->group)) + m_onceOffed.remove(qMakePair(pd->group, pd->index)); +} + +void QQuickParticleAffector::updateOffsets() +{ + if (m_system) + m_offset = m_system->mapFromItem(this, QPointF(0, 0)); +} + +bool QQuickParticleAffector::isColliding(QQuickParticleData *d) +{ + qreal myCurX = d->curX(); + qreal myCurY = d->curY(); + qreal myCurSize = d->curSize()/2; + foreach (const QString &group, m_whenCollidingWith){ + foreach (QQuickParticleData* other, m_system->groupData[m_system->groupIds[group]]->data){ + if (!other->stillAlive()) + continue; + qreal otherCurX = other->curX(); + qreal otherCurY = other->curY(); + qreal otherCurSize = other->curSize()/2; + if ((myCurX + myCurSize > otherCurX - otherCurSize + && myCurX - myCurSize < otherCurX + otherCurSize) + && (myCurY + myCurSize > otherCurY - otherCurSize + && myCurY - myCurSize < otherCurY + otherCurSize)) + return true; + } + } + return false; +} + +QT_END_NAMESPACE diff --git a/src/declarative/particles/qquickparticleaffector_p.h b/src/declarative/particles/qquickparticleaffector_p.h new file mode 100644 index 0000000000..d254759ff6 --- /dev/null +++ b/src/declarative/particles/qquickparticleaffector_p.h @@ -0,0 +1,201 @@ +/**************************************************************************** +** +** 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 PARTICLEAFFECTOR_H +#define PARTICLEAFFECTOR_H + +#include +#include "qquickparticlesystem_p.h" +#include "qquickparticleextruder_p.h" + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QQuickParticleAffector : public QQuickItem +{ + Q_OBJECT + Q_PROPERTY(QQuickParticleSystem* system READ system WRITE setSystem NOTIFY systemChanged) + Q_PROPERTY(QStringList groups READ groups WRITE setGroups NOTIFY groupsChanged) + Q_PROPERTY(QStringList whenCollidingWith READ whenCollidingWith WRITE setWhenCollidingWith NOTIFY whenCollidingWithChanged) + Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged) + Q_PROPERTY(bool once READ onceOff WRITE setOnceOff NOTIFY onceChanged) + Q_PROPERTY(QQuickParticleExtruder* shape READ shape WRITE setShape NOTIFY shapeChanged) + +public: + explicit QQuickParticleAffector(QQuickItem *parent = 0); + virtual void affectSystem(qreal dt); + virtual void reset(QQuickParticleData*);//As some store their own data per particle? + QQuickParticleSystem* system() const + { + return m_system; + } + + QStringList groups() const + { + return m_groups; + } + + bool enabled() const + { + return m_enabled; + } + + bool onceOff() const + { + return m_onceOff; + } + + QQuickParticleExtruder* shape() const + { + return m_shape; + } + + QStringList whenCollidingWith() const + { + return m_whenCollidingWith; + } + +signals: + + void systemChanged(QQuickParticleSystem* arg); + + void groupsChanged(QStringList arg); + + void enabledChanged(bool arg); + + void onceChanged(bool arg); + + void shapeChanged(QQuickParticleExtruder* arg); + + void affected(qreal x, qreal y); + + void whenCollidingWithChanged(QStringList arg); + +public slots: +void setSystem(QQuickParticleSystem* arg) +{ + if (m_system != arg) { + m_system = arg; + m_system->registerParticleAffector(this); + emit systemChanged(arg); + } +} + +void setGroups(QStringList arg) +{ + if (m_groups != arg) { + m_groups = arg; + m_updateIntSet = true; + emit groupsChanged(arg); + } +} + +void setEnabled(bool arg) +{ + if (m_enabled != arg) { + m_enabled = arg; + emit enabledChanged(arg); + } +} + +void setOnceOff(bool arg) +{ + if (m_onceOff != arg) { + m_onceOff = arg; + m_needsReset = true; + emit onceChanged(arg); + } +} + +void setShape(QQuickParticleExtruder* arg) +{ + if (m_shape != arg) { + m_shape = arg; + emit shapeChanged(arg); + } +} + +void setWhenCollidingWith(QStringList arg) +{ + if (m_whenCollidingWith != arg) { + m_whenCollidingWith = arg; + emit whenCollidingWithChanged(arg); + } +} +public slots: + void updateOffsets(); + +protected: + friend class QQuickParticleSystem; + virtual bool affectParticle(QQuickParticleData *d, qreal dt); + bool m_needsReset:1;//### What is this really saving? + bool m_ignoresTime:1; + bool m_onceOff:1; + bool m_enabled:1; + + QQuickParticleSystem* m_system; + QStringList m_groups; + bool activeGroup(int g); + bool shouldAffect(QQuickParticleData* datum);//Call to do the logic on whether it is affecting that datum + void postAffect(QQuickParticleData* datum);//Call to do the post-affect logic on particles which WERE affected(once off, needs reset, affected signal) + virtual void componentComplete(); + QPointF m_offset; + bool isAffectedConnected(); + static const qreal simulationDelta; + static const qreal simulationCutoff; +private: + QSet m_groupIds; + QSet > m_onceOffed; + bool m_updateIntSet; + + QQuickParticleExtruder* m_shape; + + QStringList m_whenCollidingWith; + + bool isColliding(QQuickParticleData* d); +}; + +QT_END_NAMESPACE +QT_END_HEADER +#endif // PARTICLEAFFECTOR_H diff --git a/src/declarative/particles/qquickparticleemitter.cpp b/src/declarative/particles/qquickparticleemitter.cpp new file mode 100644 index 0000000000..f227256f1b --- /dev/null +++ b/src/declarative/particles/qquickparticleemitter.cpp @@ -0,0 +1,501 @@ +/**************************************************************************** +** +** 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 "qquickparticleemitter_p.h" +#include +QT_BEGIN_NAMESPACE + + +/*! + \qmlclass Emitter QQuickParticleEmitter + \inqmlmodule QtQuick.Particles 2 + \brief The Emitter element allows you to emit logical particles. + + This element emits logical particles into the ParticleSystem, with the + given starting attributes. + + Note that logical particles are not + automatically rendered, you will need to have one or more + ParticlePainter elements visualizing them. + + Note that the given starting attributes can be modified at any point + in the particle's lifetime by any Affector element in the same + ParticleSystem. This includes attributes like lifespan. +*/ + + +/*! + \qmlproperty ParticleSystem QtQuick.Particles2::Emitter::system + + This is the Particle system that the Emitter will emit into. + This can be omitted if the Emitter is a direct child of the ParticleSystem +*/ +/*! + \qmlproperty string QtQuick.Particles2::Emitter::group + + This is the logical particle group which it will emit into. + + Default value is "" (empty string). +*/ +/*! + \qmlproperty Shape QtQuick.Particles2::Emitter::shape + + This shape is applied with the size of the Emitter. Particles will be emitted + randomly from any area covered by the shape. + + The default shape is a filled in rectangle, which corresponds to the full bounding + box of the Emitter. +*/ +/*! + \qmlproperty bool QtQuick.Particles2::Emitter::emitting + + If set to false, the emitter will cease emissions until it is set to true. + + Default value is true. +*/ +/*! + \qmlproperty real QtQuick.Particles2::Emitter::emitRate + + Number of particles emitted per second. + + Default value is 10 particles per second. +*/ +/*! + \qmlproperty int QtQuick.Particles2::Emitter::lifeSpan + + The time in milliseconds each emitted particle should last for. + + If you do not want particles to automatically die after a time, for example if + you wish to dispose of them manually, set lifeSpan to Emitter.InfiniteLife. + + lifeSpans greater than or equal to 600000 (10 minutes) will be treated as infinite. + Particles with lifeSpans less than or equal to 0 will start out dead. + + Default value is 1000 (one second). +*/ +/*! + \qmlproperty int QtQuick.Particles2::Emitter::lifeSpanVariation + + Particle lifespans will vary by up to this much in either direction. + + Default value is 0. +*/ + +/*! + \qmlproperty int QtQuick.Particles2::Emitter::maximumEmitted + + The maximum number of particles at a time that this emitter will have alive. + + This can be set as a performance optimization (when using burst and pulse) or + to stagger emissions. + + If this is set to a number below zero, then there is no maximum limit on the number + of particles this emitter can have alive. + + The default value is -1. +*/ +/*! + \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. + + Default value is 16. +*/ +/*! + \qmlproperty real QtQuick.Particles2::Emitter::endSize + + The size in pixels of the particles at the end of their life. Size will + be linearly interpolated during the life of the particle from this value and + size. If endSize is -1, then the size of the particle will remain constant at + the starting size. + + Default value is -1. +*/ +/*! + \qmlproperty real QtQuick.Particles2::Emitter::sizeVariation + + The size of a particle can vary by this much up or down from size/endSize. The same + random addition is made to both size and endSize for a single particle. + + Default value is 0. +*/ +/*! + \qmlproperty StochasticDirection QtQuick.Particles2::Emitter::speed + + The starting speed of the particles emitted. +*/ +/*! + \qmlproperty StochasticDirection QtQuick.Particles2::Emitter::acceleration + + The starting acceleraton of the particles emitted. +*/ +/*! + \qmlproperty qreal QtQuick.Particles2::Emitter::speedFromMovement + + If this value is non-zero, then any movement of the emitter will provide additional + starting velocity to the particles based on the movement. The additional vector will be the + same angle as the emitter's movement, with a magnitude that is the magnitude of the emitters + movement multiplied by speedFromMovement. + + Default value is 0. +*/ + +/*! + \qmlsignal QtQuick.Particles2::Emitter::onEmitParticles(Array particles) + + This handler is called when particles are emitted. particles is a javascript + array of Particle objects. You can modify particle attributes directly within the handler. + + Note that JS is slower to execute, so it is not recommended to use this in + high-volume particle systems. +*/ + +/*! \qmlmethod QtQuick.Particles2::Emitter::burst(int count) + + Emits count particles from this emitter immediately. +*/ + +/*! \qmlmethod QtQuick.Particles2::Emitter::burst(int x, int y, int count) + + Emits count particles from this emitter immediately. The particles are emitted + as if the Emitter was positioned at x,y but all other properties are the same. +*/ + +/*! \qmlmethod QtQuick.Particles2::Emitter::pulse(int duration) + + If the emitter is not enabled, enables it for duration milliseconds and then switches + it back off. +*/ + +QQuickParticleEmitter::QQuickParticleEmitter(QQuickItem *parent) : + QQuickItem(parent) + , m_particlesPerSecond(10) + , m_particleDuration(1000) + , m_particleDurationVariation(0) + , m_enabled(true) + , m_system(0) + , m_extruder(0) + , m_defaultExtruder(0) + , m_speed(&m_nullVector) + , m_acceleration(&m_nullVector) + , m_particleSize(16) + , m_particleEndSize(-1) + , m_particleSizeVariation(0) + , m_startTime(0) + , m_overwrite(true) + , m_pulseLeft(0) + , m_maxParticleCount(-1) + , m_speed_from_movement(0) + , m_reset_last(true) + , m_last_timestamp(-1) + , m_last_emission(0) + +{ + //TODO: Reset speed/acc back to null vector? Or allow null pointer? + connect(this, SIGNAL(maximumEmittedChanged(int)), + this, SIGNAL(particleCountChanged())); + connect(this, SIGNAL(particlesPerSecondChanged(qreal)), + this, SIGNAL(particleCountChanged())); + connect(this, SIGNAL(particleDurationChanged(int)), + this, SIGNAL(particleCountChanged())); +} + +QQuickParticleEmitter::~QQuickParticleEmitter() +{ + if (m_defaultExtruder) + delete m_defaultExtruder; +} + +bool QQuickParticleEmitter::isEmitConnected() +{ + static int idx = QObjectPrivate::get(this)->signalIndex("emitParticles(QDeclarativeV8Handle)"); + return QObjectPrivate::get(this)->isSignalConnected(idx); +} + +void QQuickParticleEmitter::componentComplete() +{ + if (!m_system && qobject_cast(parentItem())) + setSystem(qobject_cast(parentItem())); + QQuickItem::componentComplete(); +} + +void QQuickParticleEmitter::setEnabled(bool arg) +{ + if (m_enabled != arg) { + m_enabled = arg; + emit enabledChanged(arg); + } +} + + +QQuickParticleExtruder* QQuickParticleEmitter::effectiveExtruder() +{ + if (m_extruder) + return m_extruder; + if (!m_defaultExtruder) + m_defaultExtruder = new QQuickParticleExtruder; + return m_defaultExtruder; +} + +void QQuickParticleEmitter::pulse(int milliseconds) +{ + if (!particleCount()) + qWarning() << "pulse called on an emitter with a particle count of zero"; + if (!m_enabled) + m_pulseLeft = milliseconds; +} + +void QQuickParticleEmitter::burst(int num) +{ + if (!particleCount()) + qWarning() << "burst called on an emitter with a particle count of zero"; + m_burstQueue << qMakePair(num, QPointF(x(), y())); +} + +void QQuickParticleEmitter::burst(int num, qreal x, qreal y) +{ + if (!particleCount()) + qWarning() << "burst called on an emitter with a particle count of zero"; + m_burstQueue << qMakePair(num, QPointF(x, y)); +} + +void QQuickParticleEmitter::setMaxParticleCount(int arg) +{ + if (m_maxParticleCount != arg) { + if (arg < 0 && m_maxParticleCount >= 0){ + connect(this, SIGNAL(particlesPerSecondChanged(qreal)), + this, SIGNAL(particleCountChanged())); + connect(this, SIGNAL(particleDurationChanged(int)), + this, SIGNAL(particleCountChanged())); + }else if (arg >= 0 && m_maxParticleCount < 0){ + disconnect(this, SIGNAL(particlesPerSecondChanged(qreal)), + this, SIGNAL(particleCountChanged())); + disconnect(this, SIGNAL(particleDurationChanged(int)), + this, SIGNAL(particleCountChanged())); + } + m_overwrite = arg < 0; + m_maxParticleCount = arg; + emit maximumEmittedChanged(arg); + } +} + +int QQuickParticleEmitter::particleCount() const +{ + if (m_maxParticleCount >= 0) + return m_maxParticleCount; + return m_particlesPerSecond*((m_particleDuration+m_particleDurationVariation)/1000.0); +} + +void QQuickParticleEmitter::setSpeedFromMovement(qreal t) +{ + if (t == m_speed_from_movement) + return; + m_speed_from_movement = t; + emit speedFromMovementChanged(); +} + +void QQuickParticleEmitter::reset() +{ + m_reset_last = true; +} + +void QQuickParticleEmitter::emitWindow(int timeStamp) +{ + if (m_system == 0) + return; + if ((!m_enabled || !m_particlesPerSecond)&& !m_pulseLeft && m_burstQueue.isEmpty()){ + m_reset_last = true; + return; + } + + if (m_reset_last) { + m_last_emitter = m_last_last_emitter = QPointF(x(), y()); + if (m_last_timestamp == -1) + m_last_timestamp = (timeStamp - m_startTime)/1000.; + else + m_last_timestamp = timeStamp/1000.; + m_last_emission = m_last_timestamp; + m_reset_last = false; + m_emitCap = particleCount(); + } + + if (m_pulseLeft){ + m_pulseLeft -= timeStamp - m_last_timestamp * 1000.; + if (m_pulseLeft < 0){ + if (!m_enabled) + timeStamp += m_pulseLeft; + m_pulseLeft = 0; + } + } + qreal time = timeStamp / 1000.; + qreal particleRatio = 1. / m_particlesPerSecond; + qreal pt = m_last_emission; + qreal maxLife = (m_particleDuration + m_particleDurationVariation)/1000.0; + if (pt + maxLife < time)//We missed so much, that we should skip emiting particles that are dead by now + pt = time - maxLife; + + qreal opt = pt; // original particle time + qreal dt = time - m_last_timestamp; // timestamp delta... + if (!dt) + dt = 0.000001; + + // emitter difference since last... + qreal dex = (x() - m_last_emitter.x()); + qreal dey = (y() - m_last_emitter.y()); + + qreal ax = (m_last_last_emitter.x() + m_last_emitter.x()) / 2; + qreal bx = m_last_emitter.x(); + qreal cx = (x() + m_last_emitter.x()) / 2; + qreal ay = (m_last_last_emitter.y() + m_last_emitter.y()) / 2; + qreal by = m_last_emitter.y(); + qreal cy = (y() + m_last_emitter.y()) / 2; + + qreal sizeAtEnd = m_particleEndSize >= 0 ? m_particleEndSize : m_particleSize; + qreal emitter_x_offset = m_last_emitter.x() - x(); + qreal emitter_y_offset = m_last_emitter.y() - y(); + if (!m_burstQueue.isEmpty() && !m_pulseLeft && !m_enabled)//'outside time' emissions only + pt = time; + + QList toEmit; + + while ((pt < time && m_emitCap) || !m_burstQueue.isEmpty()) { + //int pos = m_last_particle % m_particle_count; + QQuickParticleData* datum = m_system->newDatum(m_system->groupIds[m_group], !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; + qreal vx = + - 2 * ax * (1 - t) + + 2 * bx * (1 - 2 * t) + + 2 * cx * t; + qreal vy = + - 2 * ay * (1 - t) + + 2 * by * (1 - 2 * t) + + 2 * cy * t; + + + // Particle timestamp + datum->t = pt; + datum->lifeSpan = + (m_particleDuration + + ((rand() % ((m_particleDurationVariation*2) + 1)) - m_particleDurationVariation)) + / 1000.0; + + if (datum->lifeSpan >= m_system->maxLife){ + datum->lifeSpan = m_system->maxLife; + m_emitCap--;//emitCap keeps us from reemitting 'infinite' particles after their life. Unless you reset the emitter. + } + + // Particle position + QRectF boundsRect; + if (!m_burstQueue.isEmpty()){ + boundsRect = QRectF(m_burstQueue.first().second.x() - x(), m_burstQueue.first().second.y() - y(), + width(), height()); + } else { + boundsRect = QRectF(emitter_x_offset + dex * (pt - opt) / dt, emitter_y_offset + dey * (pt - opt) / dt + , width(), height()); + } + QPointF newPos = effectiveExtruder()->extrude(boundsRect); + datum->x = newPos.x(); + datum->y = newPos.y(); + + // Particle speed + const QPointF &speed = m_speed->sample(newPos); + datum->vx = speed.x() + + m_speed_from_movement * vx; + datum->vy = speed.y() + + m_speed_from_movement * vy; + + // Particle acceleration + const QPointF &accel = m_acceleration->sample(newPos); + datum->ax = accel.x(); + datum->ay = accel.y(); + + // Particle size + float sizeVariation = -m_particleSizeVariation + + rand() / float(RAND_MAX) * m_particleSizeVariation * 2; + + float size = qMax((qreal)0.0 , m_particleSize + sizeVariation); + float endSize = qMax((qreal)0.0 , sizeAtEnd + sizeVariation); + + datum->size = size;// * float(m_emitting); + datum->endSize = endSize;// * float(m_emitting); + + toEmit << datum; + } + if (m_burstQueue.isEmpty()){ + pt += particleRatio; + }else{ + m_burstQueue.first().first--; + if (m_burstQueue.first().first <= 0) + m_burstQueue.pop_front(); + } + } + + if (isEmitConnected()) { + v8::HandleScope handle_scope; + v8::Context::Scope scope(QDeclarativeEnginePrivate::getV8Engine(qmlEngine(this))->context()); + v8::Handle array = v8::Array::New(toEmit.size()); + for (int i=0; iSet(i, toEmit[i]->v8Value().toHandle()); + + emitParticles(QDeclarativeV8Handle::fromHandle(array));//A chance for arbitrary JS changes + } + foreach (QQuickParticleData* d, toEmit) + m_system->emitParticle(d); + + m_last_emission = pt; + + m_last_last_last_emitter = m_last_last_emitter; + m_last_last_emitter = m_last_emitter; + m_last_emitter = QPointF(x(), y()); + m_last_timestamp = time; +} + + +QT_END_NAMESPACE diff --git a/src/declarative/particles/qquickparticleemitter_p.h b/src/declarative/particles/qquickparticleemitter_p.h new file mode 100644 index 0000000000..2d725e5c9e --- /dev/null +++ b/src/declarative/particles/qquickparticleemitter_p.h @@ -0,0 +1,351 @@ +/**************************************************************************** +** +** 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 PARTICLEEMITTER_H +#define PARTICLEEMITTER_H + +#include +#include +#include "qquickparticlesystem_p.h" +#include "qquickparticleextruder_p.h" +#include "qquickdirection_p.h" + +#include +#include +#include +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QQuickParticleEmitter : public QQuickItem +{ + Q_OBJECT + Q_PROPERTY(QQuickParticleSystem* system READ system WRITE setSystem NOTIFY systemChanged) + Q_PROPERTY(QString group READ group WRITE setGroup NOTIFY groupChanged) + Q_PROPERTY(QQuickParticleExtruder* shape READ extruder WRITE setExtruder NOTIFY extruderChanged) + Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged) + Q_PROPERTY(int startTime READ startTime WRITE setStartTime NOTIFY startTimeChanged) + + Q_PROPERTY(qreal emitRate READ particlesPerSecond WRITE setParticlesPerSecond NOTIFY particlesPerSecondChanged) + Q_PROPERTY(int lifeSpan READ particleDuration WRITE setParticleDuration NOTIFY particleDurationChanged) + Q_PROPERTY(int lifeSpanVariation READ particleDurationVariation WRITE setParticleDurationVariation NOTIFY particleDurationVariationChanged) + Q_PROPERTY(int maximumEmitted READ maxParticleCount WRITE setMaxParticleCount NOTIFY maximumEmittedChanged) + + Q_PROPERTY(qreal size READ particleSize WRITE setParticleSize NOTIFY particleSizeChanged) + Q_PROPERTY(qreal endSize READ particleEndSize WRITE setParticleEndSize NOTIFY particleEndSizeChanged) + Q_PROPERTY(qreal sizeVariation READ particleSizeVariation WRITE setParticleSizeVariation NOTIFY particleSizeVariationChanged) + + Q_PROPERTY(QQuickDirection *speed READ speed WRITE setSpeed NOTIFY speedChanged) + Q_PROPERTY(QQuickDirection *acceleration READ acceleration WRITE setAcceleration NOTIFY accelerationChanged) + Q_PROPERTY(qreal speedFromMovement READ speedFromMovement WRITE setSpeedFromMovement NOTIFY speedFromMovementChanged) + + Q_ENUMS(Lifetime) +public: + explicit QQuickParticleEmitter(QQuickItem *parent = 0); + virtual ~QQuickParticleEmitter(); + virtual void emitWindow(int timeStamp); + + enum Lifetime { + InfiniteLife = QQuickParticleSystem::maxLife + }; + + bool enabled() const + { + return m_enabled; + } + + qreal particlesPerSecond() const + { + return m_particlesPerSecond; + } + + int particleDuration() const + { + return m_particleDuration; + } + + QQuickParticleSystem* system() const + { + return m_system; + } + + QString group() const + { + return m_group; + } + + int particleDurationVariation() const + { + return m_particleDurationVariation; + } + + qreal speedFromMovement() const { return m_speed_from_movement; } + void setSpeedFromMovement(qreal s); + virtual void componentComplete(); +signals: + void emitParticles(QDeclarativeV8Handle particles); + void particlesPerSecondChanged(qreal); + void particleDurationChanged(int); + void enabledChanged(bool); + + void systemChanged(QQuickParticleSystem* arg); + + void groupChanged(QString arg); + + void particleDurationVariationChanged(int arg); + + void extruderChanged(QQuickParticleExtruder* arg); + + void particleSizeChanged(qreal arg); + + void particleEndSizeChanged(qreal arg); + + void particleSizeVariationChanged(qreal arg); + + void speedChanged(QQuickDirection * arg); + + void accelerationChanged(QQuickDirection * arg); + + void maximumEmittedChanged(int arg); + void particleCountChanged(); + + void speedFromMovementChanged(); + + void startTimeChanged(int arg); + +public slots: + void pulse(int milliseconds); + void burst(int num); + void burst(int num, qreal x, qreal y); + + void setEnabled(bool arg); + + void setParticlesPerSecond(qreal arg) + { + if (m_particlesPerSecond != arg) { + m_particlesPerSecond = arg; + emit particlesPerSecondChanged(arg); + } + } + + void setParticleDuration(int arg) + { + if (m_particleDuration != arg) { + m_particleDuration = arg; + emit particleDurationChanged(arg); + } + } + + void setSystem(QQuickParticleSystem* arg) + { + if (m_system != arg) { + m_system = arg; + m_system->registerParticleEmitter(this); + emit systemChanged(arg); + } + } + + void setGroup(QString arg) + { + if (m_group != arg) { + m_group = arg; + emit groupChanged(arg); + } + } + + void setParticleDurationVariation(int arg) + { + if (m_particleDurationVariation != arg) { + m_particleDurationVariation = arg; + emit particleDurationVariationChanged(arg); + } + } + void setExtruder(QQuickParticleExtruder* arg) + { + if (m_extruder != arg) { + m_extruder = arg; + emit extruderChanged(arg); + } + } + + void setParticleSize(qreal arg) + { + if (m_particleSize != arg) { + m_particleSize = arg; + emit particleSizeChanged(arg); + } + } + + void setParticleEndSize(qreal arg) + { + if (m_particleEndSize != arg) { + m_particleEndSize = arg; + emit particleEndSizeChanged(arg); + } + } + + void setParticleSizeVariation(qreal arg) + { + if (m_particleSizeVariation != arg) { + m_particleSizeVariation = arg; + emit particleSizeVariationChanged(arg); + } + } + + void setSpeed(QQuickDirection * arg) + { + if (m_speed != arg) { + m_speed = arg; + emit speedChanged(arg); + } + } + + void setAcceleration(QQuickDirection * arg) + { + if (m_acceleration != arg) { + m_acceleration = arg; + emit accelerationChanged(arg); + } + } + + void setMaxParticleCount(int arg); + + void setStartTime(int arg) + { + if (m_startTime != arg) { + m_startTime = arg; + emit startTimeChanged(arg); + } + } + + virtual void reset(); +public: + int particleCount() const; + + QQuickParticleExtruder* extruder() const + { + return m_extruder; + } + + qreal particleSize() const + { + return m_particleSize; + } + + qreal particleEndSize() const + { + return m_particleEndSize; + } + + qreal particleSizeVariation() const + { + return m_particleSizeVariation; + } + + QQuickDirection * speed() const + { + return m_speed; + } + + QQuickDirection * acceleration() const + { + return m_acceleration; + } + + int maxParticleCount() const + { + return m_maxParticleCount; + } + + int startTime() const + { + return m_startTime; + } + +protected: + qreal m_particlesPerSecond; + int m_particleDuration; + int m_particleDurationVariation; + bool m_enabled; + QQuickParticleSystem* m_system; + QString m_group; + QQuickParticleExtruder* m_extruder; + QQuickParticleExtruder* m_defaultExtruder; + QQuickParticleExtruder* effectiveExtruder(); + QQuickDirection * m_speed; + QQuickDirection * m_acceleration; + qreal m_particleSize; + qreal m_particleEndSize; + qreal m_particleSizeVariation; + + qreal m_speedFromMovement; + int m_startTime; + bool m_overwrite; + + int m_pulseLeft; + QList > m_burstQueue; + int m_maxParticleCount; + + //Used in default implementation, but might be useful + qreal m_speed_from_movement; + + int m_emitCap; + bool m_reset_last; + qreal m_last_timestamp; + qreal m_last_emission; + + QPointF m_last_emitter; + QPointF m_last_last_emitter; + QPointF m_last_last_last_emitter; + + bool isEmitConnected(); +private: + QQuickDirection m_nullVector; + +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // PARTICLEEMITTER_H diff --git a/src/declarative/particles/qquickparticleextruder.cpp b/src/declarative/particles/qquickparticleextruder.cpp new file mode 100644 index 0000000000..8b25de26be --- /dev/null +++ b/src/declarative/particles/qquickparticleextruder.cpp @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** 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 "qquickparticleextruder_p.h" + +QT_BEGIN_NAMESPACE + +/*! + \qmlclass Shape QQuickParticleExtruder + \inqmlmodule QtQuick.Particles 2 + \brief The Shape element allows you to specify an area for affectors and emitter. + + The base class is just a rectangle. +*/ + +QQuickParticleExtruder::QQuickParticleExtruder(QObject *parent) : + QObject(parent) +{ +} + +QPointF QQuickParticleExtruder::extrude(const QRectF &rect) +{ + return QPointF(((qreal)rand() / RAND_MAX) * rect.width() + rect.x(), + ((qreal)rand() / RAND_MAX) * rect.height() + rect.y()); +} + +bool QQuickParticleExtruder::contains(const QRectF &bounds, const QPointF &point) +{ + return bounds.contains(point); +} + +QT_END_NAMESPACE diff --git a/src/declarative/particles/qquickparticleextruder_p.h b/src/declarative/particles/qquickparticleextruder_p.h new file mode 100644 index 0000000000..7969abad7c --- /dev/null +++ b/src/declarative/particles/qquickparticleextruder_p.h @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** 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 PARTICLEEXTRUDER_H +#define PARTICLEEXTRUDER_H + +#include +#include +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QQuickParticleExtruder : public QObject +{ + Q_OBJECT + +public: + explicit QQuickParticleExtruder(QObject *parent = 0); + virtual QPointF extrude(const QRectF &); + virtual bool contains(const QRectF &bounds, const QPointF &point); + +signals: +public slots: +protected: +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // PARTICLEEXTRUDER_H diff --git a/src/declarative/particles/qquickparticlegroup.cpp b/src/declarative/particles/qquickparticlegroup.cpp new file mode 100644 index 0000000000..5486339611 --- /dev/null +++ b/src/declarative/particles/qquickparticlegroup.cpp @@ -0,0 +1,143 @@ +/**************************************************************************** +** +** 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 "qquickparticlegroup_p.h" + +/*! + \qmlclass ParticleGroup QQuickParticleGroup + \inqmlmodule QtQuick.Particles 2 + \brief ParticleGroup elements allow you to set attributes on a logical particle group. + + This element allows you to set timed transitions on particle groups. + + You can also use this element to group particle system elements related to the logical + particle group. Emitters, Affectors and Painters set as direct children of a ParticleGroup + will automatically apply to that logical particle group. TrailEmitters will automatically follow + the group. + + If a ParticleGroup element is not defined for a group, the group will function normally as if + none of the transition properties were set. +*/ +/*! + \qmlproperty ParticleSystem QtQuick.Particles2::ParticleGroup::system + This is the system which will contain the group. + + If the ParticleGroup is a direct child of a ParticleSystem, it will automatically be associated with it. +*/ +/*! + \qmlproperty string QtQuick.Particles2::ParticleGroup::name + This is the name of the particle group, and how it is generally referred to by other elements. + + If elements refer to a name which does not have an explicit ParticleGroup created, it will + work normally (with no transitions specified for the group). If you do not need to assign + duration based transitions to a group, you do not need to create a ParticleGroup with that name (although you may). +*/ +/*! + \qmlproperty int QtQuick.Particles2::ParticleGroup::duration + The time in milliseconds before the group will attempt to transition. + +*/ +/*! + \qmlproperty ParticleSystem QtQuick.Particles2::ParticleGroup::durationVariation + The maximum number of milliseconds that the duration of the transition cycle varies per particle in the group. + + Default value is zero. +*/ +/*! + \qmlproperty ParticleSystem QtQuick.Particles2::ParticleGroup::to + The weighted list of transitions valid for this group. + + If the chosen transition stays in this group, another duration (+/- up to durationVariation) + milliseconds will occur before another transition is attempted. +*/ + +QQuickParticleGroup::QQuickParticleGroup(QObject* parent) + : QQuickStochasticState(parent) + , m_system(0) +{ + +} + +void delayedRedirect(QDeclarativeListProperty *prop, QObject *value) +{ + QQuickParticleGroup* pg = qobject_cast(prop->object); + if (pg) + pg->delayRedirect(value); +} + +QDeclarativeListProperty QQuickParticleGroup::particleChildren() +{ + QQuickParticleSystem* system = qobject_cast(parent()); + if (system) + return QDeclarativeListProperty(this, 0, &QQuickParticleSystem::statePropertyRedirect); + else + return QDeclarativeListProperty(this, 0, &delayedRedirect); +} + +void QQuickParticleGroup::setSystem(QQuickParticleSystem* arg) +{ + if (m_system != arg) { + m_system = arg; + m_system->registerParticleGroup(this); + performDelayedRedirects(); + emit systemChanged(arg); + } +} + +void QQuickParticleGroup::delayRedirect(QObject *obj) +{ + m_delayedRedirects << obj; +} + +void QQuickParticleGroup::performDelayedRedirects() +{ + if (!m_system) + return; + foreach (QObject* obj, m_delayedRedirects) + m_system->stateRedirect(this, m_system, obj); + + m_delayedRedirects.clear(); +} + +void QQuickParticleGroup::componentComplete(){ + if (!m_system && qobject_cast(parent())) + setSystem(qobject_cast(parent())); +} diff --git a/src/declarative/particles/qquickparticlegroup_p.h b/src/declarative/particles/qquickparticlegroup_p.h new file mode 100644 index 0000000000..547e7fc597 --- /dev/null +++ b/src/declarative/particles/qquickparticlegroup_p.h @@ -0,0 +1,112 @@ +/**************************************************************************** +** +** 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 QQuickPARTICLEGROUP +#define QQuickPARTICLEGROUP +#include +#include "qquickparticlesystem_p.h" +#include "qdeclarativeparserstatus.h" + +QT_BEGIN_NAMESPACE + +class QQuickParticleGroup : public QQuickStochasticState, public QDeclarativeParserStatus +{ + Q_OBJECT + //### Would setting limits per group be useful? Or clutter the API? + //Q_PROPERTY(int maximumAlive READ maximumAlive WRITE setMaximumAlive NOTIFY maximumAliveChanged) + + Q_PROPERTY(QQuickParticleSystem* system READ system WRITE setSystem NOTIFY systemChanged) + + //Intercept children requests and assign to the group & system + Q_PROPERTY(QDeclarativeListProperty particleChildren READ particleChildren DESIGNABLE false)//### Hidden property for in-state system definitions - ought not to be used in actual "Sprite" states + Q_CLASSINFO("DefaultProperty", "particleChildren") + Q_INTERFACES(QDeclarativeParserStatus) + +public: + explicit QQuickParticleGroup(QObject* parent = 0); + + QDeclarativeListProperty particleChildren(); + + int maximumAlive() const + { + return m_maximumAlive; + } + + QQuickParticleSystem* system() const + { + return m_system; + } + +public slots: + + void setMaximumAlive(int arg) + { + if (m_maximumAlive != arg) { + m_maximumAlive = arg; + emit maximumAliveChanged(arg); + } + } + + void setSystem(QQuickParticleSystem* arg); + + void delayRedirect(QObject* obj); + +signals: + + void maximumAliveChanged(int arg); + + void systemChanged(QQuickParticleSystem* arg); + +protected: + virtual void componentComplete(); + virtual void classBegin(){;} + +private: + + void performDelayedRedirects(); + + int m_maximumAlive; + QQuickParticleSystem* m_system; + QList m_delayedRedirects; +}; + +QT_END_NAMESPACE + +#endif diff --git a/src/declarative/particles/qquickparticlepainter.cpp b/src/declarative/particles/qquickparticlepainter.cpp new file mode 100644 index 0000000000..cc0b4da181 --- /dev/null +++ b/src/declarative/particles/qquickparticlepainter.cpp @@ -0,0 +1,150 @@ +/**************************************************************************** +** +** 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 "qquickparticlepainter_p.h" +#include +QT_BEGIN_NAMESPACE +/*! + \qmlclass ParticlePainter QQuickParticlePainter + \inqmlmodule QtQuick.Particles 2 + \inherits ParticlePainter + \brief ParticlePainter elements allow you to specify how to paint particles. + + The default implementation paints nothing. See the subclasses if you want to + paint something visible. + +*/ +/*! + \qmlproperty ParticleSystem QtQuick.Particles2::ParticlePainter::system + This is the system whose particles can be painted by the element. + If the ParticlePainter is a direct child of a ParticleSystem, it will automatically be associated with it. +*/ +/*! + \qmlproperty list QtQuick.Particles2::ParticlePainter::groups + Which logical particle groups will be painted. + + If empty, it will paint the default particle group (""). +*/ +QQuickParticlePainter::QQuickParticlePainter(QQuickItem *parent) : + QQuickItem(parent), + m_system(0), m_count(0), m_pleaseReset(true), m_sentinel(new QQuickParticleData(0)) +{ +} + +void QQuickParticlePainter::componentComplete() +{ + if (!m_system && qobject_cast(parentItem())) + setSystem(qobject_cast(parentItem())); + QQuickItem::componentComplete(); +} + + +void QQuickParticlePainter::setSystem(QQuickParticleSystem *arg) +{ + if (m_system != arg) { + m_system = arg; + if (m_system){ + m_system->registerParticlePainter(this); + reset(); + } + emit systemChanged(arg); + } +} + +void QQuickParticlePainter::load(QQuickParticleData* d) +{ + if (m_pleaseReset) + return; + initialize(d->group, d->index); + m_pendingCommits << qMakePair(d->group, d->index); +} + +void QQuickParticlePainter::reload(QQuickParticleData* d) +{ + if (m_pleaseReset) + return; + m_pendingCommits << qMakePair(d->group, d->index); +} + +void QQuickParticlePainter::reset() +{ +} + +void QQuickParticlePainter::setCount(int c)//### TODO: some resizeing so that particles can reallocate on size change instead of recreate +{ + Q_ASSERT(c >= 0); //XXX + if (c == m_count) + return; + m_count = c; + emit countChanged(); + reset(); +} + +int QQuickParticlePainter::count() +{ + return m_count; +} + +void QQuickParticlePainter::calcSystemOffset(bool resetPending) +{ + if (!m_system || !parentItem()) + return; + QPointF lastOffset = m_systemOffset; + m_systemOffset = -1 * this->mapFromItem(m_system, QPointF(0.0, 0.0)); + if (lastOffset != m_systemOffset && !resetPending){ + //Reload all particles//TODO: Necessary? + foreach (const QString &g, m_groups){ + int gId = m_system->groupIds[g]; + foreach (QQuickParticleData* d, m_system->groupData[gId]->data) + reload(d); + } + } +} +typedef QPair intPair; +void QQuickParticlePainter::performPendingCommits() +{ + calcSystemOffset(); + foreach (intPair p, m_pendingCommits) + commit(p.first, p.second); + m_pendingCommits.clear(); +} + +QT_END_NAMESPACE diff --git a/src/declarative/particles/qquickparticlepainter_p.h b/src/declarative/particles/qquickparticlepainter_p.h new file mode 100644 index 0000000000..b18597d1c9 --- /dev/null +++ b/src/declarative/particles/qquickparticlepainter_p.h @@ -0,0 +1,134 @@ +/**************************************************************************** +** +** 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 PARTICLE_H +#define PARTICLE_H + +#include +#include +#include +#include "qquickparticlesystem_p.h" + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + + +class QQuickParticlePainter : public QQuickItem +{ + Q_OBJECT + Q_PROPERTY(QQuickParticleSystem* system READ system WRITE setSystem NOTIFY systemChanged) + Q_PROPERTY(QStringList groups READ groups WRITE setGroups NOTIFY groupsChanged) + +public: + explicit QQuickParticlePainter(QQuickItem *parent = 0); + //Data Interface to system + void load(QQuickParticleData*); + void reload(QQuickParticleData*); + void setCount(int c); + int count(); + void performPendingCommits();//Called from updatePaintNode + QQuickParticleSystem* system() const + { + return m_system; + } + + + QStringList groups() const + { + return m_groups; + } + +signals: + void countChanged(); + void systemChanged(QQuickParticleSystem* arg); + + void groupsChanged(QStringList arg); + +public slots: + void setSystem(QQuickParticleSystem* arg); + + void setGroups(QStringList arg) + { + if (m_groups != arg) { + m_groups = arg; + emit groupsChanged(arg); + } + } + + void calcSystemOffset(bool resetPending = false); + +protected: + /* Reset resets all your internal data structures. But anything attached to a particle should + be in attached data. So reset + reloads should have no visible effect. + ###Hunt down all cases where we do a complete reset for convenience and be more targeted + */ + virtual void reset(); + + virtual void componentComplete(); + virtual void initialize(int gIdx, int pIdx){//Called from main thread + Q_UNUSED(gIdx); + Q_UNUSED(pIdx); + } + virtual void commit(int gIdx, int pIdx){//Called in Render Thread + //###If you need to do something on size changed, check m_data size in this? Or we reset you every time? + Q_UNUSED(gIdx); + Q_UNUSED(pIdx); + } + + QQuickParticleSystem* m_system; + friend class QQuickParticleSystem; + int m_count; + bool m_pleaseReset;//Used by subclasses, but it's a nice optimization to know when stuff isn't going to matter. + QStringList m_groups; + QPointF m_systemOffset; + +private: + QQuickParticleData* m_sentinel; + QSet > m_pendingCommits; + //QVector m_shadowData;//For when we implement overwrite: false +}; + +QT_END_NAMESPACE +QT_END_HEADER +#endif // PARTICLE_H diff --git a/src/declarative/particles/qquickparticlesmodule.cpp b/src/declarative/particles/qquickparticlesmodule.cpp new file mode 100644 index 0000000000..26439c4f50 --- /dev/null +++ b/src/declarative/particles/qquickparticlesmodule.cpp @@ -0,0 +1,120 @@ +/**************************************************************************** +** +** 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 "qquickangledirection_p.h" +#include "qquickcustomparticle_p.h" +#include "qquickellipseextruder_p.h" +#include "qquicktrailemitter_p.h" +#include "qquickfriction_p.h" +#include "qquickgravity_p.h" +#include "qquickimageparticle_p.h" +#include "qquickitemparticle_p.h" +#include "qquickage_p.h" +#include "qquicklineextruder_p.h" +#include "qquickmaskextruder_p.h" +#include "qquickparticleaffector_p.h" +#include "qquickparticleemitter_p.h" +#include "qquickparticleextruder_p.h" +#include "qquickparticlepainter_p.h" +#include "qquickparticlesmodule_p.h" +#include "qquickparticlesystem_p.h" +#include "qquickpointattractor_p.h" +#include "qquickpointdirection_p.h" +#include "qquickspritegoal_p.h" +#include "qquickdirection_p.h" +#include "qquicktargetdirection_p.h" +#include "qquickturbulence_p.h" +#include "qquickwander_p.h" +#include "qquickcumulativedirection_p.h" +#include "qquickcustomaffector_p.h" +#include "qquickrectangleextruder_p.h" +#include "qquickparticlegroup_p.h" +#include "qquickgroupgoal_p.h" + +QT_BEGIN_NAMESPACE + +void QQuickParticlesModule::defineModule() +{ + const char* uri = "QtQuick.Particles"; + + qmlRegisterType(uri, 2, 0, "ParticleSystem"); + qmlRegisterType(uri, 2, 0, "ParticleGroup"); + + qmlRegisterType(uri, 2, 0, "ImageParticle"); + qmlRegisterType(uri, 2, 0, "CustomParticle"); + qmlRegisterType(uri, 2, 0, "ItemParticle"); + + qmlRegisterType(uri, 2, 0, "Emitter"); + qmlRegisterType(uri, 2, 0, "TrailEmitter"); + + qmlRegisterType(uri, 2, 0, "EllipseShape"); + qmlRegisterType(uri, 2, 0, "RectangleShape"); + qmlRegisterType(uri, 2, 0, "LineShape"); + qmlRegisterType(uri, 2, 0, "MaskShape"); + + qmlRegisterType(uri, 2, 0, "PointDirection"); + qmlRegisterType(uri, 2, 0, "AngleDirection"); + qmlRegisterType(uri, 2, 0, "TargetDirection"); + qmlRegisterType(uri, 2, 0, "CumulativeDirection"); + + qmlRegisterType(uri, 2, 0, "Affector"); + qmlRegisterType(uri, 2, 0, "Wander"); + qmlRegisterType(uri, 2, 0, "Friction"); + qmlRegisterType(uri, 2, 0, "Attractor"); + qmlRegisterType(uri, 2, 0, "Gravity"); + qmlRegisterType(uri, 2, 0, "Age"); + qmlRegisterType(uri, 2, 0, "SpriteGoal"); + qmlRegisterType(uri, 2, 0, "GroupGoal"); + qmlRegisterType(uri, 2, 0 , "Turbulence"); + + //Exposed just for completeness + qmlRegisterUncreatableType(uri, 2, 0, "ParticleAffector", + QStringLiteral("Abstract type. Use one of the inheriting types instead.")); + qmlRegisterUncreatableType(uri, 2, 0, "ParticlePainter", + QStringLiteral("Abstract type. Use one of the inheriting types instead.")); + qmlRegisterUncreatableType(uri, 2, 0, "ParticleExtruder", + QStringLiteral("Abstract type. Use one of the inheriting types instead.")); + qmlRegisterUncreatableType(uri, 2, 0, "NullVector", + QStringLiteral("Abstract type. Use one of the inheriting types instead.")); +} + +QT_END_NAMESPACE + diff --git a/src/declarative/particles/qquickparticlesmodule_p.h b/src/declarative/particles/qquickparticlesmodule_p.h new file mode 100644 index 0000000000..afea56293b --- /dev/null +++ b/src/declarative/particles/qquickparticlesmodule_p.h @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** 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 QQuickPARTICLESMODULE_H +#define QQuickPARTICLESMODULE_H + +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QQuickParticlesModule +{ +public: + static void defineModule(); +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // QQuickPARTICLESMODULE_H diff --git a/src/declarative/particles/qquickparticlesystem.cpp b/src/declarative/particles/qquickparticlesystem.cpp new file mode 100644 index 0000000000..767e1b94cc --- /dev/null +++ b/src/declarative/particles/qquickparticlesystem.cpp @@ -0,0 +1,1084 @@ +/**************************************************************************** +** +** 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 "qquickparticlesystem_p.h" +#include +#include "qquickparticleemitter_p.h" +#include "qquickparticleaffector_p.h" +#include "qquickparticlepainter_p.h" +#include +#include +#include "qquickv8particledata_p.h" +#include "qquickparticlegroup_p.h" + +#include "qquicktrailemitter_p.h"//###For auto-follow on states, perhaps should be in emitter? +#include +#include +#include + +QT_BEGIN_NAMESPACE +//###Switch to define later, for now user-friendly (no compilation) debugging is worth it +DEFINE_BOOL_CONFIG_OPTION(qmlParticlesDebug, QML_PARTICLES_DEBUG) +/*! + \qmlclass ParticleSystem QQuickParticleSystem + \inqmlmodule QtQuick.Particles 2 + \brief The ParticleSystem brings together ParticlePainter, Emitter and Affector elements. + +*/ + +/*! + \qmlproperty bool QtQuick.Particles2::ParticleSystem::running + + If running is set to false, the particle system will stop the simulation. All particles + will be destroyed when the system is set to running again. + + It can also be controlled with the start() and stop() methods. +*/ + + +/*! + \qmlproperty bool QtQuick.Particles2::ParticleSystem::paused + + If paused is set to true, the particle system will not advance the simulation. When + paused is set to false again, the simulation will resume from the same point it was + paused. + + The simulation will automatically pause if it detects that there are no live particles + left, and unpause when new live particles are added. + + It can also be controlled with the pause() and resume() methods. +*/ + +/*! + \qmlproperty bool QtQuick.Particles2::ParticleSystem::empty + + empty is set to true when there are no live particles left in the system. + + You can use this to pause the system, keeping it from spending any time updating, + but you will need to resume it in order for additional particles to be generated + by the system. + + To kill all the particles in the system, use a Kill affector. +*/ + +/*! + \qmlproperty list QtQuick.Particles2::ParticleSystem::particleStates + + You can define a sub-set of particle groups in this property in order to provide them + with stochastic state transitions. + + Each QtQuick2::Sprite in this list is interpreted as corresponding to the particle group + with ths same name. Any transitions defined in these sprites will take effect on the particle + groups as well. Additionally TrailEmitters, Affectors and ParticlePainters definined + inside one of these sprites are automatically associated with the corresponding particle group. +*/ + +/*! + \qmlmethod void QtQuick.Particles2::ParticleSystem::pause + + Pauses the simulation if it is running. + + \sa resume, paused +*/ + +/*! + \qmlmethod void QtQuick.Particles2::ParticleSystem::resume + + Resumes the simulation if it is paused. + + \sa pause, paused +*/ + +/*! + \qmlmethod void QtQuick.Particles2::ParticleSystem::start + + Starts the simulation if it has not already running. + + \sa stop, restart, running +*/ + +/*! + \qmlmethod void QtQuick.Particles2::ParticleSystem::stop + + Stops the simulation if it is running. + + \sa start, restart, running +*/ + +/*! + \qmlmethod void QtQuick.Particles2::ParticleSystem::restart + + Stops the simulation if it is running, and then starts it. + + \sa stop, restart, running +*/ +/*! + \qmlmethod void QtQuick.Particles2::ParticleSystem::reset + + Discards all currently existing particles. + +*/ +const qreal EPSILON = 0.001; +//Utility functions for when within 1ms is close enough +bool timeEqualOrGreater(qreal a, qreal b){ + return (a+EPSILON >= b); +} + +bool timeLess(qreal a, qreal b){ + return (a-EPSILON < b); +} + +bool timeEqual(qreal a, qreal b){ + return (a+EPSILON > b) && (a-EPSILON < b); +} + +int roundedTime(qreal a){// in ms + return (int)qRound(a*1000.0); +} + +QQuickParticleDataHeap::QQuickParticleDataHeap() + : m_data(0) +{ + m_data.reserve(1000); + clear(); +} + +void QQuickParticleDataHeap::grow() //###Consider automatic growth vs resize() calls from GroupData +{ + m_data.resize(1 << ++m_size); +} + +void QQuickParticleDataHeap::insert(QQuickParticleData* data) +{ + insertTimed(data, roundedTime(data->t + data->lifeSpan)); +} + +void QQuickParticleDataHeap::insertTimed(QQuickParticleData* data, int time){ + //TODO: Optimize 0 lifespan (or already dead) case + if (m_lookups.contains(time)){ + m_data[m_lookups[time]].data << data; + return; + } + if (m_end == (1 << m_size)) + grow(); + m_data[m_end].time = time; + m_data[m_end].data.clear(); + m_data[m_end].data.insert(data); + m_lookups.insert(time, m_end); + bubbleUp(m_end++); +} + +int QQuickParticleDataHeap::top() +{ + if (m_end == 0) + return 1 << 30; + return m_data[0].time; +} + +QSet QQuickParticleDataHeap::pop() +{ + if (!m_end) + return QSet (); + QSet ret = m_data[0].data; + m_lookups.remove(m_data[0].time); + if (m_end == 1){ + --m_end; + }else{ + m_data[0] = m_data[--m_end]; + bubbleDown(0); + } + return ret; +} + +void QQuickParticleDataHeap::clear() +{ + m_size = 0; + m_end = 0; + //m_size is in powers of two. So to start at 0 we have one allocated + m_data.resize(1); + m_lookups.clear(); +} + +bool QQuickParticleDataHeap::contains(QQuickParticleData* d) +{ + for (int i=0; i= m_end) + return; + int lesser = left; + int right = idx*2 + 2; + if (right < m_end){ + if (m_data[left].time > m_data[right].time) + lesser = right; + } + if (m_data[idx].time > m_data[lesser].time){ + swap(idx, lesser); + bubbleDown(lesser); + } +} + +QQuickParticleGroupData::QQuickParticleGroupData(int id, QQuickParticleSystem* sys):index(id),m_size(0),m_system(sys) +{ + initList(); +} + +QQuickParticleGroupData::~QQuickParticleGroupData() +{ + foreach (QQuickParticleData* d, data) + delete d; +} + +int QQuickParticleGroupData::size() +{ + return m_size; +} + +QString QQuickParticleGroupData::name()//### Worth caching as well? +{ + return m_system->groupIds.key(index); +} + +void QQuickParticleGroupData::setSize(int newSize){ + if (newSize == m_size) + return; + Q_ASSERT(newSize > m_size);//XXX allow shrinking + data.resize(newSize); + for (int i=m_size; igroup = index; + data[i]->index = i; + reusableIndexes << i; + } + int delta = newSize - m_size; + m_size = newSize; + foreach (QQuickParticlePainter* p, painters) + p->setCount(p->count() + delta); +} + +void QQuickParticleGroupData::initList() +{ + dataHeap.clear(); +} + +void QQuickParticleGroupData::kill(QQuickParticleData* d) +{ + Q_ASSERT(d->group == index); + d->lifeSpan = 0;//Kill off + foreach (QQuickParticlePainter* p, painters) + p->reload(d); + reusableIndexes << d->index; +} + +QQuickParticleData* QQuickParticleGroupData::newDatum(bool respectsLimits) +{ + //recycle();//Extra recycler round to be sure? + + while (!reusableIndexes.empty()){ + int idx = *(reusableIndexes.begin()); + reusableIndexes.remove(idx); + if (data[idx]->stillAlive()){// ### This means resurrection of 'dead' particles. Is that allowed? + prepareRecycler(data[idx]); + continue; + } + return data[idx]; + } + if (respectsLimits) + return 0; + + int oldSize = m_size; + setSize(oldSize + 10);//###+1,10%,+10? Choose something non-arbitrarily + reusableIndexes.remove(oldSize); + return data[oldSize]; +} + +bool QQuickParticleGroupData::recycle() +{ + while (dataHeap.top() <= m_system->timeInt){ + foreach (QQuickParticleData* datum, dataHeap.pop()){ + if (!datum->stillAlive()){ + reusableIndexes << datum->index; + }else{ + prepareRecycler(datum); //ttl has been altered mid-way, put it back + } + } + } + + //TODO: If the data is clear, gc (consider shrinking stack size)? + return reusableIndexes.count() == m_size; +} + +void QQuickParticleGroupData::prepareRecycler(QQuickParticleData* d){ + if (d->lifeSpan*1000 < m_system->maxLife){ + dataHeap.insert(d); + } else { + while ((roundedTime(d->t) + 2*m_system->maxLife/3) <= m_system->timeInt) + d->extendLife(m_system->maxLife/3000.0); + dataHeap.insertTimed(d, roundedTime(d->t) + 2*m_system->maxLife/3); + } +} + +QQuickParticleData::QQuickParticleData(QQuickParticleSystem* sys) + : group(0) + , e(0) + , system(sys) + , index(0) + , systemIndex(-1) + , colorOwner(0) + , rotationOwner(0) + , deformationOwner(0) + , animationOwner(0) + , v8Datum(0) +{ + x = 0; + y = 0; + t = -1; + lifeSpan = 0; + size = 0; + endSize = 0; + vx = 0; + vy = 0; + ax = 0; + ay = 0; + xx = 1; + xy = 0; + yx = 0; + yy = 1; + rotation = 0; + rotationSpeed = 0; + autoRotate = 0; + animIdx = 0; + frameDuration = 1; + frameCount = 1; + animT = -1; + animX = 0; + animY = 0; + animWidth = 1; + animHeight = 1; + color.r = 255; + color.g = 255; + color.b = 255; + color.a = 255; + r = 0; + delegate = 0; + modelIndex = -1; +} + +void QQuickParticleData::clone(const QQuickParticleData& other) +{ + x = other.x; + y = other.y; + t = other.t; + lifeSpan = other.lifeSpan; + size = other.size; + endSize = other.endSize; + vx = other.vx; + vy = other.vy; + ax = other.ax; + ay = other.ay; + xx = other.xx; + xy = other.xy; + yx = other.yx; + yy = other.yy; + rotation = other.rotation; + rotationSpeed = other.rotationSpeed; + autoRotate = other.autoRotate; + animIdx = other.animIdx; + frameDuration = other.frameDuration; + frameCount = other.frameCount; + animT = other.animT; + animX = other.animX; + animY = other.animY; + animWidth = other.animWidth; + animHeight = other.animHeight; + color.r = other.color.r; + color.g = other.color.g; + color.b = other.color.b; + color.a = other.color.a; + r = other.r; + delegate = other.delegate; + modelIndex = other.modelIndex; + + colorOwner = other.colorOwner; + rotationOwner = other.rotationOwner; + deformationOwner = other.deformationOwner; + animationOwner = other.animationOwner; +} + +QDeclarativeV8Handle QQuickParticleData::v8Value() +{ + if (!v8Datum) + v8Datum = new QQuickV8ParticleData(QDeclarativeEnginePrivate::getV8Engine(qmlEngine(system)), this); + return v8Datum->v8Value(); +} +//sets the x accleration without affecting the instantaneous x velocity or position +void QQuickParticleData::setInstantaneousAX(qreal ax) +{ + qreal t = (system->timeInt / 1000.0) - this->t; + qreal vx = (this->vx + t*this->ax) - t*ax; + qreal ex = this->x + this->vx * t + 0.5 * this->ax * t * t; + qreal x = ex - t*vx - 0.5 * t*t*ax; + + this->ax = ax; + this->vx = vx; + this->x = x; +} + +//sets the x velocity without affecting the instantaneous x postion +void QQuickParticleData::setInstantaneousVX(qreal vx) +{ + qreal t = (system->timeInt / 1000.0) - this->t; + qreal evx = vx - t*this->ax; + qreal ex = this->x + this->vx * t + 0.5 * this->ax * t * t; + qreal x = ex - t*evx - 0.5 * t*t*this->ax; + + this->vx = evx; + this->x = x; +} + +//sets the instantaneous x postion +void QQuickParticleData::setInstantaneousX(qreal x) +{ + qreal t = (system->timeInt / 1000.0) - this->t; + this->x = x - t*this->vx - 0.5 * t*t*this->ax; +} + +//sets the y accleration without affecting the instantaneous y velocity or position +void QQuickParticleData::setInstantaneousAY(qreal ay) +{ + qreal t = (system->timeInt / 1000.0) - this->t; + qreal vy = (this->vy + t*this->ay) - t*ay; + qreal ey = this->y + this->vy * t + 0.5 * this->ay * t * t; + qreal y = ey - t*vy - 0.5 * t*t*ay; + + this->ay = ay; + this->vy = vy; + this->y = y; +} + +//sets the y velocity without affecting the instantaneous y position +void QQuickParticleData::setInstantaneousVY(qreal vy) +{ + qreal t = (system->timeInt / 1000.0) - this->t; + qreal evy = vy - t*this->ay; + qreal ey = this->y + this->vy * t + 0.5 * this->ay * t * t; + qreal y = ey - t*evy - 0.5 * t*t*this->ay; + + this->vy = evy; + this->y = y; +} + +//sets the instantaneous Y position +void QQuickParticleData::setInstantaneousY(qreal y) +{ + qreal t = (system->timeInt / 1000.0) - this->t; + this->y = y - t*this->vy - 0.5 * t*t*this->ay; +} + +qreal QQuickParticleData::curX() const +{ + qreal t = (system->timeInt / 1000.0) - this->t; + return this->x + this->vx * t + 0.5 * this->ax * t * t; +} + +qreal QQuickParticleData::curVX() const +{ + qreal t = (system->timeInt / 1000.0) - this->t; + return this->vx + t*this->ax; +} + +qreal QQuickParticleData::curY() const +{ + qreal t = (system->timeInt / 1000.0) - this->t; + return y + vy * t + 0.5 * ay * t * t; +} + +qreal QQuickParticleData::curVY() const +{ + qreal t = (system->timeInt / 1000.0) - this->t; + return vy + t*ay; +} + +void QQuickParticleData::debugDump() +{ + qDebug() << "Particle" << systemIndex << group << "/" << index << stillAlive() + << "Pos: " << x << "," << y + << "Vel: " << vx << "," << vy + << "Acc: " << ax << "," << ay + << "Size: " << size << "," << endSize + << "Time: " << t << "," <timeInt / 1000.0) ; +} + +bool QQuickParticleData::stillAlive() +{ + if (!system) + return false; + return (t + lifeSpan - EPSILON) > ((qreal)system->timeInt/1000.0); +} + +float QQuickParticleData::curSize() +{ + if (!system || !lifeSpan) + return 0.0f; + return size + (endSize - size) * (1 - (lifeLeft() / lifeSpan)); +} + +float QQuickParticleData::lifeLeft() +{ + if (!system) + return 0.0f; + return (t + lifeSpan) - (system->timeInt/1000.0); +} + +void QQuickParticleData::extendLife(float time) +{ + qreal newX = curX(); + qreal newY = curY(); + qreal newVX = curVX(); + qreal newVY = curVY(); + + t += time; + animT += time; + + qreal elapsed = (system->timeInt / 1000.0) - t; + qreal evy = newVY - elapsed*ay; + qreal ey = newY - elapsed*evy - 0.5 * elapsed*elapsed*ay; + qreal evx = newVX - elapsed*ax; + qreal ex = newX - elapsed*evx - 0.5 * elapsed*elapsed*ax; + + x = ex; + vx = evx; + y = ey; + vy = evy; +} + +QQuickParticleSystem::QQuickParticleSystem(QQuickItem *parent) : + QQuickItem(parent), + stateEngine(0), + m_running(true), + particleCount(0), + m_nextIndex(0), + m_componentComplete(false), + m_paused(false) +{ + connect(&m_painterMapper, SIGNAL(mapped(QObject*)), + this, SLOT(loadPainter(QObject*))); + + m_debugMode = qmlParticlesDebug(); +} + +QQuickParticleSystem::~QQuickParticleSystem() +{ + foreach (QQuickParticleGroupData* gd, groupData) + delete gd; +} + +void QQuickParticleSystem::initGroups() +{ + m_reusableIndexes.clear(); + m_nextIndex = 0; + + qDeleteAll(groupData); + groupData.clear(); + groupIds.clear(); + + QQuickParticleGroupData* gd = new QQuickParticleGroupData(0, this);//Default group + groupData.insert(0,gd); + groupIds.insert(QString(), 0); + m_nextGroupId = 1; +} + +void QQuickParticleSystem::registerParticlePainter(QQuickParticlePainter* p) +{ + //TODO: a way to Unregister emitters, painters and affectors + m_painters << QPointer(p);//###Set or uniqueness checking? + connect(p, SIGNAL(groupsChanged(QStringList)), + &m_painterMapper, SLOT(map())); + loadPainter(p); +} + +void QQuickParticleSystem::registerParticleEmitter(QQuickParticleEmitter* e) +{ + m_emitters << QPointer(e);//###How to get them out? + connect(e, SIGNAL(particleCountChanged()), + this, SLOT(emittersChanged())); + connect(e, SIGNAL(groupChanged(QString)), + this, SLOT(emittersChanged())); + emittersChanged(); + e->reset();//Start, so that starttime factors appropriately +} + +void QQuickParticleSystem::registerParticleAffector(QQuickParticleAffector* a) +{ + m_affectors << QPointer(a); +} + +void QQuickParticleSystem::registerParticleGroup(QQuickParticleGroup* g) +{ + m_groups << QPointer(g); + createEngine(); +} + +void QQuickParticleSystem::setRunning(bool arg) +{ + if (m_running != arg) { + m_running = arg; + emit runningChanged(arg); + setPaused(false); + if (m_animation)//Not created until componentCompleted + m_running ? m_animation->start() : m_animation->stop(); + reset(); + } +} + +void QQuickParticleSystem::setPaused(bool arg){ + if (m_paused != arg) { + m_paused = arg; + if (m_animation && m_animation->state() != QAbstractAnimation::Stopped) + m_paused ? m_animation->pause() : m_animation->resume(); + if (!m_paused){ + foreach (QQuickParticlePainter *p, m_painters) + p->update(); + } + emit pausedChanged(arg); + } +} + +void QQuickParticleSystem::statePropertyRedirect(QDeclarativeListProperty *prop, QObject *value) +{ + //Hooks up automatic state-associated stuff + QQuickParticleSystem* sys = qobject_cast(prop->object->parent()); + QQuickParticleGroup* group = qobject_cast(prop->object); + if (!group || !sys || !value) + return; + stateRedirect(group, sys, value); +} + +void QQuickParticleSystem::stateRedirect(QQuickParticleGroup* group, QQuickParticleSystem* sys, QObject *value) +{ + QStringList list; + list << group->name(); + QQuickParticleAffector* a = qobject_cast(value); + if (a){ + a->setParentItem(sys); + a->setGroups(list); + a->setSystem(sys); + return; + } + QQuickTrailEmitter* fe = qobject_cast(value); + if (fe){ + fe->setParentItem(sys); + fe->setFollow(group->name()); + fe->setSystem(sys); + return; + } + QQuickParticleEmitter* e = qobject_cast(value); + if (e){ + e->setParentItem(sys); + e->setGroup(group->name()); + e->setSystem(sys); + return; + } + QQuickParticlePainter* p = qobject_cast(value); + if (p){ + p->setParentItem(sys); + p->setGroups(list); + p->setSystem(sys); + return; + } + qWarning() << value << " was placed inside a particle system state but cannot be taken into the particle system. It will be lost."; +} + +void QQuickParticleSystem::componentComplete() + +{ + QQuickItem::componentComplete(); + m_componentComplete = true; + m_animation = new QQuickParticleSystemAnimation(this); + reset();//restarts animation as well +} + +void QQuickParticleSystem::reset() +{ + if (!m_componentComplete) + return; + + timeInt = 0; + //Clear guarded pointers which have been deleted + int cleared = 0; + cleared += m_emitters.removeAll(0); + cleared += m_painters.removeAll(0); + cleared += m_affectors.removeAll(0); + + bySysIdx.resize(0); + initGroups();//Also clears all logical particles + + if (!m_running) + return; + + foreach (QQuickParticleEmitter* e, m_emitters) + e->reset(); + + emittersChanged(); + + foreach (QQuickParticlePainter *p, m_painters){ + loadPainter(p); + p->reset(); + } + + //### Do affectors need reset too? + if (m_animation) {//Animation is explicitly disabled in benchmarks + //reset restarts animation (if running) + if ((m_animation->state() == QAbstractAnimation::Running)) + m_animation->stop(); + m_animation->start(); + if (m_paused) + m_animation->pause(); + } + + initialized = true; +} + + +void QQuickParticleSystem::loadPainter(QObject *p) +{ + if (!m_componentComplete) + return; + + QQuickParticlePainter* painter = qobject_cast(p); + Q_ASSERT(painter);//XXX + foreach (QQuickParticleGroupData* sg, groupData) + sg->painters.remove(painter); + int particleCount = 0; + if (painter->groups().isEmpty()){//Uses default particle + QStringList def; + def << QString(); + painter->setGroups(def); + particleCount += groupData[0]->size(); + groupData[0]->painters << painter; + }else{ + foreach (const QString &group, painter->groups()){ + if (group != QLatin1String("") && !groupIds[group]){//new group + int id = m_nextGroupId++; + QQuickParticleGroupData* gd = new QQuickParticleGroupData(id, this); + groupIds.insert(group, id); + groupData.insert(id, gd); + } + particleCount += groupData[groupIds[group]]->size(); + groupData[groupIds[group]]->painters << painter; + } + } + painter->setCount(particleCount); + painter->update();//Initial update here + return; +} + +void QQuickParticleSystem::emittersChanged() +{ + if (!m_componentComplete) + return; + + m_emitters.removeAll(0); + + + QList previousSizes; + QList newSizes; + for (int i=0; isize(); + newSizes << 0; + } + + foreach (QQuickParticleEmitter* e, m_emitters){//Populate groups and set sizes. + if (!groupIds.contains(e->group()) + || (!e->group().isEmpty() && !groupIds[e->group()])){//or it was accidentally inserted by a failed lookup earlier + int id = m_nextGroupId++; + QQuickParticleGroupData* gd = new QQuickParticleGroupData(id, this); + groupIds.insert(e->group(), id); + groupData.insert(id, gd); + previousSizes << 0; + newSizes << 0; + } + newSizes[groupIds[e->group()]] += e->particleCount(); + //###: Cull emptied groups? + } + + //TODO: Garbage collection? + particleCount = 0; + for (int i=0; isetSize(qMax(newSizes[i], previousSizes[i])); + particleCount += groupData[i]->size(); + } + + if (m_debugMode) + qDebug() << "Particle system emitters changed. New particle count: " << particleCount; + + if (particleCount > bySysIdx.size())//New datum requests haven't updated it + bySysIdx.resize(particleCount); + + foreach (QQuickParticlePainter *p, m_painters) + loadPainter(p); + + if (!m_groups.isEmpty()) + createEngine(); + +} + +void QQuickParticleSystem::createEngine() +{ + if (!m_componentComplete) + return; + if (stateEngine && m_debugMode) + qDebug() << "Resetting Existing Sprite Engine..."; + //### Solve the losses if size/states go down + foreach (QQuickParticleGroup* group, m_groups){ + bool exists = false; + foreach (const QString &name, groupIds.keys()) + if (group->name() == name) + exists = true; + if (!exists){ + int id = m_nextGroupId++; + QQuickParticleGroupData* gd = new QQuickParticleGroupData(id, this); + groupIds.insert(group->name(), id); + groupData.insert(id, gd); + } + } + + if (m_groups.count()){ + //Reorder groups List so as to have the same order as groupData + QList newList; + for (int i=0; iname(); + foreach (QQuickParticleGroup* existing, m_groups){ + if (existing->name() == name){ + newList << existing; + exists = true; + } + } + if (!exists){ + newList << new QQuickParticleGroup(this); + newList.back()->setName(name); + } + } + m_groups = newList; + QList states; + foreach (QQuickParticleGroup* g, m_groups) + states << (QQuickStochasticState*)g; + + if (!stateEngine) + stateEngine = new QQuickStochasticEngine(this); + stateEngine->setCount(particleCount); + stateEngine->m_states = states; + + connect(stateEngine, SIGNAL(stateChanged(int)), + this, SLOT(particleStateChange(int))); + + }else{ + if (stateEngine) + delete stateEngine; + stateEngine = 0; + } + +} + +void QQuickParticleSystem::particleStateChange(int idx) +{ + moveGroups(bySysIdx[idx], stateEngine->curState(idx)); +} + +void QQuickParticleSystem::moveGroups(QQuickParticleData *d, int newGIdx) +{ + if (!d || newGIdx == d->group) + return; + + QQuickParticleData* pd = newDatum(newGIdx, false, d->systemIndex); + if (!pd) + return; + + pd->clone(*d); + finishNewDatum(pd); + + d->systemIndex = -1; + groupData[d->group]->kill(d); +} + +int QQuickParticleSystem::nextSystemIndex() +{ + if (!m_reusableIndexes.isEmpty()){ + int ret = *(m_reusableIndexes.begin()); + m_reusableIndexes.remove(ret); + return ret; + } + if (m_nextIndex >= bySysIdx.size()){ + bySysIdx.resize(bySysIdx.size() < 10 ? 10 : bySysIdx.size()*1.1);//###+1,10%,+10? Choose something non-arbitrarily + if (stateEngine) + stateEngine->setCount(bySysIdx.size()); + + } + return m_nextIndex++; +} + +QQuickParticleData* QQuickParticleSystem::newDatum(int groupId, bool respectLimits, int sysIndex) +{ + Q_ASSERT(groupId < groupData.count());//XXX shouldn't really be an assert + + QQuickParticleData* ret = groupData[groupId]->newDatum(respectLimits); + if (!ret){ + return 0; + } + if (sysIndex == -1){ + if (ret->systemIndex == -1) + ret->systemIndex = nextSystemIndex(); + }else{ + if (ret->systemIndex != -1){ + if (stateEngine) + stateEngine->stop(ret->systemIndex); + m_reusableIndexes << ret->systemIndex; + bySysIdx[ret->systemIndex] = 0; + } + ret->systemIndex = sysIndex; + } + bySysIdx[ret->systemIndex] = ret; + + if (stateEngine) + stateEngine->start(ret->systemIndex, ret->group); + + m_empty = false; + return ret; +} + +void QQuickParticleSystem::emitParticle(QQuickParticleData* pd) +{// called from prepareNextFrame()->emitWindow - enforce? + //Account for relative emitter position + QPointF offset = this->mapFromItem(pd->e, QPointF(0, 0)); + if (!offset.isNull()){ + pd->x += offset.x(); + pd->y += offset.y(); + } + + finishNewDatum(pd); +} + +void QQuickParticleSystem::finishNewDatum(QQuickParticleData *pd){ + Q_ASSERT(pd); + groupData[pd->group]->prepareRecycler(pd); + + foreach (QQuickParticleAffector *a, m_affectors) + if (a && a->m_needsReset) + a->reset(pd); + foreach (QQuickParticlePainter* p, groupData[pd->group]->painters) + if (p) + p->load(pd); +} + +void QQuickParticleSystem::updateCurrentTime( int currentTime ) +{ + if (!initialized) + return;//error in initialization + + //### Elapsed time never shrinks - may cause problems if left emitting for weeks at a time. + qreal dt = timeInt / 1000.; + timeInt = currentTime; + qreal time = timeInt / 1000.; + dt = time - dt; + needsReset.clear(); + + bool oldClear = m_empty; + m_empty = true; + foreach (QQuickParticleGroupData* gd, groupData)//Recycle all groups and see if they're out of live particles + m_empty = gd->recycle() && m_empty; + + if (stateEngine) + stateEngine->updateSprites(timeInt); + + foreach (QQuickParticleEmitter* emitter, m_emitters) + if (emitter) + emitter->emitWindow(timeInt); + foreach (QQuickParticleAffector* a, m_affectors) + if (a) + a->affectSystem(dt); + foreach (QQuickParticleData* d, needsReset) + foreach (QQuickParticlePainter* p, groupData[d->group]->painters) + if (p && d) + p->reload(d); + + if (oldClear != m_empty) + emptyChanged(m_empty); +} + +int QQuickParticleSystem::systemSync(QQuickParticlePainter* p) +{ + if (!m_running) + return 0; + if (!initialized) + return 0;//error in initialization + p->performPendingCommits(); + return timeInt; +} + + +QT_END_NAMESPACE diff --git a/src/declarative/particles/qquickparticlesystem_p.h b/src/declarative/particles/qquickparticlesystem_p.h new file mode 100644 index 0000000000..394546ccc4 --- /dev/null +++ b/src/declarative/particles/qquickparticlesystem_p.h @@ -0,0 +1,378 @@ +/**************************************************************************** +** +** 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 PARTICLESYSTEM_H +#define PARTICLESYSTEM_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include //For QDeclarativeV8Handle + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QQuickParticleSystem; +class QQuickParticleAffector; +class QQuickParticleEmitter; +class QQuickParticlePainter; +class QQuickParticleData; +class QQuickParticleSystemAnimation; +class QQuickStochasticEngine; +class QQuickSprite; +class QQuickV8ParticleData; +class QQuickParticleGroup; +class QQuickImageParticle; + +struct QQuickParticleDataHeapNode{ + int time;//in ms + QSet data;//Set ptrs instead? +}; + +class QQuickParticleDataHeap { + //Idea is to do a binary heap, but which also stores a set of int,Node* so that if the int already exists, you can + //add it to the data* list. Pops return the whole list at once. +public: + QQuickParticleDataHeap(); + void insert(QQuickParticleData* data); + void insertTimed(QQuickParticleData* data, int time); + + int top(); + + QSet pop(); + + void clear(); + + bool contains(QQuickParticleData*);//O(n), for debugging purposes only +private: + void grow(); + void swap(int, int); + void bubbleUp(int); + void bubbleDown(int); + int m_size; + int m_end; + QQuickParticleDataHeapNode m_tmp; + QVector m_data; + QHash m_lookups; +}; + +class Q_AUTOTEST_EXPORT QQuickParticleGroupData { +public: + QQuickParticleGroupData(int id, QQuickParticleSystem* sys); + ~QQuickParticleGroupData(); + + int size(); + QString name(); + + void setSize(int newSize); + + int index; + QSet painters; + + //TODO: Refactor particle data list out into a separate class + QVector data; + QQuickParticleDataHeap dataHeap; + QSet reusableIndexes; + bool recycle(); //Force recycling round, reutrns true if all indexes are now reusable + + void initList(); + void kill(QQuickParticleData* d); + + //After calling this, initialize, then call prepareRecycler(d) + QQuickParticleData* newDatum(bool respectsLimits); + + //TODO: Find and clean up those that don't get added to the recycler (currently they get lost) + void prepareRecycler(QQuickParticleData* d); + +private: + int m_size; + QQuickParticleSystem* m_system; +}; + +struct Color4ub { + uchar r; + uchar g; + uchar b; + uchar a; +}; + +class Q_AUTOTEST_EXPORT QQuickParticleData { +public: + //TODO: QObject like memory management (without the cost, just attached to system) + QQuickParticleData(QQuickParticleSystem* sys); + + //Convenience functions for working backwards, because parameters are from the start of particle life + //If setting multiple parameters at once, doing the conversion yourself will be faster. + + //sets the x accleration without affecting the instantaneous x velocity or position + void setInstantaneousAX(qreal ax); + //sets the x velocity without affecting the instantaneous x postion + void setInstantaneousVX(qreal vx); + //sets the instantaneous x postion + void setInstantaneousX(qreal x); + //sets the y accleration without affecting the instantaneous y velocity or position + void setInstantaneousAY(qreal ay); + //sets the y velocity without affecting the instantaneous y postion + void setInstantaneousVY(qreal vy); + //sets the instantaneous Y postion + void setInstantaneousY(qreal y); + + //TODO: Slight caching? + qreal curX() const; + qreal curVX() const; + qreal curAX() const { return ax; } + qreal curY() const; + qreal curVY() const; + qreal curAY() const { return ay; } + + int group; + QQuickParticleEmitter* e;//### Needed? + QQuickParticleSystem* system; + int index; + int systemIndex; + + //General Position Stuff + float x; + float y; + float t; + float lifeSpan; + float size; + float endSize; + float vx; + float vy; + float ax; + float ay; + + //Other stuff, now universally shared + Color4ub color; + float xx; + float xy; + float yx; + float yy; + float rotation; + float rotationSpeed; + float autoRotate;//Assume that GPUs prefer floats to bools + float animIdx; + float frameDuration; + float frameCount; + float animT; + float animX; + float animY; + float animWidth; + float animHeight; + float r; + QQuickItem* delegate; + int modelIndex; + float update;//Used by custom affectors + + //Used by image particle + QQuickImageParticle* colorOwner; + QQuickImageParticle* rotationOwner; + QQuickImageParticle* deformationOwner; + QQuickImageParticle* animationOwner; + + void debugDump(); + bool stillAlive(); + float lifeLeft(); + float curSize(); + void clone(const QQuickParticleData& other);//Not =, leaves meta-data like index + QDeclarativeV8Handle v8Value(); + void extendLife(float time); +private: + QQuickV8ParticleData* v8Datum; +}; + +class Q_AUTOTEST_EXPORT QQuickParticleSystem : public QQuickItem +{ + Q_OBJECT + Q_PROPERTY(bool running READ isRunning WRITE setRunning NOTIFY runningChanged) + Q_PROPERTY(bool paused READ isPaused WRITE setPaused NOTIFY pausedChanged) + Q_PROPERTY(bool empty READ isEmpty NOTIFY emptyChanged) + +public: + explicit QQuickParticleSystem(QQuickItem *parent = 0); + ~QQuickParticleSystem(); + + bool isRunning() const + { + return m_running; + } + + int count(){ return particleCount; } + + static const int maxLife = 600000; + +signals: + + void systemInitialized(); + void runningChanged(bool arg); + void pausedChanged(bool arg); + void emptyChanged(bool arg); + +public slots: + void start(){setRunning(true);} + void stop(){setRunning(false);} + void restart(){setRunning(false);setRunning(true);} + void pause(){setPaused(true);} + void resume(){setPaused(false);} + + void reset(); + void setRunning(bool arg); + void setPaused(bool arg); + + virtual int duration() const { return -1; } + + +protected: + //This one only once per frame (effectively) + void componentComplete(); + +private slots: + void emittersChanged(); + void loadPainter(QObject* p); + void createEngine(); //Not invoked by sprite engine, unlike Sprite uses + void particleStateChange(int idx); + +public: + //These can be called multiple times per frame, performance critical + void emitParticle(QQuickParticleData* p); + QQuickParticleData* newDatum(int groupId, bool respectLimits = true, int sysIdx = -1); + void finishNewDatum(QQuickParticleData*); + void moveGroups(QQuickParticleData *d, int newGIdx); + int nextSystemIndex(); + + //This one only once per painter per frame + int systemSync(QQuickParticlePainter* p); + + //Data members here for ease of related class and auto-test usage. Not "public" API. TODO: d_ptrize + QSet needsReset; + QVector bySysIdx; //Another reference to the data (data owned by group), but by sysIdx + QHash groupIds; + QHash groupData; + QQuickStochasticEngine* stateEngine; + + //Also only here for auto-test usage + void updateCurrentTime( int currentTime ); + QQuickParticleSystemAnimation* m_animation; + bool m_running; + + int timeInt; + bool initialized; + int particleCount; + + void registerParticlePainter(QQuickParticlePainter* p); + void registerParticleEmitter(QQuickParticleEmitter* e); + void registerParticleAffector(QQuickParticleAffector* a); + void registerParticleGroup(QQuickParticleGroup* g); + + static void statePropertyRedirect(QDeclarativeListProperty *prop, QObject *value); + static void stateRedirect(QQuickParticleGroup* group, QQuickParticleSystem* sys, QObject *value); + bool isPaused() const + { + return m_paused; + } + + bool isEmpty() const + { + return m_empty; + } + +private: + void initializeSystem(); + void initGroups(); + QList > m_emitters; + QList > m_affectors; + QList > m_painters; + QList > m_syncList; + QList m_groups; + int m_nextGroupId; + int m_nextIndex; + QSet m_reusableIndexes; + bool m_componentComplete; + + QSignalMapper m_painterMapper; + QSignalMapper m_emitterMapper; + bool m_paused; + bool m_debugMode; + bool m_allDead; + bool m_empty; +}; + +// Internally, this animation drives all the timing. Painters sync up in their updatePaintNode +class QQuickParticleSystemAnimation : public QAbstractAnimation +{ + Q_OBJECT +public: + QQuickParticleSystemAnimation(QQuickParticleSystem* system) + : QAbstractAnimation(static_cast(system)), m_system(system) + { } +protected: + virtual void updateCurrentTime( int t ) + { + m_system->updateCurrentTime(t); + } + + virtual int duration() const + { + return -1; + } + +private: + QQuickParticleSystem* m_system; +}; + + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // PARTICLESYSTEM_H + + diff --git a/src/declarative/particles/qquickpointattractor.cpp b/src/declarative/particles/qquickpointattractor.cpp new file mode 100644 index 0000000000..d96458c8bb --- /dev/null +++ b/src/declarative/particles/qquickpointattractor.cpp @@ -0,0 +1,162 @@ +/**************************************************************************** +** +** 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 "qquickpointattractor_p.h" +#include +#include +QT_BEGIN_NAMESPACE +/*! + \qmlclass Attractor QQuickAttractorAffector + \inqmlmodule QtQuick.Particles 2 + \inherits Affector + \brief The Attractor allows you to attract particles towards a specific point. + + Note that the size and position of this element affects which particles it affects. + The size of the point attracted to is always 0x0, and the location of that point + is specified by the pointX and pointY properties. + + Note that Attractor has the standard Item x,y,width and height properties. + Like other affectors, these represent the affected area. They + do not represent the 0x0 point which is the target of the attraction. +*/ + + +/*! + \qmlproperty real QtQuick.Particles2::PointAttractor::pointX + + The x coordinate of the attracting point. This is relative + to the x coordinate of the Attractor. +*/ +/*! + \qmlproperty real QtQuick.Particles2::PointAttractor::pointY + + The y coordinate of the attracting point. This is relative + to the y coordinate of the Attractor. +*/ +/*! + \qmlproperty real QtQuick.Particles2::PointAttractor::strength + + The pull, in units per second, to be exerted on an item one pixel away. + + Depending on how the attraction is proportionalToDistance this may have to + be very high or very low to have a reasonable effect on particles at a + distance. +*/ +/*! + \qmlproperty AffectableParameter QtQuick.Particles2::Attractor::affectedParameter + + What attribute of particles is directly affected. + \list + \o Attractor.Position + \o Attractor.Velocity + \o Attractor.Acceleration + \endlist +*/ +/*! + \qmlproperty Proportion QtQuick.Particles2::Attractor::proportionalToDistance + + How the distance from the particle to the point affects the strength of the attraction. + + \list + \o Attractor.Constant + \o Attractor.Linear + \o Attractor.InverseLinear + \o Attractor.Quadratic + \o Attractor.InverseQuadratic + \endlist +*/ + + +QQuickAttractorAffector::QQuickAttractorAffector(QQuickItem *parent) : + QQuickParticleAffector(parent), m_strength(0.0), m_x(0), m_y(0) + , m_physics(Velocity), m_proportionalToDistance(Linear) +{ +} + +bool QQuickAttractorAffector::affectParticle(QQuickParticleData *d, qreal dt) +{ + if (m_strength == 0.0) + return false; + qreal dx = m_x+m_offset.x() - d->curX(); + qreal dy = m_y+m_offset.y() - d->curY(); + qreal r = sqrt((dx*dx) + (dy*dy)); + qreal theta = atan2(dy,dx); + qreal ds = 0; + switch (m_proportionalToDistance){ + case InverseQuadratic: + ds = (m_strength / qMax(1.,r*r)); + break; + case InverseLinear: + ds = (m_strength / qMax(1.,r)); + break; + case Quadratic: + ds = (m_strength * qMax(1.,r*r)); + break; + case Linear: + ds = (m_strength * qMax(1.,r)); + break; + default: //also Constant + ds = m_strength; + } + ds *= dt; + dx = ds * cos(theta); + dy = ds * sin(theta); + qreal vx,vy; + switch (m_physics){ + case Position: + d->x = (d->x + dx); + d->y = (d->y + dy); + break; + case Acceleration: + d->setInstantaneousAX(d->ax + dx); + d->setInstantaneousAY(d->ay + dy); + break; + case Velocity: //also default + default: + vx = d->curVX(); + vy = d->curVY(); + d->setInstantaneousVX(vx + dx); + d->setInstantaneousVY(vy + dy); + } + + return true; +} +QT_END_NAMESPACE diff --git a/src/declarative/particles/qquickpointattractor_p.h b/src/declarative/particles/qquickpointattractor_p.h new file mode 100644 index 0000000000..b488e132e3 --- /dev/null +++ b/src/declarative/particles/qquickpointattractor_p.h @@ -0,0 +1,169 @@ +/**************************************************************************** +** +** 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 ATTRACTORAFFECTOR_H +#define ATTRACTORAFFECTOR_H +#include "qquickparticleaffector_p.h" + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QQuickAttractorAffector : public QQuickParticleAffector +{ + Q_OBJECT + Q_PROPERTY(qreal strength READ strength WRITE setStrength NOTIFY strengthChanged) + Q_PROPERTY(qreal pointX READ pointX WRITE setPointX NOTIFY pointXChanged) + Q_PROPERTY(qreal pointY READ pointY WRITE setPointY NOTIFY pointYChanged) + Q_PROPERTY(AffectableParameters affectedParameter READ affectedParameter WRITE setAffectedParameter NOTIFY affectedParameterChanged) + Q_PROPERTY(Proportion proportionalToDistance READ proportionalToDistance WRITE setProportionalToDistance NOTIFY proportionalToDistanceChanged) + Q_ENUMS(AffectableParameters) + Q_ENUMS(Proportion) + +public: + enum Proportion{ + Constant, + Linear, + Quadratic, + InverseLinear, + InverseQuadratic + }; + + enum AffectableParameters { + Position, + Velocity, + Acceleration + }; + + explicit QQuickAttractorAffector(QQuickItem *parent = 0); + + qreal strength() const + { + return m_strength; + } + + qreal pointX() const + { + return m_x; + } + + qreal pointY() const + { + return m_y; + } + + AffectableParameters affectedParameter() const + { + return m_physics; + } + + Proportion proportionalToDistance() const + { + return m_proportionalToDistance; + } + +signals: + + void strengthChanged(qreal arg); + + void pointXChanged(qreal arg); + + void pointYChanged(qreal arg); + + void affectedParameterChanged(AffectableParameters arg); + + void proportionalToDistanceChanged(Proportion arg); + +public slots: +void setStrength(qreal arg) +{ + if (m_strength != arg) { + m_strength = arg; + emit strengthChanged(arg); + } +} + +void setPointX(qreal arg) +{ + if (m_x != arg) { + m_x = arg; + emit pointXChanged(arg); + } +} + +void setPointY(qreal arg) +{ + if (m_y != arg) { + m_y = arg; + emit pointYChanged(arg); + } +} +void setAffectedParameter(AffectableParameters arg) +{ + if (m_physics != arg) { + m_physics = arg; + emit affectedParameterChanged(arg); + } +} + +void setProportionalToDistance(Proportion arg) +{ + if (m_proportionalToDistance != arg) { + m_proportionalToDistance = arg; + emit proportionalToDistanceChanged(arg); + } +} + +protected: + virtual bool affectParticle(QQuickParticleData *d, qreal dt); +private: +qreal m_strength; +qreal m_x; +qreal m_y; +AffectableParameters m_physics; +Proportion m_proportionalToDistance; +}; + +QT_END_NAMESPACE +QT_END_HEADER +#endif // ATTRACTORAFFECTOR_H diff --git a/src/declarative/particles/qquickpointdirection.cpp b/src/declarative/particles/qquickpointdirection.cpp new file mode 100644 index 0000000000..22c33d9f15 --- /dev/null +++ b/src/declarative/particles/qquickpointdirection.cpp @@ -0,0 +1,85 @@ +/**************************************************************************** +** +** 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 "qquickpointdirection_p.h" + +QT_BEGIN_NAMESPACE + +/*! + \qmlclass PointDirection QQuickPointDirection + \inqmlmodule QtQuick.Particles 2 + \inherits Direction + \brief The PointDirection element allows you to specify a direction that varies in x and y components + + The PointDirection element allows both the specification of a direction by x and y components, + as well as varying the parameters by x or y component. +*/ +/*! + \qmlproperty real QtQuick.Particles2::PointDirection::x +*/ +/*! + \qmlproperty real QtQuick.Particles2::PointDirection::y +*/ +/*! + \qmlproperty real QtQuick.Particles2::PointDirection::xVariation +*/ +/*! + \qmlproperty real QtQuick.Particles2::PointDirection::yVariation +*/ + +QQuickPointDirection::QQuickPointDirection(QObject *parent) : + QQuickDirection(parent) + , m_x(0) + , m_y(0) + , m_xVariation(0) + , m_yVariation(0) +{ +} + +const QPointF QQuickPointDirection::sample(const QPointF &) +{ + QPointF ret; + ret.setX(m_x - m_xVariation + rand() / float(RAND_MAX) * m_xVariation * 2); + ret.setY(m_y - m_yVariation + rand() / float(RAND_MAX) * m_yVariation * 2); + return ret; +} + +QT_END_NAMESPACE diff --git a/src/declarative/particles/qquickpointdirection_p.h b/src/declarative/particles/qquickpointdirection_p.h new file mode 100644 index 0000000000..29ee7cb613 --- /dev/null +++ b/src/declarative/particles/qquickpointdirection_p.h @@ -0,0 +1,135 @@ +/**************************************************************************** +** +** 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 POINTVECTOR_H +#define POINTVECTOR_H +#include "qquickdirection_p.h" + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QQuickPointDirection : public QQuickDirection +{ + Q_OBJECT + Q_PROPERTY(qreal x READ x WRITE setX NOTIFY xChanged) + Q_PROPERTY(qreal y READ y WRITE setY NOTIFY yChanged) + Q_PROPERTY(qreal xVariation READ xVariation WRITE setXVariation NOTIFY xVariationChanged) + Q_PROPERTY(qreal yVariation READ yVariation WRITE setYVariation NOTIFY yVariationChanged) +public: + explicit QQuickPointDirection(QObject *parent = 0); + virtual const QPointF sample(const QPointF &from); + qreal x() const + { + return m_x; + } + + qreal y() const + { + return m_y; + } + + qreal xVariation() const + { + return m_xVariation; + } + + qreal yVariation() const + { + return m_yVariation; + } + +signals: + + void xChanged(qreal arg); + + void yChanged(qreal arg); + + void xVariationChanged(qreal arg); + + void yVariationChanged(qreal arg); + +public slots: + void setX(qreal arg) + { + if (m_x != arg) { + m_x = arg; + emit xChanged(arg); + } + } + + void setY(qreal arg) + { + if (m_y != arg) { + m_y = arg; + emit yChanged(arg); + } + } + + void setXVariation(qreal arg) + { + if (m_xVariation != arg) { + m_xVariation = arg; + emit xVariationChanged(arg); + } + } + + void setYVariation(qreal arg) + { + if (m_yVariation != arg) { + m_yVariation = arg; + emit yVariationChanged(arg); + } + } + +private: + + qreal m_x; + qreal m_y; + qreal m_xVariation; + qreal m_yVariation; +}; + +QT_END_NAMESPACE +QT_END_HEADER +#endif // POINTVECTOR_H diff --git a/src/declarative/particles/qquickrectangleextruder.cpp b/src/declarative/particles/qquickrectangleextruder.cpp new file mode 100644 index 0000000000..d840a08d5b --- /dev/null +++ b/src/declarative/particles/qquickrectangleextruder.cpp @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** 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 "qquickrectangleextruder_p.h" + +QT_BEGIN_NAMESPACE + +/*! + \qmlclass RectangleShape QQuickRectangleExtruder + \inqmlmodule QtQuick.Particles 2 + \brief The RectangleShape element allows you to specify an area for affectors and emitter. + + Just a rectangle. +*/ + +QQuickRectangleExtruder::QQuickRectangleExtruder(QObject *parent) : + QQuickParticleExtruder(parent), m_fill(true) +{ +} + +QPointF QQuickRectangleExtruder::extrude(const QRectF &rect) +{ + if (m_fill) + return QPointF(((qreal)rand() / RAND_MAX) * rect.width() + rect.x(), + ((qreal)rand() / RAND_MAX) * rect.height() + rect.y()); + int side = rand() % 4; + switch (side){//TODO: Doesn't this overlap the corners? + case 0: + return QPointF(rect.x(), + ((qreal)rand() / RAND_MAX) * rect.height() + rect.y()); + case 1: + return QPointF(rect.width() + rect.x(), + ((qreal)rand() / RAND_MAX) * rect.height() + rect.y()); + case 2: + return QPointF(((qreal)rand() / RAND_MAX) * rect.width() + rect.x(), + rect.y()); + default: + return QPointF(((qreal)rand() / RAND_MAX) * rect.width() + rect.x(), + rect.height() + rect.y()); + } +} + +bool QQuickRectangleExtruder::contains(const QRectF &bounds, const QPointF &point) +{ + return bounds.contains(point); +} + +QT_END_NAMESPACE diff --git a/src/declarative/particles/qquickrectangleextruder_p.h b/src/declarative/particles/qquickrectangleextruder_p.h new file mode 100644 index 0000000000..ec8caaeec1 --- /dev/null +++ b/src/declarative/particles/qquickrectangleextruder_p.h @@ -0,0 +1,88 @@ +/**************************************************************************** +** +** 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 RECTANGLEEXTRUDER_H +#define RECTANGLEEXTRUDER_H + +#include "qquickparticleextruder_p.h" + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QQuickRectangleExtruder : public QQuickParticleExtruder +{ + Q_OBJECT + Q_PROPERTY(bool fill READ fill WRITE setFill NOTIFY fillChanged) + +public: + explicit QQuickRectangleExtruder(QObject *parent = 0); + virtual QPointF extrude(const QRectF &); + virtual bool contains(const QRectF &bounds, const QPointF &point); + bool fill() const + { + return m_fill; + } + +signals: + + void fillChanged(bool arg); + +public slots: + + void setFill(bool arg) + { + if (m_fill != arg) { + m_fill = arg; + emit fillChanged(arg); + } + } +protected: + bool m_fill; +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // RectangleEXTRUDER_H diff --git a/src/declarative/particles/qquickspritegoal.cpp b/src/declarative/particles/qquickspritegoal.cpp new file mode 100644 index 0000000000..7c839dbf53 --- /dev/null +++ b/src/declarative/particles/qquickspritegoal.cpp @@ -0,0 +1,153 @@ +/**************************************************************************** +** +** 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 "qquickspritegoal_p.h" +#include +#include +#include "qquickimageparticle_p.h" +#include + +QT_BEGIN_NAMESPACE + +/*! + \qmlclass SpriteGoal QQuickSpriteGoalAffector + \inqmlmodule QtQuick.Particles 2 + \inherits Affector + \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 +*/ + +QQuickSpriteGoalAffector::QQuickSpriteGoalAffector(QQuickItem *parent) : + QQuickParticleAffector(parent), + m_goalIdx(-1), + m_lastEngine(0), + m_jump(false), + m_systemStates(false), + m_notUsingEngine(false) +{ + m_ignoresTime = true; +} + +void QQuickSpriteGoalAffector::updateStateIndex(QQuickStochasticEngine* e) +{ + if (m_systemStates){ + m_goalIdx = m_system->groupIds[m_goalState]; + }else{ + m_lastEngine = e; + for (int i=0; istateCount(); i++){ + if (e->state(i)->name() == m_goalState){ + m_goalIdx = i; + return; + } + } + m_goalIdx = -1;//Can't find it + } +} + +void QQuickSpriteGoalAffector::setGoalState(QString arg) +{ + if (m_goalState != arg) { + m_goalState = arg; + emit goalStateChanged(arg); + if (m_goalState.isEmpty()) + m_goalIdx = -1; + else + m_goalIdx = -2; + } +} + +bool QQuickSpriteGoalAffector::affectParticle(QQuickParticleData *d, qreal dt) +{ + Q_UNUSED(dt); + QQuickStochasticEngine *engine = 0; + if (!m_systemStates){ + //TODO: Affect all engines + foreach (QQuickParticlePainter *p, m_system->groupData[d->group]->painters) + if (qobject_cast(p)) + engine = qobject_cast(p)->spriteEngine(); + }else{ + engine = m_system->stateEngine; + if (!engine) + m_notUsingEngine = true; + } + if (!engine && !m_notUsingEngine) + return false; + + if (m_goalIdx == -2 || engine != m_lastEngine) + updateStateIndex(engine); + int index = d->index; + if (m_systemStates) + index = d->systemIndex; + if (m_notUsingEngine){//systemStates && 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, m_goalIdx); + }else if (engine->curState(index) != m_goalIdx){ + engine->setGoal(m_goalIdx, index, m_jump); + return true; //Doesn't affect particle data, but necessary for onceOff + } + return false; +} + +QT_END_NAMESPACE diff --git a/src/declarative/particles/qquickspritegoal_p.h b/src/declarative/particles/qquickspritegoal_p.h new file mode 100644 index 0000000000..b979772a78 --- /dev/null +++ b/src/declarative/particles/qquickspritegoal_p.h @@ -0,0 +1,125 @@ +/**************************************************************************** +** +** 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 SPRITEGOALAFFECTOR_H +#define SPRITEGOALAFFECTOR_H +#include "qquickparticleaffector_p.h" +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QQuickStochasticEngine; + +class QQuickSpriteGoalAffector : public QQuickParticleAffector +{ + Q_OBJECT + Q_PROPERTY(QString goalState READ goalState WRITE setGoalState NOTIFY goalStateChanged) + Q_PROPERTY(bool jump READ jump WRITE setJump NOTIFY jumpChanged) + Q_PROPERTY(bool systemStates READ systemStates WRITE setSystemStates NOTIFY systemStatesChanged) +public: + explicit QQuickSpriteGoalAffector(QQuickItem *parent = 0); + + QString goalState() const + { + return m_goalState; + } + + bool jump() const + { + return m_jump; + } + bool systemStates() const + { + return m_systemStates; + } + +protected: + virtual bool affectParticle(QQuickParticleData *d, qreal dt); +signals: + + void goalStateChanged(QString arg); + + void jumpChanged(bool arg); + + void systemStatesChanged(bool arg); + +public slots: + +void setGoalState(QString arg); + +void setJump(bool arg) +{ + if (m_jump != arg) { + m_jump = arg; + emit jumpChanged(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); + } +} + +private: + void updateStateIndex(QQuickStochasticEngine* e); + QString m_goalState; + int m_goalIdx; + QQuickStochasticEngine* m_lastEngine; + bool m_jump; + bool m_systemStates; + + bool m_notUsingEngine; +}; + +QT_END_NAMESPACE + +QT_END_HEADER + +#endif // SPRITEGOALAFFECTOR_H diff --git a/src/declarative/particles/qquicktargetdirection.cpp b/src/declarative/particles/qquicktargetdirection.cpp new file mode 100644 index 0000000000..eb2eb16c6e --- /dev/null +++ b/src/declarative/particles/qquicktargetdirection.cpp @@ -0,0 +1,131 @@ +/**************************************************************************** +** +** 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 "qquicktargetdirection_p.h" +#include "qquickparticleemitter_p.h" +#include +#include + +QT_BEGIN_NAMESPACE +/*! + \qmlclass TargetDirection QQuickTargetDirection + \inqmlmodule QtQuick.Particles 2 + \inherits Direction + \brief The TargetDirection element allows you to specify a direction towards the target point + +*/ +/*! + \qmlproperty real QtQuick.Particles2::TargetDirection::targetX +*/ +/*! + \qmlproperty real QtQuick.Particles2::TargetDirection::targetY +*/ +/*! + \qmlproperty Item QtQuick.Particles2::TargetDirection::targetItem + If specified, this will take precedence over targetX and targetY. + The targeted point will be the center of the specified Item +*/ +/*! + \qmlproperty real QtQuick.Particles2::TargetDirection::targetVariation +*/ +/*! + \qmlproperty real QtQuick.Particles2::TargetDirection::magnitude +*/ +/*! + \qmlproperty real QtQuick.Particles2::TargetDirection::magnitudeVariation +*/ +/*! + \qmlproperty bool QtQuick.Particles2::TargetDirection::proportionalMagnitude + + If true, then the value of magnitude and magnitudeVariation shall be interpreted as multiples + of the distance between the source point and the target point, per second. + + If false(default), then the value of magnitude and magnitudeVariation shall be interpreted as + pixels per second. +*/ + +QQuickTargetDirection::QQuickTargetDirection(QObject *parent) : + QQuickDirection(parent) + , m_targetX(0) + , m_targetY(0) + , m_targetVariation(0) + , m_proportionalMagnitude(false) + , m_magnitude(0) + , m_magnitudeVariation(0) + , m_targetItem(0) +{ +} + +const QPointF QQuickTargetDirection::sample(const QPointF &from) +{ + //###This approach loses interpolating the last position of the target (like we could with the emitter) is it worthwhile? + QPointF ret; + qreal targetX; + qreal targetY; + if (m_targetItem){ + QQuickParticleEmitter* parentEmitter = qobject_cast(parent()); + targetX = m_targetItem->width()/2; + targetY = m_targetItem->height()/2; + if (!parentEmitter){ + qWarning() << "Directed vector is not a child of the emitter. Mapping of target item coordinates may fail."; + targetX += m_targetItem->x(); + targetY += m_targetItem->y(); + }else{ + ret = parentEmitter->mapFromItem(m_targetItem, QPointF(targetX, targetY)); + targetX = ret.x(); + targetY = ret.y(); + } + }else{ + targetX = m_targetX; + targetY = m_targetY; + } + targetX += 0 - from.x() - m_targetVariation + rand()/(float)RAND_MAX * m_targetVariation*2; + targetY += 0 - from.y() - m_targetVariation + rand()/(float)RAND_MAX * m_targetVariation*2; + qreal theta = atan2(targetY, targetX); + qreal mag = m_magnitude + rand()/(float)RAND_MAX * m_magnitudeVariation * 2 - m_magnitudeVariation; + if (m_proportionalMagnitude) + mag *= sqrt(targetX * targetX + targetY * targetY); + ret.setX(mag * cos(theta)); + ret.setY(mag * sin(theta)); + return ret; +} + +QT_END_NAMESPACE diff --git a/src/declarative/particles/qquicktargetdirection_p.h b/src/declarative/particles/qquicktargetdirection_p.h new file mode 100644 index 0000000000..2fc62b3ad8 --- /dev/null +++ b/src/declarative/particles/qquicktargetdirection_p.h @@ -0,0 +1,191 @@ +/**************************************************************************** +** +** 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 DIRECTEDVECTOR_H +#define DIRECTEDVECTOR_H +#include "qquickdirection_p.h" +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QQuickItem; +class QQuickTargetDirection : public QQuickDirection +{ + Q_OBJECT + Q_PROPERTY(qreal targetX READ targetX WRITE setTargetX NOTIFY targetXChanged) + Q_PROPERTY(qreal targetY READ targetY WRITE setTargetY NOTIFY targetYChanged) + //If targetItem is set, X/Y are ignored. Aims at middle of item, use variation for variation + Q_PROPERTY(QQuickItem* targetItem READ targetItem WRITE setTargetItem NOTIFY targetItemChanged) + + Q_PROPERTY(qreal targetVariation READ targetVariation WRITE setTargetVariation NOTIFY targetVariationChanged) + + //TODO: An enum would be better + Q_PROPERTY(bool proportionalMagnitude READ proportionalMagnitude WRITE setProportionalMagnitude NOTIFY proprotionalMagnitudeChanged) + Q_PROPERTY(qreal magnitude READ magnitude WRITE setMagnitude NOTIFY magnitudeChanged) + Q_PROPERTY(qreal magnitudeVariation READ magnitudeVariation WRITE setMagnitudeVariation NOTIFY magnitudeVariationChanged) + +public: + explicit QQuickTargetDirection(QObject *parent = 0); + virtual const QPointF sample(const QPointF &from); + + qreal targetX() const + { + return m_targetX; + } + + qreal targetY() const + { + return m_targetY; + } + + qreal targetVariation() const + { + return m_targetVariation; + } + + qreal magnitude() const + { + return m_magnitude; + } + + bool proportionalMagnitude() const + { + return m_proportionalMagnitude; + } + + qreal magnitudeVariation() const + { + return m_magnitudeVariation; + } + + QQuickItem* targetItem() const + { + return m_targetItem; + } + +signals: + + void targetXChanged(qreal arg); + + void targetYChanged(qreal arg); + + void targetVariationChanged(qreal arg); + + void magnitudeChanged(qreal arg); + + void proprotionalMagnitudeChanged(bool arg); + + void magnitudeVariationChanged(qreal arg); + + void targetItemChanged(QQuickItem* arg); + +public slots: + void setTargetX(qreal arg) + { + if (m_targetX != arg) { + m_targetX = arg; + emit targetXChanged(arg); + } + } + + void setTargetY(qreal arg) + { + if (m_targetY != arg) { + m_targetY = arg; + emit targetYChanged(arg); + } + } + + void setTargetVariation(qreal arg) + { + if (m_targetVariation != arg) { + m_targetVariation = arg; + emit targetVariationChanged(arg); + } + } + + void setMagnitude(qreal arg) + { + if (m_magnitude != arg) { + m_magnitude = arg; + emit magnitudeChanged(arg); + } + } + + void setProportionalMagnitude(bool arg) + { + if (m_proportionalMagnitude != arg) { + m_proportionalMagnitude = arg; + emit proprotionalMagnitudeChanged(arg); + } + } + + void setMagnitudeVariation(qreal arg) + { + if (m_magnitudeVariation != arg) { + m_magnitudeVariation = arg; + emit magnitudeVariationChanged(arg); + } + } + + void setTargetItem(QQuickItem* arg) + { + if (m_targetItem != arg) { + m_targetItem = arg; + emit targetItemChanged(arg); + } + } + +private: + qreal m_targetX; + qreal m_targetY; + qreal m_targetVariation; + bool m_proportionalMagnitude; + qreal m_magnitude; + qreal m_magnitudeVariation; + QQuickItem *m_targetItem; +}; + +QT_END_NAMESPACE +QT_END_HEADER +#endif // DIRECTEDVECTOR_H diff --git a/src/declarative/particles/qquicktrailemitter.cpp b/src/declarative/particles/qquicktrailemitter.cpp new file mode 100644 index 0000000000..b90bb1cda9 --- /dev/null +++ b/src/declarative/particles/qquicktrailemitter.cpp @@ -0,0 +1,284 @@ +/**************************************************************************** +** +** 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 "qquicktrailemitter_p.h" +#include +#include +QT_BEGIN_NAMESPACE + +/*! + \qmlclass TrailEmitter QQuickTrailEmitter + \inqmlmodule QtQuick.Particles 2 + \inherits QQuickParticleEmitter + \brief The TrailEmitter element allows you to emit logical particles from other logical particles. + + This element emits logical particles into the ParticleSystem, with the + starting positions based on those of other logical particles. +*/ +QQuickTrailEmitter::QQuickTrailEmitter(QQuickItem *parent) : + QQuickParticleEmitter(parent) + , m_particlesPerParticlePerSecond(0) + , m_lastTimeStamp(0) + , m_emitterXVariation(0) + , m_emitterYVariation(0) + , m_followCount(0) + , m_emissionExtruder(0) + , m_defaultEmissionExtruder(new QQuickParticleExtruder(this)) +{ + //TODO: If followed increased their size + connect(this, SIGNAL(followChanged(QString)), + this, SLOT(recalcParticlesPerSecond())); + connect(this, SIGNAL(particleDurationChanged(int)), + this, SLOT(recalcParticlesPerSecond())); + connect(this, SIGNAL(particlesPerParticlePerSecondChanged(int)), + this, SLOT(recalcParticlesPerSecond())); +} + +/*! + \qmlproperty string QtQuick.Particles2::TrailEmitter::follow + + The type of logical particle which this is emitting from. +*/ +/*! + \qmlproperty qreal QtQuick.Particles2::TrailEmitter::speedFromMovement + + If this value is non-zero, then any movement of the emitter will provide additional + starting velocity to the particles based on the movement. The additional vector will be the + same angle as the emitter's movement, with a magnitude that is the magnitude of the emitters + movement multiplied by speedFromMovement. + + Default value is 0. +*/ +/*! + \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. 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 +*/ +/*! + \qmlsignal QtQuick.Particles2::TrailEmitter::emitFollowParticles(Array particles, real followed) + + This handler is called when particles are emitted from the \a followed particle. \a particles contains an array of particle objects which can be directly manipulated. + + If you use this signal handler, emitParticles will not be emitted. + +*/ + +bool QQuickTrailEmitter::isEmitFollowConnected() +{ + static int idx = QObjectPrivate::get(this)->signalIndex("emitFollowParticles(QDeclarativeV8Handle,QDeclarativeV8Handle)"); + return QObjectPrivate::get(this)->isSignalConnected(idx); +} + +void QQuickTrailEmitter::recalcParticlesPerSecond(){ + if (!m_system) + return; + m_followCount = m_system->groupData[m_system->groupIds[m_follow]]->size(); + if (!m_followCount){ + setParticlesPerSecond(1);//XXX: Fix this horrendous hack, needed so they aren't turned off from start (causes crashes - test that when gone you don't crash with 0 PPPS) + }else{ + setParticlesPerSecond(m_particlesPerParticlePerSecond * m_followCount); + m_lastEmission.resize(m_followCount); + m_lastEmission.fill(m_lastTimeStamp); + } +} + +void QQuickTrailEmitter::reset() +{ + m_followCount = 0; +} + +void QQuickTrailEmitter::emitWindow(int timeStamp) +{ + if (m_system == 0) + return; + if (!m_enabled && !m_pulseLeft && m_burstQueue.isEmpty()) + return; + if (m_followCount != m_system->groupData[m_system->groupIds[m_follow]]->size()){ + qreal oldPPS = m_particlesPerSecond; + recalcParticlesPerSecond(); + if (m_particlesPerSecond != oldPPS) + return;//system may need to update + } + + if (m_pulseLeft){ + m_pulseLeft -= timeStamp - m_lastTimeStamp * 1000.; + if (m_pulseLeft < 0){ + timeStamp += m_pulseLeft; + m_pulseLeft = 0; + } + } + + //TODO: Implement startTime and speedFromMovement + qreal time = timeStamp / 1000.; + qreal particleRatio = 1. / m_particlesPerParticlePerSecond; + qreal pt; + qreal maxLife = (m_particleDuration + m_particleDurationVariation)/1000.0; + + //Have to map it into this system, because particlesystem automaps it back + QPointF offset = m_system->mapFromItem(this, QPointF(0, 0)); + qreal sizeAtEnd = m_particleEndSize >= 0 ? m_particleEndSize : m_particleSize; + + int gId = m_system->groupIds[m_follow]; + int gId2 = m_system->groupIds[m_group]; + foreach (QQuickParticleData *d, m_system->groupData[gId]->data){ + if (!d || !d->stillAlive()){ + m_lastEmission[d->index] = time; //Should only start emitting when it returns to life + continue; + } + pt = m_lastEmission[d->index]; + if (pt < d->t) + pt = d->t; + if (pt + maxLife < time)//We missed so much, that we should skip emiting particles that are dead by now + pt = time - maxLife; + + if ((width() || height()) && !effectiveExtruder()->contains(QRectF(offset.x(), offset.y(), width(), height()),QPointF(d->curX(), d->curY()))){ + m_lastEmission[d->index] = time;//jump over this time period without emitting, because it's outside + continue; + } + + QList toEmit; + + while (pt < time || !m_burstQueue.isEmpty()){ + QQuickParticleData* datum = m_system->newDatum(gId2, !m_overwrite); + if (datum){//else, skip this emission + datum->e = this;//###useful? + + // Particle timestamp + datum->t = pt; + datum->lifeSpan = + (m_particleDuration + + ((rand() % ((m_particleDurationVariation*2) + 1)) - m_particleDurationVariation)) + / 1000.0; + + // Particle position + // Note that burst location doesn't get used for follow emitter + qreal followT = pt - d->t; + qreal followT2 = followT * followT * 0.5; + 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 - eW/2, + d->y - offset.y() + d->vy * followT + d->ay * followT2 - eH/2, + eW, eH); + + QQuickParticleExtruder* effectiveEmissionExtruder = m_emissionExtruder ? m_emissionExtruder : m_defaultEmissionExtruder; + const QPointF &newPos = effectiveEmissionExtruder->extrude(boundsRect); + datum->x = newPos.x(); + datum->y = newPos.y(); + + // Particle speed + const QPointF &speed = m_speed->sample(newPos); + datum->vx = speed.x() + + m_speed_from_movement * d->vx; + datum->vy = speed.y() + + m_speed_from_movement * d->vy; + + // Particle acceleration + const QPointF &accel = m_acceleration->sample(newPos); + datum->ax = accel.x(); + datum->ay = accel.y(); + + // Particle size + float sizeVariation = -m_particleSizeVariation + + rand() / float(RAND_MAX) * m_particleSizeVariation * 2; + + float size = qMax((qreal)0.0, m_particleSize + sizeVariation); + float endSize = qMax((qreal)0.0, sizeAtEnd + sizeVariation); + + datum->size = size * float(m_enabled); + datum->endSize = endSize * float(m_enabled); + + toEmit << datum; + + m_system->emitParticle(datum); + } + if (!m_burstQueue.isEmpty()){ + m_burstQueue.first().first--; + if (m_burstQueue.first().first <= 0) + m_burstQueue.pop_front(); + }else{ + pt += particleRatio; + } + } + + if (isEmitConnected() || isEmitFollowConnected()) { + v8::HandleScope handle_scope; + v8::Context::Scope scope(QDeclarativeEnginePrivate::getV8Engine(qmlEngine(this))->context()); + v8::Handle array = v8::Array::New(toEmit.size()); + for (int i=0; iSet(i, toEmit[i]->v8Value().toHandle()); + + if (isEmitFollowConnected()) + emitFollowParticles(QDeclarativeV8Handle::fromHandle(array), d->v8Value());//A chance for many arbitrary JS changes + else if (isEmitConnected()) + emitParticles(QDeclarativeV8Handle::fromHandle(array));//A chance for arbitrary JS changes + } + foreach (QQuickParticleData* d, toEmit) + m_system->emitParticle(d); + m_lastEmission[d->index] = pt; + } + + m_lastTimeStamp = time; +} +QT_END_NAMESPACE diff --git a/src/declarative/particles/qquicktrailemitter_p.h b/src/declarative/particles/qquicktrailemitter_p.h new file mode 100644 index 0000000000..ad94d7107d --- /dev/null +++ b/src/declarative/particles/qquicktrailemitter_p.h @@ -0,0 +1,171 @@ +/**************************************************************************** +** +** 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 FOLLOWEMITTER_H +#define FOLLOWEMITTER_H +#include "qquickparticleemitter_p.h" +#include "qquickparticleaffector_p.h" + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + + +class QQuickTrailEmitter : public QQuickParticleEmitter +{ + Q_OBJECT + Q_PROPERTY(QString follow READ follow WRITE setFollow NOTIFY followChanged) + Q_PROPERTY(int emitRatePerParticle READ particlesPerParticlePerSecond WRITE setParticlesPerParticlePerSecond NOTIFY particlesPerParticlePerSecondChanged) + + Q_PROPERTY(QQuickParticleExtruder* 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 QQuickTrailEmitter(QQuickItem *parent = 0); + virtual void emitWindow(int timeStamp); + virtual void reset(); + + int particlesPerParticlePerSecond() const + { + return m_particlesPerParticlePerSecond; + } + + qreal emitterXVariation() const + { + return m_emitterXVariation; + } + + qreal emitterYVariation() const + { + return m_emitterYVariation; + } + + QString follow() const + { + return m_follow; + } + + QQuickParticleExtruder* emissonShape() const + { + return m_emissionExtruder; + } + +signals: + void emitFollowParticles(QDeclarativeV8Handle particles, QDeclarativeV8Handle followed); + + void particlesPerParticlePerSecondChanged(int arg); + + void emitterXVariationChanged(qreal arg); + + void emitterYVariationChanged(qreal arg); + + void followChanged(QString arg); + + void emissionShapeChanged(QQuickParticleExtruder* arg); + +public slots: + + void setParticlesPerParticlePerSecond(int arg) + { + if (m_particlesPerParticlePerSecond != arg) { + m_particlesPerParticlePerSecond = arg; + emit particlesPerParticlePerSecondChanged(arg); + } + } + void setEmitterXVariation(qreal arg) + { + if (m_emitterXVariation != arg) { + m_emitterXVariation = arg; + emit emitterXVariationChanged(arg); + } + } + + void setEmitterYVariation(qreal arg) + { + if (m_emitterYVariation != arg) { + m_emitterYVariation = arg; + emit emitterYVariationChanged(arg); + } + } + + void setFollow(QString arg) + { + if (m_follow != arg) { + m_follow = arg; + emit followChanged(arg); + } + } + + void setEmissionShape(QQuickParticleExtruder* arg) + { + if (m_emissionExtruder != arg) { + m_emissionExtruder = arg; + emit emissionShapeChanged(arg); + } + } + +private slots: + void recalcParticlesPerSecond(); + +private: + QSet m_pending; + QVector m_lastEmission; + int m_particlesPerParticlePerSecond; + qreal m_lastTimeStamp; + qreal m_emitterXVariation; + qreal m_emitterYVariation; + QString m_follow; + int m_followCount; + QQuickParticleExtruder* m_emissionExtruder; + QQuickParticleExtruder* m_defaultEmissionExtruder; + bool isEmitFollowConnected(); +}; + +QT_END_NAMESPACE +QT_END_HEADER +#endif // FOLLOWEMITTER_H diff --git a/src/declarative/particles/qquickturbulence.cpp b/src/declarative/particles/qquickturbulence.cpp new file mode 100644 index 0000000000..5467be7ebc --- /dev/null +++ b/src/declarative/particles/qquickturbulence.cpp @@ -0,0 +1,210 @@ +/**************************************************************************** +** +** 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 "qquickturbulence_p.h" +#include "qquickparticlepainter_p.h"//TODO: Why was this needed again? +#include +#include +#include +QT_BEGIN_NAMESPACE + +/*! + \qmlclass Turbulence QQuickTurbulenceAffector + \inqmlmodule QtQuick.Particles 2 + \inherits Affector + \brief Turbulence provides fluid like forces based on a noise image. + + The Turbulence Element scales the noise source over the area it affects, + and uses the curl of that source to generate force vectors. + + Turbulence requires a fixed size. Unlike other affectors, a 0x0 Turbulence element + will affect no particles. + + The source should be relatively smooth black and white noise, such as perlin noise. +*/ +/*! + \qmlproperty real QtQuick.Particles2::Turbulence::strength + + The magnitude of the velocity vector at any point varies between zero and + the square root of two. It will then be multiplied by strength to get the + velocity per second for the particles affected by the turbulence. +*/ +/*! + \qmlproperty url QtQuick.Particles2::Turbulence::noiseSource + + The source image to generate the turbulence from. It will be scaled to the size of the element, + so equal or larger sizes will give better results. Tweaking this image is the only way to tweak + behavior such as where vortices are or how many exist. + + The source should be a relatively smooth black and white noise image, such as perlin noise. + A default image will be used if none is provided. +*/ + +QQuickTurbulenceAffector::QQuickTurbulenceAffector(QQuickItem *parent) : + QQuickParticleAffector(parent), + m_strength(10), m_lastT(0), m_gridSize(0), m_field(0), m_vectorField(0), m_inited(false) +{ +} + +void QQuickTurbulenceAffector::geometryChanged(const QRectF &, const QRectF &) +{ + initializeGrid(); +} + +QQuickTurbulenceAffector::~QQuickTurbulenceAffector() +{ + if (m_field) { + for (int i=0; i= m_gridSize) + x = m_gridSize - 1; + if (y < 0) + y = 0; + if (y >= m_gridSize) + y = m_gridSize - 1; + return m_field[x][y]; +} + +void QQuickTurbulenceAffector::ensureInit() +{ + if (m_inited) + return; + m_inited = true; + initializeGrid(); +} + +void QQuickTurbulenceAffector::affectSystem(qreal dt) +{ + if (!m_system || !m_enabled) + return; + ensureInit(); + if (!m_gridSize) + return; + + updateOffsets();//### Needed if an ancestor is transformed. + + QRect boundsRect(0,0,m_gridSize,m_gridSize); + foreach (QQuickParticleGroupData *gd, m_system->groupData){ + if (!activeGroup(m_system->groupData.key(gd))) + continue; + foreach (QQuickParticleData *d, gd->data){ + if (!shouldAffect(d)) + continue; + QPoint pos = (QPointF(d->curX(), d->curY()) - m_offset).toPoint(); + if (!boundsRect.contains(pos,true))//Need to redo bounds checking due to quantization. + continue; + qreal fx = 0.0; + qreal fy = 0.0; + fx += m_vectorField[pos.x()][pos.y()].x() * m_strength; + fy += m_vectorField[pos.x()][pos.y()].y() * m_strength; + if (fx || fy){ + d->setInstantaneousVX(d->curVX()+ fx * dt); + d->setInstantaneousVY(d->curVY()+ fy * dt); + postAffect(d); + } + } + } +} + +QT_END_NAMESPACE diff --git a/src/declarative/particles/qquickturbulence_p.h b/src/declarative/particles/qquickturbulence_p.h new file mode 100644 index 0000000000..dc72f40eff --- /dev/null +++ b/src/declarative/particles/qquickturbulence_p.h @@ -0,0 +1,119 @@ +/**************************************************************************** +** +** 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 TURBULENCEAFFECTOR_H +#define TURBULENCEAFFECTOR_H +#include "qquickparticleaffector_p.h" +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + + +class QQuickParticlePainter; + +class QQuickTurbulenceAffector : public QQuickParticleAffector +{ + Q_OBJECT + Q_PROPERTY(qreal strength READ strength WRITE setStrength NOTIFY strengthChanged) + Q_PROPERTY(QUrl noiseSource READ noiseSource WRITE setNoiseSource NOTIFY noiseSourceChanged) + public: + explicit QQuickTurbulenceAffector(QQuickItem *parent = 0); + ~QQuickTurbulenceAffector(); + virtual void affectSystem(qreal dt); + + qreal strength() const + { + return m_strength; + } + + QUrl noiseSource() const + { + return m_noiseSource; + } +signals: + + void strengthChanged(qreal arg); + + void noiseSourceChanged(QUrl arg); + +public slots: + + void setStrength(qreal arg) + { + if (m_strength != arg) { + m_strength = arg; + emit strengthChanged(arg); + } + } + + void setNoiseSource(QUrl arg) + { + if (m_noiseSource != arg) { + m_noiseSource = arg; + emit noiseSourceChanged(arg); + initializeGrid(); + } + } + +protected: + virtual void geometryChanged(const QRectF &newGeometry, + const QRectF &oldGeometry); +private: + void ensureInit(); + void mapUpdate(); + void initializeGrid(); + qreal boundsRespectingField(int x, int y); + qreal m_strength; + qreal m_lastT; + int m_gridSize; + qreal** m_field; + QPointF** m_vectorField; + bool m_inited; + QUrl m_noiseSource; +}; + +QT_END_NAMESPACE +QT_END_HEADER +#endif // TURBULENCEAFFECTOR_H diff --git a/src/declarative/particles/qquickv8particledata.cpp b/src/declarative/particles/qquickv8particledata.cpp new file mode 100644 index 0000000000..61d70395ef --- /dev/null +++ b/src/declarative/particles/qquickv8particledata.cpp @@ -0,0 +1,384 @@ +/**************************************************************************** +** +** 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 "qquickv8particledata_p.h" +#include "qquickparticlesystem_p.h"//for QQuickParticleData +#include + +QT_BEGIN_NAMESPACE + +/*! + \qmlclass Particle + \inqmlmodule QtQuick.Particles 2 + \brief Particle elements can be manipulated in custom emitters and affectors. + + Particle elements are always managed internally by the ParticleSystem and cannot be created in QML. + However, sometimes they are exposed via signals so as to allow arbitrary changes to the particle state +*/ + +/*! + \qmlproperty real QtQuick.Particles2::Particle::initialX + The x coordinate of the particle at the beginning of its lifetime. + + The method of simulation prefers to have the initial values changed, rather + than determining and changing the value at a given time. Change initial + values in CustomEmitters instead of the current values. +*/ + +/*! + \qmlproperty real QtQuick.Particles2::Particle::initialVX + The x velocity of the particle at the beginning of its lifetime. + + The method of simulation prefers to have the initial values changed, rather + than determining and changing the value at a given time. Change initial + values in CustomEmitters instead of the current values. +*/ + +/*! + \qmlproperty real QtQuick.Particles2::Particle::initialAX + The x acceleration of the particle at the beginning of its lifetime. + + The method of simulation prefers to have the initial values changed, rather + than determining and changing the value at a given time. Change initial + values in CustomEmitters instead of the current values. +*/ + +/*! + \qmlproperty real QtQuick.Particles2::Particle::initialY + The y coordinate of the particle at the beginning of its lifetime. + + The method of simulation prefers to have the initial values changed, rather + than determining and changing the value at a given time. Change initial + values in CustomEmitters instead of the current values. +*/ + +/*! + \qmlproperty real QtQuick.Particles2::Particle::initialVY + The y velocity of the particle at the beginning of its lifetime. + + The method of simulation prefers to have the initial values changed, rather + than determining and changing the value at a given time. Change initial + values in CustomEmitters instead of the current values. +*/ + +/*! + \qmlproperty real QtQuick.Particles2::Particle::initialAY + The y acceleration of the particle at the beginning of its lifetime. + + The method of simulation prefers to have the initial values changed, rather + than determining and changing the value at a given time. Change initial + values in CustomEmitters instead of the current values. +*/ + +/*! + \qmlproperty real QtQuick.Particles2::Particle::x + The current x coordinate of the particle. +*/ + +/*! + \qmlproperty real QtQuick.Particles2::Particle::vx + The current x velocity of the particle. +*/ + +/*! + \qmlproperty real QtQuick.Particles2::Particle::ax + The current x acceleration of the particle. +*/ + +/*! + \qmlproperty real QtQuick.Particles2::Particle::y + The current y coordinate of the particle. +*/ + +/*! + \qmlproperty real QtQuick.Particles2::Particle::vy + The current y velocity of the particle. +*/ + +/*! + \qmlproperty real QtQuick.Particles2::Particle::ay + The current y acceleration of the particle. +*/ + +/*! + \qmlproperty real QtQuick.Particles2::Particle::t + The time, in seconds since the beginning of the simulation, that the particle was born. +*/ + + +/*! + \qmlproperty real QtQuick.Particles2::Particle::startSize + The size in pixels that the particle image is at the start + of its life. +*/ + + +/*! + \qmlproperty real QtQuick.Particles2::Particle::endSize + The size in pixels that the particle image is at the end + of its life. If this value is less than 0, then it is + disregarded and the particle will have its startSize for the + entire lifetime. +*/ + +/*! + \qmlproperty real QtQuick.Particles2::Particle::lifeSpan + The time in seconds that the particle will live for. +*/ + +/*! + \qmlproperty real QtQuick.Particles2::Particle::rotation + Degrees clockwise that the particle image is rotated at + the beginning of its life. +*/ + +/*! + \qmlproperty real QtQuick.Particles2::Particle::rotationSpeed + Degrees clockwise per second that the particle image is rotated at while alive. +*/ + +/*! + \qmlproperty real QtQuick.Particles2::Particle::autoRotate + If autoRotate == 1.0, then the particle's rotation will be + set so that it faces the direction of travel, plus any + rotation from the rotation or rotationSpeed properties. +*/ +/*! + \qmlmethod real QtQuick.Particles2::Particle::lifeLeft + The time in seconds that the particle has left to live at + the current point in time. +*/ +/*! + \qmlmethod real QtQuick.Particles2::Particle::currentSize + The currentSize of the particle, interpolating between startSize and endSize based on the currentTime. +*/ + + + +//### Particle data handles are not locked to within certain scopes like QQuickContext2D, but there's no way to reload either... +class QV8ParticleDataResource : public QV8ObjectResource +{ + V8_RESOURCE_TYPE(ParticleDataType) +public: + QV8ParticleDataResource(QV8Engine *e) : QV8ObjectResource(e) {} + QQuickParticleData* datum;//TODO: Guard needed? +}; + +class QV8ParticleDataDeletable : public QV8Engine::Deletable +{ +public: + QV8ParticleDataDeletable(QV8Engine *engine); + ~QV8ParticleDataDeletable(); + + v8::Persistent constructor; +}; + +static v8::Handle particleData_discard(const v8::Arguments &args) +{ + QV8ParticleDataResource *r = v8_resource_cast(args.This()); + + if (!r || !r->datum) + V8THROW_ERROR("Not a valid ParticleData object"); + + r->datum->lifeSpan = 0; //Don't kill(), because it could still be in the middle of being created + return v8::Undefined(); +} + +static v8::Handle particleData_lifeLeft(const v8::Arguments &args) +{ + QV8ParticleDataResource *r = v8_resource_cast(args.This()); + if (!r || !r->datum) + V8THROW_ERROR("Not a valid ParticleData object"); + + return v8::Number::New(r->datum->lifeLeft()); +} + +static v8::Handle particleData_curSize(const v8::Arguments &args) +{ + QV8ParticleDataResource *r = v8_resource_cast(args.This()); + if (!r || !r->datum) + V8THROW_ERROR("Not a valid ParticleData object"); + + return v8::Number::New(r->datum->curSize()); +} + +#define FLOAT_GETTER_AND_SETTER(VARIABLE) static v8::Handle particleData_get_ ## VARIABLE (v8::Local, const v8::AccessorInfo &info) \ +{ \ + QV8ParticleDataResource *r = v8_resource_cast(info.This()); \ + if (!r || !r->datum) \ + V8THROW_ERROR("Not a valid ParticleData object"); \ +\ + return v8::Number::New(r->datum-> VARIABLE);\ +}\ +\ +static void particleData_set_ ## VARIABLE (v8::Local, v8::Local value, const v8::AccessorInfo &info)\ +{\ + QV8ParticleDataResource *r = v8_resource_cast(info.This());\ + if (!r || !r->datum)\ + V8THROW_ERROR_SETTER("Not a valid ParticleData object");\ +\ + r->datum-> VARIABLE = value->NumberValue();\ +} + +#define FAKE_FLOAT_GETTER_AND_SETTER(VARIABLE, GETTER, SETTER) static v8::Handle particleData_get_ ## VARIABLE (v8::Local, const v8::AccessorInfo &info) \ +{ \ + QV8ParticleDataResource *r = v8_resource_cast(info.This()); \ + if (!r || !r->datum) \ + V8THROW_ERROR("Not a valid ParticleData object"); \ +\ + return v8::Number::New(r->datum-> GETTER ());\ +}\ +\ +static void particleData_set_ ## VARIABLE (v8::Local, v8::Local value, const v8::AccessorInfo &info)\ +{\ + QV8ParticleDataResource *r = v8_resource_cast(info.This());\ + if (!r || !r->datum)\ + V8THROW_ERROR_SETTER("Not a valid ParticleData object");\ +\ + r->datum-> SETTER ( value->NumberValue() );\ +} + +#define FLOAT_REGISTER_ACCESSOR(FT, ENGINE, VARIABLE, NAME) FT ->PrototypeTemplate()->SetAccessor( v8::String::New( #NAME ), particleData_get_ ## VARIABLE , particleData_set_ ## VARIABLE , v8::External::Wrap(ENGINE)) + +FLOAT_GETTER_AND_SETTER(x) +FLOAT_GETTER_AND_SETTER(y) +FLOAT_GETTER_AND_SETTER(t) +FLOAT_GETTER_AND_SETTER(lifeSpan) +FLOAT_GETTER_AND_SETTER(size) +FLOAT_GETTER_AND_SETTER(endSize) +FLOAT_GETTER_AND_SETTER(vx) +FLOAT_GETTER_AND_SETTER(vy) +FLOAT_GETTER_AND_SETTER(ax) +FLOAT_GETTER_AND_SETTER(ay) +FLOAT_GETTER_AND_SETTER(xx) +FLOAT_GETTER_AND_SETTER(xy) +FLOAT_GETTER_AND_SETTER(rotation) +FLOAT_GETTER_AND_SETTER(rotationSpeed) +FLOAT_GETTER_AND_SETTER(autoRotate) +FLOAT_GETTER_AND_SETTER(animIdx) +FLOAT_GETTER_AND_SETTER(frameDuration) +FLOAT_GETTER_AND_SETTER(frameCount) +FLOAT_GETTER_AND_SETTER(animT) +FLOAT_GETTER_AND_SETTER(r) +FLOAT_GETTER_AND_SETTER(update) +FAKE_FLOAT_GETTER_AND_SETTER(curX, curX, setInstantaneousX) +FAKE_FLOAT_GETTER_AND_SETTER(curVX, curVX, setInstantaneousVX) +FAKE_FLOAT_GETTER_AND_SETTER(curAX, curAX, setInstantaneousAX) +FAKE_FLOAT_GETTER_AND_SETTER(curY, curY, setInstantaneousY) +FAKE_FLOAT_GETTER_AND_SETTER(curVY, curVY, setInstantaneousVY) +FAKE_FLOAT_GETTER_AND_SETTER(curAY, curAY, setInstantaneousAY) + +//TODO: Non-floats (color, update?) once floats are working well + +QV8ParticleDataDeletable::QV8ParticleDataDeletable(QV8Engine *engine) +{ + v8::HandleScope handle_scope; + v8::Context::Scope scope(engine->context()); + + v8::Local ft = v8::FunctionTemplate::New(); + ft->InstanceTemplate()->SetHasExternalResource(true); + ft->PrototypeTemplate()->Set(v8::String::New("discard"), V8FUNCTION(particleData_discard, engine)); + ft->PrototypeTemplate()->Set(v8::String::New("lifeLeft"), V8FUNCTION(particleData_lifeLeft, engine)); + ft->PrototypeTemplate()->Set(v8::String::New("currentSize"), V8FUNCTION(particleData_curSize, engine)); + FLOAT_REGISTER_ACCESSOR(ft, engine, x, initialX); + FLOAT_REGISTER_ACCESSOR(ft, engine, y, initialY); + FLOAT_REGISTER_ACCESSOR(ft, engine, t, t); + FLOAT_REGISTER_ACCESSOR(ft, engine, lifeSpan, lifeSpan); + FLOAT_REGISTER_ACCESSOR(ft, engine, size, startSize); + FLOAT_REGISTER_ACCESSOR(ft, engine, endSize, endSize); + FLOAT_REGISTER_ACCESSOR(ft, engine, vx, initialVX); + FLOAT_REGISTER_ACCESSOR(ft, engine, vy, initialVY); + FLOAT_REGISTER_ACCESSOR(ft, engine, ax, initialAX); + FLOAT_REGISTER_ACCESSOR(ft, engine, ay, initialAY); + FLOAT_REGISTER_ACCESSOR(ft, engine, xx, xDeformationVector); + FLOAT_REGISTER_ACCESSOR(ft, engine, xy, yDeformationVector); + FLOAT_REGISTER_ACCESSOR(ft, engine, rotation, rotation); + FLOAT_REGISTER_ACCESSOR(ft, engine, rotationSpeed, rotationSpeed); + FLOAT_REGISTER_ACCESSOR(ft, engine, autoRotate, autoRotate); + FLOAT_REGISTER_ACCESSOR(ft, engine, animIdx, animationIndex); + FLOAT_REGISTER_ACCESSOR(ft, engine, frameDuration, frameDuration); + FLOAT_REGISTER_ACCESSOR(ft, engine, frameCount, frameCount); + FLOAT_REGISTER_ACCESSOR(ft, engine, animT, animationT); + FLOAT_REGISTER_ACCESSOR(ft, engine, r, r); + FLOAT_REGISTER_ACCESSOR(ft, engine, update, update); + FLOAT_REGISTER_ACCESSOR(ft, engine, curX, x); + FLOAT_REGISTER_ACCESSOR(ft, engine, curVX, vx); + FLOAT_REGISTER_ACCESSOR(ft, engine, curAX, ax); + FLOAT_REGISTER_ACCESSOR(ft, engine, curY, y); + FLOAT_REGISTER_ACCESSOR(ft, engine, curVY, vy); + FLOAT_REGISTER_ACCESSOR(ft, engine, curAY, ay); + + constructor = qPersistentNew(ft->GetFunction()); +} + +QV8ParticleDataDeletable::~QV8ParticleDataDeletable() +{ + qPersistentDispose(constructor); +} + +V8_DEFINE_EXTENSION(QV8ParticleDataDeletable, particleV8Data); + + +QQuickV8ParticleData::QQuickV8ParticleData(QV8Engine* engine, QQuickParticleData* datum) +{ + if (!engine || !datum) + return; + v8::HandleScope handle_scope; + v8::Context::Scope scope(engine->context()); + + QV8ParticleDataDeletable *d = particleV8Data(engine); + m_v8Value = qPersistentNew(d->constructor->NewInstance()); + QV8ParticleDataResource *r = new QV8ParticleDataResource(engine); + r->datum = datum; + m_v8Value->SetExternalResource(r); +} + +QQuickV8ParticleData::~QQuickV8ParticleData() +{ + qPersistentDispose(m_v8Value); +} + +QDeclarativeV8Handle QQuickV8ParticleData::v8Value() +{ + return QDeclarativeV8Handle::fromHandle(m_v8Value); +} + +QT_END_NAMESPACE diff --git a/src/declarative/particles/qquickv8particledata_p.h b/src/declarative/particles/qquickv8particledata_p.h new file mode 100644 index 0000000000..811974c132 --- /dev/null +++ b/src/declarative/particles/qquickv8particledata_p.h @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** 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 QQuickV8PARTICLEDATA_H +#define QQuickV8PARTICLEDATA_H + +#include + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + +class QQuickParticleData; +class QQuickV8ParticleData { +public: + QQuickV8ParticleData(QV8Engine*,QQuickParticleData*); + ~QQuickV8ParticleData(); + QDeclarativeV8Handle v8Value(); +private: + v8::Persistent m_v8Value; +}; + + +QT_END_NAMESPACE + +QT_END_HEADER + + +#endif diff --git a/src/declarative/particles/qquickwander.cpp b/src/declarative/particles/qquickwander.cpp new file mode 100644 index 0000000000..dfbff36076 --- /dev/null +++ b/src/declarative/particles/qquickwander.cpp @@ -0,0 +1,180 @@ +/**************************************************************************** +** +** 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 "qquickwander_p.h" +#include "qquickparticlesystem_p.h"//for ParticlesVertices +QT_BEGIN_NAMESPACE +/*! + \qmlclass Wander QQuickWanderAffector + \inqmlmodule QtQuick.Particles 2 + \inherits Affector + \brief The Wander affector allows particles to randomly vary their trajectory. + +*/ +/*! + \qmlproperty real QtQuick.Particles2::Wander::pace + + Maximum attribute change per second. +*/ +/*! + \qmlproperty real QtQuick.Particles2::Wander::xVariance + + Maximum attribute x value (as a result of Wander). + + If unset, Wander will not affect x values. +*/ +/*! + \qmlproperty real QtQuick.Particles2::Wander::yVariance + + Maximum attribute y value (as a result of Wander). + + If unset, Wander will not affect y values. +*/ +/*! + \qmlproperty AffectableParameter QtQuick.Particles2::Wander::affectedParameter + + What attribute of particles is directly affected. + \list + \o PointAttractor.Position + \o PointAttractor.Velocity + \o PointAttractor.Acceleration + \endlist +*/ + +QQuickWanderAffector::QQuickWanderAffector(QQuickItem *parent) : + QQuickParticleAffector(parent), m_xVariance(0), m_yVariance(0), m_pace(0) + , m_affectedParameter(Velocity) +{ + m_needsReset = true; +} + +QQuickWanderAffector::~QQuickWanderAffector() +{ + for (QHash::const_iterator iter=m_wanderData.constBegin(); + iter != m_wanderData.constEnd(); iter++) + delete (*iter); +} + +WanderData* QQuickWanderAffector::getData(int idx) +{ + if (m_wanderData.contains(idx)) + return m_wanderData[idx]; + WanderData* d = new WanderData; + d->x_vel = 0; + d->y_vel = 0; + d->x_peak = m_xVariance; + d->y_peak = m_yVariance; + d->x_var = m_pace * qreal(qrand()) / RAND_MAX; + d->y_var = m_pace * qreal(qrand()) / RAND_MAX; + + m_wanderData.insert(idx, d); + return d; +} + +void QQuickWanderAffector::reset(int systemIdx) +{ + if (m_wanderData.contains(systemIdx)) + delete m_wanderData[systemIdx]; + m_wanderData.remove(systemIdx); +} + +bool QQuickWanderAffector::affectParticle(QQuickParticleData* data, qreal dt) +{ + /*TODO: Add a mode which does basically this - picking a direction, going in it (random speed) and then going back + WanderData* d = getData(data->systemIndex); + if (m_xVariance != 0.) { + if ((d->x_vel > d->x_peak && d->x_var > 0.0) || (d->x_vel < -d->x_peak && d->x_var < 0.0)) { + d->x_var = -d->x_var; + d->x_peak = m_xVariance + m_xVariance * qreal(qrand()) / RAND_MAX; + } + d->x_vel += d->x_var * dt; + } + qreal dx = dt * d->x_vel; + + if (m_yVariance != 0.) { + if ((d->y_vel > d->y_peak && d->y_var > 0.0) || (d->y_vel < -d->y_peak && d->y_var < 0.0)) { + d->y_var = -d->y_var; + d->y_peak = m_yVariance + m_yVariance * qreal(qrand()) / RAND_MAX; + } + d->y_vel += d->y_var * dt; + } + qreal dy = dt * d->x_vel; + + //### Should we be amending vel instead? + ParticleVertex* p = &(data->pv); + p->x += dx; + + p->y += dy; + return true; + */ + qreal dx = dt * m_pace * (2 * qreal(qrand())/RAND_MAX - 1); + qreal dy = dt * m_pace * (2 * qreal(qrand())/RAND_MAX - 1); + qreal newX, newY; + switch (m_affectedParameter){ + case Position: + newX = data->curX() + dx; + if (m_xVariance > qAbs(newX) ) + data->x += dx; + newY = data->curY() + dy; + if (m_yVariance > qAbs(newY) ) + data->y += dy; + break; + default: + case Velocity: + newX = data->curVX() + dx; + if (m_xVariance > qAbs(newX) ) + data->setInstantaneousVX(newX); + newY = data->curVY() + dy; + if (m_yVariance > qAbs(newY) ) + data->setInstantaneousVY(newY); + break; + case Acceleration: + newX = data->ax + dx; + if (m_xVariance > qAbs(newX) ) + data->setInstantaneousAX(newX); + newY = data->ay + dy; + if (m_yVariance > qAbs(newY) ) + data->setInstantaneousAY(newY); + break; + } + return true; +} +QT_END_NAMESPACE diff --git a/src/declarative/particles/qquickwander_p.h b/src/declarative/particles/qquickwander_p.h new file mode 100644 index 0000000000..99515fe629 --- /dev/null +++ b/src/declarative/particles/qquickwander_p.h @@ -0,0 +1,161 @@ +/**************************************************************************** +** +** 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 WANDERAFFECTOR_H +#define WANDERAFFECTOR_H +#include +#include "qquickparticleaffector_p.h" + +QT_BEGIN_HEADER + +QT_BEGIN_NAMESPACE + +QT_MODULE(Declarative) + + +struct WanderData{ + qreal x_vel; + qreal y_vel; + qreal x_peak; + qreal x_var; + qreal y_peak; + qreal y_var; +}; + +class QQuickWanderAffector : public QQuickParticleAffector +{ + Q_OBJECT + Q_PROPERTY(qreal pace READ pace WRITE setPace NOTIFY paceChanged) + Q_PROPERTY(qreal xVariance READ xVariance WRITE setXVariance NOTIFY xVarianceChanged) + Q_PROPERTY(qreal yVariance READ yVariance WRITE setYVariance NOTIFY yVarianceChanged) + Q_PROPERTY(AffectableParameters affectedParameter READ affectedParameter WRITE setAffectedParameter NOTIFY affectedParameterChanged) + Q_ENUMS(AffectableParameters) + +public: + enum AffectableParameters { + Position, + Velocity, + Acceleration + }; + + explicit QQuickWanderAffector(QQuickItem *parent = 0); + ~QQuickWanderAffector(); + virtual void reset(int systemIdx); + + qreal xVariance() const + { + return m_xVariance; + } + + qreal yVariance() const + { + return m_yVariance; + } + + qreal pace() const + { + return m_pace; + } + + AffectableParameters affectedParameter() const + { + return m_affectedParameter; + } + +protected: + virtual bool affectParticle(QQuickParticleData *d, qreal dt); +signals: + + void xVarianceChanged(qreal arg); + + void yVarianceChanged(qreal arg); + + void paceChanged(qreal arg); + + + void affectedParameterChanged(AffectableParameters arg); + +public slots: +void setXVariance(qreal arg) +{ + if (m_xVariance != arg) { + m_xVariance = arg; + emit xVarianceChanged(arg); + } +} + +void setYVariance(qreal arg) +{ + if (m_yVariance != arg) { + m_yVariance = arg; + emit yVarianceChanged(arg); + } +} + +void setPace(qreal arg) +{ + if (m_pace != arg) { + m_pace = arg; + emit paceChanged(arg); + } +} + + +void setAffectedParameter(AffectableParameters arg) +{ + if (m_affectedParameter != arg) { + m_affectedParameter = arg; + emit affectedParameterChanged(arg); + } +} + +private: + WanderData* getData(int idx); + QHash m_wanderData; + qreal m_xVariance; + qreal m_yVariance; + qreal m_pace; + AffectableParameters m_affectedParameter; +}; + +QT_END_NAMESPACE +QT_END_HEADER +#endif // WANDERAFFECTOR_H diff --git a/src/declarative/particles/qsgage.cpp b/src/declarative/particles/qsgage.cpp deleted file mode 100644 index 797dd14f35..0000000000 --- a/src/declarative/particles/qsgage.cpp +++ /dev/null @@ -1,112 +0,0 @@ -/**************************************************************************** -** -** 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 "qsgage_p.h" -#include "qsgparticleemitter_p.h" -QT_BEGIN_NAMESPACE -/*! - \qmlclass Age QSGAgeAffector - \inqmlmodule QtQuick.Particles 2 - \inherits Affector - \brief The Age affector allows you to prematurely age particles - - The Age affector allows you to alter where the particle is in its lifecycle. Common uses - are to expire particles prematurely, possibly giving them time to animate out. - - The Age affector only applies to particles which are still alive. -*/ -/*! - \qmlproperty int QtQuick.Particles2::Age::lifeLeft - - The amount of life to set the particle to have. Affected particles - will advance to a point in their life where they will have this many - milliseconds left to live. -*/ - -/*! - \qmlproperty bool QtQuick.Particles2::Age::advancePosition - - advancePosition determines whether position, veclocity and acceleration are included in - the simulated aging done by the affector. If advancePosition is false, - then the position, velocity and acceleration will remain the same and only - other attributes (such as opacity) will advance in the simulation to where - it would normally be for that point in the particle's life. With advancePosition set to - true the position, velocity and acceleration will also advance to where it would - normally be by that point in the particle's life, making it advance its position - on screen. - - Default value is true. -*/ - -QSGAgeAffector::QSGAgeAffector(QQuickItem *parent) : - QSGParticleAffector(parent), m_lifeLeft(0), m_advancePosition(true) -{ -} - - -bool QSGAgeAffector::affectParticle(QSGParticleData *d, qreal dt) -{ - Q_UNUSED(dt); - if (d->stillAlive()){ - qreal curT = (qreal)m_system->timeInt/1000.0; - qreal ttl = (qreal)m_lifeLeft/1000.0; - if (!m_advancePosition && ttl > 0){ - qreal x = d->curX(); - qreal vx = d->curVX(); - qreal ax = d->curAX(); - qreal y = d->curY(); - qreal vy = d->curVY(); - qreal ay = d->curAY(); - d->t = curT - (d->lifeSpan - ttl); - d->setInstantaneousX(x); - d->setInstantaneousVX(vx); - d->setInstantaneousAX(ax); - d->setInstantaneousY(y); - d->setInstantaneousVY(vy); - d->setInstantaneousAY(ay); - } else { - d->t = curT - (d->lifeSpan - ttl); - } - return true; - } - return false; -} -QT_END_NAMESPACE diff --git a/src/declarative/particles/qsgage_p.h b/src/declarative/particles/qsgage_p.h deleted file mode 100644 index 63ec8f7592..0000000000 --- a/src/declarative/particles/qsgage_p.h +++ /dev/null @@ -1,102 +0,0 @@ -/**************************************************************************** -** -** 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 KILLAFFECTOR_H -#define KILLAFFECTOR_H -#include "qsgparticleaffector_p.h" - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - - -class QSGAgeAffector : public QSGParticleAffector -{ - Q_OBJECT - Q_PROPERTY(int lifeLeft READ lifeLeft WRITE setLifeLeft NOTIFY lifeLeftChanged) - Q_PROPERTY(bool advancePosition READ advancePosition WRITE setAdvancePosition NOTIFY advancePositionChanged) - -public: - explicit QSGAgeAffector(QQuickItem *parent = 0); - - int lifeLeft() const - { - return m_lifeLeft; - } - - bool advancePosition() const - { - return m_advancePosition; - } - -protected: - virtual bool affectParticle(QSGParticleData *d, qreal dt); -signals: - void lifeLeftChanged(int arg); - void advancePositionChanged(bool arg); - -public slots: - void setLifeLeft(int arg) - { - if (m_lifeLeft != arg) { - m_lifeLeft = arg; - emit lifeLeftChanged(arg); - } - } - - void setAdvancePosition(bool arg) - { - if (m_advancePosition != arg) { - m_advancePosition = arg; - emit advancePositionChanged(arg); - } - } - -private: - int m_lifeLeft; - bool m_advancePosition; -}; - -QT_END_NAMESPACE -QT_END_HEADER -#endif // KILLAFFECTOR_H diff --git a/src/declarative/particles/qsgangledirection.cpp b/src/declarative/particles/qsgangledirection.cpp deleted file mode 100644 index b2fb6b2fb8..0000000000 --- a/src/declarative/particles/qsgangledirection.cpp +++ /dev/null @@ -1,116 +0,0 @@ -/**************************************************************************** -** -** 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 "qsgangledirection_p.h" -#include -QT_BEGIN_NAMESPACE -const qreal CONV = 0.017453292519943295; -/*! - \qmlclass AngleDirection QSGAngleDirection - \inqmlmodule QtQuick.Particles 2 - \inherits Direction - \brief The AngleDirection element allows you to specify a direction that varies in angle - - The AngledDirection element allows both the specification of a direction by angle and magnitude, - as well as varying the parameters by angle or magnitude. -*/ -/*! - \qmlproperty real QtQuick.Particles2::AngleDirection::angle - This property specifies the base angle for the direction. - The angle of this direction will vary by no more than angleVariation - from this angle. - - Angle is specified by degrees clockwise from straight right. - - The default value is zero. -*/ -/*! - \qmlproperty real QtQuick.Particles2::AngleDirection::magnitude - This property specifies the base magnitude for the direction. - The magnitude of this direction will vary by no more than magnitudeVariation - from this magnitude. - - Magnitude is specified in units of pixels per second. - - The default value is zero. -*/ -/*! - \qmlproperty real QtQuick.Particles2::AngleDirection::angleVariation - This property specifies the maximum angle variation for the direction. - The angle of the direction will vary by up to angleVariation clockwise - and anticlockwise from the value specified in angle. - - Angle is specified by degrees clockwise from straight right. - - The default value is zero. -*/ -/*! - \qmlproperty real QtQuick.Particles2::AngleDirection::magnitudeVariation - This property specifies the base magnitude for the direction. - The magnitude of this direction will vary by no more than magnitudeVariation - from the base magnitude. - - Magnitude is specified in units of pixels per second. - - The default value is zero. -*/ -QSGAngleDirection::QSGAngleDirection(QObject *parent) : - QSGDirection(parent) - , m_angle(0) - , m_magnitude(0) - , m_angleVariation(0) - , m_magnitudeVariation(0) -{ - -} - -const QPointF QSGAngleDirection::sample(const QPointF &from) -{ - Q_UNUSED(from); - QPointF ret; - qreal theta = m_angle*CONV - m_angleVariation*CONV + rand()/float(RAND_MAX) * m_angleVariation*CONV * 2; - qreal mag = m_magnitude- m_magnitudeVariation + rand()/float(RAND_MAX) * m_magnitudeVariation * 2; - ret.setX(mag * cos(theta)); - ret.setY(mag * sin(theta)); - return ret; -} - -QT_END_NAMESPACE diff --git a/src/declarative/particles/qsgangledirection_p.h b/src/declarative/particles/qsgangledirection_p.h deleted file mode 100644 index b68d751fd8..0000000000 --- a/src/declarative/particles/qsgangledirection_p.h +++ /dev/null @@ -1,133 +0,0 @@ -/**************************************************************************** -** -** 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 QSGANGLEDDIRECTION_H -#define QSGANGLEDDIRECTION_H -#include "qsgdirection_p.h" -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QSGAngleDirection : public QSGDirection -{ - Q_OBJECT - Q_PROPERTY(qreal angle READ angle WRITE setAngle NOTIFY angleChanged) - Q_PROPERTY(qreal magnitude READ magnitude WRITE setMagnitude NOTIFY magnitudeChanged) - Q_PROPERTY(qreal angleVariation READ angleVariation WRITE setAngleVariation NOTIFY angleVariationChanged) - Q_PROPERTY(qreal magnitudeVariation READ magnitudeVariation WRITE setMagnitudeVariation NOTIFY magnitudeVariationChanged) -public: - explicit QSGAngleDirection(QObject *parent = 0); - const QPointF sample(const QPointF &from); - qreal angle() const - { - return m_angle; - } - - qreal magnitude() const - { - return m_magnitude; - } - - qreal angleVariation() const - { - return m_angleVariation; - } - - qreal magnitudeVariation() const - { - return m_magnitudeVariation; - } - -signals: - - void angleChanged(qreal arg); - - void magnitudeChanged(qreal arg); - - void angleVariationChanged(qreal arg); - - void magnitudeVariationChanged(qreal arg); - -public slots: -void setAngle(qreal arg) -{ - if (m_angle != arg) { - m_angle = arg; - emit angleChanged(arg); - } -} - -void setMagnitude(qreal arg) -{ - if (m_magnitude != arg) { - m_magnitude = arg; - emit magnitudeChanged(arg); - } -} - -void setAngleVariation(qreal arg) -{ - if (m_angleVariation != arg) { - m_angleVariation = arg; - emit angleVariationChanged(arg); - } -} - -void setMagnitudeVariation(qreal arg) -{ - if (m_magnitudeVariation != arg) { - m_magnitudeVariation = arg; - emit magnitudeVariationChanged(arg); - } -} - -private: -qreal m_angle; -qreal m_magnitude; -qreal m_angleVariation; -qreal m_magnitudeVariation; -}; - -QT_END_NAMESPACE -QT_END_HEADER -#endif // QSGANGLEDDIRECTION_H diff --git a/src/declarative/particles/qsgcumulativedirection.cpp b/src/declarative/particles/qsgcumulativedirection.cpp deleted file mode 100644 index f2bfea3acb..0000000000 --- a/src/declarative/particles/qsgcumulativedirection.cpp +++ /dev/null @@ -1,70 +0,0 @@ -/**************************************************************************** -** -** 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 "qsgcumulativedirection_p.h" -QT_BEGIN_NAMESPACE - -/*! - \qmlclass CumulativeDirection QSGCumulativeDirection - \inqmlmodule QtQuick.Particles 2 - \inherits Direction - \brief The CumulativeDirection element allows you to specify a direction made of other directions - - The CumulativeDirection element will act as a direction that sums the directions within it. -*/ -QSGCumulativeDirection::QSGCumulativeDirection(QObject *parent):QSGDirection(parent) -{ -} - -QDeclarativeListProperty QSGCumulativeDirection::directions() -{ - return QDeclarativeListProperty(this, m_directions);//TODO: Proper list property -} - -const QPointF QSGCumulativeDirection::sample(const QPointF &from) -{ - QPointF ret; - foreach (QSGDirection* dir, m_directions) - ret += dir->sample(from); - return ret; -} - -QT_END_NAMESPACE diff --git a/src/declarative/particles/qsgcumulativedirection_p.h b/src/declarative/particles/qsgcumulativedirection_p.h deleted file mode 100644 index 651e21ae65..0000000000 --- a/src/declarative/particles/qsgcumulativedirection_p.h +++ /dev/null @@ -1,69 +0,0 @@ -/**************************************************************************** -** -** 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 QSGCUMULATIVEDIRECTION_P_H -#define QSGCUMULATIVEDIRECTION_P_H -#include "qsgdirection_p.h" -#include -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QSGCumulativeDirection : public QSGDirection -{ - Q_OBJECT - Q_PROPERTY(QDeclarativeListProperty directions READ directions) - Q_CLASSINFO("DefaultProperty", "directions") -public: - explicit QSGCumulativeDirection(QObject *parent = 0); - QDeclarativeListProperty directions(); - const QPointF sample(const QPointF &from); -private: - QList m_directions; -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QSGCUMULATIVEDIRECTION_P_H diff --git a/src/declarative/particles/qsgcustomaffector.cpp b/src/declarative/particles/qsgcustomaffector.cpp deleted file mode 100644 index e8a1507e99..0000000000 --- a/src/declarative/particles/qsgcustomaffector.cpp +++ /dev/null @@ -1,211 +0,0 @@ -/**************************************************************************** -** -** 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 "qsgcustomaffector_p.h" -#include -#include -#include -#include -QT_BEGIN_NAMESPACE - -//TODO: Move docs (and inheritence) to real base when docs can propagate. Currently this pretends to be the base class! -/*! - \qmlsignal QtQuick.Particles2::Affector::affectParticles(Array particles, real dt) - - This handler is called when particles are selected to be affected. particles contains - an array of particle objects which can be directly manipulated. - - dt is the time since the last time it was affected. Use dt to normalize - trajectory manipulations to real time. - - Note that JS is slower to execute, so it is not recommended to use this in - high-volume particle systems. -*/ - -/*! - \qmlproperty StochasticDirection QtQuick.Particles2::Affector::position - - Affected particles will have their position set to this direction, - relative to the ParticleSystem. When interpreting directions as points, - imagine it as an arrow with the base at the 0,0 of the ParticleSystem and the - tip at where the specified position will be. -*/ - -/*! - \qmlproperty StochasticDirection QtQuick.Particles2::Affector::speed - - Affected particles will have their speed set to this direction. -*/ - - -/*! - \qmlproperty StochasticDirection QtQuick.Particles2::Affector::acceleration - - Affected particles will have their acceleration set to this direction. -*/ - - -/*! - \qmlproperty bool QtQuick.Particles2::Affector::relative - - Whether the affected particles have their existing position/speed/acceleration added - to the new one. - - Default is true. -*/ -QSGCustomAffector::QSGCustomAffector(QQuickItem *parent) : - QSGParticleAffector(parent) - , m_position(&m_nullVector) - , m_speed(&m_nullVector) - , m_acceleration(&m_nullVector) - , m_relative(true) -{ -} - -bool QSGCustomAffector::isAffectConnected() -{ - static int idx = QObjectPrivate::get(this)->signalIndex("affectParticles(QDeclarativeV8Handle,qreal)"); - return QObjectPrivate::get(this)->isSignalConnected(idx); -} - -void QSGCustomAffector::affectSystem(qreal dt) -{ - if (!isAffectConnected()) { - QSGParticleAffector::affectSystem(dt); - return; - } - if (!m_enabled) - return; - updateOffsets(); - - QList toAffect; - foreach (QSGParticleGroupData* gd, m_system->groupData) - if (activeGroup(m_system->groupData.key(gd))) - foreach (QSGParticleData* d, gd->data) - if (shouldAffect(d)) - toAffect << d; - - if (toAffect.isEmpty()) - return; - - if (m_onceOff) - dt = 1.0; - - v8::HandleScope handle_scope; - v8::Context::Scope scope(QDeclarativeEnginePrivate::getV8Engine(qmlEngine(this))->context()); - v8::Handle array = v8::Array::New(toAffect.size()); - for (int i=0; iSet(i, toAffect[i]->v8Value().toHandle()); - - if (dt >= simulationCutoff || dt <= simulationDelta) { - affectProperties(toAffect, dt); - emit affectParticles(QDeclarativeV8Handle::fromHandle(array), dt); - } else { - int realTime = m_system->timeInt; - m_system->timeInt -= dt * 1000.0; - while (dt > simulationDelta) { - m_system->timeInt += simulationDelta * 1000.0; - dt -= simulationDelta; - affectProperties(toAffect, simulationDelta); - emit affectParticles(QDeclarativeV8Handle::fromHandle(array), simulationDelta); - } - m_system->timeInt = realTime; - if (dt > 0.0) { - affectProperties(toAffect, dt); - emit affectParticles(QDeclarativeV8Handle::fromHandle(array), dt); - } - } - - foreach (QSGParticleData* d, toAffect) - if (d->update == 1.0) - postAffect(d); -} - -bool QSGCustomAffector::affectParticle(QSGParticleData *d, qreal dt) -{ - //This does the property based affecting, called by superclass if signal isn't hooked up. - bool changed = false; - QPointF curPos(d->curX(), d->curY()); - - if (m_acceleration != &m_nullVector){ - QPointF pos = m_acceleration->sample(curPos); - if (m_relative) { - pos *= dt; - pos += QPointF(d->curAX(), d->curAY()); - } - d->setInstantaneousAX(pos.x()); - d->setInstantaneousAY(pos.y()); - changed = true; - } - - if (m_speed != &m_nullVector){ - QPointF pos = m_speed->sample(curPos); - if (m_relative) { - pos *= dt; - pos += QPointF(d->curVX(), d->curVY()); - } - d->setInstantaneousVX(pos.x()); - d->setInstantaneousVY(pos.y()); - changed = true; - } - - if (m_position != &m_nullVector){ - QPointF pos = m_position->sample(curPos); - if (m_relative) { - pos *= dt; - pos += curPos; - } - d->setInstantaneousX(pos.x()); - d->setInstantaneousY(pos.y()); - changed = true; - } - - return changed; -} - -void QSGCustomAffector::affectProperties(const QList particles, qreal dt) -{ - foreach (QSGParticleData* d, particles) - if ( affectParticle(d, dt) ) - d->update = 1.0; -} - -QT_END_NAMESPACE diff --git a/src/declarative/particles/qsgcustomaffector_p.h b/src/declarative/particles/qsgcustomaffector_p.h deleted file mode 100644 index ed711b6c95..0000000000 --- a/src/declarative/particles/qsgcustomaffector_p.h +++ /dev/null @@ -1,164 +0,0 @@ -/**************************************************************************** -** -** 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 CUSTOMAFFECTOR_H -#define CUSTOMAFFECTOR_H - -#include -#include "qsgparticlesystem_p.h" -#include "qsgparticleextruder_p.h" -#include "qsgparticleaffector_p.h" -#include "qsgdirection_p.h" - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QSGCustomAffector : public QSGParticleAffector -{ - Q_OBJECT - Q_PROPERTY(bool relative READ relative WRITE setRelative NOTIFY relativeChanged) - Q_PROPERTY(QSGDirection *position READ position WRITE setPosition NOTIFY positionChanged RESET positionReset) - Q_PROPERTY(QSGDirection *speed READ speed WRITE setSpeed NOTIFY speedChanged RESET speedReset) - Q_PROPERTY(QSGDirection *acceleration READ acceleration WRITE setAcceleration NOTIFY accelerationChanged RESET accelerationReset) - -public: - explicit QSGCustomAffector(QQuickItem *parent = 0); - virtual void affectSystem(qreal dt); - - QSGDirection * position() const - { - return m_position; - } - - QSGDirection * speed() const - { - return m_speed; - } - - QSGDirection * acceleration() const - { - return m_acceleration; - } - - void positionReset() - { - m_position = &m_nullVector; - } - - void speedReset() - { - m_speed = &m_nullVector; - } - - void accelerationReset() - { - m_acceleration = &m_nullVector; - } - - bool relative() const - { - return m_relative; - } - - -signals: - void affectParticles(QDeclarativeV8Handle particles, qreal dt); - - void positionChanged(QSGDirection * arg); - - void speedChanged(QSGDirection * arg); - - void accelerationChanged(QSGDirection * arg); - - void relativeChanged(bool arg); - -public slots: - void setPosition(QSGDirection * arg) - { - if (m_position != arg) { - m_position = arg; - emit positionChanged(arg); - } - } - - void setSpeed(QSGDirection * arg) - { - if (m_speed != arg) { - m_speed = arg; - emit speedChanged(arg); - } - } - - void setAcceleration(QSGDirection * arg) - { - if (m_acceleration != arg) { - m_acceleration = arg; - emit accelerationChanged(arg); - } - } - - void setRelative(bool arg) - { - if (m_relative != arg) { - m_relative = arg; - emit relativeChanged(arg); - } - } - -protected: - bool isAffectConnected(); - virtual bool affectParticle(QSGParticleData *d, qreal dt); -private: - void affectProperties(const QList particles, qreal dt); - QSGDirection * m_position; - QSGDirection * m_speed; - QSGDirection * m_acceleration; - - QSGDirection m_nullVector; - bool m_relative; -}; - -QT_END_NAMESPACE -QT_END_HEADER -#endif // CUSTOMAFFECTOR_H diff --git a/src/declarative/particles/qsgcustomparticle.cpp b/src/declarative/particles/qsgcustomparticle.cpp deleted file mode 100644 index d00f6bbdda..0000000000 --- a/src/declarative/particles/qsgcustomparticle.cpp +++ /dev/null @@ -1,596 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtDeclarative 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 "qsgcustomparticle_p.h" -#include -#include - -QT_BEGIN_NAMESPACE - -//Includes comments because the code isn't self explanatory -static const char qt_particles_template_vertex_code[] = - "attribute highp vec2 qt_ParticlePos;\n" - "attribute highp vec2 qt_ParticleTex;\n" - "attribute highp vec4 qt_ParticleData; // x = time, y = lifeSpan, z = size, w = endSize\n" - "attribute highp vec4 qt_ParticleVec; // x,y = constant speed, z,w = acceleration\n" - "attribute highp float qt_ParticleR;\n" - "uniform highp mat4 qt_Matrix;\n" - "uniform highp float qt_Timestamp;\n" - "varying highp vec2 qt_TexCoord0;\n" - "void defaultMain() {\n" - " qt_TexCoord0 = qt_ParticleTex;\n" - " highp float size = qt_ParticleData.z;\n" - " highp float endSize = qt_ParticleData.w;\n" - " highp float t = (qt_Timestamp - qt_ParticleData.x) / qt_ParticleData.y;\n" - " highp float currentSize = mix(size, endSize, t * t);\n" - " if (t < 0. || t > 1.)\n" - " currentSize = 0.;\n" - " highp vec2 pos = qt_ParticlePos\n" - " - currentSize / 2. + currentSize * qt_ParticleTex // adjust size\n" - " + qt_ParticleVec.xy * t * qt_ParticleData.y // apply speed vector..\n" - " + 0.5 * qt_ParticleVec.zw * pow(t * qt_ParticleData.y, 2.);\n" - " gl_Position = qt_Matrix * vec4(pos.x, pos.y, 0, 1);\n" - "}"; -static const char qt_particles_default_vertex_code[] = - "void main() { \n" - " defaultMain(); \n" - "}"; - -static const char qt_particles_default_fragment_code[] = - "uniform sampler2D source; \n" - "varying highp vec2 qt_TexCoord0; \n" - "uniform lowp float qt_Opacity; \n" - "void main() { \n" - " gl_FragColor = texture2D(source, qt_TexCoord0) * qt_Opacity; \n" - "}"; - -static QSGGeometry::Attribute PlainParticle_Attributes[] = { - QSGGeometry::Attribute::create(0, 2, GL_FLOAT, true), // Position - QSGGeometry::Attribute::create(1, 2, GL_FLOAT), // TexCoord - QSGGeometry::Attribute::create(2, 4, GL_FLOAT), // Data - QSGGeometry::Attribute::create(3, 4, GL_FLOAT), // Vectors - QSGGeometry::Attribute::create(4, 1, GL_FLOAT) // r -}; - -static QSGGeometry::AttributeSet PlainParticle_AttributeSet = -{ - 5, // Attribute Count - (2 + 2 + 4 + 4 + 1) * sizeof(float), - PlainParticle_Attributes -}; - -struct PlainVertex { - float x; - float y; - float tx; - float ty; - float t; - float lifeSpan; - float size; - float endSize; - float vx; - float vy; - float ax; - float ay; - float r; -}; - -struct PlainVertices { - PlainVertex v1; - PlainVertex v2; - PlainVertex v3; - PlainVertex v4; -}; - -/*! - \qmlclass CustomParticle QSGCustomParticle - \inqmlmodule QtQuick.Particles 2 - \inherits ParticlePainter - \brief The CustomParticle element allows you to specify your own shader to paint particles. - -*/ - -QSGCustomParticle::QSGCustomParticle(QQuickItem* parent) - : QSGParticlePainter(parent) - , m_dirtyData(true) - , m_material(0) - , m_rootNode(0) -{ - setFlag(QQuickItem::ItemHasContents); -} - -class QSGShaderEffectMaterialObject : public QObject, public QQuickShaderEffectMaterial { }; - -QSGCustomParticle::~QSGCustomParticle() -{ - if (m_material) - m_material->deleteLater(); -} - -void QSGCustomParticle::componentComplete() -{ - reset(); - QSGParticlePainter::componentComplete(); -} - - -//Trying to keep the shader conventions the same as in qsgshadereffectitem -/*! - \qmlproperty string QtQuick.Particles2::CustomParticle::fragmentShader - - This property holds the fragment shader's GLSL source code. - The default shader expects the texture coordinate to be passed from the - vertex shader as "varying highp vec2 qt_TexCoord0", and it samples from a - sampler2D named "source". -*/ - -void QSGCustomParticle::setFragmentShader(const QByteArray &code) -{ - if (m_source.fragmentCode.constData() == code.constData()) - return; - m_source.fragmentCode = code; - if (isComponentComplete()) { - reset(); - } - emit fragmentShaderChanged(); -} - -/*! - \qmlproperty string QtQuick.Particles2::CustomParticle::vertexShader - - This property holds the vertex shader's GLSL source code. - - The default shader passes the texture coordinate along to the fragment - shader as "varying highp vec2 qt_TexCoord0". - - To aid writing a particle vertex shader, the following GLSL code is prepended - to your vertex shader: - \code - attribute highp vec2 qt_ParticlePos; - attribute highp vec2 qt_ParticleTex; - attribute highp vec4 qt_ParticleData; // x = time, y = lifeSpan, z = size, w = endSize - attribute highp vec4 qt_ParticleVec; // x,y = constant speed, z,w = acceleration - attribute highp float qt_ParticleR; - uniform highp mat4 qt_Matrix; - uniform highp float qt_Timestamp; - varying highp vec2 qt_TexCoord0; - void defaultMain() { - qt_TexCoord0 = qt_ParticleTex; - highp float size = qt_ParticleData.z; - highp float endSize = qt_ParticleData.w; - highp float t = (qt_Timestamp - qt_ParticleData.x) / qt_ParticleData.y; - highp float currentSize = mix(size, endSize, t * t); - if (t < 0. || t > 1.) - currentSize = 0.; - highp vec2 pos = qt_ParticlePos - - currentSize / 2. + currentSize * qt_ParticleTex // adjust size - + qt_ParticleVec.xy * t * qt_ParticleData.y // apply speed vector.. - + 0.5 * qt_ParticleVec.zw * pow(t * qt_ParticleData.y, 2.); - gl_Position = qt_Matrix * vec4(pos.x, pos.y, 0, 1); - } - \endcode - - defaultMain() is the same code as in the default shader, you can call this for basic - particle functions and then add additional variables for custom effects. Note that - the vertex shader for particles is responsible for simulating the movement of particles - over time, the particle data itself only has the starting position and spawn time. -*/ - -void QSGCustomParticle::setVertexShader(const QByteArray &code) -{ - if (m_source.vertexCode.constData() == code.constData()) - return; - m_source.vertexCode = code; - if (isComponentComplete()) { - reset(); - } - emit vertexShaderChanged(); -} - -void QSGCustomParticle::reset() -{ - disconnectPropertySignals(); - - m_source.attributeNames.clear(); - m_source.uniformNames.clear(); - m_source.respectsOpacity = false; - m_source.respectsMatrix = false; - m_source.className = metaObject()->className(); - - for (int i = 0; i < m_sources.size(); ++i) { - const SourceData &source = m_sources.at(i); - delete source.mapper; - if (source.item && source.item->parentItem() == this) - source.item->setParentItem(0); - } - m_sources.clear(); - - QSGParticlePainter::reset(); - m_pleaseReset = true; - update(); -} - - -void QSGCustomParticle::changeSource(int index) -{ - Q_ASSERT(index >= 0 && index < m_sources.size()); - QVariant v = property(m_sources.at(index).name.constData()); - setSource(v, index); -} - -void QSGCustomParticle::updateData() -{ - m_dirtyData = true; - update(); -} - -void QSGCustomParticle::setSource(const QVariant &var, int index) -{ - Q_ASSERT(index >= 0 && index < m_sources.size()); - - SourceData &source = m_sources[index]; - - source.item = 0; - if (var.isNull()) { - return; - } else if (!qVariantCanConvert(var)) { - qWarning("Could not assign source of type '%s' to property '%s'.", var.typeName(), source.name.constData()); - return; - } - - QObject *obj = qVariantValue(var); - source.item = qobject_cast(obj); - if (!source.item || !source.item->isTextureProvider()) { - qWarning("ShaderEffect: source uniform [%s] is not assigned a valid texture provider: %s [%s]", - source.name.constData(), qPrintable(obj->objectName()), obj->metaObject()->className()); - return; - } - - // TODO: Copy better solution in QSGShaderEffect when they find it. - // 'source.item' needs a canvas to get a scenegraph node. - // The easiest way to make sure it gets a canvas is to - // make it a part of the same item tree as 'this'. - if (source.item && source.item->parentItem() == 0) { - source.item->setParentItem(this); - source.item->setVisible(false); - } -} - -void QSGCustomParticle::disconnectPropertySignals() -{ - disconnect(this, 0, this, SLOT(updateData())); - for (int i = 0; i < m_sources.size(); ++i) { - SourceData &source = m_sources[i]; - disconnect(this, 0, source.mapper, 0); - disconnect(source.mapper, 0, this, 0); - } -} - -void QSGCustomParticle::connectPropertySignals() -{ - QSet::const_iterator it; - for (it = m_source.uniformNames.begin(); it != m_source.uniformNames.end(); ++it) { - int pi = metaObject()->indexOfProperty(it->constData()); - if (pi >= 0) { - QMetaProperty mp = metaObject()->property(pi); - if (!mp.hasNotifySignal()) - qWarning("QSGCustomParticle: property '%s' does not have notification method!", it->constData()); - QByteArray signalName("2"); - signalName.append(mp.notifySignal().signature()); - connect(this, signalName, this, SLOT(updateData())); - } else { - qWarning("QSGCustomParticle: '%s' does not have a matching property!", it->constData()); - } - } - for (int i = 0; i < m_sources.size(); ++i) { - SourceData &source = m_sources[i]; - int pi = metaObject()->indexOfProperty(source.name.constData()); - if (pi >= 0) { - QMetaProperty mp = metaObject()->property(pi); - QByteArray signalName("2"); - signalName.append(mp.notifySignal().signature()); - connect(this, signalName, source.mapper, SLOT(map())); - source.mapper->setMapping(this, i); - connect(source.mapper, SIGNAL(mapped(int)), this, SLOT(changeSource(int))); - } else { - qWarning("QSGCustomParticle: '%s' does not have a matching source!", source.name.constData()); - } - } -} - -void QSGCustomParticle::updateProperties() -{ - QByteArray vertexCode = m_source.vertexCode; - QByteArray fragmentCode = m_source.fragmentCode; - if (vertexCode.isEmpty()) - vertexCode = qt_particles_default_vertex_code; - if (fragmentCode.isEmpty()) - fragmentCode = qt_particles_default_fragment_code; - vertexCode = qt_particles_template_vertex_code + vertexCode; - - m_source.attributeNames.clear(); - m_source.attributeNames << "qt_ParticlePos" - << "qt_ParticleTex" - << "qt_ParticleData" - << "qt_ParticleVec" - << "qt_ParticleR"; - - lookThroughShaderCode(vertexCode); - lookThroughShaderCode(fragmentCode); - - if (!m_source.respectsMatrix) - qWarning("QSGCustomParticle: Missing reference to \'qt_Matrix\'."); - if (!m_source.respectsOpacity) - qWarning("QSGCustomParticle: Missing reference to \'qt_Opacity\'."); - - for (int i = 0; i < m_sources.size(); ++i) { - QVariant v = property(m_sources.at(i).name); - setSource(v, i); - } - - connectPropertySignals(); -} - -void QSGCustomParticle::lookThroughShaderCode(const QByteArray &code) -{ - // Regexp for matching attributes and uniforms. - // In human readable form: attribute|uniform [lowp|mediump|highp] - static QRegExp re(QLatin1String("\\b(attribute|uniform)\\b\\s*\\b(?:lowp|mediump|highp)?\\b\\s*\\b(\\w+)\\b\\s*\\b(\\w+)")); - Q_ASSERT(re.isValid()); - - int pos = -1; - - QString wideCode = QString::fromLatin1(code.constData(), code.size()); - - while ((pos = re.indexIn(wideCode, pos + 1)) != -1) { - QByteArray decl = re.cap(1).toLatin1(); // uniform or attribute - QByteArray type = re.cap(2).toLatin1(); // type - QByteArray name = re.cap(3).toLatin1(); // variable name - - if (decl == "attribute") { - if (!m_source.attributeNames.contains(name)) - qWarning() << "Custom Particle: Unknown attribute " << name; - } else { - Q_ASSERT(decl == "uniform");//TODO: Shouldn't assert - - if (name == "qt_Matrix") { - m_source.respectsMatrix = true; - } else if (name == "qt_Opacity") { - m_source.respectsOpacity = true; - } else if (name == "qt_Timestamp") { - //Not strictly necessary - } else { - m_source.uniformNames.insert(name); - if (type == "sampler2D") { - SourceData d; - d.mapper = new QSignalMapper; - d.name = name; - d.item = 0; - m_sources.append(d); - } - } - } - } -} - -QSGNode *QSGCustomParticle::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) -{ - Q_UNUSED(oldNode); - if (m_pleaseReset){ - - //delete m_material;//Shader effect item doesn't regen material? - - delete m_rootNode;//Automatically deletes children - m_rootNode = 0; - m_nodes.clear(); - m_pleaseReset = false; - m_dirtyData = false; - } - - if (m_system && m_system->isRunning() && !m_system->isPaused()){ - prepareNextFrame(); - if (m_rootNode) { - update(); - foreach (QSGGeometryNode* node, m_nodes) - node->markDirty(QSGNode::DirtyGeometry);//done in buildData? - } - } - - return m_rootNode; -} - -void QSGCustomParticle::prepareNextFrame(){ - if (!m_rootNode) - m_rootNode = buildCustomNodes(); - if (!m_rootNode) - return; - - m_lastTime = m_system->systemSync(this) / 1000.; - if (m_dirtyData || true)//Currently this is how we update timestamp... potentially over expensive. - buildData(); -} - -QQuickShaderEffectNode* QSGCustomParticle::buildCustomNodes() -{ -#ifdef QT_OPENGL_ES_2 - if (m_count * 4 > 0xffff) { - printf("CustomParticle: Too many particles... \n"); - return 0; - } -#endif - - if (m_count <= 0) { - printf("CustomParticle: Too few particles... \n"); - return 0; - } - - updateProperties(); - - QQuickShaderEffectProgram s = m_source; - if (s.fragmentCode.isEmpty()) - s.fragmentCode = qt_particles_default_fragment_code; - if (s.vertexCode.isEmpty()) - s.vertexCode = qt_particles_default_vertex_code; - - if (!m_material) { - m_material = new QSGShaderEffectMaterialObject; - } - - s.vertexCode = qt_particles_template_vertex_code + s.vertexCode; - m_material->setProgramSource(s); - foreach (const QString &str, m_groups){ - int gIdx = m_system->groupIds[str]; - int count = m_system->groupData[gIdx]->size(); - - QQuickShaderEffectNode* node = new QQuickShaderEffectNode(); - m_nodes.insert(gIdx, node); - - node->setMaterial(m_material); - node->markDirty(QSGNode::DirtyMaterial); - - //Create Particle Geometry - int vCount = count * 4; - int iCount = count * 6; - QSGGeometry *g = new QSGGeometry(PlainParticle_AttributeSet, vCount, iCount); - g->setDrawingMode(GL_TRIANGLES); - node->setGeometry(g); - PlainVertex *vertices = (PlainVertex *) g->vertexData(); - for (int p=0; p < count; ++p) { - commit(gIdx, p); - vertices[0].tx = 0; - vertices[0].ty = 0; - - vertices[1].tx = 1; - vertices[1].ty = 0; - - vertices[2].tx = 0; - vertices[2].ty = 1; - - vertices[3].tx = 1; - vertices[3].ty = 1; - vertices += 4; - } - quint16 *indices = g->indexDataAsUShort(); - for (int i=0; i < count; ++i) { - int o = i * 4; - indices[0] = o; - indices[1] = o + 1; - indices[2] = o + 2; - indices[3] = o + 1; - indices[4] = o + 3; - indices[5] = o + 2; - indices += 6; - } - } - foreach (QQuickShaderEffectNode* node, m_nodes){ - if (node == *(m_nodes.begin())) - continue; - (*(m_nodes.begin()))->appendChildNode(node); - } - - return *(m_nodes.begin()); -} - - -void QSGCustomParticle::buildData() -{ - if (!m_rootNode) - return; - const QByteArray timestampName("qt_Timestamp"); - QVector > values; - QVector > textures; - const QVector > &oldTextures = m_material->textureProviders(); - for (int i = 0; i < oldTextures.size(); ++i) { - QSGTextureProvider *t = oldTextures.at(i).second; - if (t) - foreach (QQuickShaderEffectNode* node, m_nodes) - disconnect(t, SIGNAL(textureChanged()), node, SLOT(markDirtyTexture())); - } - for (int i = 0; i < m_sources.size(); ++i) { - const SourceData &source = m_sources.at(i); - QSGTextureProvider *t = source.item->textureProvider(); - textures.append(qMakePair(source.name, t)); - if (t) - foreach (QQuickShaderEffectNode* node, m_nodes) - connect(t, SIGNAL(textureChanged()), node, SLOT(markDirtyTexture()), Qt::DirectConnection); - } - for (QSet::const_iterator it = m_source.uniformNames.begin(); - it != m_source.uniformNames.end(); ++it) { - values.append(qMakePair(*it, property(*it))); - } - values.append(qMakePair(timestampName, QVariant(m_lastTime))); - m_material->setUniforms(values); - m_material->setTextureProviders(textures); - m_dirtyData = false; - foreach (QQuickShaderEffectNode* node, m_nodes) - node->markDirty(QSGNode::DirtyMaterial); -} - -void QSGCustomParticle::initialize(int gIdx, int pIdx) -{ - QSGParticleData* datum = m_system->groupData[gIdx]->data[pIdx]; - datum->r = rand()/(qreal)RAND_MAX; -} - -void QSGCustomParticle::commit(int gIdx, int pIdx) -{ - if (m_nodes[gIdx] == 0) - return; - - QSGParticleData* datum = m_system->groupData[gIdx]->data[pIdx]; - PlainVertices *particles = (PlainVertices *) m_nodes[gIdx]->geometry()->vertexData(); - PlainVertex *vertices = (PlainVertex *)&particles[pIdx]; - for (int i=0; i<4; ++i) { - vertices[i].x = datum->x - m_systemOffset.x(); - vertices[i].y = datum->y - m_systemOffset.y(); - vertices[i].t = datum->t; - vertices[i].lifeSpan = datum->lifeSpan; - vertices[i].size = datum->size; - vertices[i].endSize = datum->endSize; - vertices[i].vx = datum->vx; - vertices[i].vy = datum->vy; - vertices[i].ax = datum->ax; - vertices[i].ay = datum->ay; - vertices[i].r = datum->r; - } -} - -QT_END_NAMESPACE diff --git a/src/declarative/particles/qsgcustomparticle_p.h b/src/declarative/particles/qsgcustomparticle_p.h deleted file mode 100644 index 271cc0a2a3..0000000000 --- a/src/declarative/particles/qsgcustomparticle_p.h +++ /dev/null @@ -1,121 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: Nokia Corporation (qt-info@nokia.com) -** -** This file is part of the QtDeclarative 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 CUSTOM_PARTICLE_H -#define CUSTOM_PARTICLE_H -#include "qsgparticlepainter_p.h" -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QSGNode; -struct PlainVertices; - -class QSGShaderEffectMaterialObject; - -//Genealogy: Hybrid of UltraParticle and ShaderEffect -class QSGCustomParticle : public QSGParticlePainter -{ - Q_OBJECT - Q_PROPERTY(QByteArray fragmentShader READ fragmentShader WRITE setFragmentShader NOTIFY fragmentShaderChanged) - Q_PROPERTY(QByteArray vertexShader READ vertexShader WRITE setVertexShader NOTIFY vertexShaderChanged) - -public: - explicit QSGCustomParticle(QQuickItem* parent=0); - ~QSGCustomParticle(); - - QByteArray fragmentShader() const { return m_source.fragmentCode; } - void setFragmentShader(const QByteArray &code); - - QByteArray vertexShader() const { return m_source.vertexCode; } - void setVertexShader(const QByteArray &code); -public Q_SLOTS: - void updateData(); - void changeSource(int); -Q_SIGNALS: - void fragmentShaderChanged(); - void vertexShaderChanged(); -protected: - virtual void initialize(int gIdx, int pIdx); - virtual void commit(int gIdx, int pIdx); - - QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *); - void prepareNextFrame(); - void setSource(const QVariant &var, int index); - void disconnectPropertySignals(); - void connectPropertySignals(); - void reset(); - void resize(int oldCount, int newCount); - void updateProperties(); - void lookThroughShaderCode(const QByteArray &code); - virtual void componentComplete(); - QQuickShaderEffectNode *buildCustomNodes(); - void performPendingResize(); - -private: - void buildData(); - - bool m_dirtyData; - QQuickShaderEffectProgram m_source; - struct SourceData - { - QSignalMapper *mapper; - QPointer item; - QByteArray name; - }; - QVector m_sources; - QSGShaderEffectMaterialObject *m_material; - QQuickShaderEffectNode* m_rootNode; - QHash m_nodes; - qreal m_lastTime; - -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif //HEADER_GUARD diff --git a/src/declarative/particles/qsgdirection.cpp b/src/declarative/particles/qsgdirection.cpp deleted file mode 100644 index eff4b56774..0000000000 --- a/src/declarative/particles/qsgdirection.cpp +++ /dev/null @@ -1,64 +0,0 @@ -/**************************************************************************** -** -** 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 "qsgdirection_p.h" - -QT_BEGIN_NAMESPACE -/*! - \qmlclass Direction QSGDirection - \inqmlmodule QtQuick.Particles 2 - \brief The Direction elements allow you to specify a vector space. - -*/ - - -QSGDirection::QSGDirection(QObject *parent) : - QObject(parent) -{ -} - -const QPointF QSGDirection::sample(const QPointF &from) -{ - Q_UNUSED(from); - return QPointF(); -} - -QT_END_NAMESPACE diff --git a/src/declarative/particles/qsgdirection_p.h b/src/declarative/particles/qsgdirection_p.h deleted file mode 100644 index a943145037..0000000000 --- a/src/declarative/particles/qsgdirection_p.h +++ /dev/null @@ -1,71 +0,0 @@ -/**************************************************************************** -** -** 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 VARYINGVECTOR_H -#define VARYINGVECTOR_H - -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - - -class QSGDirection : public QObject -{ - Q_OBJECT -public: - explicit QSGDirection(QObject *parent = 0); - - virtual const QPointF sample(const QPointF &from); -signals: - -public slots: - -protected: -}; - -QT_END_NAMESPACE -QT_END_HEADER -#endif // VARYINGVECTOR_H diff --git a/src/declarative/particles/qsgellipseextruder.cpp b/src/declarative/particles/qsgellipseextruder.cpp deleted file mode 100644 index 29fa3c8841..0000000000 --- a/src/declarative/particles/qsgellipseextruder.cpp +++ /dev/null @@ -1,80 +0,0 @@ -/**************************************************************************** -** -** 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 "qsgellipseextruder_p.h" -#include -QT_BEGIN_NAMESPACE -/*! - \qmlclass EllipseShape QSGEllipseExtruder - \inqmlmodule QtQuick.Particles 2 - \inherits Shape - \brief The EllipseShape represents an ellipse to other particle system elements - - This shape can be used by Emitter subclasses and Affector subclasses to have - them act upon an ellipse shaped area. -*/ -QSGEllipseExtruder::QSGEllipseExtruder(QObject *parent) : - QSGParticleExtruder(parent) - , m_fill(true) -{ -} - -/*! - \qmlproperty bool QtQuick.Particles2::EllipseShape::fill - If fill is true the ellipse is filled; otherwise it is just a border. - - Default is true. -*/ - -QPointF QSGEllipseExtruder::extrude(const QRectF & r) -{ - qreal theta = ((qreal)rand()/RAND_MAX) * 6.2831853071795862; - qreal mag = m_fill ? ((qreal)rand()/RAND_MAX) : 1; - return QPointF(r.x() + r.width()/2 + mag * (r.width()/2) * cos(theta), - r.y() + r.height()/2 + mag * (r.height()/2) * sin(theta)); -} - -bool QSGEllipseExtruder::contains(const QRectF &bounds, const QPointF &point) -{ - return bounds.contains(point);//TODO: Ellipse -} - -QT_END_NAMESPACE diff --git a/src/declarative/particles/qsgellipseextruder_p.h b/src/declarative/particles/qsgellipseextruder_p.h deleted file mode 100644 index d8e3f719a2..0000000000 --- a/src/declarative/particles/qsgellipseextruder_p.h +++ /dev/null @@ -1,86 +0,0 @@ -/**************************************************************************** -** -** 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 ELLIPSEEXTRUDER_H -#define ELLIPSEEXTRUDER_H -#include "qsgparticleextruder_p.h" - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - - -class QSGEllipseExtruder : public QSGParticleExtruder -{ - Q_OBJECT - Q_PROPERTY(bool fill READ fill WRITE setFill NOTIFY fillChanged)//###Use base class? If it's still box -public: - explicit QSGEllipseExtruder(QObject *parent = 0); - virtual QPointF extrude(const QRectF &); - virtual bool contains(const QRectF &bounds, const QPointF &point); - - bool fill() const - { - return m_fill; - } - -signals: - - void fillChanged(bool arg); - -public slots: - - void setFill(bool arg) - { - if (m_fill != arg) { - m_fill = arg; - emit fillChanged(arg); - } - } -private: - bool m_fill; -}; - -QT_END_NAMESPACE -QT_END_HEADER -#endif // ELLIPSEEXTRUDER_H diff --git a/src/declarative/particles/qsgfriction.cpp b/src/declarative/particles/qsgfriction.cpp deleted file mode 100644 index 9e32fc2c3e..0000000000 --- a/src/declarative/particles/qsgfriction.cpp +++ /dev/null @@ -1,111 +0,0 @@ -/**************************************************************************** -** -** 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 "qsgfriction_p.h" -QT_BEGIN_NAMESPACE -/*! - \qmlclass Friction QSGFrictionAffector - \inqmlmodule QtQuick.Particles 2 - \inherits Affector - \brief The Friction affector slows down movement proportional to the particle's current speed. - -*/ - -/*! - \qmlproperty real QtQuick.Particles2::Friction::factor - - A drag will be applied to moving objects which is this factor of their current velocity. -*/ -/*! - \qmlproperty real QtQuick.Particles2::Friction::threshold - - The drag will only be applied to objects with a velocity above the threshold velocity. The - drag applied will bring objects down to the threshold velocity, but no further. - - The default threshold is 0 -*/ -static qreal sign(qreal a) -{ - return a >= 0 ? 1 : -1; -} - -static const qreal epsilon = 0.00001; - -QSGFrictionAffector::QSGFrictionAffector(QQuickItem *parent) : - QSGParticleAffector(parent), m_factor(0.0), m_threshold(0.0) -{ -} - -bool QSGFrictionAffector::affectParticle(QSGParticleData *d, qreal dt) -{ - if (!m_factor) - return false; - qreal curVX = d->curVX(); - qreal curVY = d->curVY(); - if (!curVX && !curVY) - return false; - qreal newVX = curVX + (curVX * m_factor * -1 * dt); - qreal newVY = curVY + (curVY * m_factor * -1 * dt); - - if (!m_threshold) { - if (sign(curVX) != sign(newVX)) - newVX = 0; - if (sign(curVY) != sign(newVY)) - newVY = 0; - } else { - qreal curMag = sqrt(curVX*curVX + curVY*curVY); - if (curMag <= m_threshold + epsilon) - return false; - qreal newMag = sqrt(newVX*newVX + newVY*newVY); - if (newMag <= m_threshold + epsilon || //went past the threshold, stop there instead - sign(curVX) != sign(newVX) || //went so far past maybe it came out the other side! - sign(curVY) != sign(newVY)) { - qreal theta = atan2(curVY, curVX); - newVX = m_threshold * cos(theta); - newVY = m_threshold * sin(theta); - } - } - - d->setInstantaneousVX(newVX); - d->setInstantaneousVY(newVY); - return true; -} -QT_END_NAMESPACE diff --git a/src/declarative/particles/qsgfriction_p.h b/src/declarative/particles/qsgfriction_p.h deleted file mode 100644 index 9965b147aa..0000000000 --- a/src/declarative/particles/qsgfriction_p.h +++ /dev/null @@ -1,104 +0,0 @@ -/**************************************************************************** -** -** 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 FRICTIONAFFECTOR_H -#define FRICTIONAFFECTOR_H -#include "qsgparticleaffector_p.h" - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - - -class QSGFrictionAffector : public QSGParticleAffector -{ - Q_OBJECT - Q_PROPERTY(qreal factor READ factor WRITE setFactor NOTIFY factorChanged) - Q_PROPERTY(qreal threshold READ threshold WRITE setThreshold NOTIFY thresholdChanged) -public: - explicit QSGFrictionAffector(QQuickItem *parent = 0); - - qreal factor() const - { - return m_factor; - } - - qreal threshold() const - { - return m_threshold; - } - -protected: - virtual bool affectParticle(QSGParticleData *d, qreal dt); - -signals: - - void factorChanged(qreal arg); - void thresholdChanged(qreal arg); - -public slots: - - void setFactor(qreal arg) - { - if (m_factor != arg) { - m_factor = arg; - emit factorChanged(arg); - } - } - - void setThreshold(qreal arg) - { - if (m_threshold != arg) { - m_threshold = arg; - emit thresholdChanged(arg); - } - } - -private: - qreal m_factor; - qreal m_threshold; -}; - -QT_END_NAMESPACE -QT_END_HEADER -#endif // FRICTIONAFFECTOR_H diff --git a/src/declarative/particles/qsggravity.cpp b/src/declarative/particles/qsggravity.cpp deleted file mode 100644 index 8f6b221387..0000000000 --- a/src/declarative/particles/qsggravity.cpp +++ /dev/null @@ -1,104 +0,0 @@ -/**************************************************************************** -** -** 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 "qsggravity_p.h" -#include -QT_BEGIN_NAMESPACE -const qreal CONV = 0.017453292520444443; -/*! - \qmlclass Gravity QSGGravityAffector - \inqmlmodule QtQuick.Particles 2 - \inherits Affector - \brief The Gravity element allows you to set a constant accleration in an angle - - This element will set the acceleration of all affected particles to a vector of - the specified magnitude in the specified angle. If the angle or acceleration is - not varying, it is more efficient to set the specified acceleration on the Emitter. - - This element models the gravity of a massive object whose center of - gravity is far away (and thus the gravitational pull is effectively constant - across the scene). To model the gravity of an object near or inside the scene, - use PointAttractor. -*/ - -/*! - \qmlproperty real QtQuick.Particles2::Gravity::acceleration - - Pixels per second that objects will be accelerated by. -*/ -/*! - \qmlproperty real QtQuick.Particles2::Gravity::angle - - Angle of acceleration. -*/ - -QSGGravityAffector::QSGGravityAffector(QQuickItem *parent) : - QSGParticleAffector(parent), m_acceleration(-10), m_angle(90), m_xAcc(0), m_yAcc(0) -{ - connect(this, SIGNAL(accelerationChanged(qreal)), - this, SLOT(recalc())); - connect(this, SIGNAL(angleChanged(qreal)), - this, SLOT(recalc())); - recalc(); -} - -void QSGGravityAffector::recalc() -{ - qreal theta = m_angle * CONV; - m_xAcc = m_acceleration * cos(theta); - m_yAcc = m_acceleration * sin(theta); -} - -bool QSGGravityAffector::affectParticle(QSGParticleData *d, qreal dt) -{ - Q_UNUSED(dt); - bool changed = false; - if (d->ax != m_xAcc){ - d->setInstantaneousAX(m_xAcc); - changed = true; - } - if (d->ay != m_yAcc){ - d->setInstantaneousAY(m_yAcc); - changed = true; - } - return changed; -} -QT_END_NAMESPACE diff --git a/src/declarative/particles/qsggravity_p.h b/src/declarative/particles/qsggravity_p.h deleted file mode 100644 index 42bf144465..0000000000 --- a/src/declarative/particles/qsggravity_p.h +++ /dev/null @@ -1,106 +0,0 @@ -/**************************************************************************** -** -** 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 GRAVITYAFFECTOR_H -#define GRAVITYAFFECTOR_H -#include "qsgparticleaffector_p.h" - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - - -class QSGGravityAffector : public QSGParticleAffector -{ - Q_OBJECT - Q_PROPERTY(qreal acceleration READ acceleration WRITE setAcceleration NOTIFY accelerationChanged) - Q_PROPERTY(qreal angle READ angle WRITE setAngle NOTIFY angleChanged) -public: - explicit QSGGravityAffector(QQuickItem *parent = 0); - qreal acceleration() const - { - return m_acceleration; - } - - qreal angle() const - { - return m_angle; - } -protected: - virtual bool affectParticle(QSGParticleData *d, qreal dt); -signals: - - void accelerationChanged(qreal arg); - - void angleChanged(qreal arg); - -public slots: -void setAcceleration(qreal arg) -{ - if (m_acceleration != arg) { - m_acceleration = arg; - emit accelerationChanged(arg); - } -} - -void setAngle(qreal arg) -{ - if (m_angle != arg) { - m_angle = arg; - emit angleChanged(arg); - } -} - -private slots: - void recalc(); -private: - qreal m_acceleration; - qreal m_angle; - - qreal m_xAcc; - qreal m_yAcc; -}; - -QT_END_NAMESPACE -QT_END_HEADER -#endif // GRAVITYAFFECTOR_H diff --git a/src/declarative/particles/qsggroupgoal.cpp b/src/declarative/particles/qsggroupgoal.cpp deleted file mode 100644 index b83c61fd85..0000000000 --- a/src/declarative/particles/qsggroupgoal.cpp +++ /dev/null @@ -1,112 +0,0 @@ -/**************************************************************************** -** -** 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 -#include -#include "qsgimageparticle_p.h" -#include - -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(QQuickItem *parent) : - QSGParticleAffector(parent), m_jump(false) -{ - m_ignoresTime = true; -} - -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); - QQuickStochasticEngine *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 deleted file mode 100644 index 59ccb7a73f..0000000000 --- a/src/declarative/particles/qsggroupgoal_p.h +++ /dev/null @@ -1,102 +0,0 @@ -/**************************************************************************** -** -** 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 QQuickStochasticEngine; - -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(QQuickItem *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/qsgimageparticle.cpp b/src/declarative/particles/qsgimageparticle.cpp deleted file mode 100644 index 7791db6042..0000000000 --- a/src/declarative/particles/qsgimageparticle.cpp +++ /dev/null @@ -1,1773 +0,0 @@ -/**************************************************************************** -** -** 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 -#include -#include -#include -#include -#include -#include "qsgimageparticle_p.h" -#include "qsgparticleemitter_p.h" -#include -#include -#include -#include -#include - -QT_BEGIN_NAMESPACE -//###Switch to define later, for now user-friendly (no compilation) debugging is worth it -DEFINE_BOOL_CONFIG_OPTION(qmlParticlesDebug, QML_PARTICLES_DEBUG) - -#ifndef QT_OPENGL_ES_2 -#define SHADER_DEFINES "#version 120\n" -#else -#define SHADER_DEFINES "" -#endif - -//TODO: Make it larger on desktop? Requires fixing up shader code with the same define -#define UNIFORM_ARRAY_SIZE 64 - -static const char vertexShaderCode[] = - "attribute highp vec2 vPos;\n" - "attribute highp vec4 vData; // x = time, y = lifeSpan, z = size, w = endSize\n" - "attribute highp vec4 vVec; // x,y = constant speed, z,w = acceleration\n" - "uniform highp float entry;\n" - "#ifdef COLOR\n" - "attribute lowp vec4 vColor;\n" - "#endif\n" - "#ifdef DEFORM\n" - "attribute highp vec2 vTex;\n" - "attribute highp vec4 vDeformVec; //x,y x unit vector; z,w = y unit vector\n" - "attribute highp vec3 vRotation; //x = radians of rotation, y=rotation speed, z= bool autoRotate\n" - "#endif\n" - "#ifdef SPRITE\n" - "attribute highp vec4 vAnimData;// interpolate(bool), duration, frameCount (this anim), timestamp (this anim)\n" - "attribute highp vec4 vAnimPos;//sheet x,y, width/height of this anim\n" - "uniform highp vec2 animSheetSize; //width/height of whole sheet\n" - "#endif\n" - "\n" - "uniform highp mat4 qt_Matrix;\n" - "uniform highp float timestamp;\n" - "#ifdef TABLE\n" - "varying lowp vec2 tt;//y is progress if Sprite mode\n" - "uniform highp float sizetable[64];\n" - "uniform highp float opacitytable[64];\n" - "#endif\n" - "#ifdef SPRITE\n" - "varying highp vec4 fTexS;\n" - "#else\n" - "#ifdef DEFORM\n" - "varying highp vec2 fTex;\n" - "#endif\n" - "#endif\n" - "#ifdef COLOR\n" - "varying lowp vec4 fColor;\n" - "#else\n" - "varying lowp float fFade;\n" - "#endif\n" - "\n" - "\n" - "void main() {\n" - "\n" - " highp float t = (timestamp - vData.x) / vData.y;\n" - " if (t < 0. || t > 1.){\n" - "#ifdef DEFORM //Not point sprites\n" - " gl_Position = qt_Matrix * vec4(vPos.x, vPos.y, 0., 1.);\n" - "#else\n" - " gl_PointSize = 0.;\n" - "#endif\n" - " return;\n" - " }\n" - "#ifdef SPRITE\n" - " //Calculate frame location in texture\n" - " highp float frameIndex = mod((((timestamp - vAnimData.w)*1000.)/vAnimData.y),vAnimData.z);\n" - " tt.y = mod((timestamp - vAnimData.w)*1000., vAnimData.y) / vAnimData.y;\n" - "\n" - " frameIndex = floor(frameIndex);\n" - " fTexS.xy = vec2(((frameIndex + vTex.x) * vAnimPos.z / animSheetSize.x), ((vAnimPos.y + vTex.y * vAnimPos.w) / animSheetSize.y));\n" - "\n" - " //Next frame is also passed, for interpolation\n" - " //### Should the next anim be precalculated to allow for interpolation there?\n" - " if (vAnimData.x == 1.0 && frameIndex != vAnimData.z - 1.)//Can't do it for the last frame though, this anim may not loop\n" - " frameIndex = mod(frameIndex+1., vAnimData.z);\n" - " fTexS.zw = vec2(((frameIndex + vTex.x) * vAnimPos.z / animSheetSize.x), ((vAnimPos.y + vTex.y * vAnimPos.w) / animSheetSize.y));\n" - "#else\n" - "#ifdef DEFORM\n" - " fTex = vTex;\n" - "#endif\n" - "#endif\n" - " highp float currentSize = mix(vData.z, vData.w, t * t);\n" - " lowp float fade = 1.;\n" - " highp float fadeIn = min(t * 10., 1.);\n" - " highp float fadeOut = 1. - clamp((t - 0.75) * 4.,0., 1.);\n" - "\n" - "#ifdef TABLE\n" - " currentSize = currentSize * sizetable[int(floor(t*64.))];\n" - " fade = fade * opacitytable[int(floor(t*64.))];\n" - "#endif\n" - "\n" - " if (entry == 1.)\n" - " fade = fade * fadeIn * fadeOut;\n" - " else if (entry == 2.)\n" - " currentSize = currentSize * fadeIn * fadeOut;\n" - "\n" - " if (currentSize <= 0)//Sizes too small look jittery as they move\n" - " currentSize = 0;\n" - " else if (currentSize < 3)\n" - " currentSize = 3;\n" - "\n" - " highp vec2 pos;\n" - "#ifdef DEFORM\n" - " highp float rotation = vRotation.x + vRotation.y * t * vData.y;\n" - " if (vRotation.z == 1.0){\n" - " highp vec2 curVel = vVec.zw * t * vData.y + vVec.xy;\n" - " rotation += atan(curVel.y, curVel.x);\n" - " }\n" - " highp vec2 trigCalcs = vec2(cos(rotation), sin(rotation));\n" - " highp vec4 deform = vDeformVec * currentSize * (vTex.xxyy - 0.5);\n" - " highp vec4 rotatedDeform = deform.xxzz * trigCalcs.xyxy;\n" - " rotatedDeform = rotatedDeform + (deform.yyww * trigCalcs.yxyx * vec4(-1.,1.,-1.,1.));\n" - " /* The readable version:\n" - " highp vec2 xDeform = vDeformVec.xy * currentSize * (vTex.x-0.5);\n" - " highp vec2 yDeform = vDeformVec.zw * currentSize * (vTex.y-0.5);\n" - " highp vec2 xRotatedDeform;\n" - " xRotatedDeform.x = trigCalcs.x*xDeform.x - trigCalcs.y*xDeform.y;\n" - " xRotatedDeform.y = trigCalcs.y*xDeform.x + trigCalcs.x*xDeform.y;\n" - " highp vec2 yRotatedDeform;\n" - " yRotatedDeform.x = trigCalcs.x*yDeform.x - trigCalcs.y*yDeform.y;\n" - " yRotatedDeform.y = trigCalcs.y*yDeform.x + trigCalcs.x*yDeform.y;\n" - " */\n" - " pos = vPos\n" - " + rotatedDeform.xy\n" - " + rotatedDeform.zw\n" - " + vVec.xy * t * vData.y // apply speed\n" - " + 0.5 * vVec.zw * pow(t * vData.y, 2.); // apply acceleration\n" - "#else\n" - " pos = vPos\n" - " + vVec.xy * t * vData.y // apply speed vector..\n" - " + 0.5 * vVec.zw * pow(t * vData.y, 2.);\n" - " gl_PointSize = currentSize;\n" - "#endif\n" - " gl_Position = qt_Matrix * vec4(pos.x, pos.y, 0, 1);\n" - "\n" - "#ifdef COLOR\n" - " fColor = vColor * fade;\n" - "#else\n" - " fFade = fade;\n" - "#endif\n" - "#ifdef TABLE\n" - " tt.x = t;\n" - "#endif\n" - "}\n"; - -static const char fragmentShaderCode[] = - "uniform sampler2D texture;\n" - "uniform lowp float qt_Opacity;\n" - "\n" - "#ifdef SPRITE\n" - "varying highp vec4 fTexS;\n" - "#else\n" - "#ifdef DEFORM //First non-pointsprite\n" - "varying highp vec2 fTex;\n" - "#endif\n" - "#endif\n" - "#ifdef COLOR\n" - "varying lowp vec4 fColor;\n" - "#else\n" - "varying lowp float fFade;\n" - "#endif\n" - "#ifdef TABLE\n" - "varying lowp vec2 tt;\n" - "uniform sampler2D colortable;\n" - "#endif\n" - "\n" - "void main() {\n" - "#ifdef SPRITE\n" - " gl_FragColor = mix(texture2D(texture, fTexS.xy), texture2D(texture, fTexS.zw), tt.y)\n" - " * fColor\n" - " * texture2D(colortable, tt)\n" - " * qt_Opacity;\n" - "#else\n" - "#ifdef TABLE\n" - " gl_FragColor = texture2D(texture, fTex)\n" - " * fColor\n" - " * texture2D(colortable, tt)\n" - " * qt_Opacity;\n" - "#else\n" - "#ifdef DEFORM\n" - " gl_FragColor = (texture2D(texture, fTex)) * fColor * qt_Opacity;\n" - "#else\n" - "#ifdef COLOR\n" - " gl_FragColor = (texture2D(texture, gl_PointCoord)) * fColor * qt_Opacity;\n" - "#else\n" - " gl_FragColor = texture2D(texture, gl_PointCoord) * (fFade * qt_Opacity);\n" - "#endif //COLOR\n" - "#endif //DEFORM\n" - "#endif //TABLE\n" - "#endif //SPRITE\n" - "}\n"; - -const qreal CONV = 0.017453292519943295; -class ImageMaterialData -{ - public: - ImageMaterialData() - : texture(0), colorTable(0) - {} - - ~ImageMaterialData(){ - delete texture; - delete colorTable; - } - - QSGTexture *texture; - QSGTexture *colorTable; - float sizeTable[UNIFORM_ARRAY_SIZE]; - float opacityTable[UNIFORM_ARRAY_SIZE]; - - qreal timestamp; - qreal entry; - QSizeF animSheetSize; -}; - -class TabledMaterialData : public ImageMaterialData {}; -class TabledMaterial : public QSGSimpleMaterialShader -{ - QSG_DECLARE_SIMPLE_SHADER(TabledMaterial, TabledMaterialData) - -public: - TabledMaterial() - { - m_vertex_code = QByteArray(SHADER_DEFINES) - + QByteArray("#define TABLE\n#define DEFORM\n#define COLOR\n") - + vertexShaderCode; - - m_fragment_code = QByteArray(SHADER_DEFINES) - + QByteArray("#define TABLE\n#define DEFORM\n#define COLOR\n") - + fragmentShaderCode; - - Q_ASSERT(!m_vertex_code.isNull()); - Q_ASSERT(!m_fragment_code.isNull()); - } - - const char *vertexShader() const { return m_vertex_code.constData(); } - const char *fragmentShader() const { return m_fragment_code.constData(); } - - QList attributes() const { - return QList() << "vPos" << "vTex" << "vData" << "vVec" - << "vColor" << "vDeformVec" << "vRotation"; - }; - - void initialize() { - QSGSimpleMaterialShader::initialize(); - program()->bind(); - program()->setUniformValue("texture", 0); - program()->setUniformValue("colortable", 1); - glFuncs = QOpenGLContext::currentContext()->functions(); - m_timestamp_id = program()->uniformLocation("timestamp"); - m_entry_id = program()->uniformLocation("entry"); - m_sizetable_id = program()->uniformLocation("sizetable"); - m_opacitytable_id = program()->uniformLocation("opacitytable"); - } - - void updateState(const TabledMaterialData* d, const TabledMaterialData*) { - glFuncs->glActiveTexture(GL_TEXTURE1); - d->colorTable->bind(); - - glFuncs->glActiveTexture(GL_TEXTURE0); - d->texture->bind(); - - program()->setUniformValue(m_timestamp_id, (float) d->timestamp); - program()->setUniformValue(m_entry_id, (float) d->entry); - program()->setUniformValueArray(m_sizetable_id, (float*) d->sizeTable, UNIFORM_ARRAY_SIZE, 1); - program()->setUniformValueArray(m_opacitytable_id, (float*) d->opacityTable, UNIFORM_ARRAY_SIZE, 1); - } - - int m_entry_id; - int m_timestamp_id; - int m_sizetable_id; - int m_opacitytable_id; - QByteArray m_vertex_code; - QByteArray m_fragment_code; - QOpenGLFunctions* glFuncs; -}; - -class DeformableMaterialData : public ImageMaterialData {}; -class DeformableMaterial : public QSGSimpleMaterialShader -{ - QSG_DECLARE_SIMPLE_SHADER(DeformableMaterial, DeformableMaterialData) - -public: - DeformableMaterial() - { - m_vertex_code = QByteArray(SHADER_DEFINES) - + QByteArray("#define DEFORM\n#define COLOR\n") - + vertexShaderCode; - - m_fragment_code = QByteArray(SHADER_DEFINES) - + QByteArray("#define DEFORM\n#define COLOR\n") - + fragmentShaderCode; - - Q_ASSERT(!m_vertex_code.isNull()); - Q_ASSERT(!m_fragment_code.isNull()); - } - - const char *vertexShader() const { return m_vertex_code.constData(); } - const char *fragmentShader() const { return m_fragment_code.constData(); } - - QList attributes() const { - return QList() << "vPos" << "vTex" << "vData" << "vVec" - << "vColor" << "vDeformVec" << "vRotation"; - }; - - void initialize() { - QSGSimpleMaterialShader::initialize(); - program()->bind(); - program()->setUniformValue("texture", 0); - glFuncs = QOpenGLContext::currentContext()->functions(); - m_timestamp_id = program()->uniformLocation("timestamp"); - m_entry_id = program()->uniformLocation("entry"); - } - - void updateState(const DeformableMaterialData* d, const DeformableMaterialData*) { - glFuncs->glActiveTexture(GL_TEXTURE0); - d->texture->bind(); - - program()->setUniformValue(m_timestamp_id, (float) d->timestamp); - program()->setUniformValue(m_entry_id, (float) d->entry); - } - - int m_entry_id; - int m_timestamp_id; - QByteArray m_vertex_code; - QByteArray m_fragment_code; - QOpenGLFunctions* glFuncs; -}; - -class SpriteMaterialData : public ImageMaterialData {}; -class SpriteMaterial : public QSGSimpleMaterialShader -{ - QSG_DECLARE_SIMPLE_SHADER(SpriteMaterial, SpriteMaterialData) - -public: - SpriteMaterial() - { - m_vertex_code = QByteArray(SHADER_DEFINES) - + QByteArray("#define SPRITE\n#define TABLE\n#define DEFORM\n#define COLOR\n") - + vertexShaderCode; - - m_fragment_code = QByteArray(SHADER_DEFINES) - + QByteArray("#define SPRITE\n#define TABLE\n#define DEFORM\n#define COLOR\n") - + fragmentShaderCode; - - Q_ASSERT(!m_vertex_code.isNull()); - Q_ASSERT(!m_fragment_code.isNull()); - } - - const char *vertexShader() const { return m_vertex_code.constData(); } - const char *fragmentShader() const { return m_fragment_code.constData(); } - - QList attributes() const { - return QList() << "vPos" << "vTex" << "vData" << "vVec" - << "vColor" << "vDeformVec" << "vRotation" << "vAnimData" << "vAnimPos"; - }; - - void initialize() { - QSGSimpleMaterialShader::initialize(); - program()->bind(); - program()->setUniformValue("texture", 0); - program()->setUniformValue("colortable", 1); - glFuncs = QOpenGLContext::currentContext()->functions(); - m_timestamp_id = program()->uniformLocation("timestamp"); - m_animsize_id = program()->uniformLocation("animSheetSize"); - m_entry_id = program()->uniformLocation("entry"); - m_sizetable_id = program()->uniformLocation("sizetable"); - m_opacitytable_id = program()->uniformLocation("opacitytable"); - } - - void updateState(const SpriteMaterialData* d, const SpriteMaterialData*) { - glFuncs->glActiveTexture(GL_TEXTURE1); - d->colorTable->bind(); - - // make sure we end by setting GL_TEXTURE0 as active texture - glFuncs->glActiveTexture(GL_TEXTURE0); - d->texture->bind(); - - program()->setUniformValue(m_timestamp_id, (float) d->timestamp); - program()->setUniformValue(m_animsize_id, d->animSheetSize); - program()->setUniformValue(m_entry_id, (float) d->entry); - program()->setUniformValueArray(m_sizetable_id, (float*) d->sizeTable, 64, 1); - program()->setUniformValueArray(m_opacitytable_id, (float*) d->opacityTable, UNIFORM_ARRAY_SIZE, 1); - } - - int m_timestamp_id; - int m_animsize_id; - int m_entry_id; - int m_sizetable_id; - int m_opacitytable_id; - QByteArray m_vertex_code; - QByteArray m_fragment_code; - QOpenGLFunctions* glFuncs; -}; - -class ColoredMaterialData : public ImageMaterialData {}; -class ColoredMaterial : public QSGSimpleMaterialShader -{ - QSG_DECLARE_SIMPLE_SHADER(ColoredMaterial, ColoredMaterialData) - -public: - ColoredMaterial() - { - m_vertex_code = QByteArray(SHADER_DEFINES) - + QByteArray("#define COLOR\n") - + vertexShaderCode; - - m_fragment_code = QByteArray(SHADER_DEFINES) - + QByteArray("#define COLOR\n") - + fragmentShaderCode; - - Q_ASSERT(!m_vertex_code.isNull()); - Q_ASSERT(!m_fragment_code.isNull()); - } - - const char *vertexShader() const { return m_vertex_code.constData(); } - const char *fragmentShader() const { return m_fragment_code.constData(); } - - void activate() { - QSGSimpleMaterialShader::activate(); -#if !defined(QT_OPENGL_ES_2) && !defined(Q_OS_WIN) - glEnable(GL_POINT_SPRITE); - glEnable(GL_VERTEX_PROGRAM_POINT_SIZE); -#endif - } - - void deactivate() { - QSGSimpleMaterialShader::deactivate(); -#if !defined(QT_OPENGL_ES_2) && !defined(Q_OS_WIN) - glDisable(GL_POINT_SPRITE); - glDisable(GL_VERTEX_PROGRAM_POINT_SIZE); -#endif - } - - QList attributes() const { - return QList() << "vPos" << "vData" << "vVec" << "vColor"; - } - - void initialize() { - QSGSimpleMaterialShader::initialize(); - program()->bind(); - program()->setUniformValue("texture", 0); - glFuncs = QOpenGLContext::currentContext()->functions(); - m_timestamp_id = program()->uniformLocation("timestamp"); - m_entry_id = program()->uniformLocation("entry"); - } - - void updateState(const ColoredMaterialData* d, const ColoredMaterialData*) { - glFuncs->glActiveTexture(GL_TEXTURE0); - d->texture->bind(); - - program()->setUniformValue(m_timestamp_id, (float) d->timestamp); - program()->setUniformValue(m_entry_id, (float) d->entry); - } - - int m_timestamp_id; - int m_entry_id; - QByteArray m_vertex_code; - QByteArray m_fragment_code; - QOpenGLFunctions* glFuncs; -}; - -class SimpleMaterialData : public ImageMaterialData {}; -class SimpleMaterial : public QSGSimpleMaterialShader -{ - QSG_DECLARE_SIMPLE_SHADER(SimpleMaterial, SimpleMaterialData) - -public: - SimpleMaterial() - { - m_vertex_code = QByteArray(SHADER_DEFINES) - + vertexShaderCode; - - m_fragment_code = QByteArray(SHADER_DEFINES) - + fragmentShaderCode; - - Q_ASSERT(!m_vertex_code.isNull()); - Q_ASSERT(!m_fragment_code.isNull()); - } - - const char *vertexShader() const { return m_vertex_code.constData(); } - const char *fragmentShader() const { return m_fragment_code.constData(); } - - void activate() { - QSGSimpleMaterialShader::activate(); -#if !defined(QT_OPENGL_ES_2) && !defined(Q_OS_WIN) - glEnable(GL_POINT_SPRITE); - glEnable(GL_VERTEX_PROGRAM_POINT_SIZE); -#endif - } - - void deactivate() { - QSGSimpleMaterialShader::deactivate(); -#if !defined(QT_OPENGL_ES_2) && !defined(Q_OS_WIN) - glDisable(GL_POINT_SPRITE); - glDisable(GL_VERTEX_PROGRAM_POINT_SIZE); -#endif - } - - QList attributes() const { - return QList() << "vPos" << "vData" << "vVec"; - } - - void initialize() { - QSGSimpleMaterialShader::initialize(); - program()->bind(); - program()->setUniformValue("texture", 0); - glFuncs = QOpenGLContext::currentContext()->functions(); - m_timestamp_id = program()->uniformLocation("timestamp"); - m_entry_id = program()->uniformLocation("entry"); - } - - void updateState(const SimpleMaterialData* d, const SimpleMaterialData*) { - glFuncs->glActiveTexture(GL_TEXTURE0); - d->texture->bind(); - - program()->setUniformValue(m_timestamp_id, (float) d->timestamp); - program()->setUniformValue(m_entry_id, (float) d->entry); - } - - int m_timestamp_id; - int m_entry_id; - QByteArray m_vertex_code; - QByteArray m_fragment_code; - QOpenGLFunctions* glFuncs; -}; - -void fillUniformArrayFromImage(float* array, const QImage& img, int size) -{ - if (img.isNull()){ - for (int i=0; i QtQuick.Particles2::ImageParticle::sprites - - The sprite or sprites used to draw this particle. - - Note that the sprite image will be scaled to a square based on the size of - the particle being rendered. -*/ -/*! - \qmlproperty url QtQuick.Particles2::ImageParticle::colorTable - - An image whose color will be used as a 1D texture to determine color over life. E.g. when - the particle is halfway through its lifetime, it will have the color specified halfway - across the image. - - This color is blended with the color property and the color of the source image. -*/ -/*! - \qmlproperty url QtQuick.Particles2::ImageParticle::sizeTable - - An image whose opacity will be used as a 1D texture to determine size over life. - - This property is expected to be removed shortly, in favor of custom easing curves to determine size over life. -*/ -/*! - \qmlproperty url QtQuick.Particles2::ImageParticle::opacityTable - - An image whose opacity will be used as a 1D texture to determine size over life. - - This property is expected to be removed shortly, in favor of custom easing curves to determine opacity over life. -*/ -/*! - \qmlproperty color QtQuick.Particles2::ImageParticle::color - - If a color is specified, the provided image will be colorized with it. - - Default is white (no change). -*/ -/*! - \qmlproperty real QtQuick.Particles2::ImageParticle::colorVariation - - This number represents the color variation applied to individual particles. - Setting colorVariation is the same as setting redVariation, greenVariation, - and blueVariation to the same number. - - Each channel can vary between particle by up to colorVariation from its usual color. - - Color is measured, per channel, from 0.0 to 1.0. - - Default is 0.0 -*/ -/*! - \qmlproperty real QtQuick.Particles2::ImageParticle::redVariation - The variation in the red color channel between particles. - - Color is measured, per channel, from 0.0 to 1.0. - - Default is 0.0 -*/ -/*! - \qmlproperty real QtQuick.Particles2::ImageParticle::greenVariation - The variation in the green color channel between particles. - - Color is measured, per channel, from 0.0 to 1.0. - - Default is 0.0 -*/ -/*! - \qmlproperty real QtQuick.Particles2::ImageParticle::blueVariation - The variation in the blue color channel between particles. - - Color is measured, per channel, from 0.0 to 1.0. - - Default is 0.0 -*/ -/*! - \qmlproperty real QtQuick.Particles2::ImageParticle::alpha - An alpha to be applied to the image. This value is multiplied by the value in - the image, and the value in the color property. - - Particles have additive blending, so lower alpha on single particles leads - to stronger effects when multiple particles overlap. - - Alpha is measured from 0.0 to 1.0. - - Default is 1.0 -*/ -/*! - \qmlproperty real QtQuick.Particles2::ImageParticle::alphaVariation - The variation in the alpha channel between particles. - - Alpha is measured from 0.0 to 1.0. - - Default is 0.0 -*/ -/*! - \qmlproperty real QtQuick.Particles2::ImageParticle::rotation - - If set the image will be rotated by this many degrees before it is drawn. - - The particle coordinates are not transformed. -*/ -/*! - \qmlproperty real QtQuick.Particles2::ImageParticle::rotationVariation - - If set the rotation of individual particles will vary by up to this much - between particles. - -*/ -/*! - \qmlproperty real QtQuick.Particles2::ImageParticle::rotationSpeed - - If set particles will rotate at this speed in degrees/second. -*/ -/*! - \qmlproperty real QtQuick.Particles2::ImageParticle::rotationSpeedVariation - - If set the rotationSpeed of individual particles will vary by up to this much - between particles. - -*/ -/*! - \qmlproperty bool QtQuick.Particles2::ImageParticle::autoRotation - - If set to true then a rotation will be applied on top of the particles rotation, so - that it faces the direction of travel. So to face away from the direction of travel, - set autoRotation to true and rotation to 180. - - Default is false -*/ -/*! - \qmlproperty StochasticDirection QtQuick.Particles2::ImageParticle::xVector - - Allows you to deform the particle image when drawn. The rectangular image will - be deformed so that the horizontal sides are in the shape of this vector instead - of (1,0). -*/ -/*! - \qmlproperty StochasticDirection QtQuick.Particles2::ImageParticle::yVector - - Allows you to deform the particle image when drawn. The rectangular image will - be deformed so that the vertical sides are in the shape of this vector instead - of (0,1). -*/ -/*! - \qmlproperty EntryEffect QtQuick.Particles2::ImageParticle::entryEffect - - This property provides basic and cheap entrance and exit effects for the particles. - For fine-grained control, see sizeTable and opacityTable. - - Acceptable values are - \list - \o None: Particles just appear and disappear. - \o Fade: Particles fade in from 0 opacity at the start of their life, and fade out to 0 at the end. - \o Scale: Particles scale in from 0 size at the start of their life, and scale back to 0 at the end. - \endlist - - Default value is Fade. -*/ -/*! - \qmlproperty bool QtQuick.Particles2::ImageParticle::spritesInterpolate - - If set to true, sprite particles will interpolate between sprite frames each rendered frame, making - the sprites look smoother. - - Default is true. -*/ - - -QSGImageParticle::QSGImageParticle(QQuickItem* parent) - : QSGParticlePainter(parent) - , m_color_variation(0.0) - , m_rootNode(0) - , m_material(0) - , m_alphaVariation(0.0) - , m_alpha(1.0) - , m_redVariation(0.0) - , m_greenVariation(0.0) - , m_blueVariation(0.0) - , m_rotation(0) - , m_rotationVariation(0) - , m_rotationSpeed(0) - , m_rotationSpeedVariation(0) - , m_autoRotation(false) - , m_xVector(0) - , m_yVector(0) - , m_spriteEngine(0) - , m_spritesInterpolate(true) - , m_explicitColor(false) - , m_explicitRotation(false) - , m_explicitDeformation(false) - , m_explicitAnimation(false) - , m_bloat(false) - , perfLevel(Unknown) - , m_lastLevel(Unknown) - , m_debugMode(false) - , m_entryEffect(Fade) -{ - setFlag(ItemHasContents); - m_debugMode = qmlParticlesDebug(); -} - -QSGImageParticle::~QSGImageParticle() -{ -} - -QDeclarativeListProperty QSGImageParticle::sprites() -{ - return QDeclarativeListProperty(this, &m_sprites, spriteAppend, spriteCount, spriteAt, spriteClear); -} - -void QSGImageParticle::setImage(const QUrl &image) -{ - if (image == m_image_name) - return; - m_image_name = image; - emit imageChanged(); - reset(); -} - - -void QSGImageParticle::setColortable(const QUrl &table) -{ - if (table == m_colortable_name) - return; - m_colortable_name = table; - emit colortableChanged(); - reset(); -} - -void QSGImageParticle::setSizetable(const QUrl &table) -{ - if (table == m_sizetable_name) - return; - m_sizetable_name = table; - emit sizetableChanged(); - reset(); -} - -void QSGImageParticle::setOpacitytable(const QUrl &table) -{ - if (table == m_opacitytable_name) - return; - m_opacitytable_name = table; - emit opacitytableChanged(); - reset(); -} - -void QSGImageParticle::setColor(const QColor &color) -{ - if (color == m_color) - return; - m_color = color; - emit colorChanged(); - m_explicitColor = true; - if (perfLevel < Colored) - reset(); -} - -void QSGImageParticle::setColorVariation(qreal var) -{ - if (var == m_color_variation) - return; - m_color_variation = var; - emit colorVariationChanged(); - m_explicitColor = true; - if (perfLevel < Colored) - reset(); -} - -void QSGImageParticle::setAlphaVariation(qreal arg) -{ - if (m_alphaVariation != arg) { - m_alphaVariation = arg; - emit alphaVariationChanged(arg); - } - m_explicitColor = true; - if (perfLevel < Colored) - reset(); -} - -void QSGImageParticle::setAlpha(qreal arg) -{ - if (m_alpha != arg) { - m_alpha = arg; - emit alphaChanged(arg); - } - m_explicitColor = true; - if (perfLevel < Colored) - reset(); -} - -void QSGImageParticle::setRedVariation(qreal arg) -{ - if (m_redVariation != arg) { - m_redVariation = arg; - emit redVariationChanged(arg); - } - m_explicitColor = true; - if (perfLevel < Colored) - reset(); -} - -void QSGImageParticle::setGreenVariation(qreal arg) -{ - if (m_greenVariation != arg) { - m_greenVariation = arg; - emit greenVariationChanged(arg); - } - m_explicitColor = true; - if (perfLevel < Colored) - reset(); -} - -void QSGImageParticle::setBlueVariation(qreal arg) -{ - if (m_blueVariation != arg) { - m_blueVariation = arg; - emit blueVariationChanged(arg); - } - m_explicitColor = true; - if (perfLevel < Colored) - reset(); -} - -void QSGImageParticle::setRotation(qreal arg) -{ - if (m_rotation != arg) { - m_rotation = arg; - emit rotationChanged(arg); - } - m_explicitRotation = true; - if (perfLevel < Deformable) - reset(); -} - -void QSGImageParticle::setRotationVariation(qreal arg) -{ - if (m_rotationVariation != arg) { - m_rotationVariation = arg; - emit rotationVariationChanged(arg); - } - m_explicitRotation = true; - if (perfLevel < Deformable) - reset(); -} - -void QSGImageParticle::setRotationSpeed(qreal arg) -{ - if (m_rotationSpeed != arg) { - m_rotationSpeed = arg; - emit rotationSpeedChanged(arg); - } - m_explicitRotation = true; - if (perfLevel < Deformable) - reset(); -} - -void QSGImageParticle::setRotationSpeedVariation(qreal arg) -{ - if (m_rotationSpeedVariation != arg) { - m_rotationSpeedVariation = arg; - emit rotationSpeedVariationChanged(arg); - } - m_explicitRotation = true; - if (perfLevel < Deformable) - reset(); -} - -void QSGImageParticle::setAutoRotation(bool arg) -{ - if (m_autoRotation != arg) { - m_autoRotation = arg; - emit autoRotationChanged(arg); - } - m_explicitRotation = true; - if (perfLevel < Deformable) - reset(); -} - -void QSGImageParticle::setXVector(QSGDirection* arg) -{ - if (m_xVector != arg) { - m_xVector = arg; - emit xVectorChanged(arg); - } - m_explicitDeformation = true; - if (perfLevel < Deformable) - reset(); -} - -void QSGImageParticle::setYVector(QSGDirection* arg) -{ - if (m_yVector != arg) { - m_yVector = arg; - emit yVectorChanged(arg); - } - m_explicitDeformation = true; - if (perfLevel < Deformable) - reset(); -} - -void QSGImageParticle::setSpritesInterpolate(bool arg) -{ - if (m_spritesInterpolate != arg) { - m_spritesInterpolate = arg; - emit spritesInterpolateChanged(arg); - } -} - -void QSGImageParticle::setBloat(bool arg) -{ - if (m_bloat != arg) { - m_bloat = arg; - emit bloatChanged(arg); - } - if (perfLevel < 9999) - reset(); -} - -void QSGImageParticle::setEntryEffect(EntryEffect arg) -{ - if (m_entryEffect != arg) { - m_entryEffect = arg; - if (m_material) - getState(m_material)->entry = (qreal) m_entryEffect; - emit entryEffectChanged(arg); - } -} - -void QSGImageParticle::resetColor() -{ - m_explicitColor = false; - foreach (const QString &str, m_groups) - foreach (QSGParticleData* d, m_system->groupData[m_system->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->groupData[m_system->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->groupData[m_system->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(); - m_pleaseReset = true; - update(); -} - -void QSGImageParticle::createEngine() -{ - if (m_spriteEngine) - delete m_spriteEngine; - if (m_sprites.count()) - m_spriteEngine = new QQuickSpriteEngine(m_sprites, this); - else - m_spriteEngine = 0; - m_explicitAnimation = true; - reset(); -} - -static QSGGeometry::Attribute SimpleParticle_Attributes[] = { - QSGGeometry::Attribute::create(0, 2, GL_FLOAT, true), // Position - QSGGeometry::Attribute::create(1, 4, GL_FLOAT), // Data - QSGGeometry::Attribute::create(2, 4, GL_FLOAT) // Vectors -}; - -static QSGGeometry::AttributeSet SimpleParticle_AttributeSet = -{ - 3, // Attribute Count - ( 2 + 4 + 4 ) * sizeof(float), - SimpleParticle_Attributes -}; - -static QSGGeometry::Attribute ColoredParticle_Attributes[] = { - QSGGeometry::Attribute::create(0, 2, GL_FLOAT, true), // Position - QSGGeometry::Attribute::create(1, 4, GL_FLOAT), // Data - QSGGeometry::Attribute::create(2, 4, GL_FLOAT), // Vectors - QSGGeometry::Attribute::create(3, 4, GL_UNSIGNED_BYTE), // Colors -}; - -static QSGGeometry::AttributeSet ColoredParticle_AttributeSet = -{ - 4, // Attribute Count - ( 2 + 4 + 4 ) * sizeof(float) + 4 * sizeof(uchar), - ColoredParticle_Attributes -}; - -static QSGGeometry::Attribute DeformableParticle_Attributes[] = { - QSGGeometry::Attribute::create(0, 2, GL_FLOAT, true), // Position - QSGGeometry::Attribute::create(1, 2, GL_FLOAT), // TexCoord - QSGGeometry::Attribute::create(2, 4, GL_FLOAT), // Data - QSGGeometry::Attribute::create(3, 4, GL_FLOAT), // Vectors - QSGGeometry::Attribute::create(4, 4, GL_UNSIGNED_BYTE), // Colors - QSGGeometry::Attribute::create(5, 4, GL_FLOAT), // DeformationVectors - QSGGeometry::Attribute::create(6, 3, GL_FLOAT), // Rotation -}; - -static QSGGeometry::AttributeSet DeformableParticle_AttributeSet = -{ - 7, // Attribute Count - (2 + 2 + 4 + 4 + 4 + 3) * sizeof(float) + 4 * sizeof(uchar), - DeformableParticle_Attributes -}; - -static QSGGeometry::Attribute SpriteParticle_Attributes[] = { - QSGGeometry::Attribute::create(0, 2, GL_FLOAT, true), // Position - QSGGeometry::Attribute::create(1, 2, GL_FLOAT), // TexCoord - QSGGeometry::Attribute::create(2, 4, GL_FLOAT), // Data - QSGGeometry::Attribute::create(3, 4, GL_FLOAT), // Vectors - QSGGeometry::Attribute::create(4, 4, GL_UNSIGNED_BYTE), // Colors - QSGGeometry::Attribute::create(5, 4, GL_FLOAT), // DeformationVectors - QSGGeometry::Attribute::create(6, 3, GL_FLOAT), // Rotation - QSGGeometry::Attribute::create(7, 4, GL_FLOAT), // Anim Data - QSGGeometry::Attribute::create(8, 4, GL_FLOAT) // Anim Pos -}; - -static QSGGeometry::AttributeSet SpriteParticle_AttributeSet = -{ - 9, // Attribute Count - (2 + 2 + 4 + 4 + 4 + 4 + 4 + 3) * sizeof(float) + 4 * sizeof(uchar), - SpriteParticle_Attributes -}; - -void QSGImageParticle::clearShadows() -{ - m_shadowInit = false; - foreach (const QVector data, m_shadowData) - qDeleteAll(data); - m_shadowData.clear(); -} - -//Only call if you need to, may initialize the whole array first time -QSGParticleData* QSGImageParticle::getShadowDatum(QSGParticleData* datum) -{ - QSGParticleGroupData* gd = m_system->groupData[datum->group]; - if (!m_shadowData.contains(datum->group)) { - QVector data; - for (int i=0; isize(); i++){ - QSGParticleData* datum = new QSGParticleData(m_system); - *datum = *(gd->data[i]); - data << datum; - } - m_shadowData.insert(datum->group, data); - } - //### If dynamic resize is added, remember to potentially resize the shadow data on out-of-bounds access request - - return m_shadowData[datum->group][datum->index]; -} - -QSGGeometryNode* QSGImageParticle::buildParticleNodes() -{ -#ifdef QT_OPENGL_ES_2 - if (m_count * 4 > 0xffff) { - printf("ImageParticle: Too many particles - maximum 16,000 per ImageParticle.\n");//ES 2 vertex count limit is ushort - return 0; - } -#endif - - if (count() <= 0) - return 0; - - if (m_sprites.count() || m_bloat) { - perfLevel = Sprites; - } else if (!m_colortable_name.isEmpty() || !m_sizetable_name.isEmpty() - || !m_opacitytable_name.isEmpty()) { - perfLevel = Tabled; - } else if (m_autoRotation || m_rotation || m_rotationVariation - || m_rotationSpeed || m_rotationSpeedVariation - || m_xVector || m_yVector) { - perfLevel = Deformable; - } else if (m_alphaVariation || m_alpha != 1.0 || m_color.isValid() || m_color_variation - || m_redVariation || m_blueVariation || m_greenVariation) { - perfLevel = Colored; - } else { - perfLevel = Simple; - } - - foreach (const QString &str, m_groups){//For sharing higher levels, need to have highest used so it renders - int gIdx = m_system->groupIds[str]; - foreach (QSGParticlePainter* p, m_system->groupData[gIdx]->painters){ - QSGImageParticle* other = qobject_cast(p); - if (other){ - if (other->perfLevel > perfLevel) { - if (other->perfLevel >= Tabled){//Deformable is the highest level needed for this, anything higher isn't shared (or requires your own sprite) - if (perfLevel < Deformable) - perfLevel = Deformable; - } else { - perfLevel = other->perfLevel; - } - } else if (other->perfLevel < perfLevel) { - other->reset(); - } - } - } - } - - if (perfLevel >= Colored && !m_color.isValid()) - m_color = QColor(Qt::white);//Hidden default, but different from unset - - QImage image; - if (perfLevel >= Sprites){ - if (!m_spriteEngine) { - qWarning() << "ImageParticle: No sprite engine..."; - return 0; - } - image = m_spriteEngine->assembledImage(); - if (image.isNull())//Warning is printed in engine - return 0; - } else { - image = QImage(m_image_name.toLocalFile()); - if (image.isNull()) { - printf("ImageParticle: loading image failed '%s'\n", qPrintable(m_image_name.toLocalFile())); - return 0; - } - } - - clearShadows(); - if (m_material) - m_material = 0; - - //Setup material - QImage colortable; - QImage sizetable; - QImage opacitytable; - switch (perfLevel) {//Fallthrough intended - case Sprites: - m_material = SpriteMaterial::createMaterial(); - getState(m_material)->animSheetSize = QSizeF(image.size()); - m_spriteEngine->setCount(m_count); - case Tabled: - if (!m_material) - m_material = TabledMaterial::createMaterial(); - colortable = QImage(m_colortable_name.toLocalFile()); - sizetable = QImage(m_sizetable_name.toLocalFile()); - opacitytable = QImage(m_opacitytable_name.toLocalFile()); - if (colortable.isNull()){ - colortable = QImage(1,1,QImage::Format_ARGB32); - colortable.fill(Qt::white); - } - Q_ASSERT(!colortable.isNull()); - getState(m_material)->colorTable = QSGPlainTexture::fromImage(colortable); - fillUniformArrayFromImage(getState(m_material)->sizeTable, sizetable, UNIFORM_ARRAY_SIZE); - fillUniformArrayFromImage(getState(m_material)->opacityTable, opacitytable, UNIFORM_ARRAY_SIZE); - case Deformable: - if (!m_material) - m_material = DeformableMaterial::createMaterial(); - case Colored: - if (!m_material) - m_material = ColoredMaterial::createMaterial(); - default://Also Simple - if (!m_material) - m_material = SimpleMaterial::createMaterial(); - getState(m_material)->texture = QSGPlainTexture::fromImage(image); - getState(m_material)->texture->setFiltering(QSGTexture::Linear); - getState(m_material)->entry = (qreal) m_entryEffect; - m_material->setFlag(QSGMaterial::Blending); - } - - foreach (const QString &str, m_groups){ - int gIdx = m_system->groupIds[str]; - int count = m_system->groupData[gIdx]->size(); - QSGGeometryNode* node = new QSGGeometryNode(); - node->setMaterial(m_material); - node->markDirty(QSGNode::DirtyMaterial); - - m_nodes.insert(gIdx, node); - m_idxStarts.insert(gIdx, m_lastIdxStart); - m_lastIdxStart += count; - - //Create Particle Geometry - int vCount = count * 4; - int iCount = count * 6; - - QSGGeometry *g; - if (perfLevel == Sprites) - g = new QSGGeometry(SpriteParticle_AttributeSet, vCount, iCount); - else if (perfLevel == Tabled) - g = new QSGGeometry(DeformableParticle_AttributeSet, vCount, iCount); - else if (perfLevel == Deformable) - g = new QSGGeometry(DeformableParticle_AttributeSet, vCount, iCount); - else if (perfLevel == Colored) - g = new QSGGeometry(ColoredParticle_AttributeSet, count, 0); - else //Simple - g = new QSGGeometry(SimpleParticle_AttributeSet, count, 0); - - node->setGeometry(g); - if (perfLevel <= Colored){ - g->setDrawingMode(GL_POINTS); - if (m_debugMode){ - GLfloat pointSizeRange[2]; - glGetFloatv(GL_ALIASED_POINT_SIZE_RANGE, pointSizeRange); - qDebug() << "Using point sprites, GL_ALIASED_POINT_SIZE_RANGE " <setDrawingMode(GL_TRIANGLES); - - for (int p=0; p < count; ++p) - commit(gIdx, p);//commit sets geometry for the node, has its own perfLevel switch - - if (perfLevel == Sprites) - initTexCoords((SpriteVertex*)g->vertexData(), vCount); - else if (perfLevel == Tabled) - initTexCoords((DeformableVertex*)g->vertexData(), vCount); - else if (perfLevel == Deformable) - initTexCoords((DeformableVertex*)g->vertexData(), vCount); - - if (perfLevel > Colored){ - quint16 *indices = g->indexDataAsUShort(); - for (int i=0; i < count; ++i) { - int o = i * 4; - indices[0] = o; - indices[1] = o + 1; - indices[2] = o + 2; - indices[3] = o + 1; - indices[4] = o + 3; - indices[5] = o + 2; - indices += 6; - } - } - - } - - foreach (QSGGeometryNode* node, m_nodes){ - if (node == *(m_nodes.begin())) - node->setFlag(QSGGeometryNode::OwnsMaterial);//Root node owns the material for memory management purposes - else - (*(m_nodes.begin()))->appendChildNode(node); - } - - return *(m_nodes.begin()); -} - -QSGNode *QSGImageParticle::updatePaintNode(QSGNode *, UpdatePaintNodeData *) -{ - if (m_pleaseReset){ - m_lastLevel = perfLevel; - - delete m_rootNode;//Automatically deletes children, and SG manages material lifetime - m_rootNode = 0; - m_nodes.clear(); - - m_idxStarts.clear(); - m_lastIdxStart = 0; - - m_material = 0; - - m_pleaseReset = false; - } - - if (m_system && m_system->isRunning() && !m_system->isPaused()){ - prepareNextFrame(); - if (m_rootNode) { - update(); - foreach (QSGGeometryNode* node, m_nodes) - node->markDirty(QSGNode::DirtyGeometry); - } - } - - return m_rootNode; -} - -void QSGImageParticle::prepareNextFrame() -{ - if (m_rootNode == 0){//TODO: Staggered loading (as emitted) - m_rootNode = buildParticleNodes(); - if (m_rootNode == 0) - return; - if(m_debugMode){ - qDebug() << "QSGImageParticle Feature level: " << perfLevel; - qDebug() << "QSGImageParticle Nodes: "; - int count = 0; - foreach(int i, m_nodes.keys()){ - qDebug() << "Group " << i << " (" << m_system->groupData[i]->size() << " particles)"; - count += m_system->groupData[i]->size(); - } - qDebug() << "Total count: " << count; - } - } - qint64 timeStamp = m_system->systemSync(this); - - qreal time = timeStamp / 1000.; - - switch (perfLevel){//Fall-through intended - case Sprites: - //Advance State - m_spriteEngine->updateSprites(timeStamp); - foreach (const QString &str, m_groups){ - int gIdx = m_system->groupIds[str]; - int count = m_system->groupData[gIdx]->size(); - - Vertices* particles = (Vertices *) m_nodes[gIdx]->geometry()->vertexData(); - for (int i=0; i < count; i++){ - int spriteIdx = m_idxStarts[gIdx] + i; - Vertices &p = particles[i]; - int curY = m_spriteEngine->spriteY(spriteIdx);//Y is fixed per sprite row, used to distinguish rows here - if (curY != p.v1.animY){ - p.v1.animT = p.v2.animT = p.v3.animT = p.v4.animT = m_spriteEngine->spriteStart(spriteIdx)/1000.0; - p.v1.frameCount = p.v2.frameCount = p.v3.frameCount = p.v4.frameCount = m_spriteEngine->spriteFrames(spriteIdx); - p.v1.frameDuration = p.v2.frameDuration = p.v3.frameDuration = p.v4.frameDuration = m_spriteEngine->spriteDuration(spriteIdx); - p.v1.animX = p.v2.animX = p.v3.animX = p.v4.animX = m_spriteEngine->spriteX(spriteIdx); - p.v1.animY = p.v2.animY = p.v3.animY = p.v4.animY = m_spriteEngine->spriteY(spriteIdx); - p.v1.animWidth = p.v2.animWidth = p.v3.animWidth = p.v4.animWidth = m_spriteEngine->spriteWidth(spriteIdx); - p.v1.animHeight = p.v2.animHeight = p.v3.animHeight = p.v4.animHeight = m_spriteEngine->spriteHeight(spriteIdx); - } - } - } - case Tabled: - case Deformable: - case Colored: - case Simple: - default: //Also Simple - getState(m_material)->timestamp = time; - break; - } - - foreach (QSGGeometryNode* node, m_nodes) - node->markDirty(QSGNode::DirtyMaterial); -} - -void QSGImageParticle::reloadColor(const Color4ub &c, QSGParticleData* d) -{ - d->color = c; - //TODO: get index for reload - or make function take an index -} - -void QSGImageParticle::initialize(int gIdx, int pIdx) -{ - Color4ub color; - QSGParticleData* datum = m_system->groupData[gIdx]->data[pIdx]; - qreal redVariation = m_color_variation + m_redVariation; - qreal greenVariation = m_color_variation + m_greenVariation; - qreal blueVariation = m_color_variation + m_blueVariation; - int spriteIdx = m_idxStarts[gIdx] + datum->index; - float rotation; - float rotationSpeed; - float autoRotate; - switch (perfLevel){//Fall-through is intended on all of them - case Sprites: - // Initial Sprite State - if (m_explicitAnimation){ - if (!datum->animationOwner) - datum->animationOwner = this; - QSGParticleData* writeTo = (datum->animationOwner == this ? datum : getShadowDatum(datum)); - writeTo->animT = writeTo->t; - //writeTo->animInterpolate = m_spritesInterpolate; - if (m_spriteEngine){ - m_spriteEngine->start(spriteIdx); - writeTo->frameCount = m_spriteEngine->spriteFrames(spriteIdx); - writeTo->frameDuration = m_spriteEngine->spriteDuration(spriteIdx); - writeTo->animX = m_spriteEngine->spriteX(spriteIdx); - writeTo->animY = m_spriteEngine->spriteY(spriteIdx); - writeTo->animWidth = m_spriteEngine->spriteWidth(spriteIdx); - writeTo->animHeight = m_spriteEngine->spriteHeight(spriteIdx); - }else{ - writeTo->frameCount = 1; - writeTo->frameDuration = 9999; - writeTo->animX = writeTo->animY = writeTo->animWidth = writeTo->animHeight = 0; - } - } - case Tabled: - case Deformable: - //Initial Rotation - if (m_explicitDeformation){ - if (!datum->deformationOwner) - datum->deformationOwner = this; - if (m_xVector){ - const QPointF &ret = m_xVector->sample(QPointF(datum->x, datum->y)); - if (datum->deformationOwner == this) { - datum->xx = ret.x(); - datum->xy = ret.y(); - } else { - getShadowDatum(datum)->xx = ret.x(); - getShadowDatum(datum)->xy = ret.y(); - } - } - if (m_yVector){ - const QPointF &ret = m_yVector->sample(QPointF(datum->x, datum->y)); - if (datum->deformationOwner == this) { - datum->yx = ret.x(); - datum->yy = ret.y(); - } else { - getShadowDatum(datum)->yx = ret.x(); - getShadowDatum(datum)->yy = ret.y(); - } - } - } - - if (m_explicitRotation){ - if (!datum->rotationOwner) - datum->rotationOwner = this; - rotation = - (m_rotation + (m_rotationVariation - 2*((qreal)rand()/RAND_MAX)*m_rotationVariation) ) * CONV; - rotationSpeed = - (m_rotationSpeed + (m_rotationSpeedVariation - 2*((qreal)rand()/RAND_MAX)*m_rotationSpeedVariation) ) * CONV; - autoRotate = m_autoRotation?1.0:0.0; - if (datum->rotationOwner == this) { - datum->rotation = rotation; - datum->rotationSpeed = rotationSpeed; - datum->autoRotate = autoRotate; - } else { - getShadowDatum(datum)->rotation = rotation; - getShadowDatum(datum)->rotationSpeed = rotationSpeed; - getShadowDatum(datum)->autoRotate = autoRotate; - } - } - case Colored: - //Color initialization - // Particle color - if (m_explicitColor) { - if (!datum->colorOwner) - datum->colorOwner = this; - color.r = m_color.red() * (1 - redVariation) + rand() % 256 * redVariation; - color.g = m_color.green() * (1 - greenVariation) + rand() % 256 * greenVariation; - color.b = m_color.blue() * (1 - blueVariation) + rand() % 256 * blueVariation; - color.a = m_alpha * m_color.alpha() * (1 - m_alphaVariation) + rand() % 256 * m_alphaVariation; - if (datum->colorOwner == this) - datum->color = color; - else - getShadowDatum(datum)->color = color; - } - default: - break; - } -} - -void QSGImageParticle::commit(int gIdx, int pIdx) -{ - if (m_pleaseReset) - return; - QSGGeometryNode *node = m_nodes[gIdx]; - if (!node) - return; - QSGParticleData* datum = m_system->groupData[gIdx]->data[pIdx]; - node->setFlag(QSGNode::OwnsGeometry, false); - SpriteVertex *spriteVertices = (SpriteVertex *) node->geometry()->vertexData(); - DeformableVertex *deformableVertices = (DeformableVertex *) node->geometry()->vertexData(); - ColoredVertex *coloredVertices = (ColoredVertex *) node->geometry()->vertexData(); - SimpleVertex *simpleVertices = (SimpleVertex *) node->geometry()->vertexData(); - switch (perfLevel){//No automatic fall through intended on this one - case Sprites: - spriteVertices += pIdx*4; - for (int i=0; i<4; i++){ - spriteVertices[i].x = datum->x - m_systemOffset.x(); - spriteVertices[i].y = datum->y - m_systemOffset.y(); - spriteVertices[i].t = datum->t; - spriteVertices[i].lifeSpan = datum->lifeSpan; - spriteVertices[i].size = datum->size; - spriteVertices[i].endSize = datum->endSize; - spriteVertices[i].vx = datum->vx; - spriteVertices[i].vy = datum->vy; - spriteVertices[i].ax = datum->ax; - spriteVertices[i].ay = datum->ay; - if (m_explicitDeformation && datum->deformationOwner != this) { - QSGParticleData* shadow = getShadowDatum(datum); - spriteVertices[i].xx = shadow->xx; - spriteVertices[i].xy = shadow->xy; - spriteVertices[i].yx = shadow->yx; - spriteVertices[i].yy = shadow->yy; - } else { - spriteVertices[i].xx = datum->xx; - spriteVertices[i].xy = datum->xy; - spriteVertices[i].yx = datum->yx; - spriteVertices[i].yy = datum->yy; - } - if (m_explicitRotation && datum->rotationOwner != this) { - QSGParticleData* shadow = getShadowDatum(datum); - spriteVertices[i].rotation = shadow->rotation; - spriteVertices[i].rotationSpeed = shadow->rotationSpeed; - spriteVertices[i].autoRotate = shadow->autoRotate; - } else { - spriteVertices[i].rotation = datum->rotation; - spriteVertices[i].rotationSpeed = datum->rotationSpeed; - spriteVertices[i].autoRotate = datum->autoRotate; - } - spriteVertices[i].animInterpolate = m_spritesInterpolate ? 1.0 : 0.0;//### Shadow? In particleData? Or uniform? - if (m_explicitAnimation && datum->animationOwner != this) { - QSGParticleData* shadow = getShadowDatum(datum); - spriteVertices[i].frameDuration = shadow->frameDuration; - spriteVertices[i].frameCount = shadow->frameCount; - spriteVertices[i].animT = shadow->animT; - spriteVertices[i].animX = shadow->animX; - spriteVertices[i].animY = shadow->animY; - spriteVertices[i].animWidth = shadow->animWidth; - spriteVertices[i].animHeight = shadow->animHeight; - } else { - spriteVertices[i].frameDuration = datum->frameDuration; - spriteVertices[i].frameCount = datum->frameCount; - spriteVertices[i].animT = datum->animT; - spriteVertices[i].animX = datum->animX; - spriteVertices[i].animY = datum->animY; - spriteVertices[i].animWidth = datum->animWidth; - spriteVertices[i].animHeight = datum->animHeight; - } - if (m_explicitColor && datum->colorOwner != this) { - QSGParticleData* shadow = getShadowDatum(datum); - spriteVertices[i].color.r = shadow->color.r; - spriteVertices[i].color.g = shadow->color.g; - spriteVertices[i].color.b = shadow->color.b; - spriteVertices[i].color.a = shadow->color.a; - } else { - spriteVertices[i].color.r = datum->color.r; - spriteVertices[i].color.g = datum->color.g; - spriteVertices[i].color.b = datum->color.b; - spriteVertices[i].color.a = datum->color.a; - } - } - break; - case Tabled: //Fall through until it has its own vertex class - case Deformable: - deformableVertices += pIdx*4; - for (int i=0; i<4; i++){ - deformableVertices[i].x = datum->x - m_systemOffset.x(); - deformableVertices[i].y = datum->y - m_systemOffset.y(); - deformableVertices[i].t = datum->t; - deformableVertices[i].lifeSpan = datum->lifeSpan; - deformableVertices[i].size = datum->size; - deformableVertices[i].endSize = datum->endSize; - deformableVertices[i].vx = datum->vx; - deformableVertices[i].vy = datum->vy; - deformableVertices[i].ax = datum->ax; - deformableVertices[i].ay = datum->ay; - if (m_explicitDeformation && datum->deformationOwner != this) { - QSGParticleData* shadow = getShadowDatum(datum); - deformableVertices[i].xx = shadow->xx; - deformableVertices[i].xy = shadow->xy; - deformableVertices[i].yx = shadow->yx; - deformableVertices[i].yy = shadow->yy; - } else { - deformableVertices[i].xx = datum->xx; - deformableVertices[i].xy = datum->xy; - deformableVertices[i].yx = datum->yx; - deformableVertices[i].yy = datum->yy; - } - if (m_explicitRotation && datum->rotationOwner != this) { - QSGParticleData* shadow = getShadowDatum(datum); - deformableVertices[i].rotation = shadow->rotation; - deformableVertices[i].rotationSpeed = shadow->rotationSpeed; - deformableVertices[i].autoRotate = shadow->autoRotate; - } else { - deformableVertices[i].rotation = datum->rotation; - deformableVertices[i].rotationSpeed = datum->rotationSpeed; - deformableVertices[i].autoRotate = datum->autoRotate; - } - if (m_explicitColor && datum->colorOwner != this) { - QSGParticleData* shadow = getShadowDatum(datum); - deformableVertices[i].color.r = shadow->color.r; - deformableVertices[i].color.g = shadow->color.g; - deformableVertices[i].color.b = shadow->color.b; - deformableVertices[i].color.a = shadow->color.a; - } else { - deformableVertices[i].color.r = datum->color.r; - deformableVertices[i].color.g = datum->color.g; - deformableVertices[i].color.b = datum->color.b; - deformableVertices[i].color.a = datum->color.a; - } - } - break; - case Colored: - coloredVertices += pIdx*1; - for (int i=0; i<1; i++){ - coloredVertices[i].x = datum->x - m_systemOffset.x(); - coloredVertices[i].y = datum->y - m_systemOffset.y(); - coloredVertices[i].t = datum->t; - coloredVertices[i].lifeSpan = datum->lifeSpan; - coloredVertices[i].size = datum->size; - coloredVertices[i].endSize = datum->endSize; - coloredVertices[i].vx = datum->vx; - coloredVertices[i].vy = datum->vy; - coloredVertices[i].ax = datum->ax; - coloredVertices[i].ay = datum->ay; - if (m_explicitColor && datum->colorOwner != this) { - QSGParticleData* shadow = getShadowDatum(datum); - coloredVertices[i].color.r = shadow->color.r; - coloredVertices[i].color.g = shadow->color.g; - coloredVertices[i].color.b = shadow->color.b; - coloredVertices[i].color.a = shadow->color.a; - } else { - coloredVertices[i].color.r = datum->color.r; - coloredVertices[i].color.g = datum->color.g; - coloredVertices[i].color.b = datum->color.b; - coloredVertices[i].color.a = datum->color.a; - } - } - break; - case Simple: - simpleVertices += pIdx*1; - for (int i=0; i<1; i++){ - simpleVertices[i].x = datum->x - m_systemOffset.x(); - simpleVertices[i].y = datum->y - m_systemOffset.y(); - simpleVertices[i].t = datum->t; - simpleVertices[i].lifeSpan = datum->lifeSpan; - simpleVertices[i].size = datum->size; - simpleVertices[i].endSize = datum->endSize; - simpleVertices[i].vx = datum->vx; - simpleVertices[i].vy = datum->vy; - simpleVertices[i].ax = datum->ax; - simpleVertices[i].ay = datum->ay; - } - break; - default: - break; - } - - node->setFlag(QSGNode::OwnsGeometry, true); -} - - - -QT_END_NAMESPACE diff --git a/src/declarative/particles/qsgimageparticle_p.h b/src/declarative/particles/qsgimageparticle_p.h deleted file mode 100644 index 0836e3e8ec..0000000000 --- a/src/declarative/particles/qsgimageparticle_p.h +++ /dev/null @@ -1,432 +0,0 @@ -/**************************************************************************** -** -** 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 ULTRAPARTICLE_H -#define ULTRAPARTICLE_H -#include "qsgparticlepainter_p.h" -#include "qsgdirection_p.h" -#include -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class ImageMaterialData; -class QSGGeometryNode; - -class QQuickSprite; -class QQuickStochasticEngine; - -struct SimpleVertex { - float x; - float y; - float t; - float lifeSpan; - float size; - float endSize; - float vx; - float vy; - float ax; - float ay; -}; - -struct ColoredVertex { - float x; - float y; - float t; - float lifeSpan; - float size; - float endSize; - float vx; - float vy; - float ax; - float ay; - Color4ub color; -}; - -struct DeformableVertex { - float x; - float y; - float tx; - float ty; - float t; - float lifeSpan; - float size; - float endSize; - float vx; - float vy; - float ax; - float ay; - Color4ub color; - float xx; - float xy; - float yx; - float yy; - float rotation; - float rotationSpeed; - float autoRotate;//Assumed that GPUs prefer floats to bools -}; - -struct SpriteVertex { - float x; - float y; - float tx; - float ty; - float t; - float lifeSpan; - float size; - float endSize; - float vx; - float vy; - float ax; - float ay; - Color4ub color; - float xx; - float xy; - float yx; - float yy; - float rotation; - float rotationSpeed; - float autoRotate;//Assumed that GPUs prefer floats to bools - float animInterpolate; - float frameDuration; - float frameCount; - float animT; - float animX; - float animY; - float animWidth; - float animHeight; -}; - -template -struct Vertices { - Vertex v1; - Vertex v2; - Vertex v3; - Vertex v4; -}; - -class QSGImageParticle : public QSGParticlePainter -{ - Q_OBJECT - Q_PROPERTY(QUrl source READ image WRITE setImage NOTIFY imageChanged) - Q_PROPERTY(QUrl colorTable READ colortable WRITE setColortable NOTIFY colortableChanged) - Q_PROPERTY(QUrl sizeTable READ sizetable WRITE setSizetable NOTIFY sizetableChanged) - 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 RESET resetColor) - //Stacks (added) with individual colorVariations - 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 RESET resetColor) - Q_PROPERTY(qreal alphaVariation READ alphaVariation WRITE setAlphaVariation NOTIFY alphaVariationChanged RESET resetColor) - - 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 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 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 RESET resetDeformation) - Q_PROPERTY(QDeclarativeListProperty sprites READ sprites) - Q_PROPERTY(bool spritesInterpolate READ spritesInterpolate WRITE setSpritesInterpolate NOTIFY spritesInterpolateChanged) - - Q_PROPERTY(EntryEffect entryEffect READ entryEffect WRITE setEntryEffect NOTIFY entryEffectChanged) - Q_PROPERTY(bool bloat READ bloat WRITE setBloat NOTIFY bloatChanged)//Just a debugging property to bypass optimizations - Q_ENUMS(EntryEffect) -public: - explicit QSGImageParticle(QQuickItem *parent = 0); - virtual ~QSGImageParticle(); - - - QDeclarativeListProperty sprites(); - QQuickStochasticEngine* spriteEngine() {return m_spriteEngine;} - - enum EntryEffect { - None = 0, - Fade = 1, - Scale = 2 - }; - - enum PerformanceLevel{//TODO: Expose? - Unknown = 0, - Simple, - Colored, - Deformable, - Tabled, - Sprites - }; - - QUrl image() const { return m_image_name; } - void setImage(const QUrl &image); - - QUrl colortable() const { return m_colortable_name; } - void setColortable(const QUrl &table); - - QUrl sizetable() const { return m_sizetable_name; } - void setSizetable (const QUrl &table); - - QUrl opacitytable() const { return m_opacitytable_name; } - void setOpacitytable(const QUrl &table); - - QColor color() const { return m_color; } - void setColor(const QColor &color); - - qreal colorVariation() const { return m_color_variation; } - void setColorVariation(qreal var); - - qreal renderOpacity() const { return m_render_opacity; } - - qreal alphaVariation() const { return m_alphaVariation; } - - qreal alpha() const { return m_alpha; } - - qreal redVariation() const { return m_redVariation; } - - qreal greenVariation() const { return m_greenVariation; } - - qreal blueVariation() const { return m_blueVariation; } - - qreal rotation() const { return m_rotation; } - - qreal rotationVariation() const { return m_rotationVariation; } - - qreal rotationSpeed() const { return m_rotationSpeed; } - - qreal rotationSpeedVariation() const { return m_rotationSpeedVariation; } - - bool autoRotation() const { return m_autoRotation; } - - QSGDirection* xVector() const { return m_xVector; } - - QSGDirection* yVector() const { return m_yVector; } - - bool spritesInterpolate() const { return m_spritesInterpolate; } - - bool bloat() const { return m_bloat; } - - EntryEffect entryEffect() const { return m_entryEffect; } - - void resetColor(); - void resetRotation(); - void resetDeformation(); - -signals: - - void imageChanged(); - void colortableChanged(); - void sizetableChanged(); - void opacitytableChanged(); - - void colorChanged(); - void colorVariationChanged(); - - void particleDurationChanged(); - void alphaVariationChanged(qreal arg); - - void alphaChanged(qreal arg); - - void redVariationChanged(qreal arg); - - void greenVariationChanged(qreal arg); - - void blueVariationChanged(qreal arg); - - void rotationChanged(qreal arg); - - void rotationVariationChanged(qreal arg); - - void rotationSpeedChanged(qreal arg); - - void rotationSpeedVariationChanged(qreal arg); - - void autoRotationChanged(bool arg); - - void xVectorChanged(QSGDirection* arg); - - void yVectorChanged(QSGDirection* arg); - - void spritesInterpolateChanged(bool arg); - - void bloatChanged(bool arg); - - void entryEffectChanged(EntryEffect arg); - -public slots: - void reloadColor(const Color4ub &c, QSGParticleData* d); - void setAlphaVariation(qreal arg); - - void setAlpha(qreal arg); - - void setRedVariation(qreal arg); - - void setGreenVariation(qreal arg); - - void setBlueVariation(qreal arg); - - void setRotation(qreal arg); - - void setRotationVariation(qreal arg); - - void setRotationSpeed(qreal arg); - - void setRotationSpeedVariation(qreal arg); - - void setAutoRotation(bool arg); - - void setXVector(QSGDirection* arg); - - void setYVector(QSGDirection* arg); - - void setSpritesInterpolate(bool arg); - - void setBloat(bool arg); - - void setEntryEffect(EntryEffect arg); - -protected: - void reset(); - virtual void initialize(int gIdx, int pIdx); - virtual void commit(int gIdx, int pIdx); - - QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *); - void prepareNextFrame(); - QSGGeometryNode* buildParticleNodes(); - -private slots: - void createEngine(); //### method invoked by sprite list changing (in engine.h) - pretty nasty - -private: - QUrl m_image_name; - QUrl m_colortable_name; - QUrl m_sizetable_name; - QUrl m_opacitytable_name; - - - QColor m_color; - qreal m_color_variation; - qreal m_particleDuration; - - QSGGeometryNode *m_rootNode; - QHash m_nodes; - QHash m_idxStarts;//TODO: Proper resizing will lead to needing a spriteEngine per particle - do this after sprite engine gains transparent sharing? - int m_lastIdxStart; - QSGMaterial *m_material; - - // derived values... - - qreal m_render_opacity; - qreal m_alphaVariation; - qreal m_alpha; - qreal m_redVariation; - qreal m_greenVariation; - qreal m_blueVariation; - qreal m_rotation; - qreal m_rotationVariation; - qreal m_rotationSpeed; - qreal m_rotationSpeedVariation; - bool m_autoRotation; - QSGDirection* m_xVector; - QSGDirection* m_yVector; - - QList m_sprites; - QQuickSpriteEngine* m_spriteEngine; - bool m_spritesInterpolate; - - bool m_explicitColor; - bool m_explicitRotation; - bool m_explicitDeformation; - bool m_explicitAnimation; - QHash > m_shadowData; - bool m_shadowInit; - void clearShadows(); - QSGParticleData* getShadowDatum(QSGParticleData* datum); - - bool m_bloat; - PerformanceLevel perfLevel; - - PerformanceLevel m_lastLevel; - bool m_debugMode; - - template - void initTexCoords(Vertex* v, int count){ - Vertex* end = v + count; - while (v < end){ - v[0].tx = 0; - v[0].ty = 0; - - v[1].tx = 1; - v[1].ty = 0; - - v[2].tx = 0; - v[2].ty = 1; - - v[3].tx = 1; - v[3].ty = 1; - - v += 4; - } - } - - template - MaterialData* getState(QSGMaterial* m){ - return static_cast *>(m)->state(); - } - EntryEffect m_entryEffect; -}; - -QT_END_NAMESPACE -QT_END_HEADER -#endif // ULTRAPARTICLE_H diff --git a/src/declarative/particles/qsgitemparticle.cpp b/src/declarative/particles/qsgitemparticle.cpp deleted file mode 100644 index 3be40dcaa1..0000000000 --- a/src/declarative/particles/qsgitemparticle.cpp +++ /dev/null @@ -1,268 +0,0 @@ -/**************************************************************************** -** -** 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 "qsgitemparticle_p.h" -#include -#include -#include -#include -#include - -QT_BEGIN_NAMESPACE - -/*! - \qmlclass ItemParticle QQuickItemParticle - \inqmlmodule QtQuick.Particles 2 - \inherits ParticlePainter - \brief The ItemParticle element allows you to specify your own delegate to paint particles. - -*/ - - -/*! - \qmlmethod void QtQuick.Particles2::ItemParticle::freeze(Item item) - - Suspends the flow of time for the logical particle which item represents, allowing you to control its movement. -*/ - -/*! - \qmlmethod void QtQuick.Particles2::ItemParticle::unfreeze(Item item) - - Restarts the flow of time for the logical particle which item represents, allowing it to be moved by the particle system again. -*/ - -/*! - \qmlmethod void QtQuick.Particles2::ItemParticle::take(Item item, bool prioritize) - - Asks the ItemParticle to take over control of item. It will be emitted when there is a logical particle available. - - By default items form a queue when waiting for a logical particle, but if prioritize is true then it will go immediately to the - head of the queue. -*/ -/*! - \qmlmethod void QtQuick.Particles2::ItemParticle::give(Item item) - - Orders the ItemParticle to give you control of the item. It will cease controlling it and the item will lose its association to the logical particle. -*/ - -/*! - \qmlproperty bool QtQuick.Particles2::ItemParticle::fade - - If true, the item will automatically be faded in and out - at the ends of its lifetime. If false, you will have to - implement any entry effect yourself. - - Default is true. -*/ -/*! - \qmlproperty Component QtQuick.Particles2::ItemParticle::delegate - - An instance of the delegate will be created for every logical - particle, and moved along with it. -*/ - -QQuickItemParticle::QQuickItemParticle(QQuickItem *parent) : - QSGParticlePainter(parent), m_fade(true), m_delegate(0) -{ - setFlag(QQuickItem::ItemHasContents); - QTimer* manageDelegates = new QTimer(this);//TODO: don't leak - connect(manageDelegates, SIGNAL(timeout()), - this, SLOT(tick())); - manageDelegates->setInterval(16); - manageDelegates->setSingleShot(false); - manageDelegates->start(); -} - - -void QQuickItemParticle::freeze(QQuickItem* item) -{ - m_stasis << item; -} - - -void QQuickItemParticle::unfreeze(QQuickItem* item) -{ - m_stasis.remove(item); -} - -void QQuickItemParticle::take(QQuickItem *item, bool prioritize) -{ - if (prioritize) - m_pendingItems.push_front(item); - else - m_pendingItems.push_back(item); -} - -void QQuickItemParticle::give(QQuickItem *item) -{ - //TODO: This -} - -void QQuickItemParticle::initialize(int gIdx, int pIdx) -{ - m_loadables << m_system->groupData[gIdx]->data[pIdx];//defer to other thread -} - -void QQuickItemParticle::commit(int, int) -{ -} - -void QQuickItemParticle::tick() -{ - foreach (QQuickItem* item, m_deletables){ - if (m_fade) - item->setOpacity(0.); - item->setVisible(false); - QQuickItemParticleAttached* mpa; - if ((mpa = qobject_cast(qmlAttachedPropertiesObject(item)))) - mpa->detach();//reparent as well? - //TODO: Delete iff we created it - m_activeCount--; - } - m_deletables.clear(); - - foreach (QSGParticleData* d, m_loadables){ - if (m_stasis.contains(d->delegate)) - qWarning() << "Current model particles prefers overwrite:false"; - //remove old item from the particle that is dying to make room for this one - if (d->delegate) - m_deletables << d->delegate; - d->delegate = 0; - if (!m_pendingItems.isEmpty()){ - d->delegate = m_pendingItems.front(); - m_pendingItems.pop_front(); - }else if (m_delegate){ - d->delegate = qobject_cast(m_delegate->create(qmlContext(this))); - } - if (d->delegate && d){//###Data can be zero if creating an item leads to a reset - this screws things up. - d->delegate->setX(d->curX() - d->delegate->width()/2);//TODO: adjust for system? - d->delegate->setY(d->curY() - d->delegate->height()/2); - QQuickItemParticleAttached* mpa = qobject_cast(qmlAttachedPropertiesObject(d->delegate)); - if (mpa){ - mpa->m_mp = this; - mpa->attach(); - } - d->delegate->setParentItem(this); - if (m_fade) - d->delegate->setOpacity(0.); - d->delegate->setVisible(false);//Will be set to true when we prepare the next frame - m_activeCount++; - } - } - m_loadables.clear(); -} - -void QQuickItemParticle::reset() -{ - QSGParticlePainter::reset(); - //TODO: Cleanup items? - m_loadables.clear(); - //deletables? -} - - -QSGNode* QQuickItemParticle::updatePaintNode(QSGNode* n, UpdatePaintNodeData* d) -{ - //Dummy update just to get painting tick - if (m_pleaseReset){ - m_pleaseReset = false; - reset(); - } - prepareNextFrame(); - - update();//Get called again - if (n) - n->markDirty(QSGNode::DirtyMaterial); - return QQuickItem::updatePaintNode(n,d); -} - -void QQuickItemParticle::prepareNextFrame() -{ - if (!m_system) - return; - qint64 timeStamp = m_system->systemSync(this); - qreal curT = timeStamp/1000.0; - qreal dt = curT - m_lastT; - m_lastT = curT; - if (!m_activeCount) - return; - - //TODO: Size, better fade? - foreach (const QString &str, m_groups){ - int gIdx = m_system->groupIds[str]; - int count = m_system->groupData[gIdx]->size(); - - for (int i=0; igroupData[gIdx]->data[i]; - QQuickItem* item = data->delegate; - if (!item) - continue; - qreal t = ((timeStamp/1000.0) - data->t) / data->lifeSpan; - if (m_stasis.contains(item)) { - data->t += dt;//Stasis effect - continue; - } - if (t >= 1.0){//Usually happens from load - m_deletables << item; - data->delegate = 0; - }else{//Fade - data->delegate->setVisible(true); - if (m_fade){ - qreal o = 1.; - if (t<0.2) - o = t*5; - if (t>0.8) - o = (1-t)*5; - item->setOpacity(o); - } - } - item->setX(data->curX() - item->width()/2 - m_systemOffset.x()); - item->setY(data->curY() - item->height()/2 - m_systemOffset.y()); - } - } -} - -QQuickItemParticleAttached *QQuickItemParticle::qmlAttachedProperties(QObject *object) -{ - return new QQuickItemParticleAttached(object); -} - -QT_END_NAMESPACE diff --git a/src/declarative/particles/qsgitemparticle_p.h b/src/declarative/particles/qsgitemparticle_p.h deleted file mode 100644 index 813f1ced79..0000000000 --- a/src/declarative/particles/qsgitemparticle_p.h +++ /dev/null @@ -1,138 +0,0 @@ -/**************************************************************************** -** -** 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 ITEMPARTICLE_H -#define ITEMPARTICLE_H -#include "qsgparticlepainter_p.h" -#include -#include -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) -class QQuickVisualDataModel; -class QQuickItemParticleAttached; - -class QQuickItemParticle : public QSGParticlePainter -{ - Q_OBJECT - Q_PROPERTY(bool fade READ fade WRITE setFade NOTIFY fadeChanged) - Q_PROPERTY(QDeclarativeComponent* delegate READ delegate WRITE setDelegate NOTIFY delegateChanged) -public: - explicit QQuickItemParticle(QQuickItem *parent = 0); - - bool fade() const { return m_fade; } - - virtual QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *); - - static QQuickItemParticleAttached *qmlAttachedProperties(QObject *object); - QDeclarativeComponent* delegate() const - { - return m_delegate; - } - -signals: - void fadeChanged(); - - void delegateChanged(QDeclarativeComponent* arg); - -public slots: - //TODO: Add a follow mode, where moving the delegate causes the logical particle to go with it? - void freeze(QQuickItem* item); - void unfreeze(QQuickItem* item); - void take(QQuickItem* item,bool prioritize=false);//take by modelparticle - void give(QQuickItem* item);//give from modelparticle - - void setFade(bool arg){if (arg == m_fade) return; m_fade = arg; emit fadeChanged();} - void setDelegate(QDeclarativeComponent* arg) - { - if (m_delegate != arg) { - m_delegate = arg; - emit delegateChanged(arg); - } - } - -protected: - virtual void reset(); - virtual void commit(int gIdx, int pIdx); - virtual void initialize(int gIdx, int pIdx); - void prepareNextFrame(); -private slots: - void tick(); -private: - QList m_deletables; - QList< QSGParticleData* > m_loadables; - bool m_fade; - - QList m_pendingItems; - QList m_available; - QSet m_stasis; - qreal m_lastT; - int m_activeCount; - QDeclarativeComponent* m_delegate; -}; - -class QQuickItemParticleAttached : public QObject -{ - Q_OBJECT - Q_PROPERTY(QQuickItemParticle* particle READ particle CONSTANT); -public: - QQuickItemParticleAttached(QObject* parent) - : QObject(parent), m_mp(0) - {;} - QQuickItemParticle* particle() {return m_mp;} - void detach(){emit detached();} - void attach(){emit attached();} -private: - QQuickItemParticle* m_mp; - friend class QQuickItemParticle; -Q_SIGNALS: - void detached(); - void attached(); -}; - -QT_END_NAMESPACE - -QML_DECLARE_TYPEINFO(QQuickItemParticle, QML_HAS_ATTACHED_PROPERTIES) - -QT_END_HEADER -#endif // ITEMPARTICLE_H diff --git a/src/declarative/particles/qsglineextruder.cpp b/src/declarative/particles/qsglineextruder.cpp deleted file mode 100644 index 6581cf23ee..0000000000 --- a/src/declarative/particles/qsglineextruder.cpp +++ /dev/null @@ -1,84 +0,0 @@ -/**************************************************************************** -** -** 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 "qsglineextruder_p.h" -#include - -/*! - \qmlclass LineShape QSGLineExtruder - \inqmlmodule QtQuick.Particles 2 - \inherits Shape - \brief The LineShape represents a line to Affectors and Emitter - -*/ - -/*! - \qmlproperty bool QtQuick.Particles2::LineShape::mirrored - - By default, the line goes from (0,0) to (width, height) of the item that - this shape is being applied to. - - If mirrored is set to true, this will be mirrored along the y axis. - The line will then go from (0,height) to (width, 0). -*/ - -QSGLineExtruder::QSGLineExtruder(QObject *parent) : - QSGParticleExtruder(parent), m_mirrored(false) -{ -} - -QPointF QSGLineExtruder::extrude(const QRectF &r) -{ - qreal x,y; - if (!r.height()){ - x = r.width() * ((qreal)rand())/RAND_MAX; - y = 0; - }else{ - y = r.height() * ((qreal)rand())/RAND_MAX; - if (!r.width()){ - x = 0; - }else{ - x = r.width()/r.height() * y; - if (m_mirrored) - x = r.width() - x; - } - } - return QPointF(x,y); -} diff --git a/src/declarative/particles/qsglineextruder_p.h b/src/declarative/particles/qsglineextruder_p.h deleted file mode 100644 index f1f9cf85ec..0000000000 --- a/src/declarative/particles/qsglineextruder_p.h +++ /dev/null @@ -1,77 +0,0 @@ -/**************************************************************************** -** -** 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 LINEEXTRUDER_H -#define LINEEXTRUDER_H -#include "qsgparticleextruder_p.h" - -class QSGLineExtruder : public QSGParticleExtruder -{ - Q_OBJECT - //Default is topleft to bottom right. Flipped makes it topright to bottom left - Q_PROPERTY(bool mirrored READ mirrored WRITE setmirrored NOTIFY mirroredChanged) - -public: - explicit QSGLineExtruder(QObject *parent = 0); - virtual QPointF extrude(const QRectF &); - bool mirrored() const - { - return m_mirrored; - } - -signals: - - void mirroredChanged(bool arg); - -public slots: - - void setmirrored(bool arg) - { - if (m_mirrored != arg) { - m_mirrored = arg; - emit mirroredChanged(arg); - } - } -private: - bool m_mirrored; -}; - -#endif // LINEEXTRUDER_H diff --git a/src/declarative/particles/qsgmaskextruder.cpp b/src/declarative/particles/qsgmaskextruder.cpp deleted file mode 100644 index 6facfac353..0000000000 --- a/src/declarative/particles/qsgmaskextruder.cpp +++ /dev/null @@ -1,113 +0,0 @@ -/**************************************************************************** -** -** 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 "qsgmaskextruder_p.h" -#include -#include -QT_BEGIN_NAMESPACE -/*! - \qmlclass MaskShape QSGMaskExtruder - \inqmlmodule QtQuick.Particles 2 - \inherits Shape - \brief The MaskShape element allows you to represent an image as a shape to affectors and emitters. - -*/ -/*! - \qmlproperty url QtQuick.Particles2::MaskShape::source - - The image to use as the mask. Areas with non-zero opacity - will be considered inside the shape. -*/ - - -QSGMaskExtruder::QSGMaskExtruder(QObject *parent) : - QSGParticleExtruder(parent) - , m_lastWidth(-1) - , m_lastHeight(-1) -{ -} - -QPointF QSGMaskExtruder::extrude(const QRectF &r) -{ - ensureInitialized(r); - if (!m_mask.count() || m_img.isNull()) - return r.topLeft(); - const QPointF p = m_mask[rand() % m_mask.count()]; - //### Should random sub-pixel positioning be added? - return p + r.topLeft(); -} - -bool QSGMaskExtruder::contains(const QRectF &bounds, const QPointF &point) -{ - ensureInitialized(bounds);//###Current usage patterns WILL lead to different bounds/r calls. Separate list? - if (m_img.isNull()) - return false; - QPoint p = point.toPoint() - bounds.topLeft().toPoint(); - return m_img.rect().contains(p) && (bool)m_img.pixelIndex(p); -} - -void QSGMaskExtruder::ensureInitialized(const QRectF &r) -{ - if (m_lastWidth == r.width() && m_lastHeight == r.height()) - return;//Same as before - m_lastWidth = r.width(); - m_lastHeight = r.height(); - - m_img = QImage(); - m_mask.clear(); - if (m_source.isEmpty()) - return; - m_img = QImage(m_source.toLocalFile()); - if (m_img.isNull()){ - qWarning() << "MaskShape: Cannot load" << qPrintable(m_source.toLocalFile()); - return; - } - m_img = m_img.createAlphaMask(); - m_img = m_img.convertToFormat(QImage::Format_Mono);//Else LSB, but I think that's easier - m_img = m_img.scaled(r.size().toSize());//TODO: Do they need aspect ratio stuff? Or tiling? - for (int i=0; i -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QSGMaskExtruder : public QSGParticleExtruder -{ - Q_OBJECT - Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged) -public: - explicit QSGMaskExtruder(QObject *parent = 0); - virtual QPointF extrude(const QRectF &); - virtual bool contains(const QRectF &bounds, const QPointF &point); - - QUrl source() const - { - return m_source; - } - -signals: - - void sourceChanged(QUrl arg); - -public slots: - - void setSource(QUrl arg) - { - if (m_source != arg) { - m_source = arg; - m_lastHeight = -1;//Trigger reset - m_lastWidth = -1; - emit sourceChanged(arg); - } - } -private: - QUrl m_source; - - void ensureInitialized(const QRectF &r); - int m_lastWidth; - int m_lastHeight; - QImage m_img; - QList m_mask;//TODO: More memory efficient datastructures -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // MASKEXTRUDER_H diff --git a/src/declarative/particles/qsgparticleaffector.cpp b/src/declarative/particles/qsgparticleaffector.cpp deleted file mode 100644 index 9d633aa900..0000000000 --- a/src/declarative/particles/qsgparticleaffector.cpp +++ /dev/null @@ -1,278 +0,0 @@ -/**************************************************************************** -** -** 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 "qsgparticleaffector_p.h" -#include -QT_BEGIN_NAMESPACE - -/*! - \qmlclass Affector QSGParticleAffector - \inqmlmodule QtQuick.Particles 2 - \brief Affector elements can alter the attributes of logical particles at any point in their lifetime. - - The base Affector does not alter any attributes, but can be used to emit a signal - when a particle meets certain conditions. - - If an affector has a defined size, then it will only affect particles within its size and position on screen. - - Affectors have different performance characteristics to the other particle system elements. In particular, - they have some simplifications to try to maintain a simulation at real-time or faster. When running a system - with Affectors, irregular frame timings that grow too large ( > one second per frame) will cause the Affectors - to try and cut corners with a faster but less accurate simulation. If the system has multiple affectors the order - in which they are applied is not guaranteed, and when simulating larger time shifts they will simulate the whole - shift each, which can lead to different results compared to smaller time shifts. - - Accurate simulation for large numbers of particles (hundreds) with multiple affectors may be possible on some hardware, - but on less capable hardware you should expect small irregularties in the simulation as simulates with worse granularity. -*/ -/*! - \qmlproperty ParticleSystem QtQuick.Particles2::Affector::system - This is the system which will be affected by the element. - If the Affector is a direct child of a ParticleSystem, it will automatically be associated with it. -*/ -/*! - \qmlproperty list QtQuick.Particles2::Affector::groups - Which logical particle groups will be affected. - - If empty, it will affect all particles. -*/ -/*! - \qmlproperty list QtQuick.Particles2::Affector::whenCollidingWith - If any logical particle groups are specified here, then the affector - will only be triggered if the particle being examined intersects with - a particle of one of these groups. - - This is different from the groups property. The groups property selects which - particles might be examined, and if they meet other criteria (including being - within the bounds of the Affector, modified by shape) then they will be tested - again to see if they intersect with a particles from one of the particle groups - in whenCollidingWith. - - By default, no groups are specified. -*/ -/*! - \qmlproperty bool QtQuick.Particles2::Affector::enabled - If enabled is set to false, this affector will not affect any particles. - - Usually this is used to conditionally turn an affector on or off. - - Default value is true. -*/ -/*! - \qmlproperty bool QtQuick.Particles2::Affector::once - If once is set to true, this affector will only affect each particle - once in their lifetimes. If the affector normally simulates a continuous - effect over time, then it will simulate the effect of one second of time - the one instant it affects the particle. - - Default value is false. -*/ -/*! - \qmlproperty Shape QtQuick.Particles2::Affector::shape - If a size has been defined, the shape property can be used to affect a - non-rectangular area. -*/ -/*! - \qmlsignal QtQuick.Particles2::Affector::onAffected(x, y) - - This signal is emitted each time the affector actually affects a particle. - - x,y are the coordinates of the affected particle, relative to the ParticleSystem. - -*/ - -/*! - \qmlsignal QtQuick.Particles2::Affector::affectParticle(particle particle, real dt) - - This handler is called when particles are selected to be affected. - - dt is the time since the last time it was affected. Use dt to normalize - trajectory manipulations to real time. - - Note that JS is slower to execute, so it is not recommended to use this in - high-volume particle systems. -*/ -/*! - \qmlsignal QtQuick.Particles2::Affector::affected(real x, real y) - - This handler is called when a particle is selected to be affected. It will - only be called if signal is set to true. - - x,y is the particles current position. -*/ -QSGParticleAffector::QSGParticleAffector(QQuickItem *parent) : - QQuickItem(parent), m_needsReset(false), m_ignoresTime(false), m_onceOff(false), m_enabled(true) - , m_system(0), m_updateIntSet(false), m_shape(new QSGParticleExtruder(this)) -{ -} - -bool QSGParticleAffector::isAffectedConnected() -{ - static int idx = QObjectPrivate::get(this)->signalIndex("affected(qreal,qreal)"); - return QObjectPrivate::get(this)->isSignalConnected(idx); -} - - -void QSGParticleAffector::componentComplete() -{ - if (!m_system && qobject_cast(parentItem())) - setSystem(qobject_cast(parentItem())); - QQuickItem::componentComplete(); -} - -bool QSGParticleAffector::activeGroup(int g) { - if (m_updateIntSet){ - m_groupIds.clear(); - foreach (const QString &p, m_groups) - m_groupIds << m_system->groupIds[p];//###Can this occur before group ids are properly assigned? - m_updateIntSet = false; - } - return m_groupIds.isEmpty() || m_groupIds.contains(g); -} - -bool QSGParticleAffector::shouldAffect(QSGParticleData* d) -{ - if (!d) - return false; - if (activeGroup(d->group)){ - if ((m_onceOff && m_onceOffed.contains(qMakePair(d->group, d->index))) - || !d->stillAlive()) - return false; - //Need to have previous location for affected anyways - if (width() == 0 || height() == 0 - || m_shape->contains(QRectF(m_offset.x(), m_offset.y(), width(), height()), QPointF(d->curX(), d->curY()))){ - if (m_whenCollidingWith.isEmpty() || isColliding(d)){ - return true; - } - } - } - return false; - -} - -void QSGParticleAffector::postAffect(QSGParticleData* d) -{ - m_system->needsReset << d; - if (m_onceOff) - m_onceOffed << qMakePair(d->group, d->index); - if (isAffectedConnected()) - emit affected(d->curX(), d->curY()); -} - -const qreal QSGParticleAffector::simulationDelta = 0.020; -const qreal QSGParticleAffector::simulationCutoff = 1.000;//If this goes above 1.0, then m_once behaviour needs special codepath - -void QSGParticleAffector::affectSystem(qreal dt) -{ - if (!m_enabled) - return; - //If not reimplemented, calls affectParticle per particle - //But only on particles in targeted system/area - updateOffsets();//### Needed if an ancestor is transformed. - if (m_onceOff) - dt = 1.0; - foreach (QSGParticleGroupData* gd, m_system->groupData) { - if (activeGroup(m_system->groupData.key(gd))) { - foreach (QSGParticleData* d, gd->data) { - if (shouldAffect(d)) { - bool affected = false; - qreal myDt = dt; - if (!m_ignoresTime && myDt < simulationCutoff) { - int realTime = m_system->timeInt; - m_system->timeInt -= myDt * 1000.0; - while (myDt > simulationDelta) { - m_system->timeInt += simulationDelta * 1000.0; - affected = affectParticle(d, simulationDelta) || affected; - myDt -= simulationDelta; - } - m_system->timeInt = realTime; - } - if (myDt > 0.0) - affected = affectParticle(d, myDt) || affected; - if (affected) - postAffect(d); - } - } - } - } -} - -bool QSGParticleAffector::affectParticle(QSGParticleData *, qreal ) -{ - return true; -} - -void QSGParticleAffector::reset(QSGParticleData* pd) -{//TODO: This, among other ones, should be restructured so they don't all need to remember to call the superclass - if (m_onceOff) - if (activeGroup(pd->group)) - m_onceOffed.remove(qMakePair(pd->group, pd->index)); -} - -void QSGParticleAffector::updateOffsets() -{ - if (m_system) - m_offset = m_system->mapFromItem(this, QPointF(0, 0)); -} - -bool QSGParticleAffector::isColliding(QSGParticleData *d) -{ - qreal myCurX = d->curX(); - qreal myCurY = d->curY(); - qreal myCurSize = d->curSize()/2; - foreach (const QString &group, m_whenCollidingWith){ - foreach (QSGParticleData* other, m_system->groupData[m_system->groupIds[group]]->data){ - if (!other->stillAlive()) - continue; - qreal otherCurX = other->curX(); - qreal otherCurY = other->curY(); - qreal otherCurSize = other->curSize()/2; - if ((myCurX + myCurSize > otherCurX - otherCurSize - && myCurX - myCurSize < otherCurX + otherCurSize) - && (myCurY + myCurSize > otherCurY - otherCurSize - && myCurY - myCurSize < otherCurY + otherCurSize)) - return true; - } - } - return false; -} - -QT_END_NAMESPACE diff --git a/src/declarative/particles/qsgparticleaffector_p.h b/src/declarative/particles/qsgparticleaffector_p.h deleted file mode 100644 index b7fef2e226..0000000000 --- a/src/declarative/particles/qsgparticleaffector_p.h +++ /dev/null @@ -1,201 +0,0 @@ -/**************************************************************************** -** -** 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 PARTICLEAFFECTOR_H -#define PARTICLEAFFECTOR_H - -#include -#include "qsgparticlesystem_p.h" -#include "qsgparticleextruder_p.h" - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QSGParticleAffector : public QQuickItem -{ - Q_OBJECT - Q_PROPERTY(QSGParticleSystem* system READ system WRITE setSystem NOTIFY systemChanged) - Q_PROPERTY(QStringList groups READ groups WRITE setGroups NOTIFY groupsChanged) - Q_PROPERTY(QStringList whenCollidingWith READ whenCollidingWith WRITE setWhenCollidingWith NOTIFY whenCollidingWithChanged) - Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged) - Q_PROPERTY(bool once READ onceOff WRITE setOnceOff NOTIFY onceChanged) - Q_PROPERTY(QSGParticleExtruder* shape READ shape WRITE setShape NOTIFY shapeChanged) - -public: - explicit QSGParticleAffector(QQuickItem *parent = 0); - virtual void affectSystem(qreal dt); - virtual void reset(QSGParticleData*);//As some store their own data per particle? - QSGParticleSystem* system() const - { - return m_system; - } - - QStringList groups() const - { - return m_groups; - } - - bool enabled() const - { - return m_enabled; - } - - bool onceOff() const - { - return m_onceOff; - } - - QSGParticleExtruder* shape() const - { - return m_shape; - } - - QStringList whenCollidingWith() const - { - return m_whenCollidingWith; - } - -signals: - - void systemChanged(QSGParticleSystem* arg); - - void groupsChanged(QStringList arg); - - void enabledChanged(bool arg); - - void onceChanged(bool arg); - - void shapeChanged(QSGParticleExtruder* arg); - - void affected(qreal x, qreal y); - - void whenCollidingWithChanged(QStringList arg); - -public slots: -void setSystem(QSGParticleSystem* arg) -{ - if (m_system != arg) { - m_system = arg; - m_system->registerParticleAffector(this); - emit systemChanged(arg); - } -} - -void setGroups(QStringList arg) -{ - if (m_groups != arg) { - m_groups = arg; - m_updateIntSet = true; - emit groupsChanged(arg); - } -} - -void setEnabled(bool arg) -{ - if (m_enabled != arg) { - m_enabled = arg; - emit enabledChanged(arg); - } -} - -void setOnceOff(bool arg) -{ - if (m_onceOff != arg) { - m_onceOff = arg; - m_needsReset = true; - emit onceChanged(arg); - } -} - -void setShape(QSGParticleExtruder* arg) -{ - if (m_shape != arg) { - m_shape = arg; - emit shapeChanged(arg); - } -} - -void setWhenCollidingWith(QStringList arg) -{ - if (m_whenCollidingWith != arg) { - m_whenCollidingWith = arg; - emit whenCollidingWithChanged(arg); - } -} -public slots: - void updateOffsets(); - -protected: - friend class QSGParticleSystem; - virtual bool affectParticle(QSGParticleData *d, qreal dt); - bool m_needsReset:1;//### What is this really saving? - bool m_ignoresTime:1; - bool m_onceOff:1; - bool m_enabled:1; - - QSGParticleSystem* m_system; - QStringList m_groups; - bool activeGroup(int g); - bool shouldAffect(QSGParticleData* datum);//Call to do the logic on whether it is affecting that datum - void postAffect(QSGParticleData* datum);//Call to do the post-affect logic on particles which WERE affected(once off, needs reset, affected signal) - virtual void componentComplete(); - QPointF m_offset; - bool isAffectedConnected(); - static const qreal simulationDelta; - static const qreal simulationCutoff; -private: - QSet m_groupIds; - QSet > m_onceOffed; - bool m_updateIntSet; - - QSGParticleExtruder* m_shape; - - QStringList m_whenCollidingWith; - - bool isColliding(QSGParticleData* d); -}; - -QT_END_NAMESPACE -QT_END_HEADER -#endif // PARTICLEAFFECTOR_H diff --git a/src/declarative/particles/qsgparticleemitter.cpp b/src/declarative/particles/qsgparticleemitter.cpp deleted file mode 100644 index f9a35a1d8c..0000000000 --- a/src/declarative/particles/qsgparticleemitter.cpp +++ /dev/null @@ -1,501 +0,0 @@ -/**************************************************************************** -** -** 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 "qsgparticleemitter_p.h" -#include -QT_BEGIN_NAMESPACE - - -/*! - \qmlclass Emitter QSGParticleEmitter - \inqmlmodule QtQuick.Particles 2 - \brief The Emitter element allows you to emit logical particles. - - This element emits logical particles into the ParticleSystem, with the - given starting attributes. - - Note that logical particles are not - automatically rendered, you will need to have one or more - ParticlePainter elements visualizing them. - - Note that the given starting attributes can be modified at any point - in the particle's lifetime by any Affector element in the same - ParticleSystem. This includes attributes like lifespan. -*/ - - -/*! - \qmlproperty ParticleSystem QtQuick.Particles2::Emitter::system - - This is the Particle system that the Emitter will emit into. - This can be omitted if the Emitter is a direct child of the ParticleSystem -*/ -/*! - \qmlproperty string QtQuick.Particles2::Emitter::group - - This is the logical particle group which it will emit into. - - Default value is "" (empty string). -*/ -/*! - \qmlproperty Shape QtQuick.Particles2::Emitter::shape - - This shape is applied with the size of the Emitter. Particles will be emitted - randomly from any area covered by the shape. - - The default shape is a filled in rectangle, which corresponds to the full bounding - box of the Emitter. -*/ -/*! - \qmlproperty bool QtQuick.Particles2::Emitter::emitting - - If set to false, the emitter will cease emissions until it is set to true. - - Default value is true. -*/ -/*! - \qmlproperty real QtQuick.Particles2::Emitter::emitRate - - Number of particles emitted per second. - - Default value is 10 particles per second. -*/ -/*! - \qmlproperty int QtQuick.Particles2::Emitter::lifeSpan - - The time in milliseconds each emitted particle should last for. - - If you do not want particles to automatically die after a time, for example if - you wish to dispose of them manually, set lifeSpan to Emitter.InfiniteLife. - - lifeSpans greater than or equal to 600000 (10 minutes) will be treated as infinite. - Particles with lifeSpans less than or equal to 0 will start out dead. - - Default value is 1000 (one second). -*/ -/*! - \qmlproperty int QtQuick.Particles2::Emitter::lifeSpanVariation - - Particle lifespans will vary by up to this much in either direction. - - Default value is 0. -*/ - -/*! - \qmlproperty int QtQuick.Particles2::Emitter::maximumEmitted - - The maximum number of particles at a time that this emitter will have alive. - - This can be set as a performance optimization (when using burst and pulse) or - to stagger emissions. - - If this is set to a number below zero, then there is no maximum limit on the number - of particles this emitter can have alive. - - The default value is -1. -*/ -/*! - \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. - - Default value is 16. -*/ -/*! - \qmlproperty real QtQuick.Particles2::Emitter::endSize - - The size in pixels of the particles at the end of their life. Size will - be linearly interpolated during the life of the particle from this value and - size. If endSize is -1, then the size of the particle will remain constant at - the starting size. - - Default value is -1. -*/ -/*! - \qmlproperty real QtQuick.Particles2::Emitter::sizeVariation - - The size of a particle can vary by this much up or down from size/endSize. The same - random addition is made to both size and endSize for a single particle. - - Default value is 0. -*/ -/*! - \qmlproperty StochasticDirection QtQuick.Particles2::Emitter::speed - - The starting speed of the particles emitted. -*/ -/*! - \qmlproperty StochasticDirection QtQuick.Particles2::Emitter::acceleration - - The starting acceleraton of the particles emitted. -*/ -/*! - \qmlproperty qreal QtQuick.Particles2::Emitter::speedFromMovement - - If this value is non-zero, then any movement of the emitter will provide additional - starting velocity to the particles based on the movement. The additional vector will be the - same angle as the emitter's movement, with a magnitude that is the magnitude of the emitters - movement multiplied by speedFromMovement. - - Default value is 0. -*/ - -/*! - \qmlsignal QtQuick.Particles2::Emitter::onEmitParticles(Array particles) - - This handler is called when particles are emitted. particles is a javascript - array of Particle objects. You can modify particle attributes directly within the handler. - - Note that JS is slower to execute, so it is not recommended to use this in - high-volume particle systems. -*/ - -/*! \qmlmethod QtQuick.Particles2::Emitter::burst(int count) - - Emits count particles from this emitter immediately. -*/ - -/*! \qmlmethod QtQuick.Particles2::Emitter::burst(int x, int y, int count) - - Emits count particles from this emitter immediately. The particles are emitted - as if the Emitter was positioned at x,y but all other properties are the same. -*/ - -/*! \qmlmethod QtQuick.Particles2::Emitter::pulse(int duration) - - If the emitter is not enabled, enables it for duration milliseconds and then switches - it back off. -*/ - -QSGParticleEmitter::QSGParticleEmitter(QQuickItem *parent) : - QQuickItem(parent) - , m_particlesPerSecond(10) - , m_particleDuration(1000) - , m_particleDurationVariation(0) - , m_enabled(true) - , m_system(0) - , m_extruder(0) - , m_defaultExtruder(0) - , m_speed(&m_nullVector) - , m_acceleration(&m_nullVector) - , m_particleSize(16) - , m_particleEndSize(-1) - , m_particleSizeVariation(0) - , m_startTime(0) - , m_overwrite(true) - , m_pulseLeft(0) - , m_maxParticleCount(-1) - , m_speed_from_movement(0) - , m_reset_last(true) - , m_last_timestamp(-1) - , m_last_emission(0) - -{ - //TODO: Reset speed/acc back to null vector? Or allow null pointer? - connect(this, SIGNAL(maximumEmittedChanged(int)), - this, SIGNAL(particleCountChanged())); - connect(this, SIGNAL(particlesPerSecondChanged(qreal)), - this, SIGNAL(particleCountChanged())); - connect(this, SIGNAL(particleDurationChanged(int)), - this, SIGNAL(particleCountChanged())); -} - -QSGParticleEmitter::~QSGParticleEmitter() -{ - if (m_defaultExtruder) - delete m_defaultExtruder; -} - -bool QSGParticleEmitter::isEmitConnected() -{ - static int idx = QObjectPrivate::get(this)->signalIndex("emitParticles(QDeclarativeV8Handle)"); - return QObjectPrivate::get(this)->isSignalConnected(idx); -} - -void QSGParticleEmitter::componentComplete() -{ - if (!m_system && qobject_cast(parentItem())) - setSystem(qobject_cast(parentItem())); - QQuickItem::componentComplete(); -} - -void QSGParticleEmitter::setEnabled(bool arg) -{ - if (m_enabled != arg) { - m_enabled = arg; - emit enabledChanged(arg); - } -} - - -QSGParticleExtruder* QSGParticleEmitter::effectiveExtruder() -{ - if (m_extruder) - return m_extruder; - if (!m_defaultExtruder) - m_defaultExtruder = new QSGParticleExtruder; - return m_defaultExtruder; -} - -void QSGParticleEmitter::pulse(int milliseconds) -{ - if (!particleCount()) - qWarning() << "pulse called on an emitter with a particle count of zero"; - if (!m_enabled) - m_pulseLeft = milliseconds; -} - -void QSGParticleEmitter::burst(int num) -{ - if (!particleCount()) - qWarning() << "burst called on an emitter with a particle count of zero"; - m_burstQueue << qMakePair(num, QPointF(x(), y())); -} - -void QSGParticleEmitter::burst(int num, qreal x, qreal y) -{ - if (!particleCount()) - qWarning() << "burst called on an emitter with a particle count of zero"; - m_burstQueue << qMakePair(num, QPointF(x, y)); -} - -void QSGParticleEmitter::setMaxParticleCount(int arg) -{ - if (m_maxParticleCount != arg) { - if (arg < 0 && m_maxParticleCount >= 0){ - connect(this, SIGNAL(particlesPerSecondChanged(qreal)), - this, SIGNAL(particleCountChanged())); - connect(this, SIGNAL(particleDurationChanged(int)), - this, SIGNAL(particleCountChanged())); - }else if (arg >= 0 && m_maxParticleCount < 0){ - disconnect(this, SIGNAL(particlesPerSecondChanged(qreal)), - this, SIGNAL(particleCountChanged())); - disconnect(this, SIGNAL(particleDurationChanged(int)), - this, SIGNAL(particleCountChanged())); - } - m_overwrite = arg < 0; - m_maxParticleCount = arg; - emit maximumEmittedChanged(arg); - } -} - -int QSGParticleEmitter::particleCount() const -{ - if (m_maxParticleCount >= 0) - return m_maxParticleCount; - return m_particlesPerSecond*((m_particleDuration+m_particleDurationVariation)/1000.0); -} - -void QSGParticleEmitter::setSpeedFromMovement(qreal t) -{ - if (t == m_speed_from_movement) - return; - m_speed_from_movement = t; - emit speedFromMovementChanged(); -} - -void QSGParticleEmitter::reset() -{ - m_reset_last = true; -} - -void QSGParticleEmitter::emitWindow(int timeStamp) -{ - if (m_system == 0) - return; - if ((!m_enabled || !m_particlesPerSecond)&& !m_pulseLeft && m_burstQueue.isEmpty()){ - m_reset_last = true; - return; - } - - if (m_reset_last) { - m_last_emitter = m_last_last_emitter = QPointF(x(), y()); - if (m_last_timestamp == -1) - m_last_timestamp = (timeStamp - m_startTime)/1000.; - else - m_last_timestamp = timeStamp/1000.; - m_last_emission = m_last_timestamp; - m_reset_last = false; - m_emitCap = particleCount(); - } - - if (m_pulseLeft){ - m_pulseLeft -= timeStamp - m_last_timestamp * 1000.; - if (m_pulseLeft < 0){ - if (!m_enabled) - timeStamp += m_pulseLeft; - m_pulseLeft = 0; - } - } - qreal time = timeStamp / 1000.; - qreal particleRatio = 1. / m_particlesPerSecond; - qreal pt = m_last_emission; - qreal maxLife = (m_particleDuration + m_particleDurationVariation)/1000.0; - if (pt + maxLife < time)//We missed so much, that we should skip emiting particles that are dead by now - pt = time - maxLife; - - qreal opt = pt; // original particle time - qreal dt = time - m_last_timestamp; // timestamp delta... - if (!dt) - dt = 0.000001; - - // emitter difference since last... - qreal dex = (x() - m_last_emitter.x()); - qreal dey = (y() - m_last_emitter.y()); - - qreal ax = (m_last_last_emitter.x() + m_last_emitter.x()) / 2; - qreal bx = m_last_emitter.x(); - qreal cx = (x() + m_last_emitter.x()) / 2; - qreal ay = (m_last_last_emitter.y() + m_last_emitter.y()) / 2; - qreal by = m_last_emitter.y(); - qreal cy = (y() + m_last_emitter.y()) / 2; - - qreal sizeAtEnd = m_particleEndSize >= 0 ? m_particleEndSize : m_particleSize; - qreal emitter_x_offset = m_last_emitter.x() - x(); - qreal emitter_y_offset = m_last_emitter.y() - y(); - if (!m_burstQueue.isEmpty() && !m_pulseLeft && !m_enabled)//'outside time' emissions only - pt = time; - - QList toEmit; - - while ((pt < time && m_emitCap) || !m_burstQueue.isEmpty()) { - //int pos = m_last_particle % m_particle_count; - QSGParticleData* datum = m_system->newDatum(m_system->groupIds[m_group], !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; - qreal vx = - - 2 * ax * (1 - t) - + 2 * bx * (1 - 2 * t) - + 2 * cx * t; - qreal vy = - - 2 * ay * (1 - t) - + 2 * by * (1 - 2 * t) - + 2 * cy * t; - - - // Particle timestamp - datum->t = pt; - datum->lifeSpan = - (m_particleDuration - + ((rand() % ((m_particleDurationVariation*2) + 1)) - m_particleDurationVariation)) - / 1000.0; - - if (datum->lifeSpan >= m_system->maxLife){ - datum->lifeSpan = m_system->maxLife; - m_emitCap--;//emitCap keeps us from reemitting 'infinite' particles after their life. Unless you reset the emitter. - } - - // Particle position - QRectF boundsRect; - if (!m_burstQueue.isEmpty()){ - boundsRect = QRectF(m_burstQueue.first().second.x() - x(), m_burstQueue.first().second.y() - y(), - width(), height()); - } else { - boundsRect = QRectF(emitter_x_offset + dex * (pt - opt) / dt, emitter_y_offset + dey * (pt - opt) / dt - , width(), height()); - } - QPointF newPos = effectiveExtruder()->extrude(boundsRect); - datum->x = newPos.x(); - datum->y = newPos.y(); - - // Particle speed - const QPointF &speed = m_speed->sample(newPos); - datum->vx = speed.x() - + m_speed_from_movement * vx; - datum->vy = speed.y() - + m_speed_from_movement * vy; - - // Particle acceleration - const QPointF &accel = m_acceleration->sample(newPos); - datum->ax = accel.x(); - datum->ay = accel.y(); - - // Particle size - float sizeVariation = -m_particleSizeVariation - + rand() / float(RAND_MAX) * m_particleSizeVariation * 2; - - float size = qMax((qreal)0.0 , m_particleSize + sizeVariation); - float endSize = qMax((qreal)0.0 , sizeAtEnd + sizeVariation); - - datum->size = size;// * float(m_emitting); - datum->endSize = endSize;// * float(m_emitting); - - toEmit << datum; - } - if (m_burstQueue.isEmpty()){ - pt += particleRatio; - }else{ - m_burstQueue.first().first--; - if (m_burstQueue.first().first <= 0) - m_burstQueue.pop_front(); - } - } - - if (isEmitConnected()) { - v8::HandleScope handle_scope; - v8::Context::Scope scope(QDeclarativeEnginePrivate::getV8Engine(qmlEngine(this))->context()); - v8::Handle array = v8::Array::New(toEmit.size()); - for (int i=0; iSet(i, toEmit[i]->v8Value().toHandle()); - - emitParticles(QDeclarativeV8Handle::fromHandle(array));//A chance for arbitrary JS changes - } - foreach (QSGParticleData* d, toEmit) - m_system->emitParticle(d); - - m_last_emission = pt; - - m_last_last_last_emitter = m_last_last_emitter; - m_last_last_emitter = m_last_emitter; - m_last_emitter = QPointF(x(), y()); - m_last_timestamp = time; -} - - -QT_END_NAMESPACE diff --git a/src/declarative/particles/qsgparticleemitter_p.h b/src/declarative/particles/qsgparticleemitter_p.h deleted file mode 100644 index 0099c69144..0000000000 --- a/src/declarative/particles/qsgparticleemitter_p.h +++ /dev/null @@ -1,351 +0,0 @@ -/**************************************************************************** -** -** 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 PARTICLEEMITTER_H -#define PARTICLEEMITTER_H - -#include -#include -#include "qsgparticlesystem_p.h" -#include "qsgparticleextruder_p.h" -#include "qsgdirection_p.h" - -#include -#include -#include -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QSGParticleEmitter : public QQuickItem -{ - Q_OBJECT - Q_PROPERTY(QSGParticleSystem* system READ system WRITE setSystem NOTIFY systemChanged) - Q_PROPERTY(QString group READ group WRITE setGroup NOTIFY groupChanged) - Q_PROPERTY(QSGParticleExtruder* shape READ extruder WRITE setExtruder NOTIFY extruderChanged) - Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged) - Q_PROPERTY(int startTime READ startTime WRITE setStartTime NOTIFY startTimeChanged) - - Q_PROPERTY(qreal emitRate READ particlesPerSecond WRITE setParticlesPerSecond NOTIFY particlesPerSecondChanged) - Q_PROPERTY(int lifeSpan READ particleDuration WRITE setParticleDuration NOTIFY particleDurationChanged) - Q_PROPERTY(int lifeSpanVariation READ particleDurationVariation WRITE setParticleDurationVariation NOTIFY particleDurationVariationChanged) - Q_PROPERTY(int maximumEmitted READ maxParticleCount WRITE setMaxParticleCount NOTIFY maximumEmittedChanged) - - Q_PROPERTY(qreal size READ particleSize WRITE setParticleSize NOTIFY particleSizeChanged) - Q_PROPERTY(qreal endSize READ particleEndSize WRITE setParticleEndSize NOTIFY particleEndSizeChanged) - Q_PROPERTY(qreal sizeVariation READ particleSizeVariation WRITE setParticleSizeVariation NOTIFY particleSizeVariationChanged) - - Q_PROPERTY(QSGDirection *speed READ speed WRITE setSpeed NOTIFY speedChanged) - Q_PROPERTY(QSGDirection *acceleration READ acceleration WRITE setAcceleration NOTIFY accelerationChanged) - Q_PROPERTY(qreal speedFromMovement READ speedFromMovement WRITE setSpeedFromMovement NOTIFY speedFromMovementChanged) - - Q_ENUMS(Lifetime) -public: - explicit QSGParticleEmitter(QQuickItem *parent = 0); - virtual ~QSGParticleEmitter(); - virtual void emitWindow(int timeStamp); - - enum Lifetime { - InfiniteLife = QSGParticleSystem::maxLife - }; - - bool enabled() const - { - return m_enabled; - } - - qreal particlesPerSecond() const - { - return m_particlesPerSecond; - } - - int particleDuration() const - { - return m_particleDuration; - } - - QSGParticleSystem* system() const - { - return m_system; - } - - QString group() const - { - return m_group; - } - - int particleDurationVariation() const - { - return m_particleDurationVariation; - } - - qreal speedFromMovement() const { return m_speed_from_movement; } - void setSpeedFromMovement(qreal s); - virtual void componentComplete(); -signals: - void emitParticles(QDeclarativeV8Handle particles); - void particlesPerSecondChanged(qreal); - void particleDurationChanged(int); - void enabledChanged(bool); - - void systemChanged(QSGParticleSystem* arg); - - void groupChanged(QString arg); - - void particleDurationVariationChanged(int arg); - - void extruderChanged(QSGParticleExtruder* arg); - - void particleSizeChanged(qreal arg); - - void particleEndSizeChanged(qreal arg); - - void particleSizeVariationChanged(qreal arg); - - void speedChanged(QSGDirection * arg); - - void accelerationChanged(QSGDirection * arg); - - void maximumEmittedChanged(int arg); - void particleCountChanged(); - - void speedFromMovementChanged(); - - void startTimeChanged(int arg); - -public slots: - void pulse(int milliseconds); - void burst(int num); - void burst(int num, qreal x, qreal y); - - void setEnabled(bool arg); - - void setParticlesPerSecond(qreal arg) - { - if (m_particlesPerSecond != arg) { - m_particlesPerSecond = arg; - emit particlesPerSecondChanged(arg); - } - } - - void setParticleDuration(int arg) - { - if (m_particleDuration != arg) { - m_particleDuration = arg; - emit particleDurationChanged(arg); - } - } - - void setSystem(QSGParticleSystem* arg) - { - if (m_system != arg) { - m_system = arg; - m_system->registerParticleEmitter(this); - emit systemChanged(arg); - } - } - - void setGroup(QString arg) - { - if (m_group != arg) { - m_group = arg; - emit groupChanged(arg); - } - } - - void setParticleDurationVariation(int arg) - { - if (m_particleDurationVariation != arg) { - m_particleDurationVariation = arg; - emit particleDurationVariationChanged(arg); - } - } - void setExtruder(QSGParticleExtruder* arg) - { - if (m_extruder != arg) { - m_extruder = arg; - emit extruderChanged(arg); - } - } - - void setParticleSize(qreal arg) - { - if (m_particleSize != arg) { - m_particleSize = arg; - emit particleSizeChanged(arg); - } - } - - void setParticleEndSize(qreal arg) - { - if (m_particleEndSize != arg) { - m_particleEndSize = arg; - emit particleEndSizeChanged(arg); - } - } - - void setParticleSizeVariation(qreal arg) - { - if (m_particleSizeVariation != arg) { - m_particleSizeVariation = arg; - emit particleSizeVariationChanged(arg); - } - } - - void setSpeed(QSGDirection * arg) - { - if (m_speed != arg) { - m_speed = arg; - emit speedChanged(arg); - } - } - - void setAcceleration(QSGDirection * arg) - { - if (m_acceleration != arg) { - m_acceleration = arg; - emit accelerationChanged(arg); - } - } - - void setMaxParticleCount(int arg); - - void setStartTime(int arg) - { - if (m_startTime != arg) { - m_startTime = arg; - emit startTimeChanged(arg); - } - } - - virtual void reset(); -public: - int particleCount() const; - - QSGParticleExtruder* extruder() const - { - return m_extruder; - } - - qreal particleSize() const - { - return m_particleSize; - } - - qreal particleEndSize() const - { - return m_particleEndSize; - } - - qreal particleSizeVariation() const - { - return m_particleSizeVariation; - } - - QSGDirection * speed() const - { - return m_speed; - } - - QSGDirection * acceleration() const - { - return m_acceleration; - } - - int maxParticleCount() const - { - return m_maxParticleCount; - } - - int startTime() const - { - return m_startTime; - } - -protected: - qreal m_particlesPerSecond; - int m_particleDuration; - int m_particleDurationVariation; - bool m_enabled; - QSGParticleSystem* m_system; - QString m_group; - QSGParticleExtruder* m_extruder; - QSGParticleExtruder* m_defaultExtruder; - QSGParticleExtruder* effectiveExtruder(); - QSGDirection * m_speed; - QSGDirection * m_acceleration; - qreal m_particleSize; - qreal m_particleEndSize; - qreal m_particleSizeVariation; - - qreal m_speedFromMovement; - int m_startTime; - bool m_overwrite; - - int m_pulseLeft; - QList > m_burstQueue; - int m_maxParticleCount; - - //Used in default implementation, but might be useful - qreal m_speed_from_movement; - - int m_emitCap; - bool m_reset_last; - qreal m_last_timestamp; - qreal m_last_emission; - - QPointF m_last_emitter; - QPointF m_last_last_emitter; - QPointF m_last_last_last_emitter; - - bool isEmitConnected(); -private: - QSGDirection m_nullVector; - -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // PARTICLEEMITTER_H diff --git a/src/declarative/particles/qsgparticleextruder.cpp b/src/declarative/particles/qsgparticleextruder.cpp deleted file mode 100644 index 73c8ce0a66..0000000000 --- a/src/declarative/particles/qsgparticleextruder.cpp +++ /dev/null @@ -1,70 +0,0 @@ -/**************************************************************************** -** -** 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 "qsgparticleextruder_p.h" - -QT_BEGIN_NAMESPACE - -/*! - \qmlclass Shape QSGParticleExtruder - \inqmlmodule QtQuick.Particles 2 - \brief The Shape element allows you to specify an area for affectors and emitter. - - The base class is just a rectangle. -*/ - -QSGParticleExtruder::QSGParticleExtruder(QObject *parent) : - QObject(parent) -{ -} - -QPointF QSGParticleExtruder::extrude(const QRectF &rect) -{ - return QPointF(((qreal)rand() / RAND_MAX) * rect.width() + rect.x(), - ((qreal)rand() / RAND_MAX) * rect.height() + rect.y()); -} - -bool QSGParticleExtruder::contains(const QRectF &bounds, const QPointF &point) -{ - return bounds.contains(point); -} - -QT_END_NAMESPACE diff --git a/src/declarative/particles/qsgparticleextruder_p.h b/src/declarative/particles/qsgparticleextruder_p.h deleted file mode 100644 index b31b80231d..0000000000 --- a/src/declarative/particles/qsgparticleextruder_p.h +++ /dev/null @@ -1,73 +0,0 @@ -/**************************************************************************** -** -** 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 PARTICLEEXTRUDER_H -#define PARTICLEEXTRUDER_H - -#include -#include -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QSGParticleExtruder : public QObject -{ - Q_OBJECT - -public: - explicit QSGParticleExtruder(QObject *parent = 0); - virtual QPointF extrude(const QRectF &); - virtual bool contains(const QRectF &bounds, const QPointF &point); - -signals: -public slots: -protected: -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // PARTICLEEXTRUDER_H diff --git a/src/declarative/particles/qsgparticlegroup.cpp b/src/declarative/particles/qsgparticlegroup.cpp deleted file mode 100644 index c4eded93e6..0000000000 --- a/src/declarative/particles/qsgparticlegroup.cpp +++ /dev/null @@ -1,143 +0,0 @@ -/**************************************************************************** -** -** 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 "qsgparticlegroup_p.h" - -/*! - \qmlclass ParticleGroup QSGParticleGroup - \inqmlmodule QtQuick.Particles 2 - \brief ParticleGroup elements allow you to set attributes on a logical particle group. - - This element allows you to set timed transitions on particle groups. - - You can also use this element to group particle system elements related to the logical - particle group. Emitters, Affectors and Painters set as direct children of a ParticleGroup - will automatically apply to that logical particle group. TrailEmitters will automatically follow - the group. - - If a ParticleGroup element is not defined for a group, the group will function normally as if - none of the transition properties were set. -*/ -/*! - \qmlproperty ParticleSystem QtQuick.Particles2::ParticleGroup::system - This is the system which will contain the group. - - If the ParticleGroup is a direct child of a ParticleSystem, it will automatically be associated with it. -*/ -/*! - \qmlproperty string QtQuick.Particles2::ParticleGroup::name - This is the name of the particle group, and how it is generally referred to by other elements. - - If elements refer to a name which does not have an explicit ParticleGroup created, it will - work normally (with no transitions specified for the group). If you do not need to assign - duration based transitions to a group, you do not need to create a ParticleGroup with that name (although you may). -*/ -/*! - \qmlproperty int QtQuick.Particles2::ParticleGroup::duration - The time in milliseconds before the group will attempt to transition. - -*/ -/*! - \qmlproperty ParticleSystem QtQuick.Particles2::ParticleGroup::durationVariation - The maximum number of milliseconds that the duration of the transition cycle varies per particle in the group. - - Default value is zero. -*/ -/*! - \qmlproperty ParticleSystem QtQuick.Particles2::ParticleGroup::to - The weighted list of transitions valid for this group. - - If the chosen transition stays in this group, another duration (+/- up to durationVariation) - milliseconds will occur before another transition is attempted. -*/ - -QSGParticleGroup::QSGParticleGroup(QObject* parent) - : QQuickStochasticState(parent) - , m_system(0) -{ - -} - -void delayedRedirect(QDeclarativeListProperty *prop, QObject *value) -{ - QSGParticleGroup* pg = qobject_cast(prop->object); - if (pg) - pg->delayRedirect(value); -} - -QDeclarativeListProperty QSGParticleGroup::particleChildren() -{ - QSGParticleSystem* system = qobject_cast(parent()); - if (system) - return QDeclarativeListProperty(this, 0, &QSGParticleSystem::statePropertyRedirect); - else - return QDeclarativeListProperty(this, 0, &delayedRedirect); -} - -void QSGParticleGroup::setSystem(QSGParticleSystem* arg) -{ - if (m_system != arg) { - m_system = arg; - m_system->registerParticleGroup(this); - performDelayedRedirects(); - emit systemChanged(arg); - } -} - -void QSGParticleGroup::delayRedirect(QObject *obj) -{ - m_delayedRedirects << obj; -} - -void QSGParticleGroup::performDelayedRedirects() -{ - if (!m_system) - return; - foreach (QObject* obj, m_delayedRedirects) - m_system->stateRedirect(this, m_system, obj); - - m_delayedRedirects.clear(); -} - -void QSGParticleGroup::componentComplete(){ - if (!m_system && qobject_cast(parent())) - setSystem(qobject_cast(parent())); -} diff --git a/src/declarative/particles/qsgparticlegroup_p.h b/src/declarative/particles/qsgparticlegroup_p.h deleted file mode 100644 index f30539f686..0000000000 --- a/src/declarative/particles/qsgparticlegroup_p.h +++ /dev/null @@ -1,112 +0,0 @@ -/**************************************************************************** -** -** 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 QSGPARTICLEGROUP -#define QSGPARTICLEGROUP -#include -#include "qsgparticlesystem_p.h" -#include "qdeclarativeparserstatus.h" - -QT_BEGIN_NAMESPACE - -class QSGParticleGroup : public QQuickStochasticState, public QDeclarativeParserStatus -{ - Q_OBJECT - //### Would setting limits per group be useful? Or clutter the API? - //Q_PROPERTY(int maximumAlive READ maximumAlive WRITE setMaximumAlive NOTIFY maximumAliveChanged) - - Q_PROPERTY(QSGParticleSystem* system READ system WRITE setSystem NOTIFY systemChanged) - - //Intercept children requests and assign to the group & system - Q_PROPERTY(QDeclarativeListProperty particleChildren READ particleChildren DESIGNABLE false)//### Hidden property for in-state system definitions - ought not to be used in actual "Sprite" states - Q_CLASSINFO("DefaultProperty", "particleChildren") - Q_INTERFACES(QDeclarativeParserStatus) - -public: - explicit QSGParticleGroup(QObject* parent = 0); - - QDeclarativeListProperty particleChildren(); - - int maximumAlive() const - { - return m_maximumAlive; - } - - QSGParticleSystem* system() const - { - return m_system; - } - -public slots: - - void setMaximumAlive(int arg) - { - if (m_maximumAlive != arg) { - m_maximumAlive = arg; - emit maximumAliveChanged(arg); - } - } - - void setSystem(QSGParticleSystem* arg); - - void delayRedirect(QObject* obj); - -signals: - - void maximumAliveChanged(int arg); - - void systemChanged(QSGParticleSystem* arg); - -protected: - virtual void componentComplete(); - virtual void classBegin(){;} - -private: - - void performDelayedRedirects(); - - int m_maximumAlive; - QSGParticleSystem* m_system; - QList m_delayedRedirects; -}; - -QT_END_NAMESPACE - -#endif diff --git a/src/declarative/particles/qsgparticlepainter.cpp b/src/declarative/particles/qsgparticlepainter.cpp deleted file mode 100644 index c89e2ef560..0000000000 --- a/src/declarative/particles/qsgparticlepainter.cpp +++ /dev/null @@ -1,150 +0,0 @@ -/**************************************************************************** -** -** 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 "qsgparticlepainter_p.h" -#include -QT_BEGIN_NAMESPACE -/*! - \qmlclass ParticlePainter QSGParticlePainter - \inqmlmodule QtQuick.Particles 2 - \inherits ParticlePainter - \brief ParticlePainter elements allow you to specify how to paint particles. - - The default implementation paints nothing. See the subclasses if you want to - paint something visible. - -*/ -/*! - \qmlproperty ParticleSystem QtQuick.Particles2::ParticlePainter::system - This is the system whose particles can be painted by the element. - If the ParticlePainter is a direct child of a ParticleSystem, it will automatically be associated with it. -*/ -/*! - \qmlproperty list QtQuick.Particles2::ParticlePainter::groups - Which logical particle groups will be painted. - - If empty, it will paint the default particle group (""). -*/ -QSGParticlePainter::QSGParticlePainter(QQuickItem *parent) : - QQuickItem(parent), - m_system(0), m_count(0), m_pleaseReset(true), m_sentinel(new QSGParticleData(0)) -{ -} - -void QSGParticlePainter::componentComplete() -{ - if (!m_system && qobject_cast(parentItem())) - setSystem(qobject_cast(parentItem())); - QQuickItem::componentComplete(); -} - - -void QSGParticlePainter::setSystem(QSGParticleSystem *arg) -{ - if (m_system != arg) { - m_system = arg; - if (m_system){ - m_system->registerParticlePainter(this); - reset(); - } - emit systemChanged(arg); - } -} - -void QSGParticlePainter::load(QSGParticleData* d) -{ - if (m_pleaseReset) - return; - initialize(d->group, d->index); - m_pendingCommits << qMakePair(d->group, d->index); -} - -void QSGParticlePainter::reload(QSGParticleData* d) -{ - if (m_pleaseReset) - return; - m_pendingCommits << qMakePair(d->group, d->index); -} - -void QSGParticlePainter::reset() -{ -} - -void QSGParticlePainter::setCount(int c)//### TODO: some resizeing so that particles can reallocate on size change instead of recreate -{ - Q_ASSERT(c >= 0); //XXX - if (c == m_count) - return; - m_count = c; - emit countChanged(); - reset(); -} - -int QSGParticlePainter::count() -{ - return m_count; -} - -void QSGParticlePainter::calcSystemOffset(bool resetPending) -{ - if (!m_system || !parentItem()) - return; - QPointF lastOffset = m_systemOffset; - m_systemOffset = -1 * this->mapFromItem(m_system, QPointF(0.0, 0.0)); - if (lastOffset != m_systemOffset && !resetPending){ - //Reload all particles//TODO: Necessary? - foreach (const QString &g, m_groups){ - int gId = m_system->groupIds[g]; - foreach (QSGParticleData* d, m_system->groupData[gId]->data) - reload(d); - } - } -} -typedef QPair intPair; -void QSGParticlePainter::performPendingCommits() -{ - calcSystemOffset(); - foreach (intPair p, m_pendingCommits) - commit(p.first, p.second); - m_pendingCommits.clear(); -} - -QT_END_NAMESPACE diff --git a/src/declarative/particles/qsgparticlepainter_p.h b/src/declarative/particles/qsgparticlepainter_p.h deleted file mode 100644 index 32b7224df3..0000000000 --- a/src/declarative/particles/qsgparticlepainter_p.h +++ /dev/null @@ -1,134 +0,0 @@ -/**************************************************************************** -** -** 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 PARTICLE_H -#define PARTICLE_H - -#include -#include -#include -#include "qsgparticlesystem_p.h" - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - - -class QSGParticlePainter : public QQuickItem -{ - Q_OBJECT - Q_PROPERTY(QSGParticleSystem* system READ system WRITE setSystem NOTIFY systemChanged) - Q_PROPERTY(QStringList groups READ groups WRITE setGroups NOTIFY groupsChanged) - -public: - explicit QSGParticlePainter(QQuickItem *parent = 0); - //Data Interface to system - void load(QSGParticleData*); - void reload(QSGParticleData*); - void setCount(int c); - int count(); - void performPendingCommits();//Called from updatePaintNode - QSGParticleSystem* system() const - { - return m_system; - } - - - QStringList groups() const - { - return m_groups; - } - -signals: - void countChanged(); - void systemChanged(QSGParticleSystem* arg); - - void groupsChanged(QStringList arg); - -public slots: - void setSystem(QSGParticleSystem* arg); - - void setGroups(QStringList arg) - { - if (m_groups != arg) { - m_groups = arg; - emit groupsChanged(arg); - } - } - - void calcSystemOffset(bool resetPending = false); - -protected: - /* Reset resets all your internal data structures. But anything attached to a particle should - be in attached data. So reset + reloads should have no visible effect. - ###Hunt down all cases where we do a complete reset for convenience and be more targeted - */ - virtual void reset(); - - virtual void componentComplete(); - virtual void initialize(int gIdx, int pIdx){//Called from main thread - Q_UNUSED(gIdx); - Q_UNUSED(pIdx); - } - virtual void commit(int gIdx, int pIdx){//Called in Render Thread - //###If you need to do something on size changed, check m_data size in this? Or we reset you every time? - Q_UNUSED(gIdx); - Q_UNUSED(pIdx); - } - - QSGParticleSystem* m_system; - friend class QSGParticleSystem; - int m_count; - bool m_pleaseReset;//Used by subclasses, but it's a nice optimization to know when stuff isn't going to matter. - QStringList m_groups; - QPointF m_systemOffset; - -private: - QSGParticleData* m_sentinel; - QSet > m_pendingCommits; - //QVector m_shadowData;//For when we implement overwrite: false -}; - -QT_END_NAMESPACE -QT_END_HEADER -#endif // PARTICLE_H diff --git a/src/declarative/particles/qsgparticlesmodule.cpp b/src/declarative/particles/qsgparticlesmodule.cpp deleted file mode 100644 index f9a457bce1..0000000000 --- a/src/declarative/particles/qsgparticlesmodule.cpp +++ /dev/null @@ -1,120 +0,0 @@ -/**************************************************************************** -** -** 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 "qsgangledirection_p.h" -#include "qsgcustomparticle_p.h" -#include "qsgellipseextruder_p.h" -#include "qsgtrailemitter_p.h" -#include "qsgfriction_p.h" -#include "qsggravity_p.h" -#include "qsgimageparticle_p.h" -#include "qsgitemparticle_p.h" -#include "qsgage_p.h" -#include "qsglineextruder_p.h" -#include "qsgmaskextruder_p.h" -#include "qsgparticleaffector_p.h" -#include "qsgparticleemitter_p.h" -#include "qsgparticleextruder_p.h" -#include "qsgparticlepainter_p.h" -#include "qsgparticlesmodule_p.h" -#include "qsgparticlesystem_p.h" -#include "qsgpointattractor_p.h" -#include "qsgpointdirection_p.h" -#include "qsgspritegoal_p.h" -#include "qsgdirection_p.h" -#include "qsgtargetdirection_p.h" -#include "qsgturbulence_p.h" -#include "qsgwander_p.h" -#include "qsgcumulativedirection_p.h" -#include "qsgcustomaffector_p.h" -#include "qsgrectangleextruder_p.h" -#include "qsgparticlegroup_p.h" -#include "qsggroupgoal_p.h" - -QT_BEGIN_NAMESPACE - -void QSGParticlesModule::defineModule() -{ - const char* uri = "QtQuick.Particles"; - - qmlRegisterType(uri, 2, 0, "ParticleSystem"); - qmlRegisterType(uri, 2, 0, "ParticleGroup"); - - qmlRegisterType(uri, 2, 0, "ImageParticle"); - qmlRegisterType(uri, 2, 0, "CustomParticle"); - qmlRegisterType(uri, 2, 0, "ItemParticle"); - - qmlRegisterType(uri, 2, 0, "Emitter"); - qmlRegisterType(uri, 2, 0, "TrailEmitter"); - - qmlRegisterType(uri, 2, 0, "EllipseShape"); - qmlRegisterType(uri, 2, 0, "RectangleShape"); - qmlRegisterType(uri, 2, 0, "LineShape"); - qmlRegisterType(uri, 2, 0, "MaskShape"); - - qmlRegisterType(uri, 2, 0, "PointDirection"); - qmlRegisterType(uri, 2, 0, "AngleDirection"); - qmlRegisterType(uri, 2, 0, "TargetDirection"); - qmlRegisterType(uri, 2, 0, "CumulativeDirection"); - - qmlRegisterType(uri, 2, 0, "Affector"); - qmlRegisterType(uri, 2, 0, "Wander"); - qmlRegisterType(uri, 2, 0, "Friction"); - qmlRegisterType(uri, 2, 0, "Attractor"); - qmlRegisterType(uri, 2, 0, "Gravity"); - qmlRegisterType(uri, 2, 0, "Age"); - qmlRegisterType(uri, 2, 0, "SpriteGoal"); - qmlRegisterType(uri, 2, 0, "GroupGoal"); - qmlRegisterType(uri, 2, 0 , "Turbulence"); - - //Exposed just for completeness - qmlRegisterUncreatableType(uri, 2, 0, "ParticleAffector", - QStringLiteral("Abstract type. Use one of the inheriting types instead.")); - qmlRegisterUncreatableType(uri, 2, 0, "ParticlePainter", - QStringLiteral("Abstract type. Use one of the inheriting types instead.")); - qmlRegisterUncreatableType(uri, 2, 0, "ParticleExtruder", - QStringLiteral("Abstract type. Use one of the inheriting types instead.")); - qmlRegisterUncreatableType(uri, 2, 0, "NullVector", - QStringLiteral("Abstract type. Use one of the inheriting types instead.")); -} - -QT_END_NAMESPACE - diff --git a/src/declarative/particles/qsgparticlesmodule_p.h b/src/declarative/particles/qsgparticlesmodule_p.h deleted file mode 100644 index ec8d1e2b30..0000000000 --- a/src/declarative/particles/qsgparticlesmodule_p.h +++ /dev/null @@ -1,63 +0,0 @@ -/**************************************************************************** -** -** 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 QSGPARTICLESMODULE_H -#define QSGPARTICLESMODULE_H - -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QSGParticlesModule -{ -public: - static void defineModule(); -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QSGPARTICLESMODULE_H diff --git a/src/declarative/particles/qsgparticlesystem.cpp b/src/declarative/particles/qsgparticlesystem.cpp deleted file mode 100644 index 0523563843..0000000000 --- a/src/declarative/particles/qsgparticlesystem.cpp +++ /dev/null @@ -1,1084 +0,0 @@ -/**************************************************************************** -** -** 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 "qsgparticlesystem_p.h" -#include -#include "qsgparticleemitter_p.h" -#include "qsgparticleaffector_p.h" -#include "qsgparticlepainter_p.h" -#include -#include -#include "qsgv8particledata_p.h" -#include "qsgparticlegroup_p.h" - -#include "qsgtrailemitter_p.h"//###For auto-follow on states, perhaps should be in emitter? -#include -#include -#include - -QT_BEGIN_NAMESPACE -//###Switch to define later, for now user-friendly (no compilation) debugging is worth it -DEFINE_BOOL_CONFIG_OPTION(qmlParticlesDebug, QML_PARTICLES_DEBUG) -/*! - \qmlclass ParticleSystem QSGParticleSystem - \inqmlmodule QtQuick.Particles 2 - \brief The ParticleSystem brings together ParticlePainter, Emitter and Affector elements. - -*/ - -/*! - \qmlproperty bool QtQuick.Particles2::ParticleSystem::running - - If running is set to false, the particle system will stop the simulation. All particles - will be destroyed when the system is set to running again. - - It can also be controlled with the start() and stop() methods. -*/ - - -/*! - \qmlproperty bool QtQuick.Particles2::ParticleSystem::paused - - If paused is set to true, the particle system will not advance the simulation. When - paused is set to false again, the simulation will resume from the same point it was - paused. - - The simulation will automatically pause if it detects that there are no live particles - left, and unpause when new live particles are added. - - It can also be controlled with the pause() and resume() methods. -*/ - -/*! - \qmlproperty bool QtQuick.Particles2::ParticleSystem::empty - - empty is set to true when there are no live particles left in the system. - - You can use this to pause the system, keeping it from spending any time updating, - but you will need to resume it in order for additional particles to be generated - by the system. - - To kill all the particles in the system, use a Kill affector. -*/ - -/*! - \qmlproperty list QtQuick.Particles2::ParticleSystem::particleStates - - You can define a sub-set of particle groups in this property in order to provide them - with stochastic state transitions. - - Each QtQuick2::Sprite in this list is interpreted as corresponding to the particle group - with ths same name. Any transitions defined in these sprites will take effect on the particle - groups as well. Additionally TrailEmitters, Affectors and ParticlePainters definined - inside one of these sprites are automatically associated with the corresponding particle group. -*/ - -/*! - \qmlmethod void QtQuick.Particles2::ParticleSystem::pause - - Pauses the simulation if it is running. - - \sa resume, paused -*/ - -/*! - \qmlmethod void QtQuick.Particles2::ParticleSystem::resume - - Resumes the simulation if it is paused. - - \sa pause, paused -*/ - -/*! - \qmlmethod void QtQuick.Particles2::ParticleSystem::start - - Starts the simulation if it has not already running. - - \sa stop, restart, running -*/ - -/*! - \qmlmethod void QtQuick.Particles2::ParticleSystem::stop - - Stops the simulation if it is running. - - \sa start, restart, running -*/ - -/*! - \qmlmethod void QtQuick.Particles2::ParticleSystem::restart - - Stops the simulation if it is running, and then starts it. - - \sa stop, restart, running -*/ -/*! - \qmlmethod void QtQuick.Particles2::ParticleSystem::reset - - Discards all currently existing particles. - -*/ -const qreal EPSILON = 0.001; -//Utility functions for when within 1ms is close enough -bool timeEqualOrGreater(qreal a, qreal b){ - return (a+EPSILON >= b); -} - -bool timeLess(qreal a, qreal b){ - return (a-EPSILON < b); -} - -bool timeEqual(qreal a, qreal b){ - return (a+EPSILON > b) && (a-EPSILON < b); -} - -int roundedTime(qreal a){// in ms - return (int)qRound(a*1000.0); -} - -QSGParticleDataHeap::QSGParticleDataHeap() - : m_data(0) -{ - m_data.reserve(1000); - clear(); -} - -void QSGParticleDataHeap::grow() //###Consider automatic growth vs resize() calls from GroupData -{ - m_data.resize(1 << ++m_size); -} - -void QSGParticleDataHeap::insert(QSGParticleData* data) -{ - insertTimed(data, roundedTime(data->t + data->lifeSpan)); -} - -void QSGParticleDataHeap::insertTimed(QSGParticleData* data, int time){ - //TODO: Optimize 0 lifespan (or already dead) case - if (m_lookups.contains(time)){ - m_data[m_lookups[time]].data << data; - return; - } - if (m_end == (1 << m_size)) - grow(); - m_data[m_end].time = time; - m_data[m_end].data.clear(); - m_data[m_end].data.insert(data); - m_lookups.insert(time, m_end); - bubbleUp(m_end++); -} - -int QSGParticleDataHeap::top() -{ - if (m_end == 0) - return 1 << 30; - return m_data[0].time; -} - -QSet QSGParticleDataHeap::pop() -{ - if (!m_end) - return QSet (); - QSet ret = m_data[0].data; - m_lookups.remove(m_data[0].time); - if (m_end == 1){ - --m_end; - }else{ - m_data[0] = m_data[--m_end]; - bubbleDown(0); - } - return ret; -} - -void QSGParticleDataHeap::clear() -{ - m_size = 0; - m_end = 0; - //m_size is in powers of two. So to start at 0 we have one allocated - m_data.resize(1); - m_lookups.clear(); -} - -bool QSGParticleDataHeap::contains(QSGParticleData* d) -{ - for (int i=0; i= m_end) - return; - int lesser = left; - int right = idx*2 + 2; - if (right < m_end){ - if (m_data[left].time > m_data[right].time) - lesser = right; - } - if (m_data[idx].time > m_data[lesser].time){ - swap(idx, lesser); - bubbleDown(lesser); - } -} - -QSGParticleGroupData::QSGParticleGroupData(int id, QSGParticleSystem* sys):index(id),m_size(0),m_system(sys) -{ - initList(); -} - -QSGParticleGroupData::~QSGParticleGroupData() -{ - foreach (QSGParticleData* d, data) - delete d; -} - -int QSGParticleGroupData::size() -{ - return m_size; -} - -QString QSGParticleGroupData::name()//### Worth caching as well? -{ - return m_system->groupIds.key(index); -} - -void QSGParticleGroupData::setSize(int newSize){ - if (newSize == m_size) - return; - Q_ASSERT(newSize > m_size);//XXX allow shrinking - data.resize(newSize); - for (int i=m_size; igroup = index; - data[i]->index = i; - reusableIndexes << i; - } - int delta = newSize - m_size; - m_size = newSize; - foreach (QSGParticlePainter* p, painters) - p->setCount(p->count() + delta); -} - -void QSGParticleGroupData::initList() -{ - dataHeap.clear(); -} - -void QSGParticleGroupData::kill(QSGParticleData* d) -{ - Q_ASSERT(d->group == index); - d->lifeSpan = 0;//Kill off - foreach (QSGParticlePainter* p, painters) - p->reload(d); - reusableIndexes << d->index; -} - -QSGParticleData* QSGParticleGroupData::newDatum(bool respectsLimits) -{ - //recycle();//Extra recycler round to be sure? - - while (!reusableIndexes.empty()){ - int idx = *(reusableIndexes.begin()); - reusableIndexes.remove(idx); - if (data[idx]->stillAlive()){// ### This means resurrection of 'dead' particles. Is that allowed? - prepareRecycler(data[idx]); - continue; - } - return data[idx]; - } - if (respectsLimits) - return 0; - - int oldSize = m_size; - setSize(oldSize + 10);//###+1,10%,+10? Choose something non-arbitrarily - reusableIndexes.remove(oldSize); - return data[oldSize]; -} - -bool QSGParticleGroupData::recycle() -{ - while (dataHeap.top() <= m_system->timeInt){ - foreach (QSGParticleData* datum, dataHeap.pop()){ - if (!datum->stillAlive()){ - reusableIndexes << datum->index; - }else{ - prepareRecycler(datum); //ttl has been altered mid-way, put it back - } - } - } - - //TODO: If the data is clear, gc (consider shrinking stack size)? - return reusableIndexes.count() == m_size; -} - -void QSGParticleGroupData::prepareRecycler(QSGParticleData* d){ - if (d->lifeSpan*1000 < m_system->maxLife){ - dataHeap.insert(d); - } else { - while ((roundedTime(d->t) + 2*m_system->maxLife/3) <= m_system->timeInt) - d->extendLife(m_system->maxLife/3000.0); - dataHeap.insertTimed(d, roundedTime(d->t) + 2*m_system->maxLife/3); - } -} - -QSGParticleData::QSGParticleData(QSGParticleSystem* sys) - : group(0) - , e(0) - , system(sys) - , index(0) - , systemIndex(-1) - , colorOwner(0) - , rotationOwner(0) - , deformationOwner(0) - , animationOwner(0) - , v8Datum(0) -{ - x = 0; - y = 0; - t = -1; - lifeSpan = 0; - size = 0; - endSize = 0; - vx = 0; - vy = 0; - ax = 0; - ay = 0; - xx = 1; - xy = 0; - yx = 0; - yy = 1; - rotation = 0; - rotationSpeed = 0; - autoRotate = 0; - animIdx = 0; - frameDuration = 1; - frameCount = 1; - animT = -1; - animX = 0; - animY = 0; - animWidth = 1; - animHeight = 1; - color.r = 255; - color.g = 255; - color.b = 255; - color.a = 255; - r = 0; - delegate = 0; - modelIndex = -1; -} - -void QSGParticleData::clone(const QSGParticleData& other) -{ - x = other.x; - y = other.y; - t = other.t; - lifeSpan = other.lifeSpan; - size = other.size; - endSize = other.endSize; - vx = other.vx; - vy = other.vy; - ax = other.ax; - ay = other.ay; - xx = other.xx; - xy = other.xy; - yx = other.yx; - yy = other.yy; - rotation = other.rotation; - rotationSpeed = other.rotationSpeed; - autoRotate = other.autoRotate; - animIdx = other.animIdx; - frameDuration = other.frameDuration; - frameCount = other.frameCount; - animT = other.animT; - animX = other.animX; - animY = other.animY; - animWidth = other.animWidth; - animHeight = other.animHeight; - color.r = other.color.r; - color.g = other.color.g; - color.b = other.color.b; - color.a = other.color.a; - r = other.r; - delegate = other.delegate; - modelIndex = other.modelIndex; - - colorOwner = other.colorOwner; - rotationOwner = other.rotationOwner; - deformationOwner = other.deformationOwner; - animationOwner = other.animationOwner; -} - -QDeclarativeV8Handle QSGParticleData::v8Value() -{ - if (!v8Datum) - v8Datum = new QSGV8ParticleData(QDeclarativeEnginePrivate::getV8Engine(qmlEngine(system)), this); - return v8Datum->v8Value(); -} -//sets the x accleration without affecting the instantaneous x velocity or position -void QSGParticleData::setInstantaneousAX(qreal ax) -{ - qreal t = (system->timeInt / 1000.0) - this->t; - qreal vx = (this->vx + t*this->ax) - t*ax; - qreal ex = this->x + this->vx * t + 0.5 * this->ax * t * t; - qreal x = ex - t*vx - 0.5 * t*t*ax; - - this->ax = ax; - this->vx = vx; - this->x = x; -} - -//sets the x velocity without affecting the instantaneous x postion -void QSGParticleData::setInstantaneousVX(qreal vx) -{ - qreal t = (system->timeInt / 1000.0) - this->t; - qreal evx = vx - t*this->ax; - qreal ex = this->x + this->vx * t + 0.5 * this->ax * t * t; - qreal x = ex - t*evx - 0.5 * t*t*this->ax; - - this->vx = evx; - this->x = x; -} - -//sets the instantaneous x postion -void QSGParticleData::setInstantaneousX(qreal x) -{ - qreal t = (system->timeInt / 1000.0) - this->t; - this->x = x - t*this->vx - 0.5 * t*t*this->ax; -} - -//sets the y accleration without affecting the instantaneous y velocity or position -void QSGParticleData::setInstantaneousAY(qreal ay) -{ - qreal t = (system->timeInt / 1000.0) - this->t; - qreal vy = (this->vy + t*this->ay) - t*ay; - qreal ey = this->y + this->vy * t + 0.5 * this->ay * t * t; - qreal y = ey - t*vy - 0.5 * t*t*ay; - - this->ay = ay; - this->vy = vy; - this->y = y; -} - -//sets the y velocity without affecting the instantaneous y position -void QSGParticleData::setInstantaneousVY(qreal vy) -{ - qreal t = (system->timeInt / 1000.0) - this->t; - qreal evy = vy - t*this->ay; - qreal ey = this->y + this->vy * t + 0.5 * this->ay * t * t; - qreal y = ey - t*evy - 0.5 * t*t*this->ay; - - this->vy = evy; - this->y = y; -} - -//sets the instantaneous Y position -void QSGParticleData::setInstantaneousY(qreal y) -{ - qreal t = (system->timeInt / 1000.0) - this->t; - this->y = y - t*this->vy - 0.5 * t*t*this->ay; -} - -qreal QSGParticleData::curX() const -{ - qreal t = (system->timeInt / 1000.0) - this->t; - return this->x + this->vx * t + 0.5 * this->ax * t * t; -} - -qreal QSGParticleData::curVX() const -{ - qreal t = (system->timeInt / 1000.0) - this->t; - return this->vx + t*this->ax; -} - -qreal QSGParticleData::curY() const -{ - qreal t = (system->timeInt / 1000.0) - this->t; - return y + vy * t + 0.5 * ay * t * t; -} - -qreal QSGParticleData::curVY() const -{ - qreal t = (system->timeInt / 1000.0) - this->t; - return vy + t*ay; -} - -void QSGParticleData::debugDump() -{ - qDebug() << "Particle" << systemIndex << group << "/" << index << stillAlive() - << "Pos: " << x << "," << y - << "Vel: " << vx << "," << vy - << "Acc: " << ax << "," << ay - << "Size: " << size << "," << endSize - << "Time: " << t << "," <timeInt / 1000.0) ; -} - -bool QSGParticleData::stillAlive() -{ - if (!system) - return false; - return (t + lifeSpan - EPSILON) > ((qreal)system->timeInt/1000.0); -} - -float QSGParticleData::curSize() -{ - if (!system || !lifeSpan) - return 0.0f; - return size + (endSize - size) * (1 - (lifeLeft() / lifeSpan)); -} - -float QSGParticleData::lifeLeft() -{ - if (!system) - return 0.0f; - return (t + lifeSpan) - (system->timeInt/1000.0); -} - -void QSGParticleData::extendLife(float time) -{ - qreal newX = curX(); - qreal newY = curY(); - qreal newVX = curVX(); - qreal newVY = curVY(); - - t += time; - animT += time; - - qreal elapsed = (system->timeInt / 1000.0) - t; - qreal evy = newVY - elapsed*ay; - qreal ey = newY - elapsed*evy - 0.5 * elapsed*elapsed*ay; - qreal evx = newVX - elapsed*ax; - qreal ex = newX - elapsed*evx - 0.5 * elapsed*elapsed*ax; - - x = ex; - vx = evx; - y = ey; - vy = evy; -} - -QSGParticleSystem::QSGParticleSystem(QQuickItem *parent) : - QQuickItem(parent), - stateEngine(0), - m_running(true), - particleCount(0), - m_nextIndex(0), - m_componentComplete(false), - m_paused(false) -{ - connect(&m_painterMapper, SIGNAL(mapped(QObject*)), - this, SLOT(loadPainter(QObject*))); - - m_debugMode = qmlParticlesDebug(); -} - -QSGParticleSystem::~QSGParticleSystem() -{ - foreach (QSGParticleGroupData* gd, groupData) - delete gd; -} - -void QSGParticleSystem::initGroups() -{ - m_reusableIndexes.clear(); - m_nextIndex = 0; - - qDeleteAll(groupData); - groupData.clear(); - groupIds.clear(); - - QSGParticleGroupData* gd = new QSGParticleGroupData(0, this);//Default group - groupData.insert(0,gd); - groupIds.insert(QString(), 0); - m_nextGroupId = 1; -} - -void QSGParticleSystem::registerParticlePainter(QSGParticlePainter* p) -{ - //TODO: a way to Unregister emitters, painters and affectors - m_painters << QPointer(p);//###Set or uniqueness checking? - connect(p, SIGNAL(groupsChanged(QStringList)), - &m_painterMapper, SLOT(map())); - loadPainter(p); -} - -void QSGParticleSystem::registerParticleEmitter(QSGParticleEmitter* e) -{ - m_emitters << QPointer(e);//###How to get them out? - connect(e, SIGNAL(particleCountChanged()), - this, SLOT(emittersChanged())); - connect(e, SIGNAL(groupChanged(QString)), - this, SLOT(emittersChanged())); - emittersChanged(); - e->reset();//Start, so that starttime factors appropriately -} - -void QSGParticleSystem::registerParticleAffector(QSGParticleAffector* a) -{ - m_affectors << QPointer(a); -} - -void QSGParticleSystem::registerParticleGroup(QSGParticleGroup* g) -{ - m_groups << QPointer(g); - createEngine(); -} - -void QSGParticleSystem::setRunning(bool arg) -{ - if (m_running != arg) { - m_running = arg; - emit runningChanged(arg); - setPaused(false); - if (m_animation)//Not created until componentCompleted - m_running ? m_animation->start() : m_animation->stop(); - reset(); - } -} - -void QSGParticleSystem::setPaused(bool arg){ - if (m_paused != arg) { - m_paused = arg; - if (m_animation && m_animation->state() != QAbstractAnimation::Stopped) - m_paused ? m_animation->pause() : m_animation->resume(); - if (!m_paused){ - foreach (QSGParticlePainter *p, m_painters) - p->update(); - } - emit pausedChanged(arg); - } -} - -void QSGParticleSystem::statePropertyRedirect(QDeclarativeListProperty *prop, QObject *value) -{ - //Hooks up automatic state-associated stuff - QSGParticleSystem* sys = qobject_cast(prop->object->parent()); - QSGParticleGroup* group = qobject_cast(prop->object); - if (!group || !sys || !value) - return; - stateRedirect(group, sys, value); -} - -void QSGParticleSystem::stateRedirect(QSGParticleGroup* group, QSGParticleSystem* sys, QObject *value) -{ - QStringList list; - list << group->name(); - QSGParticleAffector* a = qobject_cast(value); - if (a){ - a->setParentItem(sys); - a->setGroups(list); - a->setSystem(sys); - return; - } - QSGTrailEmitter* fe = qobject_cast(value); - if (fe){ - fe->setParentItem(sys); - fe->setFollow(group->name()); - fe->setSystem(sys); - return; - } - QSGParticleEmitter* e = qobject_cast(value); - if (e){ - e->setParentItem(sys); - e->setGroup(group->name()); - e->setSystem(sys); - return; - } - QSGParticlePainter* p = qobject_cast(value); - if (p){ - p->setParentItem(sys); - p->setGroups(list); - p->setSystem(sys); - return; - } - qWarning() << value << " was placed inside a particle system state but cannot be taken into the particle system. It will be lost."; -} - -void QSGParticleSystem::componentComplete() - -{ - QQuickItem::componentComplete(); - m_componentComplete = true; - m_animation = new QSGParticleSystemAnimation(this); - reset();//restarts animation as well -} - -void QSGParticleSystem::reset() -{ - if (!m_componentComplete) - return; - - timeInt = 0; - //Clear guarded pointers which have been deleted - int cleared = 0; - cleared += m_emitters.removeAll(0); - cleared += m_painters.removeAll(0); - cleared += m_affectors.removeAll(0); - - bySysIdx.resize(0); - initGroups();//Also clears all logical particles - - if (!m_running) - return; - - foreach (QSGParticleEmitter* e, m_emitters) - e->reset(); - - emittersChanged(); - - foreach (QSGParticlePainter *p, m_painters){ - loadPainter(p); - p->reset(); - } - - //### Do affectors need reset too? - if (m_animation) {//Animation is explicitly disabled in benchmarks - //reset restarts animation (if running) - if ((m_animation->state() == QAbstractAnimation::Running)) - m_animation->stop(); - m_animation->start(); - if (m_paused) - m_animation->pause(); - } - - initialized = true; -} - - -void QSGParticleSystem::loadPainter(QObject *p) -{ - if (!m_componentComplete) - return; - - QSGParticlePainter* painter = qobject_cast(p); - Q_ASSERT(painter);//XXX - foreach (QSGParticleGroupData* sg, groupData) - sg->painters.remove(painter); - int particleCount = 0; - if (painter->groups().isEmpty()){//Uses default particle - QStringList def; - def << QString(); - painter->setGroups(def); - particleCount += groupData[0]->size(); - groupData[0]->painters << painter; - }else{ - foreach (const QString &group, painter->groups()){ - if (group != QLatin1String("") && !groupIds[group]){//new group - int id = m_nextGroupId++; - QSGParticleGroupData* gd = new QSGParticleGroupData(id, this); - groupIds.insert(group, id); - groupData.insert(id, gd); - } - particleCount += groupData[groupIds[group]]->size(); - groupData[groupIds[group]]->painters << painter; - } - } - painter->setCount(particleCount); - painter->update();//Initial update here - return; -} - -void QSGParticleSystem::emittersChanged() -{ - if (!m_componentComplete) - return; - - m_emitters.removeAll(0); - - - QList previousSizes; - QList newSizes; - for (int i=0; isize(); - newSizes << 0; - } - - foreach (QSGParticleEmitter* e, m_emitters){//Populate groups and set sizes. - if (!groupIds.contains(e->group()) - || (!e->group().isEmpty() && !groupIds[e->group()])){//or it was accidentally inserted by a failed lookup earlier - int id = m_nextGroupId++; - QSGParticleGroupData* gd = new QSGParticleGroupData(id, this); - groupIds.insert(e->group(), id); - groupData.insert(id, gd); - previousSizes << 0; - newSizes << 0; - } - newSizes[groupIds[e->group()]] += e->particleCount(); - //###: Cull emptied groups? - } - - //TODO: Garbage collection? - particleCount = 0; - for (int i=0; isetSize(qMax(newSizes[i], previousSizes[i])); - particleCount += groupData[i]->size(); - } - - if (m_debugMode) - qDebug() << "Particle system emitters changed. New particle count: " << particleCount; - - if (particleCount > bySysIdx.size())//New datum requests haven't updated it - bySysIdx.resize(particleCount); - - foreach (QSGParticlePainter *p, m_painters) - loadPainter(p); - - if (!m_groups.isEmpty()) - createEngine(); - -} - -void QSGParticleSystem::createEngine() -{ - if (!m_componentComplete) - return; - if (stateEngine && m_debugMode) - qDebug() << "Resetting Existing Sprite Engine..."; - //### Solve the losses if size/states go down - foreach (QSGParticleGroup* group, m_groups){ - bool exists = false; - foreach (const QString &name, groupIds.keys()) - if (group->name() == name) - exists = true; - if (!exists){ - int id = m_nextGroupId++; - QSGParticleGroupData* gd = new QSGParticleGroupData(id, this); - groupIds.insert(group->name(), id); - groupData.insert(id, gd); - } - } - - if (m_groups.count()){ - //Reorder groups List so as to have the same order as groupData - QList newList; - for (int i=0; iname(); - foreach (QSGParticleGroup* existing, m_groups){ - if (existing->name() == name){ - newList << existing; - exists = true; - } - } - if (!exists){ - newList << new QSGParticleGroup(this); - newList.back()->setName(name); - } - } - m_groups = newList; - QList states; - foreach (QSGParticleGroup* g, m_groups) - states << (QQuickStochasticState*)g; - - if (!stateEngine) - stateEngine = new QQuickStochasticEngine(this); - stateEngine->setCount(particleCount); - stateEngine->m_states = states; - - connect(stateEngine, SIGNAL(stateChanged(int)), - this, SLOT(particleStateChange(int))); - - }else{ - if (stateEngine) - delete stateEngine; - stateEngine = 0; - } - -} - -void QSGParticleSystem::particleStateChange(int idx) -{ - moveGroups(bySysIdx[idx], stateEngine->curState(idx)); -} - -void QSGParticleSystem::moveGroups(QSGParticleData *d, int newGIdx) -{ - if (!d || newGIdx == d->group) - return; - - QSGParticleData* pd = newDatum(newGIdx, false, d->systemIndex); - if (!pd) - return; - - pd->clone(*d); - finishNewDatum(pd); - - d->systemIndex = -1; - groupData[d->group]->kill(d); -} - -int QSGParticleSystem::nextSystemIndex() -{ - if (!m_reusableIndexes.isEmpty()){ - int ret = *(m_reusableIndexes.begin()); - m_reusableIndexes.remove(ret); - return ret; - } - if (m_nextIndex >= bySysIdx.size()){ - bySysIdx.resize(bySysIdx.size() < 10 ? 10 : bySysIdx.size()*1.1);//###+1,10%,+10? Choose something non-arbitrarily - if (stateEngine) - stateEngine->setCount(bySysIdx.size()); - - } - return m_nextIndex++; -} - -QSGParticleData* QSGParticleSystem::newDatum(int groupId, bool respectLimits, int sysIndex) -{ - Q_ASSERT(groupId < groupData.count());//XXX shouldn't really be an assert - - QSGParticleData* ret = groupData[groupId]->newDatum(respectLimits); - if (!ret){ - return 0; - } - if (sysIndex == -1){ - if (ret->systemIndex == -1) - ret->systemIndex = nextSystemIndex(); - }else{ - if (ret->systemIndex != -1){ - if (stateEngine) - stateEngine->stop(ret->systemIndex); - m_reusableIndexes << ret->systemIndex; - bySysIdx[ret->systemIndex] = 0; - } - ret->systemIndex = sysIndex; - } - bySysIdx[ret->systemIndex] = ret; - - if (stateEngine) - stateEngine->start(ret->systemIndex, ret->group); - - m_empty = false; - return ret; -} - -void QSGParticleSystem::emitParticle(QSGParticleData* pd) -{// called from prepareNextFrame()->emitWindow - enforce? - //Account for relative emitter position - QPointF offset = this->mapFromItem(pd->e, QPointF(0, 0)); - if (!offset.isNull()){ - pd->x += offset.x(); - pd->y += offset.y(); - } - - finishNewDatum(pd); -} - -void QSGParticleSystem::finishNewDatum(QSGParticleData *pd){ - Q_ASSERT(pd); - groupData[pd->group]->prepareRecycler(pd); - - foreach (QSGParticleAffector *a, m_affectors) - if (a && a->m_needsReset) - a->reset(pd); - foreach (QSGParticlePainter* p, groupData[pd->group]->painters) - if (p) - p->load(pd); -} - -void QSGParticleSystem::updateCurrentTime( int currentTime ) -{ - if (!initialized) - return;//error in initialization - - //### Elapsed time never shrinks - may cause problems if left emitting for weeks at a time. - qreal dt = timeInt / 1000.; - timeInt = currentTime; - qreal time = timeInt / 1000.; - dt = time - dt; - needsReset.clear(); - - bool oldClear = m_empty; - m_empty = true; - foreach (QSGParticleGroupData* gd, groupData)//Recycle all groups and see if they're out of live particles - m_empty = gd->recycle() && m_empty; - - if (stateEngine) - stateEngine->updateSprites(timeInt); - - foreach (QSGParticleEmitter* emitter, m_emitters) - if (emitter) - emitter->emitWindow(timeInt); - foreach (QSGParticleAffector* a, m_affectors) - if (a) - a->affectSystem(dt); - foreach (QSGParticleData* d, needsReset) - foreach (QSGParticlePainter* p, groupData[d->group]->painters) - if (p && d) - p->reload(d); - - if (oldClear != m_empty) - emptyChanged(m_empty); -} - -int QSGParticleSystem::systemSync(QSGParticlePainter* p) -{ - if (!m_running) - return 0; - if (!initialized) - return 0;//error in initialization - p->performPendingCommits(); - return timeInt; -} - - -QT_END_NAMESPACE diff --git a/src/declarative/particles/qsgparticlesystem_p.h b/src/declarative/particles/qsgparticlesystem_p.h deleted file mode 100644 index 714b536e45..0000000000 --- a/src/declarative/particles/qsgparticlesystem_p.h +++ /dev/null @@ -1,378 +0,0 @@ -/**************************************************************************** -** -** 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 PARTICLESYSTEM_H -#define PARTICLESYSTEM_H - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include //For QDeclarativeV8Handle - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QSGParticleSystem; -class QSGParticleAffector; -class QSGParticleEmitter; -class QSGParticlePainter; -class QSGParticleData; -class QSGParticleSystemAnimation; -class QQuickStochasticEngine; -class QQuickSprite; -class QSGV8ParticleData; -class QSGParticleGroup; -class QSGImageParticle; - -struct QSGParticleDataHeapNode{ - int time;//in ms - QSet data;//Set ptrs instead? -}; - -class QSGParticleDataHeap { - //Idea is to do a binary heap, but which also stores a set of int,Node* so that if the int already exists, you can - //add it to the data* list. Pops return the whole list at once. -public: - QSGParticleDataHeap(); - void insert(QSGParticleData* data); - void insertTimed(QSGParticleData* data, int time); - - int top(); - - QSet pop(); - - void clear(); - - bool contains(QSGParticleData*);//O(n), for debugging purposes only -private: - void grow(); - void swap(int, int); - void bubbleUp(int); - void bubbleDown(int); - int m_size; - int m_end; - QSGParticleDataHeapNode m_tmp; - QVector m_data; - QHash m_lookups; -}; - -class Q_AUTOTEST_EXPORT QSGParticleGroupData { -public: - QSGParticleGroupData(int id, QSGParticleSystem* sys); - ~QSGParticleGroupData(); - - int size(); - QString name(); - - void setSize(int newSize); - - int index; - QSet painters; - - //TODO: Refactor particle data list out into a separate class - QVector data; - QSGParticleDataHeap dataHeap; - QSet reusableIndexes; - bool recycle(); //Force recycling round, reutrns true if all indexes are now reusable - - void initList(); - void kill(QSGParticleData* d); - - //After calling this, initialize, then call prepareRecycler(d) - QSGParticleData* newDatum(bool respectsLimits); - - //TODO: Find and clean up those that don't get added to the recycler (currently they get lost) - void prepareRecycler(QSGParticleData* d); - -private: - int m_size; - QSGParticleSystem* m_system; -}; - -struct Color4ub { - uchar r; - uchar g; - uchar b; - uchar a; -}; - -class Q_AUTOTEST_EXPORT QSGParticleData { -public: - //TODO: QObject like memory management (without the cost, just attached to system) - QSGParticleData(QSGParticleSystem* sys); - - //Convenience functions for working backwards, because parameters are from the start of particle life - //If setting multiple parameters at once, doing the conversion yourself will be faster. - - //sets the x accleration without affecting the instantaneous x velocity or position - void setInstantaneousAX(qreal ax); - //sets the x velocity without affecting the instantaneous x postion - void setInstantaneousVX(qreal vx); - //sets the instantaneous x postion - void setInstantaneousX(qreal x); - //sets the y accleration without affecting the instantaneous y velocity or position - void setInstantaneousAY(qreal ay); - //sets the y velocity without affecting the instantaneous y postion - void setInstantaneousVY(qreal vy); - //sets the instantaneous Y postion - void setInstantaneousY(qreal y); - - //TODO: Slight caching? - qreal curX() const; - qreal curVX() const; - qreal curAX() const { return ax; } - qreal curY() const; - qreal curVY() const; - qreal curAY() const { return ay; } - - int group; - QSGParticleEmitter* e;//### Needed? - QSGParticleSystem* system; - int index; - int systemIndex; - - //General Position Stuff - float x; - float y; - float t; - float lifeSpan; - float size; - float endSize; - float vx; - float vy; - float ax; - float ay; - - //Other stuff, now universally shared - Color4ub color; - float xx; - float xy; - float yx; - float yy; - float rotation; - float rotationSpeed; - float autoRotate;//Assume that GPUs prefer floats to bools - float animIdx; - float frameDuration; - float frameCount; - float animT; - float animX; - float animY; - float animWidth; - float animHeight; - float r; - QQuickItem* delegate; - int modelIndex; - float update;//Used by custom affectors - - //Used by image particle - QSGImageParticle* colorOwner; - QSGImageParticle* rotationOwner; - QSGImageParticle* deformationOwner; - QSGImageParticle* animationOwner; - - void debugDump(); - bool stillAlive(); - float lifeLeft(); - float curSize(); - void clone(const QSGParticleData& other);//Not =, leaves meta-data like index - QDeclarativeV8Handle v8Value(); - void extendLife(float time); -private: - QSGV8ParticleData* v8Datum; -}; - -class Q_AUTOTEST_EXPORT QSGParticleSystem : public QQuickItem -{ - Q_OBJECT - Q_PROPERTY(bool running READ isRunning WRITE setRunning NOTIFY runningChanged) - Q_PROPERTY(bool paused READ isPaused WRITE setPaused NOTIFY pausedChanged) - Q_PROPERTY(bool empty READ isEmpty NOTIFY emptyChanged) - -public: - explicit QSGParticleSystem(QQuickItem *parent = 0); - ~QSGParticleSystem(); - - bool isRunning() const - { - return m_running; - } - - int count(){ return particleCount; } - - static const int maxLife = 600000; - -signals: - - void systemInitialized(); - void runningChanged(bool arg); - void pausedChanged(bool arg); - void emptyChanged(bool arg); - -public slots: - void start(){setRunning(true);} - void stop(){setRunning(false);} - void restart(){setRunning(false);setRunning(true);} - void pause(){setPaused(true);} - void resume(){setPaused(false);} - - void reset(); - void setRunning(bool arg); - void setPaused(bool arg); - - virtual int duration() const { return -1; } - - -protected: - //This one only once per frame (effectively) - void componentComplete(); - -private slots: - void emittersChanged(); - void loadPainter(QObject* p); - void createEngine(); //Not invoked by sprite engine, unlike Sprite uses - void particleStateChange(int idx); - -public: - //These can be called multiple times per frame, performance critical - void emitParticle(QSGParticleData* p); - QSGParticleData* newDatum(int groupId, bool respectLimits = true, int sysIdx = -1); - void finishNewDatum(QSGParticleData*); - void moveGroups(QSGParticleData *d, int newGIdx); - int nextSystemIndex(); - - //This one only once per painter per frame - int systemSync(QSGParticlePainter* p); - - //Data members here for ease of related class and auto-test usage. Not "public" API. TODO: d_ptrize - QSet needsReset; - QVector bySysIdx; //Another reference to the data (data owned by group), but by sysIdx - QHash groupIds; - QHash groupData; - QQuickStochasticEngine* stateEngine; - - //Also only here for auto-test usage - void updateCurrentTime( int currentTime ); - QSGParticleSystemAnimation* m_animation; - bool m_running; - - int timeInt; - bool initialized; - int particleCount; - - void registerParticlePainter(QSGParticlePainter* p); - void registerParticleEmitter(QSGParticleEmitter* e); - void registerParticleAffector(QSGParticleAffector* a); - void registerParticleGroup(QSGParticleGroup* g); - - static void statePropertyRedirect(QDeclarativeListProperty *prop, QObject *value); - static void stateRedirect(QSGParticleGroup* group, QSGParticleSystem* sys, QObject *value); - bool isPaused() const - { - return m_paused; - } - - bool isEmpty() const - { - return m_empty; - } - -private: - void initializeSystem(); - void initGroups(); - QList > m_emitters; - QList > m_affectors; - QList > m_painters; - QList > m_syncList; - QList m_groups; - int m_nextGroupId; - int m_nextIndex; - QSet m_reusableIndexes; - bool m_componentComplete; - - QSignalMapper m_painterMapper; - QSignalMapper m_emitterMapper; - bool m_paused; - bool m_debugMode; - bool m_allDead; - bool m_empty; -}; - -// Internally, this animation drives all the timing. Painters sync up in their updatePaintNode -class QSGParticleSystemAnimation : public QAbstractAnimation -{ - Q_OBJECT -public: - QSGParticleSystemAnimation(QSGParticleSystem* system) - : QAbstractAnimation(static_cast(system)), m_system(system) - { } -protected: - virtual void updateCurrentTime( int t ) - { - m_system->updateCurrentTime(t); - } - - virtual int duration() const - { - return -1; - } - -private: - QSGParticleSystem* m_system; -}; - - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // PARTICLESYSTEM_H - - diff --git a/src/declarative/particles/qsgpointattractor.cpp b/src/declarative/particles/qsgpointattractor.cpp deleted file mode 100644 index 8fb7551018..0000000000 --- a/src/declarative/particles/qsgpointattractor.cpp +++ /dev/null @@ -1,162 +0,0 @@ -/**************************************************************************** -** -** 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 "qsgpointattractor_p.h" -#include -#include -QT_BEGIN_NAMESPACE -/*! - \qmlclass Attractor QSGAttractorAffector - \inqmlmodule QtQuick.Particles 2 - \inherits Affector - \brief The Attractor allows you to attract particles towards a specific point. - - Note that the size and position of this element affects which particles it affects. - The size of the point attracted to is always 0x0, and the location of that point - is specified by the pointX and pointY properties. - - Note that Attractor has the standard Item x,y,width and height properties. - Like other affectors, these represent the affected area. They - do not represent the 0x0 point which is the target of the attraction. -*/ - - -/*! - \qmlproperty real QtQuick.Particles2::PointAttractor::pointX - - The x coordinate of the attracting point. This is relative - to the x coordinate of the Attractor. -*/ -/*! - \qmlproperty real QtQuick.Particles2::PointAttractor::pointY - - The y coordinate of the attracting point. This is relative - to the y coordinate of the Attractor. -*/ -/*! - \qmlproperty real QtQuick.Particles2::PointAttractor::strength - - The pull, in units per second, to be exerted on an item one pixel away. - - Depending on how the attraction is proportionalToDistance this may have to - be very high or very low to have a reasonable effect on particles at a - distance. -*/ -/*! - \qmlproperty AffectableParameter QtQuick.Particles2::Attractor::affectedParameter - - What attribute of particles is directly affected. - \list - \o Attractor.Position - \o Attractor.Velocity - \o Attractor.Acceleration - \endlist -*/ -/*! - \qmlproperty Proportion QtQuick.Particles2::Attractor::proportionalToDistance - - How the distance from the particle to the point affects the strength of the attraction. - - \list - \o Attractor.Constant - \o Attractor.Linear - \o Attractor.InverseLinear - \o Attractor.Quadratic - \o Attractor.InverseQuadratic - \endlist -*/ - - -QSGAttractorAffector::QSGAttractorAffector(QQuickItem *parent) : - QSGParticleAffector(parent), m_strength(0.0), m_x(0), m_y(0) - , m_physics(Velocity), m_proportionalToDistance(Linear) -{ -} - -bool QSGAttractorAffector::affectParticle(QSGParticleData *d, qreal dt) -{ - if (m_strength == 0.0) - return false; - qreal dx = m_x+m_offset.x() - d->curX(); - qreal dy = m_y+m_offset.y() - d->curY(); - qreal r = sqrt((dx*dx) + (dy*dy)); - qreal theta = atan2(dy,dx); - qreal ds = 0; - switch (m_proportionalToDistance){ - case InverseQuadratic: - ds = (m_strength / qMax(1.,r*r)); - break; - case InverseLinear: - ds = (m_strength / qMax(1.,r)); - break; - case Quadratic: - ds = (m_strength * qMax(1.,r*r)); - break; - case Linear: - ds = (m_strength * qMax(1.,r)); - break; - default: //also Constant - ds = m_strength; - } - ds *= dt; - dx = ds * cos(theta); - dy = ds * sin(theta); - qreal vx,vy; - switch (m_physics){ - case Position: - d->x = (d->x + dx); - d->y = (d->y + dy); - break; - case Acceleration: - d->setInstantaneousAX(d->ax + dx); - d->setInstantaneousAY(d->ay + dy); - break; - case Velocity: //also default - default: - vx = d->curVX(); - vy = d->curVY(); - d->setInstantaneousVX(vx + dx); - d->setInstantaneousVY(vy + dy); - } - - return true; -} -QT_END_NAMESPACE diff --git a/src/declarative/particles/qsgpointattractor_p.h b/src/declarative/particles/qsgpointattractor_p.h deleted file mode 100644 index b7dcf62fc4..0000000000 --- a/src/declarative/particles/qsgpointattractor_p.h +++ /dev/null @@ -1,169 +0,0 @@ -/**************************************************************************** -** -** 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 ATTRACTORAFFECTOR_H -#define ATTRACTORAFFECTOR_H -#include "qsgparticleaffector_p.h" - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QSGAttractorAffector : public QSGParticleAffector -{ - Q_OBJECT - Q_PROPERTY(qreal strength READ strength WRITE setStrength NOTIFY strengthChanged) - Q_PROPERTY(qreal pointX READ pointX WRITE setPointX NOTIFY pointXChanged) - Q_PROPERTY(qreal pointY READ pointY WRITE setPointY NOTIFY pointYChanged) - Q_PROPERTY(AffectableParameters affectedParameter READ affectedParameter WRITE setAffectedParameter NOTIFY affectedParameterChanged) - Q_PROPERTY(Proportion proportionalToDistance READ proportionalToDistance WRITE setProportionalToDistance NOTIFY proportionalToDistanceChanged) - Q_ENUMS(AffectableParameters) - Q_ENUMS(Proportion) - -public: - enum Proportion{ - Constant, - Linear, - Quadratic, - InverseLinear, - InverseQuadratic - }; - - enum AffectableParameters { - Position, - Velocity, - Acceleration - }; - - explicit QSGAttractorAffector(QQuickItem *parent = 0); - - qreal strength() const - { - return m_strength; - } - - qreal pointX() const - { - return m_x; - } - - qreal pointY() const - { - return m_y; - } - - AffectableParameters affectedParameter() const - { - return m_physics; - } - - Proportion proportionalToDistance() const - { - return m_proportionalToDistance; - } - -signals: - - void strengthChanged(qreal arg); - - void pointXChanged(qreal arg); - - void pointYChanged(qreal arg); - - void affectedParameterChanged(AffectableParameters arg); - - void proportionalToDistanceChanged(Proportion arg); - -public slots: -void setStrength(qreal arg) -{ - if (m_strength != arg) { - m_strength = arg; - emit strengthChanged(arg); - } -} - -void setPointX(qreal arg) -{ - if (m_x != arg) { - m_x = arg; - emit pointXChanged(arg); - } -} - -void setPointY(qreal arg) -{ - if (m_y != arg) { - m_y = arg; - emit pointYChanged(arg); - } -} -void setAffectedParameter(AffectableParameters arg) -{ - if (m_physics != arg) { - m_physics = arg; - emit affectedParameterChanged(arg); - } -} - -void setProportionalToDistance(Proportion arg) -{ - if (m_proportionalToDistance != arg) { - m_proportionalToDistance = arg; - emit proportionalToDistanceChanged(arg); - } -} - -protected: - virtual bool affectParticle(QSGParticleData *d, qreal dt); -private: -qreal m_strength; -qreal m_x; -qreal m_y; -AffectableParameters m_physics; -Proportion m_proportionalToDistance; -}; - -QT_END_NAMESPACE -QT_END_HEADER -#endif // ATTRACTORAFFECTOR_H diff --git a/src/declarative/particles/qsgpointdirection.cpp b/src/declarative/particles/qsgpointdirection.cpp deleted file mode 100644 index 2b83c271a3..0000000000 --- a/src/declarative/particles/qsgpointdirection.cpp +++ /dev/null @@ -1,85 +0,0 @@ -/**************************************************************************** -** -** 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 "qsgpointdirection_p.h" - -QT_BEGIN_NAMESPACE - -/*! - \qmlclass PointDirection QSGPointDirection - \inqmlmodule QtQuick.Particles 2 - \inherits Direction - \brief The PointDirection element allows you to specify a direction that varies in x and y components - - The PointDirection element allows both the specification of a direction by x and y components, - as well as varying the parameters by x or y component. -*/ -/*! - \qmlproperty real QtQuick.Particles2::PointDirection::x -*/ -/*! - \qmlproperty real QtQuick.Particles2::PointDirection::y -*/ -/*! - \qmlproperty real QtQuick.Particles2::PointDirection::xVariation -*/ -/*! - \qmlproperty real QtQuick.Particles2::PointDirection::yVariation -*/ - -QSGPointDirection::QSGPointDirection(QObject *parent) : - QSGDirection(parent) - , m_x(0) - , m_y(0) - , m_xVariation(0) - , m_yVariation(0) -{ -} - -const QPointF QSGPointDirection::sample(const QPointF &) -{ - QPointF ret; - ret.setX(m_x - m_xVariation + rand() / float(RAND_MAX) * m_xVariation * 2); - ret.setY(m_y - m_yVariation + rand() / float(RAND_MAX) * m_yVariation * 2); - return ret; -} - -QT_END_NAMESPACE diff --git a/src/declarative/particles/qsgpointdirection_p.h b/src/declarative/particles/qsgpointdirection_p.h deleted file mode 100644 index 0a4c17f236..0000000000 --- a/src/declarative/particles/qsgpointdirection_p.h +++ /dev/null @@ -1,135 +0,0 @@ -/**************************************************************************** -** -** 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 POINTVECTOR_H -#define POINTVECTOR_H -#include "qsgdirection_p.h" - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QSGPointDirection : public QSGDirection -{ - Q_OBJECT - Q_PROPERTY(qreal x READ x WRITE setX NOTIFY xChanged) - Q_PROPERTY(qreal y READ y WRITE setY NOTIFY yChanged) - Q_PROPERTY(qreal xVariation READ xVariation WRITE setXVariation NOTIFY xVariationChanged) - Q_PROPERTY(qreal yVariation READ yVariation WRITE setYVariation NOTIFY yVariationChanged) -public: - explicit QSGPointDirection(QObject *parent = 0); - virtual const QPointF sample(const QPointF &from); - qreal x() const - { - return m_x; - } - - qreal y() const - { - return m_y; - } - - qreal xVariation() const - { - return m_xVariation; - } - - qreal yVariation() const - { - return m_yVariation; - } - -signals: - - void xChanged(qreal arg); - - void yChanged(qreal arg); - - void xVariationChanged(qreal arg); - - void yVariationChanged(qreal arg); - -public slots: - void setX(qreal arg) - { - if (m_x != arg) { - m_x = arg; - emit xChanged(arg); - } - } - - void setY(qreal arg) - { - if (m_y != arg) { - m_y = arg; - emit yChanged(arg); - } - } - - void setXVariation(qreal arg) - { - if (m_xVariation != arg) { - m_xVariation = arg; - emit xVariationChanged(arg); - } - } - - void setYVariation(qreal arg) - { - if (m_yVariation != arg) { - m_yVariation = arg; - emit yVariationChanged(arg); - } - } - -private: - - qreal m_x; - qreal m_y; - qreal m_xVariation; - qreal m_yVariation; -}; - -QT_END_NAMESPACE -QT_END_HEADER -#endif // POINTVECTOR_H diff --git a/src/declarative/particles/qsgrectangleextruder.cpp b/src/declarative/particles/qsgrectangleextruder.cpp deleted file mode 100644 index fde227c5b8..0000000000 --- a/src/declarative/particles/qsgrectangleextruder.cpp +++ /dev/null @@ -1,86 +0,0 @@ -/**************************************************************************** -** -** 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 "qsgrectangleextruder_p.h" - -QT_BEGIN_NAMESPACE - -/*! - \qmlclass RectangleShape QSGRectangleExtruder - \inqmlmodule QtQuick.Particles 2 - \brief The RectangleShape element allows you to specify an area for affectors and emitter. - - Just a rectangle. -*/ - -QSGRectangleExtruder::QSGRectangleExtruder(QObject *parent) : - QSGParticleExtruder(parent), m_fill(true) -{ -} - -QPointF QSGRectangleExtruder::extrude(const QRectF &rect) -{ - if (m_fill) - return QPointF(((qreal)rand() / RAND_MAX) * rect.width() + rect.x(), - ((qreal)rand() / RAND_MAX) * rect.height() + rect.y()); - int side = rand() % 4; - switch (side){//TODO: Doesn't this overlap the corners? - case 0: - return QPointF(rect.x(), - ((qreal)rand() / RAND_MAX) * rect.height() + rect.y()); - case 1: - return QPointF(rect.width() + rect.x(), - ((qreal)rand() / RAND_MAX) * rect.height() + rect.y()); - case 2: - return QPointF(((qreal)rand() / RAND_MAX) * rect.width() + rect.x(), - rect.y()); - default: - return QPointF(((qreal)rand() / RAND_MAX) * rect.width() + rect.x(), - rect.height() + rect.y()); - } -} - -bool QSGRectangleExtruder::contains(const QRectF &bounds, const QPointF &point) -{ - return bounds.contains(point); -} - -QT_END_NAMESPACE diff --git a/src/declarative/particles/qsgrectangleextruder_p.h b/src/declarative/particles/qsgrectangleextruder_p.h deleted file mode 100644 index 9cc51b2cb7..0000000000 --- a/src/declarative/particles/qsgrectangleextruder_p.h +++ /dev/null @@ -1,88 +0,0 @@ -/**************************************************************************** -** -** 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 RECTANGLEEXTRUDER_H -#define RECTANGLEEXTRUDER_H - -#include "qsgparticleextruder_p.h" - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QSGRectangleExtruder : public QSGParticleExtruder -{ - Q_OBJECT - Q_PROPERTY(bool fill READ fill WRITE setFill NOTIFY fillChanged) - -public: - explicit QSGRectangleExtruder(QObject *parent = 0); - virtual QPointF extrude(const QRectF &); - virtual bool contains(const QRectF &bounds, const QPointF &point); - bool fill() const - { - return m_fill; - } - -signals: - - void fillChanged(bool arg); - -public slots: - - void setFill(bool arg) - { - if (m_fill != arg) { - m_fill = arg; - emit fillChanged(arg); - } - } -protected: - bool m_fill; -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // RectangleEXTRUDER_H diff --git a/src/declarative/particles/qsgspritegoal.cpp b/src/declarative/particles/qsgspritegoal.cpp deleted file mode 100644 index 6d4c0a309c..0000000000 --- a/src/declarative/particles/qsgspritegoal.cpp +++ /dev/null @@ -1,153 +0,0 @@ -/**************************************************************************** -** -** 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 "qsgspritegoal_p.h" -#include -#include -#include "qsgimageparticle_p.h" -#include - -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 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(QQuickItem *parent) : - QSGParticleAffector(parent), - m_goalIdx(-1), - m_lastEngine(0), - m_jump(false), - m_systemStates(false), - m_notUsingEngine(false) -{ - m_ignoresTime = true; -} - -void QSGSpriteGoalAffector::updateStateIndex(QQuickStochasticEngine* e) -{ - if (m_systemStates){ - m_goalIdx = m_system->groupIds[m_goalState]; - }else{ - m_lastEngine = e; - for (int i=0; istateCount(); i++){ - if (e->state(i)->name() == m_goalState){ - m_goalIdx = i; - return; - } - } - m_goalIdx = -1;//Can't find it - } -} - -void QSGSpriteGoalAffector::setGoalState(QString arg) -{ - if (m_goalState != arg) { - m_goalState = arg; - emit goalStateChanged(arg); - if (m_goalState.isEmpty()) - m_goalIdx = -1; - else - m_goalIdx = -2; - } -} - -bool QSGSpriteGoalAffector::affectParticle(QSGParticleData *d, qreal dt) -{ - Q_UNUSED(dt); - QQuickStochasticEngine *engine = 0; - if (!m_systemStates){ - //TODO: Affect all engines - foreach (QSGParticlePainter *p, m_system->groupData[d->group]->painters) - if (qobject_cast(p)) - engine = qobject_cast(p)->spriteEngine(); - }else{ - engine = m_system->stateEngine; - if (!engine) - m_notUsingEngine = true; - } - if (!engine && !m_notUsingEngine) - return false; - - if (m_goalIdx == -2 || engine != m_lastEngine) - updateStateIndex(engine); - int index = d->index; - if (m_systemStates) - index = d->systemIndex; - if (m_notUsingEngine){//systemStates && 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, m_goalIdx); - }else if (engine->curState(index) != m_goalIdx){ - engine->setGoal(m_goalIdx, index, m_jump); - return true; //Doesn't affect particle data, but necessary for onceOff - } - return false; -} - -QT_END_NAMESPACE diff --git a/src/declarative/particles/qsgspritegoal_p.h b/src/declarative/particles/qsgspritegoal_p.h deleted file mode 100644 index bdb86d7705..0000000000 --- a/src/declarative/particles/qsgspritegoal_p.h +++ /dev/null @@ -1,125 +0,0 @@ -/**************************************************************************** -** -** 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 SPRITEGOALAFFECTOR_H -#define SPRITEGOALAFFECTOR_H -#include "qsgparticleaffector_p.h" -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QQuickStochasticEngine; - -class QSGSpriteGoalAffector : public QSGParticleAffector -{ - Q_OBJECT - Q_PROPERTY(QString goalState READ goalState WRITE setGoalState NOTIFY goalStateChanged) - Q_PROPERTY(bool jump READ jump WRITE setJump NOTIFY jumpChanged) - Q_PROPERTY(bool systemStates READ systemStates WRITE setSystemStates NOTIFY systemStatesChanged) -public: - explicit QSGSpriteGoalAffector(QQuickItem *parent = 0); - - QString goalState() const - { - return m_goalState; - } - - bool jump() const - { - return m_jump; - } - bool systemStates() const - { - return m_systemStates; - } - -protected: - virtual bool affectParticle(QSGParticleData *d, qreal dt); -signals: - - void goalStateChanged(QString arg); - - void jumpChanged(bool arg); - - void systemStatesChanged(bool arg); - -public slots: - -void setGoalState(QString arg); - -void setJump(bool arg) -{ - if (m_jump != arg) { - m_jump = arg; - emit jumpChanged(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); - } -} - -private: - void updateStateIndex(QQuickStochasticEngine* e); - QString m_goalState; - int m_goalIdx; - QQuickStochasticEngine* m_lastEngine; - bool m_jump; - bool m_systemStates; - - bool m_notUsingEngine; -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // SPRITEGOALAFFECTOR_H diff --git a/src/declarative/particles/qsgtargetdirection.cpp b/src/declarative/particles/qsgtargetdirection.cpp deleted file mode 100644 index 79ba433851..0000000000 --- a/src/declarative/particles/qsgtargetdirection.cpp +++ /dev/null @@ -1,131 +0,0 @@ -/**************************************************************************** -** -** 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 "qsgtargetdirection_p.h" -#include "qsgparticleemitter_p.h" -#include -#include - -QT_BEGIN_NAMESPACE -/*! - \qmlclass TargetDirection QSGTargetDirection - \inqmlmodule QtQuick.Particles 2 - \inherits Direction - \brief The TargetDirection element allows you to specify a direction towards the target point - -*/ -/*! - \qmlproperty real QtQuick.Particles2::TargetDirection::targetX -*/ -/*! - \qmlproperty real QtQuick.Particles2::TargetDirection::targetY -*/ -/*! - \qmlproperty Item QtQuick.Particles2::TargetDirection::targetItem - If specified, this will take precedence over targetX and targetY. - The targeted point will be the center of the specified Item -*/ -/*! - \qmlproperty real QtQuick.Particles2::TargetDirection::targetVariation -*/ -/*! - \qmlproperty real QtQuick.Particles2::TargetDirection::magnitude -*/ -/*! - \qmlproperty real QtQuick.Particles2::TargetDirection::magnitudeVariation -*/ -/*! - \qmlproperty bool QtQuick.Particles2::TargetDirection::proportionalMagnitude - - If true, then the value of magnitude and magnitudeVariation shall be interpreted as multiples - of the distance between the source point and the target point, per second. - - If false(default), then the value of magnitude and magnitudeVariation shall be interpreted as - pixels per second. -*/ - -QSGTargetDirection::QSGTargetDirection(QObject *parent) : - QSGDirection(parent) - , m_targetX(0) - , m_targetY(0) - , m_targetVariation(0) - , m_proportionalMagnitude(false) - , m_magnitude(0) - , m_magnitudeVariation(0) - , m_targetItem(0) -{ -} - -const QPointF QSGTargetDirection::sample(const QPointF &from) -{ - //###This approach loses interpolating the last position of the target (like we could with the emitter) is it worthwhile? - QPointF ret; - qreal targetX; - qreal targetY; - if (m_targetItem){ - QSGParticleEmitter* parentEmitter = qobject_cast(parent()); - targetX = m_targetItem->width()/2; - targetY = m_targetItem->height()/2; - if (!parentEmitter){ - qWarning() << "Directed vector is not a child of the emitter. Mapping of target item coordinates may fail."; - targetX += m_targetItem->x(); - targetY += m_targetItem->y(); - }else{ - ret = parentEmitter->mapFromItem(m_targetItem, QPointF(targetX, targetY)); - targetX = ret.x(); - targetY = ret.y(); - } - }else{ - targetX = m_targetX; - targetY = m_targetY; - } - targetX += 0 - from.x() - m_targetVariation + rand()/(float)RAND_MAX * m_targetVariation*2; - targetY += 0 - from.y() - m_targetVariation + rand()/(float)RAND_MAX * m_targetVariation*2; - qreal theta = atan2(targetY, targetX); - qreal mag = m_magnitude + rand()/(float)RAND_MAX * m_magnitudeVariation * 2 - m_magnitudeVariation; - if (m_proportionalMagnitude) - mag *= sqrt(targetX * targetX + targetY * targetY); - ret.setX(mag * cos(theta)); - ret.setY(mag * sin(theta)); - return ret; -} - -QT_END_NAMESPACE diff --git a/src/declarative/particles/qsgtargetdirection_p.h b/src/declarative/particles/qsgtargetdirection_p.h deleted file mode 100644 index 5a412ee870..0000000000 --- a/src/declarative/particles/qsgtargetdirection_p.h +++ /dev/null @@ -1,191 +0,0 @@ -/**************************************************************************** -** -** 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 DIRECTEDVECTOR_H -#define DIRECTEDVECTOR_H -#include "qsgdirection_p.h" -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QQuickItem; -class QSGTargetDirection : public QSGDirection -{ - Q_OBJECT - Q_PROPERTY(qreal targetX READ targetX WRITE setTargetX NOTIFY targetXChanged) - Q_PROPERTY(qreal targetY READ targetY WRITE setTargetY NOTIFY targetYChanged) - //If targetItem is set, X/Y are ignored. Aims at middle of item, use variation for variation - Q_PROPERTY(QQuickItem* targetItem READ targetItem WRITE setTargetItem NOTIFY targetItemChanged) - - Q_PROPERTY(qreal targetVariation READ targetVariation WRITE setTargetVariation NOTIFY targetVariationChanged) - - //TODO: An enum would be better - Q_PROPERTY(bool proportionalMagnitude READ proportionalMagnitude WRITE setProportionalMagnitude NOTIFY proprotionalMagnitudeChanged) - Q_PROPERTY(qreal magnitude READ magnitude WRITE setMagnitude NOTIFY magnitudeChanged) - Q_PROPERTY(qreal magnitudeVariation READ magnitudeVariation WRITE setMagnitudeVariation NOTIFY magnitudeVariationChanged) - -public: - explicit QSGTargetDirection(QObject *parent = 0); - virtual const QPointF sample(const QPointF &from); - - qreal targetX() const - { - return m_targetX; - } - - qreal targetY() const - { - return m_targetY; - } - - qreal targetVariation() const - { - return m_targetVariation; - } - - qreal magnitude() const - { - return m_magnitude; - } - - bool proportionalMagnitude() const - { - return m_proportionalMagnitude; - } - - qreal magnitudeVariation() const - { - return m_magnitudeVariation; - } - - QQuickItem* targetItem() const - { - return m_targetItem; - } - -signals: - - void targetXChanged(qreal arg); - - void targetYChanged(qreal arg); - - void targetVariationChanged(qreal arg); - - void magnitudeChanged(qreal arg); - - void proprotionalMagnitudeChanged(bool arg); - - void magnitudeVariationChanged(qreal arg); - - void targetItemChanged(QQuickItem* arg); - -public slots: - void setTargetX(qreal arg) - { - if (m_targetX != arg) { - m_targetX = arg; - emit targetXChanged(arg); - } - } - - void setTargetY(qreal arg) - { - if (m_targetY != arg) { - m_targetY = arg; - emit targetYChanged(arg); - } - } - - void setTargetVariation(qreal arg) - { - if (m_targetVariation != arg) { - m_targetVariation = arg; - emit targetVariationChanged(arg); - } - } - - void setMagnitude(qreal arg) - { - if (m_magnitude != arg) { - m_magnitude = arg; - emit magnitudeChanged(arg); - } - } - - void setProportionalMagnitude(bool arg) - { - if (m_proportionalMagnitude != arg) { - m_proportionalMagnitude = arg; - emit proprotionalMagnitudeChanged(arg); - } - } - - void setMagnitudeVariation(qreal arg) - { - if (m_magnitudeVariation != arg) { - m_magnitudeVariation = arg; - emit magnitudeVariationChanged(arg); - } - } - - void setTargetItem(QQuickItem* arg) - { - if (m_targetItem != arg) { - m_targetItem = arg; - emit targetItemChanged(arg); - } - } - -private: - qreal m_targetX; - qreal m_targetY; - qreal m_targetVariation; - bool m_proportionalMagnitude; - qreal m_magnitude; - qreal m_magnitudeVariation; - QQuickItem *m_targetItem; -}; - -QT_END_NAMESPACE -QT_END_HEADER -#endif // DIRECTEDVECTOR_H diff --git a/src/declarative/particles/qsgtrailemitter.cpp b/src/declarative/particles/qsgtrailemitter.cpp deleted file mode 100644 index 08818ec085..0000000000 --- a/src/declarative/particles/qsgtrailemitter.cpp +++ /dev/null @@ -1,284 +0,0 @@ -/**************************************************************************** -** -** 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 "qsgtrailemitter_p.h" -#include -#include -QT_BEGIN_NAMESPACE - -/*! - \qmlclass TrailEmitter QSGTrailEmitter - \inqmlmodule QtQuick.Particles 2 - \inherits QSGParticleEmitter - \brief The TrailEmitter element allows you to emit logical particles from other logical particles. - - This element emits logical particles into the ParticleSystem, with the - starting positions based on those of other logical particles. -*/ -QSGTrailEmitter::QSGTrailEmitter(QQuickItem *parent) : - QSGParticleEmitter(parent) - , m_particlesPerParticlePerSecond(0) - , m_lastTimeStamp(0) - , m_emitterXVariation(0) - , m_emitterYVariation(0) - , m_followCount(0) - , m_emissionExtruder(0) - , m_defaultEmissionExtruder(new QSGParticleExtruder(this)) -{ - //TODO: If followed increased their size - connect(this, SIGNAL(followChanged(QString)), - this, SLOT(recalcParticlesPerSecond())); - connect(this, SIGNAL(particleDurationChanged(int)), - this, SLOT(recalcParticlesPerSecond())); - connect(this, SIGNAL(particlesPerParticlePerSecondChanged(int)), - this, SLOT(recalcParticlesPerSecond())); -} - -/*! - \qmlproperty string QtQuick.Particles2::TrailEmitter::follow - - The type of logical particle which this is emitting from. -*/ -/*! - \qmlproperty qreal QtQuick.Particles2::TrailEmitter::speedFromMovement - - If this value is non-zero, then any movement of the emitter will provide additional - starting velocity to the particles based on the movement. The additional vector will be the - same angle as the emitter's movement, with a magnitude that is the magnitude of the emitters - movement multiplied by speedFromMovement. - - Default value is 0. -*/ -/*! - \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. 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 -*/ -/*! - \qmlsignal QtQuick.Particles2::TrailEmitter::emitFollowParticles(Array particles, real followed) - - This handler is called when particles are emitted from the \a followed particle. \a particles contains an array of particle objects which can be directly manipulated. - - If you use this signal handler, emitParticles will not be emitted. - -*/ - -bool QSGTrailEmitter::isEmitFollowConnected() -{ - static int idx = QObjectPrivate::get(this)->signalIndex("emitFollowParticles(QDeclarativeV8Handle,QDeclarativeV8Handle)"); - return QObjectPrivate::get(this)->isSignalConnected(idx); -} - -void QSGTrailEmitter::recalcParticlesPerSecond(){ - if (!m_system) - return; - m_followCount = m_system->groupData[m_system->groupIds[m_follow]]->size(); - if (!m_followCount){ - setParticlesPerSecond(1);//XXX: Fix this horrendous hack, needed so they aren't turned off from start (causes crashes - test that when gone you don't crash with 0 PPPS) - }else{ - setParticlesPerSecond(m_particlesPerParticlePerSecond * m_followCount); - m_lastEmission.resize(m_followCount); - m_lastEmission.fill(m_lastTimeStamp); - } -} - -void QSGTrailEmitter::reset() -{ - m_followCount = 0; -} - -void QSGTrailEmitter::emitWindow(int timeStamp) -{ - if (m_system == 0) - return; - if (!m_enabled && !m_pulseLeft && m_burstQueue.isEmpty()) - return; - if (m_followCount != m_system->groupData[m_system->groupIds[m_follow]]->size()){ - qreal oldPPS = m_particlesPerSecond; - recalcParticlesPerSecond(); - if (m_particlesPerSecond != oldPPS) - return;//system may need to update - } - - if (m_pulseLeft){ - m_pulseLeft -= timeStamp - m_lastTimeStamp * 1000.; - if (m_pulseLeft < 0){ - timeStamp += m_pulseLeft; - m_pulseLeft = 0; - } - } - - //TODO: Implement startTime and speedFromMovement - qreal time = timeStamp / 1000.; - qreal particleRatio = 1. / m_particlesPerParticlePerSecond; - qreal pt; - qreal maxLife = (m_particleDuration + m_particleDurationVariation)/1000.0; - - //Have to map it into this system, because particlesystem automaps it back - QPointF offset = m_system->mapFromItem(this, QPointF(0, 0)); - qreal sizeAtEnd = m_particleEndSize >= 0 ? m_particleEndSize : m_particleSize; - - int gId = m_system->groupIds[m_follow]; - int gId2 = m_system->groupIds[m_group]; - foreach (QSGParticleData *d, m_system->groupData[gId]->data){ - if (!d || !d->stillAlive()){ - m_lastEmission[d->index] = time; //Should only start emitting when it returns to life - continue; - } - pt = m_lastEmission[d->index]; - if (pt < d->t) - pt = d->t; - if (pt + maxLife < time)//We missed so much, that we should skip emiting particles that are dead by now - pt = time - maxLife; - - if ((width() || height()) && !effectiveExtruder()->contains(QRectF(offset.x(), offset.y(), width(), height()),QPointF(d->curX(), d->curY()))){ - m_lastEmission[d->index] = time;//jump over this time period without emitting, because it's outside - continue; - } - - QList toEmit; - - while (pt < time || !m_burstQueue.isEmpty()){ - QSGParticleData* datum = m_system->newDatum(gId2, !m_overwrite); - if (datum){//else, skip this emission - datum->e = this;//###useful? - - // Particle timestamp - datum->t = pt; - datum->lifeSpan = - (m_particleDuration - + ((rand() % ((m_particleDurationVariation*2) + 1)) - m_particleDurationVariation)) - / 1000.0; - - // Particle position - // Note that burst location doesn't get used for follow emitter - qreal followT = pt - d->t; - qreal followT2 = followT * followT * 0.5; - 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 - 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); - datum->x = newPos.x(); - datum->y = newPos.y(); - - // Particle speed - const QPointF &speed = m_speed->sample(newPos); - datum->vx = speed.x() - + m_speed_from_movement * d->vx; - datum->vy = speed.y() - + m_speed_from_movement * d->vy; - - // Particle acceleration - const QPointF &accel = m_acceleration->sample(newPos); - datum->ax = accel.x(); - datum->ay = accel.y(); - - // Particle size - float sizeVariation = -m_particleSizeVariation - + rand() / float(RAND_MAX) * m_particleSizeVariation * 2; - - float size = qMax((qreal)0.0, m_particleSize + sizeVariation); - float endSize = qMax((qreal)0.0, sizeAtEnd + sizeVariation); - - datum->size = size * float(m_enabled); - datum->endSize = endSize * float(m_enabled); - - toEmit << datum; - - m_system->emitParticle(datum); - } - if (!m_burstQueue.isEmpty()){ - m_burstQueue.first().first--; - if (m_burstQueue.first().first <= 0) - m_burstQueue.pop_front(); - }else{ - pt += particleRatio; - } - } - - if (isEmitConnected() || isEmitFollowConnected()) { - v8::HandleScope handle_scope; - v8::Context::Scope scope(QDeclarativeEnginePrivate::getV8Engine(qmlEngine(this))->context()); - v8::Handle array = v8::Array::New(toEmit.size()); - for (int i=0; iSet(i, toEmit[i]->v8Value().toHandle()); - - if (isEmitFollowConnected()) - emitFollowParticles(QDeclarativeV8Handle::fromHandle(array), d->v8Value());//A chance for many arbitrary JS changes - else if (isEmitConnected()) - emitParticles(QDeclarativeV8Handle::fromHandle(array));//A chance for arbitrary JS changes - } - foreach (QSGParticleData* d, toEmit) - m_system->emitParticle(d); - m_lastEmission[d->index] = pt; - } - - m_lastTimeStamp = time; -} -QT_END_NAMESPACE diff --git a/src/declarative/particles/qsgtrailemitter_p.h b/src/declarative/particles/qsgtrailemitter_p.h deleted file mode 100644 index a629f56695..0000000000 --- a/src/declarative/particles/qsgtrailemitter_p.h +++ /dev/null @@ -1,171 +0,0 @@ -/**************************************************************************** -** -** 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 FOLLOWEMITTER_H -#define FOLLOWEMITTER_H -#include "qsgparticleemitter_p.h" -#include "qsgparticleaffector_p.h" - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - - -class QSGTrailEmitter : public QSGParticleEmitter -{ - Q_OBJECT - Q_PROPERTY(QString follow READ follow WRITE setFollow NOTIFY followChanged) - Q_PROPERTY(int emitRatePerParticle READ particlesPerParticlePerSecond WRITE setParticlesPerParticlePerSecond NOTIFY particlesPerParticlePerSecondChanged) - - 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(QQuickItem *parent = 0); - virtual void emitWindow(int timeStamp); - virtual void reset(); - - int particlesPerParticlePerSecond() const - { - return m_particlesPerParticlePerSecond; - } - - qreal emitterXVariation() const - { - return m_emitterXVariation; - } - - qreal emitterYVariation() const - { - return m_emitterYVariation; - } - - QString follow() const - { - return m_follow; - } - - QSGParticleExtruder* emissonShape() const - { - return m_emissionExtruder; - } - -signals: - void emitFollowParticles(QDeclarativeV8Handle particles, QDeclarativeV8Handle followed); - - void particlesPerParticlePerSecondChanged(int arg); - - void emitterXVariationChanged(qreal arg); - - void emitterYVariationChanged(qreal arg); - - void followChanged(QString arg); - - void emissionShapeChanged(QSGParticleExtruder* arg); - -public slots: - - void setParticlesPerParticlePerSecond(int arg) - { - if (m_particlesPerParticlePerSecond != arg) { - m_particlesPerParticlePerSecond = arg; - emit particlesPerParticlePerSecondChanged(arg); - } - } - void setEmitterXVariation(qreal arg) - { - if (m_emitterXVariation != arg) { - m_emitterXVariation = arg; - emit emitterXVariationChanged(arg); - } - } - - void setEmitterYVariation(qreal arg) - { - if (m_emitterYVariation != arg) { - m_emitterYVariation = arg; - emit emitterYVariationChanged(arg); - } - } - - void setFollow(QString arg) - { - if (m_follow != arg) { - m_follow = arg; - emit followChanged(arg); - } - } - - void setEmissionShape(QSGParticleExtruder* arg) - { - if (m_emissionExtruder != arg) { - m_emissionExtruder = arg; - emit emissionShapeChanged(arg); - } - } - -private slots: - void recalcParticlesPerSecond(); - -private: - QSet m_pending; - QVector m_lastEmission; - int m_particlesPerParticlePerSecond; - qreal m_lastTimeStamp; - qreal m_emitterXVariation; - qreal m_emitterYVariation; - QString m_follow; - int m_followCount; - QSGParticleExtruder* m_emissionExtruder; - QSGParticleExtruder* m_defaultEmissionExtruder; - bool isEmitFollowConnected(); -}; - -QT_END_NAMESPACE -QT_END_HEADER -#endif // FOLLOWEMITTER_H diff --git a/src/declarative/particles/qsgturbulence.cpp b/src/declarative/particles/qsgturbulence.cpp deleted file mode 100644 index 957f6f1f62..0000000000 --- a/src/declarative/particles/qsgturbulence.cpp +++ /dev/null @@ -1,210 +0,0 @@ -/**************************************************************************** -** -** 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 "qsgturbulence_p.h" -#include "qsgparticlepainter_p.h"//TODO: Why was this needed again? -#include -#include -#include -QT_BEGIN_NAMESPACE - -/*! - \qmlclass Turbulence QSGTurbulenceAffector - \inqmlmodule QtQuick.Particles 2 - \inherits Affector - \brief Turbulence provides fluid like forces based on a noise image. - - The Turbulence Element scales the noise source over the area it affects, - and uses the curl of that source to generate force vectors. - - Turbulence requires a fixed size. Unlike other affectors, a 0x0 Turbulence element - will affect no particles. - - The source should be relatively smooth black and white noise, such as perlin noise. -*/ -/*! - \qmlproperty real QtQuick.Particles2::Turbulence::strength - - The magnitude of the velocity vector at any point varies between zero and - the square root of two. It will then be multiplied by strength to get the - velocity per second for the particles affected by the turbulence. -*/ -/*! - \qmlproperty url QtQuick.Particles2::Turbulence::noiseSource - - The source image to generate the turbulence from. It will be scaled to the size of the element, - so equal or larger sizes will give better results. Tweaking this image is the only way to tweak - behavior such as where vortices are or how many exist. - - The source should be a relatively smooth black and white noise image, such as perlin noise. - A default image will be used if none is provided. -*/ - -QSGTurbulenceAffector::QSGTurbulenceAffector(QQuickItem *parent) : - QSGParticleAffector(parent), - m_strength(10), m_lastT(0), m_gridSize(0), m_field(0), m_vectorField(0), m_inited(false) -{ -} - -void QSGTurbulenceAffector::geometryChanged(const QRectF &, const QRectF &) -{ - initializeGrid(); -} - -QSGTurbulenceAffector::~QSGTurbulenceAffector() -{ - if (m_field) { - for (int i=0; i= m_gridSize) - x = m_gridSize - 1; - if (y < 0) - y = 0; - if (y >= m_gridSize) - y = m_gridSize - 1; - return m_field[x][y]; -} - -void QSGTurbulenceAffector::ensureInit() -{ - if (m_inited) - return; - m_inited = true; - initializeGrid(); -} - -void QSGTurbulenceAffector::affectSystem(qreal dt) -{ - if (!m_system || !m_enabled) - return; - ensureInit(); - if (!m_gridSize) - return; - - updateOffsets();//### Needed if an ancestor is transformed. - - QRect boundsRect(0,0,m_gridSize,m_gridSize); - foreach (QSGParticleGroupData *gd, m_system->groupData){ - if (!activeGroup(m_system->groupData.key(gd))) - continue; - foreach (QSGParticleData *d, gd->data){ - if (!shouldAffect(d)) - continue; - QPoint pos = (QPointF(d->curX(), d->curY()) - m_offset).toPoint(); - if (!boundsRect.contains(pos,true))//Need to redo bounds checking due to quantization. - continue; - qreal fx = 0.0; - qreal fy = 0.0; - fx += m_vectorField[pos.x()][pos.y()].x() * m_strength; - fy += m_vectorField[pos.x()][pos.y()].y() * m_strength; - if (fx || fy){ - d->setInstantaneousVX(d->curVX()+ fx * dt); - d->setInstantaneousVY(d->curVY()+ fy * dt); - postAffect(d); - } - } - } -} - -QT_END_NAMESPACE diff --git a/src/declarative/particles/qsgturbulence_p.h b/src/declarative/particles/qsgturbulence_p.h deleted file mode 100644 index 022bf3577b..0000000000 --- a/src/declarative/particles/qsgturbulence_p.h +++ /dev/null @@ -1,119 +0,0 @@ -/**************************************************************************** -** -** 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 TURBULENCEAFFECTOR_H -#define TURBULENCEAFFECTOR_H -#include "qsgparticleaffector_p.h" -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - - -class QSGParticlePainter; - -class QSGTurbulenceAffector : public QSGParticleAffector -{ - Q_OBJECT - Q_PROPERTY(qreal strength READ strength WRITE setStrength NOTIFY strengthChanged) - Q_PROPERTY(QUrl noiseSource READ noiseSource WRITE setNoiseSource NOTIFY noiseSourceChanged) - public: - explicit QSGTurbulenceAffector(QQuickItem *parent = 0); - ~QSGTurbulenceAffector(); - virtual void affectSystem(qreal dt); - - qreal strength() const - { - return m_strength; - } - - QUrl noiseSource() const - { - return m_noiseSource; - } -signals: - - void strengthChanged(qreal arg); - - void noiseSourceChanged(QUrl arg); - -public slots: - - void setStrength(qreal arg) - { - if (m_strength != arg) { - m_strength = arg; - emit strengthChanged(arg); - } - } - - void setNoiseSource(QUrl arg) - { - if (m_noiseSource != arg) { - m_noiseSource = arg; - emit noiseSourceChanged(arg); - initializeGrid(); - } - } - -protected: - virtual void geometryChanged(const QRectF &newGeometry, - const QRectF &oldGeometry); -private: - void ensureInit(); - void mapUpdate(); - void initializeGrid(); - qreal boundsRespectingField(int x, int y); - qreal m_strength; - qreal m_lastT; - int m_gridSize; - qreal** m_field; - QPointF** m_vectorField; - bool m_inited; - QUrl m_noiseSource; -}; - -QT_END_NAMESPACE -QT_END_HEADER -#endif // TURBULENCEAFFECTOR_H diff --git a/src/declarative/particles/qsgv8particledata.cpp b/src/declarative/particles/qsgv8particledata.cpp deleted file mode 100644 index a7a2e103a2..0000000000 --- a/src/declarative/particles/qsgv8particledata.cpp +++ /dev/null @@ -1,384 +0,0 @@ -/**************************************************************************** -** -** 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 "qsgv8particledata_p.h" -#include "qsgparticlesystem_p.h"//for QSGParticleData -#include - -QT_BEGIN_NAMESPACE - -/*! - \qmlclass Particle - \inqmlmodule QtQuick.Particles 2 - \brief Particle elements can be manipulated in custom emitters and affectors. - - Particle elements are always managed internally by the ParticleSystem and cannot be created in QML. - However, sometimes they are exposed via signals so as to allow arbitrary changes to the particle state -*/ - -/*! - \qmlproperty real QtQuick.Particles2::Particle::initialX - The x coordinate of the particle at the beginning of its lifetime. - - The method of simulation prefers to have the initial values changed, rather - than determining and changing the value at a given time. Change initial - values in CustomEmitters instead of the current values. -*/ - -/*! - \qmlproperty real QtQuick.Particles2::Particle::initialVX - The x velocity of the particle at the beginning of its lifetime. - - The method of simulation prefers to have the initial values changed, rather - than determining and changing the value at a given time. Change initial - values in CustomEmitters instead of the current values. -*/ - -/*! - \qmlproperty real QtQuick.Particles2::Particle::initialAX - The x acceleration of the particle at the beginning of its lifetime. - - The method of simulation prefers to have the initial values changed, rather - than determining and changing the value at a given time. Change initial - values in CustomEmitters instead of the current values. -*/ - -/*! - \qmlproperty real QtQuick.Particles2::Particle::initialY - The y coordinate of the particle at the beginning of its lifetime. - - The method of simulation prefers to have the initial values changed, rather - than determining and changing the value at a given time. Change initial - values in CustomEmitters instead of the current values. -*/ - -/*! - \qmlproperty real QtQuick.Particles2::Particle::initialVY - The y velocity of the particle at the beginning of its lifetime. - - The method of simulation prefers to have the initial values changed, rather - than determining and changing the value at a given time. Change initial - values in CustomEmitters instead of the current values. -*/ - -/*! - \qmlproperty real QtQuick.Particles2::Particle::initialAY - The y acceleration of the particle at the beginning of its lifetime. - - The method of simulation prefers to have the initial values changed, rather - than determining and changing the value at a given time. Change initial - values in CustomEmitters instead of the current values. -*/ - -/*! - \qmlproperty real QtQuick.Particles2::Particle::x - The current x coordinate of the particle. -*/ - -/*! - \qmlproperty real QtQuick.Particles2::Particle::vx - The current x velocity of the particle. -*/ - -/*! - \qmlproperty real QtQuick.Particles2::Particle::ax - The current x acceleration of the particle. -*/ - -/*! - \qmlproperty real QtQuick.Particles2::Particle::y - The current y coordinate of the particle. -*/ - -/*! - \qmlproperty real QtQuick.Particles2::Particle::vy - The current y velocity of the particle. -*/ - -/*! - \qmlproperty real QtQuick.Particles2::Particle::ay - The current y acceleration of the particle. -*/ - -/*! - \qmlproperty real QtQuick.Particles2::Particle::t - The time, in seconds since the beginning of the simulation, that the particle was born. -*/ - - -/*! - \qmlproperty real QtQuick.Particles2::Particle::startSize - The size in pixels that the particle image is at the start - of its life. -*/ - - -/*! - \qmlproperty real QtQuick.Particles2::Particle::endSize - The size in pixels that the particle image is at the end - of its life. If this value is less than 0, then it is - disregarded and the particle will have its startSize for the - entire lifetime. -*/ - -/*! - \qmlproperty real QtQuick.Particles2::Particle::lifeSpan - The time in seconds that the particle will live for. -*/ - -/*! - \qmlproperty real QtQuick.Particles2::Particle::rotation - Degrees clockwise that the particle image is rotated at - the beginning of its life. -*/ - -/*! - \qmlproperty real QtQuick.Particles2::Particle::rotationSpeed - Degrees clockwise per second that the particle image is rotated at while alive. -*/ - -/*! - \qmlproperty real QtQuick.Particles2::Particle::autoRotate - If autoRotate == 1.0, then the particle's rotation will be - set so that it faces the direction of travel, plus any - rotation from the rotation or rotationSpeed properties. -*/ -/*! - \qmlmethod real QtQuick.Particles2::Particle::lifeLeft - The time in seconds that the particle has left to live at - the current point in time. -*/ -/*! - \qmlmethod real QtQuick.Particles2::Particle::currentSize - The currentSize of the particle, interpolating between startSize and endSize based on the currentTime. -*/ - - - -//### Particle data handles are not locked to within certain scopes like QQuickContext2D, but there's no way to reload either... -class QV8ParticleDataResource : public QV8ObjectResource -{ - V8_RESOURCE_TYPE(ParticleDataType) -public: - QV8ParticleDataResource(QV8Engine *e) : QV8ObjectResource(e) {} - QSGParticleData* datum;//TODO: Guard needed? -}; - -class QV8ParticleDataDeletable : public QV8Engine::Deletable -{ -public: - QV8ParticleDataDeletable(QV8Engine *engine); - ~QV8ParticleDataDeletable(); - - v8::Persistent constructor; -}; - -static v8::Handle particleData_discard(const v8::Arguments &args) -{ - QV8ParticleDataResource *r = v8_resource_cast(args.This()); - - if (!r || !r->datum) - V8THROW_ERROR("Not a valid ParticleData object"); - - r->datum->lifeSpan = 0; //Don't kill(), because it could still be in the middle of being created - return v8::Undefined(); -} - -static v8::Handle particleData_lifeLeft(const v8::Arguments &args) -{ - QV8ParticleDataResource *r = v8_resource_cast(args.This()); - if (!r || !r->datum) - V8THROW_ERROR("Not a valid ParticleData object"); - - return v8::Number::New(r->datum->lifeLeft()); -} - -static v8::Handle particleData_curSize(const v8::Arguments &args) -{ - QV8ParticleDataResource *r = v8_resource_cast(args.This()); - if (!r || !r->datum) - V8THROW_ERROR("Not a valid ParticleData object"); - - return v8::Number::New(r->datum->curSize()); -} - -#define FLOAT_GETTER_AND_SETTER(VARIABLE) static v8::Handle particleData_get_ ## VARIABLE (v8::Local, const v8::AccessorInfo &info) \ -{ \ - QV8ParticleDataResource *r = v8_resource_cast(info.This()); \ - if (!r || !r->datum) \ - V8THROW_ERROR("Not a valid ParticleData object"); \ -\ - return v8::Number::New(r->datum-> VARIABLE);\ -}\ -\ -static void particleData_set_ ## VARIABLE (v8::Local, v8::Local value, const v8::AccessorInfo &info)\ -{\ - QV8ParticleDataResource *r = v8_resource_cast(info.This());\ - if (!r || !r->datum)\ - V8THROW_ERROR_SETTER("Not a valid ParticleData object");\ -\ - r->datum-> VARIABLE = value->NumberValue();\ -} - -#define FAKE_FLOAT_GETTER_AND_SETTER(VARIABLE, GETTER, SETTER) static v8::Handle particleData_get_ ## VARIABLE (v8::Local, const v8::AccessorInfo &info) \ -{ \ - QV8ParticleDataResource *r = v8_resource_cast(info.This()); \ - if (!r || !r->datum) \ - V8THROW_ERROR("Not a valid ParticleData object"); \ -\ - return v8::Number::New(r->datum-> GETTER ());\ -}\ -\ -static void particleData_set_ ## VARIABLE (v8::Local, v8::Local value, const v8::AccessorInfo &info)\ -{\ - QV8ParticleDataResource *r = v8_resource_cast(info.This());\ - if (!r || !r->datum)\ - V8THROW_ERROR_SETTER("Not a valid ParticleData object");\ -\ - r->datum-> SETTER ( value->NumberValue() );\ -} - -#define FLOAT_REGISTER_ACCESSOR(FT, ENGINE, VARIABLE, NAME) FT ->PrototypeTemplate()->SetAccessor( v8::String::New( #NAME ), particleData_get_ ## VARIABLE , particleData_set_ ## VARIABLE , v8::External::Wrap(ENGINE)) - -FLOAT_GETTER_AND_SETTER(x) -FLOAT_GETTER_AND_SETTER(y) -FLOAT_GETTER_AND_SETTER(t) -FLOAT_GETTER_AND_SETTER(lifeSpan) -FLOAT_GETTER_AND_SETTER(size) -FLOAT_GETTER_AND_SETTER(endSize) -FLOAT_GETTER_AND_SETTER(vx) -FLOAT_GETTER_AND_SETTER(vy) -FLOAT_GETTER_AND_SETTER(ax) -FLOAT_GETTER_AND_SETTER(ay) -FLOAT_GETTER_AND_SETTER(xx) -FLOAT_GETTER_AND_SETTER(xy) -FLOAT_GETTER_AND_SETTER(rotation) -FLOAT_GETTER_AND_SETTER(rotationSpeed) -FLOAT_GETTER_AND_SETTER(autoRotate) -FLOAT_GETTER_AND_SETTER(animIdx) -FLOAT_GETTER_AND_SETTER(frameDuration) -FLOAT_GETTER_AND_SETTER(frameCount) -FLOAT_GETTER_AND_SETTER(animT) -FLOAT_GETTER_AND_SETTER(r) -FLOAT_GETTER_AND_SETTER(update) -FAKE_FLOAT_GETTER_AND_SETTER(curX, curX, setInstantaneousX) -FAKE_FLOAT_GETTER_AND_SETTER(curVX, curVX, setInstantaneousVX) -FAKE_FLOAT_GETTER_AND_SETTER(curAX, curAX, setInstantaneousAX) -FAKE_FLOAT_GETTER_AND_SETTER(curY, curY, setInstantaneousY) -FAKE_FLOAT_GETTER_AND_SETTER(curVY, curVY, setInstantaneousVY) -FAKE_FLOAT_GETTER_AND_SETTER(curAY, curAY, setInstantaneousAY) - -//TODO: Non-floats (color, update?) once floats are working well - -QV8ParticleDataDeletable::QV8ParticleDataDeletable(QV8Engine *engine) -{ - v8::HandleScope handle_scope; - v8::Context::Scope scope(engine->context()); - - v8::Local ft = v8::FunctionTemplate::New(); - ft->InstanceTemplate()->SetHasExternalResource(true); - ft->PrototypeTemplate()->Set(v8::String::New("discard"), V8FUNCTION(particleData_discard, engine)); - ft->PrototypeTemplate()->Set(v8::String::New("lifeLeft"), V8FUNCTION(particleData_lifeLeft, engine)); - ft->PrototypeTemplate()->Set(v8::String::New("currentSize"), V8FUNCTION(particleData_curSize, engine)); - FLOAT_REGISTER_ACCESSOR(ft, engine, x, initialX); - FLOAT_REGISTER_ACCESSOR(ft, engine, y, initialY); - FLOAT_REGISTER_ACCESSOR(ft, engine, t, t); - FLOAT_REGISTER_ACCESSOR(ft, engine, lifeSpan, lifeSpan); - FLOAT_REGISTER_ACCESSOR(ft, engine, size, startSize); - FLOAT_REGISTER_ACCESSOR(ft, engine, endSize, endSize); - FLOAT_REGISTER_ACCESSOR(ft, engine, vx, initialVX); - FLOAT_REGISTER_ACCESSOR(ft, engine, vy, initialVY); - FLOAT_REGISTER_ACCESSOR(ft, engine, ax, initialAX); - FLOAT_REGISTER_ACCESSOR(ft, engine, ay, initialAY); - FLOAT_REGISTER_ACCESSOR(ft, engine, xx, xDeformationVector); - FLOAT_REGISTER_ACCESSOR(ft, engine, xy, yDeformationVector); - FLOAT_REGISTER_ACCESSOR(ft, engine, rotation, rotation); - FLOAT_REGISTER_ACCESSOR(ft, engine, rotationSpeed, rotationSpeed); - FLOAT_REGISTER_ACCESSOR(ft, engine, autoRotate, autoRotate); - FLOAT_REGISTER_ACCESSOR(ft, engine, animIdx, animationIndex); - FLOAT_REGISTER_ACCESSOR(ft, engine, frameDuration, frameDuration); - FLOAT_REGISTER_ACCESSOR(ft, engine, frameCount, frameCount); - FLOAT_REGISTER_ACCESSOR(ft, engine, animT, animationT); - FLOAT_REGISTER_ACCESSOR(ft, engine, r, r); - FLOAT_REGISTER_ACCESSOR(ft, engine, update, update); - FLOAT_REGISTER_ACCESSOR(ft, engine, curX, x); - FLOAT_REGISTER_ACCESSOR(ft, engine, curVX, vx); - FLOAT_REGISTER_ACCESSOR(ft, engine, curAX, ax); - FLOAT_REGISTER_ACCESSOR(ft, engine, curY, y); - FLOAT_REGISTER_ACCESSOR(ft, engine, curVY, vy); - FLOAT_REGISTER_ACCESSOR(ft, engine, curAY, ay); - - constructor = qPersistentNew(ft->GetFunction()); -} - -QV8ParticleDataDeletable::~QV8ParticleDataDeletable() -{ - qPersistentDispose(constructor); -} - -V8_DEFINE_EXTENSION(QV8ParticleDataDeletable, particleV8Data); - - -QSGV8ParticleData::QSGV8ParticleData(QV8Engine* engine, QSGParticleData* datum) -{ - if (!engine || !datum) - return; - v8::HandleScope handle_scope; - v8::Context::Scope scope(engine->context()); - - QV8ParticleDataDeletable *d = particleV8Data(engine); - m_v8Value = qPersistentNew(d->constructor->NewInstance()); - QV8ParticleDataResource *r = new QV8ParticleDataResource(engine); - r->datum = datum; - m_v8Value->SetExternalResource(r); -} - -QSGV8ParticleData::~QSGV8ParticleData() -{ - qPersistentDispose(m_v8Value); -} - -QDeclarativeV8Handle QSGV8ParticleData::v8Value() -{ - return QDeclarativeV8Handle::fromHandle(m_v8Value); -} - -QT_END_NAMESPACE diff --git a/src/declarative/particles/qsgv8particledata_p.h b/src/declarative/particles/qsgv8particledata_p.h deleted file mode 100644 index e4a78a9131..0000000000 --- a/src/declarative/particles/qsgv8particledata_p.h +++ /dev/null @@ -1,69 +0,0 @@ -/**************************************************************************** -** -** 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 QSGV8PARTICLEDATA_H -#define QSGV8PARTICLEDATA_H - -#include - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - -class QSGParticleData; -class QSGV8ParticleData { -public: - QSGV8ParticleData(QV8Engine*,QSGParticleData*); - ~QSGV8ParticleData(); - QDeclarativeV8Handle v8Value(); -private: - v8::Persistent m_v8Value; -}; - - -QT_END_NAMESPACE - -QT_END_HEADER - - -#endif diff --git a/src/declarative/particles/qsgwander.cpp b/src/declarative/particles/qsgwander.cpp deleted file mode 100644 index 2a861c2ce6..0000000000 --- a/src/declarative/particles/qsgwander.cpp +++ /dev/null @@ -1,180 +0,0 @@ -/**************************************************************************** -** -** 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 "qsgwander_p.h" -#include "qsgparticlesystem_p.h"//for ParticlesVertices -QT_BEGIN_NAMESPACE -/*! - \qmlclass Wander QSGWanderAffector - \inqmlmodule QtQuick.Particles 2 - \inherits Affector - \brief The Wander affector allows particles to randomly vary their trajectory. - -*/ -/*! - \qmlproperty real QtQuick.Particles2::Wander::pace - - Maximum attribute change per second. -*/ -/*! - \qmlproperty real QtQuick.Particles2::Wander::xVariance - - Maximum attribute x value (as a result of Wander). - - If unset, Wander will not affect x values. -*/ -/*! - \qmlproperty real QtQuick.Particles2::Wander::yVariance - - Maximum attribute y value (as a result of Wander). - - If unset, Wander will not affect y values. -*/ -/*! - \qmlproperty AffectableParameter QtQuick.Particles2::Wander::affectedParameter - - What attribute of particles is directly affected. - \list - \o PointAttractor.Position - \o PointAttractor.Velocity - \o PointAttractor.Acceleration - \endlist -*/ - -QSGWanderAffector::QSGWanderAffector(QQuickItem *parent) : - QSGParticleAffector(parent), m_xVariance(0), m_yVariance(0), m_pace(0) - , m_affectedParameter(Velocity) -{ - m_needsReset = true; -} - -QSGWanderAffector::~QSGWanderAffector() -{ - for (QHash::const_iterator iter=m_wanderData.constBegin(); - iter != m_wanderData.constEnd(); iter++) - delete (*iter); -} - -WanderData* QSGWanderAffector::getData(int idx) -{ - if (m_wanderData.contains(idx)) - return m_wanderData[idx]; - WanderData* d = new WanderData; - d->x_vel = 0; - d->y_vel = 0; - d->x_peak = m_xVariance; - d->y_peak = m_yVariance; - d->x_var = m_pace * qreal(qrand()) / RAND_MAX; - d->y_var = m_pace * qreal(qrand()) / RAND_MAX; - - m_wanderData.insert(idx, d); - return d; -} - -void QSGWanderAffector::reset(int systemIdx) -{ - if (m_wanderData.contains(systemIdx)) - delete m_wanderData[systemIdx]; - m_wanderData.remove(systemIdx); -} - -bool QSGWanderAffector::affectParticle(QSGParticleData* data, qreal dt) -{ - /*TODO: Add a mode which does basically this - picking a direction, going in it (random speed) and then going back - WanderData* d = getData(data->systemIndex); - if (m_xVariance != 0.) { - if ((d->x_vel > d->x_peak && d->x_var > 0.0) || (d->x_vel < -d->x_peak && d->x_var < 0.0)) { - d->x_var = -d->x_var; - d->x_peak = m_xVariance + m_xVariance * qreal(qrand()) / RAND_MAX; - } - d->x_vel += d->x_var * dt; - } - qreal dx = dt * d->x_vel; - - if (m_yVariance != 0.) { - if ((d->y_vel > d->y_peak && d->y_var > 0.0) || (d->y_vel < -d->y_peak && d->y_var < 0.0)) { - d->y_var = -d->y_var; - d->y_peak = m_yVariance + m_yVariance * qreal(qrand()) / RAND_MAX; - } - d->y_vel += d->y_var * dt; - } - qreal dy = dt * d->x_vel; - - //### Should we be amending vel instead? - ParticleVertex* p = &(data->pv); - p->x += dx; - - p->y += dy; - return true; - */ - qreal dx = dt * m_pace * (2 * qreal(qrand())/RAND_MAX - 1); - qreal dy = dt * m_pace * (2 * qreal(qrand())/RAND_MAX - 1); - qreal newX, newY; - switch (m_affectedParameter){ - case Position: - newX = data->curX() + dx; - if (m_xVariance > qAbs(newX) ) - data->x += dx; - newY = data->curY() + dy; - if (m_yVariance > qAbs(newY) ) - data->y += dy; - break; - default: - case Velocity: - newX = data->curVX() + dx; - if (m_xVariance > qAbs(newX) ) - data->setInstantaneousVX(newX); - newY = data->curVY() + dy; - if (m_yVariance > qAbs(newY) ) - data->setInstantaneousVY(newY); - break; - case Acceleration: - newX = data->ax + dx; - if (m_xVariance > qAbs(newX) ) - data->setInstantaneousAX(newX); - newY = data->ay + dy; - if (m_yVariance > qAbs(newY) ) - data->setInstantaneousAY(newY); - break; - } - return true; -} -QT_END_NAMESPACE diff --git a/src/declarative/particles/qsgwander_p.h b/src/declarative/particles/qsgwander_p.h deleted file mode 100644 index 6447e2f49e..0000000000 --- a/src/declarative/particles/qsgwander_p.h +++ /dev/null @@ -1,161 +0,0 @@ -/**************************************************************************** -** -** 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 WANDERAFFECTOR_H -#define WANDERAFFECTOR_H -#include -#include "qsgparticleaffector_p.h" - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -QT_MODULE(Declarative) - - -struct WanderData{ - qreal x_vel; - qreal y_vel; - qreal x_peak; - qreal x_var; - qreal y_peak; - qreal y_var; -}; - -class QSGWanderAffector : public QSGParticleAffector -{ - Q_OBJECT - Q_PROPERTY(qreal pace READ pace WRITE setPace NOTIFY paceChanged) - Q_PROPERTY(qreal xVariance READ xVariance WRITE setXVariance NOTIFY xVarianceChanged) - Q_PROPERTY(qreal yVariance READ yVariance WRITE setYVariance NOTIFY yVarianceChanged) - Q_PROPERTY(AffectableParameters affectedParameter READ affectedParameter WRITE setAffectedParameter NOTIFY affectedParameterChanged) - Q_ENUMS(AffectableParameters) - -public: - enum AffectableParameters { - Position, - Velocity, - Acceleration - }; - - explicit QSGWanderAffector(QQuickItem *parent = 0); - ~QSGWanderAffector(); - virtual void reset(int systemIdx); - - qreal xVariance() const - { - return m_xVariance; - } - - qreal yVariance() const - { - return m_yVariance; - } - - qreal pace() const - { - return m_pace; - } - - AffectableParameters affectedParameter() const - { - return m_affectedParameter; - } - -protected: - virtual bool affectParticle(QSGParticleData *d, qreal dt); -signals: - - void xVarianceChanged(qreal arg); - - void yVarianceChanged(qreal arg); - - void paceChanged(qreal arg); - - - void affectedParameterChanged(AffectableParameters arg); - -public slots: -void setXVariance(qreal arg) -{ - if (m_xVariance != arg) { - m_xVariance = arg; - emit xVarianceChanged(arg); - } -} - -void setYVariance(qreal arg) -{ - if (m_yVariance != arg) { - m_yVariance = arg; - emit yVarianceChanged(arg); - } -} - -void setPace(qreal arg) -{ - if (m_pace != arg) { - m_pace = arg; - emit paceChanged(arg); - } -} - - -void setAffectedParameter(AffectableParameters arg) -{ - if (m_affectedParameter != arg) { - m_affectedParameter = arg; - emit affectedParameterChanged(arg); - } -} - -private: - WanderData* getData(int idx); - QHash m_wanderData; - qreal m_xVariance; - qreal m_yVariance; - qreal m_pace; - AffectableParameters m_affectedParameter; -}; - -QT_END_NAMESPACE -QT_END_HEADER -#endif // WANDERAFFECTOR_H diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp index 4865a33461..673ac42095 100644 --- a/src/declarative/qml/qdeclarativeengine.cpp +++ b/src/declarative/qml/qdeclarativeengine.cpp @@ -84,7 +84,7 @@ #include #include -#include +#include #ifdef Q_OS_WIN // for %APPDATA% #include @@ -345,7 +345,7 @@ QDeclarativeEnginePrivate::QDeclarativeEnginePrivate(QDeclarativeEngine *e) QDeclarativeUtilModule::defineModule(); QDeclarativeEnginePrivate::defineModule(); QQuickItemsModule::defineModule(); - QSGParticlesModule::defineModule(); + QQuickParticlesModule::defineModule(); QDeclarativeValueTypeFactory::registerValueTypes(); } } diff --git a/tests/auto/particles/particles.pro b/tests/auto/particles/particles.pro index 2c793a988e..d376b9305e 100644 --- a/tests/auto/particles/particles.pro +++ b/tests/auto/particles/particles.pro @@ -1,27 +1,27 @@ TEMPLATE = subdirs PRIVATETESTS += \ - qsgage \ - qsgangleddirection \ - qsgcumulativedirection \ - qsgcustomaffector \ - qsgcustomparticle \ - qsgellipseextruder \ - qsgfriction \ - qsggravity \ - qsgimageparticle \ - qsgitemparticle \ - qsglineextruder \ - qsgmaskextruder \ - qsgparticlegroup \ - qsgparticlesystem \ - qsgpointattractor \ - qsgpointdirection \ - qsgrectangleextruder \ - qsgtargetdirection \ - qsgtrailemitter \ - qsgturbulence \ - qsgwander + qquickage \ + qquickangleddirection \ + qquickcumulativedirection \ + qquickcustomaffector \ + qquickcustomparticle \ + qquickellipseextruder \ + qquickfriction \ + qquickgravity \ + qquickimageparticle \ + qquickitemparticle \ + qquicklineextruder \ + qquickmaskextruder \ + qquickparticlegroup \ + qquickparticlesystem \ + qquickpointattractor \ + qquickpointdirection \ + qquickrectangleextruder \ + qquicktargetdirection \ + qquicktrailemitter \ + qquickturbulence \ + qquickwander contains(QT_CONFIG, private_tests) { SUBDIRS += $$PRIVATETESTS diff --git a/tests/auto/particles/qquickage/data/jump.qml b/tests/auto/particles/qquickage/data/jump.qml new file mode 100644 index 0000000000..e66f9f4950 --- /dev/null +++ b/tests/auto/particles/qquickage/data/jump.qml @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** 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 test suite 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$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtQuick.Particles 2.0 + +Rectangle { + color: "black" + width: 320 + height: 320 + + ParticleSystem { + id: sys + objectName: "system" + anchors.fill: parent + + Age { + once: true + advancePosition: false + lifeLeft: 100 + } + + ImageParticle { source: "../../shared/star.png" } + Emitter { + //0,0 position + size: 32 + emitRate: 1000 + lifeSpan: 500 + speed: PointDirection{ x: 500; y: 500 } + } + } +} diff --git a/tests/auto/particles/qquickage/data/kill.qml b/tests/auto/particles/qquickage/data/kill.qml new file mode 100644 index 0000000000..2558435e60 --- /dev/null +++ b/tests/auto/particles/qquickage/data/kill.qml @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** 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 test suite 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$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtQuick.Particles 2.0 + +Rectangle { + color: "black" + width: 320 + height: 320 + + ParticleSystem { + id: sys + objectName: "system" + anchors.fill: parent + + Age {} + + ImageParticle { source: "../../shared/star.png" } + Emitter{ + //0,0 position + size: 32 + emitRate: 1000 + lifeSpan: 500 + speed: PointDirection{ x: 1000; y: 1000 } + } + } +} diff --git a/tests/auto/particles/qquickage/data/onceoff.qml b/tests/auto/particles/qquickage/data/onceoff.qml new file mode 100644 index 0000000000..15d0e123b4 --- /dev/null +++ b/tests/auto/particles/qquickage/data/onceoff.qml @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** 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 test suite 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$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtQuick.Particles 2.0 + +Rectangle { + color: "black" + width: 320 + height: 320 + + ParticleSystem { + id: sys + objectName: "system" + anchors.fill: parent + + Age { + once: true + lifeLeft: 100 + } + + ImageParticle { source: "../../shared/star.png" } + Emitter{ + //0,0 position + size: 32 + emitRate: 1000 + lifeSpan: 500 + speed: PointDirection{ x: 500; y: 500 } + } + } +} diff --git a/tests/auto/particles/qquickage/data/sustained.qml b/tests/auto/particles/qquickage/data/sustained.qml new file mode 100644 index 0000000000..96aefec3dc --- /dev/null +++ b/tests/auto/particles/qquickage/data/sustained.qml @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** 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 test suite 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$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtQuick.Particles 2.0 + +Rectangle { + color: "black" + width: 320 + height: 320 + + ParticleSystem { + id: sys + objectName: "system" + anchors.fill: parent + + Age { + once: false + lifeLeft: 100 + } + + ImageParticle { source: "../../shared/star.png" } + Emitter{ + //0,0 position + size: 32 + emitRate: 1000 + lifeSpan: 500 + speed: PointDirection{ x: 500; y: 500 } + } + } +} diff --git a/tests/auto/particles/qquickage/qquickage.pro b/tests/auto/particles/qquickage/qquickage.pro new file mode 100644 index 0000000000..980d390953 --- /dev/null +++ b/tests/auto/particles/qquickage/qquickage.pro @@ -0,0 +1,13 @@ +CONFIG += testcase +TARGET = tst_qquickage +SOURCES += tst_qquickage.cpp +macx:CONFIG -= app_bundle + +testDataFiles.files = data +testDataFiles.path = . +DEPLOYMENT += testDataFiles + +CONFIG += insignificant_test + +QT += core-private gui-private v8-private declarative-private opengl-private testlib + diff --git a/tests/auto/particles/qquickage/tst_qquickage.cpp b/tests/auto/particles/qquickage/tst_qquickage.cpp new file mode 100644 index 0000000000..73db409de3 --- /dev/null +++ b/tests/auto/particles/qquickage/tst_qquickage.cpp @@ -0,0 +1,165 @@ +/**************************************************************************** +** +** 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 test suite 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 +#include "../shared/particlestestsshared.h" +#include +#include + +class tst_qquickage : public QObject +{ + Q_OBJECT +public: + tst_qquickage(); + +private slots: + void test_kill(); + void test_jump(); + void test_onceOff(); + void test_sustained(); +}; + +tst_qquickage::tst_qquickage() +{ + QUnifiedTimer::instance()->setConsistentTiming(true); +} + +void tst_qquickage::test_kill() +{ + QQuickView* view = createView(QCoreApplication::applicationDirPath() + "/data/kill.qml", 600); + QQuickParticleSystem* system = view->rootObject()->findChild("system"); + ensureAnimTime(600, system->m_animation); + + QCOMPARE(system->groupData[0]->size(), 500); + foreach (QQuickParticleData *d, system->groupData[0]->data) { + if (d->t == -1) + continue; //Particle data unused + + QCOMPARE(d->x, 0.f); + QCOMPARE(d->y, 0.f); + QCOMPARE(d->vx, 1000.f); + QCOMPARE(d->vy, 1000.f); + QCOMPARE(d->ax, 0.f); + QCOMPARE(d->ay, 0.f); + QCOMPARE(d->lifeSpan, 0.5f); + QCOMPARE(d->size, 32.f); + QCOMPARE(d->endSize, 32.f); + QVERIFY(d->t <= ((qreal)system->timeInt/1000.0) - 0.5f + EPSILON); + } +} + +void tst_qquickage::test_jump() +{ + QQuickView* view = createView(QCoreApplication::applicationDirPath() + "/data/jump.qml", 600); + QQuickParticleSystem* system = view->rootObject()->findChild("system"); + ensureAnimTime(600, system->m_animation); + + QCOMPARE(system->groupData[0]->size(), 500); + foreach (QQuickParticleData *d, system->groupData[0]->data) { + if (d->t == -1) + continue; //Particle data unused + + //Allow for a small variance because jump is trying to simulate off wall time + extremelyFuzzyCompare(d->x, -100.f, 5.0f); + extremelyFuzzyCompare(d->y, -100.f, 5.0f); + QCOMPARE(d->vx, 500.f); + QCOMPARE(d->vy, 500.f); + QCOMPARE(d->ax, 0.f); + QCOMPARE(d->ay, 0.f); + QCOMPARE(d->lifeSpan, 0.5f); + QCOMPARE(d->size, 32.f); + QCOMPARE(d->endSize, 32.f); + QVERIFY(d->t <= ((qreal)system->timeInt/1000.0) - 0.4f + EPSILON); + } +} + +void tst_qquickage::test_onceOff() +{ + QQuickView* view = createView(QCoreApplication::applicationDirPath() + "/data/onceoff.qml", 600); + QQuickParticleSystem* system = view->rootObject()->findChild("system"); + ensureAnimTime(600, system->m_animation); + + QCOMPARE(system->groupData[0]->size(), 500); + foreach (QQuickParticleData *d, system->groupData[0]->data) { + if (d->t == -1) + continue; //Particle data unused + + QCOMPARE(d->x, 0.f); + QCOMPARE(d->y, 0.f); + QCOMPARE(d->vx, 500.f); + QCOMPARE(d->vy, 500.f); + QCOMPARE(d->ax, 0.f); + QCOMPARE(d->ay, 0.f); + QCOMPARE(d->lifeSpan, 0.5f); + QCOMPARE(d->size, 32.f); + QCOMPARE(d->endSize, 32.f); + QVERIFY(d->t <= ((qreal)system->timeInt/1000.0) - 0.4f + EPSILON); + } +} + +void tst_qquickage::test_sustained() +{ + QQuickView* view = createView(QCoreApplication::applicationDirPath() + "/data/sustained.qml", 600); + QQuickParticleSystem* system = view->rootObject()->findChild("system"); + ensureAnimTime(600, system->m_animation); + //TODO: Ensure some particles have lived to 0.4s point despite unified timer + + QCOMPARE(system->groupData[0]->size(), 500); + foreach (QQuickParticleData *d, system->groupData[0]->data) { + if (d->t == -1) + continue; //Particle data unused + + QCOMPARE(d->x, 0.f); + QCOMPARE(d->y, 0.f); + QCOMPARE(d->vx, 500.f); + QCOMPARE(d->vy, 500.f); + QCOMPARE(d->ax, 0.f); + QCOMPARE(d->ay, 0.f); + QCOMPARE(d->lifeSpan, 0.5f); + QCOMPARE(d->size, 32.f); + QCOMPARE(d->endSize, 32.f); + QVERIFY(myFuzzyCompare(d->t, ((qreal)system->timeInt/1000.0) - 0.4f)); + } +} + +QTEST_MAIN(tst_qquickage); + +#include "tst_qquickage.moc" diff --git a/tests/auto/particles/qquickangleddirection/data/basic.qml b/tests/auto/particles/qquickangleddirection/data/basic.qml new file mode 100644 index 0000000000..c2fda56561 --- /dev/null +++ b/tests/auto/particles/qquickangleddirection/data/basic.qml @@ -0,0 +1,68 @@ +/**************************************************************************** +** +** 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 test suite 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$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtQuick.Particles 2.0 + +Rectangle { + color: "black" + width: 320 + height: 320 + + ParticleSystem { + id: sys + objectName: "system" + anchors.fill: parent + + ImageParticle { + source: "../../shared/star.png" + } + + Emitter{ + //0,0 position + size: 32 + emitRate: 1000 + lifeSpan: 500 + speed: AngleDirection { angle: 45; magnitude: 500 } + acceleration: AngleDirection { angle: 45; angleVariation: 22; magnitude: 250; magnitudeVariation: 249} + } + } +} diff --git a/tests/auto/particles/qquickangleddirection/qquickangleddirection.pro b/tests/auto/particles/qquickangleddirection/qquickangleddirection.pro new file mode 100644 index 0000000000..2a4ee5237a --- /dev/null +++ b/tests/auto/particles/qquickangleddirection/qquickangleddirection.pro @@ -0,0 +1,11 @@ +CONFIG += testcase +TARGET = tst_qquickangleddirection +SOURCES += tst_qquickangleddirection.cpp +macx:CONFIG -= app_bundle + +testDataFiles.files = data +testDataFiles.path = . +DEPLOYMENT += testDataFiles + +QT += core-private gui-private v8-private declarative-private opengl-private testlib + diff --git a/tests/auto/particles/qquickangleddirection/tst_qquickangleddirection.cpp b/tests/auto/particles/qquickangleddirection/tst_qquickangleddirection.cpp new file mode 100644 index 0000000000..d21753e8a0 --- /dev/null +++ b/tests/auto/particles/qquickangleddirection/tst_qquickangleddirection.cpp @@ -0,0 +1,92 @@ +/**************************************************************************** +** +** 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 test suite 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 +#include +#include "../shared/particlestestsshared.h" +#include +#include + +class tst_qquickangleddirection : public QObject +{ + Q_OBJECT +public: + tst_qquickangleddirection(); + +private slots: + void test_basic(); +}; + +tst_qquickangleddirection::tst_qquickangleddirection() +{ + QUnifiedTimer::instance()->setConsistentTiming(true); +} + +void tst_qquickangleddirection::test_basic() +{ + QQuickView* view = createView(QCoreApplication::applicationDirPath() + "/data/basic.qml", 600); + QQuickParticleSystem* system = view->rootObject()->findChild("system"); + ensureAnimTime(600, system->m_animation); + + QCOMPARE(system->groupData[0]->size(), 500); + foreach (QQuickParticleData *d, system->groupData[0]->data) { + if (d->t == -1) + continue; //Particle data unused + + QCOMPARE(d->x, 0.f); + QCOMPARE(d->y, 0.f); + QVERIFY(qFuzzyCompare(d->vx, 353.55339f)); + QVERIFY(qFuzzyCompare(d->vy, 353.55339f)); + QVERIFY(d->ax > 0.f); + QVERIFY(d->ax < 500.f); + QVERIFY(d->ay > 0.f); + QVERIFY(d->ay < 500.f); + QVERIFY(qSqrt(d->ax*d->ax + d->ay*d->ay) < 500.f); + QCOMPARE(d->lifeSpan, 0.5f); + QCOMPARE(d->size, 32.f); + QCOMPARE(d->endSize, 32.f); + QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); + } +} + +QTEST_MAIN(tst_qquickangleddirection); + +#include "tst_qquickangleddirection.moc" diff --git a/tests/auto/particles/qquickcumulativedirection/data/basic.qml b/tests/auto/particles/qquickcumulativedirection/data/basic.qml new file mode 100644 index 0000000000..bd46c4556f --- /dev/null +++ b/tests/auto/particles/qquickcumulativedirection/data/basic.qml @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** 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 test suite 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$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtQuick.Particles 2.0 + +Rectangle { + color: "black" + width: 320 + height: 320 + + ParticleSystem { + id: sys + objectName: "system" + anchors.fill: parent + + ImageParticle { + source: "../../shared/star.png" + } + + Emitter{ + //0,0 position + size: 32 + emitRate: 1000 + lifeSpan: 500 + speed: CumulativeDirection { + PointDirection { x: 100; y: -100 } + PointDirection { x: -100; y: 100 } + } + acceleration: CumulativeDirection { + AngleDirection { angle: 0; magnitude: 100 } + AngleDirection { angle: 180; magnitude: 100 } + } + } + } +} diff --git a/tests/auto/particles/qquickcumulativedirection/qquickcumulativedirection.pro b/tests/auto/particles/qquickcumulativedirection/qquickcumulativedirection.pro new file mode 100644 index 0000000000..160f63f3bc --- /dev/null +++ b/tests/auto/particles/qquickcumulativedirection/qquickcumulativedirection.pro @@ -0,0 +1,11 @@ +CONFIG += testcase +TARGET = tst_qquickcumulativedirection +SOURCES += tst_qquickcumulativedirection.cpp +macx:CONFIG -= app_bundle + +testDataFiles.files = data +testDataFiles.path = . +DEPLOYMENT += testDataFiles + +QT += core-private gui-private v8-private declarative-private opengl-private testlib + diff --git a/tests/auto/particles/qquickcumulativedirection/tst_qquickcumulativedirection.cpp b/tests/auto/particles/qquickcumulativedirection/tst_qquickcumulativedirection.cpp new file mode 100644 index 0000000000..052578f3a8 --- /dev/null +++ b/tests/auto/particles/qquickcumulativedirection/tst_qquickcumulativedirection.cpp @@ -0,0 +1,88 @@ +/**************************************************************************** +** +** 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 test suite 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 +#include "../shared/particlestestsshared.h" +#include +#include + +class tst_qquickcumulativedirection : public QObject +{ + Q_OBJECT +public: + tst_qquickcumulativedirection(); + +private slots: + void test_basic(); +}; + +tst_qquickcumulativedirection::tst_qquickcumulativedirection() +{ + QUnifiedTimer::instance()->setConsistentTiming(true); +} + +void tst_qquickcumulativedirection::test_basic() +{ + QQuickView* view = createView(QCoreApplication::applicationDirPath() + "/data/basic.qml", 600); + QQuickParticleSystem* system = view->rootObject()->findChild("system"); + ensureAnimTime(600, system->m_animation); + + QCOMPARE(system->groupData[0]->size(), 500); + foreach (QQuickParticleData *d, system->groupData[0]->data) { + if (d->t == -1) + continue; //Particle data unused + + QVERIFY(myFuzzyCompare(d->x, 0.0f)); + QVERIFY(myFuzzyCompare(d->y, 0.0f)); + QVERIFY(myFuzzyCompare(d->vx, 0.0f)); + QVERIFY(myFuzzyCompare(d->vy, 0.0f)); + QVERIFY(myFuzzyCompare(d->ax, 0.0f)); + QVERIFY(myFuzzyCompare(d->ay, 0.0f)); + QCOMPARE(d->lifeSpan, 0.5f); + QCOMPARE(d->size, 32.f); + QCOMPARE(d->endSize, 32.f); + QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); + } +} + +QTEST_MAIN(tst_qquickcumulativedirection); + +#include "tst_qquickcumulativedirection.moc" diff --git a/tests/auto/particles/qquickcustomaffector/data/basic.qml b/tests/auto/particles/qquickcustomaffector/data/basic.qml new file mode 100644 index 0000000000..7371698026 --- /dev/null +++ b/tests/auto/particles/qquickcustomaffector/data/basic.qml @@ -0,0 +1,82 @@ +/**************************************************************************** +** +** 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 test suite 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$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtQuick.Particles 2.0 + +Rectangle { + color: "black" + width: 320 + height: 320 + + ParticleSystem { + id: sys + objectName: "system" + anchors.fill: parent + + ImageParticle { + source: "../../shared/star.png" + } + + Emitter{ + //0,0 position + size: 32 + emitRate: 1000 + lifeSpan: 500 + } + + Affector { + once: true + onAffectParticles: { + for (var i=0; i +#include "../shared/particlestestsshared.h" +#include +#include + +class tst_qquickcustomaffector : public QObject +{ + Q_OBJECT +public: + tst_qquickcustomaffector(); + +private slots: + void test_basic(); + void test_move(); +}; + +tst_qquickcustomaffector::tst_qquickcustomaffector() +{ + QUnifiedTimer::instance()->setConsistentTiming(true); +} + +void tst_qquickcustomaffector::test_basic() +{ + QQuickView* view = createView(QCoreApplication::applicationDirPath() + "/data/basic.qml", 600); + QQuickParticleSystem* system = view->rootObject()->findChild("system"); + ensureAnimTime(600, system->m_animation); + + QCOMPARE(system->groupData[0]->size(), 500); + foreach (QQuickParticleData *d, system->groupData[0]->data) { + if (d->t == -1) + continue; //Particle data unused + + QCOMPARE(d->x, 100.f); + QCOMPARE(d->y, 100.f); + QCOMPARE(d->vx, 100.f); + QCOMPARE(d->vy, 100.f); + QCOMPARE(d->ax, 100.f); + QCOMPARE(d->ay, 100.f); + QCOMPARE(d->lifeSpan, 0.5f); + QCOMPARE(d->size, 100.f); + QCOMPARE(d->endSize, 100.f); + QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); + } +} + +void tst_qquickcustomaffector::test_move() +{ + QQuickView* view = createView(QCoreApplication::applicationDirPath() + "/data/move.qml", 600); + QQuickParticleSystem* system = view->rootObject()->findChild("system"); + ensureAnimTime(600, system->m_animation); + + QCOMPARE(system->groupData[0]->size(), 500); + foreach (QQuickParticleData *d, system->groupData[0]->data) { + if (d->t == -1) + continue; //Particle data unused + if (!d->stillAlive()) + continue; //parameters no longer get set once you die + + QVERIFY(myFuzzyCompare(d->curX(), 50.0)); + QVERIFY(myFuzzyCompare(d->curY(), 50.0)); + QVERIFY(myFuzzyCompare(d->curVX(), 50.0)); + QVERIFY(myFuzzyCompare(d->curVY(), 50.0)); + QVERIFY(myFuzzyCompare(d->curAX(), 50.0)); + QVERIFY(myFuzzyCompare(d->curAY(), 50.0)); + QCOMPARE(d->lifeSpan, 0.5f); + QCOMPARE(d->size, 32.f); + QCOMPARE(d->endSize, 32.f); + QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); + } +} + +QTEST_MAIN(tst_qquickcustomaffector); + +#include "tst_qquickcustomaffector.moc" diff --git a/tests/auto/particles/qquickcustomparticle/data/basic.qml b/tests/auto/particles/qquickcustomparticle/data/basic.qml new file mode 100644 index 0000000000..244f706b99 --- /dev/null +++ b/tests/auto/particles/qquickcustomparticle/data/basic.qml @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** 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 test suite 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$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtQuick.Particles 2.0 + +Rectangle { + color: "black" + width: 320 + height: 320 + + ParticleSystem { + id: sys + objectName: "system" + anchors.fill: parent + + CustomParticle { + property variant source: ShaderEffectSource { + hideSource: true + sourceItem: Image { + source: "../../shared/star.png" + } + } + } + + Emitter{ + //0,0 position + size: 32 + emitRate: 1000 + lifeSpan: 500 + } + } +} diff --git a/tests/auto/particles/qquickcustomparticle/qquickcustomparticle.pro b/tests/auto/particles/qquickcustomparticle/qquickcustomparticle.pro new file mode 100644 index 0000000000..3476a66ca2 --- /dev/null +++ b/tests/auto/particles/qquickcustomparticle/qquickcustomparticle.pro @@ -0,0 +1,11 @@ +CONFIG += testcase +TARGET = tst_qquickcustomparticle +SOURCES += tst_qquickcustomparticle.cpp +macx:CONFIG -= app_bundle + +testDataFiles.files = data +testDataFiles.path = . +DEPLOYMENT += testDataFiles + +QT += core-private gui-private v8-private declarative-private opengl-private testlib + diff --git a/tests/auto/particles/qquickcustomparticle/tst_qquickcustomparticle.cpp b/tests/auto/particles/qquickcustomparticle/tst_qquickcustomparticle.cpp new file mode 100644 index 0000000000..3c73fad3f3 --- /dev/null +++ b/tests/auto/particles/qquickcustomparticle/tst_qquickcustomparticle.cpp @@ -0,0 +1,94 @@ +/**************************************************************************** +** +** 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 test suite 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 +#include "../shared/particlestestsshared.h" +#include +#include + +class tst_qquickcustomparticle : public QObject +{ + Q_OBJECT +public: + tst_qquickcustomparticle(); + +private slots: + void test_basic(); +}; + +tst_qquickcustomparticle::tst_qquickcustomparticle() +{ + QUnifiedTimer::instance()->setConsistentTiming(true); +} + +void tst_qquickcustomparticle::test_basic() +{ + QQuickView* view = createView(QCoreApplication::applicationDirPath() + "/data/basic.qml", 600); + QVERIFY(view); + QQuickParticleSystem* system = view->rootObject()->findChild("system"); + ensureAnimTime(600, system->m_animation); + + bool oneNonZero = false; + QCOMPARE(system->groupData[0]->size(), 500); + foreach (QQuickParticleData *d, system->groupData[0]->data) { + if (d->t == -1) + continue; //Particle data unused + + QCOMPARE(d->x, 0.f); + QCOMPARE(d->y, 0.f); + QCOMPARE(d->vx, 0.f); + QCOMPARE(d->vy, 0.f); + QCOMPARE(d->ax, 0.f); + QCOMPARE(d->ay, 0.f); + QCOMPARE(d->lifeSpan, 0.5f); + QCOMPARE(d->size, 32.f); + QCOMPARE(d->endSize, 32.f); + QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); + QVERIFY(d->r >= 0.0 && d->r <= 1.0); + if (d->r != 0.0 ) + oneNonZero = true; + } + QVERIFY(oneNonZero);//Zero is a valid value, but it also needs to be set to a random number +} + +QTEST_MAIN(tst_qquickcustomparticle); + +#include "tst_qquickcustomparticle.moc" diff --git a/tests/auto/particles/qquickellipseextruder/data/basic.qml b/tests/auto/particles/qquickellipseextruder/data/basic.qml new file mode 100644 index 0000000000..fa5fb3686a --- /dev/null +++ b/tests/auto/particles/qquickellipseextruder/data/basic.qml @@ -0,0 +1,77 @@ +/**************************************************************************** +** +** 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 test suite 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$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtQuick.Particles 2.0 + +Rectangle { + color: "black" + width: 320 + height: 320 + + ParticleSystem { + id: sys + objectName: "system" + anchors.fill: parent + + ImageParticle { + groups: ["", "nondefault"] + source: "../../shared/star.png" + } + + Emitter{ + anchors.fill: parent + shape: EllipseShape{} + size: 32 + emitRate: 1000 + lifeSpan: 500 + } + + Emitter{ + group: "nondefault" + anchors.fill: parent + shape: EllipseShape{ fill: false } + size: 32 + emitRate: 1000 + lifeSpan: 500 + } + } +} diff --git a/tests/auto/particles/qquickellipseextruder/qquickellipseextruder.pro b/tests/auto/particles/qquickellipseextruder/qquickellipseextruder.pro new file mode 100644 index 0000000000..9f5147be33 --- /dev/null +++ b/tests/auto/particles/qquickellipseextruder/qquickellipseextruder.pro @@ -0,0 +1,11 @@ +CONFIG += testcase +TARGET = tst_qquickellipseextruder +SOURCES += tst_qquickellipseextruder.cpp +macx:CONFIG -= app_bundle + +testDataFiles.files = data +testDataFiles.path = . +DEPLOYMENT += testDataFiles + +QT += core-private gui-private v8-private declarative-private opengl-private testlib + diff --git a/tests/auto/particles/qquickellipseextruder/tst_qquickellipseextruder.cpp b/tests/auto/particles/qquickellipseextruder/tst_qquickellipseextruder.cpp new file mode 100644 index 0000000000..7f412c8521 --- /dev/null +++ b/tests/auto/particles/qquickellipseextruder/tst_qquickellipseextruder.cpp @@ -0,0 +1,120 @@ +/**************************************************************************** +** +** 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 test suite 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 +#include +#include "../shared/particlestestsshared.h" +#include +#include + +class tst_qquickellipseextruder : public QObject +{ + Q_OBJECT +public: + tst_qquickellipseextruder(); + +private slots: + void test_basic(); +private: + bool inCircle(qreal x, qreal y, qreal r, bool borderOnly=false); +}; + +tst_qquickellipseextruder::tst_qquickellipseextruder() +{ + QUnifiedTimer::instance()->setConsistentTiming(true); +} + +bool tst_qquickellipseextruder::inCircle(qreal x, qreal y, qreal r, bool borderOnly) +{ + x -= r; + y -= r; + if (myFuzzyCompare(x,0) && myFuzzyCompare(y,0)) + return !borderOnly; + qreal mag = qSqrt(x*x + y*y); + if (borderOnly) + return myFuzzyCompare(mag, r); //Need myFuzzyCompare for smaller Epsilon than qFuzzyCompare + else + return mag - EPSILON < r; +} + +void tst_qquickellipseextruder::test_basic() +{ + QQuickView* view = createView(QCoreApplication::applicationDirPath() + "/data/basic.qml", 600); + QQuickParticleSystem* system = view->rootObject()->findChild("system"); + ensureAnimTime(600, system->m_animation); + + //Filled + QCOMPARE(system->groupData[0]->size(), 500); + foreach (QQuickParticleData *d, system->groupData[0]->data) { + if (d->t == -1) + continue; //Particle data unused + + QVERIFY(inCircle(d->x, d->y, 160, false)); + QCOMPARE(d->vx, 0.f); + QCOMPARE(d->vy, 0.f); + QCOMPARE(d->ax, 0.f); + QCOMPARE(d->ay, 0.f); + QCOMPARE(d->lifeSpan, 0.5f); + QCOMPARE(d->size, 32.f); + QCOMPARE(d->endSize, 32.f); + QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); + } + //Just border + QCOMPARE(system->groupData[1]->size(), 500); + foreach (QQuickParticleData *d, system->groupData[1]->data) { + if (d->t == -1) + continue; //Particle data unused + + QVERIFY(inCircle(d->x, d->y, 160, true)); + QCOMPARE(d->vx, 0.f); + QCOMPARE(d->vy, 0.f); + QCOMPARE(d->ax, 0.f); + QCOMPARE(d->ay, 0.f); + QCOMPARE(d->lifeSpan, 0.5f); + QCOMPARE(d->size, 32.f); + QCOMPARE(d->endSize, 32.f); + QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); + } +} + +QTEST_MAIN(tst_qquickellipseextruder); + +#include "tst_qquickellipseextruder.moc" diff --git a/tests/auto/particles/qquickfriction/data/basic.qml b/tests/auto/particles/qquickfriction/data/basic.qml new file mode 100644 index 0000000000..87a8897914 --- /dev/null +++ b/tests/auto/particles/qquickfriction/data/basic.qml @@ -0,0 +1,87 @@ +/**************************************************************************** +** +** 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 test suite 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$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtQuick.Particles 2.0 + +Rectangle { + color: "black" + width: 320 + height: 320 + + ParticleSystem { + id: sys + objectName: "system" + anchors.fill: parent + + ImageParticle { + groups: ["","notdefault"] + source: "../../shared/star.png" + } + + Friction { + factor: 0.2 + } + + Emitter{ + //0,0 position + speed: PointDirection{x:100} + size: 32 + emitRate: 1000 + lifeSpan: 500 + } + + Friction { + groups: ["notdefault"] + factor: 1000.0 + } + + Emitter{ + //0,0 position + group: "notdefault" + y:200 + speed: PointDirection{x:100} + size: 32 + emitRate: 1000 + lifeSpan: 500 + } + } +} diff --git a/tests/auto/particles/qquickfriction/data/threshold.qml b/tests/auto/particles/qquickfriction/data/threshold.qml new file mode 100644 index 0000000000..27990c3e7e --- /dev/null +++ b/tests/auto/particles/qquickfriction/data/threshold.qml @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** 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 test suite 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$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtQuick.Particles 2.0 + +Rectangle { + color: "black" + width: 320 + height: 320 + + ParticleSystem { + id: sys + objectName: "system" + anchors.fill: parent + + ImageParticle { + groups: ["","notdefault"] + source: "../../shared/star.png" + } + + Friction { + factor: 1000 //speed limit 50 + threshold: 50 + } + + Emitter{ + //0,0 position + speed: PointDirection{x:1000} + size: 32 + emitRate: 1000 + lifeSpan: 500 + } + } +} diff --git a/tests/auto/particles/qquickfriction/qquickfriction.pro b/tests/auto/particles/qquickfriction/qquickfriction.pro new file mode 100644 index 0000000000..d6726724ff --- /dev/null +++ b/tests/auto/particles/qquickfriction/qquickfriction.pro @@ -0,0 +1,11 @@ +CONFIG += testcase +TARGET = tst_qquickfriction +SOURCES += tst_qquickfriction.cpp +macx:CONFIG -= app_bundle + +testDataFiles.files = data +testDataFiles.path = . +DEPLOYMENT += testDataFiles + +QT += core-private gui-private v8-private declarative-private opengl-private testlib + diff --git a/tests/auto/particles/qquickfriction/tst_qquickfriction.cpp b/tests/auto/particles/qquickfriction/tst_qquickfriction.cpp new file mode 100644 index 0000000000..aca4ea2330 --- /dev/null +++ b/tests/auto/particles/qquickfriction/tst_qquickfriction.cpp @@ -0,0 +1,134 @@ +/**************************************************************************** +** +** 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 test suite 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 +#include "../shared/particlestestsshared.h" +#include +#include + +class tst_qquickfriction : public QObject +{ + Q_OBJECT +public: + tst_qquickfriction(); + +private slots: + void test_basic(); + void test_threshold(); +}; + +tst_qquickfriction::tst_qquickfriction() +{ + QUnifiedTimer::instance()->setConsistentTiming(true); +} + +void tst_qquickfriction::test_basic() +{ + QQuickView* view = createView(QCoreApplication::applicationDirPath() + "/data/basic.qml", 600); + QQuickParticleSystem* system = view->rootObject()->findChild("system"); + ensureAnimTime(600, system->m_animation); + + //Default is just slowed a little + QCOMPARE(system->groupData[0]->size(), 500); + foreach (QQuickParticleData *d, system->groupData[0]->data) { + if (d->t == -1) + continue; //Particle data unused + + QVERIFY(d->vx < 100.f); + QCOMPARE(d->y, 0.f); + QCOMPARE(d->vy, 0.f); + QCOMPARE(d->ax, 0.f); + QCOMPARE(d->ay, 0.f); + QCOMPARE(d->lifeSpan, 0.5f); + QCOMPARE(d->size, 32.f); + QCOMPARE(d->endSize, 32.f); + QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); + } + + //Nondefault comes to a complete stop within the first half of its life + QCOMPARE(system->groupData[1]->size(), 500); + foreach (QQuickParticleData *d, system->groupData[1]->data) { + if (d->t == -1) + continue; //Particle data unused + + if (d->t > ((qreal)system->timeInt/1000.0) - 0.25) + continue; + QVERIFY(myFuzzyCompare(d->vx, 0.f)); + QCOMPARE(d->y, 200.f); + QCOMPARE(d->vy, 0.f); + QCOMPARE(d->ax, 0.f); + QCOMPARE(d->ay, 0.f); + QCOMPARE(d->lifeSpan, 0.5f); + QCOMPARE(d->size, 32.f); + QCOMPARE(d->endSize, 32.f); + QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); + } +} + +void tst_qquickfriction::test_threshold() +{ + QQuickView* view = createView(QCoreApplication::applicationDirPath() + "/data/threshold.qml", 600); + QQuickParticleSystem* system = view->rootObject()->findChild("system"); + ensureAnimTime(600, system->m_animation); + + //Speed capped at 50, but it might take a frame or two to get there + QCOMPARE(system->groupData[0]->size(), 500); + foreach (QQuickParticleData *d, system->groupData[0]->data) { + if (d->t == -1.0f) + continue; //Particle data unused + if (myFuzzyGEQ(d->t, ((qreal)system->timeInt/1000.0) - 0.1)) + continue; //Particle data too young + + QVERIFY(myFuzzyLEQ(d->vx, 50.f)); + QCOMPARE(d->y, 0.f); + QCOMPARE(d->vy, 0.f); + QCOMPARE(d->ax, 0.f); + QCOMPARE(d->ay, 0.f); + QCOMPARE(d->lifeSpan, 0.5f); + QCOMPARE(d->size, 32.f); + QCOMPARE(d->endSize, 32.f); + QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); + } +} + +QTEST_MAIN(tst_qquickfriction); + +#include "tst_qquickfriction.moc" diff --git a/tests/auto/particles/qquickgravity/data/basic.qml b/tests/auto/particles/qquickgravity/data/basic.qml new file mode 100644 index 0000000000..9275654297 --- /dev/null +++ b/tests/auto/particles/qquickgravity/data/basic.qml @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** 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 test suite 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$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtQuick.Particles 2.0 + +Rectangle { + color: "black" + width: 320 + height: 320 + + ParticleSystem { + id: sys + objectName: "system" + anchors.fill: parent + + ImageParticle { + source: "../../shared/star.png" + } + + Gravity { + acceleration: 1000 + angle: 45 + } + Emitter{ + //0,0 position + size: 32 + emitRate: 1000 + lifeSpan: 500 + } + } +} diff --git a/tests/auto/particles/qquickgravity/qquickgravity.pro b/tests/auto/particles/qquickgravity/qquickgravity.pro new file mode 100644 index 0000000000..bc503d932a --- /dev/null +++ b/tests/auto/particles/qquickgravity/qquickgravity.pro @@ -0,0 +1,11 @@ +CONFIG += testcase +TARGET = tst_qquickgravity +SOURCES += tst_qquickgravity.cpp +macx:CONFIG -= app_bundle + +testDataFiles.files = data +testDataFiles.path = . +DEPLOYMENT += testDataFiles + +QT += core-private gui-private v8-private declarative-private opengl-private testlib + diff --git a/tests/auto/particles/qquickgravity/tst_qquickgravity.cpp b/tests/auto/particles/qquickgravity/tst_qquickgravity.cpp new file mode 100644 index 0000000000..5613591171 --- /dev/null +++ b/tests/auto/particles/qquickgravity/tst_qquickgravity.cpp @@ -0,0 +1,84 @@ +/**************************************************************************** +** +** 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 test suite 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 +#include "../shared/particlestestsshared.h" +#include +#include + +class tst_qquickgravity : public QObject +{ + Q_OBJECT +public: + tst_qquickgravity(); + +private slots: + void test_basic(); +}; + +tst_qquickgravity::tst_qquickgravity() +{ + QUnifiedTimer::instance()->setConsistentTiming(true); +} + +void tst_qquickgravity::test_basic() +{ + QQuickView* view = createView(QCoreApplication::applicationDirPath() + "/data/basic.qml", 600); + QQuickParticleSystem* system = view->rootObject()->findChild("system"); + ensureAnimTime(600, system->m_animation); + + QCOMPARE(system->groupData[0]->size(), 500); + foreach (QQuickParticleData *d, system->groupData[0]->data) { + if (d->t == -1) + continue; //Particle data unused + + QCOMPARE(d->ax, 707.10678f); + QCOMPARE(d->ay, 707.10678f); + QCOMPARE(d->lifeSpan, 0.5f); + QCOMPARE(d->size, 32.f); + QCOMPARE(d->endSize, 32.f); + QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); + } +} + +QTEST_MAIN(tst_qquickgravity); + +#include "tst_qquickgravity.moc" diff --git a/tests/auto/particles/qquickimageparticle/data/basic.qml b/tests/auto/particles/qquickimageparticle/data/basic.qml new file mode 100644 index 0000000000..f5ef4c16c0 --- /dev/null +++ b/tests/auto/particles/qquickimageparticle/data/basic.qml @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** 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 test suite 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$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtQuick.Particles 2.0 + +Rectangle { + color: "black" + width: 320 + height: 320 + + ParticleSystem { + id: sys + objectName: "system" + anchors.fill: parent + + ImageParticle { + source: "../../shared/star.png" + } + + Emitter{ + //0,0 position + size: 32 + emitRate: 1000 + lifeSpan: 500 + } + } +} diff --git a/tests/auto/particles/qquickimageparticle/data/colored.qml b/tests/auto/particles/qquickimageparticle/data/colored.qml new file mode 100644 index 0000000000..8f4ddbf8c4 --- /dev/null +++ b/tests/auto/particles/qquickimageparticle/data/colored.qml @@ -0,0 +1,68 @@ +/**************************************************************************** +** +** 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 test suite 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$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtQuick.Particles 2.0 + +Rectangle { + color: "black" + width: 320 + height: 320 + + ParticleSystem { + id: sys + objectName: "system" + anchors.fill: parent + + ImageParticle { + source: "../../shared/star.png" + alpha: 0.5 + color: "#030201" + } + + Emitter{ + //0,0 position + size: 32 + emitRate: 1000 + lifeSpan: 500 + } + } +} diff --git a/tests/auto/particles/qquickimageparticle/data/deformed.qml b/tests/auto/particles/qquickimageparticle/data/deformed.qml new file mode 100644 index 0000000000..b0a58ee5d1 --- /dev/null +++ b/tests/auto/particles/qquickimageparticle/data/deformed.qml @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** 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 test suite 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$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtQuick.Particles 2.0 + +Rectangle { + color: "black" + width: 320 + height: 320 + + ParticleSystem { + id: sys + objectName: "system" + anchors.fill: parent + + ImageParticle { + source: "../../shared/star.png" + rotation: 90 + rotationSpeed: 90 + autoRotation: true + yVector: PointDirection{x: 0.5; y: 0.5} + xVector: PointDirection{x: 0.5; y: 0.5} + } + + Emitter{ + //0,0 position + size: 32 + emitRate: 1000 + lifeSpan: 500 + } + } +} diff --git a/tests/auto/particles/qquickimageparticle/data/sprite.qml b/tests/auto/particles/qquickimageparticle/data/sprite.qml new file mode 100644 index 0000000000..5c1acf4b04 --- /dev/null +++ b/tests/auto/particles/qquickimageparticle/data/sprite.qml @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** 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 test suite 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$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtQuick.Particles 2.0 + +Rectangle { + color: "black" + width: 320 + height: 320 + + ParticleSystem { + id: sys + objectName: "system" + anchors.fill: parent + + ImageParticle { + sprites: Sprite { + name: "happy" + source: "../../shared/squarefacesprite.png" + frames: 6 + duration: 120 + } + } + + Emitter{ + //0,0 position + size: 32 + emitRate: 1000 + lifeSpan: 500 + } + } +} diff --git a/tests/auto/particles/qquickimageparticle/data/tabled.qml b/tests/auto/particles/qquickimageparticle/data/tabled.qml new file mode 100644 index 0000000000..8a7a9ce229 --- /dev/null +++ b/tests/auto/particles/qquickimageparticle/data/tabled.qml @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** 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 test suite 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$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtQuick.Particles 2.0 + +Rectangle { + color: "black" + width: 320 + height: 320 + + ParticleSystem { + id: sys + objectName: "system" + anchors.fill: parent + + ImageParticle { + source: "../../shared/star.png" + sizeTable: "../../shared/table.png" + colorTable: "../../shared/table.png" + opacityTable: "../../shared/table.png" + } + + Emitter{ + //0,0 position + size: 32 + emitRate: 1000 + lifeSpan: 500 + } + } +} diff --git a/tests/auto/particles/qquickimageparticle/qquickimageparticle.pro b/tests/auto/particles/qquickimageparticle/qquickimageparticle.pro new file mode 100644 index 0000000000..c05ecdfb09 --- /dev/null +++ b/tests/auto/particles/qquickimageparticle/qquickimageparticle.pro @@ -0,0 +1,11 @@ +CONFIG += testcase +TARGET = tst_qquickimageparticle +SOURCES += tst_qquickimageparticle.cpp +macx:CONFIG -= app_bundle + +testDataFiles.files = data +testDataFiles.path = . +DEPLOYMENT += testDataFiles + +QT += core-private gui-private v8-private declarative-private opengl-private testlib + diff --git a/tests/auto/particles/qquickimageparticle/tst_qquickimageparticle.cpp b/tests/auto/particles/qquickimageparticle/tst_qquickimageparticle.cpp new file mode 100644 index 0000000000..e56de35137 --- /dev/null +++ b/tests/auto/particles/qquickimageparticle/tst_qquickimageparticle.cpp @@ -0,0 +1,285 @@ +/**************************************************************************** +** +** 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 test suite 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 +#include "../shared/particlestestsshared.h" +#include +#include + +const double CONV_FACTOR = 0.017453292519943295;//Degrees to radians + +class tst_qquickimageparticle : public QObject +{ + Q_OBJECT +public: + tst_qquickimageparticle(); + +private slots: + void test_basic(); + void test_colored(); + void test_deformed(); + void test_tabled(); + void test_sprite(); +}; + +tst_qquickimageparticle::tst_qquickimageparticle() +{ + QUnifiedTimer::instance()->setConsistentTiming(true); +} + +void tst_qquickimageparticle::test_basic() +{ + QQuickView* view = createView(QCoreApplication::applicationDirPath() + "/data/basic.qml", 600); + QQuickParticleSystem* system = view->rootObject()->findChild("system"); + ensureAnimTime(600, system->m_animation); + + QCOMPARE(system->groupData[0]->size(), 500); + foreach (QQuickParticleData *d, system->groupData[0]->data) { + if (d->t == -1) + continue; //Particle data unused + + QCOMPARE(d->x, 0.f); + QCOMPARE(d->y, 0.f); + QCOMPARE(d->vx, 0.f); + QCOMPARE(d->vy, 0.f); + QCOMPARE(d->ax, 0.f); + QCOMPARE(d->ay, 0.f); + QCOMPARE(d->lifeSpan, 0.5f); + QCOMPARE(d->size, 32.f); + QCOMPARE(d->endSize, 32.f); + QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); + QCOMPARE(d->color.r, (uchar)255); + QCOMPARE(d->color.g, (uchar)255); + QCOMPARE(d->color.b, (uchar)255); + QCOMPARE(d->color.a, (uchar)255); + QCOMPARE(d->xx, 1.0f); + QCOMPARE(d->xy, 0.0f); + QCOMPARE(d->yy, 1.0f); + QCOMPARE(d->yx, 0.0f); + QCOMPARE(d->rotation, 0.0f); + QCOMPARE(d->rotationSpeed, 0.0f); + QCOMPARE(d->autoRotate, 0.0f); + QCOMPARE(d->animX, 0.0f); + QCOMPARE(d->animY, 0.0f); + QCOMPARE(d->animWidth, 1.0f); + QCOMPARE(d->animHeight, 1.0f); + QCOMPARE(d->frameDuration, 1.0f); + QCOMPARE(d->frameCount, 1.0f); + QCOMPARE(d->animT, -1.0f); + } +} + + +void tst_qquickimageparticle::test_colored() +{ + QQuickView* view = createView(QCoreApplication::applicationDirPath() + "/data/colored.qml", 600); + QQuickParticleSystem* system = view->rootObject()->findChild("system"); + ensureAnimTime(600, system->m_animation); + + QCOMPARE(system->groupData[0]->size(), 500); + foreach (QQuickParticleData *d, system->groupData[0]->data) { + if (d->t == -1) + continue; //Particle data unused + + QCOMPARE(d->x, 0.f); + QCOMPARE(d->y, 0.f); + QCOMPARE(d->vx, 0.f); + QCOMPARE(d->vy, 0.f); + QCOMPARE(d->ax, 0.f); + QCOMPARE(d->ay, 0.f); + QCOMPARE(d->lifeSpan, 0.5f); + QCOMPARE(d->size, 32.f); + QCOMPARE(d->endSize, 32.f); + QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); + QCOMPARE(d->color.r, (uchar)003); + QCOMPARE(d->color.g, (uchar)002); + QCOMPARE(d->color.b, (uchar)001); + QCOMPARE(d->color.a, (uchar)127); + QCOMPARE(d->xx, 1.0f); + QCOMPARE(d->xy, 0.0f); + QCOMPARE(d->yy, 1.0f); + QCOMPARE(d->yx, 0.0f); + QCOMPARE(d->rotation, 0.0f); + QCOMPARE(d->rotationSpeed, 0.0f); + QCOMPARE(d->autoRotate, 0.0f); + QCOMPARE(d->animX, 0.0f); + QCOMPARE(d->animY, 0.0f); + QCOMPARE(d->animWidth, 1.0f); + QCOMPARE(d->animHeight, 1.0f); + QCOMPARE(d->frameDuration, 1.0f); + QCOMPARE(d->frameCount, 1.0f); + QCOMPARE(d->animT, -1.0f); + } +} + + +void tst_qquickimageparticle::test_deformed() +{ + QQuickView* view = createView(QCoreApplication::applicationDirPath() + "/data/deformed.qml", 600); + QQuickParticleSystem* system = view->rootObject()->findChild("system"); + ensureAnimTime(600, system->m_animation); + + QCOMPARE(system->groupData[0]->size(), 500); + foreach (QQuickParticleData *d, system->groupData[0]->data) { + if (d->t == -1) + continue; //Particle data unused + + QCOMPARE(d->x, 0.f); + QCOMPARE(d->y, 0.f); + QCOMPARE(d->vx, 0.f); + QCOMPARE(d->vy, 0.f); + QCOMPARE(d->ax, 0.f); + QCOMPARE(d->ay, 0.f); + QCOMPARE(d->lifeSpan, 0.5f); + QCOMPARE(d->size, 32.f); + QCOMPARE(d->endSize, 32.f); + QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); + QCOMPARE(d->color.r, (uchar)255); + QCOMPARE(d->color.g, (uchar)255); + QCOMPARE(d->color.b, (uchar)255); + QCOMPARE(d->color.a, (uchar)255); + QCOMPARE(d->xx, 0.5f); + QCOMPARE(d->xy, 0.5f); + QCOMPARE(d->yy, 0.5f); + QCOMPARE(d->yx, 0.5f); + QCOMPARE(d->rotation, 90.0f * (float)CONV_FACTOR); + QCOMPARE(d->rotationSpeed, 90.0f * (float)CONV_FACTOR); + QCOMPARE(d->autoRotate, 1.0f); + QCOMPARE(d->animX, 0.0f); + QCOMPARE(d->animY, 0.0f); + QCOMPARE(d->animWidth, 1.0f); + QCOMPARE(d->animHeight, 1.0f); + QCOMPARE(d->frameDuration, 1.0f); + QCOMPARE(d->frameCount, 1.0f); + QCOMPARE(d->animT, -1.0f); + } +} + + +void tst_qquickimageparticle::test_tabled() +{ + QQuickView* view = createView(QCoreApplication::applicationDirPath() + "/data/tabled.qml", 600); + QQuickParticleSystem* system = view->rootObject()->findChild("system"); + ensureAnimTime(600, system->m_animation); + + QCOMPARE(system->groupData[0]->size(), 500); + foreach (QQuickParticleData *d, system->groupData[0]->data) { + if (d->t == -1) + continue; //Particle data unused + + QCOMPARE(d->x, 0.f); + QCOMPARE(d->y, 0.f); + QCOMPARE(d->vx, 0.f); + QCOMPARE(d->vy, 0.f); + QCOMPARE(d->ax, 0.f); + QCOMPARE(d->ay, 0.f); + QCOMPARE(d->lifeSpan, 0.5f); + QCOMPARE(d->size, 32.f); + QCOMPARE(d->endSize, 32.f); + QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); + QCOMPARE(d->color.r, (uchar)255); + QCOMPARE(d->color.g, (uchar)255); + QCOMPARE(d->color.b, (uchar)255); + QCOMPARE(d->color.a, (uchar)255); + QCOMPARE(d->xx, 1.0f); + QCOMPARE(d->xy, 0.0f); + QCOMPARE(d->yy, 1.0f); + QCOMPARE(d->yx, 0.0f); + QCOMPARE(d->rotation, 0.0f); + QCOMPARE(d->rotationSpeed, 0.0f); + QCOMPARE(d->autoRotate, 0.0f); + QCOMPARE(d->animX, 0.0f); + QCOMPARE(d->animY, 0.0f); + QCOMPARE(d->animWidth, 1.0f); + QCOMPARE(d->animHeight, 1.0f); + QCOMPARE(d->frameDuration, 1.0f); + QCOMPARE(d->frameCount, 1.0f); + QCOMPARE(d->animT, -1.0f); + //TODO: This performance level doesn't alter particleData, but goes straight to shaders. Find something to test + } +} + + +void tst_qquickimageparticle::test_sprite() +{ + QQuickView* view = createView(QCoreApplication::applicationDirPath() + "/data/sprite.qml", 600); + QQuickParticleSystem* system = view->rootObject()->findChild("system"); + ensureAnimTime(600, system->m_animation); + + QCOMPARE(system->groupData[0]->size(), 500); + foreach (QQuickParticleData *d, system->groupData[0]->data) { + if (d->t == -1) + continue; //Particle data unused + + QCOMPARE(d->x, 0.f); + QCOMPARE(d->y, 0.f); + QCOMPARE(d->vx, 0.f); + QCOMPARE(d->vy, 0.f); + QCOMPARE(d->ax, 0.f); + QCOMPARE(d->ay, 0.f); + QCOMPARE(d->lifeSpan, 0.5f); + QCOMPARE(d->size, 32.f); + QCOMPARE(d->endSize, 32.f); + QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); + QCOMPARE(d->color.r, (uchar)255); + QCOMPARE(d->color.g, (uchar)255); + QCOMPARE(d->color.b, (uchar)255); + QCOMPARE(d->color.a, (uchar)255); + QCOMPARE(d->xx, 1.0f); + QCOMPARE(d->xy, 0.0f); + QCOMPARE(d->yy, 1.0f); + QCOMPARE(d->yx, 0.0f); + QCOMPARE(d->rotation, 0.0f); + QCOMPARE(d->rotationSpeed, 0.0f); + QCOMPARE(d->autoRotate, 0.0f); + QVERIFY(myFuzzyCompare(d->frameDuration, 120.f)); + QCOMPARE(d->frameCount, 6.0f); + QVERIFY(d->animT > 0.0f); + QCOMPARE(d->animX, 0.0f); + QCOMPARE(d->animY, 0.0f); + QCOMPARE(d->animWidth, 31.0f); + QCOMPARE(d->animHeight, 30.0f); + } +} + +QTEST_MAIN(tst_qquickimageparticle); + +#include "tst_qquickimageparticle.moc" diff --git a/tests/auto/particles/qquickitemparticle/data/basic.qml b/tests/auto/particles/qquickitemparticle/data/basic.qml new file mode 100644 index 0000000000..dbe16a0b4e --- /dev/null +++ b/tests/auto/particles/qquickitemparticle/data/basic.qml @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** 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 test suite 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$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtQuick.Particles 2.0 + +Rectangle { + color: "black" + width: 320 + height: 320 + + ParticleSystem { + id: sys + objectName: "system" + anchors.fill: parent + + ItemParticle { + delegate: Image{ source: "../../shared/star.png" } + } + + Emitter{ + //0,0 position + size: 32 + emitRate: 1000 + lifeSpan: 500 + } + } +} diff --git a/tests/auto/particles/qquickitemparticle/qquickitemparticle.pro b/tests/auto/particles/qquickitemparticle/qquickitemparticle.pro new file mode 100644 index 0000000000..dc006d2ba1 --- /dev/null +++ b/tests/auto/particles/qquickitemparticle/qquickitemparticle.pro @@ -0,0 +1,11 @@ +CONFIG += testcase +TARGET = tst_qquickitemparticle +SOURCES += tst_qquickitemparticle.cpp +macx:CONFIG -= app_bundle + +testDataFiles.files = data +testDataFiles.path = . +DEPLOYMENT += testDataFiles + +QT += core-private gui-private v8-private declarative-private opengl-private testlib + diff --git a/tests/auto/particles/qquickitemparticle/tst_qquickitemparticle.cpp b/tests/auto/particles/qquickitemparticle/tst_qquickitemparticle.cpp new file mode 100644 index 0000000000..40197ec619 --- /dev/null +++ b/tests/auto/particles/qquickitemparticle/tst_qquickitemparticle.cpp @@ -0,0 +1,95 @@ +/**************************************************************************** +** +** 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 test suite 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 +#include "../shared/particlestestsshared.h" +#include +#include +#include + +class tst_qquickitemparticle : public QObject +{ + Q_OBJECT +public: + tst_qquickitemparticle(); + +private slots: + void test_basic(); +}; + +tst_qquickitemparticle::tst_qquickitemparticle() +{ + QUnifiedTimer::instance()->setConsistentTiming(true); +} + +void tst_qquickitemparticle::test_basic() +{ + QQuickView* view = createView(QCoreApplication::applicationDirPath() + "/data/basic.qml", 600); + QQuickParticleSystem* system = view->rootObject()->findChild("system"); + ensureAnimTime(600, system->m_animation); + + QCOMPARE(system->groupData[0]->size(), 500); + foreach (QQuickParticleData *d, system->groupData[0]->data) { + if (d->t == -1) + continue; //Particle data unused + + QCOMPARE(d->x, 0.f); + QCOMPARE(d->y, 0.f); + QCOMPARE(d->vx, 0.f); + QCOMPARE(d->vy, 0.f); + QCOMPARE(d->ax, 0.f); + QCOMPARE(d->ay, 0.f); + QCOMPARE(d->lifeSpan, 0.5f); + QCOMPARE(d->size, 32.f); + QCOMPARE(d->endSize, 32.f); + QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); + if (d->t > ((qreal)system->timeInt/1000.0) - 0.05)//Delegates appear between frames, may miss the first couple + continue; + if (d->t < ((qreal)system->timeInt/1000.0) - 0.45)//Delegates cleared on death + continue; + QVERIFY(d->delegate); + QVERIFY(qobject_cast(d->delegate)); + } +} + +QTEST_MAIN(tst_qquickitemparticle); + +#include "tst_qquickitemparticle.moc" diff --git a/tests/auto/particles/qquicklineextruder/data/basic.qml b/tests/auto/particles/qquicklineextruder/data/basic.qml new file mode 100644 index 0000000000..dbe2ec5c7d --- /dev/null +++ b/tests/auto/particles/qquicklineextruder/data/basic.qml @@ -0,0 +1,76 @@ +/**************************************************************************** +** +** 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 test suite 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$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtQuick.Particles 2.0 + +Rectangle { + color: "black" + width: 320 + height: 320 + + ParticleSystem { + id: sys + objectName: "system" + anchors.fill: parent + + ImageParticle { + groups: ["", "notdefault"] + source: "../../shared/star.png" + } + + Emitter{ + anchors.fill: parent + shape: LineShape{} + size: 32 + emitRate: 1000 + lifeSpan: 500 + } + Emitter{ + anchors.fill: parent + group: "notdefault" + shape: LineShape{mirrored: true} + size: 32 + emitRate: 1000 + lifeSpan: 500 + } + } +} diff --git a/tests/auto/particles/qquicklineextruder/qquicklineextruder.pro b/tests/auto/particles/qquicklineextruder/qquicklineextruder.pro new file mode 100644 index 0000000000..255c9a4104 --- /dev/null +++ b/tests/auto/particles/qquicklineextruder/qquicklineextruder.pro @@ -0,0 +1,11 @@ +CONFIG += testcase +TARGET = tst_qquicklineextruder +SOURCES += tst_qquicklineextruder.cpp +macx:CONFIG -= app_bundle + +testDataFiles.files = data +testDataFiles.path = . +DEPLOYMENT += testDataFiles + +QT += core-private gui-private v8-private declarative-private opengl-private testlib + diff --git a/tests/auto/particles/qquicklineextruder/tst_qquicklineextruder.cpp b/tests/auto/particles/qquicklineextruder/tst_qquicklineextruder.cpp new file mode 100644 index 0000000000..ff45a9e92c --- /dev/null +++ b/tests/auto/particles/qquicklineextruder/tst_qquicklineextruder.cpp @@ -0,0 +1,103 @@ +/**************************************************************************** +** +** 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 test suite 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 +#include "../shared/particlestestsshared.h" +#include +#include + +class tst_qquicklineextruder : public QObject +{ + Q_OBJECT +public: + tst_qquicklineextruder(); + +private slots: + void test_basic(); +}; + +tst_qquicklineextruder::tst_qquicklineextruder() +{ + QUnifiedTimer::instance()->setConsistentTiming(true); +} + +void tst_qquicklineextruder::test_basic() +{ + QQuickView* view = createView(QCoreApplication::applicationDirPath() + "/data/basic.qml", 600); + QQuickParticleSystem* system = view->rootObject()->findChild("system"); + ensureAnimTime(600, system->m_animation); + + QCOMPARE(system->groupData[0]->size(), 500); + foreach (QQuickParticleData *d, system->groupData[0]->data) { + if (d->t == -1) + continue; //Particle data unused + + QCOMPARE(d->x, d->y); + QCOMPARE(d->vx, 0.f); + QCOMPARE(d->vy, 0.f); + QCOMPARE(d->ax, 0.f); + QCOMPARE(d->ay, 0.f); + QCOMPARE(d->lifeSpan, 0.5f); + QCOMPARE(d->size, 32.f); + QCOMPARE(d->endSize, 32.f); + QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); + } + + QCOMPARE(system->groupData[1]->size(), 500); + foreach (QQuickParticleData *d, system->groupData[1]->data) { + if (d->t == -1) + continue; //Particle data unused + + QCOMPARE(d->x + d->y, 320.0f); + QCOMPARE(d->vx, 0.f); + QCOMPARE(d->vy, 0.f); + QCOMPARE(d->ax, 0.f); + QCOMPARE(d->ay, 0.f); + QCOMPARE(d->lifeSpan, 0.5f); + QCOMPARE(d->size, 32.f); + QCOMPARE(d->endSize, 32.f); + QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); + } +} + +QTEST_MAIN(tst_qquicklineextruder); + +#include "tst_qquicklineextruder.moc" diff --git a/tests/auto/particles/qquickmaskextruder/data/basic.qml b/tests/auto/particles/qquickmaskextruder/data/basic.qml new file mode 100644 index 0000000000..804df83de8 --- /dev/null +++ b/tests/auto/particles/qquickmaskextruder/data/basic.qml @@ -0,0 +1,68 @@ +/**************************************************************************** +** +** 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 test suite 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$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtQuick.Particles 2.0 + +Rectangle { + color: "black" + width: 320 + height: 320 + + ParticleSystem { + id: sys + objectName: "system" + anchors.fill: parent + + ImageParticle { + source: "../../shared/star.png" + } + + Emitter{ + //100,100 rect at 100,100 + anchors.fill: parent + shape: MaskShape{source: "smallmask.png"} + size: 32 + emitRate: 1000 + lifeSpan: 500 + } + } +} diff --git a/tests/auto/particles/qquickmaskextruder/data/smallmask.png b/tests/auto/particles/qquickmaskextruder/data/smallmask.png new file mode 100644 index 0000000000..e36fb9fe55 Binary files /dev/null and b/tests/auto/particles/qquickmaskextruder/data/smallmask.png differ diff --git a/tests/auto/particles/qquickmaskextruder/qquickmaskextruder.pro b/tests/auto/particles/qquickmaskextruder/qquickmaskextruder.pro new file mode 100644 index 0000000000..b53d3610fa --- /dev/null +++ b/tests/auto/particles/qquickmaskextruder/qquickmaskextruder.pro @@ -0,0 +1,11 @@ +CONFIG += testcase +TARGET = tst_qquickmaskextruder +SOURCES += tst_qquickmaskextruder.cpp +macx:CONFIG -= app_bundle + +testDataFiles.files = data +testDataFiles.path = . +DEPLOYMENT += testDataFiles + +QT += core-private gui-private v8-private declarative-private opengl-private testlib + diff --git a/tests/auto/particles/qquickmaskextruder/tst_qquickmaskextruder.cpp b/tests/auto/particles/qquickmaskextruder/tst_qquickmaskextruder.cpp new file mode 100644 index 0000000000..b2a178fa1c --- /dev/null +++ b/tests/auto/particles/qquickmaskextruder/tst_qquickmaskextruder.cpp @@ -0,0 +1,88 @@ +/**************************************************************************** +** +** 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 test suite 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 +#include "../shared/particlestestsshared.h" +#include +#include + +class tst_qquickmaskextruder : public QObject +{ + Q_OBJECT +public: + tst_qquickmaskextruder(); + +private slots: + void test_basic(); +}; + +tst_qquickmaskextruder::tst_qquickmaskextruder() +{ + QUnifiedTimer::instance()->setConsistentTiming(true); +} + +void tst_qquickmaskextruder::test_basic() +{ + QQuickView* view = createView(QCoreApplication::applicationDirPath() + "/data/basic.qml", 600); + QQuickParticleSystem* system = view->rootObject()->findChild("system"); + ensureAnimTime(600, system->m_animation); + + QCOMPARE(system->groupData[0]->size(), 500); + foreach (QQuickParticleData *d, system->groupData[0]->data) { + if (d->t == -1) + continue; //Particle data unused + + QVERIFY(d->x >= 100.0f && d->x <= 200.0f); + QVERIFY(d->y >= 100.0f && d->y <= 200.0f); + QCOMPARE(d->vx, 0.f); + QCOMPARE(d->vy, 0.f); + QCOMPARE(d->ax, 0.f); + QCOMPARE(d->ay, 0.f); + QCOMPARE(d->lifeSpan, 0.5f); + QCOMPARE(d->size, 32.f); + QCOMPARE(d->endSize, 32.f); + QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); + } +} + +QTEST_MAIN(tst_qquickmaskextruder); + +#include "tst_qquickmaskextruder.moc" diff --git a/tests/auto/particles/qquickparticlegroup/data/basic.qml b/tests/auto/particles/qquickparticlegroup/data/basic.qml new file mode 100644 index 0000000000..97dadd7461 --- /dev/null +++ b/tests/auto/particles/qquickparticlegroup/data/basic.qml @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** 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 test suite 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$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtQuick.Particles 2.0 + +Rectangle { + color: "black" + width: 320 + height: 320 + + ParticleSystem { + id: sys + objectName: "system" + anchors.fill: parent + + ImageParticle { + source: "../../shared/star.png" + } + + ParticleGroup { + name: "notdefault" + duration: 0 + to: {"":1} + } + + Emitter{ + //0,0 position + group: "notdefault" + size: 32 + emitRate: 1000 + lifeSpan: 500 + } + } +} diff --git a/tests/auto/particles/qquickparticlegroup/qquickparticlegroup.pro b/tests/auto/particles/qquickparticlegroup/qquickparticlegroup.pro new file mode 100644 index 0000000000..b100ffaf75 --- /dev/null +++ b/tests/auto/particles/qquickparticlegroup/qquickparticlegroup.pro @@ -0,0 +1,11 @@ +CONFIG += testcase +TARGET = tst_qquickparticlegroup +SOURCES += tst_qquickparticlegroup.cpp +macx:CONFIG -= app_bundle + +testDataFiles.files = data +testDataFiles.path = . +DEPLOYMENT += testDataFiles + +QT += core-private gui-private v8-private declarative-private opengl-private testlib + diff --git a/tests/auto/particles/qquickparticlegroup/tst_qquickparticlegroup.cpp b/tests/auto/particles/qquickparticlegroup/tst_qquickparticlegroup.cpp new file mode 100644 index 0000000000..c3b155aa68 --- /dev/null +++ b/tests/auto/particles/qquickparticlegroup/tst_qquickparticlegroup.cpp @@ -0,0 +1,89 @@ +/**************************************************************************** +** +** 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 test suite 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 +#include "../shared/particlestestsshared.h" +#include +#include + +class tst_qquickparticlegroup : public QObject +{ + Q_OBJECT +public: + tst_qquickparticlegroup(); + +private slots: + void test_instantTransition(); +}; + +tst_qquickparticlegroup::tst_qquickparticlegroup() +{ + QUnifiedTimer::instance()->setConsistentTiming(true); +} + +void tst_qquickparticlegroup::test_instantTransition() +{ + QQuickView* view = createView(QCoreApplication::applicationDirPath() + "/data/basic.qml", 600); + QQuickParticleSystem* system = view->rootObject()->findChild("system"); + ensureAnimTime(600, system->m_animation); + + //A frame or two worth of particles will be missed, the transition doesn't take effect on the frame it's spawned (QTBUG-21781) + QVERIFY(system->groupData[0]->size() <= 500 && system->groupData[0]->size() >= 450); + foreach (QQuickParticleData *d, system->groupData[0]->data) { + if (d->t == -1) + continue; //Particle data unused + + QCOMPARE(d->x, 0.f); + QCOMPARE(d->y, 0.f); + QCOMPARE(d->vx, 0.f); + QCOMPARE(d->vy, 0.f); + QCOMPARE(d->ax, 0.f); + QCOMPARE(d->ay, 0.f); + QCOMPARE(d->lifeSpan, 0.5f); + QCOMPARE(d->size, 32.f); + QCOMPARE(d->endSize, 32.f); + QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); + } +} + +QTEST_MAIN(tst_qquickparticlegroup); + +#include "tst_qquickparticlegroup.moc" diff --git a/tests/auto/particles/qquickparticlesystem/data/basic.qml b/tests/auto/particles/qquickparticlesystem/data/basic.qml new file mode 100644 index 0000000000..f5ef4c16c0 --- /dev/null +++ b/tests/auto/particles/qquickparticlesystem/data/basic.qml @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** 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 test suite 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$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtQuick.Particles 2.0 + +Rectangle { + color: "black" + width: 320 + height: 320 + + ParticleSystem { + id: sys + objectName: "system" + anchors.fill: parent + + ImageParticle { + source: "../../shared/star.png" + } + + Emitter{ + //0,0 position + size: 32 + emitRate: 1000 + lifeSpan: 500 + } + } +} diff --git a/tests/auto/particles/qquickparticlesystem/qquickparticlesystem.pro b/tests/auto/particles/qquickparticlesystem/qquickparticlesystem.pro new file mode 100644 index 0000000000..65472e23f9 --- /dev/null +++ b/tests/auto/particles/qquickparticlesystem/qquickparticlesystem.pro @@ -0,0 +1,11 @@ +CONFIG += testcase +TARGET = tst_qquickparticlesystem +SOURCES += tst_qquickparticlesystem.cpp +macx:CONFIG -= app_bundle + +testDataFiles.files = data +testDataFiles.path = . +DEPLOYMENT += testDataFiles + +QT += core-private gui-private v8-private declarative-private opengl-private testlib + diff --git a/tests/auto/particles/qquickparticlesystem/tst_qquickparticlesystem.cpp b/tests/auto/particles/qquickparticlesystem/tst_qquickparticlesystem.cpp new file mode 100644 index 0000000000..b85c57da0b --- /dev/null +++ b/tests/auto/particles/qquickparticlesystem/tst_qquickparticlesystem.cpp @@ -0,0 +1,92 @@ +/**************************************************************************** +** +** 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 test suite 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 +#include "../shared/particlestestsshared.h" +#include +#include + +class tst_qquickparticlesystem : public QObject +{ + Q_OBJECT +public: + tst_qquickparticlesystem(); + +private slots: + void test_basic(); +}; + +tst_qquickparticlesystem::tst_qquickparticlesystem() +{ + QUnifiedTimer::instance()->setConsistentTiming(true); +} + +void tst_qquickparticlesystem::test_basic() +{ + QQuickView* view = createView(QCoreApplication::applicationDirPath() + "/data/basic.qml", 600); + QQuickParticleSystem* system = view->rootObject()->findChild("system"); + ensureAnimTime(600, system->m_animation); + + QCOMPARE(system->groupData[0]->size(), 500); + int stillAlive = 0; + foreach (QQuickParticleData *d, system->groupData[0]->data) { + if (d->t == -1) + continue; //Particle data unused + + if (d->stillAlive()) + stillAlive++; + QCOMPARE(d->x, 0.f); + QCOMPARE(d->y, 0.f); + QCOMPARE(d->vx, 0.f); + QCOMPARE(d->vy, 0.f); + QCOMPARE(d->ax, 0.f); + QCOMPARE(d->ay, 0.f); + QCOMPARE(d->lifeSpan, 0.5f); + QCOMPARE(d->size, 32.f); + QCOMPARE(d->endSize, 32.f); + QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); + } + QVERIFY(extremelyFuzzyCompare(stillAlive, 500, 5));//Small simulation variance is permissible. +} + +QTEST_MAIN(tst_qquickparticlesystem); + +#include "tst_qquickparticlesystem.moc" diff --git a/tests/auto/particles/qquickpointattractor/data/basic.qml b/tests/auto/particles/qquickpointattractor/data/basic.qml new file mode 100644 index 0000000000..86861a9cf2 --- /dev/null +++ b/tests/auto/particles/qquickpointattractor/data/basic.qml @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** 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 test suite 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$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtQuick.Particles 2.0 + +Rectangle { + color: "black" + width: 320 + height: 320 + + ParticleSystem { + id: sys + objectName: "system" + anchors.fill: parent + + ImageParticle { + source: "../../shared/star.png" + } + + Attractor { + anchors.centerIn: parent + proportionalToDistance: Attractor.Constant + affectedParameter: Attractor.Position + strength: 100 + } + + Emitter{ + //0,0 position + size: 32 + emitRate: 1000 + lifeSpan: 500 + } + } +} diff --git a/tests/auto/particles/qquickpointattractor/qquickpointattractor.pro b/tests/auto/particles/qquickpointattractor/qquickpointattractor.pro new file mode 100644 index 0000000000..13b512791a --- /dev/null +++ b/tests/auto/particles/qquickpointattractor/qquickpointattractor.pro @@ -0,0 +1,11 @@ +CONFIG += testcase +TARGET = tst_qquickpointattractor +SOURCES += tst_qquickpointattractor.cpp +macx:CONFIG -= app_bundle + +testDataFiles.files = data +testDataFiles.path = . +DEPLOYMENT += testDataFiles + +QT += core-private gui-private v8-private declarative-private opengl-private testlib + diff --git a/tests/auto/particles/qquickpointattractor/tst_qquickpointattractor.cpp b/tests/auto/particles/qquickpointattractor/tst_qquickpointattractor.cpp new file mode 100644 index 0000000000..6a64f919c0 --- /dev/null +++ b/tests/auto/particles/qquickpointattractor/tst_qquickpointattractor.cpp @@ -0,0 +1,89 @@ +/**************************************************************************** +** +** 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 test suite 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 +#include "../shared/particlestestsshared.h" +#include +#include + +class tst_qquickpointattractor : public QObject +{ + Q_OBJECT +public: + tst_qquickpointattractor(); + +private slots: + void test_basic(); +}; + +tst_qquickpointattractor::tst_qquickpointattractor() +{ + QUnifiedTimer::instance()->setConsistentTiming(true); +} + +void tst_qquickpointattractor::test_basic() +{ + QQuickView* view = createView(QCoreApplication::applicationDirPath() + "/data/basic.qml", 600); + QQuickParticleSystem* system = view->rootObject()->findChild("system"); + ensureAnimTime(600, system->m_animation); + + QCOMPARE(system->groupData[0]->size(), 500); + foreach (QQuickParticleData *d, system->groupData[0]->data) { + if (d->t == -1) + continue; //Particle data unused + + QVERIFY(d->x != 0.f); + QVERIFY(d->y != 0.f); + QVERIFY(d->x == d->y); + QCOMPARE(d->vx, 0.f); + QCOMPARE(d->vy, 0.f); + QCOMPARE(d->ax, 0.f); + QCOMPARE(d->ay, 0.f); + QCOMPARE(d->lifeSpan, 0.5f); + QCOMPARE(d->size, 32.f); + QCOMPARE(d->endSize, 32.f); + QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); + } +} + +QTEST_MAIN(tst_qquickpointattractor); + +#include "tst_qquickpointattractor.moc" diff --git a/tests/auto/particles/qquickpointdirection/data/basic.qml b/tests/auto/particles/qquickpointdirection/data/basic.qml new file mode 100644 index 0000000000..60c2a3e37b --- /dev/null +++ b/tests/auto/particles/qquickpointdirection/data/basic.qml @@ -0,0 +1,68 @@ +/**************************************************************************** +** +** 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 test suite 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$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtQuick.Particles 2.0 + +Rectangle { + color: "black" + width: 320 + height: 320 + + ParticleSystem { + id: sys + objectName: "system" + anchors.fill: parent + + ImageParticle { + source: "../../shared/star.png" + } + + Emitter{ + //0,0 position + size: 32 + speed: PointDirection{ x: 100; y: 100 } + acceleration: PointDirection{ x: 100; xVariation: 100; y: 100; yVariation: 100 } + emitRate: 1000 + lifeSpan: 500 + } + } +} diff --git a/tests/auto/particles/qquickpointdirection/qquickpointdirection.pro b/tests/auto/particles/qquickpointdirection/qquickpointdirection.pro new file mode 100644 index 0000000000..6adab3d75d --- /dev/null +++ b/tests/auto/particles/qquickpointdirection/qquickpointdirection.pro @@ -0,0 +1,11 @@ +CONFIG += testcase +TARGET = tst_qquickpointdirection +SOURCES += tst_qquickpointdirection.cpp +macx:CONFIG -= app_bundle + +testDataFiles.files = data +testDataFiles.path = . +DEPLOYMENT += testDataFiles + +QT += core-private gui-private v8-private declarative-private opengl-private testlib + diff --git a/tests/auto/particles/qquickpointdirection/tst_qquickpointdirection.cpp b/tests/auto/particles/qquickpointdirection/tst_qquickpointdirection.cpp new file mode 100644 index 0000000000..19cc471126 --- /dev/null +++ b/tests/auto/particles/qquickpointdirection/tst_qquickpointdirection.cpp @@ -0,0 +1,90 @@ +/**************************************************************************** +** +** 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 test suite 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 +#include "../shared/particlestestsshared.h" +#include +#include + +class tst_qquickpointdirection : public QObject +{ + Q_OBJECT +public: + tst_qquickpointdirection(); + +private slots: + void test_basic(); +}; + +tst_qquickpointdirection::tst_qquickpointdirection() +{ + QUnifiedTimer::instance()->setConsistentTiming(true); +} + +void tst_qquickpointdirection::test_basic() +{ + QQuickView* view = createView(QCoreApplication::applicationDirPath() + "/data/basic.qml", 600); + QQuickParticleSystem* system = view->rootObject()->findChild("system"); + ensureAnimTime(600, system->m_animation); + + QCOMPARE(system->groupData[0]->size(), 500); + foreach (QQuickParticleData *d, system->groupData[0]->data) { + if (d->t == -1) + continue; //Particle data unused + + QCOMPARE(d->x, 0.f); + QCOMPARE(d->y, 0.f); + QCOMPARE(d->vx, 100.f); + QCOMPARE(d->vy, 100.f); + QVERIFY(d->ax >= 0.f); + QVERIFY(d->ax <= 200.f); + QVERIFY(d->ay >= 0.f); + QVERIFY(d->ay <= 200.f); + QCOMPARE(d->lifeSpan, 0.5f); + QCOMPARE(d->size, 32.f); + QCOMPARE(d->endSize, 32.f); + QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); + } +} + +QTEST_MAIN(tst_qquickpointdirection); + +#include "tst_qquickpointdirection.moc" diff --git a/tests/auto/particles/qquickrectangleextruder/data/basic.qml b/tests/auto/particles/qquickrectangleextruder/data/basic.qml new file mode 100644 index 0000000000..a66827ed90 --- /dev/null +++ b/tests/auto/particles/qquickrectangleextruder/data/basic.qml @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** 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 test suite 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$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtQuick.Particles 2.0 + +Rectangle { + color: "black" + width: 320 + height: 320 + + ParticleSystem { + id: sys + objectName: "system" + anchors.fill: parent + + ImageParticle { + groups: ["", "notdefault"] + source: "../../shared/star.png" + } + + Emitter{ + width: 100 + height: 100 + size: 32 + shape: RectangleShape{} + emitRate: 1000 + lifeSpan: 500 + } + Emitter{ + width: 100 + height: 100 + group: "notdefault" + size: 32 + shape: RectangleShape{fill: false} + emitRate: 1000 + lifeSpan: 500 + } + } +} diff --git a/tests/auto/particles/qquickrectangleextruder/qquickrectangleextruder.pro b/tests/auto/particles/qquickrectangleextruder/qquickrectangleextruder.pro new file mode 100644 index 0000000000..fee29efcf3 --- /dev/null +++ b/tests/auto/particles/qquickrectangleextruder/qquickrectangleextruder.pro @@ -0,0 +1,11 @@ +CONFIG += testcase +TARGET = tst_qquickrectangleextruder +SOURCES += tst_qquickrectangleextruder.cpp +macx:CONFIG -= app_bundle + +testDataFiles.files = data +testDataFiles.path = . +DEPLOYMENT += testDataFiles + +QT += core-private gui-private v8-private declarative-private opengl-private testlib + diff --git a/tests/auto/particles/qquickrectangleextruder/tst_qquickrectangleextruder.cpp b/tests/auto/particles/qquickrectangleextruder/tst_qquickrectangleextruder.cpp new file mode 100644 index 0000000000..6fb2e9cae8 --- /dev/null +++ b/tests/auto/particles/qquickrectangleextruder/tst_qquickrectangleextruder.cpp @@ -0,0 +1,113 @@ +/**************************************************************************** +** +** 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 test suite 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 +#include "../shared/particlestestsshared.h" +#include +#include + +class tst_qquickrectangleextruder : public QObject +{ + Q_OBJECT +public: + tst_qquickrectangleextruder(); + +private slots: + void test_basic(); +}; + +tst_qquickrectangleextruder::tst_qquickrectangleextruder() +{ + QUnifiedTimer::instance()->setConsistentTiming(true); +} + +void tst_qquickrectangleextruder::test_basic() +{ + QQuickView* view = createView(QCoreApplication::applicationDirPath() + "/data/basic.qml", 600); + QQuickParticleSystem* system = view->rootObject()->findChild("system"); + ensureAnimTime(600, system->m_animation); + + QCOMPARE(system->groupData[0]->size(), 500); + foreach (QQuickParticleData *d, system->groupData[0]->data) { + if (d->t == -1) + continue; //Particle data unused + + QVERIFY(d->x >= 0.f); + QVERIFY(d->x <= 100.f); + QVERIFY(d->y >= 0.f); + QVERIFY(d->y <= 100.f); + QCOMPARE(d->vx, 0.f); + QCOMPARE(d->vy, 0.f); + QCOMPARE(d->ax, 0.f); + QCOMPARE(d->ay, 0.f); + QCOMPARE(d->lifeSpan, 0.5f); + QCOMPARE(d->size, 32.f); + QCOMPARE(d->endSize, 32.f); + QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); + } + + QCOMPARE(system->groupData[1]->size(), 500); + foreach (QQuickParticleData *d, system->groupData[1]->data) { + if (d->t == -1) + continue; //Particle data unused + + if (!myFuzzyCompare(d->x, 0.f) && !myFuzzyCompare(d->x, 100.f)){ + QVERIFY(d->x >= 0.f); + QVERIFY(d->x <= 100.f); + QVERIFY(myFuzzyCompare(d->y, 0.f) || myFuzzyCompare(d->y, 100.f)); + } else { + QVERIFY(d->y >= 0.f); + QVERIFY(d->y <= 100.f); + } + QCOMPARE(d->vx, 0.f); + QCOMPARE(d->vy, 0.f); + QCOMPARE(d->ax, 0.f); + QCOMPARE(d->ay, 0.f); + QCOMPARE(d->lifeSpan, 0.5f); + QCOMPARE(d->size, 32.f); + QCOMPARE(d->endSize, 32.f); + QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); + } +} + +QTEST_MAIN(tst_qquickrectangleextruder); + +#include "tst_qquickrectangleextruder.moc" diff --git a/tests/auto/particles/qquicktargetdirection/data/basic.qml b/tests/auto/particles/qquicktargetdirection/data/basic.qml new file mode 100644 index 0000000000..a8caea4641 --- /dev/null +++ b/tests/auto/particles/qquicktargetdirection/data/basic.qml @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** 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 test suite 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$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtQuick.Particles 2.0 + +Rectangle { + color: "black" + width: 320 + height: 320 + + ParticleSystem { + id: sys + objectName: "system" + anchors.fill: parent + + ImageParticle { + source: "../../shared/star.png" + } + + Emitter{ + //0,0 position + speed: TargetDirection{ targetItem: sys; proportionalMagnitude: true; magnitude: 1 } + size: 32 + emitRate: 1000 + lifeSpan: 500 + } + } +} diff --git a/tests/auto/particles/qquicktargetdirection/qquicktargetdirection.pro b/tests/auto/particles/qquicktargetdirection/qquicktargetdirection.pro new file mode 100644 index 0000000000..0de6007283 --- /dev/null +++ b/tests/auto/particles/qquicktargetdirection/qquicktargetdirection.pro @@ -0,0 +1,11 @@ +CONFIG += testcase +TARGET = tst_qquicktargetdirection +SOURCES += tst_qquicktargetdirection.cpp +macx:CONFIG -= app_bundle + +testDataFiles.files = data +testDataFiles.path = . +DEPLOYMENT += testDataFiles + +QT += core-private gui-private v8-private declarative-private opengl-private testlib + diff --git a/tests/auto/particles/qquicktargetdirection/tst_qquicktargetdirection.cpp b/tests/auto/particles/qquicktargetdirection/tst_qquicktargetdirection.cpp new file mode 100644 index 0000000000..7d83ae8830 --- /dev/null +++ b/tests/auto/particles/qquicktargetdirection/tst_qquicktargetdirection.cpp @@ -0,0 +1,88 @@ +/**************************************************************************** +** +** 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 test suite 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 +#include "../shared/particlestestsshared.h" +#include +#include + +class tst_qquicktargetdirection : public QObject +{ + Q_OBJECT +public: + tst_qquicktargetdirection(); + +private slots: + void test_basic(); +}; + +tst_qquicktargetdirection::tst_qquicktargetdirection() +{ + QUnifiedTimer::instance()->setConsistentTiming(true); +} + +void tst_qquicktargetdirection::test_basic() +{ + QQuickView* view = createView(QCoreApplication::applicationDirPath() + "/data/basic.qml", 600); + QQuickParticleSystem* system = view->rootObject()->findChild("system"); + ensureAnimTime(600, system->m_animation); + + QCOMPARE(system->groupData[0]->size(), 500); + foreach (QQuickParticleData *d, system->groupData[0]->data) { + if (d->t == -1) + continue; //Particle data unused + + QCOMPARE(d->x, 0.f); + QCOMPARE(d->y, 0.f); + QCOMPARE(d->vx, 160.f); + QCOMPARE(d->vy, 160.f); + QCOMPARE(d->ax, 0.f); + QCOMPARE(d->ay, 0.f); + QCOMPARE(d->lifeSpan, 0.5f); + QCOMPARE(d->size, 32.f); + QCOMPARE(d->endSize, 32.f); + QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); + } +} + +QTEST_MAIN(tst_qquicktargetdirection); + +#include "tst_qquicktargetdirection.moc" diff --git a/tests/auto/particles/qquicktrailemitter/data/basic.qml b/tests/auto/particles/qquicktrailemitter/data/basic.qml new file mode 100644 index 0000000000..538d14f1d5 --- /dev/null +++ b/tests/auto/particles/qquicktrailemitter/data/basic.qml @@ -0,0 +1,77 @@ +/**************************************************************************** +** +** 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 test suite 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$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtQuick.Particles 2.0 + +Rectangle { + color: "black" + width: 320 + height: 320 + + ParticleSystem { + id: sys + objectName: "system" + anchors.fill: parent + + ImageParticle { + groups: ["","notdefault"] + source: "../../shared/star.png" + } + + + TrailEmitter { + group: "notdefault" + follow: "" + size: 32 + emitRatePerParticle: 2 + lifeSpan: 500 + speed: PointDirection{ x: 500; y: 500 } + } + Emitter{ + x: 4 + y: 4 + size: 32 + emitRate: 1000 + lifeSpan: 500 + } + } +} diff --git a/tests/auto/particles/qquicktrailemitter/qquicktrailemitter.pro b/tests/auto/particles/qquicktrailemitter/qquicktrailemitter.pro new file mode 100644 index 0000000000..7b8075d625 --- /dev/null +++ b/tests/auto/particles/qquicktrailemitter/qquicktrailemitter.pro @@ -0,0 +1,11 @@ +CONFIG += testcase +TARGET = tst_qquicktrailemitter +SOURCES += tst_qquicktrailemitter.cpp +macx:CONFIG -= app_bundle + +testDataFiles.files = data +testDataFiles.path = . +DEPLOYMENT += testDataFiles + +QT += core-private gui-private v8-private declarative-private opengl-private testlib + diff --git a/tests/auto/particles/qquicktrailemitter/tst_qquicktrailemitter.cpp b/tests/auto/particles/qquicktrailemitter/tst_qquicktrailemitter.cpp new file mode 100644 index 0000000000..6325ca6efe --- /dev/null +++ b/tests/auto/particles/qquicktrailemitter/tst_qquicktrailemitter.cpp @@ -0,0 +1,105 @@ +/**************************************************************************** +** +** 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 test suite 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 +#include "../shared/particlestestsshared.h" +#include +#include + +class tst_qquicktrailemitter : public QObject +{ + Q_OBJECT +public: + tst_qquicktrailemitter(); + +private slots: + void test_basic(); +}; + +tst_qquicktrailemitter::tst_qquicktrailemitter() +{ + QUnifiedTimer::instance()->setConsistentTiming(true); +} + +void tst_qquicktrailemitter::test_basic() +{ + QQuickView* view = createView(QCoreApplication::applicationDirPath() + "/data/basic.qml", 600); + QQuickParticleSystem* system = view->rootObject()->findChild("system"); + ensureAnimTime(600, system->m_animation); + + QCOMPARE(system->groupData[0]->size(), 500); + foreach (QQuickParticleData *d, system->groupData[0]->data) { + if (d->t == -1) + continue; //Particle data unused + + QCOMPARE(d->x, 4.f); + QCOMPARE(d->y, 4.f); + QCOMPARE(d->vx, 0.f); + QCOMPARE(d->vy, 0.f); + QCOMPARE(d->ax, 0.f); + QCOMPARE(d->ay, 0.f); + QCOMPARE(d->lifeSpan, 0.5f); + QCOMPARE(d->size, 32.f); + QCOMPARE(d->endSize, 32.f); + QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); + } + + QCOMPARE(system->groupData[1]->size(), 500); + foreach (QQuickParticleData *d, system->groupData[1]->data) { + if (d->t == -1) + continue; //Particle data unused + + QCOMPARE(d->x, 4.f); + QCOMPARE(d->y, 4.f); + QCOMPARE(d->vx, 500.f); + QCOMPARE(d->vy, 500.f); + QCOMPARE(d->ax, 0.f); + QCOMPARE(d->ay, 0.f); + QCOMPARE(d->lifeSpan, 0.5f); + QCOMPARE(d->size, 32.f); + QCOMPARE(d->endSize, 32.f); + QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); + } +} + +QTEST_MAIN(tst_qquicktrailemitter); + +#include "tst_qquicktrailemitter.moc" diff --git a/tests/auto/particles/qquickturbulence/data/basic.qml b/tests/auto/particles/qquickturbulence/data/basic.qml new file mode 100644 index 0000000000..42b5cd6a97 --- /dev/null +++ b/tests/auto/particles/qquickturbulence/data/basic.qml @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** 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 test suite 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$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtQuick.Particles 2.0 + +Rectangle { + color: "black" + width: 320 + height: 320 + + ParticleSystem { + id: sys + objectName: "system" + anchors.fill: parent + + ImageParticle { + source: "../../shared/star.png" + } + + Turbulence { + anchors.fill: parent + strength: 1000 + } + + Emitter{ + //100,100 position + x: 100 + y: 100 + size: 32 + emitRate: 1000 + lifeSpan: 500 + } + } +} diff --git a/tests/auto/particles/qquickturbulence/qquickturbulence.pro b/tests/auto/particles/qquickturbulence/qquickturbulence.pro new file mode 100644 index 0000000000..405e8a6f2a --- /dev/null +++ b/tests/auto/particles/qquickturbulence/qquickturbulence.pro @@ -0,0 +1,11 @@ +CONFIG += testcase +TARGET = tst_qquickturbulence +SOURCES += tst_qquickturbulence.cpp +macx:CONFIG -= app_bundle + +testDataFiles.files = data +testDataFiles.path = . +DEPLOYMENT += testDataFiles + +QT += core-private gui-private v8-private declarative-private opengl-private testlib + diff --git a/tests/auto/particles/qquickturbulence/tst_qquickturbulence.cpp b/tests/auto/particles/qquickturbulence/tst_qquickturbulence.cpp new file mode 100644 index 0000000000..29faec2381 --- /dev/null +++ b/tests/auto/particles/qquickturbulence/tst_qquickturbulence.cpp @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** 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 test suite 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 +#include "../shared/particlestestsshared.h" +#include +#include + +class tst_qquickturbulence : public QObject +{ + Q_OBJECT +public: + tst_qquickturbulence(); + +private slots: + void test_basic(); +}; + +tst_qquickturbulence::tst_qquickturbulence() +{ + QUnifiedTimer::instance()->setConsistentTiming(true); +} + +void tst_qquickturbulence::test_basic() +{ + QQuickView* view = createView(QCoreApplication::applicationDirPath() + "/data/basic.qml", 600); + QQuickParticleSystem* system = view->rootObject()->findChild("system"); + ensureAnimTime(600, system->m_animation); + + //Note that the noise image built-in provides the 'randomness', so this test should be stable so long as it and the size + //of the Turbulence item remain the same + QCOMPARE(system->groupData[0]->size(), 500); + foreach (QQuickParticleData *d, system->groupData[0]->data) { + if (d->t == -1) + continue; //Particle data unused + + QVERIFY(d->vx != 0.f); + QVERIFY(d->vy != 0.f); + QCOMPARE(d->lifeSpan, 0.5f); + QCOMPARE(d->size, 32.f); + QCOMPARE(d->endSize, 32.f); + QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); + } +} + +QTEST_MAIN(tst_qquickturbulence); + +#include "tst_qquickturbulence.moc" diff --git a/tests/auto/particles/qquickwander/data/basic.qml b/tests/auto/particles/qquickwander/data/basic.qml new file mode 100644 index 0000000000..ebb4bd963a --- /dev/null +++ b/tests/auto/particles/qquickwander/data/basic.qml @@ -0,0 +1,72 @@ +/**************************************************************************** +** +** 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 test suite 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$ +** +****************************************************************************/ + +import QtQuick 2.0 +import QtQuick.Particles 2.0 + +Rectangle { + color: "black" + width: 320 + height: 320 + + ParticleSystem { + id: sys + objectName: "system" + anchors.fill: parent + + ImageParticle { + source: "../../shared/star.png" + } + + Wander { + pace: 400 + xVariance: 100 + yVariance: 100 + } + + Emitter{ + //0,0 position + size: 32 + emitRate: 1000 + lifeSpan: 500 + } + } +} diff --git a/tests/auto/particles/qquickwander/qquickwander.pro b/tests/auto/particles/qquickwander/qquickwander.pro new file mode 100644 index 0000000000..cf6f08e2dc --- /dev/null +++ b/tests/auto/particles/qquickwander/qquickwander.pro @@ -0,0 +1,11 @@ +CONFIG += testcase +TARGET = tst_qquickwander +SOURCES += tst_qquickwander.cpp +macx:CONFIG -= app_bundle + +testDataFiles.files = data +testDataFiles.path = . +DEPLOYMENT += testDataFiles + +QT += core-private gui-private v8-private declarative-private opengl-private testlib + diff --git a/tests/auto/particles/qquickwander/tst_qquickwander.cpp b/tests/auto/particles/qquickwander/tst_qquickwander.cpp new file mode 100644 index 0000000000..41f09d4993 --- /dev/null +++ b/tests/auto/particles/qquickwander/tst_qquickwander.cpp @@ -0,0 +1,94 @@ +/**************************************************************************** +** +** 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 test suite 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 +#include "../shared/particlestestsshared.h" +#include +#include + +class tst_qquickwander : public QObject +{ + Q_OBJECT +public: + tst_qquickwander(); + +private slots: + void test_basic(); +}; + +tst_qquickwander::tst_qquickwander() +{ + QUnifiedTimer::instance()->setConsistentTiming(true); +} + +void tst_qquickwander::test_basic() +{ + QQuickView* view = createView(QCoreApplication::applicationDirPath() + "/data/basic.qml", 600); + QQuickParticleSystem* system = view->rootObject()->findChild("system"); + ensureAnimTime(600, system->m_animation); + + QCOMPARE(system->groupData[0]->size(), 500); + //Since Wander is random perturbations, the compromise between stability and actual testing is to hope that one of + //the 500 was randomly changed from 0.0 in velocity + bool vxChanged = false; + bool vyChanged = false; + foreach (QQuickParticleData *d, system->groupData[0]->data) { + if (d->t == -1) + continue; //Particle data unused + + QCOMPARE(d->ax, 0.f); + QCOMPARE(d->ay, 0.f); + QCOMPARE(d->lifeSpan, 0.5f); + QCOMPARE(d->size, 32.f); + QCOMPARE(d->endSize, 32.f); + QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); + if (d->vx != 0.0f) + vxChanged = true; + if (d->vy != 0.0f) + vyChanged = true; + } + QVERIFY(vxChanged); + QVERIFY(vyChanged); +} + +QTEST_MAIN(tst_qquickwander); + +#include "tst_qquickwander.moc" diff --git a/tests/auto/particles/qsgage/data/jump.qml b/tests/auto/particles/qsgage/data/jump.qml deleted file mode 100644 index e66f9f4950..0000000000 --- a/tests/auto/particles/qsgage/data/jump.qml +++ /dev/null @@ -1,70 +0,0 @@ -/**************************************************************************** -** -** 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 test suite 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$ -** -****************************************************************************/ - -import QtQuick 2.0 -import QtQuick.Particles 2.0 - -Rectangle { - color: "black" - width: 320 - height: 320 - - ParticleSystem { - id: sys - objectName: "system" - anchors.fill: parent - - Age { - once: true - advancePosition: false - lifeLeft: 100 - } - - ImageParticle { source: "../../shared/star.png" } - Emitter { - //0,0 position - size: 32 - emitRate: 1000 - lifeSpan: 500 - speed: PointDirection{ x: 500; y: 500 } - } - } -} diff --git a/tests/auto/particles/qsgage/data/kill.qml b/tests/auto/particles/qsgage/data/kill.qml deleted file mode 100644 index 2558435e60..0000000000 --- a/tests/auto/particles/qsgage/data/kill.qml +++ /dev/null @@ -1,66 +0,0 @@ -/**************************************************************************** -** -** 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 test suite 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$ -** -****************************************************************************/ - -import QtQuick 2.0 -import QtQuick.Particles 2.0 - -Rectangle { - color: "black" - width: 320 - height: 320 - - ParticleSystem { - id: sys - objectName: "system" - anchors.fill: parent - - Age {} - - ImageParticle { source: "../../shared/star.png" } - Emitter{ - //0,0 position - size: 32 - emitRate: 1000 - lifeSpan: 500 - speed: PointDirection{ x: 1000; y: 1000 } - } - } -} diff --git a/tests/auto/particles/qsgage/data/onceoff.qml b/tests/auto/particles/qsgage/data/onceoff.qml deleted file mode 100644 index 15d0e123b4..0000000000 --- a/tests/auto/particles/qsgage/data/onceoff.qml +++ /dev/null @@ -1,69 +0,0 @@ -/**************************************************************************** -** -** 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 test suite 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$ -** -****************************************************************************/ - -import QtQuick 2.0 -import QtQuick.Particles 2.0 - -Rectangle { - color: "black" - width: 320 - height: 320 - - ParticleSystem { - id: sys - objectName: "system" - anchors.fill: parent - - Age { - once: true - lifeLeft: 100 - } - - ImageParticle { source: "../../shared/star.png" } - Emitter{ - //0,0 position - size: 32 - emitRate: 1000 - lifeSpan: 500 - speed: PointDirection{ x: 500; y: 500 } - } - } -} diff --git a/tests/auto/particles/qsgage/data/sustained.qml b/tests/auto/particles/qsgage/data/sustained.qml deleted file mode 100644 index 96aefec3dc..0000000000 --- a/tests/auto/particles/qsgage/data/sustained.qml +++ /dev/null @@ -1,69 +0,0 @@ -/**************************************************************************** -** -** 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 test suite 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$ -** -****************************************************************************/ - -import QtQuick 2.0 -import QtQuick.Particles 2.0 - -Rectangle { - color: "black" - width: 320 - height: 320 - - ParticleSystem { - id: sys - objectName: "system" - anchors.fill: parent - - Age { - once: false - lifeLeft: 100 - } - - ImageParticle { source: "../../shared/star.png" } - Emitter{ - //0,0 position - size: 32 - emitRate: 1000 - lifeSpan: 500 - speed: PointDirection{ x: 500; y: 500 } - } - } -} diff --git a/tests/auto/particles/qsgage/qsgage.pro b/tests/auto/particles/qsgage/qsgage.pro deleted file mode 100644 index e4904c8691..0000000000 --- a/tests/auto/particles/qsgage/qsgage.pro +++ /dev/null @@ -1,13 +0,0 @@ -CONFIG += testcase -TARGET = tst_qsgage -SOURCES += tst_qsgage.cpp -macx:CONFIG -= app_bundle - -testDataFiles.files = data -testDataFiles.path = . -DEPLOYMENT += testDataFiles - -CONFIG += insignificant_test - -QT += core-private gui-private v8-private declarative-private opengl-private testlib - diff --git a/tests/auto/particles/qsgage/tst_qsgage.cpp b/tests/auto/particles/qsgage/tst_qsgage.cpp deleted file mode 100644 index 7dc3e6ae60..0000000000 --- a/tests/auto/particles/qsgage/tst_qsgage.cpp +++ /dev/null @@ -1,165 +0,0 @@ -/**************************************************************************** -** -** 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 test suite 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 -#include "../shared/particlestestsshared.h" -#include -#include - -class tst_qsgage : public QObject -{ - Q_OBJECT -public: - tst_qsgage(); - -private slots: - void test_kill(); - void test_jump(); - void test_onceOff(); - void test_sustained(); -}; - -tst_qsgage::tst_qsgage() -{ - QUnifiedTimer::instance()->setConsistentTiming(true); -} - -void tst_qsgage::test_kill() -{ - QQuickView* view = createView(QCoreApplication::applicationDirPath() + "/data/kill.qml", 600); - QSGParticleSystem* system = view->rootObject()->findChild("system"); - ensureAnimTime(600, system->m_animation); - - QCOMPARE(system->groupData[0]->size(), 500); - foreach (QSGParticleData *d, system->groupData[0]->data) { - if (d->t == -1) - continue; //Particle data unused - - QCOMPARE(d->x, 0.f); - QCOMPARE(d->y, 0.f); - QCOMPARE(d->vx, 1000.f); - QCOMPARE(d->vy, 1000.f); - QCOMPARE(d->ax, 0.f); - QCOMPARE(d->ay, 0.f); - QCOMPARE(d->lifeSpan, 0.5f); - QCOMPARE(d->size, 32.f); - QCOMPARE(d->endSize, 32.f); - QVERIFY(d->t <= ((qreal)system->timeInt/1000.0) - 0.5f + EPSILON); - } -} - -void tst_qsgage::test_jump() -{ - QQuickView* view = createView(QCoreApplication::applicationDirPath() + "/data/jump.qml", 600); - QSGParticleSystem* system = view->rootObject()->findChild("system"); - ensureAnimTime(600, system->m_animation); - - QCOMPARE(system->groupData[0]->size(), 500); - foreach (QSGParticleData *d, system->groupData[0]->data) { - if (d->t == -1) - continue; //Particle data unused - - //Allow for a small variance because jump is trying to simulate off wall time - extremelyFuzzyCompare(d->x, -100.f, 5.0f); - extremelyFuzzyCompare(d->y, -100.f, 5.0f); - QCOMPARE(d->vx, 500.f); - QCOMPARE(d->vy, 500.f); - QCOMPARE(d->ax, 0.f); - QCOMPARE(d->ay, 0.f); - QCOMPARE(d->lifeSpan, 0.5f); - QCOMPARE(d->size, 32.f); - QCOMPARE(d->endSize, 32.f); - QVERIFY(d->t <= ((qreal)system->timeInt/1000.0) - 0.4f + EPSILON); - } -} - -void tst_qsgage::test_onceOff() -{ - QQuickView* view = createView(QCoreApplication::applicationDirPath() + "/data/onceoff.qml", 600); - QSGParticleSystem* system = view->rootObject()->findChild("system"); - ensureAnimTime(600, system->m_animation); - - QCOMPARE(system->groupData[0]->size(), 500); - foreach (QSGParticleData *d, system->groupData[0]->data) { - if (d->t == -1) - continue; //Particle data unused - - QCOMPARE(d->x, 0.f); - QCOMPARE(d->y, 0.f); - QCOMPARE(d->vx, 500.f); - QCOMPARE(d->vy, 500.f); - QCOMPARE(d->ax, 0.f); - QCOMPARE(d->ay, 0.f); - QCOMPARE(d->lifeSpan, 0.5f); - QCOMPARE(d->size, 32.f); - QCOMPARE(d->endSize, 32.f); - QVERIFY(d->t <= ((qreal)system->timeInt/1000.0) - 0.4f + EPSILON); - } -} - -void tst_qsgage::test_sustained() -{ - QQuickView* view = createView(QCoreApplication::applicationDirPath() + "/data/sustained.qml", 600); - QSGParticleSystem* system = view->rootObject()->findChild("system"); - ensureAnimTime(600, system->m_animation); - //TODO: Ensure some particles have lived to 0.4s point despite unified timer - - QCOMPARE(system->groupData[0]->size(), 500); - foreach (QSGParticleData *d, system->groupData[0]->data) { - if (d->t == -1) - continue; //Particle data unused - - QCOMPARE(d->x, 0.f); - QCOMPARE(d->y, 0.f); - QCOMPARE(d->vx, 500.f); - QCOMPARE(d->vy, 500.f); - QCOMPARE(d->ax, 0.f); - QCOMPARE(d->ay, 0.f); - QCOMPARE(d->lifeSpan, 0.5f); - QCOMPARE(d->size, 32.f); - QCOMPARE(d->endSize, 32.f); - QVERIFY(myFuzzyCompare(d->t, ((qreal)system->timeInt/1000.0) - 0.4f)); - } -} - -QTEST_MAIN(tst_qsgage); - -#include "tst_qsgage.moc" diff --git a/tests/auto/particles/qsgangleddirection/data/basic.qml b/tests/auto/particles/qsgangleddirection/data/basic.qml deleted file mode 100644 index c2fda56561..0000000000 --- a/tests/auto/particles/qsgangleddirection/data/basic.qml +++ /dev/null @@ -1,68 +0,0 @@ -/**************************************************************************** -** -** 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 test suite 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$ -** -****************************************************************************/ - -import QtQuick 2.0 -import QtQuick.Particles 2.0 - -Rectangle { - color: "black" - width: 320 - height: 320 - - ParticleSystem { - id: sys - objectName: "system" - anchors.fill: parent - - ImageParticle { - source: "../../shared/star.png" - } - - Emitter{ - //0,0 position - size: 32 - emitRate: 1000 - lifeSpan: 500 - speed: AngleDirection { angle: 45; magnitude: 500 } - acceleration: AngleDirection { angle: 45; angleVariation: 22; magnitude: 250; magnitudeVariation: 249} - } - } -} diff --git a/tests/auto/particles/qsgangleddirection/qsgangleddirection.pro b/tests/auto/particles/qsgangleddirection/qsgangleddirection.pro deleted file mode 100644 index e8e1e5b9a5..0000000000 --- a/tests/auto/particles/qsgangleddirection/qsgangleddirection.pro +++ /dev/null @@ -1,11 +0,0 @@ -CONFIG += testcase -TARGET = tst_qsgangleddirection -SOURCES += tst_qsgangleddirection.cpp -macx:CONFIG -= app_bundle - -testDataFiles.files = data -testDataFiles.path = . -DEPLOYMENT += testDataFiles - -QT += core-private gui-private v8-private declarative-private opengl-private testlib - diff --git a/tests/auto/particles/qsgangleddirection/tst_qsgangleddirection.cpp b/tests/auto/particles/qsgangleddirection/tst_qsgangleddirection.cpp deleted file mode 100644 index 2957b9ee59..0000000000 --- a/tests/auto/particles/qsgangleddirection/tst_qsgangleddirection.cpp +++ /dev/null @@ -1,92 +0,0 @@ -/**************************************************************************** -** -** 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 test suite 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 -#include -#include "../shared/particlestestsshared.h" -#include -#include - -class tst_qsgangleddirection : public QObject -{ - Q_OBJECT -public: - tst_qsgangleddirection(); - -private slots: - void test_basic(); -}; - -tst_qsgangleddirection::tst_qsgangleddirection() -{ - QUnifiedTimer::instance()->setConsistentTiming(true); -} - -void tst_qsgangleddirection::test_basic() -{ - QQuickView* view = createView(QCoreApplication::applicationDirPath() + "/data/basic.qml", 600); - QSGParticleSystem* system = view->rootObject()->findChild("system"); - ensureAnimTime(600, system->m_animation); - - QCOMPARE(system->groupData[0]->size(), 500); - foreach (QSGParticleData *d, system->groupData[0]->data) { - if (d->t == -1) - continue; //Particle data unused - - QCOMPARE(d->x, 0.f); - QCOMPARE(d->y, 0.f); - QVERIFY(qFuzzyCompare(d->vx, 353.55339f)); - QVERIFY(qFuzzyCompare(d->vy, 353.55339f)); - QVERIFY(d->ax > 0.f); - QVERIFY(d->ax < 500.f); - QVERIFY(d->ay > 0.f); - QVERIFY(d->ay < 500.f); - QVERIFY(qSqrt(d->ax*d->ax + d->ay*d->ay) < 500.f); - QCOMPARE(d->lifeSpan, 0.5f); - QCOMPARE(d->size, 32.f); - QCOMPARE(d->endSize, 32.f); - QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); - } -} - -QTEST_MAIN(tst_qsgangleddirection); - -#include "tst_qsgangleddirection.moc" diff --git a/tests/auto/particles/qsgcumulativedirection/data/basic.qml b/tests/auto/particles/qsgcumulativedirection/data/basic.qml deleted file mode 100644 index bd46c4556f..0000000000 --- a/tests/auto/particles/qsgcumulativedirection/data/basic.qml +++ /dev/null @@ -1,74 +0,0 @@ -/**************************************************************************** -** -** 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 test suite 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$ -** -****************************************************************************/ - -import QtQuick 2.0 -import QtQuick.Particles 2.0 - -Rectangle { - color: "black" - width: 320 - height: 320 - - ParticleSystem { - id: sys - objectName: "system" - anchors.fill: parent - - ImageParticle { - source: "../../shared/star.png" - } - - Emitter{ - //0,0 position - size: 32 - emitRate: 1000 - lifeSpan: 500 - speed: CumulativeDirection { - PointDirection { x: 100; y: -100 } - PointDirection { x: -100; y: 100 } - } - acceleration: CumulativeDirection { - AngleDirection { angle: 0; magnitude: 100 } - AngleDirection { angle: 180; magnitude: 100 } - } - } - } -} diff --git a/tests/auto/particles/qsgcumulativedirection/qsgcumulativedirection.pro b/tests/auto/particles/qsgcumulativedirection/qsgcumulativedirection.pro deleted file mode 100644 index 75933c679f..0000000000 --- a/tests/auto/particles/qsgcumulativedirection/qsgcumulativedirection.pro +++ /dev/null @@ -1,11 +0,0 @@ -CONFIG += testcase -TARGET = tst_qsgcumulativedirection -SOURCES += tst_qsgcumulativedirection.cpp -macx:CONFIG -= app_bundle - -testDataFiles.files = data -testDataFiles.path = . -DEPLOYMENT += testDataFiles - -QT += core-private gui-private v8-private declarative-private opengl-private testlib - diff --git a/tests/auto/particles/qsgcumulativedirection/tst_qsgcumulativedirection.cpp b/tests/auto/particles/qsgcumulativedirection/tst_qsgcumulativedirection.cpp deleted file mode 100644 index 0a21949aed..0000000000 --- a/tests/auto/particles/qsgcumulativedirection/tst_qsgcumulativedirection.cpp +++ /dev/null @@ -1,88 +0,0 @@ -/**************************************************************************** -** -** 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 test suite 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 -#include "../shared/particlestestsshared.h" -#include -#include - -class tst_qsgcumulativedirection : public QObject -{ - Q_OBJECT -public: - tst_qsgcumulativedirection(); - -private slots: - void test_basic(); -}; - -tst_qsgcumulativedirection::tst_qsgcumulativedirection() -{ - QUnifiedTimer::instance()->setConsistentTiming(true); -} - -void tst_qsgcumulativedirection::test_basic() -{ - QQuickView* view = createView(QCoreApplication::applicationDirPath() + "/data/basic.qml", 600); - QSGParticleSystem* system = view->rootObject()->findChild("system"); - ensureAnimTime(600, system->m_animation); - - QCOMPARE(system->groupData[0]->size(), 500); - foreach (QSGParticleData *d, system->groupData[0]->data) { - if (d->t == -1) - continue; //Particle data unused - - QVERIFY(myFuzzyCompare(d->x, 0.0f)); - QVERIFY(myFuzzyCompare(d->y, 0.0f)); - QVERIFY(myFuzzyCompare(d->vx, 0.0f)); - QVERIFY(myFuzzyCompare(d->vy, 0.0f)); - QVERIFY(myFuzzyCompare(d->ax, 0.0f)); - QVERIFY(myFuzzyCompare(d->ay, 0.0f)); - QCOMPARE(d->lifeSpan, 0.5f); - QCOMPARE(d->size, 32.f); - QCOMPARE(d->endSize, 32.f); - QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); - } -} - -QTEST_MAIN(tst_qsgcumulativedirection); - -#include "tst_qsgcumulativedirection.moc" diff --git a/tests/auto/particles/qsgcustomaffector/data/basic.qml b/tests/auto/particles/qsgcustomaffector/data/basic.qml deleted file mode 100644 index 7371698026..0000000000 --- a/tests/auto/particles/qsgcustomaffector/data/basic.qml +++ /dev/null @@ -1,82 +0,0 @@ -/**************************************************************************** -** -** 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 test suite 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$ -** -****************************************************************************/ - -import QtQuick 2.0 -import QtQuick.Particles 2.0 - -Rectangle { - color: "black" - width: 320 - height: 320 - - ParticleSystem { - id: sys - objectName: "system" - anchors.fill: parent - - ImageParticle { - source: "../../shared/star.png" - } - - Emitter{ - //0,0 position - size: 32 - emitRate: 1000 - lifeSpan: 500 - } - - Affector { - once: true - onAffectParticles: { - for (var i=0; i -#include "../shared/particlestestsshared.h" -#include -#include - -class tst_qsgcustomaffector : public QObject -{ - Q_OBJECT -public: - tst_qsgcustomaffector(); - -private slots: - void test_basic(); - void test_move(); -}; - -tst_qsgcustomaffector::tst_qsgcustomaffector() -{ - QUnifiedTimer::instance()->setConsistentTiming(true); -} - -void tst_qsgcustomaffector::test_basic() -{ - QQuickView* view = createView(QCoreApplication::applicationDirPath() + "/data/basic.qml", 600); - QSGParticleSystem* system = view->rootObject()->findChild("system"); - ensureAnimTime(600, system->m_animation); - - QCOMPARE(system->groupData[0]->size(), 500); - foreach (QSGParticleData *d, system->groupData[0]->data) { - if (d->t == -1) - continue; //Particle data unused - - QCOMPARE(d->x, 100.f); - QCOMPARE(d->y, 100.f); - QCOMPARE(d->vx, 100.f); - QCOMPARE(d->vy, 100.f); - QCOMPARE(d->ax, 100.f); - QCOMPARE(d->ay, 100.f); - QCOMPARE(d->lifeSpan, 0.5f); - QCOMPARE(d->size, 100.f); - QCOMPARE(d->endSize, 100.f); - QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); - } -} - -void tst_qsgcustomaffector::test_move() -{ - QQuickView* view = createView(QCoreApplication::applicationDirPath() + "/data/move.qml", 600); - QSGParticleSystem* system = view->rootObject()->findChild("system"); - ensureAnimTime(600, system->m_animation); - - QCOMPARE(system->groupData[0]->size(), 500); - foreach (QSGParticleData *d, system->groupData[0]->data) { - if (d->t == -1) - continue; //Particle data unused - if (!d->stillAlive()) - continue; //parameters no longer get set once you die - - QVERIFY(myFuzzyCompare(d->curX(), 50.0)); - QVERIFY(myFuzzyCompare(d->curY(), 50.0)); - QVERIFY(myFuzzyCompare(d->curVX(), 50.0)); - QVERIFY(myFuzzyCompare(d->curVY(), 50.0)); - QVERIFY(myFuzzyCompare(d->curAX(), 50.0)); - QVERIFY(myFuzzyCompare(d->curAY(), 50.0)); - QCOMPARE(d->lifeSpan, 0.5f); - QCOMPARE(d->size, 32.f); - QCOMPARE(d->endSize, 32.f); - QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); - } -} - -QTEST_MAIN(tst_qsgcustomaffector); - -#include "tst_qsgcustomaffector.moc" diff --git a/tests/auto/particles/qsgcustomparticle/data/basic.qml b/tests/auto/particles/qsgcustomparticle/data/basic.qml deleted file mode 100644 index 244f706b99..0000000000 --- a/tests/auto/particles/qsgcustomparticle/data/basic.qml +++ /dev/null @@ -1,71 +0,0 @@ -/**************************************************************************** -** -** 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 test suite 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$ -** -****************************************************************************/ - -import QtQuick 2.0 -import QtQuick.Particles 2.0 - -Rectangle { - color: "black" - width: 320 - height: 320 - - ParticleSystem { - id: sys - objectName: "system" - anchors.fill: parent - - CustomParticle { - property variant source: ShaderEffectSource { - hideSource: true - sourceItem: Image { - source: "../../shared/star.png" - } - } - } - - Emitter{ - //0,0 position - size: 32 - emitRate: 1000 - lifeSpan: 500 - } - } -} diff --git a/tests/auto/particles/qsgcustomparticle/qsgcustomparticle.pro b/tests/auto/particles/qsgcustomparticle/qsgcustomparticle.pro deleted file mode 100644 index 2f84d78c08..0000000000 --- a/tests/auto/particles/qsgcustomparticle/qsgcustomparticle.pro +++ /dev/null @@ -1,11 +0,0 @@ -CONFIG += testcase -TARGET = tst_qsgcustomparticle -SOURCES += tst_qsgcustomparticle.cpp -macx:CONFIG -= app_bundle - -testDataFiles.files = data -testDataFiles.path = . -DEPLOYMENT += testDataFiles - -QT += core-private gui-private v8-private declarative-private opengl-private testlib - diff --git a/tests/auto/particles/qsgcustomparticle/tst_qsgcustomparticle.cpp b/tests/auto/particles/qsgcustomparticle/tst_qsgcustomparticle.cpp deleted file mode 100644 index 6fd02cd92b..0000000000 --- a/tests/auto/particles/qsgcustomparticle/tst_qsgcustomparticle.cpp +++ /dev/null @@ -1,94 +0,0 @@ -/**************************************************************************** -** -** 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 test suite 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 -#include "../shared/particlestestsshared.h" -#include -#include - -class tst_qsgcustomparticle : public QObject -{ - Q_OBJECT -public: - tst_qsgcustomparticle(); - -private slots: - void test_basic(); -}; - -tst_qsgcustomparticle::tst_qsgcustomparticle() -{ - QUnifiedTimer::instance()->setConsistentTiming(true); -} - -void tst_qsgcustomparticle::test_basic() -{ - QQuickView* view = createView(QCoreApplication::applicationDirPath() + "/data/basic.qml", 600); - QVERIFY(view); - QSGParticleSystem* system = view->rootObject()->findChild("system"); - ensureAnimTime(600, system->m_animation); - - bool oneNonZero = false; - QCOMPARE(system->groupData[0]->size(), 500); - foreach (QSGParticleData *d, system->groupData[0]->data) { - if (d->t == -1) - continue; //Particle data unused - - QCOMPARE(d->x, 0.f); - QCOMPARE(d->y, 0.f); - QCOMPARE(d->vx, 0.f); - QCOMPARE(d->vy, 0.f); - QCOMPARE(d->ax, 0.f); - QCOMPARE(d->ay, 0.f); - QCOMPARE(d->lifeSpan, 0.5f); - QCOMPARE(d->size, 32.f); - QCOMPARE(d->endSize, 32.f); - QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); - QVERIFY(d->r >= 0.0 && d->r <= 1.0); - if (d->r != 0.0 ) - oneNonZero = true; - } - QVERIFY(oneNonZero);//Zero is a valid value, but it also needs to be set to a random number -} - -QTEST_MAIN(tst_qsgcustomparticle); - -#include "tst_qsgcustomparticle.moc" diff --git a/tests/auto/particles/qsgellipseextruder/data/basic.qml b/tests/auto/particles/qsgellipseextruder/data/basic.qml deleted file mode 100644 index fa5fb3686a..0000000000 --- a/tests/auto/particles/qsgellipseextruder/data/basic.qml +++ /dev/null @@ -1,77 +0,0 @@ -/**************************************************************************** -** -** 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 test suite 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$ -** -****************************************************************************/ - -import QtQuick 2.0 -import QtQuick.Particles 2.0 - -Rectangle { - color: "black" - width: 320 - height: 320 - - ParticleSystem { - id: sys - objectName: "system" - anchors.fill: parent - - ImageParticle { - groups: ["", "nondefault"] - source: "../../shared/star.png" - } - - Emitter{ - anchors.fill: parent - shape: EllipseShape{} - size: 32 - emitRate: 1000 - lifeSpan: 500 - } - - Emitter{ - group: "nondefault" - anchors.fill: parent - shape: EllipseShape{ fill: false } - size: 32 - emitRate: 1000 - lifeSpan: 500 - } - } -} diff --git a/tests/auto/particles/qsgellipseextruder/qsgellipseextruder.pro b/tests/auto/particles/qsgellipseextruder/qsgellipseextruder.pro deleted file mode 100644 index 297bba9952..0000000000 --- a/tests/auto/particles/qsgellipseextruder/qsgellipseextruder.pro +++ /dev/null @@ -1,11 +0,0 @@ -CONFIG += testcase -TARGET = tst_qsgellipseextruder -SOURCES += tst_qsgellipseextruder.cpp -macx:CONFIG -= app_bundle - -testDataFiles.files = data -testDataFiles.path = . -DEPLOYMENT += testDataFiles - -QT += core-private gui-private v8-private declarative-private opengl-private testlib - diff --git a/tests/auto/particles/qsgellipseextruder/tst_qsgellipseextruder.cpp b/tests/auto/particles/qsgellipseextruder/tst_qsgellipseextruder.cpp deleted file mode 100644 index 92ee0c2623..0000000000 --- a/tests/auto/particles/qsgellipseextruder/tst_qsgellipseextruder.cpp +++ /dev/null @@ -1,120 +0,0 @@ -/**************************************************************************** -** -** 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 test suite 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 -#include -#include "../shared/particlestestsshared.h" -#include -#include - -class tst_qsgellipseextruder : public QObject -{ - Q_OBJECT -public: - tst_qsgellipseextruder(); - -private slots: - void test_basic(); -private: - bool inCircle(qreal x, qreal y, qreal r, bool borderOnly=false); -}; - -tst_qsgellipseextruder::tst_qsgellipseextruder() -{ - QUnifiedTimer::instance()->setConsistentTiming(true); -} - -bool tst_qsgellipseextruder::inCircle(qreal x, qreal y, qreal r, bool borderOnly) -{ - x -= r; - y -= r; - if (myFuzzyCompare(x,0) && myFuzzyCompare(y,0)) - return !borderOnly; - qreal mag = qSqrt(x*x + y*y); - if (borderOnly) - return myFuzzyCompare(mag, r); //Need myFuzzyCompare for smaller Epsilon than qFuzzyCompare - else - return mag - EPSILON < r; -} - -void tst_qsgellipseextruder::test_basic() -{ - QQuickView* view = createView(QCoreApplication::applicationDirPath() + "/data/basic.qml", 600); - QSGParticleSystem* system = view->rootObject()->findChild("system"); - ensureAnimTime(600, system->m_animation); - - //Filled - QCOMPARE(system->groupData[0]->size(), 500); - foreach (QSGParticleData *d, system->groupData[0]->data) { - if (d->t == -1) - continue; //Particle data unused - - QVERIFY(inCircle(d->x, d->y, 160, false)); - QCOMPARE(d->vx, 0.f); - QCOMPARE(d->vy, 0.f); - QCOMPARE(d->ax, 0.f); - QCOMPARE(d->ay, 0.f); - QCOMPARE(d->lifeSpan, 0.5f); - QCOMPARE(d->size, 32.f); - QCOMPARE(d->endSize, 32.f); - QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); - } - //Just border - QCOMPARE(system->groupData[1]->size(), 500); - foreach (QSGParticleData *d, system->groupData[1]->data) { - if (d->t == -1) - continue; //Particle data unused - - QVERIFY(inCircle(d->x, d->y, 160, true)); - QCOMPARE(d->vx, 0.f); - QCOMPARE(d->vy, 0.f); - QCOMPARE(d->ax, 0.f); - QCOMPARE(d->ay, 0.f); - QCOMPARE(d->lifeSpan, 0.5f); - QCOMPARE(d->size, 32.f); - QCOMPARE(d->endSize, 32.f); - QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); - } -} - -QTEST_MAIN(tst_qsgellipseextruder); - -#include "tst_qsgellipseextruder.moc" diff --git a/tests/auto/particles/qsgfriction/data/basic.qml b/tests/auto/particles/qsgfriction/data/basic.qml deleted file mode 100644 index 87a8897914..0000000000 --- a/tests/auto/particles/qsgfriction/data/basic.qml +++ /dev/null @@ -1,87 +0,0 @@ -/**************************************************************************** -** -** 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 test suite 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$ -** -****************************************************************************/ - -import QtQuick 2.0 -import QtQuick.Particles 2.0 - -Rectangle { - color: "black" - width: 320 - height: 320 - - ParticleSystem { - id: sys - objectName: "system" - anchors.fill: parent - - ImageParticle { - groups: ["","notdefault"] - source: "../../shared/star.png" - } - - Friction { - factor: 0.2 - } - - Emitter{ - //0,0 position - speed: PointDirection{x:100} - size: 32 - emitRate: 1000 - lifeSpan: 500 - } - - Friction { - groups: ["notdefault"] - factor: 1000.0 - } - - Emitter{ - //0,0 position - group: "notdefault" - y:200 - speed: PointDirection{x:100} - size: 32 - emitRate: 1000 - lifeSpan: 500 - } - } -} diff --git a/tests/auto/particles/qsgfriction/data/threshold.qml b/tests/auto/particles/qsgfriction/data/threshold.qml deleted file mode 100644 index 27990c3e7e..0000000000 --- a/tests/auto/particles/qsgfriction/data/threshold.qml +++ /dev/null @@ -1,73 +0,0 @@ -/**************************************************************************** -** -** 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 test suite 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$ -** -****************************************************************************/ - -import QtQuick 2.0 -import QtQuick.Particles 2.0 - -Rectangle { - color: "black" - width: 320 - height: 320 - - ParticleSystem { - id: sys - objectName: "system" - anchors.fill: parent - - ImageParticle { - groups: ["","notdefault"] - source: "../../shared/star.png" - } - - Friction { - factor: 1000 //speed limit 50 - threshold: 50 - } - - Emitter{ - //0,0 position - speed: PointDirection{x:1000} - size: 32 - emitRate: 1000 - lifeSpan: 500 - } - } -} diff --git a/tests/auto/particles/qsgfriction/qsgfriction.pro b/tests/auto/particles/qsgfriction/qsgfriction.pro deleted file mode 100644 index ad3f054957..0000000000 --- a/tests/auto/particles/qsgfriction/qsgfriction.pro +++ /dev/null @@ -1,11 +0,0 @@ -CONFIG += testcase -TARGET = tst_qsgfriction -SOURCES += tst_qsgfriction.cpp -macx:CONFIG -= app_bundle - -testDataFiles.files = data -testDataFiles.path = . -DEPLOYMENT += testDataFiles - -QT += core-private gui-private v8-private declarative-private opengl-private testlib - diff --git a/tests/auto/particles/qsgfriction/tst_qsgfriction.cpp b/tests/auto/particles/qsgfriction/tst_qsgfriction.cpp deleted file mode 100644 index 3237c92421..0000000000 --- a/tests/auto/particles/qsgfriction/tst_qsgfriction.cpp +++ /dev/null @@ -1,134 +0,0 @@ -/**************************************************************************** -** -** 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 test suite 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 -#include "../shared/particlestestsshared.h" -#include -#include - -class tst_qsgfriction : public QObject -{ - Q_OBJECT -public: - tst_qsgfriction(); - -private slots: - void test_basic(); - void test_threshold(); -}; - -tst_qsgfriction::tst_qsgfriction() -{ - QUnifiedTimer::instance()->setConsistentTiming(true); -} - -void tst_qsgfriction::test_basic() -{ - QQuickView* view = createView(QCoreApplication::applicationDirPath() + "/data/basic.qml", 600); - QSGParticleSystem* system = view->rootObject()->findChild("system"); - ensureAnimTime(600, system->m_animation); - - //Default is just slowed a little - QCOMPARE(system->groupData[0]->size(), 500); - foreach (QSGParticleData *d, system->groupData[0]->data) { - if (d->t == -1) - continue; //Particle data unused - - QVERIFY(d->vx < 100.f); - QCOMPARE(d->y, 0.f); - QCOMPARE(d->vy, 0.f); - QCOMPARE(d->ax, 0.f); - QCOMPARE(d->ay, 0.f); - QCOMPARE(d->lifeSpan, 0.5f); - QCOMPARE(d->size, 32.f); - QCOMPARE(d->endSize, 32.f); - QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); - } - - //Nondefault comes to a complete stop within the first half of its life - QCOMPARE(system->groupData[1]->size(), 500); - foreach (QSGParticleData *d, system->groupData[1]->data) { - if (d->t == -1) - continue; //Particle data unused - - if (d->t > ((qreal)system->timeInt/1000.0) - 0.25) - continue; - QVERIFY(myFuzzyCompare(d->vx, 0.f)); - QCOMPARE(d->y, 200.f); - QCOMPARE(d->vy, 0.f); - QCOMPARE(d->ax, 0.f); - QCOMPARE(d->ay, 0.f); - QCOMPARE(d->lifeSpan, 0.5f); - QCOMPARE(d->size, 32.f); - QCOMPARE(d->endSize, 32.f); - QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); - } -} - -void tst_qsgfriction::test_threshold() -{ - QQuickView* view = createView(QCoreApplication::applicationDirPath() + "/data/threshold.qml", 600); - QSGParticleSystem* system = view->rootObject()->findChild("system"); - ensureAnimTime(600, system->m_animation); - - //Speed capped at 50, but it might take a frame or two to get there - QCOMPARE(system->groupData[0]->size(), 500); - foreach (QSGParticleData *d, system->groupData[0]->data) { - if (d->t == -1.0f) - continue; //Particle data unused - if (myFuzzyGEQ(d->t, ((qreal)system->timeInt/1000.0) - 0.1)) - continue; //Particle data too young - - QVERIFY(myFuzzyLEQ(d->vx, 50.f)); - QCOMPARE(d->y, 0.f); - QCOMPARE(d->vy, 0.f); - QCOMPARE(d->ax, 0.f); - QCOMPARE(d->ay, 0.f); - QCOMPARE(d->lifeSpan, 0.5f); - QCOMPARE(d->size, 32.f); - QCOMPARE(d->endSize, 32.f); - QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); - } -} - -QTEST_MAIN(tst_qsgfriction); - -#include "tst_qsgfriction.moc" diff --git a/tests/auto/particles/qsggravity/data/basic.qml b/tests/auto/particles/qsggravity/data/basic.qml deleted file mode 100644 index 9275654297..0000000000 --- a/tests/auto/particles/qsggravity/data/basic.qml +++ /dev/null @@ -1,70 +0,0 @@ -/**************************************************************************** -** -** 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 test suite 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$ -** -****************************************************************************/ - -import QtQuick 2.0 -import QtQuick.Particles 2.0 - -Rectangle { - color: "black" - width: 320 - height: 320 - - ParticleSystem { - id: sys - objectName: "system" - anchors.fill: parent - - ImageParticle { - source: "../../shared/star.png" - } - - Gravity { - acceleration: 1000 - angle: 45 - } - Emitter{ - //0,0 position - size: 32 - emitRate: 1000 - lifeSpan: 500 - } - } -} diff --git a/tests/auto/particles/qsggravity/qsggravity.pro b/tests/auto/particles/qsggravity/qsggravity.pro deleted file mode 100644 index a6e345146f..0000000000 --- a/tests/auto/particles/qsggravity/qsggravity.pro +++ /dev/null @@ -1,11 +0,0 @@ -CONFIG += testcase -TARGET = tst_qsggravity -SOURCES += tst_qsggravity.cpp -macx:CONFIG -= app_bundle - -testDataFiles.files = data -testDataFiles.path = . -DEPLOYMENT += testDataFiles - -QT += core-private gui-private v8-private declarative-private opengl-private testlib - diff --git a/tests/auto/particles/qsggravity/tst_qsggravity.cpp b/tests/auto/particles/qsggravity/tst_qsggravity.cpp deleted file mode 100644 index ae82384540..0000000000 --- a/tests/auto/particles/qsggravity/tst_qsggravity.cpp +++ /dev/null @@ -1,84 +0,0 @@ -/**************************************************************************** -** -** 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 test suite 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 -#include "../shared/particlestestsshared.h" -#include -#include - -class tst_qsggravity : public QObject -{ - Q_OBJECT -public: - tst_qsggravity(); - -private slots: - void test_basic(); -}; - -tst_qsggravity::tst_qsggravity() -{ - QUnifiedTimer::instance()->setConsistentTiming(true); -} - -void tst_qsggravity::test_basic() -{ - QQuickView* view = createView(QCoreApplication::applicationDirPath() + "/data/basic.qml", 600); - QSGParticleSystem* system = view->rootObject()->findChild("system"); - ensureAnimTime(600, system->m_animation); - - QCOMPARE(system->groupData[0]->size(), 500); - foreach (QSGParticleData *d, system->groupData[0]->data) { - if (d->t == -1) - continue; //Particle data unused - - QCOMPARE(d->ax, 707.10678f); - QCOMPARE(d->ay, 707.10678f); - QCOMPARE(d->lifeSpan, 0.5f); - QCOMPARE(d->size, 32.f); - QCOMPARE(d->endSize, 32.f); - QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); - } -} - -QTEST_MAIN(tst_qsggravity); - -#include "tst_qsggravity.moc" diff --git a/tests/auto/particles/qsgimageparticle/data/basic.qml b/tests/auto/particles/qsgimageparticle/data/basic.qml deleted file mode 100644 index f5ef4c16c0..0000000000 --- a/tests/auto/particles/qsgimageparticle/data/basic.qml +++ /dev/null @@ -1,66 +0,0 @@ -/**************************************************************************** -** -** 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 test suite 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$ -** -****************************************************************************/ - -import QtQuick 2.0 -import QtQuick.Particles 2.0 - -Rectangle { - color: "black" - width: 320 - height: 320 - - ParticleSystem { - id: sys - objectName: "system" - anchors.fill: parent - - ImageParticle { - source: "../../shared/star.png" - } - - Emitter{ - //0,0 position - size: 32 - emitRate: 1000 - lifeSpan: 500 - } - } -} diff --git a/tests/auto/particles/qsgimageparticle/data/colored.qml b/tests/auto/particles/qsgimageparticle/data/colored.qml deleted file mode 100644 index 8f4ddbf8c4..0000000000 --- a/tests/auto/particles/qsgimageparticle/data/colored.qml +++ /dev/null @@ -1,68 +0,0 @@ -/**************************************************************************** -** -** 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 test suite 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$ -** -****************************************************************************/ - -import QtQuick 2.0 -import QtQuick.Particles 2.0 - -Rectangle { - color: "black" - width: 320 - height: 320 - - ParticleSystem { - id: sys - objectName: "system" - anchors.fill: parent - - ImageParticle { - source: "../../shared/star.png" - alpha: 0.5 - color: "#030201" - } - - Emitter{ - //0,0 position - size: 32 - emitRate: 1000 - lifeSpan: 500 - } - } -} diff --git a/tests/auto/particles/qsgimageparticle/data/deformed.qml b/tests/auto/particles/qsgimageparticle/data/deformed.qml deleted file mode 100644 index b0a58ee5d1..0000000000 --- a/tests/auto/particles/qsgimageparticle/data/deformed.qml +++ /dev/null @@ -1,71 +0,0 @@ -/**************************************************************************** -** -** 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 test suite 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$ -** -****************************************************************************/ - -import QtQuick 2.0 -import QtQuick.Particles 2.0 - -Rectangle { - color: "black" - width: 320 - height: 320 - - ParticleSystem { - id: sys - objectName: "system" - anchors.fill: parent - - ImageParticle { - source: "../../shared/star.png" - rotation: 90 - rotationSpeed: 90 - autoRotation: true - yVector: PointDirection{x: 0.5; y: 0.5} - xVector: PointDirection{x: 0.5; y: 0.5} - } - - Emitter{ - //0,0 position - size: 32 - emitRate: 1000 - lifeSpan: 500 - } - } -} diff --git a/tests/auto/particles/qsgimageparticle/data/sprite.qml b/tests/auto/particles/qsgimageparticle/data/sprite.qml deleted file mode 100644 index 5c1acf4b04..0000000000 --- a/tests/auto/particles/qsgimageparticle/data/sprite.qml +++ /dev/null @@ -1,71 +0,0 @@ -/**************************************************************************** -** -** 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 test suite 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$ -** -****************************************************************************/ - -import QtQuick 2.0 -import QtQuick.Particles 2.0 - -Rectangle { - color: "black" - width: 320 - height: 320 - - ParticleSystem { - id: sys - objectName: "system" - anchors.fill: parent - - ImageParticle { - sprites: Sprite { - name: "happy" - source: "../../shared/squarefacesprite.png" - frames: 6 - duration: 120 - } - } - - Emitter{ - //0,0 position - size: 32 - emitRate: 1000 - lifeSpan: 500 - } - } -} diff --git a/tests/auto/particles/qsgimageparticle/data/tabled.qml b/tests/auto/particles/qsgimageparticle/data/tabled.qml deleted file mode 100644 index 8a7a9ce229..0000000000 --- a/tests/auto/particles/qsgimageparticle/data/tabled.qml +++ /dev/null @@ -1,69 +0,0 @@ -/**************************************************************************** -** -** 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 test suite 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$ -** -****************************************************************************/ - -import QtQuick 2.0 -import QtQuick.Particles 2.0 - -Rectangle { - color: "black" - width: 320 - height: 320 - - ParticleSystem { - id: sys - objectName: "system" - anchors.fill: parent - - ImageParticle { - source: "../../shared/star.png" - sizeTable: "../../shared/table.png" - colorTable: "../../shared/table.png" - opacityTable: "../../shared/table.png" - } - - Emitter{ - //0,0 position - size: 32 - emitRate: 1000 - lifeSpan: 500 - } - } -} diff --git a/tests/auto/particles/qsgimageparticle/qsgimageparticle.pro b/tests/auto/particles/qsgimageparticle/qsgimageparticle.pro deleted file mode 100644 index 62dbd0b817..0000000000 --- a/tests/auto/particles/qsgimageparticle/qsgimageparticle.pro +++ /dev/null @@ -1,11 +0,0 @@ -CONFIG += testcase -TARGET = tst_qsgimageparticle -SOURCES += tst_qsgimageparticle.cpp -macx:CONFIG -= app_bundle - -testDataFiles.files = data -testDataFiles.path = . -DEPLOYMENT += testDataFiles - -QT += core-private gui-private v8-private declarative-private opengl-private testlib - diff --git a/tests/auto/particles/qsgimageparticle/tst_qsgimageparticle.cpp b/tests/auto/particles/qsgimageparticle/tst_qsgimageparticle.cpp deleted file mode 100644 index cd0378392c..0000000000 --- a/tests/auto/particles/qsgimageparticle/tst_qsgimageparticle.cpp +++ /dev/null @@ -1,285 +0,0 @@ -/**************************************************************************** -** -** 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 test suite 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 -#include "../shared/particlestestsshared.h" -#include -#include - -const double CONV_FACTOR = 0.017453292519943295;//Degrees to radians - -class tst_qsgimageparticle : public QObject -{ - Q_OBJECT -public: - tst_qsgimageparticle(); - -private slots: - void test_basic(); - void test_colored(); - void test_deformed(); - void test_tabled(); - void test_sprite(); -}; - -tst_qsgimageparticle::tst_qsgimageparticle() -{ - QUnifiedTimer::instance()->setConsistentTiming(true); -} - -void tst_qsgimageparticle::test_basic() -{ - QQuickView* view = createView(QCoreApplication::applicationDirPath() + "/data/basic.qml", 600); - QSGParticleSystem* system = view->rootObject()->findChild("system"); - ensureAnimTime(600, system->m_animation); - - QCOMPARE(system->groupData[0]->size(), 500); - foreach (QSGParticleData *d, system->groupData[0]->data) { - if (d->t == -1) - continue; //Particle data unused - - QCOMPARE(d->x, 0.f); - QCOMPARE(d->y, 0.f); - QCOMPARE(d->vx, 0.f); - QCOMPARE(d->vy, 0.f); - QCOMPARE(d->ax, 0.f); - QCOMPARE(d->ay, 0.f); - QCOMPARE(d->lifeSpan, 0.5f); - QCOMPARE(d->size, 32.f); - QCOMPARE(d->endSize, 32.f); - QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); - QCOMPARE(d->color.r, (uchar)255); - QCOMPARE(d->color.g, (uchar)255); - QCOMPARE(d->color.b, (uchar)255); - QCOMPARE(d->color.a, (uchar)255); - QCOMPARE(d->xx, 1.0f); - QCOMPARE(d->xy, 0.0f); - QCOMPARE(d->yy, 1.0f); - QCOMPARE(d->yx, 0.0f); - QCOMPARE(d->rotation, 0.0f); - QCOMPARE(d->rotationSpeed, 0.0f); - QCOMPARE(d->autoRotate, 0.0f); - QCOMPARE(d->animX, 0.0f); - QCOMPARE(d->animY, 0.0f); - QCOMPARE(d->animWidth, 1.0f); - QCOMPARE(d->animHeight, 1.0f); - QCOMPARE(d->frameDuration, 1.0f); - QCOMPARE(d->frameCount, 1.0f); - QCOMPARE(d->animT, -1.0f); - } -} - - -void tst_qsgimageparticle::test_colored() -{ - QQuickView* view = createView(QCoreApplication::applicationDirPath() + "/data/colored.qml", 600); - QSGParticleSystem* system = view->rootObject()->findChild("system"); - ensureAnimTime(600, system->m_animation); - - QCOMPARE(system->groupData[0]->size(), 500); - foreach (QSGParticleData *d, system->groupData[0]->data) { - if (d->t == -1) - continue; //Particle data unused - - QCOMPARE(d->x, 0.f); - QCOMPARE(d->y, 0.f); - QCOMPARE(d->vx, 0.f); - QCOMPARE(d->vy, 0.f); - QCOMPARE(d->ax, 0.f); - QCOMPARE(d->ay, 0.f); - QCOMPARE(d->lifeSpan, 0.5f); - QCOMPARE(d->size, 32.f); - QCOMPARE(d->endSize, 32.f); - QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); - QCOMPARE(d->color.r, (uchar)003); - QCOMPARE(d->color.g, (uchar)002); - QCOMPARE(d->color.b, (uchar)001); - QCOMPARE(d->color.a, (uchar)127); - QCOMPARE(d->xx, 1.0f); - QCOMPARE(d->xy, 0.0f); - QCOMPARE(d->yy, 1.0f); - QCOMPARE(d->yx, 0.0f); - QCOMPARE(d->rotation, 0.0f); - QCOMPARE(d->rotationSpeed, 0.0f); - QCOMPARE(d->autoRotate, 0.0f); - QCOMPARE(d->animX, 0.0f); - QCOMPARE(d->animY, 0.0f); - QCOMPARE(d->animWidth, 1.0f); - QCOMPARE(d->animHeight, 1.0f); - QCOMPARE(d->frameDuration, 1.0f); - QCOMPARE(d->frameCount, 1.0f); - QCOMPARE(d->animT, -1.0f); - } -} - - -void tst_qsgimageparticle::test_deformed() -{ - QQuickView* view = createView(QCoreApplication::applicationDirPath() + "/data/deformed.qml", 600); - QSGParticleSystem* system = view->rootObject()->findChild("system"); - ensureAnimTime(600, system->m_animation); - - QCOMPARE(system->groupData[0]->size(), 500); - foreach (QSGParticleData *d, system->groupData[0]->data) { - if (d->t == -1) - continue; //Particle data unused - - QCOMPARE(d->x, 0.f); - QCOMPARE(d->y, 0.f); - QCOMPARE(d->vx, 0.f); - QCOMPARE(d->vy, 0.f); - QCOMPARE(d->ax, 0.f); - QCOMPARE(d->ay, 0.f); - QCOMPARE(d->lifeSpan, 0.5f); - QCOMPARE(d->size, 32.f); - QCOMPARE(d->endSize, 32.f); - QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); - QCOMPARE(d->color.r, (uchar)255); - QCOMPARE(d->color.g, (uchar)255); - QCOMPARE(d->color.b, (uchar)255); - QCOMPARE(d->color.a, (uchar)255); - QCOMPARE(d->xx, 0.5f); - QCOMPARE(d->xy, 0.5f); - QCOMPARE(d->yy, 0.5f); - QCOMPARE(d->yx, 0.5f); - QCOMPARE(d->rotation, 90.0f * (float)CONV_FACTOR); - QCOMPARE(d->rotationSpeed, 90.0f * (float)CONV_FACTOR); - QCOMPARE(d->autoRotate, 1.0f); - QCOMPARE(d->animX, 0.0f); - QCOMPARE(d->animY, 0.0f); - QCOMPARE(d->animWidth, 1.0f); - QCOMPARE(d->animHeight, 1.0f); - QCOMPARE(d->frameDuration, 1.0f); - QCOMPARE(d->frameCount, 1.0f); - QCOMPARE(d->animT, -1.0f); - } -} - - -void tst_qsgimageparticle::test_tabled() -{ - QQuickView* view = createView(QCoreApplication::applicationDirPath() + "/data/tabled.qml", 600); - QSGParticleSystem* system = view->rootObject()->findChild("system"); - ensureAnimTime(600, system->m_animation); - - QCOMPARE(system->groupData[0]->size(), 500); - foreach (QSGParticleData *d, system->groupData[0]->data) { - if (d->t == -1) - continue; //Particle data unused - - QCOMPARE(d->x, 0.f); - QCOMPARE(d->y, 0.f); - QCOMPARE(d->vx, 0.f); - QCOMPARE(d->vy, 0.f); - QCOMPARE(d->ax, 0.f); - QCOMPARE(d->ay, 0.f); - QCOMPARE(d->lifeSpan, 0.5f); - QCOMPARE(d->size, 32.f); - QCOMPARE(d->endSize, 32.f); - QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); - QCOMPARE(d->color.r, (uchar)255); - QCOMPARE(d->color.g, (uchar)255); - QCOMPARE(d->color.b, (uchar)255); - QCOMPARE(d->color.a, (uchar)255); - QCOMPARE(d->xx, 1.0f); - QCOMPARE(d->xy, 0.0f); - QCOMPARE(d->yy, 1.0f); - QCOMPARE(d->yx, 0.0f); - QCOMPARE(d->rotation, 0.0f); - QCOMPARE(d->rotationSpeed, 0.0f); - QCOMPARE(d->autoRotate, 0.0f); - QCOMPARE(d->animX, 0.0f); - QCOMPARE(d->animY, 0.0f); - QCOMPARE(d->animWidth, 1.0f); - QCOMPARE(d->animHeight, 1.0f); - QCOMPARE(d->frameDuration, 1.0f); - QCOMPARE(d->frameCount, 1.0f); - QCOMPARE(d->animT, -1.0f); - //TODO: This performance level doesn't alter particleData, but goes straight to shaders. Find something to test - } -} - - -void tst_qsgimageparticle::test_sprite() -{ - QQuickView* view = createView(QCoreApplication::applicationDirPath() + "/data/sprite.qml", 600); - QSGParticleSystem* system = view->rootObject()->findChild("system"); - ensureAnimTime(600, system->m_animation); - - QCOMPARE(system->groupData[0]->size(), 500); - foreach (QSGParticleData *d, system->groupData[0]->data) { - if (d->t == -1) - continue; //Particle data unused - - QCOMPARE(d->x, 0.f); - QCOMPARE(d->y, 0.f); - QCOMPARE(d->vx, 0.f); - QCOMPARE(d->vy, 0.f); - QCOMPARE(d->ax, 0.f); - QCOMPARE(d->ay, 0.f); - QCOMPARE(d->lifeSpan, 0.5f); - QCOMPARE(d->size, 32.f); - QCOMPARE(d->endSize, 32.f); - QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); - QCOMPARE(d->color.r, (uchar)255); - QCOMPARE(d->color.g, (uchar)255); - QCOMPARE(d->color.b, (uchar)255); - QCOMPARE(d->color.a, (uchar)255); - QCOMPARE(d->xx, 1.0f); - QCOMPARE(d->xy, 0.0f); - QCOMPARE(d->yy, 1.0f); - QCOMPARE(d->yx, 0.0f); - QCOMPARE(d->rotation, 0.0f); - QCOMPARE(d->rotationSpeed, 0.0f); - QCOMPARE(d->autoRotate, 0.0f); - QVERIFY(myFuzzyCompare(d->frameDuration, 120.f)); - QCOMPARE(d->frameCount, 6.0f); - QVERIFY(d->animT > 0.0f); - QCOMPARE(d->animX, 0.0f); - QCOMPARE(d->animY, 0.0f); - QCOMPARE(d->animWidth, 31.0f); - QCOMPARE(d->animHeight, 30.0f); - } -} - -QTEST_MAIN(tst_qsgimageparticle); - -#include "tst_qsgimageparticle.moc" diff --git a/tests/auto/particles/qsgitemparticle/data/basic.qml b/tests/auto/particles/qsgitemparticle/data/basic.qml deleted file mode 100644 index dbe16a0b4e..0000000000 --- a/tests/auto/particles/qsgitemparticle/data/basic.qml +++ /dev/null @@ -1,66 +0,0 @@ -/**************************************************************************** -** -** 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 test suite 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$ -** -****************************************************************************/ - -import QtQuick 2.0 -import QtQuick.Particles 2.0 - -Rectangle { - color: "black" - width: 320 - height: 320 - - ParticleSystem { - id: sys - objectName: "system" - anchors.fill: parent - - ItemParticle { - delegate: Image{ source: "../../shared/star.png" } - } - - Emitter{ - //0,0 position - size: 32 - emitRate: 1000 - lifeSpan: 500 - } - } -} diff --git a/tests/auto/particles/qsgitemparticle/qsgitemparticle.pro b/tests/auto/particles/qsgitemparticle/qsgitemparticle.pro deleted file mode 100644 index afecb905db..0000000000 --- a/tests/auto/particles/qsgitemparticle/qsgitemparticle.pro +++ /dev/null @@ -1,11 +0,0 @@ -CONFIG += testcase -TARGET = tst_qsgitemparticle -SOURCES += tst_qsgitemparticle.cpp -macx:CONFIG -= app_bundle - -testDataFiles.files = data -testDataFiles.path = . -DEPLOYMENT += testDataFiles - -QT += core-private gui-private v8-private declarative-private opengl-private testlib - diff --git a/tests/auto/particles/qsgitemparticle/tst_qsgitemparticle.cpp b/tests/auto/particles/qsgitemparticle/tst_qsgitemparticle.cpp deleted file mode 100644 index 07ae377f0f..0000000000 --- a/tests/auto/particles/qsgitemparticle/tst_qsgitemparticle.cpp +++ /dev/null @@ -1,95 +0,0 @@ -/**************************************************************************** -** -** 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 test suite 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 -#include "../shared/particlestestsshared.h" -#include -#include -#include - -class tst_qsgitemparticle : public QObject -{ - Q_OBJECT -public: - tst_qsgitemparticle(); - -private slots: - void test_basic(); -}; - -tst_qsgitemparticle::tst_qsgitemparticle() -{ - QUnifiedTimer::instance()->setConsistentTiming(true); -} - -void tst_qsgitemparticle::test_basic() -{ - QQuickView* view = createView(QCoreApplication::applicationDirPath() + "/data/basic.qml", 600); - QSGParticleSystem* system = view->rootObject()->findChild("system"); - ensureAnimTime(600, system->m_animation); - - QCOMPARE(system->groupData[0]->size(), 500); - foreach (QSGParticleData *d, system->groupData[0]->data) { - if (d->t == -1) - continue; //Particle data unused - - QCOMPARE(d->x, 0.f); - QCOMPARE(d->y, 0.f); - QCOMPARE(d->vx, 0.f); - QCOMPARE(d->vy, 0.f); - QCOMPARE(d->ax, 0.f); - QCOMPARE(d->ay, 0.f); - QCOMPARE(d->lifeSpan, 0.5f); - QCOMPARE(d->size, 32.f); - QCOMPARE(d->endSize, 32.f); - QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); - if (d->t > ((qreal)system->timeInt/1000.0) - 0.05)//Delegates appear between frames, may miss the first couple - continue; - if (d->t < ((qreal)system->timeInt/1000.0) - 0.45)//Delegates cleared on death - continue; - QVERIFY(d->delegate); - QVERIFY(qobject_cast(d->delegate)); - } -} - -QTEST_MAIN(tst_qsgitemparticle); - -#include "tst_qsgitemparticle.moc" diff --git a/tests/auto/particles/qsglineextruder/data/basic.qml b/tests/auto/particles/qsglineextruder/data/basic.qml deleted file mode 100644 index dbe2ec5c7d..0000000000 --- a/tests/auto/particles/qsglineextruder/data/basic.qml +++ /dev/null @@ -1,76 +0,0 @@ -/**************************************************************************** -** -** 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 test suite 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$ -** -****************************************************************************/ - -import QtQuick 2.0 -import QtQuick.Particles 2.0 - -Rectangle { - color: "black" - width: 320 - height: 320 - - ParticleSystem { - id: sys - objectName: "system" - anchors.fill: parent - - ImageParticle { - groups: ["", "notdefault"] - source: "../../shared/star.png" - } - - Emitter{ - anchors.fill: parent - shape: LineShape{} - size: 32 - emitRate: 1000 - lifeSpan: 500 - } - Emitter{ - anchors.fill: parent - group: "notdefault" - shape: LineShape{mirrored: true} - size: 32 - emitRate: 1000 - lifeSpan: 500 - } - } -} diff --git a/tests/auto/particles/qsglineextruder/qsglineextruder.pro b/tests/auto/particles/qsglineextruder/qsglineextruder.pro deleted file mode 100644 index 90e28fc2ae..0000000000 --- a/tests/auto/particles/qsglineextruder/qsglineextruder.pro +++ /dev/null @@ -1,11 +0,0 @@ -CONFIG += testcase -TARGET = tst_qsglineextruder -SOURCES += tst_qsglineextruder.cpp -macx:CONFIG -= app_bundle - -testDataFiles.files = data -testDataFiles.path = . -DEPLOYMENT += testDataFiles - -QT += core-private gui-private v8-private declarative-private opengl-private testlib - diff --git a/tests/auto/particles/qsglineextruder/tst_qsglineextruder.cpp b/tests/auto/particles/qsglineextruder/tst_qsglineextruder.cpp deleted file mode 100644 index b66c174211..0000000000 --- a/tests/auto/particles/qsglineextruder/tst_qsglineextruder.cpp +++ /dev/null @@ -1,103 +0,0 @@ -/**************************************************************************** -** -** 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 test suite 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 -#include "../shared/particlestestsshared.h" -#include -#include - -class tst_qsglineextruder : public QObject -{ - Q_OBJECT -public: - tst_qsglineextruder(); - -private slots: - void test_basic(); -}; - -tst_qsglineextruder::tst_qsglineextruder() -{ - QUnifiedTimer::instance()->setConsistentTiming(true); -} - -void tst_qsglineextruder::test_basic() -{ - QQuickView* view = createView(QCoreApplication::applicationDirPath() + "/data/basic.qml", 600); - QSGParticleSystem* system = view->rootObject()->findChild("system"); - ensureAnimTime(600, system->m_animation); - - QCOMPARE(system->groupData[0]->size(), 500); - foreach (QSGParticleData *d, system->groupData[0]->data) { - if (d->t == -1) - continue; //Particle data unused - - QCOMPARE(d->x, d->y); - QCOMPARE(d->vx, 0.f); - QCOMPARE(d->vy, 0.f); - QCOMPARE(d->ax, 0.f); - QCOMPARE(d->ay, 0.f); - QCOMPARE(d->lifeSpan, 0.5f); - QCOMPARE(d->size, 32.f); - QCOMPARE(d->endSize, 32.f); - QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); - } - - QCOMPARE(system->groupData[1]->size(), 500); - foreach (QSGParticleData *d, system->groupData[1]->data) { - if (d->t == -1) - continue; //Particle data unused - - QCOMPARE(d->x + d->y, 320.0f); - QCOMPARE(d->vx, 0.f); - QCOMPARE(d->vy, 0.f); - QCOMPARE(d->ax, 0.f); - QCOMPARE(d->ay, 0.f); - QCOMPARE(d->lifeSpan, 0.5f); - QCOMPARE(d->size, 32.f); - QCOMPARE(d->endSize, 32.f); - QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); - } -} - -QTEST_MAIN(tst_qsglineextruder); - -#include "tst_qsglineextruder.moc" diff --git a/tests/auto/particles/qsgmaskextruder/data/basic.qml b/tests/auto/particles/qsgmaskextruder/data/basic.qml deleted file mode 100644 index 804df83de8..0000000000 --- a/tests/auto/particles/qsgmaskextruder/data/basic.qml +++ /dev/null @@ -1,68 +0,0 @@ -/**************************************************************************** -** -** 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 test suite 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$ -** -****************************************************************************/ - -import QtQuick 2.0 -import QtQuick.Particles 2.0 - -Rectangle { - color: "black" - width: 320 - height: 320 - - ParticleSystem { - id: sys - objectName: "system" - anchors.fill: parent - - ImageParticle { - source: "../../shared/star.png" - } - - Emitter{ - //100,100 rect at 100,100 - anchors.fill: parent - shape: MaskShape{source: "smallmask.png"} - size: 32 - emitRate: 1000 - lifeSpan: 500 - } - } -} diff --git a/tests/auto/particles/qsgmaskextruder/data/smallmask.png b/tests/auto/particles/qsgmaskextruder/data/smallmask.png deleted file mode 100644 index e36fb9fe55..0000000000 Binary files a/tests/auto/particles/qsgmaskextruder/data/smallmask.png and /dev/null differ diff --git a/tests/auto/particles/qsgmaskextruder/qsgmaskextruder.pro b/tests/auto/particles/qsgmaskextruder/qsgmaskextruder.pro deleted file mode 100644 index 995adabc7b..0000000000 --- a/tests/auto/particles/qsgmaskextruder/qsgmaskextruder.pro +++ /dev/null @@ -1,11 +0,0 @@ -CONFIG += testcase -TARGET = tst_qsgmaskextruder -SOURCES += tst_qsgmaskextruder.cpp -macx:CONFIG -= app_bundle - -testDataFiles.files = data -testDataFiles.path = . -DEPLOYMENT += testDataFiles - -QT += core-private gui-private v8-private declarative-private opengl-private testlib - diff --git a/tests/auto/particles/qsgmaskextruder/tst_qsgmaskextruder.cpp b/tests/auto/particles/qsgmaskextruder/tst_qsgmaskextruder.cpp deleted file mode 100644 index 962ab27508..0000000000 --- a/tests/auto/particles/qsgmaskextruder/tst_qsgmaskextruder.cpp +++ /dev/null @@ -1,88 +0,0 @@ -/**************************************************************************** -** -** 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 test suite 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 -#include "../shared/particlestestsshared.h" -#include -#include - -class tst_qsgmaskextruder : public QObject -{ - Q_OBJECT -public: - tst_qsgmaskextruder(); - -private slots: - void test_basic(); -}; - -tst_qsgmaskextruder::tst_qsgmaskextruder() -{ - QUnifiedTimer::instance()->setConsistentTiming(true); -} - -void tst_qsgmaskextruder::test_basic() -{ - QQuickView* view = createView(QCoreApplication::applicationDirPath() + "/data/basic.qml", 600); - QSGParticleSystem* system = view->rootObject()->findChild("system"); - ensureAnimTime(600, system->m_animation); - - QCOMPARE(system->groupData[0]->size(), 500); - foreach (QSGParticleData *d, system->groupData[0]->data) { - if (d->t == -1) - continue; //Particle data unused - - QVERIFY(d->x >= 100.0f && d->x <= 200.0f); - QVERIFY(d->y >= 100.0f && d->y <= 200.0f); - QCOMPARE(d->vx, 0.f); - QCOMPARE(d->vy, 0.f); - QCOMPARE(d->ax, 0.f); - QCOMPARE(d->ay, 0.f); - QCOMPARE(d->lifeSpan, 0.5f); - QCOMPARE(d->size, 32.f); - QCOMPARE(d->endSize, 32.f); - QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); - } -} - -QTEST_MAIN(tst_qsgmaskextruder); - -#include "tst_qsgmaskextruder.moc" diff --git a/tests/auto/particles/qsgparticlegroup/data/basic.qml b/tests/auto/particles/qsgparticlegroup/data/basic.qml deleted file mode 100644 index 97dadd7461..0000000000 --- a/tests/auto/particles/qsgparticlegroup/data/basic.qml +++ /dev/null @@ -1,73 +0,0 @@ -/**************************************************************************** -** -** 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 test suite 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$ -** -****************************************************************************/ - -import QtQuick 2.0 -import QtQuick.Particles 2.0 - -Rectangle { - color: "black" - width: 320 - height: 320 - - ParticleSystem { - id: sys - objectName: "system" - anchors.fill: parent - - ImageParticle { - source: "../../shared/star.png" - } - - ParticleGroup { - name: "notdefault" - duration: 0 - to: {"":1} - } - - Emitter{ - //0,0 position - group: "notdefault" - size: 32 - emitRate: 1000 - lifeSpan: 500 - } - } -} diff --git a/tests/auto/particles/qsgparticlegroup/qsgparticlegroup.pro b/tests/auto/particles/qsgparticlegroup/qsgparticlegroup.pro deleted file mode 100644 index 3d71ee0289..0000000000 --- a/tests/auto/particles/qsgparticlegroup/qsgparticlegroup.pro +++ /dev/null @@ -1,11 +0,0 @@ -CONFIG += testcase -TARGET = tst_qsgparticlegroup -SOURCES += tst_qsgparticlegroup.cpp -macx:CONFIG -= app_bundle - -testDataFiles.files = data -testDataFiles.path = . -DEPLOYMENT += testDataFiles - -QT += core-private gui-private v8-private declarative-private opengl-private testlib - diff --git a/tests/auto/particles/qsgparticlegroup/tst_qsgparticlegroup.cpp b/tests/auto/particles/qsgparticlegroup/tst_qsgparticlegroup.cpp deleted file mode 100644 index f49f3c444d..0000000000 --- a/tests/auto/particles/qsgparticlegroup/tst_qsgparticlegroup.cpp +++ /dev/null @@ -1,89 +0,0 @@ -/**************************************************************************** -** -** 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 test suite 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 -#include "../shared/particlestestsshared.h" -#include -#include - -class tst_qsgparticlegroup : public QObject -{ - Q_OBJECT -public: - tst_qsgparticlegroup(); - -private slots: - void test_instantTransition(); -}; - -tst_qsgparticlegroup::tst_qsgparticlegroup() -{ - QUnifiedTimer::instance()->setConsistentTiming(true); -} - -void tst_qsgparticlegroup::test_instantTransition() -{ - QQuickView* view = createView(QCoreApplication::applicationDirPath() + "/data/basic.qml", 600); - QSGParticleSystem* system = view->rootObject()->findChild("system"); - ensureAnimTime(600, system->m_animation); - - //A frame or two worth of particles will be missed, the transition doesn't take effect on the frame it's spawned (QTBUG-21781) - QVERIFY(system->groupData[0]->size() <= 500 && system->groupData[0]->size() >= 450); - foreach (QSGParticleData *d, system->groupData[0]->data) { - if (d->t == -1) - continue; //Particle data unused - - QCOMPARE(d->x, 0.f); - QCOMPARE(d->y, 0.f); - QCOMPARE(d->vx, 0.f); - QCOMPARE(d->vy, 0.f); - QCOMPARE(d->ax, 0.f); - QCOMPARE(d->ay, 0.f); - QCOMPARE(d->lifeSpan, 0.5f); - QCOMPARE(d->size, 32.f); - QCOMPARE(d->endSize, 32.f); - QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); - } -} - -QTEST_MAIN(tst_qsgparticlegroup); - -#include "tst_qsgparticlegroup.moc" diff --git a/tests/auto/particles/qsgparticlesystem/data/basic.qml b/tests/auto/particles/qsgparticlesystem/data/basic.qml deleted file mode 100644 index f5ef4c16c0..0000000000 --- a/tests/auto/particles/qsgparticlesystem/data/basic.qml +++ /dev/null @@ -1,66 +0,0 @@ -/**************************************************************************** -** -** 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 test suite 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$ -** -****************************************************************************/ - -import QtQuick 2.0 -import QtQuick.Particles 2.0 - -Rectangle { - color: "black" - width: 320 - height: 320 - - ParticleSystem { - id: sys - objectName: "system" - anchors.fill: parent - - ImageParticle { - source: "../../shared/star.png" - } - - Emitter{ - //0,0 position - size: 32 - emitRate: 1000 - lifeSpan: 500 - } - } -} diff --git a/tests/auto/particles/qsgparticlesystem/qsgparticlesystem.pro b/tests/auto/particles/qsgparticlesystem/qsgparticlesystem.pro deleted file mode 100644 index 6236a20bb6..0000000000 --- a/tests/auto/particles/qsgparticlesystem/qsgparticlesystem.pro +++ /dev/null @@ -1,11 +0,0 @@ -CONFIG += testcase -TARGET = tst_qsgparticlesystem -SOURCES += tst_qsgparticlesystem.cpp -macx:CONFIG -= app_bundle - -testDataFiles.files = data -testDataFiles.path = . -DEPLOYMENT += testDataFiles - -QT += core-private gui-private v8-private declarative-private opengl-private testlib - diff --git a/tests/auto/particles/qsgparticlesystem/tst_qsgparticlesystem.cpp b/tests/auto/particles/qsgparticlesystem/tst_qsgparticlesystem.cpp deleted file mode 100644 index 06a2414e95..0000000000 --- a/tests/auto/particles/qsgparticlesystem/tst_qsgparticlesystem.cpp +++ /dev/null @@ -1,92 +0,0 @@ -/**************************************************************************** -** -** 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 test suite 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 -#include "../shared/particlestestsshared.h" -#include -#include - -class tst_qsgparticlesystem : public QObject -{ - Q_OBJECT -public: - tst_qsgparticlesystem(); - -private slots: - void test_basic(); -}; - -tst_qsgparticlesystem::tst_qsgparticlesystem() -{ - QUnifiedTimer::instance()->setConsistentTiming(true); -} - -void tst_qsgparticlesystem::test_basic() -{ - QQuickView* view = createView(QCoreApplication::applicationDirPath() + "/data/basic.qml", 600); - QSGParticleSystem* system = view->rootObject()->findChild("system"); - ensureAnimTime(600, system->m_animation); - - QCOMPARE(system->groupData[0]->size(), 500); - int stillAlive = 0; - foreach (QSGParticleData *d, system->groupData[0]->data) { - if (d->t == -1) - continue; //Particle data unused - - if (d->stillAlive()) - stillAlive++; - QCOMPARE(d->x, 0.f); - QCOMPARE(d->y, 0.f); - QCOMPARE(d->vx, 0.f); - QCOMPARE(d->vy, 0.f); - QCOMPARE(d->ax, 0.f); - QCOMPARE(d->ay, 0.f); - QCOMPARE(d->lifeSpan, 0.5f); - QCOMPARE(d->size, 32.f); - QCOMPARE(d->endSize, 32.f); - QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); - } - QVERIFY(extremelyFuzzyCompare(stillAlive, 500, 5));//Small simulation variance is permissible. -} - -QTEST_MAIN(tst_qsgparticlesystem); - -#include "tst_qsgparticlesystem.moc" diff --git a/tests/auto/particles/qsgpointattractor/data/basic.qml b/tests/auto/particles/qsgpointattractor/data/basic.qml deleted file mode 100644 index 86861a9cf2..0000000000 --- a/tests/auto/particles/qsgpointattractor/data/basic.qml +++ /dev/null @@ -1,73 +0,0 @@ -/**************************************************************************** -** -** 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 test suite 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$ -** -****************************************************************************/ - -import QtQuick 2.0 -import QtQuick.Particles 2.0 - -Rectangle { - color: "black" - width: 320 - height: 320 - - ParticleSystem { - id: sys - objectName: "system" - anchors.fill: parent - - ImageParticle { - source: "../../shared/star.png" - } - - Attractor { - anchors.centerIn: parent - proportionalToDistance: Attractor.Constant - affectedParameter: Attractor.Position - strength: 100 - } - - Emitter{ - //0,0 position - size: 32 - emitRate: 1000 - lifeSpan: 500 - } - } -} diff --git a/tests/auto/particles/qsgpointattractor/qsgpointattractor.pro b/tests/auto/particles/qsgpointattractor/qsgpointattractor.pro deleted file mode 100644 index 865d58c89d..0000000000 --- a/tests/auto/particles/qsgpointattractor/qsgpointattractor.pro +++ /dev/null @@ -1,11 +0,0 @@ -CONFIG += testcase -TARGET = tst_qsgpointattractor -SOURCES += tst_qsgpointattractor.cpp -macx:CONFIG -= app_bundle - -testDataFiles.files = data -testDataFiles.path = . -DEPLOYMENT += testDataFiles - -QT += core-private gui-private v8-private declarative-private opengl-private testlib - diff --git a/tests/auto/particles/qsgpointattractor/tst_qsgpointattractor.cpp b/tests/auto/particles/qsgpointattractor/tst_qsgpointattractor.cpp deleted file mode 100644 index 14207f9fd6..0000000000 --- a/tests/auto/particles/qsgpointattractor/tst_qsgpointattractor.cpp +++ /dev/null @@ -1,89 +0,0 @@ -/**************************************************************************** -** -** 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 test suite 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 -#include "../shared/particlestestsshared.h" -#include -#include - -class tst_qsgpointattractor : public QObject -{ - Q_OBJECT -public: - tst_qsgpointattractor(); - -private slots: - void test_basic(); -}; - -tst_qsgpointattractor::tst_qsgpointattractor() -{ - QUnifiedTimer::instance()->setConsistentTiming(true); -} - -void tst_qsgpointattractor::test_basic() -{ - QQuickView* view = createView(QCoreApplication::applicationDirPath() + "/data/basic.qml", 600); - QSGParticleSystem* system = view->rootObject()->findChild("system"); - ensureAnimTime(600, system->m_animation); - - QCOMPARE(system->groupData[0]->size(), 500); - foreach (QSGParticleData *d, system->groupData[0]->data) { - if (d->t == -1) - continue; //Particle data unused - - QVERIFY(d->x != 0.f); - QVERIFY(d->y != 0.f); - QVERIFY(d->x == d->y); - QCOMPARE(d->vx, 0.f); - QCOMPARE(d->vy, 0.f); - QCOMPARE(d->ax, 0.f); - QCOMPARE(d->ay, 0.f); - QCOMPARE(d->lifeSpan, 0.5f); - QCOMPARE(d->size, 32.f); - QCOMPARE(d->endSize, 32.f); - QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); - } -} - -QTEST_MAIN(tst_qsgpointattractor); - -#include "tst_qsgpointattractor.moc" diff --git a/tests/auto/particles/qsgpointdirection/data/basic.qml b/tests/auto/particles/qsgpointdirection/data/basic.qml deleted file mode 100644 index 60c2a3e37b..0000000000 --- a/tests/auto/particles/qsgpointdirection/data/basic.qml +++ /dev/null @@ -1,68 +0,0 @@ -/**************************************************************************** -** -** 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 test suite 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$ -** -****************************************************************************/ - -import QtQuick 2.0 -import QtQuick.Particles 2.0 - -Rectangle { - color: "black" - width: 320 - height: 320 - - ParticleSystem { - id: sys - objectName: "system" - anchors.fill: parent - - ImageParticle { - source: "../../shared/star.png" - } - - Emitter{ - //0,0 position - size: 32 - speed: PointDirection{ x: 100; y: 100 } - acceleration: PointDirection{ x: 100; xVariation: 100; y: 100; yVariation: 100 } - emitRate: 1000 - lifeSpan: 500 - } - } -} diff --git a/tests/auto/particles/qsgpointdirection/qsgpointdirection.pro b/tests/auto/particles/qsgpointdirection/qsgpointdirection.pro deleted file mode 100644 index 841464d48e..0000000000 --- a/tests/auto/particles/qsgpointdirection/qsgpointdirection.pro +++ /dev/null @@ -1,11 +0,0 @@ -CONFIG += testcase -TARGET = tst_qsgpointdirection -SOURCES += tst_qsgpointdirection.cpp -macx:CONFIG -= app_bundle - -testDataFiles.files = data -testDataFiles.path = . -DEPLOYMENT += testDataFiles - -QT += core-private gui-private v8-private declarative-private opengl-private testlib - diff --git a/tests/auto/particles/qsgpointdirection/tst_qsgpointdirection.cpp b/tests/auto/particles/qsgpointdirection/tst_qsgpointdirection.cpp deleted file mode 100644 index b9b3dc15cb..0000000000 --- a/tests/auto/particles/qsgpointdirection/tst_qsgpointdirection.cpp +++ /dev/null @@ -1,90 +0,0 @@ -/**************************************************************************** -** -** 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 test suite 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 -#include "../shared/particlestestsshared.h" -#include -#include - -class tst_qsgpointdirection : public QObject -{ - Q_OBJECT -public: - tst_qsgpointdirection(); - -private slots: - void test_basic(); -}; - -tst_qsgpointdirection::tst_qsgpointdirection() -{ - QUnifiedTimer::instance()->setConsistentTiming(true); -} - -void tst_qsgpointdirection::test_basic() -{ - QQuickView* view = createView(QCoreApplication::applicationDirPath() + "/data/basic.qml", 600); - QSGParticleSystem* system = view->rootObject()->findChild("system"); - ensureAnimTime(600, system->m_animation); - - QCOMPARE(system->groupData[0]->size(), 500); - foreach (QSGParticleData *d, system->groupData[0]->data) { - if (d->t == -1) - continue; //Particle data unused - - QCOMPARE(d->x, 0.f); - QCOMPARE(d->y, 0.f); - QCOMPARE(d->vx, 100.f); - QCOMPARE(d->vy, 100.f); - QVERIFY(d->ax >= 0.f); - QVERIFY(d->ax <= 200.f); - QVERIFY(d->ay >= 0.f); - QVERIFY(d->ay <= 200.f); - QCOMPARE(d->lifeSpan, 0.5f); - QCOMPARE(d->size, 32.f); - QCOMPARE(d->endSize, 32.f); - QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); - } -} - -QTEST_MAIN(tst_qsgpointdirection); - -#include "tst_qsgpointdirection.moc" diff --git a/tests/auto/particles/qsgrectangleextruder/data/basic.qml b/tests/auto/particles/qsgrectangleextruder/data/basic.qml deleted file mode 100644 index a66827ed90..0000000000 --- a/tests/auto/particles/qsgrectangleextruder/data/basic.qml +++ /dev/null @@ -1,78 +0,0 @@ -/**************************************************************************** -** -** 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 test suite 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$ -** -****************************************************************************/ - -import QtQuick 2.0 -import QtQuick.Particles 2.0 - -Rectangle { - color: "black" - width: 320 - height: 320 - - ParticleSystem { - id: sys - objectName: "system" - anchors.fill: parent - - ImageParticle { - groups: ["", "notdefault"] - source: "../../shared/star.png" - } - - Emitter{ - width: 100 - height: 100 - size: 32 - shape: RectangleShape{} - emitRate: 1000 - lifeSpan: 500 - } - Emitter{ - width: 100 - height: 100 - group: "notdefault" - size: 32 - shape: RectangleShape{fill: false} - emitRate: 1000 - lifeSpan: 500 - } - } -} diff --git a/tests/auto/particles/qsgrectangleextruder/qsgrectangleextruder.pro b/tests/auto/particles/qsgrectangleextruder/qsgrectangleextruder.pro deleted file mode 100644 index e0e8f51aaa..0000000000 --- a/tests/auto/particles/qsgrectangleextruder/qsgrectangleextruder.pro +++ /dev/null @@ -1,11 +0,0 @@ -CONFIG += testcase -TARGET = tst_qsgrectangleextruder -SOURCES += tst_qsgrectangleextruder.cpp -macx:CONFIG -= app_bundle - -testDataFiles.files = data -testDataFiles.path = . -DEPLOYMENT += testDataFiles - -QT += core-private gui-private v8-private declarative-private opengl-private testlib - diff --git a/tests/auto/particles/qsgrectangleextruder/tst_qsgrectangleextruder.cpp b/tests/auto/particles/qsgrectangleextruder/tst_qsgrectangleextruder.cpp deleted file mode 100644 index dd86713b5b..0000000000 --- a/tests/auto/particles/qsgrectangleextruder/tst_qsgrectangleextruder.cpp +++ /dev/null @@ -1,113 +0,0 @@ -/**************************************************************************** -** -** 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 test suite 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 -#include "../shared/particlestestsshared.h" -#include -#include - -class tst_qsgrectangleextruder : public QObject -{ - Q_OBJECT -public: - tst_qsgrectangleextruder(); - -private slots: - void test_basic(); -}; - -tst_qsgrectangleextruder::tst_qsgrectangleextruder() -{ - QUnifiedTimer::instance()->setConsistentTiming(true); -} - -void tst_qsgrectangleextruder::test_basic() -{ - QQuickView* view = createView(QCoreApplication::applicationDirPath() + "/data/basic.qml", 600); - QSGParticleSystem* system = view->rootObject()->findChild("system"); - ensureAnimTime(600, system->m_animation); - - QCOMPARE(system->groupData[0]->size(), 500); - foreach (QSGParticleData *d, system->groupData[0]->data) { - if (d->t == -1) - continue; //Particle data unused - - QVERIFY(d->x >= 0.f); - QVERIFY(d->x <= 100.f); - QVERIFY(d->y >= 0.f); - QVERIFY(d->y <= 100.f); - QCOMPARE(d->vx, 0.f); - QCOMPARE(d->vy, 0.f); - QCOMPARE(d->ax, 0.f); - QCOMPARE(d->ay, 0.f); - QCOMPARE(d->lifeSpan, 0.5f); - QCOMPARE(d->size, 32.f); - QCOMPARE(d->endSize, 32.f); - QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); - } - - QCOMPARE(system->groupData[1]->size(), 500); - foreach (QSGParticleData *d, system->groupData[1]->data) { - if (d->t == -1) - continue; //Particle data unused - - if (!myFuzzyCompare(d->x, 0.f) && !myFuzzyCompare(d->x, 100.f)){ - QVERIFY(d->x >= 0.f); - QVERIFY(d->x <= 100.f); - QVERIFY(myFuzzyCompare(d->y, 0.f) || myFuzzyCompare(d->y, 100.f)); - } else { - QVERIFY(d->y >= 0.f); - QVERIFY(d->y <= 100.f); - } - QCOMPARE(d->vx, 0.f); - QCOMPARE(d->vy, 0.f); - QCOMPARE(d->ax, 0.f); - QCOMPARE(d->ay, 0.f); - QCOMPARE(d->lifeSpan, 0.5f); - QCOMPARE(d->size, 32.f); - QCOMPARE(d->endSize, 32.f); - QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); - } -} - -QTEST_MAIN(tst_qsgrectangleextruder); - -#include "tst_qsgrectangleextruder.moc" diff --git a/tests/auto/particles/qsgtargetdirection/data/basic.qml b/tests/auto/particles/qsgtargetdirection/data/basic.qml deleted file mode 100644 index a8caea4641..0000000000 --- a/tests/auto/particles/qsgtargetdirection/data/basic.qml +++ /dev/null @@ -1,67 +0,0 @@ -/**************************************************************************** -** -** 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 test suite 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$ -** -****************************************************************************/ - -import QtQuick 2.0 -import QtQuick.Particles 2.0 - -Rectangle { - color: "black" - width: 320 - height: 320 - - ParticleSystem { - id: sys - objectName: "system" - anchors.fill: parent - - ImageParticle { - source: "../../shared/star.png" - } - - Emitter{ - //0,0 position - speed: TargetDirection{ targetItem: sys; proportionalMagnitude: true; magnitude: 1 } - size: 32 - emitRate: 1000 - lifeSpan: 500 - } - } -} diff --git a/tests/auto/particles/qsgtargetdirection/qsgtargetdirection.pro b/tests/auto/particles/qsgtargetdirection/qsgtargetdirection.pro deleted file mode 100644 index 77288f7bc1..0000000000 --- a/tests/auto/particles/qsgtargetdirection/qsgtargetdirection.pro +++ /dev/null @@ -1,11 +0,0 @@ -CONFIG += testcase -TARGET = tst_qsgtargetdirection -SOURCES += tst_qsgtargetdirection.cpp -macx:CONFIG -= app_bundle - -testDataFiles.files = data -testDataFiles.path = . -DEPLOYMENT += testDataFiles - -QT += core-private gui-private v8-private declarative-private opengl-private testlib - diff --git a/tests/auto/particles/qsgtargetdirection/tst_qsgtargetdirection.cpp b/tests/auto/particles/qsgtargetdirection/tst_qsgtargetdirection.cpp deleted file mode 100644 index 5637c4c473..0000000000 --- a/tests/auto/particles/qsgtargetdirection/tst_qsgtargetdirection.cpp +++ /dev/null @@ -1,88 +0,0 @@ -/**************************************************************************** -** -** 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 test suite 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 -#include "../shared/particlestestsshared.h" -#include -#include - -class tst_qsgtargetdirection : public QObject -{ - Q_OBJECT -public: - tst_qsgtargetdirection(); - -private slots: - void test_basic(); -}; - -tst_qsgtargetdirection::tst_qsgtargetdirection() -{ - QUnifiedTimer::instance()->setConsistentTiming(true); -} - -void tst_qsgtargetdirection::test_basic() -{ - QQuickView* view = createView(QCoreApplication::applicationDirPath() + "/data/basic.qml", 600); - QSGParticleSystem* system = view->rootObject()->findChild("system"); - ensureAnimTime(600, system->m_animation); - - QCOMPARE(system->groupData[0]->size(), 500); - foreach (QSGParticleData *d, system->groupData[0]->data) { - if (d->t == -1) - continue; //Particle data unused - - QCOMPARE(d->x, 0.f); - QCOMPARE(d->y, 0.f); - QCOMPARE(d->vx, 160.f); - QCOMPARE(d->vy, 160.f); - QCOMPARE(d->ax, 0.f); - QCOMPARE(d->ay, 0.f); - QCOMPARE(d->lifeSpan, 0.5f); - QCOMPARE(d->size, 32.f); - QCOMPARE(d->endSize, 32.f); - QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); - } -} - -QTEST_MAIN(tst_qsgtargetdirection); - -#include "tst_qsgtargetdirection.moc" diff --git a/tests/auto/particles/qsgtrailemitter/data/basic.qml b/tests/auto/particles/qsgtrailemitter/data/basic.qml deleted file mode 100644 index 538d14f1d5..0000000000 --- a/tests/auto/particles/qsgtrailemitter/data/basic.qml +++ /dev/null @@ -1,77 +0,0 @@ -/**************************************************************************** -** -** 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 test suite 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$ -** -****************************************************************************/ - -import QtQuick 2.0 -import QtQuick.Particles 2.0 - -Rectangle { - color: "black" - width: 320 - height: 320 - - ParticleSystem { - id: sys - objectName: "system" - anchors.fill: parent - - ImageParticle { - groups: ["","notdefault"] - source: "../../shared/star.png" - } - - - TrailEmitter { - group: "notdefault" - follow: "" - size: 32 - emitRatePerParticle: 2 - lifeSpan: 500 - speed: PointDirection{ x: 500; y: 500 } - } - Emitter{ - x: 4 - y: 4 - size: 32 - emitRate: 1000 - lifeSpan: 500 - } - } -} diff --git a/tests/auto/particles/qsgtrailemitter/qsgtrailemitter.pro b/tests/auto/particles/qsgtrailemitter/qsgtrailemitter.pro deleted file mode 100644 index b7cb766877..0000000000 --- a/tests/auto/particles/qsgtrailemitter/qsgtrailemitter.pro +++ /dev/null @@ -1,11 +0,0 @@ -CONFIG += testcase -TARGET = tst_qsgtrailemitter -SOURCES += tst_qsgtrailemitter.cpp -macx:CONFIG -= app_bundle - -testDataFiles.files = data -testDataFiles.path = . -DEPLOYMENT += testDataFiles - -QT += core-private gui-private v8-private declarative-private opengl-private testlib - diff --git a/tests/auto/particles/qsgtrailemitter/tst_qsgtrailemitter.cpp b/tests/auto/particles/qsgtrailemitter/tst_qsgtrailemitter.cpp deleted file mode 100644 index 19a63fb73d..0000000000 --- a/tests/auto/particles/qsgtrailemitter/tst_qsgtrailemitter.cpp +++ /dev/null @@ -1,105 +0,0 @@ -/**************************************************************************** -** -** 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 test suite 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 -#include "../shared/particlestestsshared.h" -#include -#include - -class tst_qsgtrailemitter : public QObject -{ - Q_OBJECT -public: - tst_qsgtrailemitter(); - -private slots: - void test_basic(); -}; - -tst_qsgtrailemitter::tst_qsgtrailemitter() -{ - QUnifiedTimer::instance()->setConsistentTiming(true); -} - -void tst_qsgtrailemitter::test_basic() -{ - QQuickView* view = createView(QCoreApplication::applicationDirPath() + "/data/basic.qml", 600); - QSGParticleSystem* system = view->rootObject()->findChild("system"); - ensureAnimTime(600, system->m_animation); - - QCOMPARE(system->groupData[0]->size(), 500); - foreach (QSGParticleData *d, system->groupData[0]->data) { - if (d->t == -1) - continue; //Particle data unused - - QCOMPARE(d->x, 4.f); - QCOMPARE(d->y, 4.f); - QCOMPARE(d->vx, 0.f); - QCOMPARE(d->vy, 0.f); - QCOMPARE(d->ax, 0.f); - QCOMPARE(d->ay, 0.f); - QCOMPARE(d->lifeSpan, 0.5f); - QCOMPARE(d->size, 32.f); - QCOMPARE(d->endSize, 32.f); - QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); - } - - QCOMPARE(system->groupData[1]->size(), 500); - foreach (QSGParticleData *d, system->groupData[1]->data) { - if (d->t == -1) - continue; //Particle data unused - - QCOMPARE(d->x, 4.f); - QCOMPARE(d->y, 4.f); - QCOMPARE(d->vx, 500.f); - QCOMPARE(d->vy, 500.f); - QCOMPARE(d->ax, 0.f); - QCOMPARE(d->ay, 0.f); - QCOMPARE(d->lifeSpan, 0.5f); - QCOMPARE(d->size, 32.f); - QCOMPARE(d->endSize, 32.f); - QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); - } -} - -QTEST_MAIN(tst_qsgtrailemitter); - -#include "tst_qsgtrailemitter.moc" diff --git a/tests/auto/particles/qsgturbulence/data/basic.qml b/tests/auto/particles/qsgturbulence/data/basic.qml deleted file mode 100644 index 42b5cd6a97..0000000000 --- a/tests/auto/particles/qsgturbulence/data/basic.qml +++ /dev/null @@ -1,73 +0,0 @@ -/**************************************************************************** -** -** 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 test suite 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$ -** -****************************************************************************/ - -import QtQuick 2.0 -import QtQuick.Particles 2.0 - -Rectangle { - color: "black" - width: 320 - height: 320 - - ParticleSystem { - id: sys - objectName: "system" - anchors.fill: parent - - ImageParticle { - source: "../../shared/star.png" - } - - Turbulence { - anchors.fill: parent - strength: 1000 - } - - Emitter{ - //100,100 position - x: 100 - y: 100 - size: 32 - emitRate: 1000 - lifeSpan: 500 - } - } -} diff --git a/tests/auto/particles/qsgturbulence/qsgturbulence.pro b/tests/auto/particles/qsgturbulence/qsgturbulence.pro deleted file mode 100644 index 702c1d11a5..0000000000 --- a/tests/auto/particles/qsgturbulence/qsgturbulence.pro +++ /dev/null @@ -1,11 +0,0 @@ -CONFIG += testcase -TARGET = tst_qsgturbulence -SOURCES += tst_qsgturbulence.cpp -macx:CONFIG -= app_bundle - -testDataFiles.files = data -testDataFiles.path = . -DEPLOYMENT += testDataFiles - -QT += core-private gui-private v8-private declarative-private opengl-private testlib - diff --git a/tests/auto/particles/qsgturbulence/tst_qsgturbulence.cpp b/tests/auto/particles/qsgturbulence/tst_qsgturbulence.cpp deleted file mode 100644 index ca8a797b78..0000000000 --- a/tests/auto/particles/qsgturbulence/tst_qsgturbulence.cpp +++ /dev/null @@ -1,86 +0,0 @@ -/**************************************************************************** -** -** 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 test suite 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 -#include "../shared/particlestestsshared.h" -#include -#include - -class tst_qsgturbulence : public QObject -{ - Q_OBJECT -public: - tst_qsgturbulence(); - -private slots: - void test_basic(); -}; - -tst_qsgturbulence::tst_qsgturbulence() -{ - QUnifiedTimer::instance()->setConsistentTiming(true); -} - -void tst_qsgturbulence::test_basic() -{ - QQuickView* view = createView(QCoreApplication::applicationDirPath() + "/data/basic.qml", 600); - QSGParticleSystem* system = view->rootObject()->findChild("system"); - ensureAnimTime(600, system->m_animation); - - //Note that the noise image built-in provides the 'randomness', so this test should be stable so long as it and the size - //of the Turbulence item remain the same - QCOMPARE(system->groupData[0]->size(), 500); - foreach (QSGParticleData *d, system->groupData[0]->data) { - if (d->t == -1) - continue; //Particle data unused - - QVERIFY(d->vx != 0.f); - QVERIFY(d->vy != 0.f); - QCOMPARE(d->lifeSpan, 0.5f); - QCOMPARE(d->size, 32.f); - QCOMPARE(d->endSize, 32.f); - QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); - } -} - -QTEST_MAIN(tst_qsgturbulence); - -#include "tst_qsgturbulence.moc" diff --git a/tests/auto/particles/qsgwander/data/basic.qml b/tests/auto/particles/qsgwander/data/basic.qml deleted file mode 100644 index ebb4bd963a..0000000000 --- a/tests/auto/particles/qsgwander/data/basic.qml +++ /dev/null @@ -1,72 +0,0 @@ -/**************************************************************************** -** -** 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 test suite 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$ -** -****************************************************************************/ - -import QtQuick 2.0 -import QtQuick.Particles 2.0 - -Rectangle { - color: "black" - width: 320 - height: 320 - - ParticleSystem { - id: sys - objectName: "system" - anchors.fill: parent - - ImageParticle { - source: "../../shared/star.png" - } - - Wander { - pace: 400 - xVariance: 100 - yVariance: 100 - } - - Emitter{ - //0,0 position - size: 32 - emitRate: 1000 - lifeSpan: 500 - } - } -} diff --git a/tests/auto/particles/qsgwander/qsgwander.pro b/tests/auto/particles/qsgwander/qsgwander.pro deleted file mode 100644 index e11a522885..0000000000 --- a/tests/auto/particles/qsgwander/qsgwander.pro +++ /dev/null @@ -1,11 +0,0 @@ -CONFIG += testcase -TARGET = tst_qsgwander -SOURCES += tst_qsgwander.cpp -macx:CONFIG -= app_bundle - -testDataFiles.files = data -testDataFiles.path = . -DEPLOYMENT += testDataFiles - -QT += core-private gui-private v8-private declarative-private opengl-private testlib - diff --git a/tests/auto/particles/qsgwander/tst_qsgwander.cpp b/tests/auto/particles/qsgwander/tst_qsgwander.cpp deleted file mode 100644 index 56ae15e7bb..0000000000 --- a/tests/auto/particles/qsgwander/tst_qsgwander.cpp +++ /dev/null @@ -1,94 +0,0 @@ -/**************************************************************************** -** -** 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 test suite 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 -#include "../shared/particlestestsshared.h" -#include -#include - -class tst_qsgwander : public QObject -{ - Q_OBJECT -public: - tst_qsgwander(); - -private slots: - void test_basic(); -}; - -tst_qsgwander::tst_qsgwander() -{ - QUnifiedTimer::instance()->setConsistentTiming(true); -} - -void tst_qsgwander::test_basic() -{ - QQuickView* view = createView(QCoreApplication::applicationDirPath() + "/data/basic.qml", 600); - QSGParticleSystem* system = view->rootObject()->findChild("system"); - ensureAnimTime(600, system->m_animation); - - QCOMPARE(system->groupData[0]->size(), 500); - //Since Wander is random perturbations, the compromise between stability and actual testing is to hope that one of - //the 500 was randomly changed from 0.0 in velocity - bool vxChanged = false; - bool vyChanged = false; - foreach (QSGParticleData *d, system->groupData[0]->data) { - if (d->t == -1) - continue; //Particle data unused - - QCOMPARE(d->ax, 0.f); - QCOMPARE(d->ay, 0.f); - QCOMPARE(d->lifeSpan, 0.5f); - QCOMPARE(d->size, 32.f); - QCOMPARE(d->endSize, 32.f); - QVERIFY(myFuzzyLEQ(d->t, ((qreal)system->timeInt/1000.0))); - if (d->vx != 0.0f) - vxChanged = true; - if (d->vy != 0.0f) - vyChanged = true; - } - QVERIFY(vxChanged); - QVERIFY(vyChanged); -} - -QTEST_MAIN(tst_qsgwander); - -#include "tst_qsgwander.moc" diff --git a/tests/benchmarks/particles/affectors/tst_affectors.cpp b/tests/benchmarks/particles/affectors/tst_affectors.cpp index 18068b2be2..bd9e4e1d6c 100644 --- a/tests/benchmarks/particles/affectors/tst_affectors.cpp +++ b/tests/benchmarks/particles/affectors/tst_affectors.cpp @@ -83,7 +83,7 @@ void tst_affectors::test_basic() { QFETCH(int, dt); QQuickView* view = createView(QCoreApplication::applicationDirPath() + "/data/basic.qml"); - QSGParticleSystem* system = view->rootObject()->findChild("system"); + QQuickParticleSystem* system = view->rootObject()->findChild("system"); //Pretend we're running, but we manually advance the simulation system->m_running = true; system->m_animation = 0; @@ -99,7 +99,7 @@ void tst_affectors::test_basic() int stillAlive = 0; QVERIFY(extremelyFuzzyCompare(system->groupData[0]->size(), 1000, 10));//Small simulation variance is permissible. - foreach (QSGParticleData *d, system->groupData[0]->data) { + foreach (QQuickParticleData *d, system->groupData[0]->data) { if (d->t == -1) continue; //Particle data unused @@ -123,7 +123,7 @@ void tst_affectors::test_filtered() { QFETCH(int, dt); QQuickView* view = createView(QCoreApplication::applicationDirPath() + "/data/filtered.qml"); - QSGParticleSystem* system = view->rootObject()->findChild("system"); + QQuickParticleSystem* system = view->rootObject()->findChild("system"); //Pretend we're running, but we manually advance the simulation system->m_running = true; system->m_animation = 0; @@ -139,7 +139,7 @@ void tst_affectors::test_filtered() int stillAlive = 0; QVERIFY(extremelyFuzzyCompare(system->groupData[1]->size(), 1000, 10));//Small simulation variance is permissible. - foreach (QSGParticleData *d, system->groupData[1]->data) { + foreach (QQuickParticleData *d, system->groupData[1]->data) { if (d->t == -1) continue; //Particle data unused diff --git a/tests/benchmarks/particles/emission/tst_emission.cpp b/tests/benchmarks/particles/emission/tst_emission.cpp index 01e2476431..72944bcf4d 100644 --- a/tests/benchmarks/particles/emission/tst_emission.cpp +++ b/tests/benchmarks/particles/emission/tst_emission.cpp @@ -74,7 +74,7 @@ void tst_emission::test_basic() { QFETCH(int, dt); QQuickView* view = createView(QCoreApplication::applicationDirPath() + "/data/basic.qml"); - QSGParticleSystem* system = view->rootObject()->findChild("system"); + QQuickParticleSystem* system = view->rootObject()->findChild("system"); //Pretend we're running, but we manually advance the simulation system->m_running = true; system->m_animation = 0; @@ -92,7 +92,7 @@ void tst_emission::test_basic() int stillAlive = 0; QVERIFY(extremelyFuzzyCompare(system->groupData[0]->size(), 1000, 10));//Small simulation variance is permissible. - foreach (QSGParticleData *d, system->groupData[0]->data) { + foreach (QQuickParticleData *d, system->groupData[0]->data) { if (d->t == -1) continue; //Particle data unused -- cgit v1.2.3