@@ -363,7 +363,7 @@ export class LogicEditor extends HTMLElement implements DrawableParent {
363
363
364
364
this . _actualZoomFactor = clampZoom ( newOptions . zoom )
365
365
366
- this . editTools . redrawMgr . addReason ( "options changed" , null )
366
+ this . editTools . redrawMgr . addReason ( "options changed" , null , true )
367
367
}
368
368
369
369
private setWindowTitleFrom ( docName : string | undefined ) {
@@ -627,7 +627,7 @@ export class LogicEditor extends HTMLElement implements DrawableParent {
627
627
innerScriptElem . remove ( ) // remove the data element to hide the raw data
628
628
// do this manually
629
629
this . tryLoadCircuitFromData ( )
630
- this . doRedraw ( )
630
+ this . doRedraw ( true )
631
631
return true
632
632
} else {
633
633
return false
@@ -793,7 +793,7 @@ export class LogicEditor extends HTMLElement implements DrawableParent {
793
793
}
794
794
checkbox . addEventListener ( "change" , this . wrapHandler ( ( ) => {
795
795
this . _options [ optionName ] = checkbox . checked
796
- this . editTools . redrawMgr . addReason ( "option changed: " + optionName , null )
796
+ this . editTools . redrawMgr . addReason ( "option changed: " + optionName , null , true )
797
797
this . focus ( )
798
798
} ) )
799
799
const section = div (
@@ -828,7 +828,7 @@ export class LogicEditor extends HTMLElement implements DrawableParent {
828
828
wireStylePopup . addEventListener ( "change" , this . wrapHandler ( ( ) => {
829
829
this . _options . wireStyle = wireStylePopup . value as WireStyle
830
830
this . linkMgr . invalidateAllWirePaths ( )
831
- this . editTools . redrawMgr . addReason ( "wire style changed" , null )
831
+ this . editTools . redrawMgr . addReason ( "wire style changed" , null , true )
832
832
} ) )
833
833
settingsPalette . appendChild (
834
834
div (
@@ -898,7 +898,7 @@ export class LogicEditor extends HTMLElement implements DrawableParent {
898
898
this . setCanvasSize ( )
899
899
LogicEditor . installGlobalListeners ( )
900
900
901
- this . doRedraw ( )
901
+ this . doRedraw ( true )
902
902
}
903
903
904
904
private findLightDOMChild < K extends keyof HTMLElementTagNameMap > ( tagName : K ) : HTMLElementTagNameMap [ K ] | null {
@@ -944,7 +944,7 @@ export class LogicEditor extends HTMLElement implements DrawableParent {
944
944
if ( canvasContainer !== undefined ) {
945
945
editor . wrapHandler ( ( ) => {
946
946
editor . setCanvasSize ( )
947
- editor . editTools . redrawMgr . addReason ( "window resized" , null )
947
+ editor . editTools . redrawMgr . addReason ( "window resized" , null , true )
948
948
} ) ( )
949
949
}
950
950
}
@@ -963,7 +963,7 @@ export class LogicEditor extends HTMLElement implements DrawableParent {
963
963
for ( const editor of LogicEditor . _allConnectedEditors ) {
964
964
editor . wrapHandler ( ( ) => {
965
965
editor . setCanvasSize ( )
966
- editor . editTools . redrawMgr . addReason ( "devicePixelRatio changed" , null )
966
+ editor . editTools . redrawMgr . addReason ( "devicePixelRatio changed" , null , true )
967
967
} ) ( )
968
968
}
969
969
registerPixelRatioListener ( )
@@ -1003,7 +1003,7 @@ export class LogicEditor extends HTMLElement implements DrawableParent {
1003
1003
1004
1004
// console.log(`Display/interaction is ${wantedModeStr} - ${mode}`)
1005
1005
1006
- this . editTools . redrawMgr . addReason ( "mode changed" , null )
1006
+ this . editTools . redrawMgr . addReason ( "mode changed" , null , true )
1007
1007
1008
1008
// update mode active button
1009
1009
this . root . querySelectorAll ( ".sim-mode-tool" ) . forEach ( ( elem ) => {
@@ -1070,7 +1070,7 @@ export class LogicEditor extends HTMLElement implements DrawableParent {
1070
1070
public setZoomLevel ( zoom : number ) {
1071
1071
this . _options . zoom = zoom
1072
1072
this . _actualZoomFactor = clampZoom ( zoom )
1073
- this . editTools . redrawMgr . addReason ( "zoom level changed" , null )
1073
+ this . editTools . redrawMgr . addReason ( "zoom level changed" , null , true )
1074
1074
}
1075
1075
1076
1076
public updateCustomComponentButtons ( ) {
@@ -1305,7 +1305,7 @@ export class LogicEditor extends HTMLElement implements DrawableParent {
1305
1305
this . eventMgr . clearPopperIfNecessary ( )
1306
1306
this . eventMgr . updateMouseOver ( [ this . mouseX , this . mouseY ] , false , false )
1307
1307
this . editTools . moveMgr . clear ( )
1308
- this . editTools . redrawMgr . addReason ( "editor context changed" , null )
1308
+ this . editTools . redrawMgr . addReason ( "editor context changed" , null , true )
1309
1309
1310
1310
this . focus ( )
1311
1311
}
@@ -1315,7 +1315,7 @@ export class LogicEditor extends HTMLElement implements DrawableParent {
1315
1315
if ( forceUpdate || changed ) {
1316
1316
this . setToolCursor ( MouseActions [ action ] . cursor )
1317
1317
this . _topBar ?. updateActiveTool ( action )
1318
- this . editTools . redrawMgr . addReason ( "mouse action changed" , null )
1318
+ this . editTools . redrawMgr . addReason ( "mouse action changed" , null , false )
1319
1319
this . editor . focus ( )
1320
1320
}
1321
1321
return changed
@@ -1614,7 +1614,7 @@ export class LogicEditor extends HTMLElement implements DrawableParent {
1614
1614
if ( wasDark ) {
1615
1615
setDarkMode ( false , false )
1616
1616
}
1617
- this . doDrawWithContext ( g , width , height , transform , transform , true , true )
1617
+ this . doDrawWithContext ( g , width , height , transform , transform , true , true , false )
1618
1618
if ( wasDark ) {
1619
1619
setDarkMode ( true , false )
1620
1620
}
@@ -1645,7 +1645,7 @@ export class LogicEditor extends HTMLElement implements DrawableParent {
1645
1645
const [ width , height ] = this . guessAdequateCanvasSize ( false )
1646
1646
const id = new DOMMatrix ( )
1647
1647
const svgCtx = new SVGRenderingContext ( { width, height, metadata } )
1648
- this . doDrawWithContext ( svgCtx , width , height , id , id , true , true )
1648
+ this . doDrawWithContext ( svgCtx , width , height , id , id , true , true , false )
1649
1649
const serializedSVG = svgCtx . getSerializedSvg ( )
1650
1650
return Promise . resolve ( new Blob ( [ serializedSVG ] , { type : "image/svg+xml" } ) )
1651
1651
}
@@ -1830,16 +1830,16 @@ export class LogicEditor extends HTMLElement implements DrawableParent {
1830
1830
}
1831
1831
1832
1832
const animateWires = this . _options . animateWires
1833
- const redrawReasons = redrawMgr . getReasonsAndClear ( )
1834
- if ( redrawReasons === undefined && ! animateWires ) {
1833
+ const redrawInfo = redrawMgr . getReasonsAndClear ( )
1834
+ if ( redrawInfo === undefined && ! animateWires ) {
1835
1835
return
1836
1836
}
1837
1837
1838
1838
// By now, we know that we have to redraw
1839
1839
1840
1840
// we need to reset the promise if we have real redraw reasons, not only
1841
1841
// a wire animate to run
1842
- if ( redrawReasons !== undefined && this . _propagationResolve === undefined ) {
1842
+ if ( redrawInfo !== undefined && this . _propagationResolve === undefined ) {
1843
1843
// console.log("new propagation promise")
1844
1844
// means that the promise has been resolved already and we are
1845
1845
// starting a new cycle, so we reset the promise
@@ -1848,8 +1848,9 @@ export class LogicEditor extends HTMLElement implements DrawableParent {
1848
1848
} )
1849
1849
}
1850
1850
1851
- // console.log("Drawing " + (__recalculated ? "with" : "without") + " recalc, reasons:\n " + redrawReasons)
1852
- this . doRedraw ( )
1851
+ const redrawMask = redrawInfo ?. [ 1 ] ?? false
1852
+ // console.log("Drawing " + (__recalculated ? "with" : "without") + " recalc, " + (redrawMask ? "with" : "without") + " redrawing mask, reasons:\n " + (redrawInfo?.[0]() ?? "??"))
1853
+ this . doRedraw ( redrawMask )
1853
1854
1854
1855
if ( ! redrawMgr . isAnyValuePropagating ( ) ) {
1855
1856
// console.log("No value is propagating")
@@ -1926,11 +1927,11 @@ export class LogicEditor extends HTMLElement implements DrawableParent {
1926
1927
1927
1928
public redraw ( ) {
1928
1929
this . setCanvasSize ( )
1929
- this . editTools . redrawMgr . addReason ( "explicit redraw call" , null )
1930
+ this . editTools . redrawMgr . addReason ( "explicit redraw call" , null , true )
1930
1931
this . recalcPropagateAndDrawIfNeeded ( )
1931
1932
}
1932
1933
1933
- private doRedraw ( ) {
1934
+ private doRedraw ( redrawMask : boolean ) {
1934
1935
// const timeBefore = performance.now()
1935
1936
this . _topBar ?. updateTimeLabelIfNeeded ( )
1936
1937
const g = LogicEditor . getGraphics ( this . html . mainCanvas )
@@ -1941,12 +1942,20 @@ export class LogicEditor extends HTMLElement implements DrawableParent {
1941
1942
const height = mainCanvas . height / baseDrawingScale
1942
1943
const baseTransform = new DOMMatrix ( `scale(${ this . _baseDrawingScale } )` )
1943
1944
const contentTransform = baseTransform . scale ( this . _actualZoomFactor )
1944
- this . doDrawWithContext ( g , width , height , baseTransform , contentTransform , false , false )
1945
+ this . doDrawWithContext ( g , width , height , baseTransform , contentTransform , false , false , redrawMask )
1945
1946
// const timeAfter = performance.now()
1946
1947
// console.log(`Drawing took ${timeAfter - timeBefore}ms`)
1947
1948
}
1948
1949
1949
- private doDrawWithContext ( g : GraphicsRendering , width : number , height : number , baseTransform : DOMMatrixReadOnly , contentTransform : DOMMatrixReadOnly , skipBorder : boolean , transparentBackground : boolean ) {
1950
+ private doDrawWithContext ( g : GraphicsRendering , width : number , height : number , baseTransform : DOMMatrixReadOnly , contentTransform : DOMMatrixReadOnly , skipBorder : boolean , transparentBackground : boolean , __redrawMask : boolean ) {
1951
+
1952
+ // TODO handle redrawMask
1953
+ // if (redrawMask) {
1954
+ // console.log("would redraw mask")
1955
+ // } else {
1956
+ // console.log("would not redraw mask")
1957
+ // }
1958
+
1950
1959
g . setTransform ( baseTransform )
1951
1960
g . lineCap = "square"
1952
1961
g . textBaseline = "middle"
0 commit comments