front_idill/src/communication/js/client.js
author bastiena
Tue, 31 Jul 2012 17:43:53 +0200
changeset 59 e812126f75f4
parent 58 a28488078053
child 79 9eff85166868
permissions -rw-r--r--
Front IDILL : curves more accurate
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
{
52
277c94533395 Front IDILL :
bastiena
parents: 44
diff changeset
    28
	this.socket = null;
44
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
    29
	this.mosaic = _mosaic;
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
    30
	
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
    31
	this.pointerLeft = false;
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
    32
	this.pointerRight = false;
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
    33
	this.timePointers = 100;
52
277c94533395 Front IDILL :
bastiena
parents: 44
diff changeset
    34
	this.pointerLeftTimeout = null;
277c94533395 Front IDILL :
bastiena
parents: 44
diff changeset
    35
	this.pointerRightTimeout = null;
44
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
    36
	this.isLeftHanded = false;
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
    37
	
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
    38
	this.createWebSocket('ws://' + host + ':' + port + '/');
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
{
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
    48
	var _this = this;
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
    49
	
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
    50
	//Initialise la fonctionnalité websocket du naviguateur.
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
    51
    if(window.MozWebSocket)
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
    52
	{
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
    53
        window.WebSocket = window.MozWebSocket;
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
    54
	}
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
    55
	
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
    56
	//Si le naviguateur ne supporte pas les websockets, on s'arrête là.
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
    57
    if(!window.WebSocket)
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
    58
	{
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
    }
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
    62
	//Sinon
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
    63
	else
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
    64
	{
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
    65
		//On initialise la socket.
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
    66
		this.socket = new WebSocket(host);
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
    67
		
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
    68
		//Si elle est ouverte, on notifie le Front.
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
    69
		this.socket.onopen = function()
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
    70
		{
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
    71
			console.log('Socket ouverte.');
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
    72
		}
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
    73
		//Si elle est fermée, on notifie le Front.
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
    74
		this.socket.onclose = function()
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
    75
		{
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
    76
			console.log('Socket fermée.');
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
    77
		}
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
    78
		//S'il y a un problème dans la connection, on notifie le Front.
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
    79
		this.socket.onerror = function()
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
    80
		{
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
    81
			console.log('Une erreur est survenue dans le module de Communication.');
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
    82
		}
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
    83
		//Si on reçoit un message.
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
    84
		this.socket.onmessage = function(msg)
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
    85
		{
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
    86
			_this.processMsg(msg);
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
    87
		}
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
{
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
    98
	if(typeof msg === 'undefined' || typeof msg.data === 'undefined')
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
    99
	{
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   100
		return;
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   101
	}
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   102
	
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   103
	var _this = this;
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   104
	
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   105
	
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   106
	//S'il s'agit d'une string et non d'une instruction pour les pointeurs.
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   107
	if(msg.data[0] === '2')
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   108
	{
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   109
		var instruction = msg.data.substring(2, msg.data.length);
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   110
		
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   111
		// if(instruction.indexOf("INCOMING") == -1 && instruction.indexOf('NO-USER') == -1)
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   112
		// {
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   113
			this.mosaic.manageControlEvents(instruction);
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   114
		// }
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   115
	}
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   116
	//Sinon si ce sont les coordonnées de la main droite.
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   117
	// /!\/!\ //
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   118
	else if(msg.data[0] == '1')
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   119
	{
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   120
		var instruction = msg.data.substring(2, msg.data.length);
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   121
		pt = instruction.split(';');
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   122
		var x = Math.abs(parseFloat(pt[0])), y = Math.abs(parseFloat(pt[1]));
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   123
		// console.log(Math.abs(parseFloat(pt[0])), Math.abs(parseFloat(pt[1])));
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   124
		
58
a28488078053 Front IDILL:
bastiena
parents: 52
diff changeset
   125
		this.pointerRight = true;
a28488078053 Front IDILL:
bastiena
parents: 52
diff changeset
   126
		clearTimeout(this.pointerRightTimeout);
44
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   127
		
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   128
		if(!this.mosaic.mouseInteractions && this.mosaic.currentMode != 'NO-USER' && this.mosaic.currentMode.indexOf('INCOMING') == -1)
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   129
		{
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   130
			// console.log('pt');
52
277c94533395 Front IDILL :
bastiena
parents: 44
diff changeset
   131
			this.mosaic.refreshPointers(x, y, true);
44
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   132
		}
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   133
		
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   134
		// /!\ //
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   135
		if(!this.mosaic.isMainPointerDisplayed)
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   136
		{
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   137
			this.mosaic.mainPointerDisplay(true);
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   138
			this.mosaic.isMainPointerDisplayed = true;
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   139
		}
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   140
		
58
a28488078053 Front IDILL:
bastiena
parents: 52
diff changeset
   141
		this.pointerRightTimeout = setTimeout(function()
44
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   142
		{
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   143
			// console.log('RELEASE LEFT');
58
a28488078053 Front IDILL:
bastiena
parents: 52
diff changeset
   144
			//Timeout indiquant quand la main gauche part.
a28488078053 Front IDILL:
bastiena
parents: 52
diff changeset
   145
			_this.pointerRight = false;
44
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   146
			
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   147
			if(_this.mosaic.isMainPointerDisplayed)
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   148
			{
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   149
				_this.mosaic.isMainPointerDisplayed = false;
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   150
				_this.mosaic.mainPointerDisplay(false);
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   151
			}
58
a28488078053 Front IDILL:
bastiena
parents: 52
diff changeset
   152
			
a28488078053 Front IDILL:
bastiena
parents: 52
diff changeset
   153
			if(_this.mosaic.isSearchByCurvesOn)
a28488078053 Front IDILL:
bastiena
parents: 52
diff changeset
   154
			{
a28488078053 Front IDILL:
bastiena
parents: 52
diff changeset
   155
				_this.mosaic.isSearchByCurvesOn = false;
a28488078053 Front IDILL:
bastiena
parents: 52
diff changeset
   156
				if(_this.mosaic.searchCanvas)
a28488078053 Front IDILL:
bastiena
parents: 52
diff changeset
   157
				{
a28488078053 Front IDILL:
bastiena
parents: 52
diff changeset
   158
					_this.mosaic.searchCanvas.onPointerOut();
a28488078053 Front IDILL:
bastiena
parents: 52
diff changeset
   159
					
a28488078053 Front IDILL:
bastiena
parents: 52
diff changeset
   160
					$('#mainPointer').css('background-image', 'url(./img/cursors/pointerC.png)');
a28488078053 Front IDILL:
bastiena
parents: 52
diff changeset
   161
					$('#secondPointer').css('background-image', 'url(./img/cursors/pointer2C.png)');
a28488078053 Front IDILL:
bastiena
parents: 52
diff changeset
   162
				}
a28488078053 Front IDILL:
bastiena
parents: 52
diff changeset
   163
			}
a28488078053 Front IDILL:
bastiena
parents: 52
diff changeset
   164
			//On peut effectuer de nouveau une recherche par courbes.
a28488078053 Front IDILL:
bastiena
parents: 52
diff changeset
   165
			if(!_this.pointerLeft)
a28488078053 Front IDILL:
bastiena
parents: 52
diff changeset
   166
			{
a28488078053 Front IDILL:
bastiena
parents: 52
diff changeset
   167
				_this.mosaic.mustTakeOutHands = false;
a28488078053 Front IDILL:
bastiena
parents: 52
diff changeset
   168
			}
44
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   169
		}, this.timePointers);
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   170
	}
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   171
	//Sinon si ce sont les coordonnées de la main gauche.
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   172
	else if(msg.data[0] == '0')
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   173
	{
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   174
		var instruction = msg.data.substring(2, msg.data.length);
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   175
		pt = instruction.split(';');
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   176
		var x = Math.abs(parseFloat(pt[0])), y = Math.abs(parseFloat(pt[1]));
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   177
		// console.log(Math.abs(parseFloat(pt[0])), Math.abs(parseFloat(pt[1])));
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   178
		
58
a28488078053 Front IDILL:
bastiena
parents: 52
diff changeset
   179
		this.pointerLeft = true;
a28488078053 Front IDILL:
bastiena
parents: 52
diff changeset
   180
		clearTimeout(this.pointerLeftTimeout);
44
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   181
		
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   182
		if(!this.mosaic.mouseInteractions && this.mosaic.currentMode != 'NO-USER' && this.mosaic.currentMode.indexOf('INCOMING') == -1)
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   183
		{
52
277c94533395 Front IDILL :
bastiena
parents: 44
diff changeset
   184
			this.mosaic.refreshPointers(x, y, false);
44
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   185
		}
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   186
		
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   187
		if(!this.mosaic.isSecondPointerDisplayed)
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   188
		{
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   189
			this.mosaic.secondPointerDisplay(true);
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   190
			this.mosaic.isSecondPointerDisplayed = true;
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   191
		}
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   192
		
58
a28488078053 Front IDILL:
bastiena
parents: 52
diff changeset
   193
		//Timeout indiquant quand la main droite part.
a28488078053 Front IDILL:
bastiena
parents: 52
diff changeset
   194
		this.pointerLeftTimeout = setTimeout(function()
44
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   195
		{
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   196
			// console.log('RELEASE RIGHT');
58
a28488078053 Front IDILL:
bastiena
parents: 52
diff changeset
   197
			_this.pointerLeft = false;
44
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   198
			
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   199
			if(_this.mosaic.isSecondPointerDisplayed)
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   200
			{
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   201
				_this.mosaic.isSecondPointerDisplayed = false;
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   202
				_this.mosaic.secondPointerDisplay(false);
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   203
			}
58
a28488078053 Front IDILL:
bastiena
parents: 52
diff changeset
   204
			
a28488078053 Front IDILL:
bastiena
parents: 52
diff changeset
   205
			if(_this.mosaic.isSearchByCurvesOn)
a28488078053 Front IDILL:
bastiena
parents: 52
diff changeset
   206
			{
a28488078053 Front IDILL:
bastiena
parents: 52
diff changeset
   207
				_this.mosaic.isSearchByCurvesOn = false;
a28488078053 Front IDILL:
bastiena
parents: 52
diff changeset
   208
				if(_this.mosaic.searchCanvas)
a28488078053 Front IDILL:
bastiena
parents: 52
diff changeset
   209
				{
a28488078053 Front IDILL:
bastiena
parents: 52
diff changeset
   210
					_this.mosaic.searchCanvas.onPointerOut();
a28488078053 Front IDILL:
bastiena
parents: 52
diff changeset
   211
					
a28488078053 Front IDILL:
bastiena
parents: 52
diff changeset
   212
					$('#mainPointer').css('background-image', 'url(./img/cursors/pointerC.png)');
a28488078053 Front IDILL:
bastiena
parents: 52
diff changeset
   213
					$('#secondPointer').css('background-image', 'url(./img/cursors/pointer2C.png)');
a28488078053 Front IDILL:
bastiena
parents: 52
diff changeset
   214
				}
a28488078053 Front IDILL:
bastiena
parents: 52
diff changeset
   215
			}
a28488078053 Front IDILL:
bastiena
parents: 52
diff changeset
   216
			//On peut effectuer de nouveau une recherche par courbes.
a28488078053 Front IDILL:
bastiena
parents: 52
diff changeset
   217
			if(!_this.pointerRight)
a28488078053 Front IDILL:
bastiena
parents: 52
diff changeset
   218
			{
a28488078053 Front IDILL:
bastiena
parents: 52
diff changeset
   219
				_this.mosaic.mustTakeOutHands = false;
a28488078053 Front IDILL:
bastiena
parents: 52
diff changeset
   220
			}
44
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   221
		}, this.timePointers);
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   222
	}
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   223
	
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   224
	if(this.pointerLeft && !this.pointerRight || !this.pointerLeft && this.pointerRight)
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   225
	{
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   226
		//On interrompt l'idle des pointeurs.
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   227
		this.mosaic.pointersIdleAvailable = false;
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   228
		this.mosaic.removeIdlePointers();
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   229
		this.mosaic.areBothPointersHere = false;
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   230
	}
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   231
	if(!this.pointerLeft && !this.pointerRight)
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   232
	{
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   233
		//On interrompt l'idle des pointeurs.
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   234
		this.mosaic.pointersIdleAvailable = false;
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   235
		this.mosaic.removeIdlePointers();
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   236
		this.mosaic.areBothPointersHere = false;
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   237
		
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   238
		this.mosaic.deselectAllNeighbours();
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   239
		this.mosaic.preUnzoom();
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   240
	}
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   241
	
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   242
	if(this.pointerLeft && this.pointerRight)
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   243
	{
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   244
		this.mosaic.areBothPointersHere = true;
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   245
		this.mosaic.removeCheckForBothPointersHere();
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   246
		
58
a28488078053 Front IDILL:
bastiena
parents: 52
diff changeset
   247
		//On enlève les requêtes de zoom.
a28488078053 Front IDILL:
bastiena
parents: 52
diff changeset
   248
		this.mosaic.preUnzoom();
a28488078053 Front IDILL:
bastiena
parents: 52
diff changeset
   249
		
a28488078053 Front IDILL:
bastiena
parents: 52
diff changeset
   250
		if(this.mosaic.currentMode == 'MOSAIC' || this.mosaic.currentMode == 'FILTER' && !this.mosaic.isSearchByCurvesOn)
44
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   251
		{
58
a28488078053 Front IDILL:
bastiena
parents: 52
diff changeset
   252
			$('#mainPointer').css('background-image', 'url(./img/cursors/pointer.png)');
a28488078053 Front IDILL:
bastiena
parents: 52
diff changeset
   253
			$('#secondPointer').css('background-image', 'url(./img/cursors/pointer2.png)');
44
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   254
		}
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   255
		
58
a28488078053 Front IDILL:
bastiena
parents: 52
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.
a28488078053 Front IDILL:
bastiena
parents: 52
diff changeset
   257
		if((this.mosaic.currentMode == 'FILTER' || this.mosaic.currentMode == 'SEARCH') && !this.mosaic.mustTakeOutHands)
44
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   258
		{
59
e812126f75f4 Front IDILL : curves more accurate
bastiena
parents: 58
diff changeset
   259
			// console.log('ON');
44
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   260
			if(this.mosaic.searchCanvas)
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   261
			{
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   262
				var mainPointerX = +$('#mainPointer').position().left + $('#mainPointer').width() / 2;
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   263
				var mainPointerY = +$('#mainPointer').position().top - this.mosaic.MPTop_margin + $('#mainPointer').height() / 2;
58
a28488078053 Front IDILL:
bastiena
parents: 52
diff changeset
   264
				var secondPointerX = +$('#secondPointer').position().left + $('#secondPointer').width() / 2;
a28488078053 Front IDILL:
bastiena
parents: 52
diff changeset
   265
				var secondPointerY = +$('#secondPointer').position().top - this.mosaic.MPTop_margin + $('#secondPointer').height() / 2;
44
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   266
				
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   267
				if(!this.mosaic.isSearchByCurvesOn)
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   268
				{
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   269
					this.mosaic.isSearchByCurvesOn = true;
58
a28488078053 Front IDILL:
bastiena
parents: 52
diff changeset
   270
					this.mosaic.searchCanvas.onPointerOut();
44
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   271
					this.mosaic.searchCanvas.onPointerIn(mainPointerX, mainPointerY, secondPointerX, secondPointerY);
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   272
					this.mosaic.canDrawNextCurve = true;
58
a28488078053 Front IDILL:
bastiena
parents: 52
diff changeset
   273
					
a28488078053 Front IDILL:
bastiena
parents: 52
diff changeset
   274
					this.mosaic.pointersGreen();
44
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   275
				}
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   276
				else if(this.mosaic.isSearchByCurvesOn)
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   277
				{
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   278
					if(this.mosaic.canDrawNextCurve)
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   279
					{
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   280
						this.mosaic.canDrawNextCurve = false;
8393d3473b98 Front IDILL:
bastiena
parents:
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)
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   282
						{
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   283
							this.mosaic.searchCanvas.onPointerMove(mainPointerX, mainPointerY, secondPointerX, secondPointerY);
58
a28488078053 Front IDILL:
bastiena
parents: 52
diff changeset
   284
							this.mosaic.pointersGreen();
44
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   285
						}
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   286
					}
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   287
					else
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   288
					{
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   289
						this.mosaic.nextDrawCurveTimeout = setTimeout(function()
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   290
						{
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   291
							_this.mosaic.canDrawNextCurve = true;
52
277c94533395 Front IDILL :
bastiena
parents: 44
diff changeset
   292
						}, this.mosaic.config.timeoutNextDrawCurve);
44
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   293
					}
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   294
				}
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   295
			}
58
a28488078053 Front IDILL:
bastiena
parents: 52
diff changeset
   296
			else
a28488078053 Front IDILL:
bastiena
parents: 52
diff changeset
   297
			{
a28488078053 Front IDILL:
bastiena
parents: 52
diff changeset
   298
				this.mosaic.startSearch();
a28488078053 Front IDILL:
bastiena
parents: 52
diff changeset
   299
			}
44
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   300
		}
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   301
	}
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   302
	
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   303
	//Quant on a reçu un message, on vérifie la présence des deux pointeurs.
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   304
	this.mosaic.checkForBothPointersHere();
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   305
	
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   306
	if(this.mosaic.pointersIdleAvailable)
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   307
	{
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   308
		//On effectue une vérification de la position des pointeurs pour l'idle.
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   309
		this.mosaic.detectIdlePointers();
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   310
	}
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   311
	
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   312
	//Si le timeout a besoin d'être relancé ou bien que l'affichage de l'aide est disponible.
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   313
	if(this.mosaic.pointersIdleNeedLaunch || this.mosaic.canNotifyHelp)
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   314
	{
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   315
		// console.log('launch idle');
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   316
		this.mosaic.launchIdlePointers();
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   317
		this.mosaic.pointersIdleNeedLaunch = false;
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   318
	}
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   319
	
8393d3473b98 Front IDILL:
bastiena
parents:
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. 
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   321
	if(!this.mosaic.pointersIdleAvailable && this.mosaic.currentMode != "NO-USER" && this.mosaic.currentMode.indexOf("INCOMING") == -1 && this.mosaic.areBothPointersHere)
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   322
	{
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   323
		//On enclenche la détection d'idle.
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   324
		this.mosaic.pointersIdleAvailable = true;
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   325
		this.mosaic.pointersIdleNeedLaunch = true;
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   326
	}
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   327
	// /!\/!\ //
8393d3473b98 Front IDILL:
bastiena
parents:
diff changeset
   328
}