Example #1
0
bool UIListView::scrollChildren(float touchOffset)
{
    float realOffset = touchOffset;
    
    switch (_direction)
    {
        case LISTVIEW_DIR_VERTICAL: // vertical            
            switch (_moveDirection)
            {
                case LISTVIEW_MOVE_DIR_UP: // up
                    {
                        realOffset = MIN(realOffset, _disBetweenChild);
                        
                        UIWidget* child_last = dynamic_cast<UIWidget*>(_childPool->getLastObject());
                        float child_last_bottom = child_last->getBottomInParent();
                        float scroll_bottom = _bottomBoundary;
                        
                        if (_end == _dataLength - 1)
                        {
                            if (realOffset > scroll_bottom + _disBoundaryToChild_0 - child_last_bottom)
                            {
                                realOffset = scroll_bottom + _disBoundaryToChild_0 - child_last_bottom;
                            }
                            moveChildren(realOffset);
                            return false;
                        }
                        moveChildren(realOffset);
                        
                        if (_end < _dataLength - 1)
                        {
                            collectOverTopChild();
                            unsigned int count = _overTopArray->count();
                            if (count > 0)
                            {
                                updateChild();
                                setLoopPosition();
                                _overTopArray->removeAllObjects();
                            }
                        }
                    }
                    break;
                    
                case LISTVIEW_MOVE_DIR_DOWN: // down
                    {
                        realOffset = MAX(realOffset, -_disBetweenChild);
                        
                        UIWidget* child_0 = dynamic_cast<UIWidget*>(_childPool->getObjectAtIndex(0));
                        float child_0_top = child_0->getTopInParent();
                        float scroll_top = _topBoundary;
                        
                        if (_begin == 0)
                        {
                            if (realOffset < scroll_top - _disBoundaryToChild_0 - child_0_top)
                            {
                                realOffset = scroll_top - _disBoundaryToChild_0 - child_0_top;
                            }
                            moveChildren(realOffset);
                            return false;
                        }
                        moveChildren(realOffset);
                                                
                        if (_begin > 0)
                        {
                            collectOverBottomChild();
                            int count = _overBottomArray->count();
                            if (count > 0)
                            {                                
                                updateChild();
                                setLoopPosition();
                                _overBottomArray->removeAllObjects();
                            }
                        }
                    }
                    break;
                    
                default:
                    break;
            }                                                                
            return true;
            break;
            
        case LISTVIEW_DIR_HORIZONTAL: // horizontal
            switch (_moveDirection)
            {
                case LISTVIEW_MOVE_DIR_LEFT: // left
                    {
                        realOffset = MAX(realOffset, -_disBetweenChild);
                        
                        UIWidget* child_last = dynamic_cast<UIWidget*>(_childPool->getLastObject());
                        float child_last_right = child_last->getRightInParent();
                        float scroll_right = _rightBoundary;
                        
                        if (_end == _dataLength - 1)
                        {
                            if (realOffset < scroll_right - _disBoundaryToChild_0 - child_last_right)
                            {
                                realOffset = scroll_right - _disBoundaryToChild_0 - child_last_right;
                            }
                            moveChildren(realOffset);
                            return false;
                        }
                        moveChildren(realOffset);
                                                
                        if (_end < _dataLength - 1)
                        {
                            collectOverLeftChild();
                            int count = _overLeftArray->count();
                            if (count > 0)
                            {
                                updateChild();
                                setLoopPosition();
                                _overLeftArray->removeAllObjects();
                            }
                        }                                                                                                                
                    }
                    break;
                    
                case LISTVIEW_MOVE_DIR_RIGHT: // right
                    {
                        realOffset = MIN(realOffset, _disBetweenChild);
                        
                        UIWidget* child_0 = dynamic_cast<UIWidget*>(_childPool->getObjectAtIndex(0));
                        float child_0_left = child_0->getLeftInParent();
                        float scroll_left = _leftBoundary;
                        
                        if (_begin == 0)
                        {
                            if (realOffset > scroll_left + _disBoundaryToChild_0 - child_0_left)
                            {
                                realOffset = scroll_left + _disBoundaryToChild_0 - child_0_left;
                            }
                            moveChildren(realOffset);
                            return false;
                        }
                        moveChildren(realOffset);
                                                
                        collectOverRightChild();
                        int count = _overRightArray->count();
                        if (count > 0)
                        {
                            updateChild();
                            setLoopPosition();
                            _overRightArray->removeAllObjects();
                        }                                                                                    
                    }
                    break;
                    
                default:
                    break;
            }                                                                                                      
            return true;
            break;
            
        default:
            break;
    }
    
    return false;
}
bool UIListView::scrollChildren(float touchOffset)
{
    if (m_children->count() <= 0)
    {
        return false;
    }
    
    float realOffset = touchOffset;
    
    switch (m_eDirection)
    {
        case SCROLLVIEW_DIR_VERTICAL: // vertical            
            switch (m_eMoveDirection)
            {
                case SCROLLVIEW_MOVE_DIR_UP: // up
                    {
                        UIWidget* child_last = dynamic_cast<UIWidget*>(m_pChildPool->lastObject());
//                        UIWidget* child_last = m_pChildPool->rbegin();                        
                        float child_last_bottom = child_last->getRelativeBottomPos();
                        float scroll_bottom = m_fBottomBoundary;
                        
                        if (m_nEnd == m_nDataLength - 1)
                        {
                            if (realOffset > scroll_bottom - child_last_bottom)
                            {
                                realOffset = scroll_bottom - child_last_bottom;
                            }
                            UIScrollView::moveChildren(realOffset);
                            return false;
                        }
                        UIScrollView::moveChildren(realOffset);
                        
                        if (m_nEnd < m_nDataLength - 1)
                        {
                            collectOverTopChild();
                            int count = m_overTopArray->count();
                            if (count > 0)
                            {
                                updateChild();
                                setLoopPosition();
                                m_overTopArray->removeAllObjects();
                            }
                        }
                    }
                    break;
                    
                case SCROLLVIEW_MOVE_DIR_DOWN: // down
                    {
                        UIWidget* child_0 = dynamic_cast<UIWidget*>(m_pChildPool->objectAtIndex(0));
//                        UIWidget* child_0 = m_pChildPool->begin();
                        float child_0_top = child_0->getRelativeTopPos();
                        float scroll_top = m_fTopBoundary;
                        
                        if (m_nBegin == 0)
                        {
                            if (realOffset < scroll_top - child_0_top)
                            {
                                realOffset = scroll_top - child_0_top;
                            }
                            UIScrollView::moveChildren(realOffset);
                            return false;
                        }
                        UIScrollView::moveChildren(realOffset);
                                                
                        if (m_nBegin > 0)
                        {
                            collectOverBottomChild();
                            int count = m_overBottomArray->count();
                            if (count > 0)
                            {
                                updateChild();
                                setLoopPosition();
                                m_overBottomArray->removeAllObjects();
                            }
                        }
                    }
                    break;
                    
                default:
                    break;
            }                                                                
            return true;
            break;
            
        case SCROLLVIEW_DIR_HORIZONTAL: // horizontal
            switch (m_eMoveDirection)
            {
                case SCROLLVIEW_MOVE_DIR_LEFT: // left
                    {
                        UIWidget* child_last = dynamic_cast<UIWidget*>(m_pChildPool->lastObject());
//                        UIWidget* child_last = m_pChildPool->rbegin();
                        float child_last_right = child_last->getRelativeRightPos();
                        float scroll_right = m_fRightBoundary;
                        
                        if (m_nEnd == m_nDataLength - 1)
                        {
                            if (realOffset < scroll_right - child_last_right)
                            {
                                realOffset = scroll_right - child_last_right;
                            }
                        }
                        UIScrollView::moveChildren(realOffset);
                        if (m_nEnd == m_nDataLength - 1)
                        {
                            return false;
                        }
                                                
                        if (m_nEnd < m_nDataLength - 1)
                        {
                            collectOverLeftChild();
                            int count = m_overLeftArray->count();
                            if (count > 0)
                            {
                                updateChild();
                                setLoopPosition();
                                m_overLeftArray->removeAllObjects();
                            }
                        }                                                                                                                
                    }
                    break;
                    
                case SCROLLVIEW_MOVE_DIR_RIGHT: // right
                    {
                        UIWidget* child_0 = dynamic_cast<UIWidget*>(m_pChildPool->objectAtIndex(0));
//                        UIWidget* child_0 = m_pChildPool->begin();
                        float child_0_left = child_0->getRelativeLeftPos();
                        float scroll_left = m_fLeftBoundary;
                        
                        if (m_nBegin == 0)
                        {
                            if (realOffset > scroll_left - child_0_left)
                            {
                                realOffset = scroll_left - child_0_left;
                            }
                        }
                        UIScrollView::moveChildren(realOffset);
                        if (m_nBegin == 0)
                        {
                            return false;
                        }
                                                
                        collectOverRightChild();
                        int count = m_overRightArray->count();
                        if (count > 0)
                        {
                            updateChild();
                            setLoopPosition();
                            m_overRightArray->removeAllObjects();
                        }                                                                                    
                    }
                    break;
                    
                default:
                    break;
            }                                                                                                      
            return true;
            break;
            
        default:
            break;
    }
    
    return false;
}