homemanager-fe/src/modules/house-planner/interfaces.ts

84 lines
1.7 KiB
TypeScript
Raw Normal View History

2023-01-18 17:00:51 +00:00
import { LayerObjectType } from './types';
2023-01-16 19:37:39 +00:00
export type Vec2 = [number, number];
export interface LineSegment {
start?: Vec2;
end: Vec2;
}
export interface BezierSegment extends LineSegment {
startControl: Vec2;
endControl: Vec2;
}
export interface LayerObject {
2023-01-17 18:32:15 +00:00
id: number;
2023-01-16 19:37:39 +00:00
name: string;
visible: boolean;
selected: boolean;
2023-01-17 18:32:15 +00:00
type: LayerObjectType;
2023-01-16 19:37:39 +00:00
}
export interface Line extends LayerObject {
segments: LineSegment[];
width: number;
color: string;
render?: Path2D;
lineCap?: CanvasLineCap;
2023-01-18 17:00:51 +00:00
lineJoin?: CanvasLineJoin;
2023-01-16 19:37:39 +00:00
closed?: boolean;
lineDash?: number[];
}
export interface Layer {
2023-01-17 18:32:15 +00:00
id: number;
2023-01-16 19:37:39 +00:00
contents: LayerObject[];
name: string;
color: string;
visible: boolean;
active: boolean;
}
export interface History<T> {
object: T;
property: keyof T;
value: unknown;
}
export interface UpdateEvent {
event: string;
object?: LayerObject;
}
export interface ToolEvent {
2023-01-18 17:00:51 +00:00
primary: string;
secondary?: unknown;
}
2023-01-18 18:11:54 +00:00
export interface RepositionEvent {
position: Vec2;
zoom: number;
}
2023-01-18 18:47:22 +00:00
export interface ICanvasToolMouseEvents {
mouseDown(targetObject?: LayerObject): void;
mouseMoved(mouse: Vec2, offset: Vec2, mouseAbsolute: Vec2): void;
mouseUp(moved: boolean): void;
}
export interface ICanvasToolBase<U = undefined> extends ICanvasToolMouseEvents {
2023-01-18 17:00:51 +00:00
name: string;
subTool: U | undefined;
drawHighlights(): void;
drawControls(): void;
enterPress(e: KeyboardEvent): void;
escapePress(e: KeyboardEvent): void;
setSubTool(subTool?: U): void;
activate(): void;
deactivate(): void;
selectionDeleted(): void;
selectionChanged(selection: LayerObject[]): void;
emitEvent(e: CustomEvent): void;
isToolCancelable(): boolean;
2023-01-16 19:37:39 +00:00
}