import { injectable } from 'inversify'; import { ConfigEntity } from '../../../common'; import { Emitter, Event } from '@gedit/utils'; export interface PathPointSelection { pointId?: T; bezierKey?: 'left' | 'right'; } export enum PathSelectMode { // SELECT = 'select', // 选择模式,开启区域选择, 没有贝赛尔点的选择 ADD_PATH = 'add_path', // 增加路径点模式,关闭区域选择;开启贝赛点的选择 SELECT_BEZIER = 'select_bezier', // 闭合路径或先中间点时状态;开启区域选择器加贝赛尔点的选择; } @injectable() export class PathPointSelectionEntity extends ConfigEntity { static type = 'PathPointSelectionEntity'; protected readonly onSelectionChangedEmitter = new Emitter(); readonly onSelectionChanged: Event = this.onSelectionChangedEmitter .event; private currentSelection?: PathPointSelection[] = []; // selectMode: PathSelectMode = PathSelectMode.ADD_PATH; private mode = PathSelectMode.ADD_PATH; get selectMode(): PathSelectMode { return this.mode; } set selectMode(mode: PathSelectMode) { this.mode = mode; } get selection(): PathPointSelection[] | undefined { return this.currentSelection; } set selection(selection: PathPointSelection[] | undefined) { if (this.currentSelection !== selection) { this.currentSelection = selection; this.onSelectionChangedEmitter.fire(this.currentSelection); } } // 清除选择 clearSelection(): void { this.selection = []; } // 进入编辑模式 enterPathMode(selection: PathPointSelection[] | undefined): void { this.selectMode = PathSelectMode.ADD_PATH; this.selection = selection; } exitPathMode(): void { this.selectMode = PathSelectMode.SELECT_BEZIER; this.clearSelection(); } // 进入选择模式, /* enterSelectMode(selection: PathPointSelection[] | undefined): void { this.selectMode = PathSelectMode.SELECT; this.selection = selection; } */ // 进入带编辑的选择模式 enterSelectBezierMode(selection: PathPointSelection[] | undefined): void { this.selectMode = PathSelectMode.SELECT_BEZIER; this.selection = selection; } }