4598: Fix console line y offsets when resizing r=def- a=Jupeyy

Hopefully fixes #4319
I can only imagine it happening bcs of resizing

## Checklist

- [x] Tested the change ingame (only tested with resizing)
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test if it works standalone, system.c especially
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


Co-authored-by: Jupeyy <jupjopjap@gmail.com>
This commit is contained in:
bors[bot] 2022-01-14 22:17:33 +00:00 committed by GitHub
commit e316cfdf75
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 0 deletions

View file

@ -73,6 +73,16 @@ void CGameConsole::CInstance::ClearBacklog()
m_BacklogActPage = 0; m_BacklogActPage = 0;
} }
void CGameConsole::CInstance::ClearBacklogYOffsets()
{
auto *pEntry = m_Backlog.First();
while(pEntry)
{
pEntry->m_YOffset = -1.0f;
pEntry = m_Backlog.Next(pEntry);
}
}
void CGameConsole::CInstance::ClearHistory() void CGameConsole::CInstance::ClearHistory()
{ {
m_History.Init(); m_History.Init();
@ -993,6 +1003,17 @@ void CGameConsole::OnConsoleInit()
Console()->Chain("console_output_level", ConchainConsoleOutputLevelUpdate, this); Console()->Chain("console_output_level", ConchainConsoleOutputLevelUpdate, this);
} }
void CGameConsole::OnInit()
{
// add resize event
Graphics()->AddWindowResizeListener([this](void *) {
m_LocalConsole.ClearBacklogYOffsets();
m_RemoteConsole.ClearBacklogYOffsets();
m_HasSelection = false;
},
nullptr);
}
void CGameConsole::OnStateChange(int NewState, int OldState) void CGameConsole::OnStateChange(int NewState, int OldState)
{ {
if(OldState == IClient::STATE_ONLINE && NewState < IClient::STATE_LOADING) if(OldState == IClient::STATE_ONLINE && NewState < IClient::STATE_LOADING)

View file

@ -59,6 +59,7 @@ class CGameConsole : public CComponent
void Init(CGameConsole *pGameConsole); void Init(CGameConsole *pGameConsole);
void ClearBacklog(); void ClearBacklog();
void ClearBacklogYOffsets();
void ClearHistory(); void ClearHistory();
void ExecuteLine(const char *pLine); void ExecuteLine(const char *pLine);
@ -125,6 +126,7 @@ public:
virtual void OnStateChange(int NewState, int OldState); virtual void OnStateChange(int NewState, int OldState);
virtual void OnConsoleInit(); virtual void OnConsoleInit();
virtual void OnInit();
virtual void OnReset(); virtual void OnReset();
virtual void OnRender(); virtual void OnRender();
virtual void OnMessage(int MsgType, void *pRawMsg); virtual void OnMessage(int MsgType, void *pRawMsg);