Implement LineTool.ts
This commit is contained in:
@@ -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 };
|
||||
Reference in New Issue
Block a user