Minor improvements to #1315 and add getter of current window style

This commit is contained in:
Wojtek Figat
2023-08-21 23:33:33 +02:00
parent d432654a57
commit 50c85aec6d
6 changed files with 40 additions and 18 deletions

View File

@@ -135,32 +135,48 @@ void Screen::SetCursorLock(CursorLockMode mode)
CursorLock = mode;
}
GameWindowMode Screen::GetGameWindowMode()
{
GameWindowMode result = GameWindowMode::Windowed;
#if !USE_EDITOR
auto win = Engine::MainWindow;
if (win)
{
if (GetIsFullscreen() || win->IsFullscreen())
result = GameWindowMode::Fullscreen;
else if (win->GetSettings().HasBorder)
result = GameWindowMode::Windowed;
else if (win->GetClientPosition().IsZero() && win->GetSize() == Platform::GetDesktopSize())
result = GameWindowMode::FullscreenBorderless;
else
result = GameWindowMode::Borderless;
}
#endif
return result;
}
void Screen::SetGameWindowMode(GameWindowMode windowMode)
{
#if !USE_EDITOR
auto win = Engine::MainWindow;
if (!win)
return;
switch (windowMode)
{
case GameWindowMode::Windowed:
if (GetIsFullscreen())
SetIsFullscreen(false);
#if (PLATFORM_WINDOWS)
Engine::MainWindow->SetBorderless(false, false);
#endif
win->SetBorderless(false, false);
break;
case GameWindowMode::Fullscreen:
SetIsFullscreen(true);
break;
case GameWindowMode::Borderless:
#if (PLATFORM_WINDOWS)
Engine::MainWindow->SetBorderless(true, false);
#endif
win->SetBorderless(true, false);
break;
case GameWindowMode::FullscreenBorderless:
#if (PLATFORM_WINDOWS)
Engine::MainWindow->SetBorderless(true, true);
#endif
win->SetBorderless(true, true);
break;
default: ;
}
#endif
}

View File

@@ -82,6 +82,12 @@ DECLARE_SCRIPTING_TYPE_NO_SPAWN(Screen);
/// <param name="mode">The mode.</param>
API_PROPERTY() static void SetCursorLock(CursorLockMode mode);
/// <summary>
/// Gets the game window mode.
/// </summary>
/// <returns>The current window mode.</returns>
API_PROPERTY() static GameWindowMode GetGameWindowMode();
/// <summary>
/// Sets the game window mode.
/// </summary>

View File

@@ -449,8 +449,8 @@ public:
/// 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)
/// <param name="maximized">Whether or not to make the borderless window fullscreen (maximize to cover whole screen).</param>
API_FUNCTION() virtual void SetBorderless(bool isBorderless, bool maximized = false)
{
}

View File

@@ -260,7 +260,7 @@ void WindowsWindow::Maximize()
_isDuringMaximize = false;
}
void WindowsWindow::SetBorderless(bool isBorderless, bool fullscreen)
void WindowsWindow::SetBorderless(bool isBorderless, bool maximized)
{
ASSERT(HasHWND());
@@ -292,8 +292,7 @@ void WindowsWindow::SetBorderless(bool isBorderless, bool fullscreen)
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)
if (maximized)
{
ShowWindow(_handle, SW_SHOWMAXIMIZED);
}
@@ -312,13 +311,12 @@ void WindowsWindow::SetBorderless(bool isBorderless, bool fullscreen)
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)
if (maximized)
{
Maximize();
}
@@ -327,6 +325,7 @@ void WindowsWindow::SetBorderless(bool isBorderless, bool fullscreen)
ShowWindow(_handle, SW_SHOW);
}
}
CheckForWindowResize();
}

View File

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