front_idill/src/communication/js/client.js
changeset 58 a28488078053
parent 52 277c94533395
child 59 e812126f75f4
equal deleted inserted replaced
57:d0c393730443 58:a28488078053
   120 		var instruction = msg.data.substring(2, msg.data.length);
   120 		var instruction = msg.data.substring(2, msg.data.length);
   121 		pt = instruction.split(';');
   121 		pt = instruction.split(';');
   122 		var x = Math.abs(parseFloat(pt[0])), y = Math.abs(parseFloat(pt[1]));
   122 		var x = Math.abs(parseFloat(pt[0])), y = Math.abs(parseFloat(pt[1]));
   123 		// console.log(Math.abs(parseFloat(pt[0])), Math.abs(parseFloat(pt[1])));
   123 		// console.log(Math.abs(parseFloat(pt[0])), Math.abs(parseFloat(pt[1])));
   124 		
   124 		
   125 		this.pointerLeft = true;
   125 		this.pointerRight = true;
   126 		clearTimeout(this.pointerLeftTimeout);
   126 		clearTimeout(this.pointerRightTimeout);
   127 		
   127 		
   128 		if(!this.mosaic.mouseInteractions && this.mosaic.currentMode != 'NO-USER' && this.mosaic.currentMode.indexOf('INCOMING') == -1)
   128 		if(!this.mosaic.mouseInteractions && this.mosaic.currentMode != 'NO-USER' && this.mosaic.currentMode.indexOf('INCOMING') == -1)
   129 		{
   129 		{
   130 			// console.log('pt');
   130 			// console.log('pt');
   131 			this.mosaic.refreshPointers(x, y, true);
   131 			this.mosaic.refreshPointers(x, y, true);
   136 		{
   136 		{
   137 			this.mosaic.mainPointerDisplay(true);
   137 			this.mosaic.mainPointerDisplay(true);
   138 			this.mosaic.isMainPointerDisplayed = true;
   138 			this.mosaic.isMainPointerDisplayed = true;
   139 		}
   139 		}
   140 		
   140 		
   141 		this.pointerLeftTimeout = setTimeout(function()
   141 		this.pointerRightTimeout = setTimeout(function()
   142 		{
   142 		{
   143 			// console.log('RELEASE LEFT');
   143 			// console.log('RELEASE LEFT');
   144 			_this.pointerLeft = false;
   144 			//Timeout indiquant quand la main gauche part.
       
   145 			_this.pointerRight = false;
   145 			
   146 			
   146 			if(_this.mosaic.isMainPointerDisplayed)
   147 			if(_this.mosaic.isMainPointerDisplayed)
   147 			{
   148 			{
   148 				_this.mosaic.isMainPointerDisplayed = false;
   149 				_this.mosaic.isMainPointerDisplayed = false;
   149 				_this.mosaic.mainPointerDisplay(false);
   150 				_this.mosaic.mainPointerDisplay(false);
       
   151 			}
       
   152 			
       
   153 			if(_this.mosaic.isSearchByCurvesOn)
       
   154 			{
       
   155 				_this.mosaic.isSearchByCurvesOn = false;
       
   156 				if(_this.mosaic.searchCanvas)
       
   157 				{
       
   158 					_this.mosaic.searchCanvas.onPointerOut();
       
   159 					
       
   160 					$('#mainPointer').css('background-image', 'url(./img/cursors/pointerC.png)');
       
   161 					$('#secondPointer').css('background-image', 'url(./img/cursors/pointer2C.png)');
       
   162 				}
       
   163 			}
       
   164 			//On peut effectuer de nouveau une recherche par courbes.
       
   165 			if(!_this.pointerLeft)
       
   166 			{
       
   167 				_this.mosaic.mustTakeOutHands = false;
   150 			}
   168 			}
   151 		}, this.timePointers);
   169 		}, this.timePointers);
   152 	}
   170 	}
   153 	//Sinon si ce sont les coordonnées de la main gauche.
   171 	//Sinon si ce sont les coordonnées de la main gauche.
   154 	else if(msg.data[0] == '0')
   172 	else if(msg.data[0] == '0')
   156 		var instruction = msg.data.substring(2, msg.data.length);
   174 		var instruction = msg.data.substring(2, msg.data.length);
   157 		pt = instruction.split(';');
   175 		pt = instruction.split(';');
   158 		var x = Math.abs(parseFloat(pt[0])), y = Math.abs(parseFloat(pt[1]));
   176 		var x = Math.abs(parseFloat(pt[0])), y = Math.abs(parseFloat(pt[1]));
   159 		// console.log(Math.abs(parseFloat(pt[0])), Math.abs(parseFloat(pt[1])));
   177 		// console.log(Math.abs(parseFloat(pt[0])), Math.abs(parseFloat(pt[1])));
   160 		
   178 		
   161 		this.pointerRight = true;
   179 		this.pointerLeft = true;
   162 		clearTimeout(this.pointerRightTimeout);
   180 		clearTimeout(this.pointerLeftTimeout);
   163 		
   181 		
   164 		if(!this.mosaic.mouseInteractions && this.mosaic.currentMode != 'NO-USER' && this.mosaic.currentMode.indexOf('INCOMING') == -1)
   182 		if(!this.mosaic.mouseInteractions && this.mosaic.currentMode != 'NO-USER' && this.mosaic.currentMode.indexOf('INCOMING') == -1)
   165 		{
   183 		{
   166 			this.mosaic.refreshPointers(x, y, false);
   184 			this.mosaic.refreshPointers(x, y, false);
   167 		}
   185 		}
   170 		{
   188 		{
   171 			this.mosaic.secondPointerDisplay(true);
   189 			this.mosaic.secondPointerDisplay(true);
   172 			this.mosaic.isSecondPointerDisplayed = true;
   190 			this.mosaic.isSecondPointerDisplayed = true;
   173 		}
   191 		}
   174 		
   192 		
   175 		this.pointerRightTimeout = setTimeout(function()
   193 		//Timeout indiquant quand la main droite part.
       
   194 		this.pointerLeftTimeout = setTimeout(function()
   176 		{
   195 		{
   177 			// console.log('RELEASE RIGHT');
   196 			// console.log('RELEASE RIGHT');
   178 			_this.pointerRight = false;
   197 			_this.pointerLeft = false;
   179 			
   198 			
   180 			if(_this.mosaic.isSecondPointerDisplayed)
   199 			if(_this.mosaic.isSecondPointerDisplayed)
   181 			{
   200 			{
   182 				_this.mosaic.isSecondPointerDisplayed = false;
   201 				_this.mosaic.isSecondPointerDisplayed = false;
   183 				_this.mosaic.secondPointerDisplay(false);
   202 				_this.mosaic.secondPointerDisplay(false);
       
   203 			}
       
   204 			
       
   205 			if(_this.mosaic.isSearchByCurvesOn)
       
   206 			{
       
   207 				_this.mosaic.isSearchByCurvesOn = false;
       
   208 				if(_this.mosaic.searchCanvas)
       
   209 				{
       
   210 					_this.mosaic.searchCanvas.onPointerOut();
       
   211 					
       
   212 					$('#mainPointer').css('background-image', 'url(./img/cursors/pointerC.png)');
       
   213 					$('#secondPointer').css('background-image', 'url(./img/cursors/pointer2C.png)');
       
   214 				}
       
   215 			}
       
   216 			//On peut effectuer de nouveau une recherche par courbes.
       
   217 			if(!_this.pointerRight)
       
   218 			{
       
   219 				_this.mosaic.mustTakeOutHands = false;
   184 			}
   220 			}
   185 		}, this.timePointers);
   221 		}, this.timePointers);
   186 	}
   222 	}
   187 	
   223 	
   188 	if(this.pointerLeft && !this.pointerRight || !this.pointerLeft && this.pointerRight)
   224 	if(this.pointerLeft && !this.pointerRight || !this.pointerLeft && this.pointerRight)
   189 	{
   225 	{
   190 		//On interrompt l'idle des pointeurs.
   226 		//On interrompt l'idle des pointeurs.
   191 		this.mosaic.pointersIdleAvailable = false;
   227 		this.mosaic.pointersIdleAvailable = false;
   192 		this.mosaic.removeIdlePointers();
   228 		this.mosaic.removeIdlePointers();
   193 		this.mosaic.areBothPointersHere = false;
   229 		this.mosaic.areBothPointersHere = false;
   194 		
       
   195 		if(this.mosaic.isSearchByCurvesOn)
       
   196 		{
       
   197 			this.mosaic.isSearchByCurvesOn = false;
       
   198 			if(this.mosaic.searchCanvas)
       
   199 			{
       
   200 				this.mosaic.searchCanvas.onPointerOut();
       
   201 				console.log('OUT !!!!!');
       
   202 			}
       
   203 		}
       
   204 	}
   230 	}
   205 	if(!this.pointerLeft && !this.pointerRight)
   231 	if(!this.pointerLeft && !this.pointerRight)
   206 	{
   232 	{
   207 		//On interrompt l'idle des pointeurs.
   233 		//On interrompt l'idle des pointeurs.
   208 		this.mosaic.pointersIdleAvailable = false;
   234 		this.mosaic.pointersIdleAvailable = false;
   209 		this.mosaic.removeIdlePointers();
   235 		this.mosaic.removeIdlePointers();
   210 		this.mosaic.areBothPointersHere = false;
   236 		this.mosaic.areBothPointersHere = false;
   211 		
   237 		
   212 		if(this.mosaic.isSearchByCurvesOn)
       
   213 		{
       
   214 			this.mosaic.isSearchByCurvesOn = false;
       
   215 			if(this.mosaic.searchCanvas)
       
   216 			{
       
   217 				this.mosaic.searchCanvas.onPointerOut();
       
   218 			}
       
   219 		}
       
   220 		
       
   221 		this.mosaic.deselectAllNeighbours();
   238 		this.mosaic.deselectAllNeighbours();
   222 		this.mosaic.preUnzoom();
   239 		this.mosaic.preUnzoom();
   223 	}
   240 	}
   224 	
   241 	
   225 	if(this.pointerLeft && this.pointerRight)
   242 	if(this.pointerLeft && this.pointerRight)
   226 	{
   243 	{
   227 		this.mosaic.areBothPointersHere = true;
   244 		this.mosaic.areBothPointersHere = true;
   228 		this.mosaic.removeCheckForBothPointersHere();
   245 		this.mosaic.removeCheckForBothPointersHere();
   229 		
   246 		
   230 		if(this.mosaic.currentMode == 'MOSAIC' || this.mosaic.currentMode == 'FILTER')
   247 		//On enlève les requêtes de zoom.
   231 		{
   248 		this.mosaic.preUnzoom();
   232 			$('#mainPointer').css('background-image', './img/cursors/pointer.png');
   249 		
   233 			$('#secondPointer').css('background-image', './img/cursors/pointer2.png');
   250 		if(this.mosaic.currentMode == 'MOSAIC' || this.mosaic.currentMode == 'FILTER' && !this.mosaic.isSearchByCurvesOn)
   234 		}
   251 		{
   235 		
   252 			$('#mainPointer').css('background-image', 'url(./img/cursors/pointer.png)');
   236 		if(this.mosaic.currentMode == 'FILTER' || this.mosaic.currentMode == 'SEARCH')
   253 			$('#secondPointer').css('background-image', 'url(./img/cursors/pointer2.png)');
   237 		{
   254 		}
       
   255 		
       
   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.
       
   257 		if((this.mosaic.currentMode == 'FILTER' || this.mosaic.currentMode == 'SEARCH') && !this.mosaic.mustTakeOutHands)
       
   258 		{
       
   259 			console.log('ON');
   238 			if(this.mosaic.searchCanvas)
   260 			if(this.mosaic.searchCanvas)
   239 			{
   261 			{
   240 				var mainPointerX = +$('#mainPointer').position().left + $('#mainPointer').width() / 2;
   262 				var mainPointerX = +$('#mainPointer').position().left + $('#mainPointer').width() / 2;
   241 				var mainPointerY = +$('#mainPointer').position().top - this.mosaic.MPTop_margin + $('#mainPointer').height() / 2;
   263 				var mainPointerY = +$('#mainPointer').position().top - this.mosaic.MPTop_margin + $('#mainPointer').height() / 2;
   242 				var secondPointerX = +$('#secondPointer').position().left + $('#mainPointer').width() / 2;
   264 				var secondPointerX = +$('#secondPointer').position().left + $('#secondPointer').width() / 2;
   243 				var secondPointerY = +$('#secondPointer').position().top - this.mosaic.MPTop_margin + $('#mainPointer').height() / 2;
   265 				var secondPointerY = +$('#secondPointer').position().top - this.mosaic.MPTop_margin + $('#secondPointer').height() / 2;
   244 				
   266 				
   245 				if(!this.mosaic.isSearchByCurvesOn)
   267 				if(!this.mosaic.isSearchByCurvesOn)
   246 				{
   268 				{
   247 					this.mosaic.isSearchByCurvesOn = true;
   269 					this.mosaic.isSearchByCurvesOn = true;
       
   270 					this.mosaic.searchCanvas.onPointerOut();
   248 					this.mosaic.searchCanvas.onPointerIn(mainPointerX, mainPointerY, secondPointerX, secondPointerY);
   271 					this.mosaic.searchCanvas.onPointerIn(mainPointerX, mainPointerY, secondPointerX, secondPointerY);
   249 					this.mosaic.canDrawNextCurve = true;
   272 					this.mosaic.canDrawNextCurve = true;
       
   273 					
       
   274 					this.mosaic.pointersGreen();
   250 				}
   275 				}
   251 				else if(this.mosaic.isSearchByCurvesOn)
   276 				else if(this.mosaic.isSearchByCurvesOn)
   252 				{
   277 				{
   253 					if(this.mosaic.canDrawNextCurve)
   278 					if(this.mosaic.canDrawNextCurve)
   254 					{
   279 					{
   255 						this.mosaic.canDrawNextCurve = false;
   280 						this.mosaic.canDrawNextCurve = false;
   256 						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)
   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)
   257 						{
   282 						{
   258 							console.log('move');
       
   259 							this.mosaic.searchCanvas.onPointerMove(mainPointerX, mainPointerY, secondPointerX, secondPointerY);
   283 							this.mosaic.searchCanvas.onPointerMove(mainPointerX, mainPointerY, secondPointerX, secondPointerY);
       
   284 							this.mosaic.pointersGreen();
   260 						}
   285 						}
   261 					}
   286 					}
   262 					else
   287 					else
   263 					{
   288 					{
   264 						this.mosaic.nextDrawCurveTimeout = setTimeout(function()
   289 						this.mosaic.nextDrawCurveTimeout = setTimeout(function()
   266 							_this.mosaic.canDrawNextCurve = true;
   291 							_this.mosaic.canDrawNextCurve = true;
   267 						}, this.mosaic.config.timeoutNextDrawCurve);
   292 						}, this.mosaic.config.timeoutNextDrawCurve);
   268 					}
   293 					}
   269 				}
   294 				}
   270 			}
   295 			}
       
   296 			else
       
   297 			{
       
   298 				this.mosaic.startSearch();
       
   299 			}
   271 		}
   300 		}
   272 	}
   301 	}
   273 	
   302 	
   274 	//Quant on a reçu un message, on vérifie la présence des deux pointeurs.
   303 	//Quant on a reçu un message, on vérifie la présence des deux pointeurs.
   275 	this.mosaic.checkForBothPointersHere();
   304 	this.mosaic.checkForBothPointersHere();