switch between bordered and and borderless window without restarting the client

This commit is contained in:
oy 2015-10-22 15:44:03 +02:00
parent 4691df2607
commit b27b7104ab
9 changed files with 39 additions and 22 deletions

View file

@ -88,6 +88,7 @@ public:
virtual void AutoScreenshot_Start() = 0;
virtual void ServerBrowserUpdate() = 0;
virtual void ToggleFullscreen() = 0;
virtual void ToggleWindowBordered() = 0;
// networking
virtual void EnterGame() = 0;

View file

@ -640,10 +640,6 @@ int CGraphicsBackend_SDL_OpenGL::Init(const char *pName, int Screen, int *pWidth
*pDesktopWidth = DisplayMode.w;
*pDesktopHeight = DisplayMode.h;
dbg_assert(!(Flags&IGraphicsBackend::INITFLAG_BORDERLESS)
|| !(Flags&IGraphicsBackend::INITFLAG_FULLSCREEN),
"only one of borderless and fullscreen may be activated at the same time");
// set flags
int SdlFlags = SDL_WINDOW_OPENGL;
if(Flags&IGraphicsBackend::INITFLAG_RESIZABLE)
@ -757,6 +753,11 @@ bool CGraphicsBackend_SDL_OpenGL::Fullscreen(bool State)
return SDL_SetWindowFullscreen(m_pWindow, State ? SDL_WINDOW_FULLSCREEN : 0) == 0;
}
void CGraphicsBackend_SDL_OpenGL::SetWindowBordered(bool State)
{
SDL_SetWindowBordered(m_pWindow, SDL_bool(State));
}
int CGraphicsBackend_SDL_OpenGL::WindowActive()
{
return SDL_GetWindowFlags(m_pWindow)&SDL_WINDOW_INPUT_FOCUS;

View file

@ -195,7 +195,8 @@ public:
virtual void Minimize();
virtual void Maximize();
virtual bool Fullscreen(bool State); // on=true/off=false
virtual bool Fullscreen(bool State); // on=true/off=false
virtual void SetWindowBordered(bool State); // on=true/off=false
virtual int WindowActive();
virtual int WindowOpen();
};

View file

@ -2211,11 +2211,7 @@ void CClient::ConchainServerBrowserUpdate(IConsole::IResult *pResult, void *pUse
void CClient::ToggleFullscreen()
{
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;
}
}
void CClient::ConchainFullscreen(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData)
@ -2230,6 +2226,24 @@ void CClient::ConchainFullscreen(IConsole::IResult *pResult, void *pUserData, IC
pfnCallback(pResult, pCallbackUserData);
}
void CClient::ToggleWindowBordered()
{
g_Config.m_GfxBorderless ^= 1;
Graphics()->SetWindowBordered(!g_Config.m_GfxBorderless);
}
void CClient::ConchainWindowBordered(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData)
{
CClient *pSelf = (CClient *)pUserData;
if(pSelf->Graphics() && pResult->NumArguments())
{
if(!g_Config.m_GfxFullscreen && (g_Config.m_GfxBorderless != pResult->GetInteger(0)))
pSelf->ToggleWindowBordered();
}
else
pfnCallback(pResult, pCallbackUserData);
}
void CClient::RegisterCommands()
{
m_pConsole = Kernel()->RequestInterface<IConsole>();
@ -2254,6 +2268,7 @@ void CClient::RegisterCommands()
m_pConsole->Chain("br_filter_serveraddress", ConchainServerBrowserUpdate, this);
m_pConsole->Chain("gfx_fullscreen", ConchainFullscreen, this);
m_pConsole->Chain("gfx_borderless", ConchainWindowBordered, this);
}
static CClient *CreateClient()

View file

@ -292,6 +292,7 @@ public:
static void Con_AddDemoMarker(IConsole::IResult *pResult, void *pUserData);
static void ConchainServerBrowserUpdate(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData);
static void ConchainFullscreen(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData);
static void ConchainWindowBordered(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData);
void RegisterCommands();
@ -308,5 +309,6 @@ public:
void ServerBrowserUpdate();
void ToggleFullscreen();
void ToggleWindowBordered();
};
#endif

