@@ -55,15 +55,30 @@ export default class MouseEventListener {
5555    constructor ( canvas : HTMLCanvasElement ,  streams : {  [ id : string ] : StreamDetails  } )  { 
5656        this . streams  =  streams ; 
5757
58-         const  fromMouseEvent  =  ( e : MouseEvent )  =>  ( {  x : e . offsetX ,  y : e . offsetY  } ) ; 
59-         const  fromTouchEvent  =  ( e : TouchEvent ,  fct : ( ( e : {  x : number ,  y : number  } )  =>  void ) )  =>  { 
58+         const  getDimensionsRatio  =  ( )  =>  { 
59+             return  { 
60+                 widthRatio : canvas . clientWidth  /  canvas . width , 
61+                 heightRatio : canvas . clientHeight  /  canvas . height , 
62+             } 
63+         } 
64+ 
65+         const  fromMouseEvent  =  ( e : MouseEvent )  =>  { 
66+             const  dimensionsRatio  =  getDimensionsRatio ( ) ; 
67+             return  { 
68+                 x : e . offsetX  /  dimensionsRatio . widthRatio , 
69+                 y : e . offsetY  /  dimensionsRatio . heightRatio , 
70+             } ; 
71+         } ; 
72+         const  fromTouchEvent  =  ( e : TouchEvent ,  fct : ( ( e : Coordinates )  =>  void ) )  =>  { 
6073            if  ( ! e . targetTouches [ 0 ] )  { 
6174                return ; 
6275            } 
6376            const  rect  =  ( e . target  as  HTMLCanvasElement ) . getBoundingClientRect ( ) ; 
77+             const  dimensionsRatio  =  getDimensionsRatio ( ) ; 
78+ 
6479            fct ( { 
65-                 x : e . targetTouches [ 0 ] . pageX  -  rect . left , 
66-                 y : e . targetTouches [ 0 ] . pageY  -  rect . top , 
80+                 x : ( e . targetTouches [ 0 ] . pageX  -  rect . left )   *   dimensionsRatio . widthRatio , 
81+                 y : ( e . targetTouches [ 0 ] . pageY  -  rect . top )   *   dimensionsRatio . heightRatio , 
6782            } ) ; 
6883        } ; 
6984
@@ -110,31 +125,31 @@ export default class MouseEventListener {
110125        } 
111126        this . dragStart  =  undefined ; 
112127    } 
113-     private  mouseDown ( e : Coordinates )  { 
128+     private  mouseDown ( mouseCoordinates : Coordinates )  { 
114129        if  ( this . overStream )  { 
115130            this . dragStart  =  { 
116131                ...this . overStream , 
117-                 offsetX : e . x  -  this . overStream . stream . displaySettings . position . x , 
118-                 offsetY : e . y  -  this . overStream . stream . displaySettings . position . y , 
132+                 offsetX : mouseCoordinates . x  -  this . overStream . stream . displaySettings . position . x , 
133+                 offsetY : mouseCoordinates . y  -  this . overStream . stream . displaySettings . position . y , 
119134                ...( this . overStream . stream . options . mask  ===  "circle"  ? {  circleRadius : this . overStream . stream . displaySettings . radius  }  : { } ) , 
120135                streamWidth : this . overStream . stream . displaySettings . displayResolution . width , 
121136                streamHeight : this . overStream . stream . displaySettings . displayResolution . height , 
122-                 x : e . x , 
123-                 y : e . y , 
137+                 x : mouseCoordinates . x , 
138+                 y : mouseCoordinates . y , 
124139                hasMoved : false , 
125140            } ; 
126141        }  else  { 
127142            this . dragStart  =  { 
128-                 x : e . x , 
129-                 y : e . y , 
143+                 x : mouseCoordinates . x , 
144+                 y : mouseCoordinates . y , 
130145                hasMoved : false , 
131146            } ; 
132147        } 
133148    } 
134-     private  mouseMove ( e : Coordinates )  { 
149+     private  mouseMove ( mouseCoordinates : Coordinates )  { 
135150        if  ( this . dragStart )  { 
136151            this . onDragListeners . forEach ( l  =>  l ( { 
137-                 ...e , 
152+                 ...mouseCoordinates , 
138153                dragStart : this . dragStart ! , 
139154            } ) ) ; 
140155            this . dragStart . hasMoved  =  true ; 
@@ -161,7 +176,7 @@ export default class MouseEventListener {
161176                if  ( stream . options . mask  ===  "circle" )  { 
162177                    const  centerX  =  x  +  stream . displaySettings . radius ! ; 
163178                    const  centerY  =  y  +  stream . displaySettings . radius ! ; 
164-                     const  distance  =  Math . sqrt ( Math . pow ( centerX  -  e . x ,  2 )  +  Math . pow ( centerY  -  e . y ,  2 ) ) ; 
179+                     const  distance  =  Math . sqrt ( Math . pow ( centerX  -  mouseCoordinates . x ,  2 )  +  Math . pow ( centerY  -  mouseCoordinates . y ,  2 ) ) ; 
165180                    if  ( distance  <=  stream . displaySettings . radius ! )  { 
166181                        locations . push ( "inside" ) ; 
167182                    } 
@@ -170,12 +185,12 @@ export default class MouseEventListener {
170185                    } 
171186                }  else  { 
172187
173-                     if  ( e . x  >  x  &&  e . x  <  x  +  width  &&  e . y  >  y  &&  e . y  <  y  +  height )  locations . push ( "inside" ) ; 
188+                     if  ( mouseCoordinates . x  >  x  &&  mouseCoordinates . x  <  x  +  width  &&  mouseCoordinates . y  >  y  &&  mouseCoordinates . y  <  y  +  height )  locations . push ( "inside" ) ; 
174189
175-                     if  ( e . x  >  x  &&  e . x  <  x  +  width  &&  e . y  >  y  -  10  &&  e . y  <  y  +  10 )  locations . push ( "top" ) ; 
176-                     if  ( e . x  >  x  &&  e . x  <  x  +  width  &&  e . y  >  y  +  height  -  10  &&  e . y  <  y  +  height  +  10 )  locations . push ( "bottom" ) ; 
177-                     if  ( e . y  >  y  &&  e . y  <  y  +  height  &&  e . x  >  x  -  10  &&  e . x  <  x  +  10 )  locations . push ( "left" ) ; 
178-                     if  ( e . y  >  y  &&  e . y  <  y  +  height  &&  e . x  >  x  +  width  -  10  &&  e . x  <  x  +  width  +  10 )  locations . push ( "right" ) ; 
190+                     if  ( mouseCoordinates . x  >  x  &&  mouseCoordinates . x  <  x  +  width  &&  mouseCoordinates . y  >  y  -  10  &&  mouseCoordinates . y  <  y  +  10 )  locations . push ( "top" ) ; 
191+                     if  ( mouseCoordinates . x  >  x  &&  mouseCoordinates . x  <  x  +  width  &&  mouseCoordinates . y  >  y  +  height  -  10  &&  mouseCoordinates . y  <  y  +  height  +  10 )  locations . push ( "bottom" ) ; 
192+                     if  ( mouseCoordinates . y  >  y  &&  mouseCoordinates . y  <  y  +  height  &&  mouseCoordinates . x  >  x  -  10  &&  mouseCoordinates . x  <  x  +  10 )  locations . push ( "left" ) ; 
193+                     if  ( mouseCoordinates . y  >  y  &&  mouseCoordinates . y  <  y  +  height  &&  mouseCoordinates . x  >  x  +  width  -  10  &&  mouseCoordinates . x  <  x  +  width  +  10 )  locations . push ( "right" ) ; 
179194                } 
180195
181196                if  ( locations . length  >  0  &&  stream . displaySettings . index !  >  index )  { 
@@ -190,7 +205,7 @@ export default class MouseEventListener {
190205
191206            this . onMoveListeners . forEach ( l  =>  l ( { 
192207                ...( this . overStream  ? this . overStream !  : { } ) , 
193-                 ...e 
208+                 ...mouseCoordinates 
194209            } ) ) ; 
195210        } 
196211    } 
0 commit comments