Back to shtanton's homepage
summaryrefslogtreecommitdiff
path: root/src/index.html.in
diff options
context:
space:
mode:
Diffstat (limited to 'src/index.html.in')
-rw-r--r--src/index.html.in27
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) {