class ToolManager { constructor(app) { this.app = app; this.currentTool = 'pointer'; this.snapToGrid = true; // Tool-specific state this.isDrawing = false; this.isPanning = false; this.isDraggingElement = false; this.isRotatingElement = false; // Drawing state this.startX = 0; this.startY = 0; // Panning state this.lastPanX = 0; this.lastPanY = 0; // Element manipulation state this.draggedElement = null; this.dragStartX = 0; this.dragStartY = 0; this.rotatedElement = null; this.rotateStartAngle = 0; } // Set current tool and update UI setTool(tool) { console.log(`Setting tool to: ${tool}`); this.currentTool = tool; this.app.uiManager.updateToolButtons(tool); this.app.uiManager.updateInstructionText(tool); this.updateCanvasCursor(tool); console.log(`Current tool is now: ${this.currentTool}`); } // Update canvas cursor based on current tool updateCanvasCursor(tool) { const cursors = { 'pointer': 'default', 'hand': 'grab', 'move': 'move', 'rotate': 'crosshair', 'room': 'crosshair', 'wall': 'crosshair', 'door': 'copy', 'window': 'copy' }; const cursor = cursors[tool] || 'default'; this.app.canvas.style.cursor = cursor; // Update during interactions if (tool === 'hand') { this.app.canvas.addEventListener('mousedown', () => { this.app.canvas.style.cursor = 'grabbing'; }); this.app.canvas.addEventListener('mouseup', () => { this.app.canvas.style.cursor = 'grab'; }); } } // Get current tool getCurrentTool() { return this.currentTool; } // Check if currently drawing isCurrentlyDrawing() { return this.isDrawing; } // Toggle grid snapping toggleSnap() { this.snapToGrid = !this.snapToGrid; this.updateToggleButton('toggleSnapBtn', this.snapToGrid); } // Update toggle button appearance updateToggleButton(buttonId, isActive) { const button = document.getElementById(buttonId); if (button) { if (isActive) { button.classList.add('bg-green-100'); button.classList.remove('bg-gray-100'); } else { button.classList.remove('bg-green-100'); button.classList.add('bg-gray-100'); } } } // Reset all tool states resetStates() { this.isDrawing = false; this.isPanning = false; this.isDraggingElement = false; this.isRotatingElement = false; this.draggedElement = null; this.rotatedElement = null; } }