0.2 version add desktop components multitouch, joystick, multicast
[mardrone] / mardrone / JoyStickTouch.qml
1 import QtQuick 1.0
2 import TouchArea 1.0
3
4 Item {
5         id:joystick
6         property int xv:(knob.x-(width-knob.width)/2)*(200/(width-knob.width))
7         property int yv:(knob.y-(height-knob.height)/2)*(200/(height-knob.height))
8         property bool pressed:false
9         property int touchPointId:-1
10         property bool touchmode:false
11         property url joyBackground:"joybox.png"
12         width: 200
13         height: 200
14
15         Rectangle {
16             id:knob
17             x:parent.width/2-width/2
18             y:parent.width/2-height/2
19             width:20;
20             height:20;
21             Image {
22                 anchors.centerIn:parent
23                 id: knobimage
24                 source: "joyknob.png"
25             }
26         }
27
28         TouchArea {
29                 id: joyarea
30                 anchors.fill:parent
31                 minimumTouches: 1
32                 maximumTouches: 1
33
34                 onTouchStart: {
35                 //    console.log("TouchArea:ontouchStart " + joyarea.touches.length);
36                     var touch = joyarea.touches[0];
37                 //    console.log("touchStart",touch.id," at ",touch.y,touch.x,stick.x);
38                     knob.x=touch.x;
39                     knob.y=touch.y;
40                     pressed=true;
41                     touchmode=true
42                 }
43                 onTouchMove: {
44                //     console.log("TouchArea:ontouchMove " + joyarea.changedTouches.length);
45                     var touch = joyarea.changedTouches[0];
46                 //    console.log("touchMove",touch.id," at ",touch.y,touch.x);
47                     knob.x=touch.x;
48                     knob.y=touch.y;
49                 }
50
51                 onTouchEnd: {
52                 //    console.log("TouchArea:ontouchEnd " + joyarea.releasedTouches.length);
53                    var touch = joyarea.releasedTouches[0];
54                 //    console.log("JoyStick:touchEnd",touch.x,touch.y)
55                     knob.x=width/2-knob.width/2
56                     knob.y=width/2-knob.height/2
57                     pressed=false;
58
59                 }
60         }
61         MouseArea {
62             id:mouse_area
63             visible:!touchmode
64             anchors.fill:parent
65             drag.minimumX:0
66             drag.minimumY:0
67             drag.maximumX:parent.width-knob.width
68             drag.maximumY:parent.height-knob.height
69             drag.target:knob;
70             onReleased:{
71                 knob.x=parent.width/2-knob.width/2;
72                 knob.y=parent.height/2-knob.height/2;
73             }
74         }
75         Image {
76             source:joyBackground
77             anchors.fill:parent
78         }
79
80   }