tr2/shell: center offscreen window on game launch
Some checks are pending
Run code linters / Run code linters (push) Waiting to run
Publish a pre-release / TR1 (Linux) (push) Waiting to run
Publish a pre-release / TR1 (Windows) (push) Waiting to run
Publish a pre-release / TR1 (Mac) (push) Waiting to run
Publish a pre-release / TR2 (Linux) (push) Waiting to run
Publish a pre-release / TR2 (Windows) (push) Waiting to run
Publish a pre-release / TR2 (Mac) (push) Waiting to run
Publish a pre-release / Create a prerelease (push) Blocked by required conditions

This commit is contained in:
Marcin Kurczewski 2025-04-22 23:26:07 +02:00
parent 169ee7603f
commit 69b08d55ca
2 changed files with 30 additions and 4 deletions

View file

@ -15,6 +15,7 @@
- added the current music track and timestamp to the savegame so they now persist on load (#2579) - 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 waterfalls to the savegame so that they now persist on load (#2686)
- added support for aspect ratio-specific images (#1840) - 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 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 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) - changed the number of static mesh slots from 50 to 256 (#2734)

View file

@ -138,10 +138,35 @@ static void M_SyncToWindow(void)
width = 1280; width = 1280;
height = 720; height = 720;
} }
if (x == -1 && y == -1) { // default config state
const SHELL_SIZE display_size = Shell_GetCurrentDisplaySize(); // Handle default position
x = (display_size.w - width) / 2; if (x == -1 && y == -1) {
y = (display_size.h - height) / 2; 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); SDL_SetWindowFullscreen(g_SDLWindow, 0);