mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
Allow windows resizing
This commit is contained in:
parent
5c7bc040e8
commit
cafd1a4e8f
|
@ -3990,7 +3990,6 @@ void CCommandProcessorFragment_SDL::Cmd_VSync(const CCommandBuffer::SCommand_VSy
|
||||||
|
|
||||||
void CCommandProcessorFragment_SDL::Cmd_Resize(const CCommandBuffer::SCommand_Resize *pCommand)
|
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);
|
glViewport(0, 0, pCommand->m_Width, pCommand->m_Height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4333,11 +4332,6 @@ int CGraphicsBackend_SDL_OpenGL::Init(const char *pName, int *Screen, int *pWidt
|
||||||
dbg_msg("gfx", "unable to init SDL video: %s", SDL_GetError());
|
dbg_msg("gfx", "unable to init SDL video: %s", SDL_GetError());
|
||||||
return EGraphicsBackendErrorCodes::GRAPHICS_BACKEND_ERROR_CODE_SDL_INIT_FAILED;
|
return EGraphicsBackendErrorCodes::GRAPHICS_BACKEND_ERROR_CODE_SDL_INIT_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CONF_FAMILY_WINDOWS
|
|
||||||
if(!getenv("SDL_VIDEO_WINDOW_POS") && !getenv("SDL_VIDEO_CENTERED")) // ignore_convention
|
|
||||||
putenv("SDL_VIDEO_WINDOW_POS=center"); // ignore_convention
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_ClearError();
|
SDL_ClearError();
|
||||||
|
@ -4491,10 +4485,8 @@ int CGraphicsBackend_SDL_OpenGL::Init(const char *pName, int *Screen, int *pWidt
|
||||||
int SdlFlags = SDL_WINDOW_OPENGL | SDL_WINDOW_INPUT_GRABBED | SDL_WINDOW_INPUT_FOCUS | SDL_WINDOW_MOUSE_FOCUS;
|
int SdlFlags = SDL_WINDOW_OPENGL | SDL_WINDOW_INPUT_GRABBED | SDL_WINDOW_INPUT_FOCUS | SDL_WINDOW_MOUSE_FOCUS;
|
||||||
if(Flags & IGraphicsBackend::INITFLAG_HIGHDPI)
|
if(Flags & IGraphicsBackend::INITFLAG_HIGHDPI)
|
||||||
SdlFlags |= SDL_WINDOW_ALLOW_HIGHDPI;
|
SdlFlags |= SDL_WINDOW_ALLOW_HIGHDPI;
|
||||||
#if defined(SDL_VIDEO_DRIVER_X11)
|
|
||||||
if(Flags & IGraphicsBackend::INITFLAG_RESIZABLE)
|
if(Flags & IGraphicsBackend::INITFLAG_RESIZABLE)
|
||||||
SdlFlags |= SDL_WINDOW_RESIZABLE;
|
SdlFlags |= SDL_WINDOW_RESIZABLE;
|
||||||
#endif
|
|
||||||
if(Flags & IGraphicsBackend::INITFLAG_BORDERLESS)
|
if(Flags & IGraphicsBackend::INITFLAG_BORDERLESS)
|
||||||
SdlFlags |= SDL_WINDOW_BORDERLESS;
|
SdlFlags |= SDL_WINDOW_BORDERLESS;
|
||||||
if(Flags & IGraphicsBackend::INITFLAG_FULLSCREEN)
|
if(Flags & IGraphicsBackend::INITFLAG_FULLSCREEN)
|
||||||
|
@ -4542,8 +4534,8 @@ int CGraphicsBackend_SDL_OpenGL::Init(const char *pName, int *Screen, int *pWidt
|
||||||
|
|
||||||
m_pWindow = SDL_CreateWindow(
|
m_pWindow = SDL_CreateWindow(
|
||||||
pName,
|
pName,
|
||||||
SDL_WINDOWPOS_UNDEFINED,
|
SDL_WINDOWPOS_CENTERED,
|
||||||
SDL_WINDOWPOS_UNDEFINED,
|
SDL_WINDOWPOS_CENTERED,
|
||||||
*pWidth,
|
*pWidth,
|
||||||
*pHeight,
|
*pHeight,
|
||||||
SdlFlags);
|
SdlFlags);
|
||||||
|
@ -4809,6 +4801,16 @@ void CGraphicsBackend_SDL_OpenGL::SetWindowGrab(bool Grab)
|
||||||
SDL_SetWindowGrab(m_pWindow, Grab ? SDL_TRUE : SDL_FALSE);
|
SDL_SetWindowGrab(m_pWindow, Grab ? SDL_TRUE : SDL_FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CGraphicsBackend_SDL_OpenGL::ResizeWindow(int w, int h)
|
||||||
|
{
|
||||||
|
SDL_SetWindowSize(m_pWindow, w, h);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CGraphicsBackend_SDL_OpenGL::GetViewportSize(int &w, int &h)
|
||||||
|
{
|
||||||
|
SDL_GL_GetDrawableSize(m_pWindow, &w, &h);
|
||||||
|
}
|
||||||
|
|
||||||
void CGraphicsBackend_SDL_OpenGL::NotifyWindow()
|
void CGraphicsBackend_SDL_OpenGL::NotifyWindow()
|
||||||
{
|
{
|
||||||
// get window handle
|
// get window handle
|
||||||
|
|
|
@ -518,6 +518,8 @@ public:
|
||||||
virtual int WindowActive();
|
virtual int WindowActive();
|
||||||
virtual int WindowOpen();
|
virtual int WindowOpen();
|
||||||
virtual void SetWindowGrab(bool Grab);
|
virtual void SetWindowGrab(bool Grab);
|
||||||
|
virtual void ResizeWindow(int w, int h);
|
||||||
|
virtual void GetViewportSize(int &w, int &h);
|
||||||
virtual void NotifyWindow();
|
virtual void NotifyWindow();
|
||||||
|
|
||||||
virtual bool IsNewOpenGL() { return m_UseNewOpenGL; }
|
virtual bool IsNewOpenGL() { return m_UseNewOpenGL; }
|
||||||
|
|
|
@ -2433,27 +2433,33 @@ bool CGraphics_Threaded::SetWindowScreen(int Index)
|
||||||
return m_pBackend->SetWindowScreen(Index);
|
return m_pBackend->SetWindowScreen(Index);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CGraphics_Threaded::Resize(int w, int h)
|
void CGraphics_Threaded::Resize(int w, int h, bool SetWindowSize)
|
||||||
{
|
{
|
||||||
#if defined(CONF_VIDEORECORDER)
|
#if defined(CONF_VIDEORECORDER)
|
||||||
if(IVideo::Current() && IVideo::Current()->IsRecording())
|
if(IVideo::Current() && IVideo::Current()->IsRecording())
|
||||||
return;
|
return;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if(m_ScreenWidth == w && m_ScreenHeight == h)
|
if(m_DesktopScreenWidth == w && m_DesktopScreenHeight == h)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(h > 4 * w / 5)
|
if(SetWindowSize)
|
||||||
h = 4 * w / 5;
|
m_pBackend->ResizeWindow(w, h);
|
||||||
if(w > 21 * h / 9)
|
|
||||||
w = 21 * h / 9;
|
|
||||||
|
|
||||||
m_ScreenWidth = w;
|
m_DesktopScreenWidth = w;
|
||||||
m_ScreenHeight = h;
|
m_DesktopScreenHeight = h;
|
||||||
|
|
||||||
|
m_pBackend->GetViewportSize(m_ScreenWidth, m_ScreenHeight);
|
||||||
|
|
||||||
|
// adjust the viewport to only allow certain aspect ratios
|
||||||
|
if(m_ScreenHeight > 4 * m_ScreenWidth / 5)
|
||||||
|
m_ScreenHeight = 4 * m_ScreenWidth / 5;
|
||||||
|
if(m_ScreenWidth > 21 * m_ScreenHeight / 9)
|
||||||
|
m_ScreenWidth = 21 * m_ScreenHeight / 9;
|
||||||
|
|
||||||
CCommandBuffer::SCommand_Resize Cmd;
|
CCommandBuffer::SCommand_Resize Cmd;
|
||||||
Cmd.m_Width = w;
|
Cmd.m_Width = m_ScreenWidth;
|
||||||
Cmd.m_Height = h;
|
Cmd.m_Height = m_ScreenHeight;
|
||||||
m_pCommandBuffer->AddCommand(Cmd);
|
m_pCommandBuffer->AddCommand(Cmd);
|
||||||
|
|
||||||
// kick the command buffer
|
// kick the command buffer
|
||||||
|
|
|
@ -659,6 +659,8 @@ public:
|
||||||
virtual int WindowActive() = 0;
|
virtual int WindowActive() = 0;
|
||||||
virtual int WindowOpen() = 0;
|
virtual int WindowOpen() = 0;
|
||||||
virtual void SetWindowGrab(bool Grab) = 0;
|
virtual void SetWindowGrab(bool Grab) = 0;
|
||||||
|
virtual void ResizeWindow(int w, int h) = 0;
|
||||||
|
virtual void GetViewportSize(int &w, int &h) = 0;
|
||||||
virtual void NotifyWindow() = 0;
|
virtual void NotifyWindow() = 0;
|
||||||
|
|
||||||
virtual void RunBuffer(CCommandBuffer *pBuffer) = 0;
|
virtual void RunBuffer(CCommandBuffer *pBuffer) = 0;
|
||||||
|
@ -1112,7 +1114,7 @@ public:
|
||||||
bool Fullscreen(bool State) override;
|
bool Fullscreen(bool State) override;
|
||||||
void SetWindowBordered(bool State) override;
|
void SetWindowBordered(bool State) override;
|
||||||
bool SetWindowScreen(int Index) override;
|
bool SetWindowScreen(int Index) override;
|
||||||
void Resize(int w, int h) override;
|
void Resize(int w, int h, bool SetWindowSize = false) override;
|
||||||
void AddWindowResizeListener(WINDOW_RESIZE_FUNC pFunc, void *pUser) override;
|
void AddWindowResizeListener(WINDOW_RESIZE_FUNC pFunc, void *pUser) override;
|
||||||
int GetWindowScreen() override;
|
int GetWindowScreen() override;
|
||||||
|
|
||||||
|
|
|
@ -327,9 +327,7 @@ int CInput::Update()
|
||||||
switch(Event.window.event)
|
switch(Event.window.event)
|
||||||
{
|
{
|
||||||
case SDL_WINDOWEVENT_RESIZED:
|
case SDL_WINDOWEVENT_RESIZED:
|
||||||
#if defined(SDL_VIDEO_DRIVER_X11)
|
|
||||||
Graphics()->Resize(Event.window.data1, Event.window.data2);
|
Graphics()->Resize(Event.window.data1, Event.window.data2);
|
||||||
#endif
|
|
||||||
break;
|
break;
|
||||||
case SDL_WINDOWEVENT_FOCUS_GAINED:
|
case SDL_WINDOWEVENT_FOCUS_GAINED:
|
||||||
if(m_InputGrabbed)
|
if(m_InputGrabbed)
|
||||||
|
|
|
@ -201,7 +201,7 @@ public:
|
||||||
virtual bool SetWindowScreen(int Index) = 0;
|
virtual bool SetWindowScreen(int Index) = 0;
|
||||||
virtual bool SetVSync(bool State) = 0;
|
virtual bool SetVSync(bool State) = 0;
|
||||||
virtual int GetWindowScreen() = 0;
|
virtual int GetWindowScreen() = 0;
|
||||||
virtual void Resize(int w, int h) = 0;
|
virtual void Resize(int w, int h, bool SetWindowSize = false) = 0;
|
||||||
virtual void AddWindowResizeListener(WINDOW_RESIZE_FUNC pFunc, void *pUser) = 0;
|
virtual void AddWindowResizeListener(WINDOW_RESIZE_FUNC pFunc, void *pUser) = 0;
|
||||||
|
|
||||||
virtual void Clear(float r, float g, float b) = 0;
|
virtual void Clear(float r, float g, float b) = 0;
|
||||||
|
|
|
@ -1056,11 +1056,7 @@ void CMenus::RenderSettingsGraphics(CUIRect MainView)
|
||||||
g_Config.m_GfxColorDepth = Depth;
|
g_Config.m_GfxColorDepth = Depth;
|
||||||
g_Config.m_GfxScreenWidth = s_aModes[NewSelected].m_Width;
|
g_Config.m_GfxScreenWidth = s_aModes[NewSelected].m_Width;
|
||||||
g_Config.m_GfxScreenHeight = s_aModes[NewSelected].m_Height;
|
g_Config.m_GfxScreenHeight = s_aModes[NewSelected].m_Height;
|
||||||
#if defined(SDL_VIDEO_DRIVER_X11)
|
Graphics()->Resize(g_Config.m_GfxScreenWidth, g_Config.m_GfxScreenHeight, true);
|
||||||
Graphics()->Resize(g_Config.m_GfxScreenWidth, g_Config.m_GfxScreenHeight);
|
|
||||||
#else
|
|
||||||
CheckSettings = true;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// switches
|
// switches
|
||||||
|
|
Loading…
Reference in a new issue