Resize window without restarting client

This commit is contained in:
def 2016-04-30 17:59:58 +02:00
parent 74f4ad77d6
commit 644fec7e55
13 changed files with 73 additions and 25 deletions

View file

@ -459,6 +459,12 @@ void CCommandProcessorFragment_SDL::Cmd_VSync(const CCommandBuffer::SCommand_VSy
*pCommand->m_pRetOk = SDL_GL_SetSwapInterval(pCommand->m_VSync) == 0;
}
void CCommandProcessorFragment_SDL::Cmd_Resize(const CCommandBuffer::SCommand_Resize *pCommand)
{
SDL_SetWindowSize(m_pWindow, pCommand->m_Width, pCommand->m_Height);
glViewport(0, 0, pCommand->m_Width, pCommand->m_Height);
}
void CCommandProcessorFragment_SDL::Cmd_VideoModes(const CCommandBuffer::SCommand_VideoModes *pCommand)
{
SDL_DisplayMode mode;
@ -505,6 +511,7 @@ bool CCommandProcessorFragment_SDL::RunCommand(const CCommandBuffer::SCommand *p
{
case CCommandBuffer::CMD_SWAP: Cmd_Swap(static_cast<const CCommandBuffer::SCommand_Swap *>(pBaseCommand)); break;
case CCommandBuffer::CMD_VSYNC: Cmd_VSync(static_cast<const CCommandBuffer::SCommand_VSync *>(pBaseCommand)); break;
case CCommandBuffer::CMD_RESIZE: Cmd_Resize(static_cast<const CCommandBuffer::SCommand_Resize *>(pBaseCommand)); break;
case CCommandBuffer::CMD_VIDEOMODES: Cmd_VideoModes(static_cast<const CCommandBuffer::SCommand_VideoModes *>(pBaseCommand)); break;
case CMD_INIT: Cmd_Init(static_cast<const SCommand_Init *>(pBaseCommand)); break;
case CMD_SHUTDOWN: Cmd_Shutdown(static_cast<const SCommand_Shutdown *>(pBaseCommand)); break;

View file

@ -157,6 +157,7 @@ private:
void Cmd_Shutdown(const SCommand_Shutdown *pCommand);
void Cmd_Swap(const CCommandBuffer::SCommand_Swap *pCommand);
void Cmd_VSync(const CCommandBuffer::SCommand_VSync *pCommand);
void Cmd_Resize(const CCommandBuffer::SCommand_Resize *pCommand);
void Cmd_VideoModes(const CCommandBuffer::SCommand_VideoModes *pCommand);
public:
CCommandProcessorFragment_SDL();

View file

@ -786,7 +786,7 @@ int CGraphics_Threaded::IssueInit()
if(g_Config.m_GfxBorderless) Flags |= IGraphicsBackend::INITFLAG_BORDERLESS;
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;
if(g_Config.m_GfxResizable) Flags |= IGraphicsBackend::INITFLAG_RESIZABLE;
return m_pBackend->Init("DDNet Client", &g_Config.m_GfxScreen, &g_Config.m_GfxScreenWidth, &g_Config.m_GfxScreenHeight, g_Config.m_GfxFsaaSamples, Flags, &m_DesktopScreenWidth, &m_DesktopScreenHeight);
}
@ -910,6 +910,29 @@ bool CGraphics_Threaded::SetWindowScreen(int Index)
return m_pBackend->SetWindowScreen(Index);
}
void CGraphics_Threaded::Resize(int w, int h)
{
if(m_ScreenWidth == w && m_ScreenHeight == h)
return;
if(h > 4*w/5)
h = 4*w/5;
if(w > 21*h/9)
w = 21*h/9;
m_ScreenWidth = w;
m_ScreenHeight = h;
CCommandBuffer::SCommand_Resize Cmd;
Cmd.m_Width = w;
Cmd.m_Height = h;
m_pCommandBuffer->AddCommand(Cmd);
// kick the command buffer
KickCommandBuffer();
WaitForIdle();
}
int CGraphics_Threaded::GetWindowScreen()
{
return m_pBackend->GetWindowScreen();

View file

@ -85,6 +85,7 @@ public:
CMD_VSYNC,
CMD_SCREENSHOT,
CMD_VIDEOMODES,
CMD_RESIZE,
};
@ -215,6 +216,14 @@ public:
bool *m_pRetOk;
};
struct SCommand_Resize : public SCommand
{
SCommand_Resize() : SCommand(CMD_RESIZE) {}
int m_Width;
int m_Height;
};
struct SCommand_Texture_Create : public SCommand
{
SCommand_Texture_Create() : SCommand(CMD_TEXTURE_CREATE) {}
@ -446,6 +455,7 @@ public:
virtual bool Fullscreen(bool State);
virtual void SetWindowBordered(bool State);
virtual bool SetWindowScreen(int Index);
virtual void Resize(int w, int h);
virtual int GetWindowScreen();
virtual int WindowActive();

View file

@ -65,7 +65,7 @@ void CInput::MouseRelative(float *x, float *y)
*y = ny;
#else
int nx = 0, ny = 0;
float Sens = ((g_Config.m_ClDyncam && g_Config.m_ClDyncamMousesens) ? g_Config.m_ClDyncamMousesens : g_Config.m_InpMousesens) / 50.0f;
float Sens = ((g_Config.m_ClDyncam && g_Config.m_ClDyncamMousesens) ? g_Config.m_ClDyncamMousesens : g_Config.m_InpMousesens) / 100.0f;
SDL_GetRelativeMouseState(&nx,&ny);
@ -173,10 +173,9 @@ int CInput::Update()
switch (Event.type)
{
case SDL_TEXTINPUT:
{
if(!IgnoreKeys)
AddEvent(Event.text.text, 0, IInput::FLAG_TEXT);
break;
}
// handle keys
case SDL_KEYDOWN:
Key = KeycodeToKey(Event.key.keysym.sym);
@ -222,15 +221,24 @@ int CInput::Update()
case SDL_WINDOWEVENT:
// Ignore keys following a focus gain as they may be part of global
// shortcuts
if(Event.window.event == SDL_WINDOWEVENT_FOCUS_GAINED)
IgnoreKeys = true;
#if defined(CONF_PLATFORM_MACOSX) // Todo: remove this when fixed in SDL
if(Event.window.event == SDL_WINDOWEVENT_MAXIMIZED)
switch (Event.window.event)
{
case SDL_WINDOWEVENT_RESIZED:
case SDL_WINDOWEVENT_SIZE_CHANGED:
Graphics()->Resize(Event.window.data1, Event.window.data2);
break;
case SDL_WINDOWEVENT_FOCUS_GAINED:
case SDL_WINDOWEVENT_FOCUS_LOST:
// TODO: Check if from FOCUS_LOST til FOCUS_GAINED is good enough, maybe also ENTER and LEAVE
IgnoreKeys = true;
break;
#if defined(CONF_PLATFORM_MACOSX) // Todo: remove this when fixed in SDL
case SDL_WINDOWEVENT_MAXIMIZED:
MouseModeAbsolute();
MouseModeRelative();
}
break;
#endif
}
break;
// other messages

View file

@ -71,6 +71,7 @@ public:
virtual bool SetWindowScreen(int Index) = 0;
virtual bool SetVSync(bool State) = 0;
virtual int GetWindowScreen() = 0;
virtual void Resize(int w, int h) = 0;
virtual void Clear(float r, float g, float b) = 0;

View file

@ -102,6 +102,7 @@ MACRO_CONFIG_INT(GfxAlphabits, gfx_alphabits, 0, 0, 0, CFGFLAG_SAVE|CFGFLAG_CLIE
MACRO_CONFIG_INT(GfxColorDepth, gfx_color_depth, 24, 16, 24, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Colors bits for framebuffer (fullscreen only)")
//MACRO_CONFIG_INT(GfxClear, gfx_clear, 1, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Clear screen before rendering")
MACRO_CONFIG_INT(GfxVsync, gfx_vsync, 1, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Vertical sync")
MACRO_CONFIG_INT(GfxResizable, gfx_resizable, 1, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Enables window resizing")
MACRO_CONFIG_INT(GfxDisplayAllModes, gfx_display_all_modes, 0, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "")
MACRO_CONFIG_INT(GfxTextureCompression, gfx_texture_compression, 0, 0, 1, CFGFLAG_SAVE|CFGFLAG_CLIENT, "Use texture compression")
#if defined(__ANDROID__)
@ -167,7 +168,6 @@ MACRO_CONFIG_INT(DbgPref, dbg_pref, 0, 0, 1, CFGFLAG_SERVER, "Performance output
MACRO_CONFIG_INT(DbgGraphs, dbg_graphs, 0, 0, 1, CFGFLAG_CLIENT, "Performance graphs")
MACRO_CONFIG_INT(DbgHitch, dbg_hitch, 0, 0, 0, CFGFLAG_SERVER, "Hitch warnings")
MACRO_CONFIG_STR(DbgStressServer, dbg_stress_server, 32, "localhost", CFGFLAG_CLIENT, "Server to stress")
MACRO_CONFIG_INT(DbgResizable, dbg_resizable, 0, 0, 0, CFGFLAG_CLIENT, "Enables window resizing")
// DDRace
MACRO_CONFIG_STR(SvWelcome, sv_welcome, 64, "", CFGFLAG_SERVER, "Message that will be displayed to players who join the server")

View file

@ -488,7 +488,7 @@ bool CControls::OnMouseMove(float x, float y)
{
m_OldMouseX = x;
m_OldMouseY = y;
m_MousePos[g_Config.m_ClDummy] = vec2((x - g_Config.m_GfxScreenWidth/2), (y - g_Config.m_GfxScreenHeight/2));
m_MousePos[g_Config.m_ClDummy] = vec2((x - Graphics()->Width()/2), (y - Graphics()->Height()/2));
ClampMousePos();
}
#else

View file

@ -61,7 +61,7 @@ void CMenus::RenderServerbrowserServerList(CUIRect View)
COL_VERSION,
};
static CColumn s_aCols[] = {
CColumn s_aCols[] = {
{-1, -1, " ", -1, 2.0f, 0, {0}, {0}},
{COL_FLAG_LOCK, -1, " ", -1, 14.0f, 0, {0}, {0}},
{COL_FLAG_FAV, -1, " ", -1, 14.0f, 0, {0}, {0}},

View file

@ -850,7 +850,7 @@ void CMenus::RenderSettingsGraphics(CUIRect MainView)
g_Config.m_GfxColorDepth = Depth;
g_Config.m_GfxScreenWidth = s_aModes[NewSelected].m_Width;
g_Config.m_GfxScreenHeight = s_aModes[NewSelected].m_Height;
CheckSettings = true;
Graphics()->Resize(g_Config.m_GfxScreenWidth, g_Config.m_GfxScreenHeight);
}
// switches
@ -935,8 +935,6 @@ void CMenus::RenderSettingsGraphics(CUIRect MainView)
m_NeedRestartGraphics = true;
}
//
CUIRect Text;
MainView.HSplitTop(20.0f, 0, &MainView);
MainView.HSplitTop(20.0f, &Text, &MainView);

View file

@ -158,7 +158,7 @@ bool CSpectator::OnMouseMove(float x, float y)
{
m_OldMouseX = x;
m_OldMouseY = y;
m_SelectorMouse = vec2((x - g_Config.m_GfxScreenWidth/2), (y - g_Config.m_GfxScreenHeight/2));
m_SelectorMouse = vec2((x - Graphics()->ScreenWidth()/2), (y - Graphics()->ScreenHeight()/2));
}
#else
UI()->ConvertMouseMove(&x, &y);

View file

@ -335,7 +335,7 @@ void CRenderTools::RenderTeleOverlay(CTeleTile *pTele, int w, int h, float Scale
int EndY = (int)(ScreenY1/Scale)+1;
int EndX = (int)(ScreenX1/Scale)+1;
if(EndX - StartX > g_Config.m_GfxScreenWidth / g_Config.m_GfxTextOverlay || EndY - StartY > g_Config.m_GfxScreenHeight / g_Config.m_GfxTextOverlay)
if(EndX - StartX > Graphics()->ScreenWidth() / g_Config.m_GfxTextOverlay || EndY - StartY > Graphics()->ScreenHeight() / g_Config.m_GfxTextOverlay)
return; // its useless to render text at this distance
for(int y = StartY; y < EndY; y++)
@ -380,7 +380,7 @@ void CRenderTools::RenderSpeedupOverlay(CSpeedupTile *pSpeedup, int w, int h, fl
int EndY = (int)(ScreenY1/Scale)+1;
int EndX = (int)(ScreenX1/Scale)+1;
if(EndX - StartX > g_Config.m_GfxScreenWidth / g_Config.m_GfxTextOverlay || EndY - StartY > g_Config.m_GfxScreenHeight / g_Config.m_GfxTextOverlay)
if(EndX - StartX > Graphics()->ScreenWidth() / g_Config.m_GfxTextOverlay || EndY - StartY > Graphics()->ScreenHeight() / g_Config.m_GfxTextOverlay)
return; // its useless to render text at this distance
for(int y = StartY; y < EndY; y++)
@ -449,7 +449,7 @@ void CRenderTools::RenderSwitchOverlay(CSwitchTile *pSwitch, int w, int h, float
int EndY = (int)(ScreenY1/Scale)+1;
int EndX = (int)(ScreenX1/Scale)+1;
if(EndX - StartX > g_Config.m_GfxScreenWidth / g_Config.m_GfxTextOverlay || EndY - StartY > g_Config.m_GfxScreenHeight / g_Config.m_GfxTextOverlay)
if(EndX - StartX > Graphics()->ScreenWidth() / g_Config.m_GfxTextOverlay || EndY - StartY > Graphics()->ScreenHeight() / g_Config.m_GfxTextOverlay)
return; // its useless to render text at this distance
for(int y = StartY; y < EndY; y++)
@ -507,7 +507,7 @@ void CRenderTools::RenderTuneOverlay(CTuneTile *pTune, int w, int h, float Scale
int EndY = (int)(ScreenY1/Scale)+1;
int EndX = (int)(ScreenX1/Scale)+1;
if(EndX - StartX > g_Config.m_GfxScreenWidth / g_Config.m_GfxTextOverlay || EndY - StartY > g_Config.m_GfxScreenHeight / g_Config.m_GfxTextOverlay)
if(EndX - StartX > Graphics()->ScreenWidth() / g_Config.m_GfxTextOverlay || EndY - StartY > Graphics()->ScreenHeight() / g_Config.m_GfxTextOverlay)
return; // its useless to render text at this distance
for(int y = StartY; y < EndY; y++)

View file

@ -5524,8 +5524,8 @@ void CEditor::UpdateAndRender()
tx = s_MouseX;
ty = s_MouseY;
s_MouseX = (rx / (float)g_Config.m_GfxScreenWidth) * UI()->Screen()->w;
s_MouseY = (ry / (float)g_Config.m_GfxScreenHeight) * UI()->Screen()->h;
s_MouseX = (rx / (float)Graphics()->ScreenWidth()) * UI()->Screen()->w;
s_MouseY = (ry / (float)Graphics()->ScreenHeight()) * UI()->Screen()->h;
s_MouseX = clamp(s_MouseX, 0.0f, UI()->Screen()->w);
s_MouseY = clamp(s_MouseY, 0.0f, UI()->Screen()->h);