aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Harris <bjh21@bjh21.me.uk>2022-10-27 11:27:22 +0100
committerBen Harris <bjh21@bjh21.me.uk>2022-10-27 22:51:54 +0100
commit9783bbfbc01f2faff86daaa53e46bf68848b8b7c (patch)
tree4f8251b8629cd4fbebd3befb9a87f37b06adc700
parent532d662722da1fa8cce211ced79da575059d359c (diff)
downloadpuzzles-9783bbfbc01f2faff86daaa53e46bf68848b8b7c.zip
puzzles-9783bbfbc01f2faff86daaa53e46bf68848b8b7c.tar.gz
puzzles-9783bbfbc01f2faff86daaa53e46bf68848b8b7c.tar.bz2
puzzles-9783bbfbc01f2faff86daaa53e46bf68848b8b7c.tar.xz
js: Split setting nominal and actual canvas size
Now zooming in and out repeatedly doesn't cause the canvas to wither away, but user resizes don't stick any more. Still more to do.
Diffstat (limited to '')
-rw-r--r--emcc.c2
-rw-r--r--emcclib.js28
2 files changed, 23 insertions, 7 deletions
diff --git a/emcc.c b/emcc.c
index 3c9850a..4591ccb 100644
--- a/emcc.c
+++ b/emcc.c
@@ -82,6 +82,7 @@ extern void js_canvas_copy_from_blitter(int id, int x, int y, int w, int h);
extern void js_canvas_make_statusbar(void);
extern void js_canvas_set_statusbar(const char *text);
extern void js_canvas_set_size(int w, int h);
+extern void js_canvas_set_nominal_size();
extern void js_dialog_init(const char *title);
extern void js_dialog_string(int i, const char *title, const char *initvalue);
@@ -189,6 +190,7 @@ static void resize(void)
w = h = INT_MAX;
midend_size(me, &w, &h, false);
js_canvas_set_size(w, h);
+ js_canvas_set_nominal_size();
canvas_w = w;
canvas_h = h;
}
diff --git a/emcclib.js b/emcclib.js
index f29137a..1fb3a90 100644
--- a/emcclib.js
+++ b/emcclib.js
@@ -539,20 +539,34 @@ mergeInto(LibraryManager.library, {
/*
* void js_canvas_set_size(int w, int h);
*
- * Set the size of the puzzle canvas. Called at setup, and every
- * time the user picks new puzzle settings requiring a different
- * size.
+ * Set the size of the puzzle canvas. Called whenever the size of
+ * the canvas needs to change. That might be because of a change
+ * of configuration, because the user has resized the puzzle, or
+ * because the device pixel ratio has changed.
*/
js_canvas_set_size: function(w, h) {
- var dpr = window.devicePixelRatio || 1;
onscreen_canvas.width = w;
offscreen_canvas.width = w;
- resizable_div.style.width = w / dpr + "px";
- nominal_width = w / dpr;
+ resizable_div.style.width = w / (window.devicePixelRatio || 1) + "px";
onscreen_canvas.height = h;
offscreen_canvas.height = h;
- nominal_height = h / dpr;
+ },
+
+ /*
+ * void js_canvas_set_nominal_size();
+ *
+ * Set the nominal size of the puzzle to the current canvas size
+ * scaled to CSS pixels. This should be called whenever the
+ * canvas size is changed other than in response to a change of
+ * device pixel ratio. This nominal size will then be used at
+ * every change of device pixel ratio to calculate the new
+ * physical size of the canvas.
+ */
+ js_canvas_set_nominal_size: function() {
+ var dpr = window.devicePixelRatio || 1;
+ nominal_width = onscreen_canvas.width / dpr;
+ nominal_height = onscreen_canvas.height / dpr;
},
/*