front_idill/src/communication/js/client.js
author bastiena
Fri, 14 Sep 2012 11:09:16 +0200
changeset 95 63aaf895ea3a
parent 79 9eff85166868
permissions -rw-r--r--
Fusion
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
52
277c94533395 Front IDILL :
bastiena
parents: 44
diff changeset
     1
/*
277c94533395 Front IDILL :
bastiena
parents: 44
diff changeset
     2
* This file is part of the TraKERS\Front IDILL package.
277c94533395 Front IDILL :
bastiena
parents: 44
diff changeset
     3
*
277c94533395 Front IDILL :
bastiena
parents: 44
diff changeset
     4
* (c) IRI <http://www.iri.centrepompidou.fr/>
277c94533395 Front IDILL :
bastiena
parents: 44
diff changeset
     5
*
277c94533395 Front IDILL :
bastiena
parents: 44
diff changeset
     6
* For the full copyright and license information, please view the LICENSE
277c94533395 Front IDILL :
bastiena
parents: 44
diff changeset
     7
* file that was distributed with this source code.
277c94533395 Front IDILL :
bastiena
parents: 44
diff changeset
     8
*/
277c94533395 Front IDILL :
bastiena
parents: 44
diff changeset
     9
277c94533395 Front IDILL :
bastiena
parents: 44
diff changeset
    10
/*
277c94533395 Front IDILL :
bastiena
parents: 44
diff changeset
    11
 * Projet : TraKERS
277c94533395 Front IDILL :
bastiena
parents: 44
diff changeset
    12
 * Module : Front IDILL
277c94533395 Front IDILL :
bastiena
parents: 44
diff changeset
    13
 * Fichier : client.js
277c94533395 Front IDILL :
bastiena
parents: 44
diff changeset
    14
 * 
277c94533395 Front IDILL :
bastiena
parents: 44
diff changeset
    15
 * Auteur : alexandre.bastien@iri.centrepompidou.fr
277c94533395 Front IDILL :
bastiena
parents: 44
diff changeset
    16
 * 
277c94533395 Front IDILL :
bastiena
parents: 44
diff changeset
    17
 * Fonctionnalités : Définit la "classe" client permettant de recevoir les instructions du Middleware, sous forme de sockets (via le serveur WebSocket du Middleware).
277c94533395 Front IDILL :
bastiena
parents: 44
diff changeset
    18
 */
277c94533395 Front IDILL :
bastiena
parents: 44
diff changeset
    19
44
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
    20
/*
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
    21
 * Un client est défini par une socket, qui permettra de recevoir les données du server websocket du Middleware.
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
    22
 * On accède aussi à la mosaïque.
52
277c94533395 Front IDILL :
bastiena
parents: 44
diff changeset
    23
 * Est appelé dans le fichier :
277c94533395 Front IDILL :
bastiena
parents: 44
diff changeset
    24
 * mosaic > fonction loadParameters.
44
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
    25
*/
52
277c94533395 Front IDILL :
bastiena
parents: 44
diff changeset
    26
function Client(host, port, _mosaic)
44
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
    27
{
79
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
    28
    this.socket = null;
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
    29
    this.mosaic = _mosaic;
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
    30
    
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
    31
    this.pointerLeft = false;
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
    32
    this.pointerRight = false;
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
    33
    this.timePointers = 100;
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
    34
    this.pointerLeftTimeout = null;
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
    35
    this.pointerRightTimeout = null;
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
    36
    this.isLeftHanded = false;
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
    37
    
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
    38
    this.createWebSocket('ws://' + host + ':' + port + '/');
44
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
    39
}
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
    40
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
    41
/*
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
    42
 * Création et Initialisation des sockets et listeners permettant d'écouter le server.
52
277c94533395 Front IDILL :
bastiena
parents: 44
diff changeset
    43
 * Est appelé dans le fichier :
277c94533395 Front IDILL :
bastiena
parents: 44
diff changeset
    44
 * client > fonction Client.
44
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
    45
*/
52
277c94533395 Front IDILL :
bastiena
parents: 44
diff changeset
    46
Client.prototype.createWebSocket = function(host)
44
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
    47
{
79
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
    48
    var _this = this;
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
    49
    
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
    50
    //Initialise la fonctionnalité websocket du naviguateur.
44
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
    51
    if(window.MozWebSocket)
79
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
    52
    {
44
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
    53
        window.WebSocket = window.MozWebSocket;
79
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
    54
    }
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
    55
    
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
    56
    //Si le naviguateur ne supporte pas les websockets, on s'arrête là.
44
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
    57
    if(!window.WebSocket)
79
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
    58
    {
44
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
    59
        alert('Votre navigateur ne supporte pas les webSocket!');
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
    60
        return false;
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
    61
    }
79
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
    62
    //Sinon
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
    63
    else
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
    64
    {
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
    65
        //On initialise la socket.
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
    66
        this.socket = new WebSocket(host);
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
    67
        
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
    68
        //Si elle est ouverte, on notifie le Front.
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
    69
        this.socket.onopen = function()
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
    70
        {
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
    71
            console.log('Socket ouverte.');
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
    72
        }
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
    73
        //Si elle est fermée, on notifie le Front.
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
    74
        this.socket.onclose = function()
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
    75
        {
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
    76
            console.log('Socket fermée.');
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
    77
        }
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
    78
        //S'il y a un problème dans la connection, on notifie le Front.
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
    79
        this.socket.onerror = function()
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
    80
        {
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
    81
            console.log('Une erreur est survenue dans le module de Communication.');
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
    82
        }
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
    83
        //Si on reçoit un message.
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
    84
        this.socket.onmessage = function(msg)
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
    85
        {
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
    86
            _this.processMsg(msg);
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
    87
        }
44
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
    88
    }
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
    89
}
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
    90
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
    91
/*
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
    92
 * Traite un message reçu du Middleware.
52
277c94533395 Front IDILL :
bastiena
parents: 44
diff changeset
    93
 * Est appelé dans le fichier :
277c94533395 Front IDILL :
bastiena
parents: 44
diff changeset
    94
 * client > fonction createWebSocket.
44
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
    95
*/
52
277c94533395 Front IDILL :
bastiena
parents: 44
diff changeset
    96
