From 9fea70a00a18faeb4dd9a577d00f225218213cf8 Mon Sep 17 00:00:00 2001 From: Jens Cornelsen <79703163+IB-Cornelsen@users.noreply.github.com> Date: Tue, 10 Dec 2024 02:02:32 +0100 Subject: [PATCH] CAD --- .../erstellung-energieausweise/index.astro | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/src/pages/faq/erstellung-energieausweise/index.astro b/src/pages/faq/erstellung-energieausweise/index.astro index b4096e2b..0ac8fbf8 100644 --- a/src/pages/faq/erstellung-energieausweise/index.astro +++ b/src/pages/faq/erstellung-energieausweise/index.astro @@ -111,6 +111,61 @@ import Layout from "#layouts/cadLayout.astro"; ctx.stroke(); } + + +// Track whether we are actively drawing a temporary line +let isMouseOverCanvas = false; + +// Event to draw a temporary line +canvas.addEventListener('mousemove', (e) => { + if (!lastEndPoint || !isMouseOverCanvas) return; + + const cursorX = snapToGrid(e.offsetX); + const cursorY = snapToGrid(e.offsetY); + + // Clear the canvas (excluding the captured drawings) + ctx.clearRect(0, 0, canvas.width, canvas.height); + drawGrid(); + + // Redraw all captured lines + capturedLines.forEach(line => { + drawLine(line.startX, line.startY, line.endX, line.endY); + }); + + // Draw the temporary line + drawTemporaryLine(lastEndPoint.x, lastEndPoint.y, cursorX, cursorY); +}); + +// Mouse enters canvas +canvas.addEventListener('mouseenter', () => { + isMouseOverCanvas = true; +}); + +// Mouse leaves canvas +canvas.addEventListener('mouseleave', () => { + isMouseOverCanvas = false; + ctx.clearRect(0, 0, canvas.width, canvas.height); + drawGrid(); + + // Redraw all captured lines + capturedLines.forEach(line => { + drawLine(line.startX, line.startY, line.endX, line.endY); + }); +}); + +// Function to draw a temporary line +function drawTemporaryLine(x1, y1, x2, y2) { + ctx.beginPath(); + ctx.strokeStyle = "#aaaaaa"; // Light gray for the temporary line + ctx.lineWidth = 1; + ctx.setLineDash([5, 5]); // Dashed line + ctx.moveTo(x1, y1); + ctx.lineTo(x2, y2); + ctx.stroke(); + ctx.setLineDash([]); // Reset to solid lines for permanent drawings +} + + // Initialize canvas drawGrid(); // Draw the grid when the page loads