From 992683c7726dad128902e4586c930df41bc7f1be Mon Sep 17 00:00:00 2001 From: def Date: Thu, 31 Dec 2020 10:03:15 +0100 Subject: [PATCH] Dynamically size scoreboard title --- src/game/client/components/scoreboard.cpp | 11 +++++++---- src/game/editor/editor.cpp | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/game/client/components/scoreboard.cpp b/src/game/client/components/scoreboard.cpp index 5c91685da..bc607f6ad 100644 --- a/src/game/client/components/scoreboard.cpp +++ b/src/game/client/components/scoreboard.cpp @@ -197,13 +197,16 @@ void CScoreboard::RenderScoreboard(float x, float y, float w, int Team, const ch // render title float TitleFontsize = 40.0f; + int TitleWidth = (lower32 || lower24 || lower16) ? 1140 : 440; if(!pTitle) { if(m_pClient->m_Snap.m_pGameInfoObj->m_GameStateFlags & GAMESTATEFLAG_GAMEOVER) pTitle = Localize("Game over"); else { - str_utf8_truncate(aBuf, sizeof(aBuf), Client()->GetCurrentMap(), 16); + str_utf8_copy(aBuf, Client()->GetCurrentMap(), sizeof(aBuf)); + while(TextRender()->TextWidth(0, TitleFontsize, aBuf, -1, -1.0f) > TitleWidth) + aBuf[str_length(aBuf) - 1] = '\0'; if(str_comp(aBuf, Client()->GetCurrentMap())) str_append(aBuf, "…", sizeof(aBuf)); pTitle = aBuf; @@ -614,18 +617,18 @@ void CScoreboard::OnRender() { if(m_pClient->m_Snap.m_aTeamSize[0] > 48) { - RenderScoreboard(Width / 2 - w, 150.0f, w, -4, 0); RenderScoreboard(Width / 2, 150.0f, w, -5, ""); + RenderScoreboard(Width / 2 - w, 150.0f, w, -4, 0); } else if(m_pClient->m_Snap.m_aTeamSize[0] > 32) { - RenderScoreboard(Width / 2 - w, 150.0f, w, -7, 0); RenderScoreboard(Width / 2, 150.0f, w, -8, ""); + RenderScoreboard(Width / 2 - w, 150.0f, w, -7, 0); } else if(m_pClient->m_Snap.m_aTeamSize[0] > 16) { - RenderScoreboard(Width / 2 - w, 150.0f, w, -6, 0); RenderScoreboard(Width / 2, 150.0f, w, -3, ""); + RenderScoreboard(Width / 2 - w, 150.0f, w, -6, 0); } else { diff --git a/src/game/editor/editor.cpp b/src/game/editor/editor.cpp index 9eb8ab49a..56978e07d 100644 --- a/src/game/editor/editor.cpp +++ b/src/game/editor/editor.cpp @@ -2975,7 +2975,7 @@ float CEditor::ScaleFontSize(char *pText, int TextSize, float FontSize, int Widt else { pText[str_length(pText) - 4] = '\0'; - str_append(pText, "...", TextSize); + str_append(pText, "…", TextSize); } } return FontSize;