Пример #1
0
void UIPageView::movePages(float offset)
{
    ccArray* arrayPages = m_pages->data;
    int length = arrayPages->num;
    for (int i = 0; i < length; i++)
    {
        UIWidget* child = (UIWidget*)(arrayPages->arr[i]);
        movePagePoint.x = child->getPosition().x + offset;
        movePagePoint.y = child->getPosition().y;
        child->setPosition(movePagePoint);
    }
}
Пример #2
0
void UIPageView::scrollToPage(int idx)
{
    if (idx < 0 || idx >= (int)(m_pages->count()))
    {
        return;
    }
    m_nCurPageIdx = idx;
    UIWidget* curPage = dynamic_cast<UIWidget*>(m_pages->objectAtIndex(idx));
    m_fAutoScrollDistance = -(curPage->getPosition().x);
    m_fAutoScrollSpeed = fabs(m_fAutoScrollDistance)/0.2f;
    m_nAutoScrollDir = m_fAutoScrollDistance > 0 ? 1 : 0;
    m_bIsAutoScrolling = true;
}
Пример #3
0
void UIListView::moveChildren(float offset)
{
    switch (_direction)
    {
        case LISTVIEW_DIR_VERTICAL: // vertical
        {
            ccArray* arrayChildren = _children->data;
            int childrenCount = arrayChildren->num;
            for (int i = 0; i < childrenCount; i++)
            {
                UIWidget* child = (UIWidget*)(arrayChildren->arr[i]);
                _moveChildPoint.x = child->getPosition().x;
                _moveChildPoint.y = child->getPosition().y + offset;
                child->setPosition(_moveChildPoint);
            }
            break;
        }
            
        case LISTVIEW_DIR_HORIZONTAL: // horizontal
        {
            ccArray* arrayChildren = _children->data;
            int childrenCount = arrayChildren->num;
            for (int i=0;i<childrenCount;i++)
            {
                UIWidget* child = (UIWidget*)(arrayChildren->arr[i]);
                _moveChildPoint.x = child->getPosition().x + offset;
                _moveChildPoint.y = child->getPosition().y;
                child->setPosition(_moveChildPoint);
            }
            break;
        }
            
        default:
            break;
    }
}
void UIScrollView::moveChildren(float offset)
{
    switch (m_eDirection)
    {
        case SCROLLVIEW_DIR_VERTICAL: // vertical
        {
            ccArray* arrayChildren = m_children->data;
            int childrenCount = arrayChildren->num;
            for (int i = 0; i < childrenCount; i++)
            {
                UIWidget* child = (UIWidget*)(arrayChildren->arr[i]);
                moveChildPoint.x = child->getPosition().x;
                moveChildPoint.y = child->getPosition().y + offset;
                child->setPosition(moveChildPoint);
                child->setVisible(child->checkBeVisibleInParent());
            }
            break;
        }
        case SCROLLVIEW_DIR_HORIZONTAL: // horizontal
        {
            ccArray* arrayChildren = m_children->data;
            int childrenCount = arrayChildren->num;
            for (int i=0;i<childrenCount;i++)
            {
                UIWidget* child = (UIWidget*)(arrayChildren->arr[i]);
                moveChildPoint.x = child->getPosition().x + offset;
                moveChildPoint.y = child->getPosition().y;
                child->setPosition(moveChildPoint);
                child->setVisible(child->checkBeVisibleInParent());
            }
            break;
        }
        default:
            break;
    }
}
Пример #5
0
void UIPageView::insertPage(Layout* page, int idx)
{
    if (idx < 0)
    {
        return;
    }
    if (!page)
    {
        return;
    }
    if (page->getWidgetType() != WidgetTypeContainer)
    {
        return;
    }
    if (m_pages->containsObject(page))
    {
        return;
    }

    int pageCount = m_pages->count();
    if (idx >= pageCount)
    {
        addPage(page);
    }
    else
    {
        m_pages->insertObject(page, idx);
        page->setPosition(ccp(getPositionXByIndex(idx), 0));
        addChild(page);
        CCSize pSize = page->getSize();
        CCSize pvSize = getSize();
        if (!pSize.equals(pvSize))
        {
            CCLOG("page size does not match pageview size, it will be force sized!");
            page->setSize(pvSize);
        }
        ccArray* arrayPages = m_pages->data;
        int length = arrayPages->num;
        for (int i=(idx+1); i<length; i++) {
            UIWidget* behindPage = dynamic_cast<UIWidget*>(arrayPages->arr[i]);
            CCPoint formerPos = behindPage->getPosition();
            behindPage->setPosition(ccp(formerPos.x+getSize().width, 0));
        }
        updateBoundaryPages();
    }
}
Пример #6
0
void SelectMenuView::onPageViewMove( CCObject *pSender, PageViewEventType type )
{
	switch (type)
	{
	case PAGEVIEW_EVENT_TURNING:
		{
			char tmp[32];
			UIPageView* pageView = dynamic_cast<UIPageView*>(pSender);
			// pageView->getCurPageIndex()
			UIWidget* widget = this->getWidgetByName("bottomUIWidget");
			UIWidget* selectedPoint = widget->getChildByName("selected");
			sprintf(tmp,"unselect%d",pageView->getCurPageIndex() + 1);
			UIWidget* unselectedPoint = widget->getChildByName(tmp);
			selectedPoint->setPosition(unselectedPoint->getPosition());
		}
		break;
	}
}
Пример #7
0
void UIPageView::handleReleaseLogic(const CCPoint &touchPoint)
{
    UIWidget* curPage = dynamic_cast<UIWidget*>(m_pages->objectAtIndex(m_nCurPageIdx));
    if (curPage)
    {
        CCPoint curPagePos = curPage->getPosition();
        int pageCount = m_pages->count();
        float curPageLocation = curPagePos.x;
        float pageWidth = getSize().width;
        float boundary = pageWidth/2.0f;
        if (curPageLocation <= -boundary)
        {
            if (m_nCurPageIdx >= pageCount-1)
            {
                scrollPages(-curPageLocation);
            }
            else
            {
                scrollToPage(m_nCurPageIdx+1);
            }
        }
        else if (curPageLocation >= boundary)
        {
            if (m_nCurPageIdx <= 0)
            {
                scrollPages(-curPageLocation);
            }
            else
            {
                scrollToPage(m_nCurPageIdx-1);
            }
        }
        else
        {
            scrollToPage(m_nCurPageIdx);
        }
    }
}
Пример #8
0
void UIListView::setLoopPosition()
{
    switch (_direction)
    {
        case LISTVIEW_DIR_VERTICAL: // vertical
            switch (_moveDirection)
            {
                case LISTVIEW_MOVE_DIR_UP: // up
                {
                    ccArray* arrayChildren = _children->data;
                    unsigned int childrenCount = arrayChildren->num;
                    
                    if (_overTopArray->count() == childrenCount)
                    {
                        unsigned int count = childrenCount;
                        for (unsigned int i = 0; i < count; ++i)
                        {   
                            UIWidget* child = dynamic_cast<UIWidget*>(_overTopArray->getObjectAtIndex(i));
                            
                            if (i == 0)
                            {
                                float height = child->getSize().height;
                                float offset = (child->getWidgetType() == WidgetTypeWidget) ? height / 2 : height;
                                float y = _topBoundary - _disBoundaryToChild_0 - offset;
                                child->setPosition(Point(child->getPosition().x, y));
                            }
                            else
                            {
                                UIWidget* prev_child = dynamic_cast<UIWidget*>(_overTopArray->getObjectAtIndex(i - 1));
                                child->setPosition(Point(child->getPosition().x, prev_child->getPosition().y - _disBetweenChild));
                            }
                        }
                    }
                    else
                    {
                        float scroll_top = _topBoundary;
                        
                        ccArray* arrayChildren = _children->data;
                        int count = arrayChildren->num;
                        for (int i = 0; i < count; ++i)
                        {
                            UIWidget* child = dynamic_cast<UIWidget*>(arrayChildren->arr[i]);
                            float child_bottom = child->getBottomInParent();
                            
                            if (child_bottom >= scroll_top)
                            {
                                int index = (i == 0) ? (count - 1) : (i - 1);
                                UIWidget* prev_child = dynamic_cast<UIWidget*>(arrayChildren->arr[index]);
                                child->setPosition(Point(child->getPosition().x, prev_child->getPosition().y - _disBetweenChild));
                            }
                        }
                    }
                }
                    break;
                    
                case LISTVIEW_MOVE_DIR_DOWN: // down
                {
                    ccArray* arrayChildren = _children->data;
                    unsigned int childrenCount = arrayChildren->num;
                    
                    if (_overBottomArray->count() == childrenCount)
                    {
                        unsigned int count = childrenCount;
                        for (unsigned int i = 0; i < count; ++i)
                        {
                            UIWidget* child = dynamic_cast<UIWidget*>(_overBottomArray->getObjectAtIndex(i));
                            
                            if (i == 0)
                            {                                
                                float y = _bottomBoundary + _disBoundaryToChild_0 - _disBetweenChild;
                                child->setPosition(Point(child->getPosition().x, y));
                            }
                            else
                            {
                                UIWidget* prev_child = dynamic_cast<UIWidget*>(_overBottomArray->getObjectAtIndex(i - 1));
                                child->setPosition(Point(child->getPosition().x, prev_child->getPosition().y + _disBetweenChild));
                            }
                        }
                    }
                    else
                    {
                        float scroll_bottom = _bottomBoundary;
                        
                        ccArray* arrayChildren = _children->data;
                        int count = arrayChildren->num;
                        for (int i = count - 1; i >= 0; --i)
                        {
                            UIWidget* child = dynamic_cast<UIWidget*>(arrayChildren->arr[i]);
                            float child_top = child->getTopInParent();
                            
                            if (child_top <= scroll_bottom)
                            {
                                int index = (i == count - 1) ? 0 : (i + 1);
                                UIWidget* next_child = dynamic_cast<UIWidget*>(arrayChildren->arr[index]);
                                child->setPosition(Point(child->getPosition().x, next_child->getPosition().y + _disBetweenChild));
                            }
                        }
                    }
                }
                    break;
                    
                default:
                    break;
            }
            break;
            
        case LISTVIEW_DIR_HORIZONTAL: // horizontal
            switch (_moveDirection)
            {
                case LISTVIEW_MOVE_DIR_LEFT: // left
                {
                    ccArray* arrayChildren = _children->data;
                    unsigned int childrenCount = arrayChildren->num;
                    
                    if (_overLeftArray->count() == childrenCount)
                    {
                        unsigned int count = childrenCount;
                        for (unsigned int i = 0; i < count; ++i)
                        {
                            UIWidget* child = dynamic_cast<UIWidget*>(_overLeftArray->getObjectAtIndex(i));
                            
                            if (i == 0)
                            {
                                float width = child->getSize().width;
                                float offset = (child->getWidgetType() == WidgetTypeWidget) ? (width / 2) : 0;                                
                                float x = _leftBoundary + _disBoundaryToChild_0 + width + offset;
                                child->setPosition(Point(x, child->getPosition().y));
                            }
                            else
                            {
                                UIWidget* prev_child = dynamic_cast<UIWidget*>(_overLeftArray->getObjectAtIndex(i - 1));
                                child->setPosition(Point(prev_child->getPosition().x + _disBetweenChild, child->getPosition().y));
                            }
                        }
                    }
                    else
                    {
                        float scroll_left = _leftBoundary;
                        
                        ccArray* arrayChildren = _children->data;
                        int count = arrayChildren->num;
                        for (int i = 0; i < count; ++i)
                        {
                            UIWidget* child = dynamic_cast<UIWidget*>(arrayChildren->arr[i]);
                            float child_right = child->getRightInParent();
                            
                            if (child_right <= scroll_left)
                            {
                                int index = (i == 0) ? (count - 1) : (i - 1);
                                UIWidget* prev_child = dynamic_cast<UIWidget*>(arrayChildren->arr[index]);
                                child->setPosition(Point(prev_child->getPosition().x + _disBetweenChild, child->getPosition().y));
                            }
                        }
                    }
                }
                    break;
                    
                case LISTVIEW_MOVE_DIR_RIGHT: // right
                {
                    ccArray* arrayChildren = _children->data;
                    unsigned int childrenCount = arrayChildren->num;
                    
                    if (_overRightArray->count() == childrenCount)
                    {
                        unsigned int count = childrenCount;
                        for (unsigned int i = 0; i < count; ++i)
                        {
                            UIWidget* child = dynamic_cast<UIWidget*>(_overRightArray->getObjectAtIndex(i));
                            
                            if (i == 0)
                            {
                                float x = _rightBoundary - _disBoundaryToChild_0 + _disBetweenChild;
                                child->setPosition(Point(x, child->getPosition().y));
                            }
                            else
                            {
                                UIWidget* prev_child = dynamic_cast<UIWidget*>(_overRightArray->getObjectAtIndex(i - 1));
                                child->setPosition(Point(prev_child->getPosition().x - _disBetweenChild, child->getPosition().y));
                            }
                        }
                    }
                    else
                    {
                        float scroll_right = _rightBoundary;
                        
                        ccArray* arrayChildren = _children->data;
                        int count = arrayChildren->num;
                        for (int i = count - 1; i >= 0; --i)
                        {
                            UIWidget* child = dynamic_cast<UIWidget*>(arrayChildren->arr[i]);
                            float child_left = child->getLeftInParent();
                            
                            if (child_left >= scroll_right)
                            {
                                int index = (i == count - 1) ? 0 : (i + 1);
                                UIWidget* next_child = dynamic_cast<UIWidget*>(arrayChildren->arr[index]);
                                child->setPosition(Point(next_child->getPosition().x - _disBetweenChild, child->getPosition().y));
                            }
                        }
                    }
                }
                    break;
                    
                default:
                    break;
            }
            break;
            
        default:
            break;
    }
}
void UIListView::setLoopPosition()
{
    switch (m_eDirection)
    {
        case SCROLLVIEW_DIR_VERTICAL: // vertical
            switch (m_eMoveDirection)
            {
                case SCROLLVIEW_MOVE_DIR_UP: // up
                    if (m_overTopArray->count() == m_children->count())
                    {
                        int count = m_overTopArray->count();
                        for (int i = 0; i < count; ++i)
                        {   
                            UIWidget* child = dynamic_cast<UIWidget*>(m_overTopArray->objectAtIndex(i));
                            
                            if (i == 0)
                            {
                                float y = (count - 1);
//                                float y = (0 - m_fDisBetweenChild) + m_fDisBetweenChild * (count - 1);
                                child->setPosition(ccp(child->getPosition().x, y));
                            }
                            else
                            {
                                UIWidget* prev_child = dynamic_cast<UIWidget*>(m_overTopArray->objectAtIndex(i - 1));
                                child->setPosition(ccp(child->getPosition().x, prev_child->getPosition().y));
                            }
                        }
                    }
                    else
                    {
                        float scroll_top = m_fTopBoundary;
                        
                        int count = m_children->count();
                        for (int i = 0; i < count; ++i)
                        {
                            UIWidget* child = dynamic_cast<UIWidget*>(m_children->objectAtIndex(i));
                            float child_bottom = child->getRelativeBottomPos();
                            
                            if (child_bottom >= scroll_top)
                            {
                                int index = (i == 0) ? (count - 1) : (i - 1);
                                UIWidget* prev_child = dynamic_cast<UIWidget*>(m_children->objectAtIndex(index));
                                child->setPosition(ccp(child->getPosition().x, prev_child->getPosition().y));
                            }
                        }
                    }
                    break;
                    
                case SCROLLVIEW_MOVE_DIR_DOWN: // down
                    if (m_overBottomArray->count() == m_children->count())
                    {
                        int count = m_overBottomArray->count();
                        for (int i = 0; i < count; ++i)
                        {
                            UIWidget* child = dynamic_cast<UIWidget*>(m_overBottomArray->objectAtIndex(i));
                            
                            if (i == 0)
                            {
                                float y = (m_fTopBoundary) * (count - 1);
//                                float y = (m_fTopBoundary) - m_fDisBetweenChild * (count - 1);
                                child->setPosition(ccp(child->getPosition().x, y));
                            }
                            else
                            {
                                UIWidget* prev_child = dynamic_cast<UIWidget*>(m_overBottomArray->objectAtIndex(i - 1));
                                child->setPosition(ccp(child->getPosition().x, prev_child->getPosition().y));                                    
                            }
                        }
                    }
                    else
                    {
                        float scroll_bottom = m_fBottomBoundary;
                        
                        int count = m_children->count();
                        for (int i = count - 1; i >= 0; --i)
                        {
                            UIWidget* child = dynamic_cast<UIWidget*>(m_children->objectAtIndex(i));
                            float child_top = child->getRelativeTopPos();
                            
                            if (child_top <= scroll_bottom)
                            {
                                int index = (i == count - 1) ? 0 : (i + 1);
                                UIWidget* next_child = dynamic_cast<UIWidget*>(m_children->objectAtIndex(index));
                                child->setPosition(ccp(child->getPosition().x, next_child->getPosition().y));                                    
                            }
                        }
                    }
                    break;
                    
                default:
                    break;
            }
            break;
            
        case SCROLLVIEW_DIR_HORIZONTAL: // horizontal
            switch (m_eMoveDirection)
            {
                case SCROLLVIEW_MOVE_DIR_LEFT: // left
                    if (m_overLeftArray->count() == m_children->count())
                    {
                        int count = m_overLeftArray->count();
                        for (int i = 0; i < count; ++i)
                        {
                            UIWidget* child = dynamic_cast<UIWidget*>(m_overLeftArray->objectAtIndex(i));
                            
                            if (i == 0)
                            {
                                float x = m_fRightBoundary * (count - 1);
//                                float x = (m_fRightBoundary + m_fDisBetweenChild) - m_fDisBetweenChild * (count - 1);
                                child->setPosition(ccp(x, child->getPosition().y));
                            }
                            else
                            {
                                UIWidget* prev_child = dynamic_cast<UIWidget*>(m_overLeftArray->objectAtIndex(i - 1));
                                child->setPosition(ccp(prev_child->getPosition().x, child->getPosition().y));                                    
                            }
                        }
                    }
                    else
                    {
                        float scroll_left = m_fLeftBoundary;
                        
                        int count = m_children->count();
                        for (int i = 0; i < count; ++i)
                        {
                            UIWidget* child = dynamic_cast<UIWidget*>(m_children->objectAtIndex(i));
                            float child_right = child->getRelativeRightPos();
                            
                            if (child_right <= scroll_left)
                            {
                                int index = (i == 0) ? (count - 1) : (i - 1);
                                UIWidget* prev_child = dynamic_cast<UIWidget*>(m_children->objectAtIndex(index));
                                child->setPosition(ccp(prev_child->getPosition().x, child->getPosition().y));
                            }
                        }
                    }
                    break;
                    
                case SCROLLVIEW_MOVE_DIR_RIGHT: // right
                    if (m_overRightArray->count() == m_children->count())
                    {
                        int count = m_overRightArray->count();
                        for (int i = 0; i < count; ++i)
                        {
                            UIWidget* child = dynamic_cast<UIWidget*>(m_overRightArray->objectAtIndex(i));
                            
                            if (i == 0)
                            {
                                float x = (count - 1);
//                                float x = (0 - m_fDisBetweenChild) + m_fDisBetweenChild * (count - 1);
                                child->setPosition(ccp(x, child->getPosition().y));
                            }
                            else
                            {
                                UIWidget* prev_child = dynamic_cast<UIWidget*>(m_overRightArray->objectAtIndex(i - 1));
                                child->setPosition(ccp(prev_child->getPosition().x, child->getPosition().y));                                    
                            }
                        }
                    }
                    else
                    {
                        float scroll_right = m_fRightBoundary;
                        
                        int count = m_children->count();
                        for (int i = count - 1; i >= 0; --i)
                        {
                            UIWidget* child = dynamic_cast<UIWidget*>(m_children->objectAtIndex(i));
                            float child_left = child->getRelativeLeftPos();
                            
                            if (child_left >= scroll_right)
                            {
                                int index = (i == count - 1) ? 0 : (i + 1);
                                UIWidget* next_child = dynamic_cast<UIWidget*>(m_children->objectAtIndex(index));
                                child->setPosition(ccp(next_child->getPosition().x, child->getPosition().y));
                            }
                        }
                    }
                    break;
                    
                default:
                    break;
            }
            break;
            
        default:
            break;
    }
}