File

src/toolbox/shapes/Ellipse.ts

Extends

BaseShapeTool

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 draw
draw(options: DrawEllipseOptions)
Parameters :
Name Type Optional
options DrawEllipseOptions No
Returns : this
Public drawCircle
drawCircle(options: DrawCircleOptions)
Parameters :
Name Type Optional
options DrawCircleOptions No
Returns : this
Public addPoint
addPoint()
Inherited from BaseShapeTool
Defined in BaseShapeTool:62
Returns : this
Public clip
clip(options?: literal type)
Inherited from BaseShapeTool
Defined in BaseShapeTool:116
Parameters :
Name Type Optional
options literal type Yes
Returns : this
Public fill
fill(options?: literal type)
Inherited from BaseShapeTool
Defined in BaseShapeTool:86
Parameters :
Name Type Optional
options literal type Yes
Returns : this
Public move
move(x: number, y: number)
Inherited from BaseShapeTool
Defined in BaseShapeTool:78
Parameters :
Name Type Optional
x number No
y number No
Returns : this
Public removePoint
removePoint()
Inherited from BaseShapeTool
Defined in BaseShapeTool:70
Returns : this
Public setDashOffset
setDashOffset(offset: number)
Inherited from BaseShapeTool
Defined in BaseShapeTool:38
Parameters :
Name Type Optional
offset number No
Returns : this
Public setFillColor
setFillColor(color: string | CanvasGradient | CanvasPattern)
Inherited from BaseShapeTool
Defined in BaseShapeTool:6
Parameters :
Name Type Optional
color string | CanvasGradient | CanvasPattern No
Returns : this
Public setLineCap
setLineCap(lineCapStyle: CanvasLineCap)
Inherited from BaseShapeTool
Defined in BaseShapeTool:30
Parameters :
Name Type Optional
lineCapStyle CanvasLineCap No
Returns : this
Public setLineDash
setLineDash(segments: number[])
Inherited from BaseShapeTool
Defined in BaseShapeTool:108
Parameters :
Name Type Optional Default value
segments number[] No []
Returns : this
Public setLineJoinStyle
setLineJoinStyle(style: "round" | "bevel" | "miter")
Inherited from BaseShapeTool
Defined in BaseShapeTool:46
Parameters :
Name Type Optional
style "round" | "bevel" | "miter" No
Returns : this
Public setLineWidth
setLineWidth(width: number)
Inherited from BaseShapeTool
Defined in BaseShapeTool:22
Parameters :
Name Type Optional
width number No
Returns : this
Public setMiterLimit
setMiterLimit(limit: number)
Inherited from BaseShapeTool
Defined in BaseShapeTool:54
Parameters :
Name Type Optional
limit number No
Returns : this
Public setStrokeColor
setStrokeColor(color: string | CanvasGradient | CanvasPattern)
Inherited from BaseShapeTool
Defined in BaseShapeTool:14
Parameters :
Name Type Optional
color string | CanvasGradient | CanvasPattern No
Returns : this
Public stroke
stroke(options?: literal type)
Inherited from BaseShapeTool
Defined in BaseShapeTool:100
Parameters :
Name Type Optional
options literal type Yes
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 { BaseShapeTool } from "../base/BaseShapeTool";

export interface DrawEllipseOptions {
    x: number;
    y: number;
    radiusX: number;
    radiusY: number;
    rotation: number;
    startAngle: number;
    endAngle: number;
    counterclockwise?: boolean;
}

export type DrawCircleOptions = Omit<DrawEllipseOptions, "radiusX" | "radiusY" | "rotation"> & { radius: number };

export class EllipseTool extends BaseShapeTool {
    public draw(options: DrawEllipseOptions) {
        this.history.push((ctx) => {
            options.counterclockwise ??= false;
            ctx.ellipse(
                options.x,
                options.y,
                options.radiusX,
                options.radiusY,
                options.rotation,
                options.startAngle,
                options.endAngle,
                options.counterclockwise
            );
        });

        return this;
    }

    public drawCircle(options: DrawCircleOptions) {
        this.history.push((ctx) => {
            options.counterclockwise ??= false;
            ctx.arc(
                options.x,
                options.y,
                options.radius,
                options.startAngle,
                options.endAngle,
                options.counterclockwise
            );
        });

        return this;
    }
}

results matching ""

    No results matching ""