front_idill/extern/fajran-npTuioClient/example/tuio.js
author bastiena
Thu, 12 Apr 2012 15:33:25 +0200
changeset 28 9ccef81f02ab
parent 21 e4e5f02787a1
permissions -rw-r--r--
Charset set to UTF-8 without bom tab replaced by 4 spaces \r\n replaced by \n in non cs files
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
21
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
     1
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
     2
var tuio = {
28
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 21
diff changeset
     3
    cursors: [],
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 21
diff changeset
     4
    objects: [],
21
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
     5
28
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 21
diff changeset
     6
    _data: {},
21
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
     7
28
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 21
diff changeset
     8
    _cb_object_add:    function(obj) { },
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 21
diff changeset
     9
    _cb_object_update: function(obj) { },
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 21
diff changeset
    10
    _cb_object_remove: function(obj) { },
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 21
diff changeset
    11
    _cb_cursor_add:    function(cur) { },
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 21
diff changeset
    12
    _cb_cursor_update: function(cur) { },
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 21
diff changeset
    13
    _cb_cursor_remove: function(cur) { },
21
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    14
28
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 21
diff changeset
    15
    // Callback from the main event handler
21
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    16
28
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 21
diff changeset
    17
    callback: function(type, sid, fid, x, y, angle) {
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 21
diff changeset
    18
        var data;
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 21
diff changeset
    19
        
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 21
diff changeset
    20
        if ((type != 0) && (type != 3)) {
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 21
diff changeset
    21
            data = this._data[sid];
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 21
diff changeset
    22
        }
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 21
diff changeset
    23
        else {
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 21
diff changeset
    24
            data = {
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 21
diff changeset
    25
                sid: sid,
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 21
diff changeset
    26
                fid: fid
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 21
diff changeset
    27
            }
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 21
diff changeset
    28
            this._data[sid] = data;
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 21
diff changeset
    29
        }
21
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    30
28
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 21
diff changeset
    31
        data.x = x;
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 21
diff changeset
    32
        data.y = y;
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 21
diff changeset
    33
        
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 21
diff changeset
    34
        if (type < 3) {
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 21
diff changeset
    35
            data.angle = angle;
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 21
diff changeset
    36
        }
21
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    37
28
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 21
diff changeset
    38
        switch (type) {
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 21
diff changeset
    39
            case 0: 
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 21
diff changeset
    40
                this.objects.push(data);
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 21
diff changeset
    41
                this._cb_object_add(data);
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 21
diff changeset
    42
                break;
21
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    43
28
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 21
diff changeset
    44
            case 1: 
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 21
diff changeset
    45
                this._cb_object_update(data);
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 21
diff changeset
    46
                break;
21
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    47
28
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 21
diff changeset
    48
            case 2: 
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 21
diff changeset
    49
                this.objects.splice(this.objects.indexOf(data), 1);
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 21
diff changeset
    50
                this._cb_object_remove(data);
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 21
diff changeset
    51
                break;
21
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    52
28
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 21
diff changeset
    53
            case 3: 
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 21
diff changeset
    54
                this.cursors.push(data);
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 21
diff changeset
    55
                this._cb_cursor_add(data);
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 21
diff changeset
    56
                break;
21
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    57
28
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 21
diff changeset
    58
            case 4: 
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 21
diff changeset
    59
                this._cb_cursor_update(data);
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 21
diff changeset
    60
                break;
21
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    61
28
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 21
diff changeset
    62
            case 5: 
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 21
diff changeset
    63
                this.cursors.splice(this.cursors.indexOf(data), 1);
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 21
diff changeset
    64
                this._cb_cursor_remove(data);
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 21
diff changeset
    65
                break;
21
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    66
28
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 21
diff changeset
    67
            default:
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 21
diff changeset
    68
                break;
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 21
diff changeset
    69
        }
21
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    70
28
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 21
diff changeset
    71
        if ((type == 2) || (type == 5)) {
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 21
diff changeset
    72
            delete this._data[sid];
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 21
diff changeset
    73
        }
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 21
diff changeset
    74
    },
21
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    75
28
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 21
diff changeset
    76
    // Callback for the developer
21
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    77
28
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 21
diff changeset
    78
    object_add:    function(f) { this._cb_object_add    = f; },
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 21
diff changeset
    79
    object_update: function(f) { this._cb_object_update = f; },
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 21
diff changeset
    80
    object_remove: function(f) { this._cb_object_remove = f; },
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 21
diff changeset
    81
    cursor_add:    function(f) { this._cb_cursor_add    = f; },
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 21
diff changeset
    82
    cursor_update: function(f) { this._cb_cursor_update = f; },
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 21
diff changeset
    83
    cursor_remove: function(f) { this._cb_cursor_remove = f; },
21
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    84
}
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    85
28
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 21
diff changeset
    86
function tuio_callback(type, sid, fid, x, y, angle)    {
9ccef81f02ab Charset set to UTF-8 without bom
bastiena
parents: 21
diff changeset
    87
    tuio.callback(type, sid, fid, x, y, angle);
21
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    88
}
e4e5f02787a1 Front IDILL :
bastiena
parents:
diff changeset
    89