@@ -296,6 +296,15 @@ export class CanvasEngine {
296
296
this . canvas . addEventListener ( "wheel" , this . mouseWheelHandler , {
297
297
passive : false ,
298
298
} ) ;
299
+ this . canvas . addEventListener ( "touchstart" , this . touchStartHandler , {
300
+ passive : false ,
301
+ } ) ;
302
+ this . canvas . addEventListener ( "touchmove" , this . touchMoveHandler , {
303
+ passive : false ,
304
+ } ) ;
305
+ this . canvas . addEventListener ( "touchend" , this . touchEndHandler , {
306
+ passive : false ,
307
+ } ) ;
299
308
}
300
309
301
310
setTool ( tool : ToolType ) {
@@ -777,7 +786,7 @@ export class CanvasEngine {
777
786
778
787
mouseDownHandler = ( e : MouseEvent ) => {
779
788
const { x, y } = this . transformPanScale ( e . clientX , e . clientY ) ;
780
-
789
+ console . log ( "x, y: " , x , y ) ;
781
790
if ( this . activeTool === "selection" ) {
782
791
const selectedShape = this . SelectionController . getSelectedShape ( ) ;
783
792
if ( selectedShape ) {
@@ -974,6 +983,46 @@ export class CanvasEngine {
974
983
}
975
984
} ;
976
985
986
+ touchStartHandler = ( e : TouchEvent ) => {
987
+ e . preventDefault ( ) ;
988
+ const touch = e . touches [ 0 ] ;
989
+ if ( ! touch ) return ;
990
+
991
+ const simulatedMouse = new MouseEvent ( "mousedown" , {
992
+ clientX : touch . clientX ,
993
+ clientY : touch . clientY ,
994
+ } ) ;
995
+
996
+ console . log ( "Touch started at" , touch . clientX , touch . clientY ) ;
997
+
998
+ this . mouseDownHandler ( simulatedMouse ) ;
999
+ } ;
1000
+
1001
+ touchMoveHandler = ( e : TouchEvent ) => {
1002
+ e . preventDefault ( ) ;
1003
+ const touch = e . touches [ 0 ] ;
1004
+ if ( ! touch ) return ;
1005
+
1006
+ const simulatedMouse = new MouseEvent ( "mousemove" , {
1007
+ clientX : touch . clientX ,
1008
+ clientY : touch . clientY ,
1009
+ } ) ;
1010
+
1011
+ this . mouseMoveHandler ( simulatedMouse ) ;
1012
+ } ;
1013
+
1014
+ touchEndHandler = ( e : TouchEvent ) => {
1015
+ e . preventDefault ( ) ;
1016
+ const touch = e . changedTouches [ 0 ] ;
1017
+ if ( touch ) {
1018
+ const simulatedMouse = new MouseEvent ( "mouseup" , {
1019
+ clientX : touch . clientX ,
1020
+ clientY : touch . clientY ,
1021
+ } ) ;
1022
+ this . mouseUpHandler ( simulatedMouse ) ;
1023
+ }
1024
+ } ;
1025
+
977
1026
private handleTexty ( e : MouseEvent ) {
978
1027
const { x, y } = this . transformPanScale ( e . clientX , e . clientY ) ;
979
1028
@@ -1767,6 +1816,9 @@ export class CanvasEngine {
1767
1816
this . canvas . removeEventListener ( "mousemove" , this . mouseMoveHandler ) ;
1768
1817
this . canvas . removeEventListener ( "mouseup" , this . mouseUpHandler ) ;
1769
1818
this . canvas . removeEventListener ( "wheel" , this . mouseWheelHandler ) ;
1819
+ this . canvas . removeEventListener ( "touchstart" , this . touchStartHandler ) ;
1820
+ this . canvas . removeEventListener ( "touchmove" , this . touchMoveHandler ) ;
1821
+ this . canvas . removeEventListener ( "touchend" , this . touchEndHandler ) ;
1770
1822
1771
1823
if ( this . socket ?. readyState === WebSocket . OPEN ) {
1772
1824
this . socket . send (
0 commit comments