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

This commit is contained in:
Chandler Cox
2023-08-14 18:11:05 -05:00
parent 09be2375f6
commit cfd11a7e77
5 changed files with 112 additions and 0 deletions

View File

@@ -445,6 +445,15 @@ public:
{
}
/// <summary>
/// Sets the window to be borderless or not and to be fullscreen.
/// </summary>
/// <param name="isBorderless">Whether or not to have borders on window.</param>
/// <param name="fullscreen">Whether or not to make the borderless window fullscreen.</param>
API_FUNCTION() virtual void SetBorderless(bool isBorderless, bool fullscreen)
{
}
/// <summary>
/// Restores the window state before minimizing or maximizing.
/// </summary>

View File

@@ -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());

View File

@@ -100,6 +100,7 @@ public:
void Hide() override;
void Minimize() override;
void Maximize() override;
void SetBorderless(bool isBorderless, bool fullscreen) override;
void Restore() override;
bool IsClosed() const override;
bool IsForegroundWindow() const override;