From 97699bff280a2d5fb9c6073861e098139f7020b1 Mon Sep 17 00:00:00 2001 From: Nayam Amarshe <25067102+NayamAmarshe@users.noreply.github.com> Date: Wed, 30 Oct 2024 20:06:14 +0530 Subject: [PATCH] Fix lens view --- .../components/main-content/lens-view.tsx | 122 ++++++++++-------- 1 file changed, 71 insertions(+), 51 deletions(-) diff --git a/renderer/components/main-content/lens-view.tsx b/renderer/components/main-content/lens-view.tsx index ac27949..b11f6ff 100644 --- a/renderer/components/main-content/lens-view.tsx +++ b/renderer/components/main-content/lens-view.tsx @@ -37,66 +37,86 @@ const LensViewer = ({ sanitizedImagePath: string; sanitizedUpscaledImagePath: string; }) => { - const upscaledImageRef = useRef(null); + const [hoverPosition, setHoverPosition] = useState({ x: 0, y: 0 }); + const [isHovering, setIsHovering] = useState(false); - const [lensPosition, setLensPosition] = useState({ x: 0, y: 0 }); + const handleMouseMove = (e) => { + const { left, top, width, height } = + e.currentTarget.getBoundingClientRect(); + const x = ((e.clientX - left) / width) * 100; + const y = ((e.clientY - top) / height) * 100; - const handleMouseMoveCompare = (e: React.MouseEvent) => { - if (upscaledImageRef.current) { - const { left, top, width, height } = - upscaledImageRef.current.getBoundingClientRect(); - const x = e.clientX - left; - const y = e.clientY - top; - setLensPosition({ - x: Math.max(0, Math.min(x - lensSize, width - lensSize * 2)), - y: Math.max(0, Math.min(y - lensSize / 2, height - lensSize)), - }); - } + setHoverPosition({ x, y }); }; + const handleMouseEnter = () => setIsHovering(true); + const handleMouseLeave = () => setIsHovering(false); + + const originalImage = "file:///" + sanitizedImagePath; + const upscaledImage = "file:///" + sanitizedUpscaledImagePath; + return ( -
- {/* UPSCALED IMAGE */} - Upscaled - {/* LENS */} +
+ {/* Main image container */}
-
- + {isHovering && ( +
- -
-
- Original - Upscayl -
+ )}
+ + {/* Enlarged views for original and upscaled images */} + {isHovering && ( +
+
+ + Original + +
+
+ + AI Upscaled + +
+
+ )}
); };