diff options
| author | Charlie Stanton <charlie@shtanton.xyz> | 2025-04-06 17:38:19 +0100 | 
|---|---|---|
| committer | Charlie Stanton <charlie@shtanton.xyz> | 2025-04-06 17:38:19 +0100 | 
| commit | c8260245622780be003a897464bd5f7798b3a307 (patch) | |
| tree | 313f23caca398d01bb5c1760e8a5dd3ea2393bc0 | |
| parent | 8ae382513b15f7050f81a65a3a156f6e3ac7c178 (diff) | |
| download | ldjam57-c8260245622780be003a897464bd5f7798b3a307.tar | |
web assembly port now fills the screen
| -rw-r--r-- | src/index.html.in | 27 | 
1 files changed, 16 insertions, 11 deletions
| 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<a ? b : a;      } -    function max_width() { -        return html.clientHeight * 0.7 | 0; -    } -      function render() { -        let width  = canvas.width  = min(html.clientWidth, max_width()); -        let height = canvas.height = width; +			if (64 + html.clientHeight * (20 / 16) > 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) { | 
