front_js/pointers/pointers/js/pointers.js
changeset 48 983d7be910c1
parent 41 d2f735d7763f
equal deleted inserted replaced
47:4e1ee94d70b1 48:983d7be910c1
    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;
   133         top: pointerY,
   148         top: pointerY,
   134         left: pointerX
   149         left: pointerX
   135     });
   150     });
   136 }
   151 }
   137 
   152 
   138 pointers.prototype.refreshSecondPointer = function(x, y)
   153 Pointers.prototype.refreshSecondPointer = function(x, y)
   139 {
   154 {
   140     if(!this.mouseInteractions)
   155     if(!this.mouseInteractions)
   141     {
   156     {
   142         x *= 7;
   157         x *= 7;
   143         y *= 7;
   158         y *= 7;
   174     {
   189     {
   175         top: pointerY,
   190         top: pointerY,
   176         left: pointerX
   191         left: pointerX
   177     });
   192     });
   178 }
   193 }
       
   194 
       
   195 /*
       
   196  * Met à jour l'affichage du texte.
       
   197 */
       
   198 Pointers.prototype.textUpdate = function()
       
   199 {
       
   200 	if(this.isMainPointerDisplayed && this.isSecondPointerDisplayed)
       
   201 	{
       
   202 		$('#textPanel').html('Les deux pointeurs sont détectés.');
       
   203 	}
       
   204 	else if(this.isMainPointerDisplayed && !this.isSecondPointerDisplayed)
       
   205 	{
       
   206 		$('#textPanel').html('Le pointer droit est détecté.');
       
   207 	}
       
   208 	else if(!this.isMainPointerDisplayed && this.isSecondPointerDisplayed)
       
   209 	{
       
   210 		$('#textPanel').html('Le pointeur gauche est détecté.');
       
   211 	}
       
   212 	if(!this.isMainPointerDisplayed && !this.isSecondPointerDisplayed)
       
   213 	{
       
   214 		$('#textPanel').html('Les mains sont trop loin ou trop près.');
       
   215 	}
       
   216 }