src/toolbox/base/BaseShapeTool.ts
Properties |
Methods |
|
| Public autoClear |
Default value : false
|
|
Inherited from
ToolBox
|
|
Defined in
ToolBox:9
|
| Public history |
Type : HistoryCallback[]
|
Default value : []
|
|
Inherited from
ToolBox
|
|
Defined in
ToolBox:8
|
| Public Readonly layer |
Type : Layer
|
|
Inherited from
ToolBox
|
|
Defined in
ToolBox:9
|
| Public addPoint |
addPoint()
|
|
Defined in src/toolbox/base/BaseShapeTool.ts:62
|
|
Returns :
this
|
| Public clip | ||||||
clip(options?: literal type)
|
||||||
|
Defined in src/toolbox/base/BaseShapeTool.ts:116
|
||||||
|
Parameters :
Returns :
this
|
| Public fill | ||||||
fill(options?: literal type)
|
||||||
|
Defined in src/toolbox/base/BaseShapeTool.ts:86
|
||||||
|
Parameters :
Returns :
this
|
| Public move |
move(x: number, y: number)
|
|
Defined in src/toolbox/base/BaseShapeTool.ts:78
|
|
Returns :
this
|
| Public removePoint |
removePoint()
|
|
Defined in src/toolbox/base/BaseShapeTool.ts:70
|
|
Returns :
this
|
| Public setDashOffset | ||||||
setDashOffset(offset: number)
|
||||||
|
Defined in src/toolbox/base/BaseShapeTool.ts:38
|
||||||
|
Parameters :
Returns :
this
|
| Public setFillColor | ||||||
setFillColor(color: string | CanvasGradient | CanvasPattern)
|
||||||
|
Defined in src/toolbox/base/BaseShapeTool.ts:6
|
||||||
|
Parameters :
Returns :
this
|
| Public setLineCap | ||||||
setLineCap(lineCapStyle: CanvasLineCap)
|
||||||
|
Defined in src/toolbox/base/BaseShapeTool.ts:30
|
||||||
|
Parameters :
Returns :
this
|
| Public setLineDash | ||||||||
setLineDash(segments: number[])
|
||||||||
|
Defined in src/toolbox/base/BaseShapeTool.ts:108
|
||||||||
|
Parameters :
Returns :
this
|
| Public setLineJoinStyle | ||||||
setLineJoinStyle(style: "round" | "bevel" | "miter")
|
||||||
|
Defined in src/toolbox/base/BaseShapeTool.ts:46
|
||||||
|
Parameters :
Returns :
this
|
| Public setLineWidth | ||||||
setLineWidth(width: number)
|
||||||
|
Defined in src/toolbox/base/BaseShapeTool.ts:22
|
||||||
|
Parameters :
Returns :
this
|
| Public setMiterLimit | ||||||
setMiterLimit(limit: number)
|
||||||
|
Defined in src/toolbox/base/BaseShapeTool.ts:54
|
||||||
|
Parameters :
Returns :
this
|
| Public setStrokeColor | ||||||
setStrokeColor(color: string | CanvasGradient | CanvasPattern)
|
||||||
|
Defined in src/toolbox/base/BaseShapeTool.ts:14
|
||||||
|
Parameters :
Returns :
this
|
| Public stroke | ||||||
stroke(options?: literal type)
|
||||||
|
Defined in src/toolbox/base/BaseShapeTool.ts:100
|
||||||
|
Parameters :
Returns :
this
|
| Public render |
render()
|
|
Inherited from
ToolBox
|
|
Defined in
ToolBox:27
|
|
Returns :
void
|
| Public restore |
restore()
|
|
Inherited from
ToolBox
|
|
Defined in
ToolBox:19
|
|
Returns :
this
|
| Public save |
save()
|
|
Inherited from
ToolBox
|
|
Defined in
ToolBox:11
|
|
Returns :
this
|
import { Path2D } from "@napi-rs/canvas";
import { makeArgs } from "../../utils/makeArgs";
import { ToolBox } from "./ToolBox";
export class BaseShapeTool extends ToolBox {
public setFillColor(color: string | CanvasGradient | CanvasPattern) {
this.history.push((ctx) => {
ctx.fillStyle = color;
});
return this;
}
public setStrokeColor(color: string | CanvasGradient | CanvasPattern) {
this.history.push((ctx) => {
ctx.strokeStyle = color;
});
return this;
}
public setLineWidth(width: number) {
this.history.push((ctx) => {
ctx.lineWidth = width;
});
return this;
}
public setLineCap(lineCapStyle: CanvasLineCap) {
this.history.push((ctx) => {
ctx.lineCap = lineCapStyle;
});
return this;
}
public setDashOffset(offset: number) {
this.history.push((ctx) => {
ctx.lineDashOffset = offset;
});
return this;
}
public setLineJoinStyle(style: "round" | "bevel" | "miter") {
this.history.push((ctx) => {
ctx.lineJoin = style;
});
return this;
}
public setMiterLimit(limit: number) {
this.history.push((ctx) => {
ctx.miterLimit = limit;
});
return this;
}
public addPoint() {
this.history.push((ctx) => {
ctx.beginPath();
});
return this;
}
public removePoint() {
this.history.push((ctx) => {
ctx.closePath();
});
return this;
}
public move(x: number, y: number) {
this.history.push((ctx) => {
ctx.moveTo(x, y);
});
return this;
}
public fill(options?: { fillRule?: "evenodd" | "nonzero"; path: Path2D }) {
this.history.push((ctx) => {
if (!options) return ctx.fill();
ctx.fill(
...makeArgs(
(arg, idx) => (idx === 0 ? arg instanceof Path2D : idx === 1 ? typeof arg === "string" : false),
[options.path, options.fillRule]
)
);
});
return this;
}
public stroke(options?: { path: Path2D }) {
this.history.push((ctx) => {
options?.path ? ctx.stroke(options.path) : ctx.stroke();
});
return this;
}
public setLineDash(segments: number[] = []) {
this.history.push((ctx) => {
ctx.setLineDash(segments);
});
return this;
}
public clip(options?: { fillRule?: "evenodd" | "nonzero"; path?: Path2D }) {
this.history.push((ctx) => {
if (!options) return ctx.clip();
ctx.clip(
...makeArgs(
(arg, idx) => (idx === 0 ? arg instanceof Path2D : idx === 1 ? typeof arg === "string" : false),
[options.path, options.fillRule]
)
);
});
return this;
}
}