|
21
|
1 |
|
|
|
2 |
var tuio = { |
|
28
|
3 |
cursors: [], |
|
|
4 |
objects: [], |
|
21
|
5 |
|
|
28
|
6 |
_data: {}, |
|
21
|
7 |
|
|
28
|
8 |
_cb_object_add: function(obj) { }, |
|
|
9 |
_cb_object_update: function(obj) { }, |
|
|
10 |
_cb_object_remove: function(obj) { }, |
|
|
11 |
_cb_cursor_add: function(cur) { }, |
|
|
12 |
_cb_cursor_update: function(cur) { }, |
|
|
13 |
_cb_cursor_remove: function(cur) { }, |
|
21
|
14 |
|
|
28
|
15 |
// Callback from the main event handler |
|
21
|
16 |
|
|
28
|
17 |
callback: function(type, sid, fid, x, y, angle) { |
|
|
18 |
var data; |
|
|
19 |
|
|
|
20 |
if ((type != 0) && (type != 3)) { |
|
|
21 |
data = this._data[sid]; |
|
|
22 |
} |
|
|
23 |
else { |
|
|
24 |
data = { |
|
|
25 |
sid: sid, |
|
|
26 |
fid: fid |
|
|
27 |
} |
|
|
28 |
this._data[sid] = data; |
|
|
29 |
} |
|
21
|
30 |
|
|
28
|
31 |
data.x = x; |
|
|
32 |
data.y = y; |
|
|
33 |
|
|
|
34 |
if (type < 3) { |
|
|
35 |
data.angle = angle; |
|
|
36 |
} |
|
21
|
37 |
|
|
28
|
38 |
switch (type) { |
|
|
39 |
case 0: |
|
|
40 |
this.objects.push(data); |
|
|
41 |
this._cb_object_add(data); |
|
|
42 |
break; |
|
21
|
43 |
|
|
28
|
44 |
case 1: |
|
|
45 |
this._cb_object_update(data); |
|
|
46 |
break; |
|
21
|
47 |
|
|
28
|
48 |
case 2: |
|
|
49 |
this.objects.splice(this.objects.indexOf(data), 1); |
|
|
50 |
this._cb_object_remove(data); |
|
|
51 |
break; |
|
21
|
52 |
|
|
28
|
53 |
case 3: |
|
|
54 |
this.cursors.push(data); |
|
|
55 |
this._cb_cursor_add(data); |
|
|
56 |
break; |
|
21
|
57 |
|
|
28
|
58 |
case 4: |
|
|
59 |
this._cb_cursor_update(data); |
|
|
60 |
break; |
|
21
|
61 |
|
|
28
|
62 |
case 5: |
|
|
63 |
this.cursors.splice(this.cursors.indexOf(data), 1); |
|
|
64 |
this._cb_cursor_remove(data); |
|
|
65 |
break; |
|
21
|
66 |
|
|
28
|
67 |
default: |
|
|
68 |
break; |
|
|
69 |
} |
|
21
|
70 |
|
|
28
|
71 |
if ((type == 2) || (type == 5)) { |
|
|
72 |
delete this._data[sid]; |
|
|
73 |
} |
|
|
74 |
}, |
|
21
|
75 |
|
|
28
|
76 |
// Callback for the developer |
|
21
|
77 |
|
|
28
|
78 |
object_add: function(f) { this._cb_object_add = f; }, |
|
|
79 |
object_update: function(f) { this._cb_object_update = f; }, |
|
|
80 |
object_remove: function(f) { this._cb_object_remove = f; }, |
|
|
81 |
cursor_add: function(f) { this._cb_cursor_add = f; }, |
|
|
82 |
cursor_update: function(f) { this._cb_cursor_update = f; }, |
|
|
83 |
cursor_remove: function(f) { this._cb_cursor_remove = f; }, |
|
21
|
84 |
} |
|
|
85 |
|
|
28
|
86 |
function tuio_callback(type, sid, fid, x, y, angle) { |
|
|
87 |
tuio.callback(type, sid, fid, x, y, angle); |
|
21
|
88 |
} |
|
|
89 |
|