Remove duplicated logic in bounceScrollChildren()

This commit is contained in:
Neo Kim 2015-06-19 12:31:57 +09:00
parent 1971b01280
commit a3ff9573b0
2 changed files with 121 additions and 151 deletions

View File

@ -438,6 +438,7 @@ void ScrollView::checkBounceBoundary(bool* pTopBounceNeeded, bool* pBottomBounce
{ {
(*pBottomBounceNeeded) = false; (*pBottomBounceNeeded) = false;
} }
float icTopPos = _innerContainer->getTopBoundary(); float icTopPos = _innerContainer->getTopBoundary();
if (icTopPos < _topBoundary) if (icTopPos < _topBoundary)
{ {
@ -448,6 +449,7 @@ void ScrollView::checkBounceBoundary(bool* pTopBounceNeeded, bool* pBottomBounce
{ {
(*pTopBounceNeeded) = false; (*pTopBounceNeeded) = false;
} }
float icRightPos = _innerContainer->getRightBoundary(); float icRightPos = _innerContainer->getRightBoundary();
if (icRightPos < _rightBoundary) if (icRightPos < _rightBoundary)
{ {
@ -458,6 +460,7 @@ void ScrollView::checkBounceBoundary(bool* pTopBounceNeeded, bool* pBottomBounce
{ {
(*pRightBounceNeeded) = false; (*pRightBounceNeeded) = false;
} }
float icLeftPos = _innerContainer->getLeftBoundary(); float icLeftPos = _innerContainer->getLeftBoundary();
if (icLeftPos > _leftBoundary) if (icLeftPos > _leftBoundary)
{ {
@ -554,137 +557,97 @@ void ScrollView::stopAutoScrollChildren()
_autoScrollAddUpTime = 0.0f; _autoScrollAddUpTime = 0.0f;
} }
bool ScrollView::processBounceScrollTop(float* offsetYResult, float touchOffsetY)
{
float icBottomPos = _innerContainer->getBottomBoundary();
if (icBottomPos + touchOffsetY <= _bottomBoundary)
{
(*offsetYResult) = _bottomBoundary - icBottomPos;
processScrollEvent(MoveDirection::BOTTOM, true);
return false;
}
return true;
}
bool ScrollView::processBounceScrollBottom(float* offsetYResult, float touchOffsetY)
{
float icTopPos = _innerContainer->getTopBoundary();
if (icTopPos + touchOffsetY >= _topBoundary)
{
(*offsetYResult) = _topBoundary - icTopPos;
processScrollEvent(MoveDirection::TOP, true);
return false;
}
return true;
}
bool ScrollView::processBounceScrollLeft(float* offsetXResult, float touchOffsetX)
{
float icRightPos = _innerContainer->getRightBoundary();
if (icRightPos + touchOffsetX >= _rightBoundary)
{
(*offsetXResult) = _rightBoundary - icRightPos;
processScrollEvent(MoveDirection::RIGHT, true);
return false;
}
return true;
}
bool ScrollView::processBounceScrollRight(float* offsetXResult, float touchOffsetX)
{
float icLefrPos = _innerContainer->getLeftBoundary();
if (icLefrPos + touchOffsetX <= _leftBoundary)
{
(*offsetXResult) = _leftBoundary - icLefrPos;
processScrollEvent(MoveDirection::LEFT, true);
return false;
}
return true;
}
bool ScrollView::bounceScrollChildren(float touchOffsetX, float touchOffsetY) bool ScrollView::bounceScrollChildren(float touchOffsetX, float touchOffsetY)
{ {
bool scrollenabled = true; bool scrollenabled = true;
if (touchOffsetX > 0.0f && touchOffsetY > 0.0f) //first quadrant //bounce to top-right
{ float realOffsetX = touchOffsetX;
float realOffsetX = touchOffsetX; float realOffsetY = touchOffsetY;
float realOffsetY = touchOffsetY;
float icRightPos = _innerContainer->getRightBoundary(); if (touchOffsetY > 0.0f) //first quadrant //bounce to top-right
if (icRightPos + realOffsetX >= _rightBoundary) {
{ if (touchOffsetX > 0.0f) //first quadrant //bounce to top-right
realOffsetX = _rightBoundary - icRightPos; {
processScrollEvent(MoveDirection::RIGHT, true); scrollenabled = processBounceScrollLeft(&realOffsetX, touchOffsetX);
scrollenabled = false; }
} else if(touchOffsetX < 0.0f) //second quadrant //bounce to top-left
float icTopPos = _innerContainer->getTopBoundary(); {
if (icTopPos + touchOffsetY >= _topBoundary) scrollenabled = processBounceScrollRight(&realOffsetX, touchOffsetX);
{ }
realOffsetY = _topBoundary - icTopPos; scrollenabled = processBounceScrollBottom(&realOffsetY, touchOffsetY);
processScrollEvent(MoveDirection::TOP, true); }
scrollenabled = false; else if (touchOffsetY < 0.0f) //third quadrant //bounce to bottom-left
} {
moveChildren(realOffsetX, realOffsetY); if (touchOffsetX < 0.0f) //third quadrant //bounce to bottom-left
} {
else if(touchOffsetX < 0.0f && touchOffsetY > 0.0f) //second quadrant //bounce to top-left scrollenabled = processBounceScrollRight(&realOffsetX, touchOffsetX);
{ }
float realOffsetX = touchOffsetX; else if (touchOffsetX > 0.0f) //forth quadrant //bounce to bottom-right
float realOffsetY = touchOffsetY; {
float icLefrPos = _innerContainer->getLeftBoundary(); scrollenabled = processBounceScrollLeft(&realOffsetX, touchOffsetX);
if (icLefrPos + realOffsetX <= _leftBoundary) }
{ scrollenabled = processBounceScrollTop(&realOffsetY, touchOffsetY);
realOffsetX = _leftBoundary - icLefrPos; }
processScrollEvent(MoveDirection::LEFT, true); else
scrollenabled = false; {
} if (touchOffsetX > 0.0f) //bounce to right
float icTopPos = _innerContainer->getTopBoundary(); {
if (icTopPos + touchOffsetY >= _topBoundary) scrollenabled = processBounceScrollLeft(&realOffsetX, touchOffsetX);
{ }
realOffsetY = _topBoundary - icTopPos; else if (touchOffsetX < 0.0f) //bounce to left
processScrollEvent(MoveDirection::TOP, true); {
scrollenabled = false; scrollenabled = processBounceScrollRight(&realOffsetX, touchOffsetX);
} }
moveChildren(realOffsetX, realOffsetY); }
} moveChildren(realOffsetX, realOffsetY);
else if (touchOffsetX < 0.0f && touchOffsetY < 0.0f) //third quadrant //bounce to bottom-left
{
float realOffsetX = touchOffsetX;
float realOffsetY = touchOffsetY;
float icLefrPos = _innerContainer->getLeftBoundary();
if (icLefrPos + realOffsetX <= _leftBoundary)
{
realOffsetX = _leftBoundary - icLefrPos;
processScrollEvent(MoveDirection::LEFT, true);
scrollenabled = false;
}
float icBottomPos = _innerContainer->getBottomBoundary();
if (icBottomPos + touchOffsetY <= _bottomBoundary)
{
realOffsetY = _bottomBoundary - icBottomPos;
processScrollEvent(MoveDirection::BOTTOM, true);
scrollenabled = false;
}
moveChildren(realOffsetX, realOffsetY);
}
else if (touchOffsetX > 0.0f && touchOffsetY < 0.0f) //forth quadrant //bounce to bottom-right
{
float realOffsetX = touchOffsetX;
float realOffsetY = touchOffsetY;
float icRightPos = _innerContainer->getRightBoundary();
if (icRightPos + realOffsetX >= _rightBoundary)
{
realOffsetX = _rightBoundary - icRightPos;
processScrollEvent(MoveDirection::RIGHT, true);
scrollenabled = false;
}
float icBottomPos = _innerContainer->getBottomBoundary();
if (icBottomPos + touchOffsetY <= _bottomBoundary)
{
realOffsetY = _bottomBoundary - icBottomPos;
processScrollEvent(MoveDirection::BOTTOM, true);
scrollenabled = false;
}
moveChildren(realOffsetX, realOffsetY);
}
else if (touchOffsetX == 0.0f && touchOffsetY > 0.0f) // bounce to top
{
float realOffsetY = touchOffsetY;
float icTopPos = _innerContainer->getTopBoundary();
if (icTopPos + touchOffsetY >= _topBoundary)
{
realOffsetY = _topBoundary - icTopPos;
processScrollEvent(MoveDirection::TOP, true);
scrollenabled = false;
}
moveChildren(0.0f, realOffsetY);
}
else if (touchOffsetX == 0.0f && touchOffsetY < 0.0f) //bounce to bottom
{
float realOffsetY = touchOffsetY;
float icBottomPos = _innerContainer->getBottomBoundary();
if (icBottomPos + touchOffsetY <= _bottomBoundary)
{
realOffsetY = _bottomBoundary - icBottomPos;
processScrollEvent(MoveDirection::BOTTOM, true);
scrollenabled = false;
}
moveChildren(0.0f, realOffsetY);
}
else if (touchOffsetX > 0.0f && touchOffsetY == 0.0f) //bounce to right
{
float realOffsetX = touchOffsetX;
float icRightPos = _innerContainer->getRightBoundary();
if (icRightPos + realOffsetX >= _rightBoundary)
{
realOffsetX = _rightBoundary - icRightPos;
processScrollEvent(MoveDirection::RIGHT, true);
scrollenabled = false;
}
moveChildren(realOffsetX, 0.0f);
}
else if (touchOffsetX < 0.0f && touchOffsetY == 0.0f) //bounce to left
{
float realOffsetX = touchOffsetX;
float icLeftPos = _innerContainer->getLeftBoundary();
if (icLeftPos + realOffsetX <= _leftBoundary)
{
realOffsetX = _leftBoundary - icLeftPos;
processScrollEvent(MoveDirection::LEFT, true);
scrollenabled = false;
}
moveChildren(realOffsetX, 0.0f);
}
return scrollenabled; return scrollenabled;
} }
@ -843,19 +806,6 @@ bool ScrollView::checkCustomScrollDestination(float* touchOffsetX, float* touchO
return scrollenabled; return scrollenabled;
} }
bool ScrollView::processScrollBottom(float* offsetYResult, float touchOffsetY)
{
float boundary = (_bounceEnabled ? _bounceTopBoundary : _topBoundary);
float icTopPos = _innerContainer->getTopBoundary();
if (icTopPos + touchOffsetY <= boundary)
{
(*offsetYResult) = boundary - icTopPos;
processScrollEvent(MoveDirection::TOP, false);
return false;
}
return true;
}
bool ScrollView::processScrollTop(float* offsetYResult, float touchOffsetY) bool ScrollView::processScrollTop(float* offsetYResult, float touchOffsetY)
{ {
float boundary = (_bounceEnabled ? _bounceBottomBoundary : _bottomBoundary); float boundary = (_bounceEnabled ? _bounceBottomBoundary : _bottomBoundary);
@ -869,14 +819,14 @@ bool ScrollView::processScrollTop(float* offsetYResult, float touchOffsetY)
return true; return true;
} }
bool ScrollView::processScrollRight(float* offsetXResult, float touchOffsetX) bool ScrollView::processScrollBottom(float* offsetYResult, float touchOffsetY)
{ {
float boundary = (_bounceEnabled ? _bounceLeftBoundary : _leftBoundary); float boundary = (_bounceEnabled ? _bounceTopBoundary : _topBoundary);
float icLeftPos = _innerContainer->getLeftBoundary(); float icTopPos = _innerContainer->getTopBoundary();
if (icLeftPos + touchOffsetX >= boundary) if (icTopPos + touchOffsetY <= boundary)
{ {
(*offsetXResult) = boundary - icLeftPos; (*offsetYResult) = boundary - icTopPos;
processScrollEvent(MoveDirection::LEFT, false); processScrollEvent(MoveDirection::TOP, false);
return false; return false;
} }
return true; return true;
@ -895,6 +845,19 @@ bool ScrollView::processScrollLeft(float* offsetXResult, float touchOffsetX)
return true; return true;
} }
bool ScrollView::processScrollRight(float* offsetXResult, float touchOffsetX)
{
float boundary = (_bounceEnabled ? _bounceLeftBoundary : _leftBoundary);
float icLeftPos = _innerContainer->getLeftBoundary();
if (icLeftPos + touchOffsetX >= boundary)
{
(*offsetXResult) = boundary - icLeftPos;
processScrollEvent(MoveDirection::LEFT, false);
return false;
}
return true;
}
bool ScrollView::scrollChildren(float touchOffsetX, float touchOffsetY) bool ScrollView::scrollChildren(float touchOffsetX, float touchOffsetY)
{ {
processScrollingEvent(); processScrollingEvent();

View File

@ -441,13 +441,20 @@ protected:
virtual bool scrollChildren(float touchOffsetX, float touchOffsetY); virtual bool scrollChildren(float touchOffsetX, float touchOffsetY);
// // Without bounce
bool processScrollBottom(float* offsetYResult, float touchOffsetY);
bool processScrollTop(float* offsetYResult, float touchOffsetY); bool processScrollTop(float* offsetYResult, float touchOffsetY);
bool processScrollRight(float* offsetXResult, float touchOffsetX); bool processScrollBottom(float* offsetYResult, float touchOffsetY);
bool processScrollLeft(float* offsetXResult, float touchOffsetX); bool processScrollLeft(float* offsetXResult, float touchOffsetX);
bool processScrollRight(float* offsetXResult, float touchOffsetX);
// With bounce
bool processBounceScrollTop(float* offsetYResult, float touchOffsetY);
bool processBounceScrollBottom(float* offsetYResult, float touchOffsetY);
bool processBounceScrollLeft(float* offsetXResult, float touchOffsetX);
bool processBounceScrollRight(float* offsetXResult, float touchOffsetX);
bool bounceScrollChildren(float touchOffsetX, float touchOffsetY); bool bounceScrollChildren(float touchOffsetX, float touchOffsetY);
void startRecordSlidAction(); void startRecordSlidAction();
virtual void endRecordSlidAction(); virtual void endRecordSlidAction();