Client.prototype.processMsg = function(msg)
44
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
    97
{
79
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
    98
    if(typeof msg === 'undefined' || typeof msg.data === 'undefined')
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
    99
    {
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   100
        return;
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   101
    }
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   102
    
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   103
    var _this = this;
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   104
    
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   105
    
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   106
    //S'il s'agit d'une string et non d'une instruction pour les pointeurs.
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   107
    if(msg.data[0] === '2')
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   108
    {
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   109
        var instruction = msg.data.substring(2, msg.data.length);
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   110
        
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   111
        // if(instruction.indexOf("INCOMING") == -1 && instruction.indexOf('NO-USER') == -1)
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   112
        // {
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   113
            this.mosaic.manageControlEvents(instruction);
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   114
        // }
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   115
    }
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   116
    //Sinon si ce sont les coordonnées de la main droite.
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   117
    // /!\/!\ //
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   118
    else if(msg.data[0] == '1')
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   119
    {
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   120
        var instruction = msg.data.substring(2, msg.data.length);
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   121
        pt = instruction.split(';');
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   122
        var x = Math.abs(parseFloat(pt[0])), y = Math.abs(parseFloat(pt[1]));
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   123
        // console.log(Math.abs(parseFloat(pt[0])), Math.abs(parseFloat(pt[1])));
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   124
        
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   125
        this.pointerRight = true;
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   126
        clearTimeout(this.pointerRightTimeout);
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   127
        
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   128
        if(!this.mosaic.mouseInteractions && this.mosaic.currentMode != 'NO-USER' && this.mosaic.currentMode.indexOf('INCOMING') == -1)
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   129
        {
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   130
            // console.log('pt');
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   131
            this.mosaic.refreshPointers(x, y, true);
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   132
        }
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   133
        
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   134
        // /!\ //
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   135
        if(!this.mosaic.isMainPointerDisplayed)
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   136
        {
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   137
            this.mosaic.mainPointerDisplay(true);
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   138
            this.mosaic.isMainPointerDisplayed = true;
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   139
        }
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   140
        
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   141
        this.pointerRightTimeout = setTimeout(function()
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   142
        {
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   143
            // console.log('RELEASE LEFT');
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   144
            //Timeout indiquant quand la main gauche part.
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   145
            _this.pointerRight = false;
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   146
            
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   147
            if(_this.mosaic.isMainPointerDisplayed)
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   148
            {
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   149
                _this.mosaic.isMainPointerDisplayed = false;
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   150
                _this.mosaic.mainPointerDisplay(false);
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   151
            }
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   152
            
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   153
            if(_this.mosaic.isSearchByCurvesOn)
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   154
            {
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   155
                _this.mosaic.isSearchByCurvesOn = false;
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   156
                if(_this.mosaic.searchCanvas)
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   157
                {
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   158
                    _this.mosaic.searchCanvas.onPointerOut();
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   159
                    
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   160
                    $('#mainPointer').css('background-image', 'url(./img/cursors/pointerC.png)');
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   161
                    $('#secondPointer').css('background-image', 'url(./img/cursors/pointer2C.png)');
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   162
                }
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   163
            }
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   164
            //On peut effectuer de nouveau une recherche par courbes.
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   165
            if(!_this.pointerLeft)
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   166
            {
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   167
                _this.mosaic.mustTakeOutHands = false;
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   168
            }
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   169
        }, this.timePointers);
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   170
    }
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   171
    //Sinon si ce sont les coordonnées de la main gauche.
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   172
    else if(msg.data[0] == '0')
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   173
    {
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   174
        var instruction = msg.data.substring(2, msg.data.length);
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   175
        pt = instruction.split(';');
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   176
        var x = Math.abs(parseFloat(pt[0])), y = Math.abs(parseFloat(pt[1]));
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   177
        // console.log(Math.abs(parseFloat(pt[0])), Math.abs(parseFloat(pt[1])));
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   178
        
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   179
        this.pointerLeft = true;
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   180
        clearTimeout(this.pointerLeftTimeout);
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   181
        
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   182
        if(!this.mosaic.mouseInteractions && this.mosaic.currentMode != 'NO-USER' && this.mosaic.currentMode.indexOf('INCOMING') == -1)
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   183
        {
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   184
            this.mosaic.refreshPointers(x, y, false);
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   185
        }
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   186
        
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   187
        if(!this.mosaic.isSecondPointerDisplayed)
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   188
        {
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   189
            this.mosaic.secondPointerDisplay(true);
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   190
            this.mosaic.isSecondPointerDisplayed = true;
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   191
        }
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   192
        
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   193
        //Timeout indiquant quand la main droite part.
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   194
        this.pointerLeftTimeout = setTimeout(function()
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   195
        {
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   196
            // console.log('RELEASE RIGHT');
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   197
            _this.pointerLeft = false;
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   198
            
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   199
            if(_this.mosaic.isSecondPointerDisplayed)
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   200
            {
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   201
                _this.mosaic.isSecondPointerDisplayed = false;
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   202
                _this.mosaic.secondPointerDisplay(false);
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   203
            }
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   204
            
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   205
            if(_this.mosaic.isSearchByCurvesOn)
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   206
            {
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   207
                _this.mosaic.isSearchByCurvesOn = false;
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   208
                if(_this.mosaic.searchCanvas)
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   209
                {
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   210
                    _this.mosaic.searchCanvas.onPointerOut();
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   211
                    
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   212
                    $('#mainPointer').css('background-image', 'url(./img/cursors/pointerC.png)');
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   213
                    $('#secondPointer').css('background-image', 'url(./img/cursors/pointer2C.png)');
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   214
                }
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   215
            }
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   216
            //On peut effectuer de nouveau une recherche par courbes.
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   217
            if(!_this.pointerRight)
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   218
            {
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   219
                _this.mosaic.mustTakeOutHands = false;
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   220
            }
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   221
        }, this.timePointers);
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   222
    }
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   223
    
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   224
    if(this.pointerLeft && !this.pointerRight || !this.pointerLeft && this.pointerRight)
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   225
    {
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   226
        //On interrompt l'idle des pointeurs.
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   227
        this.mosaic.pointersIdleAvailable = false;
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   228
        this.mosaic.removeIdlePointers();
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   229
        this.mosaic.areBothPointersHere = false;
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   230
    }
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   231
    if(!this.pointerLeft && !this.pointerRight)
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   232
    {
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   233
        //On interrompt l'idle des pointeurs.
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   234
        this.mosaic.pointersIdleAvailable = false;
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   235
        this.mosaic.removeIdlePointers();
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   236
        this.mosaic.areBothPointersHere = false;
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   237
        
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   238
        this.mosaic.deselectAllNeighbours();
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   239
        this.mosaic.preUnzoom();
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   240
    }
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   241
    
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   242
    if(this.pointerLeft && this.pointerRight)
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   243
    {
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   244
        this.mosaic.areBothPointersHere = true;
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   245
        this.mosaic.removeCheckForBothPointersHere();
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   246
        
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   247
        //On enlève les requêtes de zoom.
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   248
        this.mosaic.preUnzoom();
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   249
        
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   250
        if(this.mosaic.currentMode == 'MOSAIC' || this.mosaic.currentMode == 'FILTER' && !this.mosaic.isSearchByCurvesOn)
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   251
        {
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   252
            $('#mainPointer').css('background-image', 'url(./img/cursors/pointer.png)');
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   253
            $('#secondPointer').css('background-image', 'url(./img/cursors/pointer2.png)');
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   254
        }
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   255
        
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   256
        //Si on est dans un des modes de recherche et que les mains ont été retirées après la précédente recherche.
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   257
        if((this.mosaic.currentMode == 'FILTER' || this.mosaic.currentMode == 'SEARCH') && !this.mosaic.mustTakeOutHands)
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   258
        {
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   259
            // console.log('ON');
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   260
            if(this.mosaic.searchCanvas)
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   261
            {
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   262
                var mainPointerX = +$('#mainPointer').position().left + $('#mainPointer').width() / 2;
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   263
                var mainPointerY = +$('#mainPointer').position().top - this.mosaic.MPTop_margin + $('#mainPointer').height() / 2;
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   264
                var secondPointerX = +$('#secondPointer').position().left + $('#secondPointer').width() / 2;
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   265
                var secondPointerY = +$('#secondPointer').position().top - this.mosaic.MPTop_margin + $('#secondPointer').height() / 2;
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   266
                
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   267
                if(!this.mosaic.isSearchByCurvesOn)
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   268
                {
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   269
                    this.mosaic.isSearchByCurvesOn = true;
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   270
                    this.mosaic.searchCanvas.onPointerOut();
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   271
                    this.mosaic.searchCanvas.onPointerIn(mainPointerX, mainPointerY, secondPointerX, secondPointerY);
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   272
                    this.mosaic.canDrawNextCurve = true;
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   273
                    
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   274
                    this.mosaic.pointersGreen();
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   275
                }
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   276
                else if(this.mosaic.isSearchByCurvesOn)
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   277
                {
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   278
                    if(this.mosaic.canDrawNextCurve)
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   279
                    {
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   280
                        this.mosaic.canDrawNextCurve = false;
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   281
                        if(Math.abs(mainPointerX - this.mosaic.mainPointerLastX) > 10 || Math.abs(mainPointerY - this.mosaic.mainPointerLastY) > 10 || Math.abs(secondPointerX - this.mosaic.secondPointerLastX) > 10 || Math.abs(secondPointerY - this.mosaic.secondPointerLastY) > 10)
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   282
                        {
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   283
                            this.mosaic.searchCanvas.onPointerMove(mainPointerX, mainPointerY, secondPointerX, secondPointerY);
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   284
                            this.mosaic.pointersGreen();
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   285
                        }
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   286
                    }
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   287
                    else
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   288
                    {
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   289
                        this.mosaic.nextDrawCurveTimeout = setTimeout(function()
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   290
                        {
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   291
                            _this.mosaic.canDrawNextCurve = true;
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   292
                        }, this.mosaic.config.timeoutNextDrawCurve);
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   293
                    }
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   294
                }
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   295
            }
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   296
            else
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   297
            {
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   298
                this.mosaic.startSearch();
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   299
            }
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   300
        }
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   301
    }
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   302
    
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   303
    //Quant on a reçu un message, on vérifie la présence des deux pointeurs.
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   304
    this.mosaic.checkForBothPointersHere();
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   305
    
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   306
    if(this.mosaic.pointersIdleAvailable)
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   307
    {
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   308
        //On effectue une vérification de la position des pointeurs pour l'idle.
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   309
        this.mosaic.detectIdlePointers();
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   310
    }
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   311
    
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   312
    //Si le timeout a besoin d'être relancé ou bien que l'affichage de l'aide est disponible.
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   313
    if(this.mosaic.pointersIdleNeedLaunch || this.mosaic.canNotifyHelp)
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   314
    {
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   315
        // console.log('launch idle');
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   316
        this.mosaic.launchIdlePointers();
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   317
        this.mosaic.pointersIdleNeedLaunch = false;
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   318
    }
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   319
    
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   320
    //Si la détection d'idle n'est pas activée et qu'on est dans un mode permettant l'interaction de l'utilisateur. 
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   321
    if(!this.mosaic.pointersIdleAvailable && this.mosaic.currentMode != "NO-USER" && this.mosaic.currentMode.indexOf("INCOMING") == -1 && this.mosaic.areBothPointersHere)
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   322
    {
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   323
        //On enclenche la détection d'idle.
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   324
        this.mosaic.pointersIdleAvailable = true;
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   325
        this.mosaic.pointersIdleNeedLaunch = true;
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   326
    }
9eff85166868 Front IDILL :
bastiena
parents: 59
diff changeset
   327
    // /!\/!\ //
44
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   328
}