Add borderless window on Windows platform and add easy function in Screen class to change window mode.

This commit is contained in:
2023-08-14 18:11:05 -05:00
parent 09be2375f6
commit cfd11a7e77
5 changed files with 112 additions and 0 deletions
@@ -260,6 +260,76 @@ void WindowsWindow::Maximize()
_isDuringMaximize = false;
}
void WindowsWindow::SetBorderless(bool isBorderless, bool fullscreen)
{
ASSERT(HasHWND());
if (IsFullscreen())
SetIsFullscreen(false);
// Fixes issue of borderless window not going full screen
if (IsMaximized())
Restore();
_settings.HasBorder = !isBorderless;
BringToFront();
if (isBorderless)
{
LONG lStyle = GetWindowLong(_handle, GWL_STYLE);
lStyle &= ~(WS_THICKFRAME | WS_SYSMENU | WS_OVERLAPPED | WS_BORDER | WS_CAPTION);
lStyle |= WS_POPUP;
lStyle |= WS_CLIPCHILDREN | WS_CLIPSIBLINGS;
#if WINDOWS_USE_NEW_BORDER_LESS
if (_settings.IsRegularWindow)
style |= WS_BORDER | WS_CAPTION | WS_DLGFRAME | WS_SYSMENU | WS_THICKFRAME | WS_GROUP;
#elif WINDOWS_USE_NEWER_BORDER_LESS
if (_settings.IsRegularWindow)
lStyle |= WS_THICKFRAME | WS_SYSMENU;
#endif
SetWindowLong(_handle, GWL_STYLE, lStyle);
SetWindowPos(_handle, HWND_TOP, 0, 0,0, 0, SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
if (fullscreen)
{
ShowWindow(_handle, SW_SHOWMAXIMIZED);
}
else
{
ShowWindow(_handle, SW_SHOW);
}
}
else
{
LONG lStyle = GetWindowLong(_handle, GWL_STYLE);
lStyle &= ~(WS_POPUP | WS_CLIPCHILDREN | WS_CLIPSIBLINGS);
if (_settings.AllowMaximize)
lStyle |= WS_MAXIMIZEBOX;
if (_settings.AllowMinimize)
lStyle |= WS_MINIMIZEBOX;
if (_settings.HasSizingFrame)
lStyle |= WS_THICKFRAME;
// Create window style flags
lStyle |= WS_OVERLAPPED | WS_SYSMENU | WS_BORDER | WS_CAPTION;
SetWindowLong(_handle, GWL_STYLE, lStyle);
SetWindowPos(_handle, nullptr, 0, 0, (int)_settings.Size.X, (int)_settings.Size.Y, SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
if (fullscreen)
{
Maximize();
}
else
{
ShowWindow(_handle, SW_SHOW);
}
}
CheckForWindowResize();
}
void WindowsWindow::Restore()
{
ASSERT(HasHWND());