aboutsummaryrefslogtreecommitdiff
path: root/emccpre.js
diff options
context:
space:
mode:
authorBen Harris <bjh21@bjh21.me.uk>2022-10-22 18:40:01 +0100
committerBen Harris <bjh21@bjh21.me.uk>2022-10-22 18:40:01 +0100
commit989c6defb0419111f1f22807849f361e26f5a083 (patch)
tree92a34589561032ea625a2ccdc693a14b17395147 /emccpre.js
parent24ce6260d55b53c27bd92a92116816b437e83e0c (diff)
downloadpuzzles-989c6defb0419111f1f22807849f361e26f5a083.zip
puzzles-989c6defb0419111f1f22807849f361e26f5a083.tar.gz
puzzles-989c6defb0419111f1f22807849f361e26f5a083.tar.bz2
puzzles-989c6defb0419111f1f22807849f361e26f5a083.tar.xz
js: Pay attention to changes in device pixel ratio
Because it's the simplest thing to do, when we notice such a change we keep the current puzzle at its existing size measured in device pixels. This has the rather odd consequence that when changing the text size in Firefox, the size of the puzzle remains constant.
Diffstat (limited to 'emccpre.js')
-rw-r--r--emccpre.js13
1 files changed, 13 insertions, 0 deletions
diff --git a/emccpre.js b/emccpre.js
index d12ef79..f97fb63 100644
--- a/emccpre.js
+++ b/emccpre.js
@@ -526,6 +526,19 @@ function initPuzzle() {
}
});
+ /*
+ * Arrange to detect changes of device pixel ratio. Adapted from
+ * <https://developer.mozilla.org/en-US/docs/Web/API/Window/
+ * devicePixelRatio> (CC0).
+ */
+ const update_pixel_ratio = () => {
+ let dpr = window.devicePixelRatio;
+ resizable_div.style.width = onscreen_canvas.width / dpr + "px";
+ matchMedia(`(resolution: ${dpr}dppx)`)
+ .addEventListener("change", update_pixel_ratio, { once: true })
+ }
+ update_pixel_ratio();
+
Module.onRuntimeInitialized = function() {
// Run the C setup function, passing argv[1] as the fragment
// identifier (so that permalinks of the form puzzle.html#game-id