Only call onresize events if actual size changed

clearify difference between resize and window property change for resolution list
This commit is contained in:
Jupeyy 2023-02-25 15:15:16 +01:00
parent 36f8a69872
commit 9530077588
7 changed files with 50 additions and 29 deletions

View file

@ -2910,12 +2910,18 @@ int CGraphics_Threaded::GetNumScreens() const
void CGraphics_Threaded::Minimize()
{
m_pBackend->Minimize();
for(auto &PropChangedListener : m_vPropChangeListeners)
PropChangedListener();
}
void CGraphics_Threaded::Maximize()
{
// TODO: SDL
m_pBackend->Maximize();
for(auto &PropChangedListener : m_vPropChangeListeners)
PropChangedListener();
}
void CGraphics_Threaded::WarnPngliteIncompatibleImages(bool Warn)
@ -2929,6 +2935,9 @@ void CGraphics_Threaded::SetWindowParams(int FullscreenMode, bool IsBorderless,
CVideoMode CurMode;
m_pBackend->GetCurrentVideoMode(CurMode, m_ScreenHiDPIScale, g_Config.m_GfxDesktopWidth, g_Config.m_GfxDesktopHeight, g_Config.m_GfxScreen);
GotResized(CurMode.m_WindowWidth, CurMode.m_WindowHeight, CurMode.m_RefreshRate);
for(auto &PropChangedListener : m_vPropChangeListeners)
PropChangedListener();
}
bool CGraphics_Threaded::SetWindowScreen(int Index)
@ -2941,6 +2950,9 @@ bool CGraphics_Threaded::SetWindowScreen(int Index)
m_pBackend->GetViewportSize(m_ScreenWidth, m_ScreenHeight);
AdjustViewport(true);
m_ScreenHiDPIScale = m_ScreenWidth / (float)g_Config.m_GfxScreenWidth;
for(auto &PropChangedListener : m_vPropChangeListeners)
PropChangedListener();
return true;
}
@ -2957,6 +2969,9 @@ void CGraphics_Threaded::Move(int x, int y)
m_pBackend->GetViewportSize(m_ScreenWidth, m_ScreenHeight);
AdjustViewport(true);
m_ScreenHiDPIScale = m_ScreenWidth / (float)g_Config.m_GfxScreenWidth;
for(auto &PropChangedListener : m_vPropChangeListeners)
PropChangedListener();
}
void CGraphics_Threaded::Resize(int w, int h, int RefreshRate)
@ -2990,6 +3005,8 @@ void CGraphics_Threaded::GotResized(int w, int h, int RefreshRate)
RefreshRate = g_Config.m_GfxScreenRefreshRate;
// if the size change event is triggered, set all parameters and change the viewport
auto PrevCanvasWidth = m_ScreenWidth;
auto PrevCanvasHeight = m_ScreenHeight;
m_pBackend->GetViewportSize(m_ScreenWidth, m_ScreenHeight);
AdjustViewport(false);
@ -3007,13 +3024,21 @@ void CGraphics_Threaded::GotResized(int w, int h, int RefreshRate)
KickCommandBuffer();
WaitForIdle();
for(auto &ResizeListener : m_vResizeListeners)
ResizeListener.m_pFunc(ResizeListener.m_pUser);
if(PrevCanvasWidth != m_ScreenWidth || PrevCanvasHeight != m_ScreenHeight)
{
for(auto &ResizeListener : m_vResizeListeners)
ResizeListener();
}
}
void CGraphics_Threaded::AddWindowResizeListener(WINDOW_RESIZE_FUNC pFunc, void *pUser)
void CGraphics_Threaded::AddWindowResizeListener(WINDOW_RESIZE_FUNC pFunc)
{
m_vResizeListeners.emplace_back(pFunc, pUser);
m_vResizeListeners.emplace_back(pFunc);
}
void CGraphics_Threaded::AddWindowPropChangeListener(WINDOW_PROPS_CHANGED_FUNC pFunc)
{
m_vPropChangeListeners.emplace_back(pFunc);
}
int CGraphics_Threaded::GetWindowScreen()

View file

