Move OnWindowResize listener to engine, handle editor

Register the `OnWindowResize` listener in the engine client instead of the game client and properly dispatch the event also to the editor, so text containers in the editor are cleared when the window is resized.

Closes #7018.
This commit is contained in:
Robert Müller 2023-08-15 19:39:22 +02:00
parent 5567c56d3a
commit 7168fb15d2
8 changed files with 30 additions and 15 deletions

View file

@ -181,6 +181,7 @@ public:
virtual void SetWindowParams(int FullscreenMode, bool IsBorderless, bool AllowResizing) = 0;
virtual void ToggleWindowVSync() = 0;
virtual void Notify(const char *pTitle, const char *pMessage) = 0;
virtual void OnWindowResize() = 0;
virtual void UpdateAndSwap() = 0;
@ -316,6 +317,7 @@ public:
virtual void OnMessage(int MsgID, CUnpacker *pUnpacker, int Conn, bool Dummy) = 0;
virtual void OnPredict() = 0;
virtual void OnActivateEditor() = 0;
virtual void OnWindowResize() = 0;
virtual int OnSnapInput(int *pData, bool Dummy, bool Force) = 0;
virtual void OnDummySwap() = 0;

View file

@ -1122,13 +1122,12 @@ void CClient::DebugRender()
float sp = Graphics()->ScreenWidth() / 100.0f;
float x = Graphics()->ScreenWidth() - w - sp;
ITextRender *pTextRender = Kernel()->RequestInterface<ITextRender>();
m_FpsGraph.Scale();
m_FpsGraph.Render(Graphics(), pTextRender, x, sp * 5, w, h, "FPS");
m_FpsGraph.Render(Graphics(), TextRender(), x, sp * 5, w, h, "FPS");
m_InputtimeMarginGraph.Scale();
m_InputtimeMarginGraph.Render(Graphics(), pTextRender, x, sp * 6 + h, w, h, "Prediction Margin");
m_InputtimeMarginGraph.Render(Graphics(), TextRender(), x, sp * 6 + h, w, h, "Prediction Margin");
m_GametimeMarginGraph.Scale();
m_GametimeMarginGraph.Render(Graphics(), pTextRender, x, sp * 7 + h * 2, w, h, "Gametime Margin");
m_GametimeMarginGraph.Render(Graphics(), TextRender(), x, sp * 7 + h * 2, w, h, "Gametime Margin");
}
}
@ -3038,8 +3037,8 @@ void CClient::Run()
#endif
// init text render
IEngineTextRender *pTextRender = Kernel()->RequestInterface<IEngineTextRender>();
pTextRender->Init();
m_pTextRender = Kernel()->RequestInterface<IEngineTextRender>();
m_pTextRender->Init();
// init the input
Input()->Init();
@ -3058,6 +3057,8 @@ void CClient::Run()
str_copy(g_Config.m_SteamName, Steam()->GetPlayerName());
}
Graphics()->AddWindowResizeListener([this] { OnWindowResize(); });
GameClient()->OnInit();
m_pConsole->Print(IConsole::OUTPUT_LEVEL_STANDARD, "client", "version " GAME_RELEASE_VERSION " on " CONF_PLATFORM_STRING " " CONF_ARCH_STRING, ColorRGBA(0.7f, 0.7f, 1.0f, 1.0f));
@ -3398,7 +3399,7 @@ void CClient::Run()
delete m_pEditor;
// shutdown text render while graphics are still available
pTextRender->Shutdown();
m_pTextRender->Shutdown();
}
bool CClient::InitNetworkClient(char *pError, size_t ErrorSize)
@ -4287,6 +4288,14 @@ void CClient::Notify(const char *pTitle, const char *pMessage)
Graphics()->NotifyWindow();
}
void CClient::OnWindowResize()
{
TextRender()->OnPreWindowResize();
GameClient()->OnWindowResize();
m_pEditor->OnWindowResize();
TextRender()->OnWindowResize();
}
void CClient::ConchainWindowVSync(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData)
{
CClient *pSelf = (CClient *)pUserData;

View file

@ -121,6 +121,7 @@ class CClient : public IClient, public CDemoPlayer::IListener
IEngineSound *m_pSound = nullptr;
ISteam *m_pSteam = nullptr;
IStorage *m_pStorage = nullptr;
IEngineTextRender *m_pTextRender = nullptr;
IUpdater *m_pUpdater = nullptr;
CNetClient m_aNetClient[NUM_CONNS];
@ -311,6 +312,7 @@ public:
IEngineSound *Sound() { return m_pSound; }
ISteam *Steam() { return m_pSteam; }
IStorage *Storage() { return m_pStorage; }
IEngineTextRender *TextRender() { return m_pTextRender; }
IUpdater *Updater() { return m_pUpdater; }
CClient();
@ -510,6 +512,7 @@ public:
void SetWindowParams(int FullscreenMode, bool IsBorderless, bool AllowResizing) override;
void ToggleWindowVSync() override;
void Notify(const char *pTitle, const char *pMessage) override;
void OnWindowResize() override;
void BenchmarkQuit(int Seconds, const char *pFilename);
void UpdateAndSwap() override;

View file

@ -13,6 +13,7 @@ public:
virtual void OnUpdate() = 0;
virtual void OnRender() = 0;
virtual void OnActivate() = 0;
virtual void OnWindowResize() = 0;
virtual bool HasUnsavedData() const = 0;
virtual bool Load(const char *pFilename, int StorageType) = 0;
virtual bool Save(const char *pFilename) = 0;

View file

@ -227,8 +227,6 @@ void CGameClient::OnInit()
m_pGraphics = Kernel()->RequestInterface<IGraphics>();
m_pGraphics->AddWindowResizeListener([this] { OnWindowResize(); });
// propagate pointers
m_UI.Init(Kernel());
m_RenderTools.Init(Graphics(), TextRender());
@ -964,13 +962,10 @@ void CGameClient::OnFlagGrab(int TeamID)
void CGameClient::OnWindowResize()
{
TextRender()->OnPreWindowResize();
for(auto &pComponent : m_vpAll)
pComponent->OnWindowResize();
UI()->OnWindowResize();
TextRender()->OnWindowResize();
}
void CGameClient::OnLanguageChange()
@ -991,7 +986,7 @@ void CGameClient::HandleLanguageChanged()
TextRender()->SetFontLanguageVariant(g_Config.m_ClLanguagefile);
// Clear all text containers
OnWindowResize();
Client()->OnWindowResize();
}
void CGameClient::RenderShutdownMessage()

View file

@ -485,8 +485,7 @@ public:
virtual void OnStartGame();
virtual void OnStartRound();
virtual void OnFlagGrab(int TeamID);
void OnWindowResize();
void OnWindowResize() override;
bool m_LanguageChanged = false;
void OnLanguageChange();

View file

@ -8292,6 +8292,11 @@ void CEditor::OnActivate()
ResetIngameMoved();
}
void CEditor::OnWindowResize()
{
UI()->OnWindowResize();
}
void CEditor::LoadCurrentMap()
{
if(Load(m_pClient->GetCurrentMapPath(), IStorage::TYPE_SAVE))

View file

@ -950,6 +950,7 @@ public:
void OnUpdate() override;
void OnRender() override;
void OnActivate() override;
void OnWindowResize() override;
bool HasUnsavedData() const override { return m_Map.m_Modified; }
void UpdateMentions() override { m_Mentions++; }
void ResetMentions() override { m_Mentions = 0; }