From c8260245622780be003a897464bd5f7798b3a307 Mon Sep 17 00:00:00 2001 From: Charlie Stanton Date: Sun, 6 Apr 2025 17:38:19 +0100 Subject: web assembly port now fills the screen --- src/index.html.in | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) (limited to 'src/index.html.in') diff --git a/src/index.html.in b/src/index.html.in index 9329c25..119d646 100644 --- a/src/index.html.in +++ b/src/index.html.in @@ -101,13 +101,16 @@ async function main() { return b html.clientWidth) { + canvas.width = html.clientWidth; + canvas.height = (html.clientWidth - 64) * (16 / 20); + } else { + canvas.width = 64 + html.clientHeight * (20 / 16); + canvas.height = html.clientHeight; + } + let width = canvas.width; + let height = canvas.height; let ptr = exports.game_render(width, height, mousex, mousey); let dl = new Int32Array(memory.buffer, ptr); let len = dl[0]; @@ -132,19 +135,21 @@ async function main() { } } - function onresize() { html.style.maxWidth = `${max_width()}px`; } + function onresize() { /*html.style.maxWidth = `${max_width()}px`; */} window.addEventListener("resize", onresize); onresize(); canvas.addEventListener("mousemove", function(e) { - mousex = e.clientX; - mousey = e.clientY; + const rect = e.target.getBoundingClientRect(); + mousex = e.clientX - rect.left; + mousey = e.clientY - rect.top; exports.game_update(INPUT_MOVE, mousex, mousey, now()); }); canvas.addEventListener("mousedown", function(e) { - mousex = e.clientX; - mousey = e.clientY; + const rect = e.target.getBoundingClientRect(); + mousex = e.clientX - rect.left; + mousey = e.clientY - rect.top; if (e.button == 0) { exports.game_update(INPUT_CLICK, mousex, mousey, now()); } else if (e.button == 2) { -- cgit v1.2.3