@ -878,14 +878,8 @@ class CGraphics_Threaded : public IEngineGraphics
std::vector<SQuadContainer> m_vQuadContainers;
int m_FirstFreeQuadContainer;
struct SWindowResizeListener
{
SWindowResizeListener(WINDOW_RESIZE_FUNC pFunc, void *pUser) :
m_pFunc(std::move(pFunc)), m_pUser(pUser) {}
WINDOW_RESIZE_FUNC m_pFunc;
void *m_pUser;
};
std::vector<SWindowResizeListener> m_vResizeListeners;
std::vector<WINDOW_RESIZE_FUNC> m_vResizeListeners;
std::vector<WINDOW_PROPS_CHANGED_FUNC> m_vPropChangeListeners;
void *AllocCommandBufferData(unsigned AllocSize);
@ -1268,7 +1262,8 @@ public:
void Resize(int w, int h, int RefreshRate) override;
void GotResized(int w, int h, int RefreshRate) override;
void UpdateViewport(int X, int Y, int W, int H, bool ByResize) override;
void AddWindowResizeListener(WINDOW_RESIZE_FUNC pFunc, void *pUser) override;
void AddWindowResizeListener(WINDOW_RESIZE_FUNC pFunc) override;
void AddWindowPropChangeListener(WINDOW_PROPS_CHANGED_FUNC pFunc) override;
int GetWindowScreen() override;
void WindowDestroyNtf(uint32_t WindowID) override;

View file

@ -199,7 +199,8 @@ struct STWGraphicGPU
typedef STWGraphicGPU TTWGraphicsGPUList;
typedef std::function<void(void *)> WINDOW_RESIZE_FUNC;
typedef std::function<void()> WINDOW_RESIZE_FUNC;
typedef std::function<void()> WINDOW_PROPS_CHANGED_FUNC;
namespace client_data7 {
struct CDataSprite; // NOLINT(bugprone-forward-declaration-namespace)
@ -261,7 +262,16 @@ public:
virtual void Resize(int w, int h, int RefreshRate) = 0;
virtual void GotResized(int w, int h, int RefreshRate) = 0;
virtual void UpdateViewport(int X, int Y, int W, int H, bool ByResize) = 0;
virtual void AddWindowResizeListener(WINDOW_RESIZE_FUNC pFunc, void *pUser) = 0;
/**
* Listens to a resize event of the canvas, which is usually caused by a window resize.
* Will only be triggered if the actual size changed.
*/
virtual void AddWindowResizeListener(WINDOW_RESIZE_FUNC pFunc) = 0;
/**
* Listens to various window property changes, such as minimize, maximize, move, fullscreen mode
*/
virtual void AddWindowPropChangeListener(WINDOW_PROPS_CHANGED_FUNC pFunc) = 0;
virtual void WindowDestroyNtf(uint32_t WindowID) = 0;
virtual void WindowCreateNtf(uint32_t WindowID) = 0;

View file

@ -1106,12 +1106,11 @@ void CGameConsole::OnInit()
m_pConsoleLogger = new CConsoleLogger(this);
Engine()->SetAdditionalLogger(std::unique_ptr<ILogger>(m_pConsoleLogger));
// add resize event
Graphics()->AddWindowResizeListener([this](void *) {
Graphics()->AddWindowResizeListener([this]() {
m_LocalConsole.ClearBacklogYOffsets();
m_RemoteConsole.ClearBacklogYOffsets();
m_HasSelection = false;
},
nullptr);
});
}
void CGameConsole::OnStateChange(int NewState, int OldState)

View file

@ -1508,10 +1508,9 @@ void CMenus::RenderSettingsGraphics(CUIRect MainView)
{
s_WasInit = true;
Graphics()->AddWindowResizeListener([&](void *pUser) {
Graphics()->AddWindowPropChangeListener([]() {
s_ModesReload = true;
},
this);
});
}
if(s_ModesReload || g_Config.m_GfxDisplayAllVideoModes != s_InitDisplayAllVideoModes)

View file

@ -225,7 +225,7 @@ void CGameClient::OnInit()
m_pGraphics = Kernel()->RequestInterface<IGraphics>();
m_pGraphics->AddWindowResizeListener(OnWindowResizeCB, this);
m_pGraphics->AddWindowResizeListener([this] { OnWindowResize(); });
// propagate pointers
m_UI.Init(Kernel());
@ -903,12 +903,6 @@ void CGameClient::OnWindowResize()
TextRender()->OnWindowResize();
}
void CGameClient::OnWindowResizeCB(void *pUser)
{
CGameClient *pClient = (CGameClient *)pUser;
pClient->OnWindowResize();
}
void CGameClient::OnLanguageChange()
{
UI()->OnLanguageChange();

View file

@ -474,7 +474,6 @@ public:
virtual void OnFlagGrab(int TeamID);
void OnWindowResize();
static void OnWindowResizeCB(void *pUser);
void OnLanguageChange();