18 */ |
18 */ |
19 |
19 |
20 /* |
20 /* |
21 * Classe définissant les pointers. |
21 * Classe définissant les pointers. |
22 */ |
22 */ |
23 function pointers() |
23 function Pointers(config) |
24 { |
24 { |
25 this.mainPointerLastX = 0; |
25 this.mainPointerLastX = 0; |
26 this.mainPointerLastY = 0; |
26 this.mainPointerLastY = 0; |
27 this.secondPointerLastX = 0; |
27 this.secondPointerLastX = 0; |
28 this.secondPointerLastY = 0; |
28 this.secondPointerLastY = 0; |
|
29 |
|
30 this.isMainPointerDisplayed = false; |
|
31 this.isSecondPointerDisplayed = false; |
|
32 |
|
33 this.pointerLeftTimeout = null; |
|
34 this.pointerRightTimeout = null; |
|
35 |
|
36 this.config = config; |
|
37 |
|
38 this.client = new Client(this.config.host, this.config.port, this); |
|
39 |
|
40 this.addPointers(); |
29 } |
41 } |
30 |
42 |
31 /* |
43 /* |
32 * Affiche les pointeurs. |
44 * Affiche les pointeurs. |
33 */ |
45 */ |
34 pointers.prototype.addPointers = function() |
46 Pointers.prototype.addPointers = function() |
35 { |
47 { |
36 var mainPointer = '<div id="mainPointer" class="pointers"></div>'; |
48 var mainPointer = '<div id="mainPointer" class="pointers"></div>'; |
37 var secondPointer = '<div id="secondPointer" class="pointers"></div>'; |
49 var secondPointer = '<div id="secondPointer" class="pointers"></div>'; |
38 $('body').append(mainPointer + secondPointer); |
50 var textPanel = "<div id='textPanel'>Les mains sont trop loin ou trop près.</div>"; |
|
51 $('body').append(textPanel + mainPointer + secondPointer); |
39 |
52 |
40 $('#secondPointer').css( |
53 $('#secondPointer').css( |
41 { |
54 { |
42 top: $(window).height() / 2 - $('#secondPointer').height() / 2, |
55 top: $(window).height() / 2 - $('#secondPointer').height() / 2, |
43 left: $(window).width() / 4 - $('#secondPointer').width() / 2 |
56 left: $(window).width() / 4 - $('#secondPointer').width() / 2, |
|
57 opacity: 0 |
44 }); |
58 }); |
45 |
59 |
46 this.secondPointerLastX = $(window).width() / 4 - $('#secondPointer').width() / 2; |
60 this.secondPointerLastX = $(window).width() / 4 - $('#secondPointer').width() / 2; |
47 this.secondPointerLastY = $(window).height() / 2 - $('#secondPointer').height() / 2; |
61 this.secondPointerLastY = $(window).height() / 2 - $('#secondPointer').height() / 2; |
48 |
62 |
49 $('#mainPointer').css( |
63 $('#mainPointer').css( |
50 { |
64 { |
51 top: $(window).height() / 2 - $('#mainPointer').height() / 2, |
65 top: $(window).height() / 2 - $('#mainPointer').height() / 2, |
52 left: $(window).width() * 3 / 4 - $('#mainPointer').width() / 2 |
66 left: $(window).width() * 3 / 4 - $('#mainPointer').width() / 2, |
|
67 opacity: 0 |
53 }); |
68 }); |
54 |
69 |
55 this.mainPointerLastX = $(window).width() * 3 / 4 - $('#mainPointer').width() / 2; |
70 this.mainPointerLastX = $(window).width() * 3 / 4 - $('#mainPointer').width() / 2; |
56 this.mainPointerLastY = $(window).height() / 2 - $('#mainPointer').height() / 2; |
71 this.mainPointerLastY = $(window).height() / 2 - $('#mainPointer').height() / 2; |
57 } |
72 } |
58 |
73 |
59 /* |
74 /* |
60 * Affiche/Masque le pointeur principal. |
75 * Affiche/Masque le pointeur principal. |
61 * Main est un booléen valant vrai s'il faut afficher le pointeur. |
76 * Main est un booléen valant vrai s'il faut afficher le pointeur. |
62 */ |
77 */ |
63 pointers.prototype.mainPointerDisplay = function(main) |
78 Pointers.prototype.mainPointerDisplay = function(main) |
64 { |
79 { |
65 var _this = this; |
80 var _this = this; |
66 |
81 |
67 //Si le booléen est à vrai, on affiche le pointeur. |
82 //Si le booléen est à vrai, on affiche le pointeur. |
68 if(main) |
83 if(main) |
69 { |
84 { |
70 $('#mainPointer').fadeTo(this.config['timeFilling'], '1'); |
85 $('#mainPointer').fadeTo(this.config.timeFilling, '1'); |
71 } |
86 } |
72 else |
87 else |
73 { |
88 { |
74 $('#mainPointer').fadeTo(this.config['timeFilling'], '0'); |
89 $('#mainPointer').fadeTo(this.config.timeFilling, '0'); |
75 } |
90 } |
76 } |
91 } |
77 /* |
92 /* |
78 * Affiche/Masque le pointeur secondaire. |
93 * Affiche/Masque le pointeur secondaire. |
79 * Main est un booléen valant vrai s'il faut afficher le pointeur. |
94 * Main est un booléen valant vrai s'il faut afficher le pointeur. |
80 */ |
95 */ |
81 pointers.prototype.secondPointerDisplay = function(second) |
96 Pointers.prototype.secondPointerDisplay = function(second) |
82 { |
97 { |
83 var _this = this; |
98 var _this = this; |
84 |
99 |
85 //Si le booléen est à vrai, on affiche le pointeur. |
100 //Si le booléen est à vrai, on affiche le pointeur. |
86 if(second) |
101 if(second) |
87 { |
102 { |
88 $('#secondPointer').fadeTo(this.config['timeFilling'], '1'); |
103 $('#secondPointer').fadeTo(this.config.timeFilling, '1'); |
89 } |
104 } |
90 else |
105 else |
91 { |
106 { |
92 $('#secondPointer').fadeTo(this.config['timeFilling'], '0'); |
107 $('#secondPointer').fadeTo(this.config.timeFilling, '0'); |
93 } |
108 } |
94 } |
109 } |
95 |
110 |
96 /* |
111 /* |
97 * Raffraîchit la position des pointeurs. |
112 * Raffraîchit la position des pointeurs. |
98 */ |
113 */ |
99 pointers.prototype.refreshMainPointer = function(x, y) |
114 Pointers.prototype.refreshMainPointer = function(x, y) |
100 { |
115 { |
101 x *= 7; |
116 x *= 7; |
102 y *= 7; |
117 y *= 7; |
103 x -= $(window).width() * 3 / 4; |
118 x -= $(window).width() * 3 / 4; |
104 y -= $(window).height() * 2 / 4; |
119 y -= $(window).height() * 2 / 4; |