switch screen without restarting the client

This commit is contained in:
oy 2015-10-22 19:51:53 +02:00
parent 444b605d88
commit 0b29a42e2b
8 changed files with 53 additions and 3 deletions

View file

@ -87,6 +87,9 @@ public:
virtual void RecordGameMessage(bool State) = 0;
virtual void AutoScreenshot_Start() = 0;
virtual void ServerBrowserUpdate() = 0;
// gfx
virtual void SwitchWindowScreen(int Index) = 0;
virtual void ToggleFullscreen() = 0;
virtual void ToggleWindowBordered() = 0;
virtual void ToggleWindowVSync() = 0;

View file

@ -641,12 +641,12 @@ int CGraphicsBackend_SDL_OpenGL::Init(const char *pName, int *Screen, int *pWidt
int NumScreens = SDL_GetNumVideoDisplays();
if(NumScreens > 0)
{
clamp(*Screen, 0, NumScreens);
if(SDL_GetDisplayBounds(*Screen, &ScreenPos) != 0)
clamp(*Screen, 0, NumScreens-1);
if(SDL_GetDisplayBounds(*Screen, &ScreenPos) != 0)
{
dbg_msg("gfx", "unable to retrieve screen information: %s", SDL_GetError());
return -1;
}
}
}
else
@ -783,6 +783,22 @@ void CGraphicsBackend_SDL_OpenGL::SetWindowBordered(bool State)
SDL_SetWindowBordered(m_pWindow, SDL_bool(State));
}
bool CGraphicsBackend_SDL_OpenGL::SetWindowScreen(int Index)
{
int NumScreens = SDL_GetNumVideoDisplays();
if(Index >= 0 && Index < NumScreens)
{
SDL_Rect ScreenPos;
if(SDL_GetDisplayBounds(Index, &ScreenPos) == 0)
{
SDL_SetWindowPosition(m_pWindow, ScreenPos.x, ScreenPos.y);
return true;
}
}
return false;
}
int CGraphicsBackend_SDL_OpenGL::WindowActive()
{
return SDL_GetWindowFlags(m_pWindow)&SDL_WINDOW_INPUT_FOCUS;

View file

@ -198,6 +198,7 @@ public:
virtual void Maximize();
virtual bool Fullscreen(bool State); // on=true/off=false
virtual void SetWindowBordered(bool State); // on=true/off=false
virtual bool SetWindowScreen(int Index);
virtual int WindowActive();
virtual int WindowOpen();
};

View file

@ -2208,6 +2208,24 @@ void CClient::ConchainServerBrowserUpdate(IConsole::IResult *pResult, void *pUse
((CClient *)pUserData)->ServerBrowserUpdate();
}
void CClient::SwitchWindowScreen(int Index)
{
if(Graphics()->SetWindowScreen(Index))
g_Config.m_GfxScreen = Index;
}
void CClient::ConchainWindowScreen(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData)
{
CClient *pSelf = (CClient *)pUserData;
if(pSelf->Graphics() && pResult->NumArguments())
{
if(g_Config.m_GfxScreen != pResult->GetInteger(0))
pSelf->SwitchWindowScreen(pResult->GetInteger(0));
}
else
pfnCallback(pResult, pCallbackUserData);
}
void CClient::ToggleFullscreen()
{
if(Graphics()->Fullscreen(g_Config.m_GfxFullscreen^1))
@ -2285,6 +2303,7 @@ void CClient::RegisterCommands()
m_pConsole->Chain("br_filter_gametype", ConchainServerBrowserUpdate, this);
m_pConsole->Chain("br_filter_serveraddress", ConchainServerBrowserUpdate, this);
m_pConsole->Chain("gfx_screen", ConchainWindowScreen, this);
m_pConsole->Chain("gfx_fullscreen", ConchainFullscreen, this);
m_pConsole->Chain("gfx_borderless", ConchainWindowBordered, this);
m_pConsole->Chain("gfx_vsync", ConchainWindowVSync, this);

View file

@ -293,6 +293,7 @@ public:
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);
static void ConchainWindowScreen(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData);
static void ConchainWindowVSync(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData);
void RegisterCommands();
@ -309,6 +310,8 @@ public:
void ServerBrowserUpdate();
// gfx
void SwitchWindowScreen(int Index);
void ToggleFullscreen();
void ToggleWindowBordered();
void ToggleWindowVSync();

View file

@ -853,6 +853,11 @@ void CGraphics_Threaded::SetWindowBordered(bool State)
m_pBackend->SetWindowBordered(State);
}
bool CGraphics_Threaded::SetWindowScreen(int Index)
{
return m_pBackend->SetWindowScreen(Index);
}
int CGraphics_Threaded::WindowActive()
{
return m_pBackend->WindowActive();

View file

@ -319,6 +319,7 @@ public:
virtual void Maximize() = 0;
virtual bool Fullscreen(bool State) = 0;
virtual void SetWindowBordered(bool State) = 0;
virtual bool SetWindowScreen(int Index) = 0;
virtual int WindowActive() = 0;
virtual int WindowOpen() = 0;
@ -437,6 +438,7 @@ public:
virtual void Maximize();
virtual bool Fullscreen(bool State);
virtual void SetWindowBordered(bool State);
virtual bool SetWindowScreen(int Index);
virtual int WindowActive();
virtual int WindowOpen();

View file

@ -199,6 +199,7 @@ public:
virtual bool Fullscreen(bool State) = 0;
virtual void SetWindowBordered(bool State) = 0;
virtual bool SetWindowScreen(int Index) = 0;
virtual void Minimize() = 0;
virtual void Maximize() = 0;