mirror of
https://github.com/godotengine/godot.git
synced 2025-12-08 06:09:55 +00:00
Better HiDPI support in HTML5.
This commit is contained in:
parent
7d0896e763
commit
806edcae5b
2 changed files with 19 additions and 7 deletions
18
misc/dist/html/full-size.html
vendored
18
misc/dist/html/full-size.html
vendored
|
|
@ -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();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue