summaryrefslogtreecommitdiffstats
path: root/examples/declarative/snow/snow.qml
blob: f65e0ac5e2b3db29cf3c0ab1e9699f2e7ee602e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
Rect {
    id: ImagePanel
    width: 1024
    height: 768
    color: "black"

    property int maximumColumn: 4
    property int selectedItemRow: 0
    property int selectedItemColumn: 0

    Script { source: "create.js" }

    onSelectedItemColumnChanged: if (selectedItemColumn == maximumColumn) createNewBlock();

    property int imageWidth: 200
    property int imageHeight: 200

    property int selectedX: selectedItemColumn * imageWidth
    property int selectedY: selectedItemRow * imageHeight

    Item {
        anchors.centeredIn: parent
        HorizontalLayout {
            id: MyLayout
            property real targetX: -(selectedX + imageWidth / 2)

            property real targetDeform: 0
            property bool slowDeform: true

            property real deform: 0
            deform: Follow {
                id: "DeformFollow"; source: MyLayout.targetDeform; velocity: MyLayout.slowDeform?0.1:2
                onSyncChanged: if(inSync) { MyLayout.slowDeform = true; MyLayout.targetDeform = 0; }
            }
                
            ImageBatch { offset: 0; ref: ImagePanel }

            x: Follow { source: MyLayout.targetX; velocity: 1000 }
            y: Follow { source: -(selectedY + imageHeight / 2); velocity: 500 }
        }

        transform: Rotation3D { 
            axis { startX: 0; startY: 0; endX: 0; endY: 1 }
            angle: MyLayout.deform * 100
        }
    }

    Script {
        function leftPressed() {
            if (selectedItemColumn <= 0) return;
            selectedItemColumn -= 1;
            MyLayout.slowDeform = false;
            MyLayout.targetDeform = Math.max(Math.min(MyLayout.deform - 0.1, -0.1), -0.4);
        }
        function rightPressed() {
            selectedItemColumn += 1;
            MyLayout.slowDeform = false;
            MyLayout.targetDeform = Math.min(Math.max(MyLayout.deform + 0.1, 0.1), 0.4);
        }
    }
    KeyActions {
        focus: true
        leftArrow: "leftPressed()"
        rightArrow: "rightPressed()"
        upArrow: "if (selectedItemRow > 0) selectedItemRow = selectedItemRow - 1"
        downArrow: "if (selectedItemRow < 3) selectedItemRow = selectedItemRow + 1"
    }
}