void ScrollView::handleReleaseLogic(Touch *touch)
{
    // Gather the last touch information when released
    {
        Vec2 touchPositionInNodeSpace = this->convertToNodeSpace(touch->getLocation());
        Vec2 previousTouchPositionInNodeSpace = this->convertToNodeSpace(touch->getPreviousLocation());
        Vec2 delta = touchPositionInNodeSpace - previousTouchPositionInNodeSpace;

        gatherTouchMove(delta);
    }

    _bePressed = false;

    bool bounceBackStarted = startBounceBackIfNeeded();
    if(!bounceBackStarted && _inertiaScrollEnabled)
    {
        Vec2 touchMoveVelocity = calculateTouchMoveVelocity();
        if(touchMoveVelocity != Vec2::ZERO)
        {
            startInertiaScroll(touchMoveVelocity);
        }
    }

    if(_verticalScrollBar != nullptr)
    {
        _verticalScrollBar->onTouchEnded();
    }
    if(_horizontalScrollBar != nullptr)
    {
        _horizontalScrollBar->onTouchEnded();
    }
}
Beispiel #2
0
void ScrollView::processInertiaScrolling(float dt)
{
    _inertiaScrollElapsedTime += dt;
    if(isOutOfBoundaryLeftOrRight() || isOutOfBoundaryTopOrBottom())
    {
        // If the inner container is out of boundary, shorten the inertia time.
        _inertiaScrollElapsedTime += dt * (45000 / INERTIA_DEACCELERATION);
    }
    float percentage = _inertiaScrollElapsedTime / _inertiaScrollExpectedTime;
    if(percentage >= 1)
    {
        _inertiaScrolling = false;
        startBounceBackIfNeeded();
        return;
    }
    percentage = tweenfunc::quartEaseOut(percentage);
    
    Vec2 inertiaVelocity = _inertiaInitiVelocity * (1 - percentage);
    Vec2 displacement = inertiaVelocity * dt;
    if(!_bounceEnabled)
    {
        Vec2 outOfBoundary = getHowMuchOutOfBoundary(displacement);
        if(outOfBoundary != Vec2::ZERO)
        {
            // Don't allow to go out of boundary
            displacement += outOfBoundary;
            _inertiaScrolling = false;
        }
    }
    moveChildren(displacement.x, displacement.y);
}
void ScrollView::handleReleaseLogic(Touch *touch)
{
    // Gather the last touch information when released
    {
        Vec3 currPt, prevPt;
        if(calculateCurrAndPrevTouchPoints(touch, &currPt, &prevPt))
        {
            Vec3 delta3 = currPt - prevPt;
            Vec2 delta(delta3.x, delta3.y);
            gatherTouchMove(delta);
        }
    }

    _bePressed = false;

    bool bounceBackStarted = startBounceBackIfNeeded();
    if(!bounceBackStarted && _inertiaScrollEnabled)
    {
        Vec2 touchMoveVelocity = calculateTouchMoveVelocity();
        if(touchMoveVelocity != Vec2::ZERO)
        {
            startInertiaScroll(touchMoveVelocity);
        }
    }

    if(_verticalScrollBar != nullptr)
    {
        _verticalScrollBar->onTouchEnded();
    }
    if(_horizontalScrollBar != nullptr)
    {
        _horizontalScrollBar->onTouchEnded();
    }
}
Beispiel #4
0
void ScrollView::endRecordSlidAction()
{
    bool bounceBackStarted = startBounceBackIfNeeded();
    if(!bounceBackStarted && _inertiaScrollEnabled)
    {
        startInertiaScroll();
    }
}
void ScrollView::moveInnerContainer(const Vec2& deltaMove, bool canStartBounceBack)
{
    Vec2 adjustedMove = flattenVectorByDirection(deltaMove);

    setInnerContainerPosition(getInnerContainerPosition() + adjustedMove);

    Vec2 outOfBoundary = getHowMuchOutOfBoundary();
    updateScrollBar(outOfBoundary);

    if(_bounceEnabled && canStartBounceBack)
    {
        startBounceBackIfNeeded();
    }
}