import { ISketchUtils } from './Sketch'; import { Subscribe, IKey } from './utils/index'; export interface ILayerState { /** * 相对坐标 x * * 单位是 [[Sketch]] 实例的 `unit` 值 */ x: number; /** * 相对坐标 y * * 单位是 [[Sketch]] 实例的 `unit` 值 */ y: number; /** * 相对旋转角度 * * 用的是角度的数值,不是弧度 */ rotate: number; /** * 横向放大倍率 */ scaleX: number; /** * 纵向放大倍率 */ scaleY: number; /** * 不透明度 */ opacity: number; /** * 填充颜色 */ fill: CanvasFillStrokeStyles['fillStyle']; /** * 描边颜色 */ stroke: CanvasFillStrokeStyles['strokeStyle']; /** * 描边宽度 */ strokeWidth: CanvasPathDrawingStyles['lineWidth']; /** * 可见 */ visible: boolean; } export interface ILayerEvent { render: (ctx: CanvasRenderingContext2D, utils: ISketchUtils) => void; rendered: () => void; change: () => void; parent: (value: Layer) => void; children: (value: Layer[]) => void; clone: (value: Layer) => void; x: (x: ILayerState['x']) => void; y: (y: ILayerState['y']) => void; opacity: (opacity: ILayerState['opacity']) => void; rotate: (rotate: ILayerState['rotate']) => void; scaleX: (x: ILayerState['scaleX']) => void; scaleY: (y: ILayerState['scaleY']) => void; stroke: (stroke: ILayerState['stroke']) => void; strokeWidth: (strokeWidth: ILayerState['strokeWidth']) => void; fill: (fill: ILayerState['fill']) => void; visible: (visible: ILayerState['visible']) => void; } /** * 图层 * * 基础类,其他形状、图形类都是继承自 [[Layer]] */ export default class Layer { state: ILayerState; parent: Layer | null; children: Layer[]; protected subscribe: Subscribe; constructor(state?: Partial); /** * 添加子图层 */ add(layer: Layer): this; /** * 添加到父图层 */ addTo(layer: Layer): this; /** * 移除子图层 */ remove(layer: Layer): this; /** * 移除全部子图层 */ removeAll(): this; /** * 克隆 */ clone(): Layer; /** * 渲染 */ render(ctx: CanvasRenderingContext2D, utils: ISketchUtils): void; /** * 获得当前图层 在画布中的状态 * * x, y返回的是相对坐标 */ getLayerStatus(): { x: number; y: number; rotate: number; scaleX: number; scaleY: number; opacity: number; }; /** * 将原始北面转向目标图层 * @param layer 目标图层 * @param offset 偏移角度 */ turnTo(layer: Layer, offset?: number): this; /** * 设置坐标 */ xy(x: ILayerState['x'], y: ILayerState['y']): this; /** * 设置透明度 */ opacity(value: ILayerState['opacity']): this; /** * 设置旋转角度 */ rotate(value: ILayerState['rotate']): this; /** * 设置缩放 */ scale(x: ILayerState['scaleX'], y?: ILayerState['scaleY']): this; /** * 设置描边颜色 */ stroke(value: ILayerState['stroke']): this; /** * 设置描边宽度 */ strokeWidth(value: ILayerState['strokeWidth']): this; /** * 设置填充颜色 */ fill(value: ILayerState['fill']): this; /** * 设置为可见 */ show(): this; /** * 设置为不可见 */ hide(): this; /** * 绑定事件监听 */ on = IKey>(type: K, event: T[K]): this; /** * 绑定一次性事件监听 */ once = IKey>(type: K, event: T[K]): this; /** * 取消事件监听 */ off = IKey>(type: K, event: T[K]): this; /** * 发起事件 */ emit = IKey>(type: K, args: Parameters): this; protected _clone(): Layer; protected _render(ctx: CanvasRenderingContext2D, utils: ISketchUtils): void; } /** * @ignore */ export declare function isLayer(value: unknown): value is Layer;