deferred drawing
This commit is contained in:
13
canvas.ts
13
canvas.ts
@@ -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";
|
||||||
|
Reference in New Issue
Block a user