@@ -296,6 +296,15 @@ export class CanvasEngine {
296296 this . canvas . addEventListener ( "wheel" , this . mouseWheelHandler , {
297297 passive : false ,
298298 } ) ;
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+ } ) ;
299308 }
300309
301310 setTool ( tool : ToolType ) {
@@ -777,7 +786,7 @@ export class CanvasEngine {
777786
778787 mouseDownHandler = ( e : MouseEvent ) => {
779788 const { x, y } = this . transformPanScale ( e . clientX , e . clientY ) ;
780-
789+ console . log ( "x, y: " , x , y ) ;
781790 if ( this . activeTool === "selection" ) {
782791 const selectedShape = this . SelectionController . getSelectedShape ( ) ;
783792 if ( selectedShape ) {
@@ -974,6 +983,46 @@ export class CanvasEngine {
974983 }
975984 } ;
976985
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+
9771026 private handleTexty ( e : MouseEvent ) {
9781027 const { x, y } = this . transformPanScale ( e . clientX , e . clientY ) ;
9791028
@@ -1767,6 +1816,9 @@ export class CanvasEngine {
17671816 this . canvas . removeEventListener ( "mousemove" , this . mouseMoveHandler ) ;
17681817 this . canvas . removeEventListener ( "mouseup" , this . mouseUpHandler ) ;
17691818 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 ) ;
17701822
17711823 if ( this . socket ?. readyState === WebSocket . OPEN ) {
17721824 this . socket . send (
0 commit comments