86 |
91 |
|
public static Dim limitInitialWindowSize(Graphics graphics) { |
87 |
92 |
|
if (graphics.isFullscreen()) { |
88 |
93 |
|
// If fullscreen, we fill the entire screen already so nothing needs to be done |
89 |
|
- |
} else { |
90 |
|
- |
// Width/height of the window in physical pixels |
91 |
|
- |
int w = graphics.getBackBufferWidth(); |
92 |
|
- |
int h = graphics.getBackBufferHeight(); |
93 |
|
- |
|
94 |
|
- |
// Limit window size so it fits inside the current monitor (with a margin for OS bars/decorations) |
95 |
|
- |
DisplayMode displayMode = graphics.getDisplayMode(); |
96 |
|
- |
int maxW = displayMode.width - 100; |
97 |
|
- |
int maxH = displayMode.height - 150; |
98 |
|
- |
|
99 |
|
- |
int dw = Math.min(0, maxW - w); |
100 |
|
- |
int dh = Math.min(0, maxH - h); |
101 |
|
- |
graphics.setWindowedMode(w + dw, h + dh); |
102 |
|
- |
|
103 |
|
- |
// Also change the window's position so it's centered on its previous location |
104 |
|
- |
Lwjgl3Window window = getCurrentWindow(); |
105 |
|
- |
window.setPosition(window.getPositionX() - dw / 2, window.getPositionY() - dh / 2); |
|
94 |
+ |
return Dim.of(graphics.getBackBufferWidth(), graphics.getBackBufferHeight()); |
106 |
95 |
|
} |
107 |
96 |
|
|
108 |
|
- |
return Dim.of(graphics.getBackBufferWidth(), graphics.getBackBufferHeight()); |
|
97 |
+ |
// Width/height of the window in physical pixels |
|
98 |
+ |
int w = graphics.getBackBufferWidth(); |
|
99 |
+ |
int h = graphics.getBackBufferHeight(); |
|
100 |
+ |
|
|
101 |
+ |
// Limit window size so it fits inside the current monitor (with a margin for OS bars/decorations) |
|
102 |
+ |
DisplayMode displayMode = graphics.getDisplayMode(); |
|
103 |
+ |
int targetW = Math.min(w, displayMode.width - 100); |
|
104 |
+ |
int targetH = Math.min(h, displayMode.height - 150); |
|
105 |
+ |
|
|
106 |
+ |
float scale = Math.min(targetW / (float)w, targetH / (float)h); |
|
107 |
+ |
targetW = Math.round(w * scale); |
|
108 |
+ |
targetH = Math.round(h * scale); |
|
109 |
+ |
graphics.setWindowedMode(targetW, targetH); |
|
110 |
+ |
|
|
111 |
+ |
return Dim.of(targetW, targetH); |
109 |
112 |
|
} |
110 |
113 |
|
|
111 |
114 |
|
} |