shithub: puzzles

Download patch

ref: 0254a163ff002aca56a6e08d7a5799f34cf48d94
parent: 989c6defb0419111f1f22807849f361e26f5a083
author: Ben Harris <bjh21@bjh21.me.uk>
date: Sat Oct 22 14:50:34 EDT 2022

js: Make resizing of puzzles work properly again

This requires looking at the CSS size of the puzzle canvas rather than
its internal size, and then adjusting the new size to account for the
device pixel ratio.

--- a/emccpre.js
+++ b/emccpre.js
@@ -482,10 +482,10 @@
     resize_handle.onmousedown = function(event) {
         if (event.button == 0) {
             var xy = element_coords(onscreen_canvas);
-            resize_xbase = xy.x + onscreen_canvas.width / 2;
+            resize_xbase = xy.x + onscreen_canvas.offsetWidth / 2;
             resize_ybase = xy.y;
-            resize_xoffset = xy.x + onscreen_canvas.width - event.pageX;
-            resize_yoffset = xy.y + onscreen_canvas.height - event.pageY;
+            resize_xoffset = xy.x + onscreen_canvas.offsetWidth - event.pageX;
+            resize_yoffset = xy.y + onscreen_canvas.offsetHeight - event.pageY;
         } else {
             restore_pending = true;
         }
@@ -494,8 +494,10 @@
     };
     window.addEventListener("mousemove", function(event) {
         if (resize_xbase !== null && resize_ybase !== null) {
-            resize_puzzle((event.pageX + resize_xoffset - resize_xbase) * 2,
-                          (event.pageY + resize_yoffset - resize_ybase));
+            var dpr = window.devicePixelRatio || 1;
+            resize_puzzle(
+                (event.pageX + resize_xoffset - resize_xbase) * dpr * 2,
+                (event.pageY + resize_yoffset - resize_ybase) * dpr);
             event.preventDefault();
             // Chrome insists on selecting text during a resize drag
             // no matter what I do