151 lines
4.2 KiB
TypeScript
151 lines
4.2 KiB
TypeScript
import { BitmapFont, BitmapText, Container, FederatedMouseEvent, Point } from 'pixi.js';
|
||
import { GraphicData, GraphicTemplate, JlGraphic } from '../core/JlGraphic';
|
||
import { AppInteractionPlugin, InteractionPlugin, KeyListener } from '../plugins';
|
||
import { GraphicApp, GraphicAppOptions, ICanvasProperties, IGraphicApp, IJlCanvas } from './JlGraphicApp';
|
||
/**
|
||
* 图形绘制助手
|
||
*/
|
||
export declare abstract class GraphicDrawAssistant<GT extends GraphicTemplate, GD extends GraphicData> extends AppInteractionPlugin {
|
||
readonly __GraphicDrawAssistant = true;
|
||
app: IDrawApp;
|
||
type: string;
|
||
description: string;
|
||
icon: string;
|
||
container: Container;
|
||
graphicTemplate: GT;
|
||
escListener: KeyListener;
|
||
onEsc(): void;
|
||
constructor(graphicApp: IDrawApp, graphicTemplate: GT, icon: string, description: string);
|
||
get canvas(): IJlCanvas;
|
||
bind(): void;
|
||
unbind(): void;
|
||
onLeftDown(e: FederatedMouseEvent): void;
|
||
onMouseMove(e: FederatedMouseEvent): void;
|
||
onLeftUp(e: FederatedMouseEvent): void;
|
||
onRightDown(e: FederatedMouseEvent): void;
|
||
onRightUp(e: FederatedMouseEvent): void;
|
||
onRightClick(e: FederatedMouseEvent): void;
|
||
/**
|
||
* 获取下一个id
|
||
*/
|
||
nextId(): number;
|
||
clearCache(): void;
|
||
/**
|
||
* 重绘
|
||
* @param cp 鼠标所在画布坐标
|
||
*/
|
||
abstract redraw(cp: Point): void;
|
||
abstract prepareData(data: GD): boolean;
|
||
toCanvasCoordinates(p: Point): Point;
|
||
/**
|
||
* 保存创建的图形对象
|
||
*/
|
||
storeGraphic(...graphics: JlGraphic[]): void;
|
||
/**
|
||
* 创建并添加到图形App
|
||
*/
|
||
createAndStore(finish: boolean): JlGraphic | null;
|
||
/**
|
||
* 绘制完成
|
||
*/
|
||
finish(...graphics: JlGraphic[]): void;
|
||
}
|
||
/**
|
||
* 绘制助手类型
|
||
*/
|
||
export type DrawAssistant = GraphicDrawAssistant<GraphicTemplate, GraphicData>;
|
||
/**
|
||
* 绘制配置选项
|
||
*/
|
||
export type DrawAppOptions = GraphicAppOptions;
|
||
/**
|
||
* 绘制应用接口
|
||
*/
|
||
export interface IDrawApp extends IGraphicApp {
|
||
/**
|
||
* 是否正在绘制图形
|
||
*/
|
||
get drawing(): boolean;
|
||
/**
|
||
* 更新绘制中状态
|
||
*/
|
||
set drawing(value: boolean);
|
||
/**
|
||
* 设置配置选项
|
||
* @param options
|
||
*/
|
||
setOptions(options: DrawAppOptions): void;
|
||
/**
|
||
* 获取绘制助手
|
||
*/
|
||
getDrawAssistant<DA extends DrawAssistant>(graphicType: string): DA;
|
||
/**
|
||
* 更新画布并记录
|
||
* @param data
|
||
*/
|
||
updateCanvasAndRecord(data: ICanvasProperties): void;
|
||
/**
|
||
* 更新图形并记录
|
||
* @param g
|
||
* @param data
|
||
*/
|
||
updateGraphicAndRecord(g: JlGraphic, data: GraphicData): void;
|
||
/**
|
||
* 绑定form表单对象
|
||
* @param form
|
||
*/
|
||
bindFormData(form: GraphicData): void;
|
||
/**
|
||
* 解绑form表单对象
|
||
* @param form
|
||
*/
|
||
unbindFormData(form: GraphicData): void;
|
||
}
|
||
/**
|
||
* 绘制应用
|
||
*/
|
||
export declare class JlDrawApp extends GraphicApp implements IDrawApp {
|
||
font: BitmapFont;
|
||
coordinates: BitmapText;
|
||
scaleText: BitmapText;
|
||
drawAssistants: DrawAssistant[];
|
||
_drawing: boolean;
|
||
private debouncedFormDataUpdator;
|
||
get drawing(): boolean;
|
||
set drawing(value: boolean);
|
||
constructor(options: DrawAppOptions);
|
||
setOptions(options: DrawAppOptions): void;
|
||
registerInteractionPlugin(...plugins: InteractionPlugin[]): void;
|
||
getDrawAssistant<DA extends DrawAssistant>(graphicType: string): DA;
|
||
private appOperationRecord;
|
||
/**
|
||
* 绘制状态信息显示
|
||
*/
|
||
private appendDrawStatesDisplay;
|
||
bindKeyboardOperation(): void;
|
||
/**
|
||
* 图形对象存储处理,默认添加图形交互
|
||
* @param graphic
|
||
*/
|
||
beforeGraphicStore(graphic: JlGraphic): void;
|
||
formData: GraphicData | undefined;
|
||
/**
|
||
* 绑定form表单对象
|
||
* @param form
|
||
*/
|
||
bindFormData(form: GraphicData): void;
|
||
/**
|
||
* 移除form绑定
|
||
* @param form
|
||
*/
|
||
unbindFormData(form: GraphicData): void;
|
||
private formDataSyncListen;
|
||
/**
|
||
* 处理表单数据更新(使用debounce限流)
|
||
*/
|
||
private handleFormDataUpdate;
|
||
private doFormDataUpdate;
|
||
updateCanvasAndRecord(data: ICanvasProperties): void;
|
||
updateGraphicAndRecord(g: JlGraphic, data: GraphicData): void;
|
||
}
|