diff --git a/client/src/components/canvas.tsx b/client/src/components/canvas.tsx index f906353..f9e2426 100644 --- a/client/src/components/canvas.tsx +++ b/client/src/components/canvas.tsx @@ -24,6 +24,7 @@ export function Canvas({ const containerRef = useRef(null); const [zoom, setZoom] = useState(1); const [pixelSize, setPixelSize] = useState(8); + const [mouseCoords, setMouseCoords] = useState<{x: number, y: number} | null>(null); // Create pixel map for O(1) lookup const pixelMap = new Map(); @@ -36,6 +37,14 @@ export function Canvas({ onPixelClick(x, y); }; + const handlePixelMouseEnter = (x: number, y: number) => { + setMouseCoords({ x, y }); + }; + + const handlePixelMouseLeave = () => { + setMouseCoords(null); + }; + const handleZoomIn = () => { setZoom(prev => Math.min(prev * 1.2, 3)); }; @@ -67,11 +76,49 @@ export function Canvas({ className="w-full h-full overflow-auto p-8" data-testid="canvas-container" > -
+ {/* Coordinate System Container */} +
+ {/* Top X-axis coordinates */} +
+ {Array.from({ length: Math.ceil(canvasWidth / 10) }, (_, i) => ( +
+ {i * 10} +
+ ))} +
+ + {/* Canvas with left Y-axis coordinates */} +
+ {/* Left Y-axis coordinates */} +
+ {Array.from({ length: Math.ceil(canvasHeight / 10) }, (_, i) => ( +
+ {i * 10} +
+ ))} +
+ + {/* Main Canvas */} +
{Array.from({ length: canvasHeight }, (_, y) => Array.from({ length: canvasWidth }, (_, x) => { const pixelColor = pixelMap.get(`${x},${y}`) || "#FFFFFF"; @@ -88,6 +135,8 @@ export function Canvas({ height: `${pixelSize}px` }} onClick={() => handlePixelClick(x, y)} + onMouseEnter={() => handlePixelMouseEnter(x, y)} + onMouseLeave={handlePixelMouseLeave} data-testid={`pixel-${x}-${y}`} data-x={x} data-y={y} @@ -95,9 +144,26 @@ export function Canvas({ ); }) )} +
+
+ {/* Coordinate Info Display */} +
+
+ Canvas: {canvasWidth} × {canvasHeight} +
+
+ Zoom: {Math.round(zoom * 100)}% +
+ {mouseCoords && ( +
+ Mouse: ({mouseCoords.x}, {mouseCoords.y}) +
+ )} +
+ {/* Zoom Controls */}