File

src/toolbox/eraser/Eraser.ts

Extends

ToolBox

Index

Properties
Methods

Properties

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

Methods

Public circular
circular(options)
Parameters :
Name Optional
options No
Returns : this
Public rectangular
rectangular(options: EraserOptions)
Parameters :
Name Type Optional
options EraserOptions No
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 { ToolBox } from "../base/ToolBox";

export interface EraserOptions {
    x: number;
    y: number;
    width: number;
    height: number;
}

export class EraserTool extends ToolBox {
    public rectangular(options: EraserOptions) {
        this.history.push((ctx) => {
            ctx.clearRect(options.x, options.y, options.width, options.height);
        });
        return this;
    }

    public circular(options: Omit<EraserOptions, "width" | "height"> & { radius?: number }) {
        this.history.push((ctx) => {
            ctx.beginPath();
            ctx.arc(options.x, options.y, options.radius ?? 50, 0, 2 * Math.PI);
            ctx.clip();
            ctx.clearRect(0, 0, this.layer.width, this.layer.height);
            ctx.closePath();
        });
        return this;
    }
}

results matching ""

    No results matching ""