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