From: Alan Alpert Date: Mon, 18 Jun 2012 04:13:31 +0000 (+1000) Subject: Update particles examples en masse X-Git-Tag: upstream/5.2.1~1549 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f4e75e134f5712156ad2b720b48265da683dda94;p=platform%2Fupstream%2Fqtdeclarative.git Update particles examples en masse Change-Id: I882f59c687d790bc55cf59abf6f0ea80b65b50d9 Reviewed-by: Alan Alpert --- diff --git a/doc/src/images/qml-customparticle-example.png b/doc/src/images/qml-customparticle-example.png new file mode 100644 index 0000000..e23c6c8 Binary files /dev/null and b/doc/src/images/qml-customparticle-example.png differ diff --git a/doc/src/images/qml-emitters-example.png b/doc/src/images/qml-emitters-example.png new file mode 100644 index 0000000..0025afd Binary files /dev/null and b/doc/src/images/qml-emitters-example.png differ diff --git a/doc/src/images/qml-imageparticle-example.png b/doc/src/images/qml-imageparticle-example.png new file mode 100644 index 0000000..9e44abe Binary files /dev/null and b/doc/src/images/qml-imageparticle-example.png differ diff --git a/doc/src/images/qml-system-example.png b/doc/src/images/qml-system-example.png new file mode 100644 index 0000000..1a317c4 Binary files /dev/null and b/doc/src/images/qml-system-example.png differ diff --git a/examples/particles/customparticle/blurparticles.qml b/examples/particles/customparticle/content/blurparticles.qml similarity index 97% rename from examples/particles/customparticle/blurparticles.qml rename to examples/particles/customparticle/content/blurparticles.qml index 9b432e0..c1ad03b 100644 --- a/examples/particles/customparticle/blurparticles.qml +++ b/examples/particles/customparticle/content/blurparticles.qml @@ -63,11 +63,12 @@ Rectangle { } Image { id: theItem - source: "../images/starfish_1.png" + source: "../../images/starfish_1.png" } CustomParticle { system: sys + //! [vertex] vertexShader:" uniform lowp float qt_Opacity; varying lowp float fFade; @@ -83,6 +84,7 @@ Rectangle { fBlur = max(0.2 * t, t * qt_ParticleR); } " + //! [vertex] property variant source: theSource property variant blurred: ShaderEffectSource { smooth: true @@ -125,6 +127,7 @@ Rectangle { }" } } + //! [fragment] fragmentShader: " uniform sampler2D source; uniform sampler2D blurred; @@ -134,6 +137,7 @@ Rectangle { void main() { gl_FragColor = mix(texture2D(source, qt_TexCoord0), texture2D(blurred, qt_TexCoord0), min(1.0,fBlur*3.0)) * fFade; }" + //! [fragment] } } diff --git a/examples/particles/customparticle/fragmentshader.qml b/examples/particles/customparticle/content/fragmentshader.qml similarity index 94% rename from examples/particles/customparticle/fragmentshader.qml rename to examples/particles/customparticle/content/fragmentshader.qml index 367cc99..e2f4f92 100644 --- a/examples/particles/customparticle/fragmentshader.qml +++ b/examples/particles/customparticle/content/fragmentshader.qml @@ -43,8 +43,8 @@ import QtQuick.Particles 2.0 ParticleSystem { id: root - width: 1024 - height: 768 + width: 320 + height: 480 Rectangle { z: -1 anchors.fill: parent @@ -52,7 +52,7 @@ ParticleSystem { Text { anchors.bottom: parent.bottom anchors.horizontalCenter: parent.horizontalCenter - font.pixelSize: 36 + font.pixelSize: 14 color: "white" text: "It's all in the fragment shader." } @@ -64,7 +64,6 @@ ParticleSystem { size: 24 sizeVariation: 16 velocity: PointDirection {x: root.width/10; y: root.height/10;} - //acceleration: AngledDirection {angle:225; magnitude: root.width/36; angleVariation: 45; magnitudeVariation: 80} acceleration: PointDirection {x: -root.width/40; y: -root.height/40; xVariation: -root.width/20; yVariation: -root.width/20} } @@ -97,9 +96,10 @@ ParticleSystem { highp float fadeOut = 1. - max(0., min((t - 0.75) * 4., 1.)); fFade = fadeIn * fadeOut * qt_Opacity; - fPos = vec2(pos.x/1024., pos.y/768.); + fPos = vec2(pos.x/320., pos.y/480.); } " + //! [0] fragmentShader: " varying highp vec2 fPos; varying lowp float fFade; @@ -110,6 +110,7 @@ ParticleSystem { highp float circleFactor = max(min(1.0 - dist, 1.0), 0.0); gl_FragColor = vec4(fPos.x*2.0 - fPos.y, fPos.y*2.0 - fPos.x, fPos.x*fPos.y*2.0, 0.0) * circleFactor * fFade; }" + //! [0] } } diff --git a/examples/particles/customparticle/imagecolors.qml b/examples/particles/customparticle/content/imagecolors.qml similarity index 87% rename from examples/particles/customparticle/imagecolors.qml rename to examples/particles/customparticle/content/imagecolors.qml index 94e5123..62345f7 100644 --- a/examples/particles/customparticle/imagecolors.qml +++ b/examples/particles/customparticle/content/imagecolors.qml @@ -62,7 +62,7 @@ Rectangle { } Image { id: picture - source: "../images/starfish_3.png" + source: "../../images/starfish_3.png" } ShaderEffectSource { id: particleSource @@ -71,8 +71,9 @@ Rectangle { } Image { id: particle - source: "../images/particle4.png" + source: "../../images/particle4.png" } + //! [vertex] vertexShader:" uniform highp float maxWidth; uniform highp float maxHeight; @@ -81,14 +82,20 @@ Rectangle { uniform lowp float qt_Opacity; void main() { - fTex2 = vec2(qt_ParticlePos.x / maxWidth, qt_ParticlePos.y / maxHeight); + + fTex2 = vec2(qt_ParticlePos.x, qt_ParticlePos.y); + //Uncomment this next line for each particle to use full texture, instead of the solid color at the center of the particle. + //fTex2 = fTex2 + ((- qt_ParticleData.z / 2. + qt_ParticleData.z) * qt_ParticleTex); //Adjusts size so it's like a chunk of image. + fTex2 = fTex2 / vec2(maxWidth, maxHeight); highp float t = (qt_Timestamp - qt_ParticleData.x) / qt_ParticleData.y; fFade = min(t*4., (1.-t*t)*.75) * qt_Opacity; defaultMain(); } " + //! [vertex] property variant particleTexture: particleSource property variant pictureTexture: pictureSource + //! [fragment] fragmentShader: " uniform sampler2D particleTexture; uniform sampler2D pictureTexture; @@ -98,6 +105,7 @@ Rectangle { void main() { gl_FragColor = texture2D(pictureTexture, fTex2) * texture2D(particleTexture, qt_TexCoord0).w * fFade; }" + //! [fragment] } Emitter { diff --git a/examples/particles/customparticle/customparticle.pro b/examples/particles/customparticle/customparticle.pro new file mode 100644 index 0000000..d26778f --- /dev/null +++ b/examples/particles/customparticle/customparticle.pro @@ -0,0 +1,10 @@ +TEMPLATE = app + +QT += quick qml +SOURCES += main.cpp + +target.path = $$[QT_INSTALL_EXAMPLES]/qtdeclarative/particles/customparticle +qml.files = customparticle.qml content +qml.path = $$[QT_INSTALL_EXAMPLES]/qtdeclarative/particles/customparticle +INSTALLS += target qml + diff --git a/examples/particles/customparticle/customparticle.qml b/examples/particles/customparticle/customparticle.qml new file mode 100644 index 0000000..cb2972b --- /dev/null +++ b/examples/particles/customparticle/customparticle.qml @@ -0,0 +1,84 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 +import "../../shared" as Examples + +/*! + \title QtQuick.Particles Examples - CustomParticle + \example particles/customparticle + \brief This is a collection of examples using CustomParticle in the QML particle system. + \image qml-customparticle-example.png + + This is a collection of small QML examples relating to using CustomParticle in the particle system. + Each example is a small QML file emphasizing a different way to use CustomParticle. + + Blur Particles adds a blur effect to the particles, which increases over the particle's life time. + It uses a custom vertex shader: + \snippet examples/particles/customparticle/content/blurparticles.qml vertex + to propagate life time simulation to a custom fragement shader: + \snippet examples/particles/customparticle/content/blurparticles.qml fragment + which has access to both the normal image sampler and a blurred sampler, the image plus a ShaderEffect. + + Fragment Shader just uses the particle system as a vertex delivery system. + \snippet examples/particles/customparticle/content/fragmentshader.qml 0 + + Image Colors uses CustomParticle to assign colors to particles based on their location in a picture. + The vertex shader, + \snippet examples/particles/customparticle/content/imagecolors.qml vertex + passes along the starting position for each vertex to the fragment shader, + \snippet examples/particles/customparticle/content/imagecolors.qml fragment + which uses it to determine the color for that particle. + +*/ + +Item { + height: 480 + width: 320 + Examples.LauncherList { + id: ll + anchors.fill: parent + Component.onCompleted: { + addExample("Blur Particles", "Particles that get blurred over time", Qt.resolvedUrl("content/blurparticles.qml")); + addExample("Fragment Shader", "Particles drawn with a custom fragment shader", Qt.resolvedUrl("content/fragmentshader.qml")); + addExample("Image Colors", "An image explodes into colored particles", Qt.resolvedUrl("content/imagecolors.qml")); + } + } +} diff --git a/examples/particles/customparticle/customparticle.qmlproject b/examples/particles/customparticle/customparticle.qmlproject new file mode 100644 index 0000000..6ea1849 --- /dev/null +++ b/examples/particles/customparticle/customparticle.qmlproject @@ -0,0 +1,16 @@ +import QmlProject 1.1 + +Project { + mainFile: "customparticle.qml" + + /* Include .qml, .js, and image files from current directory and subdirectories */ + QmlFiles { + directory: "." + } + JavaScriptFiles { + directory: "." + } + ImageFiles { + directory: "." + } +} diff --git a/examples/particles/customparticle/main.cpp b/examples/particles/customparticle/main.cpp new file mode 100644 index 0000000..f401c36 --- /dev/null +++ b/examples/particles/customparticle/main.cpp @@ -0,0 +1,41 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "../../shared/shared.h" +DECLARATIVE_EXAMPLE_MAIN(customparticle) diff --git a/examples/particles/emitters/burstandpulse.qml b/examples/particles/emitters/content/burstandpulse.qml similarity index 58% rename from examples/particles/emitters/burstandpulse.qml rename to examples/particles/emitters/content/burstandpulse.qml index c6d39b5..377ce9d 100644 --- a/examples/particles/emitters/burstandpulse.qml +++ b/examples/particles/emitters/content/burstandpulse.qml @@ -42,43 +42,69 @@ import QtQuick 2.0 import QtQuick.Particles 2.0 Rectangle { - width: 360 - height: 540 + width: 320 + height: 480 color: "black" - MouseArea { - id: ma - anchors.fill: parent - acceptedButtons: Qt.LeftButton | Qt.RightButton - onClicked: { - if (mouse.button == Qt.LeftButton) - emitter.burst(1000); - else - emitter.pulse(500); + property bool lastWasPulse: false + Timer { + interval: 3500 + triggeredOnStart: true + running: true + repeat: true + onTriggered: { + //! [0] + if (lastWasPulse) { + burstEmitter.burst(500); + lastWasPulse = false; + } else { + pulseEmitter.pulse(500); + lastWasPulse = true; + } + //! [0] } } - ParticleSystem { id: particles - } - - ImageParticle { anchors.fill: parent - system: particles - source: "../images/star.png" - alpha: 0 - colorVariation: 0.6 - } + ImageParticle { + source: "../../images/star.png" + alpha: 0 + colorVariation: 0.6 + } - Emitter { - id: emitter - x: ma.mouseX - y: ma.mouseY - system: particles - emitRate: 2000 - lifeSpan: 2000 - enabled: false - velocity: AngleDirection{magnitude: 64; angleVariation: 360} - size: 24 - sizeVariation: 8 + Emitter { + id: burstEmitter + x: parent.width/2 + y: parent.height/3 + emitRate: 1000 + lifeSpan: 2000 + enabled: false + velocity: AngleDirection{magnitude: 64; angleVariation: 360} + size: 24 + sizeVariation: 8 + Text { + anchors.centerIn: parent + color: "white" + font.pixelSize: 18 + text: "Burst" + } + } + Emitter { + id: pulseEmitter + x: parent.width/2 + y: 2*parent.height/3 + emitRate: 1000 + lifeSpan: 2000 + enabled: false + velocity: AngleDirection{magnitude: 64; angleVariation: 360} + size: 24 + sizeVariation: 8 + Text { + anchors.centerIn: parent + color: "white" + font.pixelSize: 18 + text: "Pulse" + } + } } } diff --git a/examples/particles/emitters/customemitter.qml b/examples/particles/emitters/content/customemitter.qml similarity index 95% rename from examples/particles/emitters/customemitter.qml rename to examples/particles/emitters/content/customemitter.qml index 135b3d7..baa513b 100644 --- a/examples/particles/emitters/customemitter.qml +++ b/examples/particles/emitters/content/customemitter.qml @@ -68,6 +68,7 @@ ParticleSystem { emitRate: 120 size: 12 anchors.centerIn: parent + //! [0] onEmitParticles: { for (var i=0; i 0) { var item = fakeParticle.createObject(root); item.lifeSpan = Math.random() * 5000 + 5000; - item.x = Math.random() * 320 + 320; + item.x = Math.random() * (root.width/2) + (root.width/2); item.y = 0; number--; } @@ -89,9 +90,9 @@ Rectangle { property int lifeSpan: 10000 width: 32 height: 32 - source: "../images/particle.png" + source: "../../images/particle.png" y: 0 - PropertyAnimation on y {from: -16; to: 480-16; duration: container.lifeSpan; running: true} + PropertyAnimation on y {from: -16; to: root.height-16; duration: container.lifeSpan; running: true} SequentialAnimation on opacity { running: true NumberAnimation { from:0; to: 1; duration: 500} @@ -102,7 +103,19 @@ Rectangle { } } } + //! [fake] + //Hooked to a timer, but click for extra bursts that really stress performance + Timer { + interval: 10000 + triggeredOnStart: true + repeat: true + running: true + onTriggered: { + emitter.burst(1000); + fakeEmitter.burst(1000); + } + } Text { anchors.left: parent.left anchors.bottom: parent.bottom diff --git a/examples/particles/simple/dynamicemitters.qml b/examples/particles/system/content/dynamicemitters.qml similarity index 79% rename from examples/particles/simple/dynamicemitters.qml rename to examples/particles/system/content/dynamicemitters.qml index 8f007f3..5fa4960 100644 --- a/examples/particles/simple/dynamicemitters.qml +++ b/examples/particles/system/content/dynamicemitters.qml @@ -51,7 +51,7 @@ Rectangle { } ImageParticle { system: sys - source: "../images/particle.png" + source: "../../images/particle.png" color: "white" colorVariation: 1.0 alpha: 0.1 @@ -104,19 +104,37 @@ Rectangle { } } + function customEmit(x,y) { + //! [0] + for (var i=0; i<8; i++) { + var obj = emitterComp.createObject(root); + obj.x = x + obj.y = y + obj.targetX = Math.random() * 240 - 120 + obj.x + obj.targetY = Math.random() * 240 - 120 + obj.y + obj.life = Math.round(Math.random() * 2400) + 200 + obj.emitRate = Math.round(Math.random() * 32) + 32 + obj.go(); + } + //! [0] + } + + Timer { + interval: 10000 + triggeredOnStart: true + running: true + repeat: true + onTriggered: customEmit(Math.random() * 320, Math.random() * 480) + } MouseArea { anchors.fill: parent - onClicked: { - for (var i=0; i<8; i++) { - var obj = emitterComp.createObject(root); - obj.x = mouse.x - obj.y = mouse.y - obj.targetX = Math.random() * 240 - 120 + obj.x - obj.targetY = Math.random() * 240 - 120 + obj.y - obj.life = Math.round(Math.random() * 2400) + 200 - obj.emitRate = Math.round(Math.random() * 32) + 32 - obj.go(); - } - } + onClicked: customEmit(mouse.x, mouse.y); + } + + Text { + anchors.horizontalCenter: parent.horizontalCenter + text: "Click Somewhere" + color: "white" + font.pixelSize: 24 } } diff --git a/examples/particles/simple/multiplepainters.qml b/examples/particles/system/content/multiplepainters.qml similarity index 90% rename from examples/particles/simple/multiplepainters.qml rename to examples/particles/system/content/multiplepainters.qml index 62a2548..e2f9f17 100644 --- a/examples/particles/simple/multiplepainters.qml +++ b/examples/particles/system/content/multiplepainters.qml @@ -54,6 +54,12 @@ Rectangle { anchors.fill: parent onClicked: cloneMode = !cloneMode; } + Text { + anchors.horizontalCenter: parent.horizontalCenter + text: "Click to Toggle" + color: "white" + font.pixelSize: 24 + } Emitter { system: sys y:root.height + 20 @@ -67,14 +73,14 @@ Rectangle { ImageParticle { system: sys visible: !cloneMode - source: "../images/particle2.png" + source: "../../images/particle2.png" } ImageParticle { system: sys visible: cloneMode z: 0 - source: "../images/particle3.png" + source: "../../images/particle3.png" } ImageParticle { @@ -85,6 +91,6 @@ Rectangle { height: 240 width: root.width z: 1 - source: "../images/particle.png" + source: "../../images/particle.png" } } diff --git a/examples/particles/simple/startstop.qml b/examples/particles/system/content/startstop.qml similarity index 92% rename from examples/particles/simple/startstop.qml rename to examples/particles/system/content/startstop.qml index 62105b2..501d206 100644 --- a/examples/particles/simple/startstop.qml +++ b/examples/particles/system/content/startstop.qml @@ -45,6 +45,11 @@ Rectangle { width: 360 height: 540 color: "black" + Text { + text: "Left click to start/stop\nRight click to pause/unpause" + color: "white" + font.pixelSize: 24 + } MouseArea { anchors.fill: parent acceptedButtons: Qt.LeftButton | Qt.RightButton @@ -64,8 +69,8 @@ Rectangle { ImageParticle { anchors.fill: parent system: particles - source: "../images/star.png" - sizeTable: "../images/sparkleSize.png" + source: "../../images/star.png" + sizeTable: "../../images/sparkleSize.png" alpha: 0 colorVariation: 0.6 } diff --git a/examples/particles/emitters/timedgroupchanges.qml b/examples/particles/system/content/timedgroupchanges.qml similarity index 96% rename from examples/particles/emitters/timedgroupchanges.qml rename to examples/particles/system/content/timedgroupchanges.qml index 84e8cc0..8d6961b 100644 --- a/examples/particles/emitters/timedgroupchanges.qml +++ b/examples/particles/system/content/timedgroupchanges.qml @@ -48,12 +48,15 @@ Rectangle { ParticleSystem { anchors.fill: parent id: syssy + //! [0] ParticleGroup { name: "fire" duration: 2000 durationVariation: 2000 to: {"splode":1} } + //! [0] + //! [1] ParticleGroup { name: "splode" duration: 400 @@ -68,6 +71,8 @@ Rectangle { acceleration: PointDirection {y:100; yVariation: 20} } } + //! [1] + //! [2] ParticleGroup { name: "dead" duration: 1000 @@ -76,6 +81,7 @@ Rectangle { onAffected: worksEmitter.burst(400,x,y) } } + //! [2] Timer { interval: 6000 @@ -113,7 +119,7 @@ Rectangle { ImageParticle { groups: ["works", "fire", "splode"] - source: "../images/particle.png" + source: "../../images/particle.png" entryEffect: ImageParticle.Scale } } diff --git a/examples/particles/system/main.cpp b/examples/particles/system/main.cpp new file mode 100644 index 0000000..724d598 --- /dev/null +++ b/examples/particles/system/main.cpp @@ -0,0 +1,41 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "../../shared/shared.h" +DECLARATIVE_EXAMPLE_MAIN(system) diff --git a/examples/particles/system/system.pro b/examples/particles/system/system.pro new file mode 100644 index 0000000..613abfa --- /dev/null +++ b/examples/particles/system/system.pro @@ -0,0 +1,10 @@ +TEMPLATE = app + +QT += quick qml +SOURCES += main.cpp + +target.path = $$[QT_INSTALL_EXAMPLES]/qtdeclarative/particles/system +qml.files = system.qml content +qml.path = $$[QT_INSTALL_EXAMPLES]/qtdeclarative/particles/system +INSTALLS += target qml + diff --git a/examples/particles/system/system.qml b/examples/particles/system/system.qml new file mode 100644 index 0000000..acc9870 --- /dev/null +++ b/examples/particles/system/system.qml @@ -0,0 +1,90 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/ +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor +** the names of its contributors may be used to endorse or promote +** products derived from this software without specific prior written +** permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 +import "../../shared" as Examples + +/*! + \title QtQuick.Particles Examples - Affectors + \example particles/system + \brief This is a collection of examples using Affectors in the QML particle system. + \image qml-system-example.png + + This is a collection of small QML examples relating to using Affectors in the particle system. + Each example is a small QML file emphasizing a particular element or feature. + + Dynamic comparison compares using the particle system to getting a similar effect with the following code that dynamically instantiates Image elements. + \snippet examples/particles/system/content/dynamiccomparison.qml fake + Note how the Image elements are not able to be randomly colorized. + + Start and Stop simply sets the running and paused states of a ParticleSystem. While the system does not perform any simulation when stopped or paused, a restart restarts the simulation from the beginning, while unpausing resumes the simulation from where it was. + + Timed group changes is an example that highlights the ParticleGroup element. While normally referring to groups with a string name is sufficent, additional effects can be + done by setting properties on groups. + The first group has a variable duration on it, but always transitions to the second group. + \snippet examples/particles/system/content/timedgroupchanges.qml 0 + The second group has a TrailEmitter on it, and a fixed duration for emitting into the third group. By placing the TrailEmitter as a direct child of the ParticleGroup, it automatically selects that group to follow. + \snippet examples/particles/system/content/timedgroupchanges.qml 1 + The third group has an Affector as a direct child, which makes the affector automatically target this group. The affector means that as soon as particles enter this group, a burst function can be called on another emitter, using the x,y positions of this particle. + \snippet examples/particles/system/content/timedgroupchanges.qml 2 + + If TrailEmitter does not suit your needs for multiple emitters, you can also dynamically create Emitters while still using the same ParticleSystem and image particle + \snippet examples/particles/system/content/dynamicemitters.qml 0 + Note that this effect, a flurry of flying rainbow spears, would be better served with TrailEmitter. It is only done with dynamic emitters in this example to show the concept more simply. + + Multiple Painters shows how to control paint ordering of individual particles. While the paint ordering of particles within one ImagePainter is not strictly defined, ImageParticle elements follow the normal Z-ordering rules for QtQuick items. This example allow you to paint the inside of the particles above the black borders using a pair of ImageParticles each painting different parts of the same logical particle. + +*/ + +Item { + height: 480 + width: 320 + Examples.LauncherList { + id: ll + anchors.fill: parent + Component.onCompleted: { + addExample("Dynamic Comparison", "Compares with dynamically created elements", Qt.resolvedUrl("content/dynamiccomparison.qml")); + addExample("StartStop", "Start and stop the simulation", Qt.resolvedUrl("content/startstop.qml")); + addExample("Timed group changes", "Emit into managed groups", Qt.resolvedUrl("content/timedgroupchanges.qml")); + addExample("Dynamic Emitters", "Dynamically instantiated emitters with a single system", Qt.resolvedUrl("content/dynamicemitters.qml")); + addExample("Multiple Painters", "Several ParticlePainters on the same logical particles", Qt.resolvedUrl("content/multiplepainters.qml")); + } + } +} diff --git a/examples/particles/system/system.qmlproject b/examples/particles/system/system.qmlproject new file mode 100644 index 0000000..1f9df3c --- /dev/null +++ b/examples/particles/system/system.qmlproject @@ -0,0 +1,16 @@ +import QmlProject 1.1 + +Project { + mainFile: "system.qml" + + /* Include .qml, .js, and image files from current directory and subdirectories */ + QmlFiles { + directory: "." + } + JavaScriptFiles { + directory: "." + } + ImageFiles { + directory: "." + } +}