mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-13 03:28:19 +00:00
Merge #6365
6365: Fix erratic smooth scrolling when scroll time is changed r=def- a=Robyt3 Remember the maximum animation time when initiating a smooth scroll, so the smooth scrolling does not change erratically when `ui_smooth_scroll_time` is changed while smooth scrolling is in progress. ## 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 (especially base/) or added coverage to integration test - [ ] 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: Robert Müller <robytemueller@gmail.com>
This commit is contained in:
commit
8acda309b0
|
@ -13,6 +13,7 @@ CScrollRegion::CScrollRegion()
|
||||||
{
|
{
|
||||||
m_ScrollY = 0.0f;
|
m_ScrollY = 0.0f;
|
||||||
m_ContentH = 0.0f;
|
m_ContentH = 0.0f;
|
||||||
|
m_AnimTimeMax = 0.0f;
|
||||||
m_AnimTime = 0.0f;
|
m_AnimTime = 0.0f;
|
||||||
m_AnimInitScrollY = 0.0f;
|
m_AnimInitScrollY = 0.0f;
|
||||||
m_AnimTargetScrollY = 0.0f;
|
m_AnimTargetScrollY = 0.0f;
|
||||||
|
@ -68,23 +69,23 @@ void CScrollRegion::End()
|
||||||
CUIRect RegionRect = m_ClipRect;
|
CUIRect RegionRect = m_ClipRect;
|
||||||
RegionRect.w += m_Params.m_ScrollbarWidth;
|
RegionRect.w += m_Params.m_ScrollbarWidth;
|
||||||
|
|
||||||
const float AnimationDuration = g_Config.m_UiSmoothScrollTime / 1000.0f;
|
|
||||||
|
|
||||||
if(UI()->Enabled() && UI()->MouseHovered(&RegionRect))
|
if(UI()->Enabled() && UI()->MouseHovered(&RegionRect))
|
||||||
{
|
{
|
||||||
const bool IsPageScroll = Input()->AltIsPressed();
|
float ScrollDirection = 0.0f;
|
||||||
const float ScrollUnit = IsPageScroll ? m_ClipRect.h : m_Params.m_ScrollUnit;
|
|
||||||
if(UI()->ConsumeHotkey(CUI::HOTKEY_SCROLL_UP))
|
if(UI()->ConsumeHotkey(CUI::HOTKEY_SCROLL_UP))
|
||||||
{
|
ScrollDirection = -1.0f;
|
||||||
m_AnimTime = AnimationDuration;
|
|
||||||
m_AnimInitScrollY = m_ScrollY;
|
|
||||||
m_AnimTargetScrollY -= ScrollUnit;
|
|
||||||
}
|
|
||||||
else if(UI()->ConsumeHotkey(CUI::HOTKEY_SCROLL_DOWN))
|
else if(UI()->ConsumeHotkey(CUI::HOTKEY_SCROLL_DOWN))
|
||||||
|
ScrollDirection = 1.0f;
|
||||||
|
|
||||||
|
if(ScrollDirection != 0.0f)
|
||||||
{
|
{
|
||||||
m_AnimTime = AnimationDuration;
|
const bool IsPageScroll = Input()->AltIsPressed();
|
||||||
|
const float ScrollUnit = IsPageScroll ? m_ClipRect.h : m_Params.m_ScrollUnit;
|
||||||
|
|
||||||
|
m_AnimTimeMax = g_Config.m_UiSmoothScrollTime / 1000.0f;
|
||||||
|
m_AnimTime = m_AnimTimeMax;
|
||||||
m_AnimInitScrollY = m_ScrollY;
|
m_AnimInitScrollY = m_ScrollY;
|
||||||
m_AnimTargetScrollY += ScrollUnit;
|
m_AnimTargetScrollY += ScrollDirection * ScrollUnit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,7 +112,7 @@ void CScrollRegion::End()
|
||||||
if(m_AnimTime > 0.0f)
|
if(m_AnimTime > 0.0f)
|
||||||
{
|
{
|
||||||
m_AnimTime -= Client()->RenderFrameTime();
|
m_AnimTime -= Client()->RenderFrameTime();
|
||||||
float AnimProgress = (1.0f - powf(m_AnimTime / AnimationDuration, 3.0f)); // cubic ease out
|
float AnimProgress = (1.0f - powf(m_AnimTime / m_AnimTimeMax, 3.0f)); // cubic ease out
|
||||||
m_ScrollY = m_AnimInitScrollY + (m_AnimTargetScrollY - m_AnimInitScrollY) * AnimProgress;
|
m_ScrollY = m_AnimInitScrollY + (m_AnimTargetScrollY - m_AnimInitScrollY) * AnimProgress;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -91,6 +91,7 @@ private:
|
||||||
float m_ContentH;
|
float m_ContentH;
|
||||||
float m_RequestScrollY; // [0, ContentHeight]
|
float m_RequestScrollY; // [0, ContentHeight]
|
||||||
|
|
||||||
|
float m_AnimTimeMax;
|
||||||
float m_AnimTime;
|
float m_AnimTime;
|
||||||
float m_AnimInitScrollY;
|
float m_AnimInitScrollY;
|
||||||
float m_AnimTargetScrollY;
|
float m_AnimTargetScrollY;
|
||||||
|
|
Loading…
Reference in a new issue