File

src/toolbox/shapes/Line.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 arc
arc(options: DrawArcOptions)
Parameters :
Name Type Optional
options DrawArcOptions No
Returns : this
Public arcTo
arcTo(options: ArcToPoint)
Parameters :
Name Type Optional
options ArcToPoint No
Returns : this
Public cubicBezierCurve
cubicBezierCurve(options: CubicBezierCurveOptions)
Parameters :
Name Type Optional
options CubicBezierCurveOptions No
Returns : this
Public draw
draw(from: number, to: number)
Parameters :
Name Type Optional
from number No
to number No
Returns : this
Public quadraticBezierCurve
quadraticBezierCurve(options: QuadraticBezierCurveOptions)
Parameters :
Name Type Optional
options QuadraticBezierCurveOptions 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 DrawArcOptions {
    x: number;
    y: number;
    radius: number;
    startAngle: number;
    endAngle: number;
    counterclockwise?: boolean;
}

export interface ArcToPoint {
    x1: number;
    y1: number;
    x2: number;
    y2: number;
    radius: number;
}

export interface QuadraticBezierCurveOptions {
    controlPointX: number;
    controlPointY: number;
    x: number;
    y: number;
}

export interface CubicBezierCurveOptions {
    firstControlPointX: number;
    firstControlPointY: number;
    secondControlPointX: number;
    secondControlPointY: number;
    x: number;
    y: number;
}

export class LineTool extends BaseShapeTool {
    public draw(from: number, to: number) {
        this.history.push((ctx) => {
            ctx.lineTo(from, to);
        });

        return this;
    }

    public arc(options: DrawArcOptions) {
        this.history.push((ctx) => {
            ctx.arc(
                options.x,
                options.y,
                options.radius,
                options.startAngle,
                options.endAngle,
                !!options.counterclockwise
            );
        });

        return this;
    }

    public arcTo(options: ArcToPoint) {
        this.history.push((ctx) => {
            ctx.arcTo(options.x1, options.y1, options.x2, options.y2, options.radius);
        });

        return this;
    }

    public quadraticBezierCurve(options: QuadraticBezierCurveOptions) {
        this.history.push((ctx) => {
            ctx.quadraticCurveTo(options.controlPointX, options.controlPointY, options.x, options.y);
        });

        return this;
    }

    public cubicBezierCurve(options: CubicBezierCurveOptions) {
        this.history.push((ctx) => {
            ctx.bezierCurveTo(
                options.firstControlPointX,
                options.firstControlPointY,
                options.secondControlPointX,
                options.secondControlPointY,
                options.x,
                options.y
            );
        });

        return this;
    }
}

results matching ""

    No results matching ""