Files
web-cad/frontend/src/tools/drawing/PolylineTool.ts
T

51 lines
1.2 KiB
TypeScript
Raw Normal View History

2026-06-22 07:23:13 +00:00
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 };