-
Notifications
You must be signed in to change notification settings - Fork 3
/
TouchJoint.qml
106 lines (82 loc) · 2.62 KB
/
TouchJoint.qml
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
import QtQuick 2.0
import Box2D 2.0
import Ros 1.0
TouchPoint {
id: touch
property string name: "touch"
property bool movingItem: false
property bool drawing: false
// when used to draw on the background:
property var currentStroke: []
property color color: "black"
property MouseJoint joint: MouseJoint {
bodyA: anchor
dampingRatio: 1
maxForce: 1
}
onXChanged: {
if(movingItem) {
joint.target = Qt.point(x, y);
}
// (only add stroke point in one dimension (Y) to avoid double drawing)
}
onYChanged: {
if(movingItem) {
joint.target = Qt.point(x, y);
}
if (drawing) {
currentStroke.push(Qt.point(x,y));
drawingarea.update();
}
}
onPressedChanged: {
if (pressed) {
// find out whether we touched an item
var obj = interactiveitems.childAt(x, y);
if (obj.objectName === "interactive") {
movingItem = true;
// restack item to the top
interactiveitems.currentMaxZ += 1;
obj.z=interactiveitems.currentMaxZ;
// update the join forces
joint.maxForce = obj.body.getMass() * 500;
joint.target = Qt.point(x, y);
joint.bodyB = obj.body;
}
else {
if (drawingarea.drawEnabled) {
currentStroke = [];
color = drawingarea.fgColor;
drawing = true;
}
}
}
else { // released
if(movingItem) {
joint.bodyB = null;
movingItem = false;
}
if(drawing) {
drawing = false;
if (drawingarea.drawEnabled) {
drawingarea.finishStroke(currentStroke);
}
currentStroke = [];
}
}
}
property var tf: Item {
// the TF broadcaster can not directly target 'touch' as TouchPoint is not a QtQuickItem
id: touchtracker
x: touch.x
y: touch.y
TFBroadcaster {
active: drawing || touch.movingItem
target: parent
frame: touch.name
origin: mapOrigin
parentframe: mapOrigin.name
pixelscale: sandbox.pixel2meter
}
}
}