From cfb42e17c20e66b09a302e03169ad50c708148b0 Mon Sep 17 00:00:00 2001 From: Nimetu Date: Sun, 6 Dec 2015 16:38:29 +0200 Subject: [PATCH] Added: Smooth scrolling --- code/nel/include/nel/gui/group_scrolltext.h | 5 ++ code/nel/src/gui/group_scrolltext.cpp | 54 +++++++++++++++++++-- 2 files changed, 56 insertions(+), 3 deletions(-) diff --git a/code/nel/include/nel/gui/group_scrolltext.h b/code/nel/include/nel/gui/group_scrolltext.h index 7c5c58f22..66fc89044 100644 --- a/code/nel/include/nel/gui/group_scrolltext.h +++ b/code/nel/include/nel/gui/group_scrolltext.h @@ -66,6 +66,8 @@ namespace NLGUI // from CCtrlBase virtual void elementCaptured(CCtrlBase *capturedElement); + // setup vertical scrolling event + void smoothScrollY (sint32 dy); REFLECT_EXPORT_START(CGroupScrollText, CInterfaceGroup) REFLECT_EXPORT_END @@ -78,6 +80,9 @@ namespace NLGUI bool _Settuped; bool _InvertScrollBar; sint32 _ListHeight; + bool _Scrolling; + float _ScrollDistance; + bool _ClockMsgEventRegistered; protected: void setup(); void updateScrollBar(); diff --git a/code/nel/src/gui/group_scrolltext.cpp b/code/nel/src/gui/group_scrolltext.cpp index 2fa6c828e..c82bd40bf 100644 --- a/code/nel/src/gui/group_scrolltext.cpp +++ b/code/nel/src/gui/group_scrolltext.cpp @@ -40,8 +40,11 @@ namespace NLGUI _Settuped(false), _InvertScrollBar(true), _ListHeight(0), + _Scrolling(false), + _ScrollDistance(0), + _ClockMsgEventRegistered(false), _StartHeight(0), - _EllapsedTime(0) + _EllapsedTime(0) { _IsGroupScrollText = true; } @@ -166,18 +169,63 @@ namespace NLGUI { if (isIn(eventDesc.getX(), eventDesc.getY())) { - sint32 h = _List->getMaxHReal() / 2; + // limit scroll to 100px with single wheel event + sint32 h = std::min(100, _List->getMaxHReal() / 2); if (h == 0) h = 1; - _ScrollBar->moveTargetY(- eventDesc.getWheel() * h); + + smoothScrollY(- eventDesc.getWheel() * h); return true; } } } } + + if (event.getType() == NLGUI::CEventDescriptor::system) + { + if (_Scrolling && _ScrollBar) + { + float dy = _ScrollDistance / 4; + if ((sint32) dy != 0) + { + _ScrollBar->moveTargetY(dy); + _ScrollDistance -= dy; + } + else + { + _Scrolling = false; + if (_ClockMsgEventRegistered) + { + _ClockMsgEventRegistered = false; + CWidgetManager::getInstance()->unregisterClockMsgTarget(this); + } + } + } + } + if (CInterfaceGroup::handleEvent(event)) return true; return false; } + //======================================================================== + void CGroupScrollText::smoothScrollY(sint32 dy) + { + if (!_Scrolling) + { + _Scrolling = true; + _ScrollDistance = 0; + + // register for clock tick event if not already done + CWidgetManager *pWM = CWidgetManager::getInstance(); + if (!pWM->isClockMsgTarget(this)) + { + pWM->registerClockMsgTarget(this); + _ClockMsgEventRegistered = true; + } + } + + _ScrollDistance += dy; + } + //======================================================================== void CGroupScrollText::setup() {