Complement ToggleFullscreen and change ToggleBorderlessWindowed

This commit is contained in:
ubkp 2023-10-20 21:09:54 -03:00
parent f26c96db75
commit 75b8f38825

View File

@ -223,73 +223,46 @@ bool WindowShouldClose(void)
// Toggle fullscreen mode
void ToggleFullscreen(void)
{
if (!IsWindowState(FLAG_FULLSCREEN_MODE))
const int monitor = SDL_GetWindowDisplayIndex(platform.window);
const int monitorCount = SDL_GetNumVideoDisplays();
if ((monitor >= 0) && (monitor < monitorCount))
{
SDL_SetWindowFullscreen(platform.window, SDL_WINDOW_FULLSCREEN);
CORE.Window.flags |= FLAG_FULLSCREEN_MODE;
}
else
if ((CORE.Window.flags & FLAG_FULLSCREEN_MODE) > 0)
{
SDL_SetWindowFullscreen(platform.window, 0);
CORE.Window.flags &= ~FLAG_FULLSCREEN_MODE;
CORE.Window.fullscreen = false;
}
else
{
SDL_SetWindowFullscreen(platform.window, SDL_WINDOW_FULLSCREEN);
CORE.Window.flags |= FLAG_FULLSCREEN_MODE;
CORE.Window.fullscreen = true;
}
}
else TRACELOG(LOG_WARNING, "SDL: Failed to find selected monitor");
}
// Toggle borderless windowed mode
void ToggleBorderlessWindowed(void)
{
// Leave fullscreen before attempting to set borderless windowed mode and get screen position from it
bool wasOnFullscreen = false;
if (CORE.Window.fullscreen)
const int monitor = SDL_GetWindowDisplayIndex(platform.window);
const int monitorCount = SDL_GetNumVideoDisplays();
if ((monitor >= 0) && (monitor < monitorCount))
{
CORE.Window.previousPosition = CORE.Window.position;
ToggleFullscreen();
wasOnFullscreen = true;
}
if (!IsWindowState(FLAG_BORDERLESS_WINDOWED_MODE))
if ((CORE.Window.flags & FLAG_BORDERLESS_WINDOWED_MODE) > 0)
{
// Store the window's current position and size
SDL_GetWindowPosition(platform.window, &CORE.Window.previousPosition.x, &CORE.Window.previousPosition.y);
CORE.Window.previousScreen = CORE.Window.screen;
// Set screen position and size inside valid bounds
SDL_Rect displayBounds;
if (SDL_GetDisplayBounds(GetCurrentMonitor(), &displayBounds) == 0)
{
SDL_SetWindowPosition(platform.window, displayBounds.x, displayBounds.y);
SDL_SetWindowSize(platform.window, displayBounds.w, displayBounds.h);
}
// Set borderless mode and flag
SDL_SetWindowBordered(platform.window, SDL_FALSE);
CORE.Window.flags |= FLAG_WINDOW_UNDECORATED;
// Set topmost modes and flag
SDL_SetWindowAlwaysOnTop(platform.window, SDL_TRUE);
CORE.Window.flags |= FLAG_WINDOW_TOPMOST;
// Set borderless windowed flag
CORE.Window.flags |= FLAG_BORDERLESS_WINDOWED_MODE;
SDL_SetWindowFullscreen(platform.window, 0);
CORE.Window.flags &= ~FLAG_BORDERLESS_WINDOWED_MODE;
}
else
{
// Remove borderless mode and flag
SDL_SetWindowBordered(platform.window, SDL_TRUE);
CORE.Window.flags &= ~FLAG_WINDOW_UNDECORATED;
// Remove topmost modes and flag
SDL_SetWindowAlwaysOnTop(platform.window, SDL_FALSE);
CORE.Window.flags &= ~FLAG_WINDOW_TOPMOST;
// Restore the window's previous size and position
SDL_SetWindowSize(platform.window, CORE.Window.previousScreen.width, CORE.Window.previousScreen.height);
SDL_SetWindowPosition(platform.window, CORE.Window.previousPosition.x, CORE.Window.previousPosition.y);
// Remove borderless windowed flag
CORE.Window.flags &= ~FLAG_BORDERLESS_WINDOWED_MODE;
SDL_SetWindowFullscreen(platform.window, SDL_WINDOW_FULLSCREEN_DESKTOP);
CORE.Window.flags |= FLAG_BORDERLESS_WINDOWED_MODE;
}
}
else TRACELOG(LOG_WARNING, "SDL: Failed to find selected monitor");
}
// Set window state: maximized, if resizable
void MaximizeWindow(void)