From 5d8dc15d8643e5f6e27ca3c0648a3208eb3e8f31 Mon Sep 17 00:00:00 2001 From: Leopoldadmin Date: Mon, 22 Jun 2026 07:23:13 +0000 Subject: [PATCH] Implement PolylineTool.ts --- frontend/src/tools/drawing/PolylineTool.ts | 51 ++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 frontend/src/tools/drawing/PolylineTool.ts diff --git a/frontend/src/tools/drawing/PolylineTool.ts b/frontend/src/tools/drawing/PolylineTool.ts new file mode 100644 index 0000000..19a96ea --- /dev/null +++ b/frontend/src/tools/drawing/PolylineTool.ts @@ -0,0 +1,51 @@ +import { Tool } from '../Tool'; +import { YjsDocument } from '../../crdt/YjsDocument'; + +class PolylineTool extends Tool { + private points: Array<{ x: number; y: number }> = []; + private isDrawing: boolean = false; + + constructor(yjsDoc: YjsDocument) { + super(yjsDoc); + this.name = 'PolylineTool'; + } + + onMouseDown(event: MouseEvent): void { + if (!this.isDrawing) { + // Start drawing + this.isDrawing = true; + this.points = [{ x: event.clientX, y: event.clientY }]; + } else { + // Add point to polyline + this.points.push({ x: event.clientX, y: event.clientY }); + + // If shift key is not pressed, finish the polyline + if (!event.shiftKey) { + this.yjsDoc.createPolyline([...this.points]); + this.reset(); + } + } + } + + onMouseMove(event: MouseEvent): void { + // Preview polyline while drawing + } + + onMouseUp(event: MouseEvent): void { + // Handle mouse up if needed + } + + onKeyUp(event: KeyboardEvent): void { + // Handle key up events + if (event.key === 'Escape') { + this.reset(); + } + } + + reset(): void { + this.points = []; + this.isDrawing = false; + } +} + +export { PolylineTool }; \ No newline at end of file