Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
c58861bc93 | |||
7d6b54825d | |||
f1bd085384 |
25
canvas.ts
25
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();
|
||||
}
|
||||
@@ -227,12 +228,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) {
|
||||
@@ -414,6 +430,15 @@ interface IStyle {
|
||||
|
||||
noStroke?: boolean;
|
||||
noFill?: boolean;
|
||||
|
||||
textAlign?: "center" | "end" | "left" | "right" | "start";
|
||||
textBaseline?:
|
||||
| "alphabetic"
|
||||
| "top"
|
||||
| "hanging"
|
||||
| "middle"
|
||||
| "ideographic"
|
||||
| "bottom";
|
||||
}
|
||||
|
||||
interface IDrawable {
|
||||
|
Reference in New Issue
Block a user