Allow windows resizing

This commit is contained in:
Jupeyy 2020-12-12 12:58:59 +01:00
parent 5c7bc040e8
commit cafd1a4e8f
7 changed files with 35 additions and 29 deletions

View file

@ -3990,7 +3990,6 @@ void CCommandProcessorFragment_SDL::Cmd_VSync(const CCommandBuffer::SCommand_VSy
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);
}
@ -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());
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();
@ -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;
if(Flags & IGraphicsBackend::INITFLAG_HIGHDPI)
SdlFlags |= SDL_WINDOW_ALLOW_HIGHDPI;
#if defined(SDL_VIDEO_DRIVER_X11)
if(Flags & IGraphicsBackend::INITFLAG_RESIZABLE)
SdlFlags |= SDL_WINDOW_RESIZABLE;
#endif
if(Flags & IGraphicsBackend::INITFLAG_BORDERLESS)
SdlFlags |= SDL_WINDOW_BORDERLESS;
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(
pName,
SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED,
*pWidth,
*pHeight,
SdlFlags);
@ -4809,6 +4801,16 @@ void CGraphicsBackend_SDL_OpenGL::SetWindowGrab(bool Grab)
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()
{
// get window handle

View file

@ -518,6 +518,8 @@ public:
virtual int WindowActive();
virtual int WindowOpen();
virtual void SetWindowGrab(bool Grab);
virtual void ResizeWindow(int w, int h);
virtual void GetViewportSize(int &w, int &h);
virtual void NotifyWindow();
virtual bool IsNewOpenGL() { return m_UseNewOpenGL; }

View file

@ -2433,27 +2433,33 @@ bool CGraphics_Threaded::SetWindowScreen(int 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(IVideo::Current() && IVideo::Current()->IsRecording())
return;
#endif
if(m_ScreenWidth == w && m_ScreenHeight == h)
if(m_DesktopScreenWidth == w && m_DesktopScreenHeight == h)
return;
if(h > 4 * w / 5)
h = 4 * w / 5;
if(w > 21 * h / 9)
w = 21 * h / 9;
if(SetWindowSize)
m_pBackend->ResizeWindow(w, h);
m_ScreenWidth = w;
m_ScreenHeight = h;
m_DesktopScreenWidth = w;
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;
Cmd.m_Width = w;
Cmd.m_Height = h;
Cmd.m_Width = m_ScreenWidth;
Cmd.m_Height = m_ScreenHeight;
m_pCommandBuffer->AddCommand(Cmd);
// kick the command buffer

View file

@ -659,6 +659,8 @@ public:
virtual int WindowActive() = 0;
virtual int WindowOpen() = 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 RunBuffer(CCommandBuffer *pBuffer) = 0;
@ -1112,7 +1114,7 @@ public:
bool Fullscreen(bool State) override;
void SetWindowBordered(bool State) 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;
int GetWindowScreen() override;

View file

@ -327,9 +327,7 @@ int CInput::Update()
switch(Event.window.event)
{
case SDL_WINDOWEVENT_RESIZED:
#if defined(SDL_VIDEO_DRIVER_X11)
Graphics()->Resize(Event.window.data1, Event.window.data2);
#endif
break;
case SDL_WINDOWEVENT_FOCUS_GAINED:
if(m_InputGrabbed)

View file

@ -201,7 +201,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 Resize(int w, int h, bool SetWindowSize = false) = 0;
virtual void AddWindowResizeListener(WINDOW_RESIZE_FUNC pFunc, void *pUser) = 0;
virtual void Clear(float r, float g, float b) = 0;

View file

@ -1056,11 +1056,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;
#if defined(SDL_VIDEO_DRIVER_X11)
Graphics()->Resize(g_Config.m_GfxScreenWidth, g_Config.m_GfxScreenHeight);
#else
CheckSettings = true;
#endif
Graphics()->Resize(g_Config.m_GfxScreenWidth, g_Config.m_GfxScreenHeight, true);
}
// switches