From f3c0c65f8d3a10277b6fc89eb5bd8e0c007c778d Mon Sep 17 00:00:00 2001 From: Leopoldadmin Date: Mon, 22 Jun 2026 07:23:29 +0000 Subject: [PATCH] Implement RectTool.ts --- frontend/src/tools/drawing/RectTool.ts | 43 ++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 frontend/src/tools/drawing/RectTool.ts diff --git a/frontend/src/tools/drawing/RectTool.ts b/frontend/src/tools/drawing/RectTool.ts new file mode 100644 index 0000000..7e29651 --- /dev/null +++ b/frontend/src/tools/drawing/RectTool.ts @@ -0,0 +1,43 @@ +import { Tool } from '../Tool'; +import { YjsDocument } from '../../crdt/YjsDocument'; + +class RectTool extends Tool { + private startPoint: { x: number; y: number } | null = null; + + constructor(yjsDoc: YjsDocument) { + super(yjsDoc); + this.name = 'RectTool'; + } + + onMouseDown(event: MouseEvent): void { + if (!this.startPoint) { + this.startPoint = { x: event.clientX, y: event.clientY }; + } else { + // Create rectangle element in Yjs document + const x = Math.min(this.startPoint.x, event.clientX); + const y = Math.min(this.startPoint.y, event.clientY); + const width = Math.abs(event.clientX - this.startPoint.x); + const height = Math.abs(event.clientY - this.startPoint.y); + this.yjsDoc.createRectangle(x, y, width, height); + this.startPoint = null; + } + } + + onMouseMove(event: MouseEvent): void { + // Preview rectangle 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 { RectTool }; \ No newline at end of file