Merge with develop

This commit is contained in:
Nimetu 2015-12-06 16:38:52 +02:00
parent f81fc44305
commit 29e5b70825
4 changed files with 69 additions and 24 deletions

View file

@ -147,7 +147,7 @@ namespace NLGUI
sint32 _Aligned; // 0-Top 1-Bottom 2-Left 3-Right sint32 _Aligned; // 0-Top 1-Bottom 2-Left 3-Right
sint32 _TrackDispPos; sint32 _TrackDispPos;
sint32 _TrackPos; float _TrackPos;
sint32 _TrackSize; sint32 _TrackSize;
sint32 _TrackSizeMin; sint32 _TrackSizeMin;

View file

@ -66,6 +66,8 @@ namespace NLGUI
// from CCtrlBase // from CCtrlBase
virtual void elementCaptured(CCtrlBase *capturedElement); virtual void elementCaptured(CCtrlBase *capturedElement);
// setup vertical scrolling event
void smoothScrollY (sint32 dy);
REFLECT_EXPORT_START(CGroupScrollText, CInterfaceGroup) REFLECT_EXPORT_START(CGroupScrollText, CInterfaceGroup)
REFLECT_EXPORT_END REFLECT_EXPORT_END
@ -78,6 +80,9 @@ namespace NLGUI
bool _Settuped; bool _Settuped;
bool _InvertScrollBar; bool _InvertScrollBar;
sint32 _ListHeight; sint32 _ListHeight;
bool _Scrolling;
float _ScrollDistance;
bool _ClockMsgEventRegistered;
protected: protected:
void setup(); void setup();
void updateScrollBar(); void updateScrollBar();

View file