View file

@ -707,14 +707,8 @@ void CGraphics_Threaded::QuadsText(float x, float y, float Size, const char *pTe
int CGraphics_Threaded::IssueInit()
{
int Flags = 0;
if(g_Config.m_GfxBorderless && g_Config.m_GfxFullscreen)
{
dbg_msg("gfx", "both borderless and fullscreen activated, disabling borderless");
g_Config.m_GfxBorderless = 0;
}
if(g_Config.m_GfxBorderless) Flags |= IGraphicsBackend::INITFLAG_BORDERLESS;
else if(g_Config.m_GfxFullscreen) Flags |= IGraphicsBackend::INITFLAG_FULLSCREEN;
if(g_Config.m_GfxFullscreen) Flags |= IGraphicsBackend::INITFLAG_FULLSCREEN;
if(g_Config.m_GfxVsync) Flags |= IGraphicsBackend::INITFLAG_VSYNC;
if(g_Config.m_DbgResizable) Flags |= IGraphicsBackend::INITFLAG_RESIZABLE;
@ -855,6 +849,11 @@ bool CGraphics_Threaded::Fullscreen(bool State)
return m_pBackend->Fullscreen(State);
}
void CGraphics_Threaded::SetWindowBordered(bool State)
{
m_pBackend->SetWindowBordered(State);
}
int CGraphics_Threaded::WindowActive()
{
return m_pBackend->WindowActive();

View file

@ -310,6 +310,7 @@ public:
virtual void Minimize() = 0;
virtual void Maximize() = 0;
virtual bool Fullscreen(bool State) = 0;
virtual void SetWindowBordered(bool State) = 0;
virtual int WindowActive() = 0;
virtual int WindowOpen() = 0;
@ -427,6 +428,7 @@ public:
virtual void Minimize();
virtual void Maximize();
virtual bool Fullscreen(bool State);
virtual void SetWindowBordered(bool State);
virtual int WindowActive();
virtual int WindowOpen();

View file

@ -197,6 +197,7 @@ public:
virtual void Shutdown() = 0;
virtual bool Fullscreen(bool State) = 0;
virtual void SetWindowBordered(bool State) = 0;
virtual void Minimize() = 0;
virtual void Maximize() = 0;

View file

@ -1166,7 +1166,6 @@ void CMenus::RenderSettingsGraphics(CUIRect MainView)
static int s_GfxScreenWidth = g_Config.m_GfxScreenWidth;
static int s_GfxScreenHeight = g_Config.m_GfxScreenHeight;
static int s_GfxBorderless = g_Config.m_GfxBorderless;
static int s_GfxVsync = g_Config.m_GfxVsync;
static int s_GfxFsaaSamples = g_Config.m_GfxFsaaSamples;
static int s_GfxTextureQuality = g_Config.m_GfxTextureQuality;
@ -1214,10 +1213,7 @@ void CMenus::RenderSettingsGraphics(CUIRect MainView)
Button.VSplitLeft(ButtonHeight, 0, &Button);
static int s_ButtonGfxBorderless = 0;
if(DoButton_CheckBox(&s_ButtonGfxBorderless, Localize("Borderless window"), g_Config.m_GfxBorderless, &Button))
{
g_Config.m_GfxBorderless ^= 1;
CheckSettings = true;
}
Client()->ToggleWindowBordered();
}
Screen.HSplitTop(Spacing, 0, &Screen);
@ -1467,7 +1463,6 @@ void CMenus::RenderSettingsGraphics(CUIRect MainView)
{
if(s_GfxScreenWidth == g_Config.m_GfxScreenWidth &&
s_GfxScreenHeight == g_Config.m_GfxScreenHeight &&
s_GfxBorderless == g_Config.m_GfxBorderless &&
s_GfxVsync == g_Config.m_GfxVsync &&
s_GfxFsaaSamples == g_Config.m_GfxFsaaSamples &&
s_GfxTextureQuality == g_Config.m_GfxTextureQuality &&