graphic-pixi/lib/plugins/GraphicEditPlugin.d.ts
2023-12-14 13:07:43 +08:00

83 lines
3.3 KiB
TypeScript

import { Container, DisplayObject, Graphics, IDestroyOptions, IPointData } from 'pixi.js';
import { JlGraphic } from '../core';
import { DraggablePoint } from '../graphic';
export declare abstract class GraphicEditPlugin<DO extends DisplayObject = DisplayObject> extends Container {
graphic: DO;
constructor(g: DO);
destroy(options?: boolean | IDestroyOptions | undefined): void;
abstract updateEditedPointsPosition(): void;
hideAll(): void;
showAll(): void;
}
export interface ILineGraphic extends JlGraphic {
get linePoints(): IPointData[];
set linePoints(points: IPointData[]);
}
export declare abstract class LineEditPlugin extends GraphicEditPlugin<ILineGraphic> {
linePoints: IPointData[];
editedPoints: DraggablePoint[];
constructor(g: ILineGraphic);
destroy(options?: boolean | IDestroyOptions | undefined): void;
reset(): void;
abstract initEditPoints(): void;
}
export declare function getWayLineIndex(points: IPointData[], p: IPointData): {
start: number;
end: number;
};
export declare function getWaypointRangeIndex(points: IPointData[], curve: boolean, p: IPointData, lineWidth: number): {
start: number;
end: number;
};
export type onEditPointCreate = (g: ILineGraphic, dp: DraggablePoint, index: number) => void;
export interface IEditPointOptions {
/**
* 编辑点创建处理
*/
onEditPointCreate?: onEditPointCreate;
}
/**
* 折线编辑(兼容线段)
*/
export declare class PolylineEditPlugin extends LineEditPlugin {
static Name: string;
options: IEditPointOptions;
constructor(g: ILineGraphic, options?: IEditPointOptions);
initEditPoints(): void;
updateEditedPointsPosition(): void;
}
export interface BezierCurveEditPointOptions extends IEditPointOptions {
auxiliaryLineColor?: string;
smooth?: boolean;
symmetry?: boolean;
}
export interface ICompleteBezierCurveEditPointOptions extends BezierCurveEditPointOptions {
smooth: boolean;
}
export declare function addWayPoint(graphic: ILineGraphic, curve: boolean, start: number, end: number, p: IPointData): void;
export declare function addLineWayPoint(graphic: ILineGraphic, start: number, end: number, p: IPointData): void;
export declare function addPolygonSegmentingPoint(graphic: ILineGraphic, start: number, end: number, knife?: number): void;
export declare function addBezierWayPoint(graphic: ILineGraphic, start: number, end: number, p: IPointData): void;
export declare function removeWayPoint(graphic: ILineGraphic, curve: boolean, i: number): void;
export declare function removeLineWayPoint(graphic: ILineGraphic, i: number): void;
export declare function removeBezierWayPoint(graphic: ILineGraphic, i: number): void;
/**
* 清除路径点(只留端点),适用于直线和贝塞尔曲线
* @param graphic
* @param curve
*/
export declare function clearWayPoint(graphic: ILineGraphic, curve: boolean): void;
/**
* 贝塞尔曲线编辑
*/
export declare class BezierCurveEditPlugin extends LineEditPlugin {
static Name: string;
options: ICompleteBezierCurveEditPointOptions;
auxiliaryLines: Graphics[];
constructor(g: ILineGraphic, options?: BezierCurveEditPointOptions);
reset(): void;
initEditPoints(): void;
drawAuxiliaryLine(line: Graphics, p1: IPointData, p2: IPointData): void;
updateEditedPointsPosition(): void;
}