@@ -30,7 +30,7 @@ import { Tests } from "./Tests"
30
30
import { TestsPalette } from "./TestsPalette"
31
31
import { Timeline } from "./Timeline"
32
32
import { TopBar } from "./TopBar"
33
- import { EditorSelection , MouseDragEvent , TouchDragEvent , UIEventManager } from "./UIEventManager"
33
+ import { EditorSelection , PointerDragEvent , UIEventManager } from "./UIEventManager"
34
34
import { UndoManager } from './UndoManager'
35
35
import { Component , ComponentBase } from "./components/Component"
36
36
import { CustomComponent } from "./components/CustomComponent"
@@ -115,7 +115,7 @@ const DEFAULT_EDITOR_OPTIONS = {
115
115
116
116
export type EditorOptions = typeof DEFAULT_EDITOR_OPTIONS
117
117
118
- export const MouseActions = {
118
+ export const PointerActions = {
119
119
edit : {
120
120
cursor : null ,
121
121
paramTypes : [ ] ,
@@ -137,9 +137,9 @@ export const MouseActions = {
137
137
paramTypes : any [ ]
138
138
} >
139
139
140
- export type MouseActionParams < M extends keyof typeof MouseActions > = typeof MouseActions [ M ] [ "paramTypes" ]
140
+ export type PoionterActionParams < M extends keyof typeof PointerActions > = typeof PointerActions [ M ] [ "paramTypes" ]
141
141
142
- export type MouseAction = keyof typeof MouseActions
142
+ export type PointerAction = keyof typeof PointerActions
143
143
144
144
type InitialData = { _type : "url" , url : string } | { _type : "json" , json : string } | { _type : "compressed" , str : string }
145
145
@@ -284,8 +284,8 @@ export class LogicEditor extends HTMLElement implements DrawableParent {
284
284
285
285
private _baseDrawingScale = 1
286
286
private _actualZoomFactor = 1
287
- public mouseX = - 1000 // offscreen at start
288
- public mouseY = - 1000
287
+ public pointerX = - 1000 // offscreen at start
288
+ public pointerY = - 1000
289
289
290
290
public constructor ( ) {
291
291
super ( )
@@ -739,7 +739,7 @@ export class LogicEditor extends HTMLElement implements DrawableParent {
739
739
console . log ( "ERROR: Could not find group button" )
740
740
}
741
741
} else {
742
- groupButton . addEventListener ( "mousedown " , this . wrapHandler ( e => {
742
+ groupButton . addEventListener ( "pointerdown " , this . wrapHandler ( e => {
743
743
const success = this . makeGroupWithSelection ( )
744
744
if ( success ) {
745
745
e . preventDefault ( )
@@ -834,7 +834,7 @@ export class LogicEditor extends HTMLElement implements DrawableParent {
834
834
textArea . addEventListener ( "focus" , selectAllListener )
835
835
}
836
836
837
- this . setCurrentMouseAction ( "edit" , true )
837
+ this . setCurrentPointerAction ( "edit" , true )
838
838
this . timeline . reset ( )
839
839
840
840
// Options
@@ -987,14 +987,14 @@ export class LogicEditor extends HTMLElement implements DrawableParent {
987
987
window . gallery = gallery
988
988
989
989
window . addEventListener ( "pointermove" , e => {
990
- // console.log(`pointermove with x=${e.clientX}, y=${e.clientY}`)
990
+ // console.log(`pointermove (type '${e.pointerType}') with x=${e.clientX}, y=${e.clientY}`)
991
991
for ( const editor of LogicEditor . _allConnectedEditors ) {
992
992
const canvasContainer = editor . html . canvasContainer
993
993
if ( canvasContainer !== undefined ) {
994
994
const canvasPos = canvasContainer . getBoundingClientRect ( )
995
995
// console.log(canvasContainer.getBoundingClientRect(), { x: e.clientX - canvasPos.left, y: e.clientY - canvasPos.top })
996
- editor . mouseX = e . clientX - canvasPos . left
997
- editor . mouseY = e . clientY - canvasPos . top
996
+ editor . pointerX = e . clientX - canvasPos . left
997
+ editor . pointerY = e . clientY - canvasPos . top
998
998
}
999
999
}
1000
1000
// console.log("--")
@@ -1088,7 +1088,7 @@ export class LogicEditor extends HTMLElement implements DrawableParent {
1088
1088
} )
1089
1089
1090
1090
if ( mode < Mode . CONNECT ) {
1091
- this . setCurrentMouseAction ( "edit" )
1091
+ this . setCurrentPointerAction ( "edit" )
1092
1092
}
1093
1093
1094
1094
const showComponentsAndEditControls : UIDisplay =
@@ -1180,9 +1180,9 @@ export class LogicEditor extends HTMLElement implements DrawableParent {
1180
1180
sessionStorage . setItem ( key , saveStr )
1181
1181
if ( this . _autosave ) {
1182
1182
localStorage . setItem ( key , saveStr )
1183
- console . log ( `Saved circuit to session and local storage with key '${ key } '` )
1183
+ // console.log(`Saved circuit to session and local storage with key '${key}'`)
1184
1184
} else {
1185
- console . log ( `Saved circuit to session (not local) storage with key '${ key } '` )
1185
+ // console.log(`Saved circuit to session (not local) storage with key '${key}'`)
1186
1186
}
1187
1187
} catch ( e ) {
1188
1188
console . error ( "Failed to save circuit to browser storage" , e )
@@ -1524,31 +1524,31 @@ export class LogicEditor extends HTMLElement implements DrawableParent {
1524
1524
this . _highlightedItems = undefined
1525
1525
this . eventMgr . currentSelection = undefined
1526
1526
this . eventMgr . clearPopperIfNecessary ( )
1527
- this . eventMgr . updateMouseOver ( [ this . mouseX , this . mouseY ] , false , false )
1527
+ this . eventMgr . updatePointerOver ( [ this . pointerX , this . pointerY ] , false , false )
1528
1528
this . editTools . testsPalette . update ( )
1529
1529
this . editTools . moveMgr . clear ( )
1530
1530
this . editTools . redrawMgr . requestRedraw ( { why : "editor root changed" , invalidateMask : true , invalidateTests : true } )
1531
1531
1532
1532
this . focus ( )
1533
1533
}
1534
1534
1535
- public setCurrentMouseAction < M extends MouseAction > ( action : M , forceUpdate : boolean = false , ...params : MouseActionParams < M > ) : boolean {
1535
+ public setCurrentPointerAction < M extends PointerAction > ( action : M , forceUpdate : boolean = false , ...params : PoionterActionParams < M > ) : boolean {
1536
1536
const changed = this . eventMgr . setHandlersFor ( action , ...params )
1537
1537
if ( forceUpdate || changed ) {
1538
- this . setToolCursor ( MouseActions [ action ] . cursor )
1538
+ this . setToolCursor ( PointerActions [ action ] . cursor )
1539
1539
this . _topBar ?. updateActiveTool ( action )
1540
1540
this . editTools . redrawMgr . requestRedraw ( { why : "mouse action changed" } )
1541
1541
this . editor . focus ( )
1542
1542
}
1543
1543
return changed
1544
1544
}
1545
1545
1546
- public updateCursor ( e ?: MouseEvent | TouchEvent ) {
1546
+ public updateCursor ( e ?: PointerEvent ) {
1547
1547
const cursor =
1548
1548
this . editTools . moveMgr . areDrawablesMoving ( )
1549
1549
? "grabbing"
1550
1550
: this . _toolCursor
1551
- ?? this . eventMgr . currentMouseOverComp ?. cursorWhenMouseover ( e )
1551
+ ?? this . eventMgr . currentPointerOverComp ?. cursorWhenMouseover ( e )
1552
1552
?? "default"
1553
1553
this . html . canvasContainer . style . cursor = cursor
1554
1554
}
@@ -1557,7 +1557,7 @@ export class LogicEditor extends HTMLElement implements DrawableParent {
1557
1557
return this . _messageBar ?. showMessage ( msg , duration , withCloseButton ) ?? ( ( ) => undefined )
1558
1558
}
1559
1559
1560
- public offsetXYForContextMenu ( e : MouseEvent | TouchEvent | MouseDragEvent | TouchDragEvent , snapToGrid = false ) : [ number , number ] {
1560
+ public offsetXYForContextMenu ( e : MouseEvent | PointerDragEvent , snapToGrid = false ) : [ number , number ] {
1561
1561
const mainCanvas = this . html . mainCanvas
1562
1562
let x , y
1563
1563
@@ -1578,7 +1578,7 @@ export class LogicEditor extends HTMLElement implements DrawableParent {
1578
1578
return [ x , y ]
1579
1579
}
1580
1580
1581
- public offsetXY ( e : MouseEvent | TouchEvent , skipScaling : boolean = false ) : [ number , number ] {
1581
+ public offsetXY ( e : MouseEvent , skipScaling : boolean = false ) : [ number , number ] {
1582
1582
const [ unscaledX , unscaledY ] = ( ( ) => {
1583
1583
const mainCanvas = this . html . mainCanvas
1584
1584
let target = e . target
@@ -1612,28 +1612,30 @@ export class LogicEditor extends HTMLElement implements DrawableParent {
1612
1612
]
1613
1613
}
1614
1614
} else {
1615
- const elemRect = ( target as HTMLElement ) . getBoundingClientRect ( )
1616
- const bodyRect = document . body . getBoundingClientRect ( )
1617
- const touch = e . changedTouches [ 0 ]
1618
- const offsetX = touch . pageX - ( elemRect . left - bodyRect . left )
1619
- const offsetY = touch . pageY - ( elemRect . top - bodyRect . top )
1620
-
1621
- if ( target === mainCanvas ) {
1622
- return [ offsetX , offsetY ]
1623
- } else {
1624
- const canvasRect = mainCanvas . getBoundingClientRect ( )
1625
- return [
1626
- Math . max ( GRID_STEP * 2 , offsetX + elemRect . x - canvasRect . x ) ,
1627
- Math . max ( GRID_STEP * 2 , offsetY + elemRect . y - canvasRect . y ) ,
1628
- ]
1629
- }
1615
+ console . error ( "calling offsetXY with TouchEvent" )
1616
+ throw new Error ( "not implemented" )
1617
+ // const elemRect = (target as HTMLElement).getBoundingClientRect()
1618
+ // const bodyRect = document.body.getBoundingClientRect()
1619
+ // const touch = e.changedTouches[0]
1620
+ // const offsetX = touch.pageX - (elemRect.left - bodyRect.left)
1621
+ // const offsetY = touch.pageY - (elemRect.top - bodyRect.top)
1622
+
1623
+ // if (target === mainCanvas) {
1624
+ // return [offsetX, offsetY]
1625
+ // } else {
1626
+ // const canvasRect = mainCanvas.getBoundingClientRect()
1627
+ // return [
1628
+ // Math.max(GRID_STEP * 2, offsetX + elemRect.x - canvasRect.x),
1629
+ // Math.max(GRID_STEP * 2, offsetY + elemRect.y - canvasRect.y),
1630
+ // ]
1631
+ // }
1630
1632
}
1631
1633
} ) ( )
1632
1634
const currentScale = skipScaling ? 1 : this . _actualZoomFactor
1633
1635
return [ unscaledX / currentScale , unscaledY / currentScale ]
1634
1636
}
1635
1637
1636
- public offsetXYForComponent ( e : MouseEvent | TouchEvent , comp : Component ) : [ number , number ] {
1638
+ public offsetXYForComponent ( e : PointerEvent , comp : Component ) : [ number , number ] {
1637
1639
const offset = this . offsetXY ( e )
1638
1640
if ( comp . orient === Orientation . default ) {
1639
1641
return offset
@@ -2390,7 +2392,7 @@ export class LogicEditor extends HTMLElement implements DrawableParent {
2390
2392
const drawTime = this . timeline . logicalTime ( )
2391
2393
const drawTimeAnimationFraction = ! this . _options . animateWires ? undefined : ( drawTime / 1000 ) % 1
2392
2394
g . strokeStyle = COLOR_COMPONENT_BORDER
2393
- const currentMouseOverComp = this . eventMgr . currentMouseOverComp
2395
+ const currentMouseOverComp = this . eventMgr . currentPointerOverComp
2394
2396
const drawParams : DrawParams = {
2395
2397
drawTime,
2396
2398
drawTimeAnimationFraction,
@@ -2529,7 +2531,7 @@ export class LogicEditor extends HTMLElement implements DrawableParent {
2529
2531
// ... but then, beware of duplicated custom components if pasting into the same circuit,
2530
2532
// or find some compatibility criterion for component defs (e.g., number of in/out nodes
2531
2533
// and names) that would seem enough to determine they are the same (beyond their id/name)
2532
- const reprs = Serialization . buildComponentsAndWireObject ( componentsToInclude , [ ] , [ this . mouseX , this . mouseY ] )
2534
+ const reprs = Serialization . buildComponentsAndWireObject ( componentsToInclude , [ ] , [ this . pointerX , this . pointerY ] )
2533
2535
if ( reprs . components === undefined && reprs . wires === undefined ) {
2534
2536
return false
2535
2537
}
0 commit comments