|
52
|
1 |
/* |
|
|
2 |
* This file is part of the TraKERS\Front IDILL package. |
|
|
3 |
* |
|
|
4 |
* (c) IRI <http://www.iri.centrepompidou.fr/> |
|
|
5 |
* |
|
|
6 |
* For the full copyright and license information, please view the LICENSE |
|
|
7 |
* file that was distributed with this source code. |
|
|
8 |
*/ |
|
|
9 |
|
|
|
10 |
/* |
|
|
11 |
* Projet : TraKERS |
|
|
12 |
* Module : Front IDILL |
|
|
13 |
* Fichier : searchCanvas.js |
|
|
14 |
* |
|
|
15 |
* Auteur : alexandre.bastien@iri.centrepompidou.fr |
|
|
16 |
* |
|
|
17 |
* Fonctionnalités : Définit les fonctions de recherche par courbe de haut niveau (instantiation et manipulation de la classe de recherche par courbe mais pas les courbes en elles-mêmes ni le détecteur). |
|
|
18 |
*/ |
|
45
|
19 |
|
|
|
20 |
/* |
|
|
21 |
* Déclaration du canvas de recherche par courbes. |
|
52
|
22 |
* Est appelé dans le fichier : |
|
|
23 |
* search > fonction startSearch. |
|
45
|
24 |
*/ |
|
52
|
25 |
function SearchCanvas(_canvasTop, _canvasLeft, _canvasWidth, _canvasHeight, _margin_top, _fadeTime, _inMosaic, _mosaic) |
|
35
|
26 |
{ |
|
52
|
27 |
//Coordonnées, dimensions et autres paramètres du canvas. |
|
|
28 |
this.canvasTop = _canvasTop; |
|
|
29 |
this.canvasLeft = _canvasLeft; |
|
|
30 |
this.canvasWidth = _canvasWidth; |
|
|
31 |
this.canvasHeight = _canvasHeight; |
|
|
32 |
this.fadeTime = _fadeTime; |
|
|
33 |
this.margin_top = _margin_top; |
|
|
34 |
|
|
|
35 |
this.mosaic = _mosaic; |
|
|
36 |
|
|
|
37 |
//Courbe du pointeur principal. |
|
|
38 |
this.mainPath; |
|
|
39 |
this.mainPathStroke; |
|
|
40 |
|
|
|
41 |
//Courbe du pointeur secondaire. |
|
|
42 |
this.secondPath; |
|
|
43 |
this.secondPathStroke; |
|
|
44 |
|
|
|
45 |
//Courbe indicatrice de la direction actuelle. |
|
|
46 |
this.direction; |
|
|
47 |
|
|
|
48 |
//Point précédent des pointeurs. |
|
|
49 |
this.mainLastPoint; |
|
|
50 |
this.secondLastPoint; |
|
|
51 |
|
|
|
52 |
//Coordonnées précédentes des pointeurs. |
|
|
53 |
this.mainPointerLastX; |
|
|
54 |
this.mainPointerLastY; |
|
|
55 |
this.secondPointerLastX; |
|
|
56 |
this.secondPointerLastY; |
|
|
57 |
|
|
|
58 |
this.inMosaic = _inMosaic; |
|
|
59 |
|
|
|
60 |
this.detector; |
|
35
|
61 |
} |
|
|
62 |
|
|
45
|
63 |
/* |
|
|
64 |
* Fonction d'initialisation du canvas de recherche par courbes. |
|
52
|
65 |
* Est appelé dans le fichier : |
|
|
66 |
* search > fonction startSearch. |
|
45
|
67 |
*/ |
|
52
|
68 |
SearchCanvas.prototype.create = function(dictionary) |
|
35
|
69 |
{ |
|
52
|
70 |
var _this = this; |
|
|
71 |
|
|
|
72 |
//On crée le canvas. |
|
|
73 |
var canvas = '<canvas id="paperCanvas" width="' + this.canvasWidth + 'px" height="' + this.canvasHeight + 'px" class="canvas"></canvas>'; |
|
|
74 |
//On l'ajoute à la page. |
|
|
75 |
$('body').append(canvas); |
|
|
76 |
|
|
|
77 |
$('.canvas').css( |
|
|
78 |
{ |
|
|
79 |
top: this.canvasTop, |
|
|
80 |
left: this.canvasLeft |
|
|
81 |
}); |
|
|
82 |
|
|
|
83 |
//S'il est dans la mosaique, on le réhausse en fonction de la taille de la marge verticale. |
|
|
84 |
if(this.inMosaic) |
|
|
85 |
{ |
|
|
86 |
$('.canvas').css( |
|
|
87 |
{ |
|
|
88 |
"margin-top": this.margin_top |
|
|
89 |
}); |
|
|
90 |
} |
|
|
91 |
|
|
|
92 |
//On instancie le détecteur de courbes de recherche. |
|
|
93 |
this.detector = new CurvesDetector(6, 100, dictionary, this.mosaic); |
|
|
94 |
|
|
|
95 |
//On active le canvas. |
|
|
96 |
paper.setup('paperCanvas'); |
|
35
|
97 |
}; |
|
|
98 |
|
|
45
|
99 |
/* |
|
|
100 |
* Fonction appelée pour quitter le mode de recherche par courbes. |
|
52
|
101 |
* Est appelé dans le fichier : |
|
|
102 |
* search > fonction leaveSearch. |
|
45
|
103 |
*/ |
|
52
|
104 |
SearchCanvas.prototype.leaveSearch = function() |
|
35
|
105 |
{ |
|
52
|
106 |
$('.canvas').fadeTo(this.fadeTime, 0, function() |
|
|
107 |
{ |
|
|
108 |
$('.canvas').remove(); |
|
|
109 |
}); |
|
79
|
110 |
|
|
|
111 |
if(this.mosaic.isTablet) |
|
|
112 |
{ |
|
|
113 |
this.mosaic.isTouchStart = false; |
|
|
114 |
} |
|
35
|
115 |
}; |
|
|
116 |
|
|
45
|
117 |
/* |
|
|
118 |
* Fonction de déclaration des courbes. |
|
52
|
119 |
* Est appelé dans les fichiers : |
|
|
120 |
* mosaic > fonctions onMouseDown et onMouseMove. |
|
|
121 |
* client > fonction processMsg. |
|
45
|
122 |
*/ |
|
52
|
123 |
SearchCanvas.prototype.onPointerIn = function(mainPointerX, mainPointerY, secondPointerX, secondPointerY) |
|
35
|
124 |
{ |
|
79
|
125 |
// console.log('IN'); |
|
|
126 |
|
|
52
|
127 |
if(this.mosaic.currentMode != 'MOSAIC' && this.mosaic.currentMode != 'FILTER') |
|
|
128 |
{ |
|
|
129 |
mainPointerX -= 130; |
|
|
130 |
mainPointerY -= 60; |
|
79
|
131 |
|
|
|
132 |
if(secondPointerX && secondPointerY) |
|
|
133 |
{ |
|
|
134 |
secondPointerX -= 130; |
|
|
135 |
secondPointerY -= 60; |
|
|
136 |
} |
|
52
|
137 |
} |
|
|
138 |
|
|
|
139 |
//On obtient les coordonnées du pointeur principal en px. |
|
|
140 |
mainPointerX = Math.floor(mainPointerX); |
|
|
141 |
mainPointerY = Math.floor(mainPointerY); |
|
|
142 |
|
|
|
143 |
//On forme le contour la courbe principale. |
|
|
144 |
this.mainPathStroke = new paper.Path(); |
|
|
145 |
this.mainPathStroke.strokeColor = '#366F7A'; |
|
|
146 |
this.mainPathStroke.strokeWidth = 18; |
|
|
147 |
this.mainPathStroke.strokeCap = 'round'; |
|
|
148 |
this.mainPathStroke.strokeJoin = 'round'; |
|
|
149 |
|
|
|
150 |
//On forme la courbe principale. |
|
|
151 |
this.mainPath = new paper.Path(); |
|
|
152 |
this.mainPath.strokeColor = '#02FEFF'; |
|
|
153 |
this.mainPath.strokeWidth = 10; |
|
|
154 |
this.mainPath.strokeCap = 'round'; |
|
|
155 |
this.mainPath.strokeJoin = 'round'; |
|
|
156 |
|
|
|
157 |
//Si on a un pointeur secondaire |
|
|
158 |
if(secondPointerX && secondPointerY) |
|
|
159 |
{ |
|
|
160 |
//On obtient les coordonnées du pointeur secondaire en px. |
|
|
161 |
secondPointerX = Math.floor(secondPointerX); |
|
|
162 |
secondPointerY = Math.floor(secondPointerY); |
|
|
163 |
|
|
|
164 |
//On forme le contour de la courbe secondaire. |
|
|
165 |
this.secondPathStroke = new paper.Path(); |
|
58
|
166 |
this.secondPathStroke.strokeColor = '#366F7A'; |
|
|
167 |
this.secondPathStroke.strokeWidth = 18; |
|
52
|
168 |
this.secondPathStroke.strokeCap = 'round'; |
|
|
169 |
this.secondPathStroke.strokeJoin = 'round'; |
|
|
170 |
|
|
|
171 |
//On forme la courbe secondaire. |
|
|
172 |
this.secondPath = new paper.Path(); |
|
58
|
173 |
this.secondPath.strokeColor = '#02FEFF'; |
|
52
|
174 |
this.secondPath.strokeWidth = 10; |
|
|
175 |
this.secondPath.strokeCap = 'round'; |
|
|
176 |
this.secondPath.strokeJoin = 'round'; |
|
|
177 |
} |
|
|
178 |
|
|
|
179 |
//On raffraichit l'affichage. |
|
|
180 |
paper.view.draw(); |
|
35
|
181 |
}; |
|
|
182 |
|
|
45
|
183 |
/* |
|
|
184 |
* Fonction appelée lorsque les pointeurs bougent pour construire la courbe. |
|
52
|
185 |
* Est appelé dans les fichiers : |
|
|
186 |
* mosaic > fonction onMouseMove. |
|
|
187 |
* client > fonction processMsg. |
|
45
|
188 |
*/ |
|
52
|
189 |
SearchCanvas.prototype.onPointerMove = function(mainPointerX, mainPointerY, secondPointerX, secondPointerY) |
|
45
|
190 |
{ |
|
79
|
191 |
// console.log('MOVE'); |
|
|
192 |
|
|
52
|
193 |
//Si on est dans une video, on réhausse |
|
59
|
194 |
if(this.mosaic.currentMode != 'MOSAIC' && this.mosaic.currentMode != 'FILTER' && this.mosaic.config.mouseInteractions) |
|
52
|
195 |
{ |
|
79
|
196 |
// mainPointerX -= 130; |
|
|
197 |
// mainPointerY -= 60; |
|
|
198 |
|
|
|
199 |
if(secondPointerX && secondPointerY) |
|
|
200 |
{ |
|
|
201 |
secondPointerX -= 130; |
|
|
202 |
secondPointerY -= 60; |
|
|
203 |
} |
|
52
|
204 |
} |
|
|
205 |
|
|
|
206 |
//On obtient les coordonnées du pointeur principal en px. |
|
|
207 |
mainPointerX = Math.floor(mainPointerX); |
|
|
208 |
mainPointerY = Math.floor(mainPointerY); |
|
|
209 |
|
|
|
210 |
//Si les coordonnées du pointeur principal n'ont pas été affectées, on les affecte. |
|
|
211 |
if(!this.mainPointerLastX || !this.mainPointerLastY) |
|
|
212 |
{ |
|
|
213 |
this.mainPointerLastX = mainPointerX; |
|
|
214 |
this.mainPointerLastY = mainPointerY; |
|
|
215 |
} |
|
|
216 |
|
|
|
217 |
//On crée les points de la courbe principale. |
|
|
218 |
var mainPoint = new paper.Point(mainPointerX, mainPointerY); |
|
|
219 |
var mainPointStroke = new paper.Point(mainPointerX, mainPointerY); |
|
|
220 |
|
|
|
221 |
//On les ajoute à la courbe. |
|
|
222 |
this.mainPathStroke.add(mainPointStroke); |
|
|
223 |
this.mainPathStroke.smooth(); |
|
|
224 |
|
|
|
225 |
//On place le premier point de la courbe, qu'on lisse. |
|
|
226 |
this.mainPath.add(mainPoint); |
|
|
227 |
this.mainPath.smooth(); |
|
|
228 |
|
|
|
229 |
//Si on a un pointeur secondaire. |
|
|
230 |
if(secondPointerX && secondPointerY) |
|
|
231 |
{ |
|
|
232 |
//On obtient les coordonnées du pointeur secondaire en px. |
|
|
233 |
secondPointerX = Math.floor(secondPointerX); |
|
|
234 |
secondPointerY = Math.floor(secondPointerY); |
|
|
235 |
|
|
|
236 |
//Si les coordonnées du pointeur principal n'ont pas été affectées, on les affecte. |
|
|
237 |
if(!this.secondPointerLastX || !this.secondPointerLastY) |
|
|
238 |
{ |
|
|
239 |
this.secondPointerLastX = secondPointerX; |
|
|
240 |
this.secondPointerLastY = secondPointerY; |
|
|
241 |
} |
|
|
242 |
|
|
|
243 |
//On crée les points de la courbe secondaire. |
|
58
|
244 |
var secondPoint = new paper.Point(secondPointerX, secondPointerY); |
|
|
245 |
var secondPointStroke = new paper.Point(secondPointerX, secondPointerY); |
|
52
|
246 |
|
|
|
247 |
//On les ajoute à la courbe. |
|
|
248 |
this.secondPathStroke.add(secondPointStroke); |
|
|
249 |
this.secondPathStroke.smooth(); |
|
|
250 |
|
|
|
251 |
//On place le premier point de la seconde courbe, qu'on lisse. |
|
|
252 |
this.secondPath.add(secondPoint); |
|
|
253 |
this.secondPath.smooth(); |
|
|
254 |
|
|
|
255 |
//On met l'avant dernière position du pointeur secondaire à jour. |
|
|
256 |
if(this.secondPointerLastX != secondPointerX) |
|
|
257 |
{ |
|
|
258 |
this.secondPointerLastX = secondPointerX; |
|
|
259 |
} |
|
|
260 |
if(this.secondPointerLastY != secondPointerY) |
|
|
261 |
{ |
|
|
262 |
this.secondPointerLastY = secondPointerY; |
|
|
263 |
} |
|
|
264 |
} |
|
|
265 |
|
|
|
266 |
//On met l'avant dernière position du pointeur principal à jour. |
|
|
267 |
if(this.mainPointerLastX != mainPointerX) |
|
|
268 |
{ |
|
|
269 |
this.mainPointerLastX = mainPointerX; |
|
|
270 |
} |
|
|
271 |
if(this.mainPointerLastY != mainPointerY) |
|
|
272 |
{ |
|
|
273 |
this.mainPointerLastY = mainPointerY; |
|
|
274 |
} |
|
|
275 |
|
|
|
276 |
//On met à jour les points dans le détecteur de courbes. |
|
58
|
277 |
this.detector.updatePos(mainPointerX, mainPointerY, secondPointerX, secondPointerY); |
|
52
|
278 |
|
|
|
279 |
//On met à jour l'affichage. |
|
|
280 |
paper.view.draw(); |
|
45
|
281 |
}; |
|
|
282 |
|
|
|
283 |
/* |
|
|
284 |
* Fonction appelée lorsqu'on cesse de dessiner une courbe. |
|
52
|
285 |
* Est appelé dans les fichiers : |
|
|
286 |
* mosaic > fonction onMouseUp. |
|
|
287 |
* client > fonction processMsg. |
|
45
|
288 |
*/ |
|
52
|
289 |
SearchCanvas.prototype.onPointerOut = function() |
|
35
|
290 |
{ |
|
79
|
291 |
// console.log('OUT'); |
|
|
292 |
// console.trace(); |
|
|
293 |
|
|
|
294 |
//On quitte la zone de recherche. |
|
|
295 |
this.isUserInSearchZone = false; |
|
|
296 |
|
|
|
297 |
//On regarde si ce qu'on a tracé correspond à une courbe en particulier. |
|
|
298 |
var gesture_match = this.mosaic.gestureWithSameCode(this.mosaic.actualCode); |
|
|
299 |
this.mosaic.actualCode = ''; |
|
|
300 |
|
|
|
301 |
//Si oui. |
|
|
302 |
if(gesture_match.length > 0) |
|
|
303 |
{ |
|
|
304 |
//Si on est en mode recherche dans une vidéo et que le player est prêt. |
|
|
305 |
if(this.mosaic.currentMode == "SEARCH" && this.mosaic.playerIsReady) |
|
|
306 |
{ |
|
|
307 |
//On effectue une recherche dans cette vidéo. |
|
|
308 |
this.mosaic.player.widgets[0].searchByGesture(gesture_match); |
|
|
309 |
this.mosaic.isCurrentlyInASearchByGesture = this.mosaic.player.widgets[0].isCurrentlyInASearchByGesture; |
|
|
310 |
|
|
|
311 |
//On va au premier marqueur trouvé. |
|
|
312 |
if(this.mosaic.player && this.mosaic.player.widgets[0] && this.mosaic.timeToGoAt[this.mosaic.centerId] === 0 && this.mosaic.player.widgets[0].atLeastOneSearchMarker(this.mosaic.currentSearchGesture[this.mosaic.centerId])) |
|
|
313 |
{ |
|
|
314 |
this.mosaic.player.widgets[0].goToFirstSearchedMarker(this.mosaic.currentSearchGesture[this.mosaic.centerId]); |
|
|
315 |
} |
|
|
316 |
|
|
|
317 |
//On affiche la notification de gesture de recherche. |
|
|
318 |
this.mosaic.removeNotifications(); |
|
|
319 |
this.mosaic.currentSearchGesture[this.mosaic.centerId] = gesture_match; |
|
|
320 |
this.mosaic.searchGesture(gesture_match, 'valid'); |
|
|
321 |
this.mosaic.curvesGesturesFound = false; |
|
|
322 |
} |
|
|
323 |
//Si on est en mode de filtrage de mosaique. |
|
|
324 |
else if(this.mosaic.currentMode == "FILTER") |
|
|
325 |
{ |
|
|
326 |
if(this.mosaic.isMosaicFiltered) |
|
|
327 |
{ |
|
|
328 |
//On notifie la recherche par filtrage. |
|
|
329 |
this.mosaic.removeNotifications(); |
|
|
330 |
this.mosaic.filterSearchedType = gesture_match; |
|
|
331 |
this.mosaic.filterGesture(gesture_match, 'valid'); |
|
|
332 |
//On filtre la mosaique. |
|
|
333 |
this.mosaic.searchFilter(gesture_match); |
|
|
334 |
this.mosaic.curvesGesturesFound = false; |
|
|
335 |
} |
|
|
336 |
} |
|
|
337 |
} |
|
|
338 |
//Si aucune gesture ne matche dans le dictionnaire. |
|
|
339 |
else if(!this.mosaic.mustTakeOutHands && this.mosaic.mouseInteractions) |
|
|
340 |
{ |
|
|
341 |
//Si on était en mode filtrage de la mosaïque et qu'aucune gesture de filtrage n'avait été détectée avant ca, on revient en mode mosaïque. |
|
|
342 |
if(this.mosaic.currentMode == "FILTER" && this.mosaic.filterSearchedType == "") |
|
|
343 |
{ |
|
|
344 |
this.mosaic.currentMode = "MOSAIC"; |
|
|
345 |
this.mosaic.isMosaicFiltered = false; |
|
|
346 |
} |
|
|
347 |
//Sinon si on était en mode recherche dans une video et qu'aucune gesture n'avait été détectée avant ca, on revient en mode video. |
|
|
348 |
if(this.mosaic.currentMode == "SEARCH" && this.mosaic.currentSearchGesture[this.mosaic.centerId] == "") |
|
|
349 |
{ |
|
|
350 |
this.mosaic.currentMode = "VIDEO"; |
|
|
351 |
} |
|
|
352 |
} |
|
|
353 |
|
|
52
|
354 |
//On réinitialise la courbe principale. |
|
79
|
355 |
if(this.mainPathStroke) |
|
|
356 |
{ |
|
|
357 |
this.mainPathStroke.remove(); |
|
|
358 |
} |
|
|
359 |
if(this.mainPath) |
|
|
360 |
{ |
|
|
361 |
this.mainPath.remove(); |
|
|
362 |
} |
|
52
|
363 |
|
|
|
364 |
this.mainPointerLastX = 0; |
|
|
365 |
this.mainPointerLastY = 0; |
|
79
|
366 |
this.mainPointerX = 0; |
|
|
367 |
this.mainPointerY = 0; |
|
52
|
368 |
|
|
|
369 |
//On réinitialise le détecteur. |
|
|
370 |
this.detector.reinit(); |
|
|
371 |
|
|
|
372 |
//Si on a un second pointeur, on réinitialise la courbe secondaire. |
|
|
373 |
if(this.secondPathStroke) |
|
|
374 |
{ |
|
|
375 |
this.secondPathStroke.remove(); |
|
|
376 |
} |
|
|
377 |
if(this.secondPath) |
|
|
378 |
{ |
|
|
379 |
this.secondPath.remove(); |
|
|
380 |
} |
|
|
381 |
|
|
|
382 |
//On met à jour l'affichage. |
|
|
383 |
paper.view.draw(); |
|
35
|
384 |
}; |