Parcourir la source

Introduce basic viewmode sans box2d

Change-Id: Id8e65e5b8bf24bcc537b37bc5d2191f371fa7e6b
Donald Carr il y a 9 ans
Parent
commit
4835a6afec
4 fichiers modifiés avec 183 ajouts et 35 suppressions
  1. 133 0
      qml/basic/Basic.qml
  2. 37 4
      qml/main.qml
  3. 12 31
      qml/physics/Physics.qml
  4. 1 0
      qml/qml.qrc

+ 133 - 0
qml/basic/Basic.qml

@@ -0,0 +1,133 @@
+import QtQuick 2.5
+import Box2D 2.0
+import Qt.labs.settings 1.0
+
+import "../effects"
+
+Item {
+    id: root
+
+    signal togglePause
+    signal next
+
+    property var pictureDelegate: Component {
+        Image {
+            property var effect
+
+            fillMode: Image.PreserveAspectFit
+            source: imageModel.randomPicture()
+            width: parent.width
+            mirror: generalSettings.randomlyMirrorArt && (Math.random() < 0.5)
+            smooth: generalSettings.smoothArt
+
+            sourceSize.height: height
+            sourceSize.width: width
+        }
+    }
+
+    property var effectDelegate: Qt.createComponent("../VisualEffect.qml")
+
+    anchors.fill: parent
+
+    Settings {
+        id: basicSettings
+        category: "Basic"
+
+        property int animationDuration: 2000
+        property int easingType: Easing.Linear
+    }
+
+    Component {
+        id: columnComponent
+
+        Item {
+            id: column
+
+            x: width * index
+            height: parent.height
+            width: parent.width/generalSettings.columnCount
+
+            Item {
+                id: artworkStack
+
+                property var headElement
+                property var pictureArray: []
+                property int artworkHeight: 0
+                property int compoundArtworkHeight: 0
+                property bool full: artworkHeight > root.height
+
+                height: childrenRect.height
+                width: parent.width
+
+                function addImage() {
+                    var image = pictureDelegate.createObject(artworkStack)
+
+                    if (generalSettings.effect !== "" && Effects.validate(generalSettings.effect)) {
+                        image.effect = effectDelegate.createObject(artworkStack, { target: image, effect: generalSettings.effect })
+                    }
+
+                    artworkHeight += image.height
+                    compoundArtworkHeight += image.height
+                    image.y = root.height - compoundArtworkHeight
+
+                    pictureArray.push(image)
+                    itemCount++
+                }
+
+                function removeImage(image) {
+                    if (image.effect) {
+                        image.effect.destroy()
+                    }
+                    image.destroy()
+                    itemCount--
+                }
+
+                function shift() {
+                    if (headElement) {
+                        headElement.destroy()
+                    }
+                    headElement = pictureArray.shift()
+                    artworkHeight -= headElement.height
+                    artworkStack.y += headElement.height
+                }
+
+                Timer {
+                    id: populateTimer
+                    running: !artworkStack.full
+                    repeat: true
+                    interval: 100*Math.random() + 100
+                    onTriggered: artworkStack.addImage()
+                }
+
+                Timer {
+                    id: deathTimer
+                    running: artworkStack.full
+                    repeat: true
+                    interval: globalVars.adjustedInterval
+                    onTriggered: artworkStack.shift()
+                }
+
+                Behavior on y {
+                    NumberAnimation {
+                        duration: Math.min(globalVars.adjustedInterval, basicSettings.animationDuration)
+                        easing.type: basicSettings.easingType
+                    }
+                }
+            }
+
+            Connections {
+                target: root
+                onTogglePause: deathTimer.running = !deathTimer.running
+                onNext: deathTimer.triggered()
+            }
+        }
+    }
+
+    Repeater {
+        model: generalSettings.columnCount
+        delegate: columnComponent
+    }
+
+    Keys.onUpPressed: root.togglePause()
+    Keys.onDownPressed: root.next()
+}

+ 37 - 4
qml/main.qml

@@ -2,7 +2,7 @@ import QtQuick 2.5
 import QtQuick.Window 2.2
 import Qt.labs.settings 1.0
 
