UNPKG

can-draw

Version:

Draw canvas conveniently.

53 lines (52 loc) 1.69 kB
import { AllShapeConfigInterface, AllShapes, Coords, ICustomShapeConfig, ShapeType } from '../types'; /** * 形状 * 对各形状设置x,y时,内部会默认进行translate(x, y)的操作 * 将坐标系进行平移操作,并以(x, y)作为新的坐标系原点 * 即每个形状实例都有一个属于自己的内部坐标系 * * Shape constructor to handle all shapes instance * @constructor * @memberOf CanDraw */ export declare class Shape { protected readonly _type: ShapeType | 'NONE'; protected _contextMounted: boolean; protected _canvasCtx: CanvasRenderingContext2D; protected _shapes: Array<AllShapes>; SHAPE_CONFIG: AllShapeConfigInterface; constructor(type?: ShapeType); _mount(ctx: CanvasRenderingContext2D): this; add(...shapes: Array<AllShapes>): this; clear(): this; getType(): "CIRCLE" | "LINE" | "RING" | "CUSTOM" | "TEXT" | "NONE"; getShapes(): AllShapes[]; getIsContextMounted(): boolean; } /** * CanDrawShape * @abstract * @constructor */ export declare abstract class CanDrawShape extends Shape { SHAPE_CONFIG: Exclude<AllShapeConfigInterface, ICustomShapeConfig>; protected constructor(type: Exclude<ShapeType, 'CUSTOM'>); /** * 相对于当前位置进行偏移 * @param {number} x * @param{number} y */ setOffsetXY({ x, y }: Coords): void; /** * 设置绘图原点 * @param x * @param y */ setXY({ x, y }: Coords): void; /** * 重新设置配置项 * @param config * @param merge 是否合并配置项 */ setConfig(config: Exclude<AllShapeConfigInterface, ICustomShapeConfig>, merge?: boolean): void; }