From 22b99b070355b00b3c7cc1b9fc9c4f9851b6dfa1 Mon Sep 17 00:00:00 2001 From: Natan Date: Thu, 26 Sep 2024 20:57:52 -0300 Subject: [PATCH] Wip window size --- .../gdx/backends/teavm/TeaApplication.java | 9 +----- .../gdx/backends/teavm/TeaGraphics.java | 31 ++++++++++++------- .../backends/teavm/dom/impl/TeaWindow.java | 4 +-- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/backends/backend-teavm/src/main/java/com/github/xpenatan/gdx/backends/teavm/TeaApplication.java b/backends/backend-teavm/src/main/java/com/github/xpenatan/gdx/backends/teavm/TeaApplication.java index b1ab7341..c6e1de21 100644 --- a/backends/backend-teavm/src/main/java/com/github/xpenatan/gdx/backends/teavm/TeaApplication.java +++ b/backends/backend-teavm/src/main/java/com/github/xpenatan/gdx/backends/teavm/TeaApplication.java @@ -192,14 +192,7 @@ public void handleEvent(EventWrapper evt) { } if(graphics != null) { - // event calls us with logical pixel size, so if we use physical pixels internally, - // we need to convert them - if(config.usePhysicalPixels) { - double density = graphics.getNativeScreenDensity(); - width = (int)(width * density); - height = (int)(height * density); - } - graphics.setCanvasSize(width, height); + graphics.setCanvasSize(width, height, config.usePhysicalPixels); } } }); diff --git a/backends/backend-teavm/src/main/java/com/github/xpenatan/gdx/backends/teavm/TeaGraphics.java b/backends/backend-teavm/src/main/java/com/github/xpenatan/gdx/backends/teavm/TeaGraphics.java index 6cb341e2..b23255ca 100644 --- a/backends/backend-teavm/src/main/java/com/github/xpenatan/gdx/backends/teavm/TeaGraphics.java +++ b/backends/backend-teavm/src/main/java/com/github/xpenatan/gdx/backends/teavm/TeaGraphics.java @@ -81,17 +81,18 @@ public TeaGraphics(TeaApplicationConfiguration config) { if(config.width >= 0 || config.height >= 0) { if(config.isFixedSizeApplication()) { - setCanvasSize(config.width, config.height); + setCanvasSize(config.width, config.height, false); } else { TeaWindow currentWindow = TeaWindow.get(); int width = currentWindow.getClientWidth() - config.padHorizontal; int height = currentWindow.getClientHeight() - config.padVertical; - double density = config.usePhysicalPixels ? getNativeScreenDensity() : 1; - setCanvasSize((int)(density * width), (int)(density * height)); + setCanvasSize(width, height, config.usePhysicalPixels); } } + context.viewport(0, 0, getWidth(), getHeight()); + // listen to fullscreen changes addFullscreenChangeListener(canvas, new FullscreenChanged() { @Override @@ -331,20 +332,26 @@ public boolean setWindowedMode(int width, int height) { if(isFullscreen()) exitFullscreen(); // don't set canvas for resizable applications, resize handler will do it if(!config.isAutoSizeApplication()) { - setCanvasSize(width, height); + setCanvasSize(width, height, config.usePhysicalPixels); } return true; } - void setCanvasSize(int width, int height) { - canvas.setWidth(width); - canvas.setHeight(height); - if(config.usePhysicalPixels) { - //TODO Not tested - double density = getNativeScreenDensity(); + void setCanvasSize(int width, int height, boolean usePhysicalPixels) { + // event calls us with logical pixel size, so if we use physical pixels internally, + // we need to convert them + double density = 1; + if(usePhysicalPixels) { + density = getNativeScreenDensity(); + } + int w = (int)(width * density); + int h = (int)(height * density); + canvas.setWidth(w); + canvas.setHeight(h); + if(usePhysicalPixels) { StyleWrapper style = canvas.getStyle(); - style.setProperty("width", width / density + StyleWrapper.Unit.PX.getType()); - style.setProperty("height", height / density + StyleWrapper.Unit.PX.getType()); + style.setProperty("width", width + StyleWrapper.Unit.PX.getType()); + style.setProperty("height", height + StyleWrapper.Unit.PX.getType()); } } diff --git a/backends/backend-teavm/src/main/java/com/github/xpenatan/gdx/backends/teavm/dom/impl/TeaWindow.java b/backends/backend-teavm/src/main/java/com/github/xpenatan/gdx/backends/teavm/dom/impl/TeaWindow.java index 92a829f1..5bfada0a 100644 --- a/backends/backend-teavm/src/main/java/com/github/xpenatan/gdx/backends/teavm/dom/impl/TeaWindow.java +++ b/backends/backend-teavm/src/main/java/com/github/xpenatan/gdx/backends/teavm/dom/impl/TeaWindow.java @@ -54,12 +54,12 @@ public LocationWrapper getLocation() { @Override public int getClientWidth() { - return window.getDocument().getDocumentElement().getClientWidth(); + return window.getInnerWidth(); } @Override public int getClientHeight() { - return window.getDocument().getDocumentElement().getClientHeight(); + return window.getInnerHeight(); } @Override