From c174274edc5a4c704801e0a60707f1cc79907848 Mon Sep 17 00:00:00 2001 From: Dennis Felsing Date: Wed, 27 Apr 2022 00:51:02 +0200 Subject: [PATCH] Fix tooltip locations after window resize (fixes #5026) --- src/game/client/components/tooltips.cpp | 31 +++++++------------------ 1 file changed, 9 insertions(+), 22 deletions(-) diff --git a/src/game/client/components/tooltips.cpp b/src/game/client/components/tooltips.cpp index 482696b70..53da6a212 100644 --- a/src/game/client/components/tooltips.cpp +++ b/src/game/client/components/tooltips.cpp @@ -30,32 +30,19 @@ inline void CTooltips::ClearActiveTooltip() void CTooltips::DoToolTip(const void *pID, const CUIRect *pNearRect, const char *pText, float WidthHint) { uintptr_t ID = reinterpret_cast(pID); + const auto result = m_Tooltips.emplace(ID, CTooltip{ + *pNearRect, + pText, + WidthHint}); + CTooltip &Tooltip = result.first->second; - const auto &it = m_Tooltips.find(ID); - - if(it == m_Tooltips.end()) + if(!result.second) { - CTooltip NewTooltip = { - *pNearRect, - pText, - WidthHint, - }; - - m_Tooltips[ID] = NewTooltip; - - CTooltip &Tooltip = m_Tooltips[ID]; - - if(UI()->MouseInside(&Tooltip.m_Rect)) - { - SetActiveTooltip(Tooltip); - } + Tooltip.m_Rect = *pNearRect; // update in case of window resize } - else + if(UI()->MouseInside(&Tooltip.m_Rect)) { - if(UI()->MouseInside(&it->second.m_Rect)) - { - SetActiveTooltip(it->second); - } + SetActiveTooltip(Tooltip); } }