|
1 /* |
|
2 * This file is part of the TraKERS\Front JS 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 JS |
|
13 * Fichier : gestures.js |
|
14 * |
|
15 * Auteur : alexandre.bastien@iri.centrepompidou.fr |
|
16 * |
|
17 * Fonctionnalités : Définit la "classe" de gestion des gestes et définit des fonctions d'intéraction. |
|
18 */ |
|
19 |
|
20 /* |
|
21 * Classe définissant les gestes. |
|
22 */ |
|
23 function gestures(config) |
|
24 { |
|
25 this.isGestureShown = false; |
|
26 this.showGestureTimeout; |
|
27 |
|
28 this.imgWidth; |
|
29 this.imgHeight; |
|
30 |
|
31 this.config = config; |
|
32 |
|
33 var textPanel = "<div id='textPanel'>Aucune gesture n'est détectée.</div>"; |
|
34 var imagePanel = "<img id='imagePanel' src='./img/black.png'></img>"; |
|
35 $('body').append(textPanel + imagePanel); |
|
36 |
|
37 $('#imagePanel').load(function() |
|
38 { |
|
39 this.imgWidth = $('#imagePanel').width(); |
|
40 this.imgHeight = $('#imagePanel').height(); |
|
41 |
|
42 //On positionne l'image au centre de l'écran. |
|
43 $('#imagePanel').css( |
|
44 { |
|
45 top: ($(window).height() - this.imgWidth) / 2, |
|
46 left: ($(window).width() - this.imgHeight) / 2 |
|
47 }); |
|
48 }); |
|
49 |
|
50 this.wsClient = new client(this.config["host"], this.config["port"], this); |
|
51 } |
|
52 |
|
53 /* |
|
54 * Affiche les gestures reçues. |
|
55 */ |
|
56 gestures.prototype.showGesture = function(gesture) |
|
57 { |
|
58 //Si on n'avait aucune gesture, on peut l'afficher. |
|
59 if(!this.isGestureShown) |
|
60 { |
|
61 var _this = this; |
|
62 |
|
63 this.isGestureShown = true; |
|
64 $('#textPanel').html("Gesture de code " + gesture + " détectée."); |
|
65 //On retrouve le nom du fichier image correspondant dans le code de la gesture. |
|
66 gesture = gesture.toLowerCase().replace('-', '_'); |
|
67 $('#imagePanel').attr("src", "./img/" + gesture + ".png"); |
|
68 |
|
69 //On supprime l'affichage au bout de N ms. |
|
70 this.showGestureTimeout = setTimeout(function() |
|
71 { |
|
72 _this.isGestureShown = false; |
|
73 $('#imagePanel').attr("src", "./img/black.png"); |
|
74 $('#textPanel').html("Aucune gesture n'est détectée."); |
|
75 }, this.config["timeShowGesture"]); |
|
76 } |
|
77 } |