285 lines
7.3 KiB
TypeScript
285 lines
7.3 KiB
TypeScript
import { Container, DisplayObject, IPointData, Rectangle } from 'pixi.js';
|
||
import { GraphicRelation, RelationManage } from './GraphicRelation';
|
||
import { GraphicQueryStore } from './GraphicStore';
|
||
export interface IGraphicTransform {
|
||
position: IPointData;
|
||
scale: IPointData;
|
||
rotation: number;
|
||
skew: IPointData;
|
||
}
|
||
/**
|
||
* 图形变换数据
|
||
*/
|
||
export declare class GraphicTransform {
|
||
position: IPointData;
|
||
scale: IPointData;
|
||
rotation: number;
|
||
skew: IPointData;
|
||
constructor(position: IPointData, scale: IPointData, rotation: number, skew: IPointData);
|
||
static default(): GraphicTransform;
|
||
static fromObject(obj: DisplayObject): GraphicTransform;
|
||
static from(transform: IGraphicTransform | undefined): GraphicTransform;
|
||
}
|
||
export interface IChildTransform {
|
||
name: string;
|
||
transform: IGraphicTransform;
|
||
}
|
||
/**
|
||
* 图形子元素变换
|
||
*/
|
||
export declare class ChildTransform {
|
||
name: string;
|
||
transform: GraphicTransform;
|
||
constructor(name: string, transform: GraphicTransform);
|
||
static fromChild(child: DisplayObject): ChildTransform;
|
||
static from(ct: IChildTransform): ChildTransform;
|
||
}
|
||
/**
|
||
* 图形数据
|
||
*/
|
||
export interface GraphicData {
|
||
get id(): string;
|
||
set id(v: string);
|
||
get graphicType(): string;
|
||
set graphicType(v: string);
|
||
get transform(): GraphicTransform;
|
||
set transform(v: GraphicTransform);
|
||
get childTransforms(): ChildTransform[] | undefined;
|
||
set childTransforms(v: ChildTransform[] | undefined);
|
||
/**
|
||
* 克隆消息
|
||
*/
|
||
clone(): GraphicData;
|
||
/**
|
||
* 从给定数据拷贝
|
||
* @param data
|
||
*/
|
||
copyFrom(data: GraphicData): void;
|
||
/**
|
||
* 是否相等
|
||
* @param other
|
||
*/
|
||
eq(other: GraphicData): boolean;
|
||
}
|
||
/**
|
||
* 图形状态
|
||
*/
|
||
export interface GraphicState {
|
||
get code(): string;
|
||
get graphicType(): string;
|
||
remove?: boolean;
|
||
/**
|
||
* 克隆消息
|
||
*/
|
||
clone(): GraphicState;
|
||
/**
|
||
* 从给定数据拷贝
|
||
* @param data
|
||
*/
|
||
copyFrom(data: GraphicState): void;
|
||
/**
|
||
* 是否相等
|
||
* @param data
|
||
*/
|
||
eq(data: GraphicState): boolean;
|
||
}
|
||
export interface GraphicAnimationOptions {
|
||
name: string;
|
||
run?: (dt: number) => void;
|
||
}
|
||
export declare class GraphicAnimation {
|
||
options: GraphicAnimationOptions;
|
||
_running: boolean;
|
||
/**
|
||
* 倍速
|
||
*/
|
||
_xSpeed: number;
|
||
constructor(options: GraphicAnimationOptions);
|
||
static init(options: GraphicAnimationOptions): GraphicAnimation;
|
||
pause(): GraphicAnimation;
|
||
resume(): GraphicAnimation;
|
||
get name(): string;
|
||
get running(): boolean;
|
||
get xSpeed(): number;
|
||
set xSpeed(v: number);
|
||
run(dt: number): GraphicAnimation;
|
||
}
|
||
/**
|
||
* 图形对象基类
|
||
*/
|
||
export declare abstract class JlGraphic extends Container {
|
||
readonly __JlGraphic: true;
|
||
readonly type: string;
|
||
private _id;
|
||
private _code;
|
||
_datas?: GraphicData;
|
||
_states?: GraphicState;
|
||
private _relationManage?;
|
||
private _queryStore?;
|
||
constructor(type: string);
|
||
/**
|
||
* 添加图形动画,只有在画布上才能添加
|
||
* @param animation
|
||
*/
|
||
addAnimation(animation: GraphicAnimation): void;
|
||
removeAnimation(name: string): void;
|
||
animation(name: string): GraphicAnimation | undefined;
|
||
removeAllAnimation(): void;
|
||
/**
|
||
* 更新选中状态
|
||
* @param selected
|
||
* @returns 是否更新
|
||
*/
|
||
updateSelected(selected: boolean): boolean;
|
||
invertSelected(): void;
|
||
fireSelected(): void;
|
||
hasSelectedChilds(): boolean;
|
||
setChildSelected(child: DisplayObject): boolean;
|
||
invertChildSelected(child: DisplayObject): boolean;
|
||
removeAllChildSelected(): void;
|
||
fireChildSelected(child: DisplayObject): void;
|
||
exitChildEdit(): void;
|
||
/**
|
||
* 是否此对象id/code
|
||
*/
|
||
isIdOrCode(s: string): boolean;
|
||
/**
|
||
* 获取图形id,如果图形数据对象存在,则返回图形数据对象id
|
||
*/
|
||
get id(): string;
|
||
/**
|
||
* 设置图形id,如果图形数据存在,则同时设置图形数据id
|
||
*/
|
||
set id(v: string);
|
||
/**
|
||
* 获取图形业务code,如果业务code在图形数据或图形状态中,则需要重写此方法
|
||
*/
|
||
get code(): string;
|
||
/**
|
||
* 设置图形业务code,如果业务code在图形数据或图形状态中,则需要重写此方法
|
||
*/
|
||
set code(v: string);
|
||
getDatas<D extends GraphicData>(): D;
|
||
getStates<S extends GraphicState>(): S;
|
||
get queryStore(): GraphicQueryStore;
|
||
set queryStore(v: GraphicQueryStore);
|
||
get relationManage(): RelationManage;
|
||
set relationManage(v: RelationManage);
|
||
/**
|
||
* 构建图形关系
|
||
* @param g
|
||
*/
|
||
buildRelation(): void;
|
||
/**
|
||
* 从数据加载恢复图形关系
|
||
*/
|
||
loadRelations(): void;
|
||
/**
|
||
* 获取当前图形的所有图形关系
|
||
* @returns
|
||
*/
|
||
getAllRelations(): GraphicRelation[];
|
||
/**
|
||
* 获取当前图形的所有指定类型图形关系
|
||
* @param type
|
||
* @returns
|
||
*/
|
||
queryRelationByType(type: string): GraphicRelation[];
|
||
/**
|
||
* 删除当前图形关联的指定类型的关系
|
||
* @param type
|
||
*/
|
||
deleteRelationByType(type: string): void;
|
||
/**
|
||
* 构建并保存关系数据到datas中
|
||
*/
|
||
saveRelations(): void;
|
||
/**
|
||
* 保存数据,复制,非原始数据
|
||
* @returns
|
||
*/
|
||
saveData<D extends GraphicData>(): D;
|
||
/**
|
||
* 构建子元素变换列表
|
||
* @returns
|
||
*/
|
||
private buildChildTransforms;
|
||
/**
|
||
* 加载数据
|
||
* @param data
|
||
*/
|
||
loadData(data: GraphicData): void;
|
||
private loadTransformFrom;
|
||
/**
|
||
* 更新图形数据
|
||
* @param data
|
||
* @returns
|
||
*/
|
||
updateData(data: GraphicData): boolean;
|
||
/**
|
||
* 图形数据更新
|
||
*/
|
||
onDataChange(newVal: GraphicData, old?: GraphicData): void;
|
||
/**
|
||
* 加载状态
|
||
* @param state
|
||
*/
|
||
loadState(state: GraphicState): void;
|
||
/**
|
||
* 更新状态
|
||
* @param state
|
||
* @returns
|
||
*/
|
||
updateStates(state: GraphicState): boolean;
|
||
/**
|
||
* 图形状态更新处理
|
||
*/
|
||
onStateChange(newVal: GraphicState, old?: GraphicState): void;
|
||
repaint(): void;
|
||
/**
|
||
* 处理重绘逻辑
|
||
*/
|
||
abstract doRepaint(): void;
|
||
/**
|
||
* 处理删除逻辑
|
||
*/
|
||
onDelete(): void;
|
||
/**
|
||
* 框选检测,默认取图形包围盒判定,若需要精细判定-子类重写此方法
|
||
* @param box
|
||
* @returns
|
||
*/
|
||
boxIntersectCheck(box: Rectangle): boolean;
|
||
}
|
||
export type CreateData = () => GraphicData;
|
||
export type CreateState = () => GraphicState;
|
||
export interface IGraphicTemplateOptions {
|
||
dataTemplate?: GraphicData;
|
||
stateTemplate?: GraphicState;
|
||
}
|
||
/**
|
||
* 图形对象模板
|
||
*/
|
||
export declare abstract class JlGraphicTemplate<G extends JlGraphic> {
|
||
readonly type: string;
|
||
options: IGraphicTemplateOptions;
|
||
constructor(type: string, options: IGraphicTemplateOptions);
|
||
get datas(): GraphicData;
|
||
get states(): GraphicState;
|
||
/**
|
||
* 初始化一个新的图形对象
|
||
*/
|
||
abstract new(): G;
|
||
/**
|
||
* 加载图形对象需要用到的资源
|
||
*/
|
||
loadAssets(): Promise<any>;
|
||
/**
|
||
* 克隆图形对象
|
||
* @param graphic
|
||
* @returns
|
||
*/
|
||
clone(graphic: G): G;
|
||
}
|
||
export type GraphicTemplate = JlGraphicTemplate<JlGraphic>;
|