Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
95afbf9bd3 | |||
c58861bc93 | |||
7d6b54825d |
23
canvas.ts
23
canvas.ts
@@ -89,6 +89,7 @@ export class Doodler {
|
||||
// }
|
||||
for (const [i, l] of (this.layers || []).entries()) {
|
||||
l(this.ctx, i);
|
||||
this.drawDeferred();
|
||||
}
|
||||
this.drawUI();
|
||||
}
|
||||
@@ -198,6 +199,13 @@ export class Doodler {
|
||||
this.ctx.restore();
|
||||
}
|
||||
|
||||
drawWithAlpha(alpha: number, cb: () => void) {
|
||||
this.ctx.save();
|
||||
this.ctx.globalAlpha = Math.min(Math.max(alpha, 0), 1);
|
||||
cb();
|
||||
this.ctx.restore();
|
||||
}
|
||||
|
||||
drawImage(img: HTMLImageElement, at: Vector): void;
|
||||
drawImage(img: HTMLImageElement, at: Vector, w: number, h: number): void;
|
||||
drawImage(img: HTMLImageElement, at: Vector, w?: number, h?: number) {
|
||||
@@ -227,12 +235,27 @@ export class Doodler {
|
||||
);
|
||||
}
|
||||
|
||||
private deferredDrawings: (() => void)[] = [];
|
||||
|
||||
deferDrawing(cb: () => void) {
|
||||
this.deferredDrawings.push(cb);
|
||||
}
|
||||
|
||||
drawDeferred() {
|
||||
while (this.deferredDrawings.length) {
|
||||
this.deferredDrawings.pop()?.();
|
||||
}
|
||||
}
|
||||
|
||||
setStyle(style?: IStyle) {
|
||||
const ctx = this.ctx;
|
||||
ctx.fillStyle = style?.color || style?.fillColor || "black";
|
||||
ctx.strokeStyle = style?.color || style?.strokeColor || "black";
|
||||
|
||||
ctx.lineWidth = style?.weight || 1;
|
||||
|
||||
ctx.textAlign = style?.textAlign || ctx.textAlign;
|
||||
ctx.textBaseline = style?.textBaseline || ctx.textBaseline;
|
||||
}
|
||||
|
||||
fillText(text: string, pos: Vector, maxWidth: number, style?: IStyle) {
|
||||
|
Reference in New Issue
Block a user