deferred drawing

This commit is contained in:
Emmaline Autumn 2023-10-24 01:11:15 -06:00
parent 7d6b54825d
commit c58861bc93

View File

@ -89,6 +89,7 @@ export class Doodler {
// } // }
for (const [i, l] of (this.layers || []).entries()) { for (const [i, l] of (this.layers || []).entries()) {
l(this.ctx, i); l(this.ctx, i);
this.drawDeferred();
} }
this.drawUI(); this.drawUI();
} }
@ -227,6 +228,18 @@ export class Doodler {
); );
} }
private deferredDrawings: (() => void)[] = [];
deferDrawing(cb: () => void) {
this.deferredDrawings.push(cb);
}
drawDeferred() {
while (this.deferredDrawings.length) {
this.deferredDrawings.pop()?.();
}
}
setStyle(style?: IStyle) { setStyle(style?: IStyle) {
const ctx = this.ctx; const ctx = this.ctx;
ctx.fillStyle = style?.color || style?.fillColor || "black"; ctx.fillStyle = style?.color || style?.fillColor || "black";