mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 01:58:19 +00:00
Fix windows macro and split the resize events
This commit is contained in:
parent
ca07c0a92f
commit
69202fdc22
|
@ -309,7 +309,7 @@ static bool BackendInitGlew(EBackendType BackendType, int &GlewMajor, int &GlewM
|
|||
return true;
|
||||
}
|
||||
// Don't allow GL 3.3, if the driver doesn't support atleast OpenGL 4.5
|
||||
#ifndef CONF_PLATFORM_WINDOWS
|
||||
#ifndef CONF_FAMILY_WINDOWS
|
||||
if(GLEW_VERSION_4_4)
|
||||
{
|
||||
GlewMajor = 4;
|
||||
|
@ -726,17 +726,28 @@ void CGraphicsBackend_SDL_OpenGL::GetVideoModes(CVideoMode *pModes, int MaxModes
|
|||
void CGraphicsBackend_SDL_OpenGL::GetCurrentVideoMode(CVideoMode &CurMode, int HiDPIScale, int MaxWindowWidth, int MaxWindowHeight, int Screen)
|
||||
{
|
||||
SDL_DisplayMode DPMode;
|
||||
if(SDL_GetDesktopDisplayMode(Screen, &DPMode) < 0)
|
||||
// if "real" fullscreen, obtain the video mode for that
|
||||
if((SDL_GetWindowFlags(m_pWindow) & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN)
|
||||
{
|
||||
dbg_msg("gfx", "unable to get display mode: %s", SDL_GetError());
|
||||
if(SDL_GetCurrentDisplayMode(Screen, &DPMode))
|
||||
{
|
||||
dbg_msg("gfx", "unable to get display mode: %s", SDL_GetError());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
int Width = 0;
|
||||
int Height = 0;
|
||||
SDL_GL_GetDrawableSize(m_pWindow, &Width, &Height);
|
||||
DPMode.w = Width;
|
||||
DPMode.h = Height;
|
||||
if(SDL_GetDesktopDisplayMode(Screen, &DPMode) < 0)
|
||||
{
|
||||
dbg_msg("gfx", "unable to get display mode: %s", SDL_GetError());
|
||||
}
|
||||
else
|
||||
{
|
||||
int Width = 0;
|
||||
int Height = 0;
|
||||
SDL_GL_GetDrawableSize(m_pWindow, &Width, &Height);
|
||||
DPMode.w = Width;
|
||||
DPMode.h = Height;
|
||||
}
|
||||
}
|
||||
DisplayToVideoMode(&CurMode, &DPMode, HiDPIScale, DPMode.refresh_rate);
|
||||
}
|
||||
|
@ -1173,16 +1184,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, int RefreshRate)
|
||||
bool CGraphicsBackend_SDL_OpenGL::ResizeWindow(int w, int h, int RefreshRate)
|
||||
{
|
||||
// don't call resize events when the window is at fullscreen desktop
|
||||
if(!m_pWindow || (SDL_GetWindowFlags(m_pWindow) & SDL_WINDOW_FULLSCREEN_DESKTOP) == SDL_WINDOW_FULLSCREEN_DESKTOP)
|
||||
return;
|
||||
return false;
|
||||
|
||||
// if the window is at fullscreen use SDL_SetWindowDisplayMode instead, suggested by SDL
|
||||
if(SDL_GetWindowFlags(m_pWindow) & SDL_WINDOW_FULLSCREEN)
|
||||
{
|
||||
#ifdef CONF_PLATFORM_WINDOWS
|
||||
#ifdef CONF_FAMILY_WINDOWS
|
||||
// in windows make the window windowed mode first, this prevents strange window glitches (other games probably do something similar)
|
||||
SetWindowParams(0, 1);
|
||||
#endif
|
||||
|
@ -1193,11 +1204,12 @@ void CGraphicsBackend_SDL_OpenGL::ResizeWindow(int w, int h, int RefreshRate)
|
|||
SetMode.h = h;
|
||||
SetMode.refresh_rate = RefreshRate;
|
||||
SDL_SetWindowDisplayMode(m_pWindow, SDL_GetClosestDisplayMode(g_Config.m_GfxScreen, &SetMode, &ClosestMode));
|
||||
#ifdef CONF_PLATFORM_WINDOWS
|
||||
#ifdef CONF_FAMILY_WINDOWS
|
||||
// now change it back to fullscreen, this will restore the above set state, bcs SDL saves fullscreen modes appart from other video modes (as of SDL 2.0.16)
|
||||
// see implementation of SDL_SetWindowDisplayMode
|
||||
SetWindowParams(1, 0);
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1206,6 +1218,8 @@ void CGraphicsBackend_SDL_OpenGL::ResizeWindow(int w, int h, int RefreshRate)
|
|||
// remove maximize flag
|
||||
SDL_RestoreWindow(m_pWindow);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void CGraphicsBackend_SDL_OpenGL::GetViewportSize(int &w, int &h)
|
||||
|
|
|
@ -260,7 +260,7 @@ public:
|
|||
virtual int WindowActive();
|
||||
virtual int WindowOpen();
|
||||
virtual void SetWindowGrab(bool Grab);
|
||||
virtual void ResizeWindow(int w, int h, int RefreshRate);
|
||||
virtual bool ResizeWindow(int w, int h, int RefreshRate);
|
||||
virtual void GetViewportSize(int &w, int &h);
|
||||
virtual void NotifyWindow();
|
||||
|
||||
|
|
|
@ -2315,7 +2315,7 @@ void CGraphics_Threaded::SetWindowParams(int FullscreenMode, bool IsBorderless)
|
|||
m_pBackend->SetWindowParams(FullscreenMode, IsBorderless);
|
||||
CVideoMode CurMode;
|
||||
m_pBackend->GetCurrentVideoMode(CurMode, m_ScreenHiDPIScale, g_Config.m_GfxDesktopWidth, g_Config.m_GfxDesktopHeight, g_Config.m_GfxScreen);
|
||||
Resize(CurMode.m_WindowWidth, CurMode.m_WindowHeight, CurMode.m_RefreshRate, false, true);
|
||||
GotResized(CurMode.m_WindowWidth, CurMode.m_WindowHeight, CurMode.m_RefreshRate);
|
||||
}
|
||||
|
||||
bool CGraphics_Threaded::SetWindowScreen(int Index)
|
||||
|
@ -2344,56 +2344,68 @@ void CGraphics_Threaded::Move(int x, int y)
|
|||
m_ScreenHiDPIScale = m_ScreenWidth / (float)g_Config.m_GfxScreenWidth;
|
||||
}
|
||||
|
||||
void CGraphics_Threaded::Resize(int w, int h, int RefreshRate, bool SetWindowSize, bool ForceResizeEvent)
|
||||
void CGraphics_Threaded::Resize(int w, int h, int RefreshRate)
|
||||
{
|
||||
#if defined(CONF_VIDEORECORDER)
|
||||
if(IVideo::Current() && IVideo::Current()->IsRecording())
|
||||
return;
|
||||
#endif
|
||||
|
||||
if(!ForceResizeEvent && WindowWidth() == w && WindowHeight() == h && (RefreshRate != -1 && RefreshRate == m_ScreenRefreshRate))
|
||||
if(WindowWidth() == w && WindowHeight() == h && RefreshRate == m_ScreenRefreshRate)
|
||||
return;
|
||||
|
||||
// if the size is changed manually, only set the window resize, a window size changed event is triggered anyway
|
||||
if(SetWindowSize)
|
||||
if(m_pBackend->ResizeWindow(w, h, RefreshRate))
|
||||
{
|
||||
m_pBackend->ResizeWindow(w, h, RefreshRate);
|
||||
CVideoMode CurMode;
|
||||
m_pBackend->GetCurrentVideoMode(CurMode, m_ScreenHiDPIScale, g_Config.m_GfxDesktopWidth, g_Config.m_GfxDesktopHeight, g_Config.m_GfxScreen);
|
||||
GotResized(w, h, RefreshRate);
|
||||
}
|
||||
else
|
||||
}
|
||||
|
||||
void CGraphics_Threaded::GotResized(int w, int h, int RefreshRate)
|
||||
{
|
||||
#if defined(CONF_VIDEORECORDER)
|
||||
if(IVideo::Current() && IVideo::Current()->IsRecording())
|
||||
return;
|
||||
#endif
|
||||
|
||||
// if RefreshRate is -1 use the current config refresh rate
|
||||
if(RefreshRate == -1)
|
||||
RefreshRate = g_Config.m_GfxScreenRefreshRate;
|
||||
|
||||
// if the size change event is triggered, set all parameters and change the viewport
|
||||
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;
|
||||
|
||||
m_ScreenRefreshRate = RefreshRate;
|
||||
|
||||
g_Config.m_GfxScreenWidth = w;
|
||||
g_Config.m_GfxScreenHeight = h;
|
||||
g_Config.m_GfxScreenRefreshRate = m_ScreenRefreshRate;
|
||||
m_ScreenHiDPIScale = m_ScreenWidth / (float)g_Config.m_GfxScreenWidth;
|
||||
|
||||
CCommandBuffer::SCommand_Update_Viewport Cmd;
|
||||
Cmd.m_X = 0;
|
||||
Cmd.m_Y = 0;
|
||||
Cmd.m_Width = m_ScreenWidth;
|
||||
Cmd.m_Height = m_ScreenHeight;
|
||||
|
||||
if(!AddCmd(
|
||||
Cmd, [] { return true; }, "failed to add resize command"))
|
||||
{
|
||||
// if the size change event is triggered, set all parameters and change the viewport
|
||||
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;
|
||||
|
||||
m_ScreenRefreshRate = RefreshRate == -1 ? m_ScreenRefreshRate : RefreshRate;
|
||||
|
||||
g_Config.m_GfxScreenWidth = w;
|
||||
g_Config.m_GfxScreenHeight = h;
|
||||
g_Config.m_GfxScreenRefreshRate = m_ScreenRefreshRate;
|
||||
m_ScreenHiDPIScale = m_ScreenWidth / (float)g_Config.m_GfxScreenWidth;
|
||||
|
||||
CCommandBuffer::SCommand_Update_Viewport Cmd;
|
||||
Cmd.m_X = 0;
|
||||
Cmd.m_Y = 0;
|
||||
Cmd.m_Width = m_ScreenWidth;
|
||||
Cmd.m_Height = m_ScreenHeight;
|
||||
|
||||
if(!AddCmd(
|
||||
Cmd, [] { return true; }, "failed to add resize command"))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// kick the command buffer and wait
|
||||
KickCommandBuffer();
|
||||
WaitForIdle();
|
||||
|
||||
for(auto &ResizeListener : m_ResizeListeners)
|
||||
ResizeListener.m_pFunc(ResizeListener.m_pUser);
|
||||
return;
|
||||
}
|
||||
|
||||
// kick the command buffer and wait
|
||||
KickCommandBuffer();
|
||||
WaitForIdle();
|
||||
|
||||
for(auto &ResizeListener : m_ResizeListeners)
|
||||
ResizeListener.m_pFunc(ResizeListener.m_pUser);
|
||||
}
|
||||
|
||||
void CGraphics_Threaded::AddWindowResizeListener(WINDOW_RESIZE_FUNC pFunc, void *pUser)
|
||||
|
|
|
@ -676,7 +676,8 @@ public:
|
|||
virtual int WindowActive() = 0;
|
||||
virtual int WindowOpen() = 0;
|
||||
virtual void SetWindowGrab(bool Grab) = 0;
|
||||
virtual void ResizeWindow(int w, int h, int RefreshRate) = 0;
|
||||
// returns true, if the video mode changed
|
||||
virtual bool ResizeWindow(int w, int h, int RefreshRate) = 0;
|
||||
virtual void GetViewportSize(int &w, int &h) = 0;
|
||||
virtual void NotifyWindow() = 0;
|
||||
|
||||
|
@ -1168,7 +1169,8 @@ public:
|
|||
void SetWindowParams(int FullscreenMode, bool IsBorderless) override;
|
||||
bool SetWindowScreen(int Index) override;
|
||||
void Move(int x, int y) override;
|
||||
void Resize(int w, int h, int RefreshRate, bool SetWindowSize = false, bool ForceResizeEvent = false) override;
|
||||
void Resize(int w, int h, int RefreshRate) override;
|
||||
void GotResized(int w, int h, int RefreshRate) override;
|
||||
void AddWindowResizeListener(WINDOW_RESIZE_FUNC pFunc, void *pUser) override;
|
||||
int GetWindowScreen() override;
|
||||
|
||||
|
|
|
@ -150,7 +150,8 @@ public:
|
|||
void SetWindowParams(int FullscreenMode, bool IsBorderless) override{};
|
||||
bool SetWindowScreen(int Index) override { return false; };
|
||||
void Move(int x, int y) override{};
|
||||
void Resize(int w, int h, int RefreshRate, bool SetWindowSize = false, bool ForceResizeEvent = false) override{};
|
||||
void Resize(int w, int h, int RefreshRate) override{};
|
||||
void GotResized(int w, int h, int RefreshRate) override{};
|
||||
void AddWindowResizeListener(WINDOW_RESIZE_FUNC pFunc, void *pUser) override{};
|
||||
int GetWindowScreen() override { return 0; };
|
||||
|
||||
|
|
|
@ -364,7 +364,7 @@ int CInput::Update()
|
|||
break;
|
||||
// listen to size changes, this includes our manual changes and the ones by the window manager
|
||||
case SDL_WINDOWEVENT_SIZE_CHANGED:
|
||||
Graphics()->Resize(Event.window.data1, Event.window.data2, -1);
|
||||
Graphics()->GotResized(Event.window.data1, Event.window.data2, -1);
|
||||
break;
|
||||
case SDL_WINDOWEVENT_FOCUS_GAINED:
|
||||
if(m_InputGrabbed)
|
||||
|
|
|
@ -214,7 +214,8 @@ public:
|
|||
virtual bool SetVSync(bool State) = 0;
|
||||
virtual int GetWindowScreen() = 0;
|
||||
virtual void Move(int x, int y) = 0;
|
||||
virtual void Resize(int w, int h, int RefreshRate, bool SetWindowSize = false, bool ForceResizeEvent = false) = 0;
|
||||
virtual void Resize(int w, int h, int RefreshRate) = 0;
|
||||
virtual void GotResized(int w, int h, int RefreshRate) = 0;
|
||||
virtual void AddWindowResizeListener(WINDOW_RESIZE_FUNC pFunc, void *pUser) = 0;
|
||||
|
||||
virtual void WindowDestroyNtf(uint32_t WindowID) = 0;
|
||||
|
|
|
@ -1167,7 +1167,7 @@ void CMenus::RenderSettingsGraphics(CUIRect MainView)
|
|||
g_Config.m_GfxScreenWidth = s_aModes[NewSelected].m_WindowWidth;
|
||||
g_Config.m_GfxScreenHeight = s_aModes[NewSelected].m_WindowHeight;
|
||||
g_Config.m_GfxScreenRefreshRate = s_aModes[NewSelected].m_RefreshRate;
|
||||
Graphics()->Resize(g_Config.m_GfxScreenWidth, g_Config.m_GfxScreenHeight, g_Config.m_GfxScreenRefreshRate, true);
|
||||
Graphics()->Resize(g_Config.m_GfxScreenWidth, g_Config.m_GfxScreenHeight, g_Config.m_GfxScreenRefreshRate);
|
||||
}
|
||||
|
||||
// switches
|
||||
|
|
Loading…
Reference in a new issue