5048: fix tooltips rendering when they shouldn't, fixes #5035 r=def- a=edg-l

<!-- What is the motivation for the changes of this pull request -->

fixes #5035

## Checklist

- [x] Tested the change ingame
- [ ] 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: Edgar Luque <git@edgarluque.com>
This commit is contained in:
bors[bot] 2022-04-30 09:47:42 +00:00 committed by GitHub
commit 7c83bf85ec
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 1 deletions

View file

@ -33,13 +33,17 @@ void CTooltips::DoToolTip(const void *pID, const CUIRect *pNearRect, const char
const auto result = m_Tooltips.emplace(ID, CTooltip{
*pNearRect,
pText,
WidthHint});
WidthHint,
false});
CTooltip &Tooltip = result.first->second;
if(!result.second)
{
Tooltip.m_Rect = *pNearRect; // update in case of window resize
}
Tooltip.m_OnScreen = true;
if(UI()->MouseInside(&Tooltip.m_Rect))
{
SetActiveTooltip(Tooltip);
@ -54,10 +58,14 @@ void CTooltips::OnRender()
if(!UI()->MouseInside(&Tooltip.m_Rect))
{
Tooltip.m_OnScreen = false;
ClearActiveTooltip();
return;
}
if(!Tooltip.m_OnScreen)
return;
// Delay tooltip until 1 second passed.
if(HoverTime > time_get() - time_freq())
return;
@ -100,5 +108,6 @@ void CTooltips::OnRender()
RenderTools()->DrawUIRect(&Rect, ColorRGBA(0.2, 0.2, 0.2, 0.80f), CUI::CORNER_ALL, 5.0f);
Rect.Margin(2.0f, &Rect);
UI()->DoLabel(&Rect, Tooltip.m_pText, 14.0f, TEXTALIGN_LEFT);
Tooltip.m_OnScreen = false;
}
}

View file

@ -13,6 +13,7 @@ struct CTooltip
CUIRect m_Rect;
const char *m_pText;
float m_WidthHint;
bool m_OnScreen; // used to know if the tooltip should be rendered.
};
/**