@ -653,8 +653,7 @@ namespace NLGUI
factor = -(float)_Target->getOfsY() / factor; factor = -(float)_Target->getOfsY() / factor;
if (factor < 0.0f) factor = 0.0f; if (factor < 0.0f) factor = 0.0f;
if (factor > 1.0f) factor = 1.0f; if (factor > 1.0f) factor = 1.0f;
factor = factor * (getHReal()-_TrackSize); _TrackPos = factor * (getHReal()-_TrackSize);
_TrackPos = (sint32)factor;
} }
else // TOP else // TOP
{ {
@ -663,8 +662,7 @@ namespace NLGUI
if (factor < 0.0f) factor = 0.0f; if (factor < 0.0f) factor = 0.0f;
if (factor > 1.0f) factor = 1.0f; if (factor > 1.0f) factor = 1.0f;
sint32 hreal = getHReal(); sint32 hreal = getHReal();
factor = (1.0f-factor) * (hreal - _TrackSize); _TrackPos = (1.0f-factor) * (hreal - _TrackSize);
_TrackPos = (sint32)factor;
} }
} }
@ -712,8 +710,7 @@ namespace NLGUI
factor = -(float)_Target->getOfsX() / factor; factor = -(float)_Target->getOfsX() / factor;
if (factor < 0.0f) factor = 0.0f; if (factor < 0.0f) factor = 0.0f;
if (factor > 1.0f) factor = 1.0f; if (factor > 1.0f) factor = 1.0f;
factor = factor * (getWReal()-_TrackSize); _TrackPos = factor * (getWReal()-_TrackSize);
_TrackPos = (sint32)factor;
} }
else // RIGHT else // RIGHT
{ {
@ -722,8 +719,7 @@ namespace NLGUI
if (factor < 0.0f) factor = 0.0f; if (factor < 0.0f) factor = 0.0f;
if (factor > 1.0f) factor = 1.0f; if (factor > 1.0f) factor = 1.0f;
sint32 hreal = getWReal(); sint32 hreal = getWReal();
factor = (1.0f-factor) * (hreal - _TrackSize); _TrackPos = (1.0f-factor) * (hreal - _TrackSize);
_TrackPos = (sint32)factor;
} }
} }
@ -930,8 +926,8 @@ namespace NLGUI
if ((getWReal()-_TrackSize) <= 0) if ((getWReal()-_TrackSize) <= 0)
return 0; return 0;
sint32 newtpos; float newtpos;
sint32 tpos = _TrackPos; float tpos = _TrackPos;
sint32 tsize = _TrackSize; sint32 tsize = _TrackSize;
// Limit the scroller to the defined area // Limit the scroller to the defined area
@ -998,8 +994,8 @@ namespace NLGUI
if ((getHReal()-_TrackSize) <= 0) if ((getHReal()-_TrackSize) <= 0)
return 0; return 0;
sint32 newtpos; float newtpos;
sint32 tpos = _TrackPos; float tpos = _TrackPos;
sint32 tsize = _TrackSize; sint32 tsize = _TrackSize;
// Limit the scroller to the defined area // Limit the scroller to the defined area
@ -1202,16 +1198,14 @@ namespace NLGUI
float factor = (float)(wReal-maxWReal); float factor = (float)(wReal-maxWReal);
factor = -(float)ofsX / factor; factor = -(float)ofsX / factor;
clamp(factor, 0.f, 1.f); clamp(factor, 0.f, 1.f);
factor = factor * (getWReal()-_TrackSize); _TrackPos = factor * (getWReal()-_TrackSize);
_TrackPos = (sint32)factor;
} }
else // RIGHT else // RIGHT
{ {
float factor = (float)(wReal-maxWReal); float factor = (float)(wReal-maxWReal);
factor = (float)ofsX / factor; factor = (float)ofsX / factor;
clamp(factor, 0.f, 1.f); clamp(factor, 0.f, 1.f);
factor = (1.0f-factor) * (getWReal() - _TrackSize); _TrackPos = (1.0f-factor) * (getWReal() - _TrackSize);
_TrackPos = (sint32)factor;
} }
// invalidate only position. 1 pass is sufficient // invalidate only position. 1 pass is sufficient
@ -1240,8 +1234,7 @@ namespace NLGUI
float factor = (float)(hReal-maxHReal); float factor = (float)(hReal-maxHReal);
factor = -(float)ofsY / factor; factor = -(float)ofsY / factor;
clamp(factor, 0.f, 1.f); clamp(factor, 0.f, 1.f);
factor = factor * (getHReal()-_TrackSize); _TrackPos = factor * (getHReal()-_TrackSize);
_TrackPos = (sint32)factor;
} }
else // TOP else // TOP
{ {
@ -1250,8 +1243,7 @@ namespace NLGUI
float factor = (float)(hReal-maxHReal); float factor = (float)(hReal-maxHReal);
factor = (float)ofsY / factor; factor = (float)ofsY / factor;
clamp(factor, 0.f, 1.f); clamp(factor, 0.f, 1.f);
factor = (1.0f-factor) * (getHReal() - _TrackSize); _TrackPos = (1.0f-factor) * (getHReal() - _TrackSize);
_TrackPos = (sint32)factor;
} }
// invalidate only position. 1 pass is sufficient // invalidate only position. 1 pass is sufficient

View file

@ -40,6 +40,9 @@ namespace NLGUI
_Settuped(false), _Settuped(false),
_InvertScrollBar(true), _InvertScrollBar(true),
_ListHeight(0), _ListHeight(0),
_Scrolling(false),
_ScrollDistance(0),
_ClockMsgEventRegistered(false),
_StartHeight(0), _StartHeight(0),
_EllapsedTime(0) _EllapsedTime(0)
{ {
@ -166,18 +169,63 @@ namespace NLGUI
{ {
if (isIn(eventDesc.getX(), eventDesc.getY())) 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; if (h == 0) h = 1;
_ScrollBar->moveTargetY(- eventDesc.getWheel() * h);
smoothScrollY(- eventDesc.getWheel() * h);
return true; 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; if (CInterfaceGroup::handleEvent(event)) return true;
return false; 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() void CGroupScrollText::setup()
{ {