From bf60bbb6c59b954d84765809f266802cd44100f5 Mon Sep 17 00:00:00 2001 From: Brooklyn Nicholson Date: Fri, 26 Jun 2026 00:42:19 -0500 Subject: [PATCH] refactor(desktop): collapse overlay zoom-anchor math --- .../src/app/pet-overlay/pet-overlay-app.tsx | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/apps/desktop/src/app/pet-overlay/pet-overlay-app.tsx b/apps/desktop/src/app/pet-overlay/pet-overlay-app.tsx index dbcee4b29ed..ae3c1860b7c 100644 --- a/apps/desktop/src/app/pet-overlay/pet-overlay-app.tsx +++ b/apps/desktop/src/app/pet-overlay/pet-overlay-app.tsx @@ -324,20 +324,18 @@ export function PetOverlayApp() { const anchor = zoomAnchorRef.current zoomAnchorRef.current = null - // The sprite's bottom-center sits at (curW/2, curH - paddingBottom) and - // scales about that point. Solve for the new window origin that holds either - // the cursor pixel (wheel) or that bottom-center (slider) at a fixed spot. - const dx = anchor ? anchor.clientX - curW / 2 : 0 - const dy = anchor ? anchor.clientY - (curH - PET_PADDING_BOTTOM) : 0 + // The sprite scales about its bottom-center, at window-local (curW/2, + // curH - paddingBottom). Hold the anchor pixel fixed on screen as it scales; + // with no wheel anchor we pin the bottom-center itself (ratio 1 ⇒ no shift). const ratio = anchor?.ratio ?? 1 - const anchorX = anchor?.clientX ?? curW / 2 - const anchorY = anchor?.clientY ?? curH - PET_PADDING_BOTTOM + const ax = anchor?.clientX ?? curW / 2 + const ay = anchor?.clientY ?? curH - PET_PADDING_BOTTOM const bounds = { height, width, - x: Math.round(window.screenX + anchorX - dx * ratio - width / 2), - y: Math.round(window.screenY + anchorY - dy * ratio - (height - PET_PADDING_BOTTOM)) + x: Math.round(window.screenX + ax - (ax - curW / 2) * ratio - width / 2), + y: Math.round(window.screenY + ay - (ay - (curH - PET_PADDING_BOTTOM)) * ratio - (height - PET_PADDING_BOTTOM)) } window.hermesDesktop?.petOverlay?.setBounds(bounds)