From 806edcae5bf94dced436cd6d27cb94a3a8134e3b Mon Sep 17 00:00:00 2001 From: Fabio Alessandrelli Date: Thu, 30 Jul 2020 17:10:16 +0200 Subject: Better HiDPI support in HTML5. --- misc/dist/html/full-size.html | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'misc') diff --git a/misc/dist/html/full-size.html b/misc/dist/html/full-size.html index be25ce4839..b293fc9711 100644 --- a/misc/dist/html/full-size.html +++ b/misc/dist/html/full-size.html @@ -156,6 +156,9 @@ $GODOT_HEAD_INCLUDE var initializing = true; var statusMode = 'hidden'; + var lastWidth = 0; + var lastHeight = 0; + var lastScale = 0; var animationCallbacks = []; function animate(time) { @@ -165,11 +168,16 @@ $GODOT_HEAD_INCLUDE requestAnimationFrame(animate); function adjustCanvasDimensions() { - var scale = window.devicePixelRatio || 1; - var width = window.innerWidth; - var height = window.innerHeight; - canvas.width = width * scale; - canvas.height = height * scale; + const scale = window.devicePixelRatio || 1; + if (lastWidth != window.innerWidth || lastHeight != window.innerHeight || lastScale != scale) { + lastScale = scale; + lastWidth = window.innerWidth; + lastHeight = window.innerHeight; + canvas.width = Math.floor(lastWidth * scale); + canvas.height = Math.floor(lastHeight * scale); + canvas.style.width = lastWidth + "px"; + canvas.style.height = lastHeight + "px"; + } } animationCallbacks.push(adjustCanvasDimensions); adjustCanvasDimensions(); -- cgit v1.2.3