Implement DimensionTool.ts
This commit is contained in:
@@ -0,0 +1,44 @@
|
|||||||
|
import { Tool } from '../Tool';
|
||||||
|
import { YjsDocument } from '../../crdt/YjsDocument';
|
||||||
|
|
||||||
|
class DimensionTool extends Tool {
|
||||||
|
private startPoint: { x: number; y: number } | null = null;
|
||||||
|
|
||||||
|
constructor(yjsDoc: YjsDocument) {
|
||||||
|
super(yjsDoc);
|
||||||
|
this.name = 'DimensionTool';
|
||||||
|
}
|
||||||
|
|
||||||
|
onMouseDown(event: MouseEvent): void {
|
||||||
|
if (!this.startPoint) {
|
||||||
|
this.startPoint = { x: event.clientX, y: event.clientY };
|
||||||
|
} else {
|
||||||
|
// Create dimension element in Yjs document
|
||||||
|
this.yjsDoc.createDimension(
|
||||||
|
this.startPoint.x,
|
||||||
|
this.startPoint.y,
|
||||||
|
event.clientX,
|
||||||
|
event.clientY
|
||||||
|
);
|
||||||
|
this.startPoint = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onMouseMove(event: MouseEvent): void {
|
||||||
|
// Preview dimension while dragging
|
||||||
|
}
|
||||||
|
|
||||||
|
onMouseUp(event: MouseEvent): void {
|
||||||
|
// Handle mouse up if needed
|
||||||
|
}
|
||||||
|
|
||||||
|
onKeyUp(event: KeyboardEvent): void {
|
||||||
|
// Handle key up events
|
||||||
|
}
|
||||||
|
|
||||||
|
reset(): void {
|
||||||
|
this.startPoint = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export { DimensionTool };
|
||||||
Reference in New Issue
Block a user