aboutsummaryrefslogtreecommitdiff
path: root/emccpre.js
diff options
context:
space:
mode:
authorBen Harris <bjh21@bjh21.me.uk>2022-10-27 14:30:23 +0100
committerBen Harris <bjh21@bjh21.me.uk>2022-10-27 22:51:54 +0100
commitfa58dd85b7ee06fed8d7a5ecc14fda8146f7521b (patch)
tree5b96a2e0dfb80ff7c7db2440faa169f6b2786ade /emccpre.js
parent9783bbfbc01f2faff86daaa53e46bf68848b8b7c (diff)
downloadpuzzles-fa58dd85b7ee06fed8d7a5ecc14fda8146f7521b.zip
puzzles-fa58dd85b7ee06fed8d7a5ecc14fda8146f7521b.tar.gz
puzzles-fa58dd85b7ee06fed8d7a5ecc14fda8146f7521b.tar.bz2
puzzles-fa58dd85b7ee06fed8d7a5ecc14fda8146f7521b.tar.xz
js: Distinguish manual resizes from device pixel ratio changes
This adds a new callback, rescale_puzzle(), that's called when the device pixel ratio changes. This means that resize_puzzle() can safely set the nominal canvas size, which means that manual resizing of the puzzle now sticks. Still missing: paying attention to the device pixel ratio when choosing the initial (or reset) size.
Diffstat (limited to 'emccpre.js')
-rw-r--r--emccpre.js4
1 files changed, 3 insertions, 1 deletions
diff --git a/emccpre.js b/emccpre.js
index 0c555f9..c2af60a 100644
--- a/emccpre.js
+++ b/emccpre.js
@@ -535,12 +535,14 @@ function initPuzzle() {
* <https://developer.mozilla.org/en-US/docs/Web/API/Window/
* devicePixelRatio> (CC0) to work on older browsers.
*/
+ var rescale_puzzle = Module.cwrap('rescale_puzzle',
+ 'void', ['number', 'number']);
var mql = null;
var update_pixel_ratio = function() {
var dpr = window.devicePixelRatio;
if (mql !== null)
mql.removeListener(update_pixel_ratio);
- resize_puzzle(nominal_width * dpr, nominal_height * dpr);
+ rescale_puzzle(nominal_width * dpr, nominal_height * dpr);
mql = window.matchMedia(`(resolution: ${dpr}dppx)`);
mql.addListener(update_pixel_ratio);
}