示例#1
0
unsigned int CABatchView::atlasIndexForSubview(CAView *view, int nZ)
{
    const CAVector<CAView*>& pBrothers = view->getSuperview()->getSubviews();
    
    unsigned int uSubviewIndex = (unsigned int)pBrothers.getIndex(view);

    bool bIgnoreParent = (CABatchView*)(view->getSuperview()) == this;
    CAView *pPrevious = NULL;
    if (uSubviewIndex > 0 && uSubviewIndex < UINT_MAX)
    {
        pPrevious = (CAView*)(pBrothers.at(uSubviewIndex - 1));
    }

    if (bIgnoreParent)
    {
        if (uSubviewIndex == 0)
        {
            return 0;
        }

        return highestAtlasIndexInSubview(pPrevious) + 1;
    }

    if (uSubviewIndex == 0)
    {
        CAView *p = (CAView*)(view->getSuperview());

        if (nZ < 0)
        {
            return p->getAtlasIndex();
        }
        else
        {
            return p->getAtlasIndex() + 1;
        }
    }
    else
    {
        if ((pPrevious->getZOrder() < 0 && nZ < 0) || (pPrevious->getZOrder() >= 0 && nZ >= 0))
        {
            return highestAtlasIndexInSubview(pPrevious) + 1;
        }

        CAView *p = (CAView*)(view->getSuperview());
        return p->getAtlasIndex() + 1;
    }

    CCAssert(0, "should not run here");
    return 0;
}
示例#2
0
void CABatchView::sortAllSubview()
{
    if (m_bReorderChildDirty)
    {
        int i = 0,j = 0,length = m_pSubviews->data->num;
        CAView ** x = (CAView**)m_pSubviews->data->arr;
        CAView *tempItem = NULL;

        for(i=1; i<length; i++)
        {
            tempItem = x[i];
            j = i-1;


            while(j>=0 && ( tempItem->getZOrder() < x[j]->getZOrder() || ( tempItem->getZOrder() == x[j]->getZOrder() && tempItem->getOrderOfArrival() < x[j]->getOrderOfArrival() ) ) )
            {
                x[j+1] = x[j];
                j--;
            }

            x[j+1] = tempItem;
        }

        if (m_pSubviews->count() > 0)
        {
            arrayMakeObjectsPerformSelector(m_pSubviews, sortAllSubviews, CAView*);

            int index=0;

            CAObject* pObj = NULL;
            CCARRAY_FOREACH(m_pSubviews, pObj)
            {
                CAView* pChild = (CAView*)pObj;
                updateAtlasIndex(pChild, &index);
            }
        }
示例#3
0
void CABatchView::updateAtlasIndex(CAView* view, int* curIndex)
{
    const CAVector<CAView*> pVector = view->getSubviews();
    unsigned int count = (unsigned int)pVector.size();

    int oldIndex = 0;

    if( count == 0 )
    {
        oldIndex = view->getAtlasIndex();
        view->setAtlasIndex(*curIndex);
        view->setOrderOfArrival(0);
        if (oldIndex != *curIndex)
        {
            swap(oldIndex, *curIndex);
        }
        (*curIndex)++;
    }
    else
    {
        bool needNewIndex = true;

        if (pVector.front()->getZOrder() >= 0)
        {
            oldIndex = view->getAtlasIndex();
            view->setAtlasIndex(*curIndex);
            view->setOrderOfArrival(0);
            if (oldIndex != *curIndex)
            {
                swap(oldIndex, *curIndex);
            }
            (*curIndex)++;
            
            needNewIndex = false;
        }
        
        CAVector<CAView*>::const_iterator itr;
        for (itr=pVector.begin(); itr!=pVector.end(); itr++)
        {
            CAView* subview = *itr;
            if (needNewIndex && subview->getZOrder() >= 0)
            {
                oldIndex = view->getAtlasIndex();
                view->setAtlasIndex(*curIndex);
                view->setOrderOfArrival(0);
                if (oldIndex != *curIndex)
                {
                    this->swap(oldIndex, *curIndex);
                }
                (*curIndex)++;
                needNewIndex = false;
                
            }
            
            updateAtlasIndex(subview, curIndex);
        }

        if (needNewIndex)
        {
            oldIndex = view->getAtlasIndex();
            view->setAtlasIndex(*curIndex);
            view->setOrderOfArrival(0);
            if (oldIndex!=*curIndex)
            {
                swap(oldIndex, *curIndex);
            }
            (*curIndex)++;
        }
    }
}