Change burst to use ms instead of s
authorAlan Alpert <alan.alpert@nokia.com>
Thu, 22 Sep 2011 05:11:28 +0000 (15:11 +1000)
committerQt by Nokia <qt-info@nokia.com>
Thu, 22 Sep 2011 05:22:15 +0000 (07:22 +0200)
Also renames that variable, and adds a burst example.

Change-Id: I53787612f287e71d9afb5618bd445c8aa72fd39e
Reviewed-on: http://codereview.qt-project.org/5349
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Martin Jones <martin.jones@nokia.com>

examples/declarative/particles/emitters/burstandpulse.qml [new file with mode: 0644]
src/declarative/particles/qsgparticleemitter.cpp
src/declarative/particles/qsgparticleemitter_p.h
src/declarative/particles/qsgtrailemitter.cpp

diff --git a/examples/declarative/particles/emitters/burstandpulse.qml b/examples/declarative/particles/emitters/burstandpulse.qml
new file mode 100644 (file)
index 0000000..44c90f3
--- /dev/null
@@ -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 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 QtQuick.Particles 2.0
+
+Rectangle {
+    width: 360
+    height: 540
+    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);
+        }
+    }
+
+    ParticleSystem {
+        id: particles
+    }
+
+    ImageParticle {
+        anchors.fill: parent
+        system: particles
+        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
+        speed: AngleDirection{magnitude: 64; angleVariation: 360}
+        size: 24
+        sizeVariation: 8
+    }
+}
index e1a7ef2..bdd008a 100644 (file)
@@ -206,9 +206,9 @@ QT_BEGIN_NAMESPACE
     as if the Emitter was positioned at x,y but all other properties are the same.
 */
 
-/*! \qmlmethod QtQuick.Particles2::Emitter::pulse(real duration)
+/*! \qmlmethod QtQuick.Particles2::Emitter::pulse(int duration)
 
-    If the emitter is not enabled, enables it for duration seconds and then switches
+    If the emitter is not enabled, enables it for duration milliseconds and then switches
     it back off.
 */
 
@@ -227,7 +227,7 @@ QSGParticleEmitter::QSGParticleEmitter(QSGItem *parent) :
   , m_particleEndSize(-1)
   , m_particleSizeVariation(0)
   , m_startTime(0)
-  , m_burstLeft(0)
+  , m_pulseLeft(0)
   , m_maxParticleCount(-1)
   , m_speed_from_movement(0)
   , m_reset_last(true)
@@ -282,12 +282,12 @@ QSGParticleExtruder* QSGParticleEmitter::effectiveExtruder()
     return m_defaultExtruder;
 }
 
-void QSGParticleEmitter::pulse(qreal seconds)
+void QSGParticleEmitter::pulse(int milliseconds)
 {
     if (!particleCount())
         qWarning() << "pulse called on an emitter with a particle count of zero";
     if (!m_enabled)
-        m_burstLeft = seconds*1000.0;//TODO: Change name to match
+        m_pulseLeft = milliseconds;
 }
 
 void QSGParticleEmitter::burst(int num)
@@ -348,7 +348,7 @@ void QSGParticleEmitter::emitWindow(int timeStamp)
 {
     if (m_system == 0)
         return;
-    if ((!m_enabled || !m_particlesPerSecond)&& !m_burstLeft && m_burstQueue.isEmpty()){
+    if ((!m_enabled || !m_particlesPerSecond)&& !m_pulseLeft && m_burstQueue.isEmpty()){
         m_reset_last = true;
         return;
     }
@@ -364,12 +364,12 @@ void QSGParticleEmitter::emitWindow(int timeStamp)
         m_emitCap = particleCount();
     }
 
-    if (m_burstLeft){
-        m_burstLeft -= timeStamp - m_last_timestamp * 1000.;
-        if (m_burstLeft < 0){
+    if (m_pulseLeft){
+        m_pulseLeft -= timeStamp - m_last_timestamp * 1000.;
+        if (m_pulseLeft < 0){
             if (!m_enabled)
-                timeStamp += m_burstLeft;
-            m_burstLeft = 0;
+                timeStamp += m_pulseLeft;
+            m_pulseLeft = 0;
         }
     }
     qreal time = timeStamp / 1000.;
@@ -395,7 +395,7 @@ void QSGParticleEmitter::emitWindow(int timeStamp)
     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_burstLeft && !m_enabled)//'outside time' emissions only
+    if (!m_burstQueue.isEmpty() && !m_pulseLeft && !m_enabled)//'outside time' emissions only
         pt = time;
 
     QList<QSGParticleData*> toEmit;
index 11c79ec..8a41cb6 100644 (file)
@@ -154,7 +154,7 @@ signals:
     void startTimeChanged(int arg);
 
 public slots:
-    void pulse(qreal seconds);
+    void pulse(int milliseconds);
     void burst(int num);
     void burst(int num, qreal x, qreal y);
 
@@ -322,7 +322,7 @@ protected:
        int m_startTime;
        bool m_overwrite;
 
-       int m_burstLeft;//TODO: Rename to pulse
+       int m_pulseLeft;
        QList<QPair<int, QPointF > > m_burstQueue;
        int m_maxParticleCount;
 
index e819663..51d9875 100644 (file)
@@ -139,7 +139,7 @@ void QSGTrailEmitter::emitWindow(int timeStamp)
 {
     if (m_system == 0)
         return;
-    if (!m_enabled && !m_burstLeft && m_burstQueue.isEmpty())
+    if (!m_enabled && !m_pulseLeft && m_burstQueue.isEmpty())
         return;
     if (m_followCount != m_system->m_groupData[m_system->m_groupIds[m_follow]]->size()){
         qreal oldPPS = m_particlesPerSecond;
@@ -148,11 +148,11 @@ void QSGTrailEmitter::emitWindow(int timeStamp)
             return;//system may need to update
     }
 
-    if (m_burstLeft){
-        m_burstLeft -= timeStamp - m_lastTimeStamp * 1000.;
-        if (m_burstLeft < 0){
-            timeStamp += m_burstLeft;
-            m_burstLeft = 0;
+    if (m_pulseLeft){
+        m_pulseLeft -= timeStamp - m_lastTimeStamp * 1000.;
+        if (m_pulseLeft < 0){
+            timeStamp += m_pulseLeft;
+            m_pulseLeft = 0;
         }
     }