Skip to content

Commit

Permalink
Wip window size
Browse files Browse the repository at this point in the history
  • Loading branch information
xpenatan committed Sep 26, 2024
1 parent 1b1d48a commit 22b99b0
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 22b99b0

Please sign in to comment.