void CATabBarController::viewDidLoad() { CCPoint tab_bar_rectOrgin = CCPointZero; CCRect container_rect = this->getView()->getBounds(); CCSize container_view_size = container_rect.size; container_view_size.width *= m_pViewControllers.size(); if (m_bTabBarHidden) { tab_bar_rectOrgin = this->getTabBarTakeBackPoint(); } else { tab_bar_rectOrgin = this->getTabBarOpenPoint(); container_rect.size.height -= m_pTabBar->getFrame().size.height; if (m_eTabBarVerticalAlignment == CABarVerticalAlignmentTop) { container_rect.origin.y = m_pTabBar->getFrame().size.height; } } m_pContainer = CAPageView::createWithFrame(container_rect, CAPageView::CAPageViewDirectionHorizontal); m_pContainer->setBackGroundColor(CAColor_clear); m_pContainer->setPageViewDelegate(this); m_pContainer->setScrollViewDelegate(this); m_pContainer->setScrollEnabled(m_bscrollEnabled); m_pContainer->setDisplayRange(true); this->getView()->addSubview(m_pContainer); CAVector<CAView*> views; for (int i=0; i<m_pViewControllers.size(); i++) { CAView* view = new CAView(); views.pushBack(view); view->release(); } m_pContainer->setViews(views); if (m_pTabBarBackGroundImage) { m_pTabBar->setBackGroundImage(m_pTabBarBackGroundImage); } else { m_pTabBar->setBackGroundColor(m_sTabBarBackGroundColor); } if (m_pTabBarSelectedBackGroundImage) { m_pTabBar->setSelectedBackGroundImage(m_pTabBarSelectedBackGroundImage); } else { m_pTabBar->setSelectedBackGroundColor(m_sTabBarSelectedBackGroundColor); } if (m_pTabBarSelectedIndicatorImage) { m_pTabBar->setSelectedIndicatorImage(m_pTabBarSelectedIndicatorImage); } else { m_pTabBar->setSelectedIndicatorColor(m_sTabBarSelectedBackGroundColor); } m_pTabBar->setTitleColorForNormal(m_sTabBarTitleColor); m_pTabBar->setTitleColorForSelected(m_sTabBarSelectedTitleColor); if (m_bShowTabBarSelectedIndicator) { m_pTabBar->showSelectedIndicator(); } m_pTabBar->setFrameOrigin(tab_bar_rectOrgin); this->getView()->addSubview(m_pTabBar); m_pTabBar->setSelectedAtIndex(m_nSelectedIndex); this->renderingSelectedViewController(); }
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(); }
void CAPickerView::reloadAllComponents() { if (m_delegate && m_dataSource) { // clear old data m_tableViews.clear(); m_selected.clear(); m_componentsIndex.clear(); m_displayRow.clear(); // clear all tableviews removeAllSubviews(); // reload data int component = m_dataSource->numberOfComponentsInPickerView(this); float total_width = calcTotalWidth(component); m_componentsIndex.resize(component); m_componentOffsetX.resize(component); m_displayRow.resize(component); float start_x = getFrame().size.width/2 - total_width/2; for (int i=0; i<component; i++) { m_selected.push_back(0); m_componentsIndex[i] = std::vector<int>(); m_componentOffsetX[i] = start_x; m_displayRow[i] = getFrame().size.height/m_dataSource->rowHeightForComponent(this, i); if (m_displayRow[i] % 2 == 0) { m_displayRow[i] += 1; } // create tableview float tableWidth = m_dataSource->widthForComponent(this, i); float tableHeight = m_dataSource->rowHeightForComponent(this, i) * m_displayRow[i]; float start_y = getFrame().size.height/2 - tableHeight/2; CATableView* tableView = CATableView::createWithFrame(CCRect(start_x, start_y, tableWidth, tableHeight)); tableView->setTableViewDataSource(this); tableView->setScrollViewDelegate(this); tableView->setSeparatorViewHeight(0); tableView->setSeparatorColor(CAColor_clear); tableView->setShowsScrollIndicators(false); m_tableViews.pushBack(tableView); addSubview(tableView); // create highlight CCSize selectSize = CCSizeMake(tableWidth, m_dataSource->rowHeightForComponent(this, i)); CAView* select = m_dataSource->viewForSelect(this, i, selectSize); if (!select) { CCRect sepRect = CCRectMake(start_x, getFrame().size.height/2 - m_dataSource->rowHeightForComponent(this, i)/2, tableWidth, 1); addSubview(CAView::createWithFrame(sepRect, m_separateColor)); sepRect.origin.y += m_dataSource->rowHeightForComponent(this, i); addSubview(CAView::createWithFrame(sepRect, m_separateColor)); } else { select->setCenter(CCRectMake(start_x, getFrame().size.height/2, selectSize.width, selectSize.height)); addSubview(select); } reloadComponent(1,i, true); start_x += m_dataSource->widthForComponent(this, i); } } }
void CATabBar::showItems() { do { CC_BREAK_IF(m_pViews.empty() == false); unsigned int count = MIN(m_nMaxShowCount, m_pItems.size()); float width = m_obContentSize.width / count; float height = m_obContentSize.height; m_cItemSize = CCSize(width, height); for (unsigned int i=0; i<count; i++) { CAView* view = CAView::createWithFrame(CCRect(i * width, 0, width, height), ccc4(0, 0, 0, 0)); this->insertSubview(view, 3); view->setDisplayRange(false); m_pViews.push_back(view); CAImageView* imageView = NULL; CCLabelTTF* title = NULL; if (m_pItems.at(i)->getImage()) { imageView = CAImageView::createWithImage(m_pItems.at(i)->getImage()); imageView->setTag(0xffff); view->addSubview(imageView); } if (m_pItems.at(i)->getTitle().compare("") != 0) { int fontSize = this->getContentSize().height / 5.0f; title = CCLabelTTF::create(m_pItems.at(i)->getTitle().c_str(), "Arial", fontSize); title->setTag(0xfffe); view->addSubview(title); } if (imageView && title == NULL) { CCSize imageViewSize = imageView->getBounds().size; float scaleX = width / imageViewSize.width * 2/3.0f; float scaleY = height / imageViewSize.height * 2/3.0f; float scale = MIN(scaleX, scaleY); scale = MIN(scale, 1.0f); imageViewSize = ccpMult(imageViewSize, scale); CCRect rect; rect.origin = view->getBounds().size/2; rect.size = imageViewSize; imageView->setCenter(rect); } else if (title && imageView == NULL) { int fontSize = this->getContentSize().height / 2.0f; title->setFontSize(fontSize); CCSize titleSize = title->getBounds().size; float titleScale = height / titleSize.height * 1/2.0f; titleSize = ccpMult(titleSize, titleScale); CCRect rect; rect.origin = view->getBounds().size/2; rect.size = titleSize; title->setCenter(rect); } else if (title && imageView) { CCSize imageViewSize = imageView->getBounds().size; float scaleX = width / imageViewSize.width * 1/2.0f; float scaleY = height / imageViewSize.height * 1/2.0f; float scale = MIN(scaleX, scaleY); scale = MIN(scale, 1.0f); imageViewSize = ccpMult(imageViewSize, scale); CCRect rect; rect.size = imageViewSize; rect.origin = view->getBounds().size; rect.origin.x *= 1/2.0f; rect.origin.y *= 7/20.0f; imageView->setCenter(rect); CCSize titleSize = title->getBounds().size; float titleScale = height / titleSize.height * 3/10; titleSize = ccpMult(titleSize, titleScale); CCRect rect2; rect2.size = titleSize; rect2.origin = view->getBounds().size; rect2.origin.x *= 1/2.0f; rect2.origin.y *= 15/20.0f; title->setCenter(rect2); } } } while (0); }
void CATouchController::touchMoved() { CC_RETURN_IF(ccpDistance(m_tFirstPoint, m_pTouch->getLocation()) < _px(32)); m_tFirstPoint = CCPointZero; if (!m_vTouchMovedsViewCache.empty()) { bool isScheduledPassing = CAScheduler::isScheduled(schedule_selector(CATouchController::passingTouchesViews), this); CAScheduler::unschedule(schedule_selector(CATouchController::passingTouchesViews), this); while (!m_vTouchMovedsViewCache.empty()) { CAResponder* responder = m_vTouchMovedsViewCache.back(); CCPoint pointOffSet = CCPointZero; if (CAView* v = dynamic_cast<CAView*>(responder)) { pointOffSet = ccpSub(v->convertToNodeSpace(m_pTouch->getLocation()), v->convertToNodeSpace(m_pTouch->getPreviousLocation())); } else if (CAViewController* c = dynamic_cast<CAViewController*>(responder)) { pointOffSet = ccpSub(c->getView()->convertToNodeSpace(m_pTouch->getLocation()), c->getView()->convertToNodeSpace(m_pTouch->getPreviousLocation())); } else { pointOffSet = ccpSub(m_pTouch->getLocation(), m_pTouch->getPreviousLocation()); } pointOffSet.x = fabsf(pointOffSet.x); pointOffSet.y = fabsf(pointOffSet.y); do { CC_BREAK_IF(!responder->isTouchMovedListenHorizontal() && pointOffSet.x >= pointOffSet.y); CC_BREAK_IF(!responder->isTouchMovedListenVertical() && pointOffSet.x < pointOffSet.y); m_vTouchMovedsView.pushBack(m_vTouchMovedsViewCache.back()); } while (0); m_vTouchMovedsViewCache.popBack(); } CAVector<CAResponder * > tTouchesViews = m_vTouchesViews; if (!m_vTouchMovedsView.empty()) { if (!isScheduledPassing) { CAVector<CAResponder*>::iterator itr; // for (itr = m_vTouchMovedsView.begin(); itr != m_vTouchMovedsView.end(); itr++) { m_vTouchesViews.eraseObject(*itr, true); } // for (itr=m_vTouchesViews.begin(); itr!=m_vTouchesViews.end(); itr++) { (*itr)->ccTouchCancelled(m_pTouch, m_pEvent); } } { m_vTouchesViews.clear(); for (int i=0; i<m_vTouchMovedsView.size(); i++) { CAResponder* responder = m_vTouchMovedsView.at(i); CCPoint pointOffSet = CCPointZero; if (CAView* v = dynamic_cast<CAView*>(responder)) { pointOffSet = ccpSub(v->convertToNodeSpace(m_pTouch->getLocation()), v->convertToNodeSpace(m_pTouch->getPreviousLocation())); } else if (CAViewController* c = dynamic_cast<CAViewController*>(responder)) { pointOffSet = ccpSub(c->getView()->convertToNodeSpace(m_pTouch->getLocation()), c->getView()->convertToNodeSpace(m_pTouch->getPreviousLocation())); } else { pointOffSet = ccpSub(m_pTouch->getLocation(), m_pTouch->getPreviousLocation()); } if (responder->isTouchMovedListenHorizontal() && fabsf(pointOffSet.x) >= fabsf(pointOffSet.y)) { CC_CONTINUE_IF(responder->isSlidingMinX() && pointOffSet.x > 0); CC_CONTINUE_IF(responder->isSlidingMaxX() && pointOffSet.x < 0); } if (responder->isTouchMovedListenVertical() && fabsf(pointOffSet.x) < fabsf(pointOffSet.y)) { CC_CONTINUE_IF(responder->isSlidingMinY() && pointOffSet.y > 0); CC_CONTINUE_IF(responder->isSlidingMaxY() && pointOffSet.y < 0); } m_vTouchesViews.pushBack(responder); if (tTouchesViews.contains(responder)==false) { responder->ccTouchBegan(m_pTouch, m_pEvent); } break; } if (m_vTouchesViews.empty()) { m_vTouchesViews.pushBack(m_vTouchMovedsView.front()); if (tTouchesViews.contains(m_vTouchesViews.back())==false) { m_vTouchesViews.back()->ccTouchBegan(m_pTouch, m_pEvent);// } } } } } CAView* view = dynamic_cast<CAView*>(CAApplication::getApplication()->getTouchDispatcher()->getFirstResponder()); bool isContainsFirstPoint = view && view->convertRectToWorldSpace(view->getBounds()).containsPoint(m_tFirstPoint); if (!isContainsFirstPoint && view) { view->ccTouchMoved(m_pTouch, m_pEvent); } CAVector<CAResponder*>::iterator itr; for (itr=m_vTouchesViews.begin(); itr!=m_vTouchesViews.end(); itr++) { (*itr)->ccTouchMoved(m_pTouch, m_pEvent); } }
std::vector<CAResponder*> CATouchController::getEventListener(CATouch* touch, CAView* view) { CAResponder* responder = view; std::vector<CAResponder*> vector; do { vector.push_back(responder); CAResponder* nextResponder = NULL; if (CAView* view = dynamic_cast<CAView*>(responder)) { if (view->getViewDelegate()) { nextResponder = view->nextResponder(); } else { view->sortAllSubviews(); CAVector<CAView*>::const_reverse_iterator itr; for (itr=view->getSubviews().rbegin(); itr!=view->getSubviews().rend(); itr++) { CAView* subview = *itr; if (subview->isVisible() && subview->isTouchEnabled()) { CCPoint point = subview->convertTouchToNodeSpace(touch); if (subview->getBounds().containsPoint(point)) { nextResponder = subview; break; } } } } } else if (CAViewController* viewController = dynamic_cast<CAViewController*>(responder)) { CAVector<CAView*>::const_reverse_iterator itr; for (itr=viewController->getView()->getSubviews().rbegin(); itr!=viewController->getView()->getSubviews().rend(); itr++) { CAView* subview = *itr; if (subview->isVisible() && subview->isTouchEnabled()) { CCPoint point = subview->convertTouchToNodeSpace(touch); if (subview->getBounds().containsPoint(point)) { nextResponder = subview; break; } } } } responder = nextResponder; } while (responder); return vector; }
void CATableView::reloadData() { this->reloadViewSizeData(); this->removeAllSubviews(); float width = this->getBounds().size.width; int y = 0; if (m_pTablePullDownView) { m_pTablePullDownView->setFrame(CCRect(0, -(float)m_nTablePullViewHeight, width, m_nTablePullViewHeight)); this->addSubview(m_pTablePullDownView); } if (m_pTablePullUpView) { m_pTablePullUpView->setFrame(CCRect(0, this->getBounds().size.height, width, m_nTablePullViewHeight)); this->addSubview(m_pTablePullUpView); } if (m_pTableHeaderView) { m_pTableHeaderView->setFrame(CCRect(0, y, width, m_nTableHeaderHeight)); this->addSubview(m_pTableHeaderView); y += m_nTableHeaderHeight; } unsigned int sectionCount = m_pTableViewDataSource->numberOfSections(this); m_rTableCellRectss.resize(sectionCount); for (unsigned int i=0; i<sectionCount; i++) { CAView* sectionHeaderView = m_pTableViewDataSource->tableViewSectionViewForHeaderInSection(this, i); if (sectionHeaderView) { sectionHeaderView->setFrame(CCRect(0, y, width, m_nSectionHeaderHeights.at(i))); this->addSubview(sectionHeaderView); } y += m_nSectionHeaderHeights[i]; m_rTableCellRectss[i].resize(m_nRowHeightss[i].size()); for (unsigned int j=0; j<m_rTableCellRectss[i].size(); j++) { m_rTableCellRectss[i][j] = CCRect(0, y, width, m_nRowHeightss[i][j]); CATableViewCell* cell = m_pTableViewDataSource->tableCellAtIndex(this, i, j); cell->setFrame(m_rTableCellRectss[i][j]); this->addSubview(cell); cell->setSection(i); cell->setRow(j); m_pTableCells.push_back(cell); y += m_nRowHeightss[i][j]; if (j < m_nRowHeightss.at(i).size() - 1) { CAView* view = CAView::createWithFrame(CCRect(0, y, width, 1), m_separatorColor); this->addSubview(view); y += 1; } } CAView* sectionFooterView = m_pTableViewDataSource->tableViewSectionViewForFooterInSection(this, i); if (sectionFooterView) { sectionFooterView->setFrame(CCRect(0, y, width, m_nSectionFooterHeights.at(i))); this->addSubview(sectionFooterView); } y += m_nSectionFooterHeights.at(i); } if (m_pTableFooterView) { m_pTableFooterView->setFrame(CCRect(0, y, width, m_nTableFooterHeight)); this->addSubview(m_pTableFooterView); y += m_nTableFooterHeight; } }
void CATouchController::touchMoved() { CC_RETURN_IF(ccpDistance(m_tFirstPoint, m_pTouch->getLocation()) < 16); m_tFirstPoint = DPointZero; if (!m_vTouchMovedsViewCache.empty()) { bool isScheduledPassing = CAScheduler::isScheduled(schedule_selector(CATouchController::passingTouchesViews), this); bool isTouchEventScrollHandOverToSuperview = true; for (CAVector<CAResponder*>::iterator itr=m_vTouchesViews.begin(); itr!=m_vTouchesViews.end(); itr++) { CC_CONTINUE_IF((*itr)->isTouchEventScrollHandOverToSuperview()); isTouchEventScrollHandOverToSuperview = false; break; } if (isScheduledPassing || isTouchEventScrollHandOverToSuperview) { CAScheduler::unschedule(schedule_selector(CATouchController::passingTouchesViews), this); while (!m_vTouchMovedsViewCache.empty()) { CAResponder* responder = m_vTouchMovedsViewCache.back(); DPoint pointOffSet = DPointZero; if (CAView* v = dynamic_cast<CAView*>(responder)) { pointOffSet = ccpSub(v->convertToNodeSpace(m_pTouch->getLocation()), v->convertToNodeSpace(m_pTouch->getPreviousLocation())); } else if (CAViewController* c = dynamic_cast<CAViewController*>(responder)) { pointOffSet = ccpSub(c->getView()->convertToNodeSpace(m_pTouch->getLocation()), c->getView()->convertToNodeSpace(m_pTouch->getPreviousLocation())); } else { pointOffSet = ccpSub(m_pTouch->getLocation(), m_pTouch->getPreviousLocation()); } pointOffSet.x = fabsf(pointOffSet.x); pointOffSet.y = fabsf(pointOffSet.y); do { CC_BREAK_IF(!responder->isHorizontalScrollEnabled() && pointOffSet.x >= pointOffSet.y); CC_BREAK_IF(!responder->isVerticalScrollEnabled() && pointOffSet.x < pointOffSet.y); m_vTouchMovedsView.pushBack(m_vTouchMovedsViewCache.back()); } while (0); m_vTouchMovedsViewCache.popBack(); } if (!m_vTouchMovedsView.empty()) { bool isTouchCancelled = true; CAVector<CAResponder*>::iterator itr; for (itr=m_vTouchesViews.begin(); itr!=m_vTouchesViews.end(); itr++) { CAResponder* responder = (*itr); if (responder->isPriorityScroll()) { DPoint pointOffSet = DPointZero; if (CAView* v = dynamic_cast<CAView*>(responder)) { pointOffSet = ccpSub(v->convertToNodeSpace(m_pTouch->getLocation()), v->convertToNodeSpace(m_pTouch->getPreviousLocation())); } else if (CAViewController* c = dynamic_cast<CAViewController*>(responder)) { pointOffSet = ccpSub(c->getView()->convertToNodeSpace(m_pTouch->getLocation()), c->getView()->convertToNodeSpace(m_pTouch->getPreviousLocation())); } else { pointOffSet = ccpSub(m_pTouch->getLocation(), m_pTouch->getPreviousLocation()); } if (!responder->isReachBoundaryHandOverToSuperview()) { isTouchCancelled = false; break; } if (responder->isHorizontalScrollEnabled() && fabsf(pointOffSet.x) >= fabsf(pointOffSet.y)) { if (!responder->isReachBoundaryLeft() && pointOffSet.x >= 0) { isTouchCancelled = false; break; } if (!responder->isReachBoundaryRight() && pointOffSet.x <= 0) { isTouchCancelled = false; break; } } if (responder->isVerticalScrollEnabled() && fabsf(pointOffSet.x) < fabsf(pointOffSet.y)) { if (!responder->isReachBoundaryUp() && pointOffSet.y >= 0) { isTouchCancelled = false; break; } if (!responder->isReachBoundaryDown() && pointOffSet.y <= 0) { isTouchCancelled = false; break; } } } } if (isTouchCancelled) { if (!isScheduledPassing) { CAVector<CAResponder*>::iterator itr; for (itr=m_vTouchesViews.begin(); itr!=m_vTouchesViews.end(); itr++) { this->touchCancelledWithResponder(*itr); } } m_vTouchesViews.clear(); } if (isScheduledPassing || m_vTouchesViews.empty()) { for (int i=0; i<m_vTouchMovedsView.size(); i++) { CAResponder* responder = m_vTouchMovedsView.at(i); DPoint pointOffSet = DPointZero; if (CAView* v = dynamic_cast<CAView*>(responder)) { pointOffSet = ccpSub(v->convertToNodeSpace(m_pTouch->getLocation()), v->convertToNodeSpace(m_pTouch->getPreviousLocation())); } else if (CAViewController* c = dynamic_cast<CAViewController*>(responder)) { pointOffSet = ccpSub(c->getView()->convertToNodeSpace(m_pTouch->getLocation()), c->getView()->convertToNodeSpace(m_pTouch->getPreviousLocation())); } else { pointOffSet = ccpSub(m_pTouch->getLocation(), m_pTouch->getPreviousLocation()); } if (responder->isReachBoundaryHandOverToSuperview()) { if (responder->isHorizontalScrollEnabled() && fabsf(pointOffSet.x) >= fabsf(pointOffSet.y)) { CC_CONTINUE_IF(responder->isReachBoundaryLeft() && pointOffSet.x > 0); CC_CONTINUE_IF(responder->isReachBoundaryRight() && pointOffSet.x < 0); } else if (responder->isVerticalScrollEnabled() && fabsf(pointOffSet.x) < fabsf(pointOffSet.y)) { CC_CONTINUE_IF(responder->isReachBoundaryUp() && pointOffSet.y > 0); CC_CONTINUE_IF(responder->isReachBoundaryDown() && pointOffSet.y < 0); } } if (this->touchBeganWithResponder(responder)) { m_vTouchesViews.pushBack(responder); } break; } if (m_vTouchesViews.empty()) { m_vTouchesViews.pushBack(m_vTouchMovedsView.front()); while (m_vTouchesViews.back()) { if (this->touchBeganWithResponder(m_vTouchesViews.back())) { break; } m_vTouchesViews.popBack(); } } } } } } CAView* view = dynamic_cast<CAView*>(CAApplication::getApplication()->getTouchDispatcher()->getFirstResponder()); bool isContainsFirstPoint = view && view->convertRectToWorldSpace(view->getBounds()).containsPoint(m_tFirstPoint); if (!isContainsFirstPoint && view && view->isScrollEnabled()) { this->touchMovedWithResponder(view); } CAVector<CAResponder*>::iterator itr; for (itr=m_vTouchesViews.begin(); itr!=m_vTouchesViews.end(); itr++) { CC_CONTINUE_IF(!(*itr)->isScrollEnabled()); this->touchMovedWithResponder(*itr); } }
void CATableView::reloadData() { this->reloadViewSizeData(); this->removeAllSubviews(); float width = this->getBounds().size.width; int y = 0; if (m_pTablePullDownView) { m_pTablePullDownView->setFrame(CCRect(0, -(float)m_nTablePullViewHeight, width, m_nTablePullViewHeight)); this->addSubview(m_pTablePullDownView); } if (m_pTableHeaderView) { m_pTableHeaderView->setFrame(CCRect(0, y, width, m_nTableHeaderHeight)); this->addSubview(m_pTableHeaderView); y += m_nTableHeaderHeight; } unsigned int sectionCount = m_pTableViewDataSource->numberOfSections(this); m_rTableCellRectss.resize(sectionCount); m_rLineRectss.resize(sectionCount); for (unsigned int i=0; i<sectionCount; i++) { CCRect sectionHeaderRect = CCRect(0, y, width, m_nSectionHeaderHeights.at(i)); CAView* sectionHeaderView = m_pTableViewDataSource->tableViewSectionViewForHeaderInSection(this, sectionHeaderRect.size, i); //CC_DEPRECATED_ATTRIBUTE if (sectionHeaderView == NULL) { sectionHeaderView = m_pTableViewDataSource->tableViewSectionViewForHeaderInSection(this, i); } if (sectionHeaderView) { sectionHeaderView->setFrame(sectionHeaderRect); this->insertSubview(sectionHeaderView, 2); m_pSectionHeaderViews[i] = sectionHeaderView; } y += m_nSectionHeaderHeights[i]; m_rTableCellRectss[i].resize(m_nRowHeightss[i].size()); m_rLineRectss[i].resize(m_nRowHeightss[i].size()); for (unsigned int j=0; j<m_rTableCellRectss[i].size(); j++) { m_rTableCellRectss[i][j] = CCRect(0, y, width, m_nRowHeightss[i][j]); y += m_nRowHeightss[i][j]; m_rLineRectss[i][j] = CCRect(0, y, width, m_nSeparatorViewHeight); y += m_nSeparatorViewHeight; } CCRect sectionFooterRect = CCRect(0, y, width, m_nSectionFooterHeights.at(i)); CAView* sectionFooterView = m_pTableViewDataSource->tableViewSectionViewForFooterInSection(this, sectionFooterRect.size, i); //CC_DEPRECATED_ATTRIBUTE if (sectionFooterView == NULL) { sectionFooterView = m_pTableViewDataSource->tableViewSectionViewForFooterInSection(this, i); } if (sectionFooterView) { sectionFooterView->setFrame(sectionFooterRect); this->insertSubview(sectionFooterView, 2); m_pSectionFooterViews[i] = sectionFooterView; } CCRect sectionRect = sectionHeaderRect; sectionRect.size.height = sectionFooterRect.origin.y + sectionFooterRect.size.height - sectionHeaderRect.origin.y; m_rSectionRects.push_back(sectionRect); y += m_nSectionFooterHeights.at(i); } if (m_pTableFooterView) { m_pTableFooterView->setFrame(CCRect(0, y, width, m_nTableFooterHeight)); this->addSubview(m_pTableFooterView); y += m_nTableFooterHeight; } if (m_pTablePullUpView) { m_pTablePullUpView->setFrame(CCRect(0, m_obViewSize.height, width, m_nTablePullViewHeight)); this->addSubview(m_pTablePullUpView); } this->loadTableCell(); this->updateSectionHeaderAndFooterRects(); }
// [email protected]: 2015-03-08 void CANavigationController::popToRootViewControllerAnimated(bool animated) { if (m_pViewControllers.size() == 1) { return ; } float x = this->getView()->getBounds().size.width; CAView* backContainer = m_pContainers.back(); backContainer->setFrameOrigin(CCPointZero); size_t index = 0; CAViewController* showViewController = m_pViewControllers.at(index); showViewController->viewDidAppear(); CAView* showContainer = m_pContainers.at(index); showContainer->setVisible(true); showContainer->setFrameOrigin(CCPoint(-x/2.0f, 0)); { CCRect rect = this->getView()->getBounds(); CCPoint point = this->getNavigationBarNowPoint(showViewController); switch (m_eNavigationBarVerticalAlignment) { case CABarVerticalAlignmentTop: { rect.origin.y = point.y + m_tNavigationBarSize.height; rect.size.height = rect.size.height - rect.origin.y; } break; case CABarVerticalAlignmentBottom: { rect.size.height = point.y; } break; default: break; } m_pNavigationBars.at(index)->setFrameOrigin(point); CAView* secondContainer = m_pSecondContainers.at(index); secondContainer->setFrame(rect); showViewController->getSuperViewRect(secondContainer->getBounds()); } CAApplication::getApplication()->getTouchDispatcher()->setDispatchEventsFalse(); if (animated) { CAViewAnimation::beginAnimations("", NULL); CAViewAnimation::setAnimationDuration(0.25f); CAViewAnimation::setAnimationDelay(0.02f); CAViewAnimation::setAnimationCurve(CAViewAnimationCurveEaseOut); showContainer->setFrameOrigin(CCPointZero); CAViewAnimation::commitAnimations(); CAViewAnimation::beginAnimations("", NULL); CAViewAnimation::setAnimationDuration(0.25f); CAViewAnimation::setAnimationDelay(0.03f); CAViewAnimation::setAnimationCurve(CAViewAnimationCurveEaseOut); CAViewAnimation::setAnimationDidStopSelector(this, CAViewAnimation0_selector(CANavigationController::popToRootViewControllerFinish)); backContainer->setFrameOrigin(CCPoint(x, 0)); CAViewAnimation::commitAnimations(); } else { this->popToRootViewControllerFinish(); } }
void CCTransitionCrossFade::onEnter() { CCTransitionScene::onEnter(); // create a transparent color layer // in which we are going to add our rendertextures ccColor4B color = {0,0,0,0}; CCSize size = CCDirector::sharedDirector()->getWinSize(); CAView* layer = CAView::createWithFrame(CCRect(0, 0, size.width, size.height)); layer->setColor(ccc3(color.r, color.g, color.b)); layer->setOpacity(color.a); // create the first render texture for inScene CCRenderTexture* inTexture = CCRenderTexture::create((int)size.width, (int)size.height); if (NULL == inTexture) { return; } inTexture->getSprite()->setAnchorPoint( ccp(0.5f,0.5f) ); inTexture->setPosition( ccp(size.width/2, size.height/2) ); inTexture->setAnchorPoint( ccp(0.5f,0.5f) ); // render inScene to its texturebuffer inTexture->begin(); m_pInScene->visit(); inTexture->end(); // create the second render texture for outScene CCRenderTexture* outTexture = CCRenderTexture::create((int)size.width, (int)size.height); outTexture->getSprite()->setAnchorPoint( ccp(0.5f,0.5f) ); outTexture->setPosition( ccp(size.width/2, size.height/2) ); outTexture->setAnchorPoint( ccp(0.5f,0.5f) ); // render outScene to its texturebuffer outTexture->begin(); m_pOutScene->visit(); outTexture->end(); // create blend functions ccBlendFunc blend1 = {GL_ONE, GL_ONE}; // inScene will lay on background and will not be used with alpha ccBlendFunc blend2 = {GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA}; // we are going to blend outScene via alpha // set blendfunctions inTexture->getSprite()->setBlendFunc(blend1); outTexture->getSprite()->setBlendFunc(blend2); // add render textures to the layer layer->addSubview(inTexture); layer->addSubview(outTexture); // initial opacity: inTexture->getSprite()->setOpacity(255); outTexture->getSprite()->setOpacity(255); // create the blend action CCAction* layerAction = CCSequence::create ( CCFadeTo::create(m_fDuration, 0), CCCallFunc::create(this, callfunc_selector(CCTransitionScene::hideOutShowIn)), CCCallFunc::create(this, callfunc_selector(CCTransitionScene::finish)), NULL ); // run the blend action outTexture->getSprite()->runAction( layerAction ); // add the layer (which contains our two rendertextures) to the scene layer->setTag(kSceneFade); insertSubview(layer, 2); }