Пример #1
0
void CACollectionView::loadCollectionCell()
{
	CCRect rect = this->getBounds();
	rect.origin = getContentOffset();
	rect.origin.y -= rect.size.height * 0.1f;
	rect.size.height *= 1.2f;

	std::map<CAIndexPath3E, CACollectionViewCell*>::iterator itr;
	for (itr = m_pUsedCollectionCells.begin(); itr != m_pUsedCollectionCells.end(); itr++)
	{
		CC_CONTINUE_IF(itr->second != NULL);

		CAIndexPath3E r = itr->first;
		CCRect cellRect = m_rUsedCollectionCellRects[r];
		CC_CONTINUE_IF(!rect.intersectsRect(cellRect));

		CACollectionViewCell* cell = m_pCollectionViewDataSource->collectionCellAtIndex(this, cellRect.size, r.section, r.row, r.item);
		if (cell)
		{
			cell->m_nSection = r.section;
			cell->m_nRow = r.row;
			cell->m_nItem = r.item;
			cell->updateDisplayedAlpha(this->getAlpha());
			this->addSubview(cell);
			cell->setFrame(cellRect);
			itr->second = cell;

			if (m_pSelectedCollectionCells.count(r))
			{
				cell->setControlStateSelected();
			}
		}
	}
}
Пример #2
0
void CAListView::recoveryCell()
{
	DRect rect = this->getBounds();
	rect.origin = getContentOffset();
    rect.origin.y -= rect.size.height * 0.1f;
    rect.origin.x -= rect.size.width * 0.1f;
    rect.size.width *= 1.2f;
    rect.size.height *= 1.2f;
    
	std::map<unsigned int, CAListViewCell*>::iterator itr;
	for (itr = m_mpUsedListCells.begin(); itr != m_mpUsedListCells.end(); itr++)
	{
		CAListViewCell* cell = itr->second;
		CC_CONTINUE_IF(cell == NULL);

		DRect cellRect = cell->getFrame();
		CC_CONTINUE_IF(rect.intersectsRect(cellRect));
		
		m_mpFreedListCells[cell->getReuseIdentifier()].pushBack(cell);
		cell->removeFromSuperview();
		cell->resetCell();
		itr->second = NULL;
        m_vpUsedListCells.eraseObject(cell);
		
        CAView* line = m_pUsedLines[itr->first];
        CC_CONTINUE_IF(line == NULL);
        m_pFreedLines.pushBack(line);
        line->removeFromSuperview();
        m_pUsedLines[itr->first] = NULL;
	}
}
Пример #3
0
void CATableView::recoveryTableCell()
{
    CCRect rect = this->getBounds();
	rect.origin = getContentOffset();
    rect.origin.y -= rect.size.height * 0.1f;
    rect.size.height *= 1.2f;
    
    std::map<CAIndexPath2E, CATableViewCell*>::iterator itr;
    for (itr=m_pUsedTableCells.begin();
         itr!=m_pUsedTableCells.end();
         itr++)
    {
        CATableViewCell* cell = itr->second;
        CC_CONTINUE_IF(cell == NULL);
        CCRect cellRect = cell->getFrame();

        CC_CONTINUE_IF(rect.intersectsRect(cellRect));
        m_pFreedTableCells[cell->getReuseIdentifier()].pushBack(cell);
        cell->removeFromSuperview();
        cell->resetTableViewCell();
        itr->second = NULL;
        
        CAView* line = m_pUsedLines[itr->first];
        CC_CONTINUE_IF(line == NULL);
        m_pFreedLines.pushBack(line);
        line->removeFromSuperview();
        m_pUsedLines[itr->first] = NULL;
    }
}
Пример #4
0
void CAListView::clearData()
{
	std::map<unsigned int, CAView*>::iterator it = m_pUsedLines.begin();
	for (; it != m_pUsedLines.end(); ++it)
	{
		CAView* view = it->second;
		CC_CONTINUE_IF(view == NULL);
		m_pFreedLines.pushBack(view);
		view->removeFromSuperview();
	}
	m_pUsedLines.clear();

	m_mpUsedListCells.clear();

	for (int i = 0; i < m_vpUsedListCells.size(); i++)
	{
		CAListViewCell* cell = m_vpUsedListCells.at(i);
		CC_CONTINUE_IF(cell == NULL);
		m_mpFreedListCells[cell->getReuseIdentifier()].pushBack(cell);
		cell->removeFromSuperview();
		cell->resetCell();
	}
	m_vpUsedListCells.clear();
	
	m_nIndexs = 0;
	m_rIndexRects.clear();
	m_rLineRects.clear();
	m_rHeaderRect = m_rFooterRect = DRectZero;
	m_pHighlightedListCells = NULL;
}
Пример #5
0
void CAListView::loadCell()
{
	DRect rect = this->getBounds();
	rect.origin = getContentOffset();
    rect.origin.y -= rect.size.height * 0.1f;
    rect.origin.x -= rect.size.width * 0.1f;
    rect.size.width *= 1.2f;
    rect.size.height *= 1.2f;
    
	std::map<unsigned int, CAListViewCell*>::iterator itr;
	for (itr = m_mpUsedListCells.begin(); itr != m_mpUsedListCells.end(); itr++)
	{
		CC_CONTINUE_IF(itr->second != NULL);

		unsigned int index = itr->first;
		DRect cellRect = m_rIndexRects[index];
		CC_CONTINUE_IF(!rect.intersectsRect(cellRect));

		CAListViewCell* cell = m_pListViewDataSource->listViewCellAtIndex(this, cellRect.size, index);
		if (cell)
		{
            cell->m_nIndex = index;
            cell->updateDisplayedAlpha(this->getAlpha());
			addSubview(cell);
			cell->setFrame(cellRect);
            m_mpUsedListCells[index] = cell;
            m_vpUsedListCells.pushBack(cell);
		}

		if (m_pSelectedListCells.count(index))
		{
			cell->setControlState(CAControlStateSelected);
		}
        
        if (m_pListViewDataSource)
        {
            m_pListViewDataSource->listViewWillDisplayCellAtIndex(this, cell, index);
        }
        
        CAView* view = this->dequeueReusableLine();
        DRect lineRect = m_rLineRects[index];
        if (view == NULL)
        {
            view = CAView::createWithFrame(lineRect, m_obSeparatorColor);
        }
        m_pUsedLines[index] = view;
        this->insertSubview(view, 1);
		view->setFrame(lineRect);
	}
}
Пример #6
0
void CAAutoCollectionView::updateSectionHeaderAndFooterRects()
{
	DRect rect = this->getBounds();
	rect.origin = getContentOffset();

	for (int i = 0; i < m_rCollectionViewSection.size(); i++)
	{
		CollectionViewSection& cvs = m_rCollectionViewSection[i];

		CC_CONTINUE_IF(!rect.intersectsRect(cvs.rSectionRect));

		CAView* header = cvs.pSectionHeaderView;
		CAView* footer = cvs.pSectionFooterView;
		
		float headerHeight = cvs.nSectionHeaderHeight;
		float footerHeight = cvs.nSectionFooterHeight;

		if (header && m_bAlwaysTopSectionHeader)
		{
			DPoint p1 = rect.origin;
			p1.y = MAX(p1.y, cvs.rSectionRect.origin.y);
			p1.y = MIN(p1.y, cvs.rSectionRect.origin.y + cvs.rSectionRect.size.height
				- headerHeight - footerHeight);
			header->setFrameOrigin(p1);
		}
		if (footer && m_bAlwaysBottomSectionFooter)
		{
			DPoint p2 = DPointZero;
			p2.y = MIN(rect.origin.y + this->getBounds().size.height - footerHeight,
				cvs.rSectionRect.origin.y + cvs.rSectionRect.size.height - footerHeight);
			p2.y = MAX(p2.y, cvs.rSectionRect.origin.y + headerHeight);
			footer->setFrameOrigin(p2);
		}
	}
}
Пример #7
0
void CAControl::setContentSize(const CCSize& var)
{
    CAView::setContentSize(var);
    
    for(int i=0; i<CAControlStateAll; i++)
    {
        CC_CONTINUE_IF(m_pBackGroundView[i] == NULL);
        m_pBackGroundView[i]->setFrame(this->getBounds());
    }
}
Пример #8
0
void CAButton::updateWithPreferredSize()
{
    for (int i=0; i<CAControlStateAll; i++)
    {
        CC_CONTINUE_IF(m_pBackGroundView[i] == NULL);
        CC_CONTINUE_IF(this->getBounds().equals(m_pBackGroundView[i]->getBounds()));
        
        if (CAScale9ImageView* _var = dynamic_cast<CAScale9ImageView*>(m_pBackGroundView[i]))
        {
            _var->setFrame(this->getBounds());
        }
        else
        {
            m_pBackGroundView[i]->setFrame(this->getBounds());
        }
    }
    
    m_pLabel->setFontSize(this->getBounds().size.height * 0.667f);
}
Пример #9
0
void CATabBarController::pageViewDidEndTurning(CAPageView* pageView)
{
    for (int i = MAX((int)m_nSelectedIndex - 1, 0);
         i < MIN((int)m_nSelectedIndex + 2, m_pViewControllers.size());
         i++)
    {
        CC_CONTINUE_IF(i == pageView->getCurrPage());
        m_pViewControllers.at(i)->getView()->setVisible(false);
    }
    CC_RETURN_IF(m_nSelectedIndex == pageView->getCurrPage());
    this->showSelectedViewControllerAtIndex(pageView->getCurrPage());
}
Пример #10
0
CAResponder* getLastResponder(CATouch* touch, const CAVector<CAView*>& subviews)
{
    CAResponder* lastResponder = NULL;
    
    for (CAVector<CAView*>::const_reverse_iterator itr=subviews.rbegin();
         itr!=subviews.rend();
         itr++)
    {
        CAView* subview = *itr;
        if (subview->isVisible())
        {
            if (CAViewController* viewController = dynamic_cast<CAViewController*>(subview->getContentContainer()))
            {
                CC_CONTINUE_IF(!viewController->isTouchEnabled());
                
                DPoint point = subview->convertTouchToNodeSpace(touch);
                
                if (subview->getBounds().containsPoint(point))
                {
                    lastResponder = viewController;
                    break;
                }
            }
            else
            {
                CC_CONTINUE_IF(!subview->isTouchEnabled());
                
                DPoint point = subview->convertTouchToNodeSpace(touch);
                
                if (subview->getBounds().containsPoint(point))
                {
                    lastResponder = subview;
                    break;
                }
            }
        }
    }
    
    return lastResponder;
}
Пример #11
0
void CATableView::loadTableCell()
{
    CCRect rect = this->getBounds();
	rect.origin = getContentOffset();
    rect.origin.y -= rect.size.height * 0.1f;
    rect.size.height *= 1.2f;
    
    for (unsigned int i=0; i<(unsigned int)m_rTableCellRectss.size(); i++)
    {
        for (unsigned int j=0; j<(unsigned int)m_rTableCellRectss.at(i).size(); j++)
        {
            CAIndexPath2E indexPath = CAIndexPath2E(i, j);
            CC_CONTINUE_IF(m_pUsedTableCells.count(indexPath) && m_pUsedTableCells[indexPath]);
            CCRect cellRect = m_rTableCellRectss[i][j];
            CC_CONTINUE_IF(!rect.intersectsRect(cellRect));
            CATableViewCell* cell = m_pTableViewDataSource->tableCellAtIndex(this, m_rTableCellRectss[i][j].size, i, j);
            CC_CONTINUE_IF(cell == NULL);
            cell->m_nSection = i;
            cell->m_nRow = j;
            cell->updateDisplayedAlpha(this->getAlpha());
            m_pContainer->addSubview(cell);
            cell->setFrame(m_rTableCellRectss[i][j]);
            m_pUsedTableCells[indexPath] = cell;
            if (m_pSelectedTableCells.count(indexPath))
            {
                cell->setControlStateSelected();
            }
            
            CAView* view = this->dequeueReusableLine();
            CCRect lineRect = m_rLineRectss[i][j];
            if (view == NULL)
            {
                view = CAView::createWithFrame(lineRect, m_obSeparatorColor);
            }
            m_pUsedLines[indexPath] = view;
            this->insertSubview(view, 1);
            view->setFrame(lineRect);
        }
    }
}
Пример #12
0
void CATabBarController::pageViewDidEndTurning(CAPageView* pageView)
{
    CAApplication::getApplication()->getTouchDispatcher()->setDispatchEventsTrue();
    for (int i = MAX((int)m_nSelectedIndex - 1, 0);
         i < MIN((int)m_nSelectedIndex + 2, m_pViewControllers.size());
         i++)
    {
        CC_CONTINUE_IF(i == pageView->getCurrPage());
        m_pViewControllers.at(i)->getView()->setVisible(false);
    }
    CC_RETURN_IF(m_nSelectedIndex == pageView->getCurrPage());
    this->showSelectedViewControllerAtIndex(pageView->getCurrPage());
}
void CACollectionView::recoveryCollectionCell()
{
	DRect rect = this->getBounds();
	rect.origin = getContentOffset();
	rect.origin.y -= rect.size.height * 0.1f;
	rect.size.height *= 1.2f;

	std::map<CAIndexPath3E, CACollectionViewCell*>::iterator itr;
	for (itr = m_mpUsedCollectionCells.begin(); itr != m_mpUsedCollectionCells.end(); itr++)
	{
		CACollectionViewCell* cell = itr->second;
		CC_CONTINUE_IF(cell == NULL);

		DRect cellRect = cell->getFrame();
		CC_CONTINUE_IF(rect.intersectsRect(cellRect));

		m_mpFreedCollectionCells[cell->getReuseIdentifier()].pushBack(cell);
		cell->removeFromSuperview();
		cell->resetCollectionViewCell();
		itr->second = NULL;
        m_vpUsedCollectionCells.eraseObject(cell);
	}
}
Пример #14
0
void CAButton::setContentSize(const CCSize & var)
{
    CCSize size = var;
    size.height = MAX(size.height, _px(60));
    size.width = MAX(size.width, size.height);
    CAView::setContentSize(size);
    for(int i=0; i<CAControlStateAll; i++)
    {
        CC_CONTINUE_IF(m_pBackGroundView[i] == NULL);
        m_pBackGroundView[i]->setFrame(this->getBounds());
    }
    
    this->updateWithPreferredSize();
    this->setControlState(m_eControlState);
}
Пример #15
0
void CATouchController::touchBegan()
{
    m_tFirstPoint = m_pTouch->getLocation();
    
    std::vector<CAResponder*> vector;
    
    CAView* view = dynamic_cast<CAView*>(CAApplication::getApplication()->getTouchDispatcher()->getFirstResponder());
    bool isContainsFirstPoint = view && view->convertRectToWorldSpace(view->getBounds()).containsPoint(m_tFirstPoint);
    if (isContainsFirstPoint)
    {
        vector = this->getEventListener(m_pTouch, view);
    }
    else
    {
        vector = this->getEventListener(m_pTouch, CAApplication::getApplication()->getRootWindow());
    }
    
    std::vector<CAResponder*>::iterator itr;
    for (itr=vector.begin(); itr!=vector.end(); itr++)
    {
        CC_CONTINUE_IF(!(*itr)->isPriorityScroll());
        CC_CONTINUE_IF(!(*itr)->isScrollEnabled());
        CC_CONTINUE_IF(!(*itr)->isHorizontalScrollEnabled() && !(*itr)->isVerticalScrollEnabled());
        m_vTouchMovedsViewCache.pushBack((*itr));
    }
    m_vTouchesViews.pushBack(vector.back());
    
    if (!m_vTouchMovedsViewCache.empty())
    {
        CAScheduler::schedule(schedule_selector(CATouchController::passingTouchesViews), this, 0, 0, 0.05f);
    }
    else
    {
        this->passingTouchesViews();
    }
}
Пример #16
0
void CATouchDispatcher::touchesMoved(CCSet *touches, CAEvent *pEvent)
{
    m_bLocked = true;
    
    CATouch *pTouch;
    CCSetIterator setIter;
    for (setIter = touches->begin(); setIter != touches->end(); setIter++)
    {
        pTouch = (CATouch *)(*setIter);
        
        CATouchController* touchController = m_vTouchControllers[pTouch->getID()];
        CC_CONTINUE_IF(touchController == NULL);
        touchController->touchMoved();
    }
    m_bLocked = false;
}
Пример #17
0
bool CAAutoCollectionView::ccTouchBegan(CATouch *pTouch, CAEvent *pEvent)
{
    if (!m_vTouches.empty())
    {
        m_vTouches.replace(0, pTouch);
        return true;
    }
	bool isInertia = m_tInertia.getLength() < 1.0f;
	if (!CAScrollView::ccTouchBegan(pTouch, pEvent))
		return false;

	if (m_bAllowsSelection && this->isScrollWindowNotOutSide() == false && isInertia)
	{
		DPoint point = m_pContainer->convertTouchToNodeSpace(pTouch);

		std::map<CAIndexPath3E, CACollectionViewCell*>::iterator itr;
		for (itr = m_mpUsedCollectionCells.begin(); itr != m_mpUsedCollectionCells.end(); ++itr)
		{
			CACollectionViewCell* pCell = itr->second;
			CC_CONTINUE_IF(pCell == NULL);

			if (pCell->getFrame().containsPoint(point) && pCell->isVisible())
			{
				CC_BREAK_IF(pCell->getControlState() == CAControlStateDisabled);

                if (m_pHighlightedCollectionCells != pCell)
                {
                    if (m_pHighlightedCollectionCells)
                    {
                        m_pHighlightedCollectionCells->setControlStateNormal();
                    }
                    
                    m_pHighlightedCollectionCells = pCell;
                }

				CC_BREAK_IF(pCell->getControlState() == CAControlStateSelected);

                CAViewAnimation::beginAnimations(m_s__StrID, NULL);
                CAViewAnimation::setAnimationDuration(0.05f);
                CAViewAnimation::setAnimationDidStopSelector(pCell, CAViewAnimation0_selector(CACollectionViewCell::setControlStateHighlighted));
                CAViewAnimation::commitAnimations();
				break;
			}
		}
	}
	return true;
}
Пример #18
0
void CATableView::clearData()
{
    m_nSections = 0;
    m_nRowsInSections.clear();
    m_nSectionHeaderHeights.clear();
    m_nSectionFooterHeights.clear();
    std::vector<std::vector<unsigned int> >::iterator itr;
    for (itr=m_nRowHeightss.begin(); itr!=m_nRowHeightss.end(); itr++)
    {
        itr->clear();
    }
    m_nRowHeightss.clear();
    
    std::vector<std::vector<CCRect> >::iterator itr2;
    for (itr2=m_rTableCellRectss.begin(); itr2!=m_rTableCellRectss.end(); itr2++)
    {
        itr2->clear();
    }
    m_rTableCellRectss.clear();
    
    m_rSectionRects.clear();
    
    std::vector<std::vector<CCRect> >::iterator itr3;
    for (itr3=m_rLineRectss.begin(); itr3!=m_rLineRectss.end(); itr3++)
    {
        itr3->clear();
    }
    m_rLineRectss.clear();
    
    m_pSelectedTableCells.clear();
    m_pUsedLines.clear();
    
    std::map<CAIndexPath2E, CATableViewCell*>::iterator itr4;
    for (itr4=m_pUsedTableCells.begin(); itr4!=m_pUsedTableCells.end(); itr4++)
    {
        CATableViewCell* cell = itr4->second;
        CC_CONTINUE_IF(cell == NULL);
        m_pFreedTableCells[cell->getReuseIdentifier()].pushBack(cell);
        itr4->second = NULL;
        cell->removeFromSuperview();
        cell->resetTableViewCell();
    }
    m_pUsedTableCells.clear();
    m_pSectionHeaderViews.clear();
    m_pSectionHeaderViews.clear();
}
Пример #19
0
bool CAListView::ccTouchBegan(CATouch *pTouch, CAEvent *pEvent)
{
	if (m_pTouches->count() > 0)
	{
		m_pTouches->replaceObjectAtIndex(0, pTouch);
		return true;
	}
    bool isInertia = m_tInertia.getLength() < 1.0f;
	if (!CAScrollView::ccTouchBegan(pTouch, pEvent))
		return false;

	if (m_bAllowsSelection && this->isScrollWindowNotOutSide() == false && isInertia)
	{
		CCPoint point = m_pContainer->convertTouchToNodeSpace(pTouch);

		std::map<unsigned int, CAListViewCell*>::iterator itr;
		for (itr = m_pUsedListCells.begin(); itr != m_pUsedListCells.end(); ++itr)
		{
			CAListViewCell* pCell = itr->second;
			CC_CONTINUE_IF(pCell == NULL);

			if (pCell->getFrame().containsPoint(point) && pCell->isVisible())
			{
				CC_BREAK_IF(pCell->getControlState() == CAControlStateDisabled);

				if (m_pHighlightedListCells)
				{
					m_pHighlightedListCells->setControlStateNormal();
				}

				m_pHighlightedListCells = pCell;

				CC_BREAK_IF(pCell->getControlState() == CAControlStateSelected);

				CCDelayTime* delayTime = CCDelayTime::create(0.05f);
				CCCallFunc* func = CCCallFunc::create(pCell, callfunc_selector(CAListViewCell::setControlStateHighlighted));
				CCSequence* actions = CCSequence::create(delayTime, func, NULL);
				m_pContainer->runAction(actions);
				break;
			}
		}
	}
	return true;
}
Пример #20
0
void CCEGLViewProtocol::getSetOfTouchesEndOrCancel(CCSet& set, int num, int ids[], float xs[], float ys[])
{
    for (int i = 0; i < num; ++i)
    {
        int id = ids[i];
        float x = xs[i];
        float y = ys[i];

        CC_CONTINUE_IF(s_TouchesIntergerDict.find(id) == s_TouchesIntergerDict.end());
        int index = s_TouchesIntergerDict.at(id);

        /* Add to the set to send to the director */
        CATouch* pTouch = s_pTouches[index];
        if (pTouch)
        {
            CCLOGINFO("Ending touches with id: %d, x=%f, y=%f", id, x, y);
            pTouch->setTouchInfo(index,
                                 (x - m_obViewPortRect.origin.x) / m_fScaleX,
                                 (y - m_obViewPortRect.origin.y) / m_fScaleY);

            set.addObject(pTouch);

            // release the object
            pTouch->release();
            s_pTouches[index] = NULL;
            removeUsedIndexBit(index);

            s_TouchesIntergerDict.erase(id);

        }
        else
        {
            CCLOG("Ending touches with id: %d error", id);
            return;
        }

    }

    if (set.count() == 0)
    {
        CCLOG("touchesEnded or touchesCancel: count = 0");
        return;
    }
}
Пример #21
0
void CAAutoCollectionView::clearData()
{
	m_mpUsedCollectionCells.clear();
	m_rUsedCollectionCellRects.clear();
	m_pSelectedCollectionCells.clear();
	m_rCollectionViewSection.clear();

	for (int i = 0; i < m_vpUsedCollectionCells.size(); i++)
	{
		CACollectionViewCell* cell = m_vpUsedCollectionCells.at(i);
		CC_CONTINUE_IF(cell == NULL);
		m_mpFreedCollectionCells[cell->getReuseIdentifier()].pushBack(cell);
		cell->removeFromSuperview();
		cell->resetCollectionViewCell();
	}
	m_vpUsedCollectionCells.clear();

	m_pHighlightedCollectionCells = NULL;
}
void CACollectionView::updateSectionHeaderAndFooterRects()
{
	DRect rect = this->getBounds();
	rect.origin = getContentOffset();

	std::vector<DRect>::iterator itr;
	for (itr = m_rSectionRects.begin(); itr != m_rSectionRects.end(); itr++)
	{
		CC_CONTINUE_IF(!rect.intersectsRect(*itr));
		int i = (int)(itr - m_rSectionRects.begin());
		CAView* header = NULL;
		CAView* footer = NULL;
		float headerHeight = 0;
		float footerHeight = 0;
		if (m_pSectionHeaderViews.find(i) != m_pSectionHeaderViews.end())
		{
			header = m_pSectionHeaderViews[i];
			headerHeight = m_pSectionHeaderViews[i]->getFrame().size.height;
		}
		if (m_pSectionFooterViews.find(i) != m_pSectionFooterViews.end())
		{
			footer = m_pSectionFooterViews[i];
			footerHeight = m_pSectionFooterViews[i]->getFrame().size.height;
		}
		if (header && m_bAlwaysTopSectionHeader)
		{
			DPoint p1 = rect.origin;
			p1.y = MAX(p1.y, itr->origin.y);
			p1.y = MIN(p1.y, itr->origin.y + itr->size.height
				- headerHeight - footerHeight);
			header->setFrameOrigin(p1);
		}
		if (footer && m_bAlwaysBottomSectionFooter)
		{
			DPoint p2 = DPointZero;
			p2.y = MIN(rect.origin.y + this->getBounds().size.height - footerHeight,
				itr->origin.y + itr->size.height - footerHeight);
			p2.y = MAX(p2.y, itr->origin.y + headerHeight);
			footer->setFrameOrigin(p2);
		}
	}
}
Пример #23
0
void CATabBarController::renderingSelectedViewController()
{
    m_pTabBar->setSelectedAtIndex(m_nSelectedIndex);
    
    for (int i=0; i<m_pViewControllers.size(); i++)
    {
        CC_CONTINUE_IF(!m_pViewControllers.at(i)->getView()->isVisible());
        m_pViewControllers.at(i)->getView()->setVisible(false);
        m_pViewControllers.at(i)->viewDidDisappear();
    }
    
    if (m_pViewControllers.at(m_nSelectedIndex)->getView()->getSuperview() == NULL)
    {
        m_pViewControllers.at(m_nSelectedIndex)->getView()->setFrame(m_pContainer->getBounds());
        m_pViewControllers.at(m_nSelectedIndex)->addViewFromSuperview(m_pContainer);
    }
    
    m_pViewControllers.at(m_nSelectedIndex)->getView()->setVisible(true);
    m_pViewControllers.at(m_nSelectedIndex)->viewDidAppear();
}
Пример #24
0
CABatchView * CABatchView::addViewWithoutQuad(CAView* view, unsigned int z, int aTag)
{
    CCAssert( view != NULL, "Argument must be non-NULL");

    view->setAtlasIndex(z);

    int i=0;
 
    CAVector<CAView*>::iterator itr;
    for (itr=m_obDescendants.begin(); itr!=m_obDescendants.end(); itr++)
    {
        CC_CONTINUE_IF((*itr)->getAtlasIndex() < z);
        ++i;
    }
    m_obDescendants.insert(i, view);

    CAView::insertSubview(view, z);
    view->setTag(aTag);
    reorderBatch(false);

    return this;
}
void CACollectionView::mouseMoved(CATouch* pTouch, CAEvent* pEvent)
{
    if (m_bAllowsSelection)
    {
        DPoint point = m_pContainer->convertTouchToNodeSpace(pTouch);
        
        std::map<CAIndexPath3E, CACollectionViewCell*>::iterator itr;
        for (itr = m_mpUsedCollectionCells.begin(); itr != m_mpUsedCollectionCells.end(); ++itr)
        {
            CACollectionViewCell* cell = itr->second;
            CC_CONTINUE_IF(cell == NULL);
            if (cell->getFrame().containsPoint(point) && cell->isVisible())
            {
                CC_BREAK_IF(cell->getControlState() == CAControlStateDisabled);
                
                if (m_pHighlightedCollectionCells)
                {
                    CAIndexPath3E index = CAIndexPath3E(m_pHighlightedCollectionCells->getSection(),
                                                        m_pHighlightedCollectionCells->getRow(),
                                                        m_pHighlightedCollectionCells->getItem());
                    if (m_pSelectedCollectionCells.count(index))
                    {
                        m_pHighlightedCollectionCells->setControlStateHighlighted();
                    }
                    else
                    {
                        m_pHighlightedCollectionCells->setControlStateNormal();
                    }
                    
                }
                
                m_pHighlightedCollectionCells = cell;
                cell->setControlStateHighlighted();
                
                break;
            }
        }
    }
}
Пример #26
0
void CATabBarController::update(float dt)
{
    CCRect rect = m_pContainer->getFrame();
    CCSize size = m_pContainer->getViewSize();

    switch (m_eTabBarVerticalAlignment)
    {
    case CABarVerticalAlignmentTop:
    {
        rect.origin.y = m_pTabBar->getFrame().origin.y + m_pTabBar->getFrame().size.height;
        rect.size.height = this->getView()->getBounds().size.height - rect.origin.y;
    }
    break;
    case CABarVerticalAlignmentBottom:
    {
        rect.size.height = m_pTabBar->getFrame().origin.y;
    }
    break;
    default:
        break;
    }
    size.height = rect.size.height;

    m_pContainer->setFrame(rect);
    CCPoint point = m_pContainer->getContentOffset();
    m_pContainer->setViewSize(size);
    m_pContainer->setContentOffset(point, false);

    for (unsigned int i=0; i<m_pViewControllers.size(); i++)
    {
        CAViewController* viewController = m_pViewControllers.at(i);
        CAView* superview = viewController->getView()->getSuperview();
        CC_CONTINUE_IF(superview == NULL);
        rect.origin.x = superview->getFrameOrigin().x;
        rect.origin.y = 0;
        superview->setFrame(rect);
        viewController->getSuperViewRect(superview->getBounds());
    }
}
Пример #27
0
void CAListView::mouseMoved(CATouch* pTouch, CAEvent* pEvent)
{
    if (m_bAllowsSelection)
    {
        DPoint point = m_pContainer->convertTouchToNodeSpace(pTouch);
        
        std::map<unsigned int, CAListViewCell*>::iterator itr;
        for (itr = m_mpUsedListCells.begin(); itr != m_mpUsedListCells.end(); ++itr)
        {
            CAListViewCell* pCell = itr->second;
            CC_CONTINUE_IF(pCell == NULL);
            
            if (pCell->getFrame().containsPoint(point) && pCell->isVisible())
            {
                CC_BREAK_IF(pCell->getControlState() == CAControlStateDisabled);
                
                if (m_pHighlightedListCells)
                {
                    unsigned int index = m_pHighlightedListCells->getIndex();
                    if (m_pSelectedListCells.count(index))
                    {
                        m_pHighlightedListCells->setControlStateHighlighted();
                    }
                    else
                    {
                        m_pHighlightedListCells->setControlStateNormal();
                    }
                    
                }
                
                m_pHighlightedListCells = pCell;
                pCell->setControlStateHighlighted();

                break;
            }
        }
    }
}
Пример #28
0
void CCEGLViewProtocol::handleTouchesMove(int num, int ids[], float xs[], float ys[])
{
    CCSet set;
    for (int i = 0; i < num; ++i)
    {
        int id = ids[i];
        float x = xs[i];
        float y = ys[i];

        CC_CONTINUE_IF(s_TouchesIntergerDict.find(id) == s_TouchesIntergerDict.end());
        int index = s_TouchesIntergerDict.at(id);

        CCLOGINFO("Moving touches with id: %d, x=%f, y=%f", id, x, y);
        CATouch* pTouch = s_pTouches[index];
        if (pTouch)
        {
            pTouch->setTouchInfo(index,
                                 (x - m_obViewPortRect.origin.x) / m_fScaleX,
                                 (y - m_obViewPortRect.origin.y) / m_fScaleY);

            set.addObject(pTouch);
        }
        else
        {
            // It is error, should return.
            CCLOG("Moving touches with id: %d error", id);
            return;
        }
    }

    if (set.count() == 0)
    {
        CCLOG("touchesMoved: count = 0");
        return;
    }

    m_pDelegate->touchesMoved(&set, NULL);
}
Пример #29
0
void CAListView::reloadData()
{
	if (m_pListViewDataSource == NULL)
		return;
    
    this->reloadViewSizeData();
    
    this->removeAllSubviews();
    
    m_pUsedLines.clear();
	m_pUsedListCells.clear();
	m_pFreedListCells.clear();
    m_pSelectedListCells.clear();
	
	CCRect winRect = this->getBounds();
    winRect.origin = this->getContentOffset();
    
	if (m_nListHeaderHeight > 0)
	{
		if (m_pListHeaderView)
		{
			m_pListHeaderView->setFrame(m_rHeaderRect);
			addSubview(m_pListHeaderView);
		}
	}

	unsigned int cellCount = m_pListViewDataSource->numberOfIndex(this);
	for (unsigned i = 0; i < cellCount; i++)
	{
		if (m_nIndexs > 0)
		{
			std::pair<std::map<unsigned int, CAListViewCell*>::iterator, bool> itrResult =
				m_pUsedListCells.insert(std::make_pair(i, (CAListViewCell*)NULL));

			CC_CONTINUE_IF(!winRect.intersectsRect(m_rIndexRects[i]));

			CAListViewCell* pCellView = m_pListViewDataSource->listViewCellAtIndex(this, m_rIndexRects[i].size, i);
			if (pCellView)
			{
				pCellView->m_nIndex = i;
				pCellView->setFrame(m_rIndexRects[i]);
				addSubview(pCellView);
				itrResult.first->second = pCellView;
			}
		}
        
		if (m_nSeparatorViewHeight > 0)
		{
			CAView* view = CAView::createWithFrame(m_rLineRects[i], m_obSeparatorColor);
			addSubview(view);
            m_pUsedLines[i] = view;
		}
	}

	if (m_nListFooterHeight > 0)
	{
		if (m_pListFooterView)
		{
			m_pListFooterView->setFrame(m_rFooterRect);
			addSubview(m_pListFooterView);
		}
	}
    this->layoutPullToRefreshView();
    this->startDeaccelerateScroll();
}
void CACollectionView::reloadData()
{
	CC_RETURN_IF(m_pCollectionViewDataSource == NULL);
    
	this->reloadViewSizeData();
    
	this->removeAllSubviews();
    
	DRect winRect = this->getBounds();
	winRect.origin = getContentOffset();
	float width = winRect.size.width;
	int y = 0;
    
	if (m_nCollectionHeaderHeight > 0 && m_pCollectionHeaderView)
	{
		m_pCollectionHeaderView->setDisplayRange(true);
		m_pCollectionHeaderView->setFrame(DRect(0, y, width, m_nCollectionHeaderHeight));
		addSubview(m_pCollectionHeaderView);
		y += m_nCollectionHeaderHeight;
	}
    
;
    int begin = (int)m_rSectionRects.size();
    m_rSectionRects.resize(m_rSectionRects.size() + m_nSections);
	for (int i = 0; i < m_nSections; i++)
	{
		unsigned int iSectionHeaderHeight = m_nSectionHeaderHeights.at(i);
		DRect sectionHeaderRect = DRect(0, y, width, iSectionHeaderHeight);
		if (iSectionHeaderHeight>0)
		{
			CAView* pSectionHeaderView = m_pCollectionViewDataSource->collectionViewSectionViewForHeaderInSection(this, sectionHeaderRect.size, i);
			if (pSectionHeaderView != NULL)
			{
				pSectionHeaderView->setDisplayRange(true);
				pSectionHeaderView->setFrame(sectionHeaderRect);
				insertSubview(pSectionHeaderView, 1);
				m_pSectionHeaderViews[i] = pSectionHeaderView;
				y += iSectionHeaderHeight;
			}
		}
        
		y += m_nVertInterval;
		unsigned int rowCount = m_nRowsInSections.at(i);
		for (int j = 0; j < rowCount; j++)
		{
			int iHeight = m_nRowHeightss.at(i).at(j);
            
			unsigned int itemCount = m_pCollectionViewDataSource->numberOfItemsInRowsInSection(this, i, j);
            
			unsigned int cellWidth = 0;
			if (itemCount>0)
			{
				cellWidth = (width - m_nHoriInterval) / itemCount - m_nHoriInterval;
			}
			for (int k = 0; k < itemCount; k++)
			{
				CAIndexPath3E indexPath = CAIndexPath3E(i, j, k);
				DRect cellRect = DRect(m_nHoriInterval + (cellWidth + m_nHoriInterval)*k, y, cellWidth, iHeight);
				m_rUsedCollectionCellRects[indexPath] = cellRect;
                
				std::pair<std::map<CAIndexPath3E, CACollectionViewCell*>::iterator, bool> itrResult =
                m_mpUsedCollectionCells.insert(std::make_pair(indexPath, (CACollectionViewCell*)NULL));
                
				CC_CONTINUE_IF(!winRect.intersectsRect(cellRect));
                
				CACollectionViewCell* cell = m_pCollectionViewDataSource->collectionCellAtIndex(this, cellRect.size, i, j, k);
				if (cell)
				{
					addSubview(cell);
					cell->setFrame(cellRect);
					cell->m_nSection = i;
					cell->m_nRow = j;
					cell->m_nItem = k;
					itrResult.first->second = cell;
                    m_vpUsedCollectionCells.pushBack(cell);
                    
                    if (m_pCollectionViewDataSource)
                    {
                        m_pCollectionViewDataSource->collectionViewWillDisplayCellAtIndex(this, cell, i, j, k);
                    }
				}
			}
			y += (iHeight + m_nVertInterval);
		}
        
		unsigned int iSectionFooterHeight = m_nSectionFooterHeights.at(i);
		DRect sectionFooterRect = DRect(0, y, width, iSectionFooterHeight);
		if (iSectionFooterHeight > 0)
		{
			CAView* pSectionFooterView = m_pCollectionViewDataSource->collectionViewSectionViewForFooterInSection(this, sectionFooterRect.size, i);
			if (pSectionFooterView != NULL)
			{
				pSectionFooterView->setDisplayRange(true);
				pSectionFooterView->setFrame(sectionFooterRect);
				insertSubview(pSectionFooterView, 1);
				m_pSectionFooterViews[i] = pSectionFooterView;
				y += iSectionFooterHeight;
			}
		}
        
		DRect sectionRect = sectionHeaderRect;
		sectionRect.size.height = sectionFooterRect.origin.y
        + sectionFooterRect.size.height
        - sectionHeaderRect.origin.y;
        m_rSectionRects[begin + i] = sectionRect;
	}
    
	if (m_nCollectionFooterHeight > 0 && m_pCollectionFooterView)
	{
		m_pCollectionFooterView->setFrame(DRect(0, y, width, m_nCollectionFooterHeight));
		addSubview(m_pCollectionFooterView);
		y += m_nCollectionFooterHeight;
	}
    
	this->updateSectionHeaderAndFooterRects();
	this->layoutPullToRefreshView();
	this->startDeaccelerateScroll();
}