-import "physics"
+import "basic"
 
 Window {
     id: appWindow
@@ -10,12 +10,26 @@ Window {
     width: 1024
     height: 768
 
+    property int itemCount
+
+    function reset() {
+        itemCount = 0
+    }
+
+    QtObject {
+        id: globalVars
+        property int adjustedInterval: 1000*(generalSettings.interval > 60 ? 60*(generalSettings.interval-60) : generalSettings.interval)*(Math.random()+1)
+    }
+
     Settings {
         id: generalSettings
         property int columnCount: 5
         property int interval: 5
         property bool viewItemCount: false
         property string effect: ""
+        property bool smoothArt: false
+        property bool randomlyMirrorArt: true
+        onColumnCountChanged: reset()
     }
 
     Rectangle {
@@ -24,7 +38,7 @@ Window {
         anchors.fill: parent
         Keys.forwardTo: [punk, toplevelhandler]
 
-        Physics {
+        Basic {
             // TODO: generalize all this
             id: punk
         }
@@ -38,13 +52,14 @@ Window {
     }
 
     Rectangle {
-        visible: imageModel.rowCount() === 0
-
         function checkModel() {
             visible = (imageModel.rowCount() === 0)
         }
 
+        z: 1
+        visible: imageModel.rowCount() === 0
         color: "red"
+
         width: childrenRect.width
         height: childrenRect.height
         anchors { bottom: parent.bottom; horizontalCenter: parent.horizontalCenter }
@@ -57,5 +72,23 @@ Window {
         Component.onCompleted: modelRelay.countChanged.connect(checkModel);
     }
 
+    Rectangle {
+        z: 1
+        opacity: 0.5
+        visible: generalSettings.viewItemCount
+        color: "black"
+
+        anchors { right: parent.right; top: parent.top }
+        width: itemCountLabel.width
+        height: itemCountLabel.height
+
+        Text {
+            id: itemCountLabel
+            font.pixelSize: 100
+            text: itemCount
+            color: "white"
+        }
+    }
+
     Component.onCompleted: showFullScreen()
 }

+ 12 - 31
qml/physics/Physics.qml

@@ -30,7 +30,6 @@ Item {
     QtObject {
         id: d
         property real pace: physicsSettings.pace/60.0
-        property int itemCount: 0
         property int itemTravel: physicsSettings.itemTravel
         property int primedColumns: 0
         property int columnCount: generalSettings.columnCount
@@ -39,7 +38,6 @@ Item {
         property string effect: generalSettings.effect
 
         function reset() {
-            itemCount = 0
             primedColumns = 0
         }
 
@@ -65,13 +63,8 @@ Item {
             property int stackHeight: 0
             property bool full: false
             property int xOffset: width * index
-
-            onStackHeightChanged: {
-                if (!column.full && (stackHeight > root.height)) {
-                    d.primedColumns += 1
-                    column.full = true
-                }
-            }
+            property var pictureArray: []
+            property bool fixedRotation: true
 
             function considerImage() {
                 if (stackHeight < (1.3 + 1/d.columnCount)*root.height) {
@@ -93,7 +86,7 @@ Item {
                 image.y = floor.y - stackHeight
 
                 pictureArray.push(image)
-                d.itemCount++
+                itemCount++
             }
 
             function removeImage(image) {
@@ -102,7 +95,7 @@ Item {
                 }
                 stackHeight -= (image.height + d.itemTravel)
                 image.destroy()
-                d.itemCount--
+                itemCount--
             }
 
             function shiftImageToLimbo() {
@@ -113,13 +106,16 @@ Item {
                 }
             }
 
-            width: parent.width/d.columnCount
+            onStackHeightChanged: {
+                if (!column.full && (stackHeight > root.height)) {
+                    d.primedColumns += 1
+                    column.full = true
+                }
+            }
 
+            width: parent.width/d.columnCount
             anchors { top: parent.top; bottom: parent.bottom }
 
-            property var pictureArray: []
-            property bool fixedRotation: true
-
             World {
                 id: isolatedWorld
                 timeStep: d.pace
@@ -154,7 +150,7 @@ Item {
                 id: deathTimer
                 running: d.running
                 repeat: true
-                interval: 1000*(generalSettings.interval > 60 ? 60*(generalSettings.interval-60) : generalSettings.interval)*(Math.random()+1)
+                interval: globalVars.adjustedInterval
                 onTriggered: shiftImageToLimbo()
             }
 
@@ -227,21 +223,6 @@ Item {
         }
     }
 
-    Rectangle {
-        visible: generalSettings.viewItemCount
-        z: 1
-        color: "black"
-        anchors { right: parent.right; top: parent.top }
-        width: itemCountLabel.width
-        height: itemCountLabel.height
-        Text {
-            id: itemCountLabel
-            font.pixelSize: 100
-            text: d.itemCount
-            color: "white"
-        }
-    }
-
     Keys.onUpPressed: root.togglePause()
     Keys.onDownPressed: root.toggleChaos() //root.next()
 

+ 1 - 0
qml/qml.qrc

@@ -7,6 +7,7 @@
         <file>physics/RectangleBoxBody.qml</file>
         <file>physics/HorizontalArtDelegate.qml</file>
         <file>physics/Physics.qml</file>
+        <file>basic/Basic.qml</file>
         <file>effects/Effect.qml</file>
         <file>effects/Billboard.qml</file>
         <file>effects/Emboss.qml</file>