From 354696afb7b3fbb2c9f9f706377238c0d1b24553 Mon Sep 17 00:00:00 2001 From: def Date: Fri, 29 Apr 2016 21:07:10 +0200 Subject: [PATCH] switch between fullscreen and windowed mode without restarting the client (by oy) --- src/engine/client/backend_sdl.cpp | 5 +++++ src/engine/client/backend_sdl.h | 1 + src/engine/client/graphics_threaded.cpp | 5 +++++ src/engine/client/graphics_threaded.h | 2 ++ src/engine/graphics.h | 2 ++ src/game/client/components/menus_settings.cpp | 11 +++++------ 6 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/engine/client/backend_sdl.cpp b/src/engine/client/backend_sdl.cpp index 0ce517907..89723ae41 100644 --- a/src/engine/client/backend_sdl.cpp +++ b/src/engine/client/backend_sdl.cpp @@ -696,6 +696,11 @@ void CGraphicsBackend_SDL_OpenGL::Maximize() // TODO: SDL } +bool CGraphicsBackend_SDL_OpenGL::Fullscreen(bool State) +{ + return SDL_SetWindowFullscreen(m_pWindow, State ? SDL_WINDOW_FULLSCREEN : 0) == 0; +} + int CGraphicsBackend_SDL_OpenGL::WindowActive() { return SDL_GetWindowFlags(m_pWindow)&SDL_WINDOW_INPUT_FOCUS; diff --git a/src/engine/client/backend_sdl.h b/src/engine/client/backend_sdl.h index 9ebb80255..796ecc188 100644 --- a/src/engine/client/backend_sdl.h +++ b/src/engine/client/backend_sdl.h @@ -188,6 +188,7 @@ public: virtual void Minimize(); virtual void Maximize(); + virtual bool Fullscreen(bool State); virtual int WindowActive(); virtual int WindowOpen(); virtual void SetWindowGrab(bool Grab); diff --git a/src/engine/client/graphics_threaded.cpp b/src/engine/client/graphics_threaded.cpp index 82dbd04ab..245277166 100644 --- a/src/engine/client/graphics_threaded.cpp +++ b/src/engine/client/graphics_threaded.cpp @@ -895,6 +895,11 @@ void CGraphics_Threaded::Maximize() m_pBackend->Maximize(); } +bool CGraphics_Threaded::Fullscreen(bool State) +{ + return m_pBackend->Fullscreen(State); +} + int CGraphics_Threaded::WindowActive() { return m_pBackend->WindowActive(); diff --git a/src/engine/client/graphics_threaded.h b/src/engine/client/graphics_threaded.h index bdfbd391f..5c94e92b1 100644 --- a/src/engine/client/graphics_threaded.h +++ b/src/engine/client/graphics_threaded.h @@ -311,6 +311,7 @@ public: virtual void Minimize() = 0; virtual void Maximize() = 0; + virtual bool Fullscreen(bool State) = 0; virtual int WindowActive() = 0; virtual int WindowOpen() = 0; virtual void SetWindowGrab(bool Grab) = 0; @@ -427,6 +428,7 @@ public: virtual void Minimize(); virtual void Maximize(); + virtual bool Fullscreen(bool State); virtual int WindowActive(); virtual int WindowOpen(); diff --git a/src/engine/graphics.h b/src/engine/graphics.h index f148b07ee..085f56f86 100644 --- a/src/engine/graphics.h +++ b/src/engine/graphics.h @@ -66,6 +66,8 @@ public: int ScreenHeight() const { return m_ScreenHeight; } float ScreenAspect() const { return (float)ScreenWidth()/(float)ScreenHeight(); } + virtual bool Fullscreen(bool State) = 0; + virtual void Clear(float r, float g, float b) = 0; virtual void ClipEnable(int x, int y, int w, int h) = 0; diff --git a/src/game/client/components/menus_settings.cpp b/src/game/client/components/menus_settings.cpp index 55331805d..1defaa477 100644 --- a/src/game/client/components/menus_settings.cpp +++ b/src/game/client/components/menus_settings.cpp @@ -802,7 +802,6 @@ void CMenus::RenderSettingsGraphics(CUIRect MainView) static int s_GfxScreenHeight = g_Config.m_GfxScreenHeight; static int s_GfxColorDepth = g_Config.m_GfxColorDepth; static int s_GfxBorderless = g_Config.m_GfxBorderless; - static int s_GfxFullscreen = g_Config.m_GfxFullscreen; static int s_GfxVsync = g_Config.m_GfxVsync; static int s_GfxFsaaSamples = g_Config.m_GfxFsaaSamples; static int s_GfxTextureQuality = g_Config.m_GfxTextureQuality; @@ -868,10 +867,11 @@ void CMenus::RenderSettingsGraphics(CUIRect MainView) MainView.HSplitTop(20.0f, &Button, &MainView); if(DoButton_CheckBox(&g_Config.m_GfxFullscreen, Localize("Fullscreen"), g_Config.m_GfxFullscreen, &Button)) { - g_Config.m_GfxFullscreen ^= 1; - if(g_Config.m_GfxFullscreen && g_Config.m_GfxBorderless) - g_Config.m_GfxBorderless = 0; - CheckSettings = true; + if(Graphics()->Fullscreen(g_Config.m_GfxFullscreen^1)) + { g_Config.m_GfxFullscreen ^= 1; + if(g_Config.m_GfxFullscreen && g_Config.m_GfxBorderless) + g_Config.m_GfxBorderless = 0; + } } MainView.HSplitTop(20.0f, &Button, &MainView); @@ -919,7 +919,6 @@ void CMenus::RenderSettingsGraphics(CUIRect MainView) s_GfxScreenHeight == g_Config.m_GfxScreenHeight && s_GfxColorDepth == g_Config.m_GfxColorDepth && s_GfxBorderless == g_Config.m_GfxBorderless && - s_GfxFullscreen == g_Config.m_GfxFullscreen && s_GfxVsync == g_Config.m_GfxVsync && s_GfxFsaaSamples == g_Config.m_GfxFsaaSamples && s_GfxTextureQuality == g_Config.m_GfxTextureQuality &&