aboutsummaryrefslogtreecommitdiffstats
path: root/DemoApplication/pages/Page4.qml
blob: 47828dd8d121e06469aea6c3961b982074ab3469 (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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import QtQuick 2.0
import CursorNavigation 1.0
import QtGamepad 1.0
import "../controls"

Item {
    //CursorNavigation.acceptsCursor: true

    Timer {
        id: cooldownTimer
        interval: 500
        repeat: false
    }

    Rectangle {
        id: pointerRect
        border.color: "orange"
        border.width: 1
        visible: false
        color: "transparent"
    }

    Gamepad {
        deviceId: GamepadManager.connectedGamepads.length > 0 ? GamepadManager.connectedGamepads[0] : -1

        function handleMove() {
            var v = Qt.vector2d(axisLeftX, axisLeftY)
            if (v.length() >= 0.99 && !cooldownTimer.running) {
                //console.log("handle joystick move, v=" + v)
                parent.CursorNavigation.move(Qt.vector2d(axisLeftX, axisLeftY), 10)
                cooldownTimer.start()
            } else if (v.length() >= 0.1) {
                parent.CursorNavigation.setMagnitude(v)
                var item = parent.CursorNavigation.find(v, 10)
                //cooldownTimer.start()
                if (item != undefined) {
                    pointerRect.x = item.x
                    pointerRect.y = item.y
                    pointerRect.width = item.width
                    pointerRect.height = item.height
                    pointerRect.visible = true
                }
            } else {
                parent.CursorNavigation.setMagnitude(0,0)
                pointerRect.visible = false
            }
        }

        onAxisLeftXChanged: handleMove()
        onAxisLeftYChanged: handleMove()
    }

    CNButton {
        id: cNButton
        x: 20
        y: 20
    }

    CNButton {
        id: cNButton1
        x: 20
        y: 120
    }

    CNButton {
        id: cNButton2
        x: 20
        y: 220
    }

    CNButton {
        id: cNButton3
        x: 150
        y: 20
    }

    CNButton {
        id: cNButton4
        x: 150
        y: 120
    }

    CNButton {
        id: cNButton5
        x: 150
        y: 220
        focus: true
    }

    CNButton {
        id: cNButton6
        x: 280
        y: 20
    }

    CNButton {
        id: cNButton7
        x: 280
        y: 120
    }

    CNButton {
        id: cNButton8
        x: 280
        y: 220
    }

}