diff --git a/frontend/src/tools/drawing/LineTool.ts b/frontend/src/tools/drawing/LineTool.ts new file mode 100644 index 0000000..129c599 --- /dev/null +++ b/frontend/src/tools/drawing/LineTool.ts @@ -0,0 +1,39 @@ +import { Tool } from '../Tool'; +import { YjsDocument } from '../../crdt/YjsDocument'; + +class LineTool extends Tool { + private startPoint: { x: number; y: number } | null = null; + + constructor(yjsDoc: YjsDocument) { + super(yjsDoc); + this.name = 'LineTool'; + } + + onMouseDown(event: MouseEvent): void { + if (!this.startPoint) { + this.startPoint = { x: event.clientX, y: event.clientY }; + } else { + // Create line element in Yjs document + this.yjsDoc.createLine(this.startPoint.x, this.startPoint.y, event.clientX, event.clientY); + this.startPoint = null; + } + } + + onMouseMove(event: MouseEvent): void { + // Preview line 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 { LineTool }; \ No newline at end of file