mirror of
https://github.com/LostArtefacts/TRX.git
synced 2025-04-28 12:47:58 +03:00
tr2/shell: center offscreen window on game launch
This commit is contained in:
parent
5d6a1db061
commit
55e96ba377
2 changed files with 30 additions and 4 deletions
|
@ -15,6 +15,7 @@
|
|||
- added the current music track and timestamp to the savegame so they now persist on load (#2579)
|
||||
- added waterfalls to the savegame so that they now persist on load (#2686)
|
||||
- added support for aspect ratio-specific images (#1840)
|
||||
- added a guard to ensure the game always starts on a visible screen even after unplugging displays (#2819)
|
||||
- changed savegame files to be stored in the `saves` directory (#2087)
|
||||
- changed the default fog distance to 22 tiles cutting off at 30 tiles to match TR1X (#1622)
|
||||
- changed the number of static mesh slots from 50 to 256 (#2734)
|
||||
|
|
|
@ -138,10 +138,35 @@ static void M_SyncToWindow(void)
|
|||
width = 1280;
|
||||
height = 720;
|
||||
}
|
||||
if (x == -1 && y == -1) { // default config state
|
||||
const SHELL_SIZE display_size = Shell_GetCurrentDisplaySize();
|
||||
x = (display_size.w - width) / 2;
|
||||
y = (display_size.h - height) / 2;
|
||||
|
||||
// Handle default position
|
||||
if (x == -1 && y == -1) {
|
||||
SDL_DisplayMode display_mode;
|
||||
SDL_GetCurrentDisplayMode(0, &display_mode);
|
||||
x = (display_mode.w - width) / 2;
|
||||
y = (display_mode.h - height) / 2;
|
||||
} else {
|
||||
// Adjust window position if completely offscreen
|
||||
bool on_screen = false;
|
||||
const int32_t num_displays = SDL_GetNumVideoDisplays();
|
||||
for (int32_t i = 0; i < num_displays; i++) {
|
||||
SDL_Rect bounds;
|
||||
SDL_GetDisplayBounds(i, &bounds);
|
||||
if (x + width > bounds.x && x < bounds.x + bounds.w
|
||||
&& y + height > bounds.y && y < bounds.y + bounds.h) {
|
||||
on_screen = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!on_screen) {
|
||||
x = 0;
|
||||
y = 0;
|
||||
// Find the first display to reposition the window
|
||||
SDL_Rect bounds;
|
||||
SDL_GetDisplayBounds(0, &bounds);
|
||||
x = bounds.x + (bounds.w - width) / 2;
|
||||
y = bounds.y + (bounds.h - height) / 2;
|
||||
}
|
||||
}
|
||||
|
||||
SDL_SetWindowFullscreen(g_SDLWindow, 0);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue