void CANavigationController::layoutNewContainer() { CCRect navigation_bar_rect = CCRectZero; navigation_bar_rect.size = m_tNavigationBarSize; CCRect container_rect = this->getView()->getBounds(); if (m_bNavigationBarHidden) { navigation_bar_rect.origin = this->getNavigationBarTakeBackPoint(); } else { container_rect.size.height -= m_tNavigationBarSize.height; navigation_bar_rect.origin = this->getNavigationBarOpenPoint(); if (m_eNavigationBarVerticalAlignment == CABarVerticalAlignmentTop) { container_rect.origin.y = m_tNavigationBarSize.height; } } CAView* container = m_pContainers.back(); container->setFrame(this->getView()->getBounds()); CANavigationBar* navigationBar = m_pNavigationBars.back(); navigationBar->setFrame(navigation_bar_rect); CAView* secondContainer = m_pSecondContainers.back(); secondContainer->setFrame(container_rect); CAViewController* viewController = m_pViewControllers.back(); viewController->addViewFromSuperview(secondContainer); viewController->viewDidAppear(); }
void CAWindow::presentModalViewController(CAViewController* controller, bool animated) { CC_RETURN_IF(controller == NULL); CC_RETURN_IF(m_pModalViewController); CC_SAFE_RETAIN(controller); m_pModalViewController = controller; m_pModalViewController->addViewFromSuperview(this); m_pModalViewController->getView()->setZOrder(CAWindowZOderCenter); m_pModalViewController->viewDidAppear(); CAApplication::getApplication()->getTouchDispatcher()->setDispatchEventsFalse(); if (animated) { CAView* view = m_pModalViewController->getView(); DRect frame = view->getFrame(); frame.origin.y = frame.size.height; view->setFrame(frame); DRect endFrame = DRectZero; endFrame.size = view->getFrame().size; CAViewAnimation::beginAnimations("", NULL); CAViewAnimation::setAnimationDuration(0.25f); CAViewAnimation::setAnimationDelay(0.1f); CAViewAnimation::setAnimationCurve(CAViewAnimationCurveLinear); CAViewAnimation::setAnimationDidStopSelector(this, CAViewAnimation0_selector(CAWindow::presentEnd)); view->setFrame(endFrame); CAViewAnimation::commitAnimations(); } else { this->presentEnd(); } }
void CANavigationController::ccTouchMoved(CATouch *pTouch, CAEvent *pEvent) { CC_RETURN_IF(m_pViewControllers.size() <= 1); CC_RETURN_IF(m_bTouchMoved == false); float offDis = pTouch->getLocation().x - pTouch->getPreviousLocation().x; CAView* showContainer = m_pContainers.at(m_pContainers.size() - 2); if (!showContainer->getBounds().size.equals(this->getView()->getBounds().size)) { showContainer->setFrame(this->getView()->getBounds()); } showContainer->setVisible(true); showContainer->setTouchEnabled(false); CAView* backContainer = m_pContainers.back(); DPoint point1 = backContainer->getFrameOrigin(); point1.x += offDis; point1.x = MAX(point1.x, 0); point1.x = MIN(point1.x, this->getView()->getBounds().size.width); backContainer->setFrameOrigin(point1); backContainer->setTouchEnabled(false); DPoint point2 = showContainer->getCenterOrigin(); point2.x = point1.x/2; showContainer->setCenterOrigin(point2); m_bPopViewController = ((offDis > 10) || point1.x > this->getView()->getBounds().size.width/4); }
void CAWindow::presentModalViewController(CAViewController* controller, bool animated) { CC_RETURN_IF(controller == NULL); CC_RETURN_IF(m_pModalViewController); CC_SAFE_RETAIN(controller); m_pModalViewController = controller; m_pModalViewController->addViewFromSuperview(this); m_pModalViewController->getView()->setZOrder(CAWindowZoderCenter); if (animated) { CAView* view = m_pModalViewController->getView(); CCRect frame = view->getFrame(); frame.origin.y = frame.size.height; view->setFrame(frame); CCRect endFrame = CCRectZero; endFrame.size = view->getFrame().size; CCCallFunc* start = CCCallFunc::create(this, callfunc_selector(CAWindow::presentStart)); CCCallFunc* end = CCCallFunc::create(this, callfunc_selector(CAWindow::presentEnd)); CCDelayTime* delayTime = CCDelayTime::create(0.1f); CCFrameTo* frameTo = CCFrameTo::create(0.3f, endFrame); CCEaseSineOut* easeBack = CCEaseSineOut::create(frameTo); CCSequence* allActions = CCSequence::create(start, delayTime, easeBack, end, NULL); view->runAction(allActions); } }
void CAWindow::dismissModalViewController(bool animated) { CC_RETURN_IF(m_pModalViewController == NULL); if (m_pRootViewController) { m_pRootViewController->viewDidAppear(); } CAApplication::getApplication()->getTouchDispatcher()->setDispatchEventsFalse(); if (animated) { CAView* view = m_pModalViewController->getView(); DRect endFrame = view->getFrame(); endFrame.origin.y = endFrame.size.height; CAViewAnimation::beginAnimations("", NULL); CAViewAnimation::setAnimationDuration(0.25f); CAViewAnimation::setAnimationDelay(0.1f); CAViewAnimation::setAnimationCurve(CAViewAnimationCurveLinear); CAViewAnimation::setAnimationDidStopSelector(this, CAViewAnimation0_selector(CAWindow::dismissEnd)); view->setFrame(endFrame); CAViewAnimation::commitAnimations(); } else { this->dismissEnd(); } }
void CANavigationController::update(float dt) { CCRect rect = this->getView()->getBounds(); CCPoint point = this->getNavigationBarNowPoint(); 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.back()->setFrameOrigin(point); CAView* secondContainer = m_pSecondContainers.back(); CAViewController* viewController = m_pViewControllers.back(); secondContainer->setFrame(rect); viewController->getSuperViewRect(secondContainer->getBounds()); }
void FSNewsAboutController::viewDidLoad() { winSize = this->getView()->getBounds().size; if (p_TableView!=NULL) { this->getView()->removeSubview(p_TableView); p_TableView = NULL; } p_TableView= CATableView::createWithFrame(CADipRect(0, -150, winSize.width, winSize.height+150)); p_TableView->setTableViewDataSource(this); p_TableView->setTableViewDelegate(this); p_TableView->setAllowsSelection(true); p_TableView->setAllowsMultipleSelection(false); p_TableView->setAlwaysTopSectionHeader(false); this->getView()->addSubview(p_TableView); p_TableView->setTableHeaderHeight(_px(602)); CAView* view = CAView::createWithColor(CAColor_clear); view->setFrame(CADipRect(0,0,winSize.width,602)); CAImageView* head_bg = CAImageView::createWithFrame(CADipRect(0,0,winSize.width,602)); head_bg->setImage(CAImage::create("image/about_head_bg.png")); view->addSubview(head_bg); // CAImageView* head = CAImageView::createWithCenter(CADipRect(winSize.width/2,320,96,96)); // head->setImage(CAImage::create("image/avatar_bg_70.png")); // view->addSubview(head); p_TableView->setTableHeaderView(view); }
// [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(DPointZero); size_t index = 0; CAViewController* showViewController = m_pViewControllers.at(index); showViewController->viewDidAppear(); CAView* showContainer = m_pContainers.at(index); showContainer->setVisible(true); showContainer->setFrameOrigin(DPoint(-x/2.0f, 0)); { DPoint point = this->getNavigationBarNowPoint(showViewController); DRect rect = this->getView()->getBounds(); rect.origin.y = point.y + m_tNavigationBarSize.height; rect.size.height = rect.size.height - rect.origin.y; 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(DPointZero); 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(DPoint(x, 0)); CAViewAnimation::commitAnimations(); } else { this->popToRootViewControllerFinish(); } }
void CDNewsViewController::initNewsPageView() { //初始化pageView CAView* tempview = CAView::create(); p_PageView = CAPageView::createWithFrame(DRect(0,0,winSize.width,winSize.width/2), CAPageViewDirectionHorizontal); p_PageView->setPageViewDelegate(this); p_PageView->setTouchEnabled(true); CAVector<CAView* > viewList; CommonUrlImageView* temImage0 = CommonUrlImageView::createWithFrame(DRect(winSize.width/2,100,winSize.width,winSize.width/2)); temImage0->setImageViewScaleType(CAImageViewScaleTypeFitImageCrop); temImage0->setImage(CAImage::create("image/HelloWorld.png")); temImage0->setUrl(m_page[m_page.size()-1].m_pic); viewList.pushBack(temImage0); for (int i=0; i<m_page.size(); i++) { //初始化viewList CommonUrlImageView* temImage = CommonUrlImageView::createWithFrame(DRect(winSize.width/2,100,winSize.width,winSize.width/2)); temImage->setImageViewScaleType(CAImageViewScaleTypeFitImageCrop); temImage->setImage(CAImage::create("image/HelloWorld.png")); temImage->setUrl(m_page[i].m_pic); viewList.pushBack(temImage); } CommonUrlImageView* temImage1 = CommonUrlImageView::createWithFrame(DRect(winSize.width/2,100,winSize.width,winSize.width/2)); temImage1->setImageViewScaleType(CAImageViewScaleTypeFitImageCrop); temImage1->setImage(CAImage::create("image/HelloWorld.png")); temImage1->setUrl(m_page[0].m_pic); viewList.pushBack(temImage1); p_PageView->setViews(viewList); tempview->addSubview(p_PageView); p_PageView->setCurrPage(1, false); pageControl = CAPageControl::createWithCenter(DRect(winSize.width-80, winSize.width/2-25, 100, 50)); pageControl->setNumberOfPages((int)m_page.size()); pageControl->setPageIndicatorImage(CAImage::create("image/pagecontrol_selected.png")); pageControl->setCurrIndicatorImage(CAImage::create("image/pagecontrol_bg.png")); pageControl->setPageIndicatorTintColor(CAColor_gray); //pageControl->setCurrentPageIndicatorTintColor(CAColor_clear); pageControl->addTarget(this, CAControl_selector(CDNewsViewController::pageControlCallBack)); tempview->addSubview(pageControl); CAView* bg = CAView::createWithColor(ccc4(0, 0, 0, 128)); bg->setFrame(DRect(0,winSize.width/2-50,winSize.width,50)); tempview->addSubview(bg); if (m_page.size()>0) { pageViewTitle = CALabel::createWithFrame(DRect(10, winSize.width/2-40, winSize.width-50, 50)); pageViewTitle->setText(m_page[0].m_title); pageViewTitle->setColor(CAColor_white); pageViewTitle->setFontSize(_px(28)); tempview->addSubview(pageViewTitle); } p_TableView->setTableHeaderView(tempview); p_TableView->setTableHeaderHeight(_px(winSize.width/2)); }
void CATextSelViewEx::showTextViewMark(const std::vector<CCRect>& vt) { hideTextViewMark(); for (int i = 0; i < vt.size(); i++) { CAView* pTextMaskView = CAView::createWithColor(ccc4(60, 120, 240, 127)); pTextMaskView->setFrame(vt[i]); addSubview(pTextMaskView); m_pTextViewMask.push_back(pTextMaskView); } this->setVisible(true); }
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); } }
void CANavigationController::layoutNewContainer() { CAViewController* viewController = m_pViewControllers.back(); DRect navigation_bar_rect = DRectZero; navigation_bar_rect.size = m_tNavigationBarSize; DRect container_rect = this->getView()->getBounds(); if (m_bNavigationBarHidden || viewController->getNavigationBarItem()->isNagigationBarHidden()) { navigation_bar_rect.origin = this->getNavigationBarTakeBackPoint(); } else { container_rect.size.height -= m_tNavigationBarSize.height; navigation_bar_rect.origin = this->getNavigationBarOpenPoint(); container_rect.origin.y = m_tNavigationBarSize.height; } CAView* container = m_pContainers.back(); container->setFrame(this->getView()->getBounds()); CANavigationBar* navigationBar = m_pNavigationBars.back(); navigationBar->setFrame(navigation_bar_rect); CAView* secondContainer = m_pSecondContainers.back(); secondContainer->setFrame(container_rect); viewController->addViewFromSuperview(secondContainer); if (m_pViewControllers.size() > 1) { viewController->viewDidAppear(); } }
void CANavigationController::update(float dt) { CAViewController* viewController = m_pViewControllers.back(); DPoint point = this->getNavigationBarNowPoint(viewController); DRect rect = this->getView()->getBounds(); rect.origin.y = point.y + m_tNavigationBarSize.height; rect.size.height = rect.size.height - rect.origin.y; m_pNavigationBars.back()->setFrameOrigin(point); CAView* secondContainer = m_pSecondContainers.back(); secondContainer->setFrame(rect); viewController->getSuperViewRect(secondContainer->getBounds()); }
void CANavigationController::createWithContainer(CAViewController* viewController) { CAView* container = new CAView(); container->setFrame(this->getView()->getBounds()); this->getView()->addSubview(container); m_pContainers.pushBack(container); container->release(); CANavigationBar* navigationBar = CANavigationBar::create(DSize(this->getView()->getBounds().size.width, 0)); if (viewController->getNavigationBarItem() == NULL && viewController->getTitle().compare("") != 0) { viewController->setNavigationBarItem(CANavigationBarItem::create(viewController->getTitle())); } if (m_pViewControllers.empty()) { viewController->getNavigationBarItem()->setShowGoBackButton(false); } navigationBar->setItem(viewController->getNavigationBarItem()); if (m_pNavigationBarBackgroundImage) { navigationBar->setBackgroundView(CAScale9ImageView::createWithImage(m_pNavigationBarBackgroundImage)); } else { navigationBar->setBackgroundView(CAView::create()); } navigationBar->getBackgroundView()->setColor(m_sNavigationBarBackgroundColor); navigationBar->setTitleColor(m_sNavigationBarTitleColor); navigationBar->setTitleColor(m_sNavigationBarTitleColor); container->insertSubview(navigationBar, 1); navigationBar->setDelegate(this); m_pNavigationBars.pushBack(navigationBar); CAView* secondContainer = new CAView(); container->addSubview(secondContainer); secondContainer->release(); m_pSecondContainers.pushBack(secondContainer); viewController->m_pNavigationController = this; m_pViewControllers.pushBack(viewController); }
void ShowTextViewMask() { HideTextViewMask(); int iFlagTrick = -1; std::vector<DRect> vt = getZZCRect(); for (int i = 0; i < vt.size(); i++) { CAView* pTextMaskView = CAView::createWithColor(ccc4(60, 120, 240, 127)); if (vt[i].origin.y == iFlagTrick) { vt[i].InflateRect(0, -1, 0, -1); } iFlagTrick = vt[i].origin.y + vt[i].size.height; pTextMaskView->setFrame(vt[i]); m_pContainerView->addSubview(pTextMaskView); m_vTextViewMask.push_back(pTextMaskView); } }
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); } } }
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()); } }
void CATableView::reloadData() { this->reloadViewSizeData(); this->removeAllSubviews(); float width = this->getBounds().size.width; int y = 0; if (m_pTablePullDownView) { this->addSubview(m_pTablePullDownView); m_pTablePullDownView->setFrame(CCRect(0, -(float)m_nTablePullViewHeight, width, m_nTablePullViewHeight)); } if (m_pTableHeaderView) { m_pTableHeaderView->setDisplayRange(true); this->addSubview(m_pTableHeaderView); m_pTableHeaderView->setFrame(CCRect(0, y, width, m_nTableHeaderHeight)); 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) { this->insertSubview(sectionHeaderView, 2); sectionHeaderView->setFrame(sectionHeaderRect); } 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) { this->insertSubview(sectionFooterView, 2); sectionFooterView->setFrame(sectionFooterRect); } y += m_nSectionFooterHeights.at(i); } if (m_pTableFooterView) { m_pTableFooterView->setDisplayRange(true); this->addSubview(m_pTableFooterView); m_pTableFooterView->setFrame(CCRect(0, y, width, m_nTableFooterHeight)); y += m_nTableFooterHeight; } if (m_pTablePullUpView) { this->addSubview(m_pTablePullUpView); m_pTablePullUpView->setFrame(CCRect(0, m_obViewSize.height, width, m_nTablePullViewHeight)); } this->loadTableCell(); }
CAViewController* CANavigationController::popViewControllerAnimated(bool animated) { if (m_pViewControllers.size() == 1) { return NULL; } float x = this->getView()->getBounds().size.width; CAViewController* backViewController = m_pViewControllers.back(); CAView* backContainer = m_pContainers.back(); { backContainer->setFrameOrigin(CCPointZero); } size_t index = m_pViewControllers.size() - 2; CAViewController* showViewController = m_pViewControllers.at(index); showViewController->viewDidAppear(); CAView* showContainer = m_pContainers.at(index); showContainer->setVisible(true); { 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) { showContainer->setFrameOrigin(CCPoint(-x/2.0f, 0)); CAViewAnimation::beginAnimations("", NULL); CAViewAnimation::setAnimationDuration(0.25f); CAViewAnimation::setAnimationDelay(1/30.0f); CAViewAnimation::setAnimationCurve(CAViewAnimationCurveEaseOut); showContainer->setFrameOrigin(CCPointZero); CAViewAnimation::commitAnimations(); CAViewAnimation::beginAnimations("", NULL); CAViewAnimation::setAnimationDuration(0.25f); CAViewAnimation::setAnimationDelay(1/60.0f); CAViewAnimation::setAnimationCurve(CAViewAnimationCurveEaseOut); CAViewAnimation::setAnimationDidStopSelector(this, CAViewAnimation0_selector(CANavigationController::popViewControllerFinish)); backContainer->setFrameOrigin(CCPoint(x, 0)); CAViewAnimation::commitAnimations(); } else { this->popViewControllerFinish(); } return backViewController; }
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; } }
int CAAutoCollectionView::calculateAllRects() { int dw = 0, dd = 0, dv = 0; if (m_pCollectionViewOrientation == CACollectionViewOrientationVertical) { dw = this->getBounds().size.width - 2 * m_iHoriMargins; dd = m_iVertMargins + m_nCollectionHeaderHeight; dv = m_nVertCellInterval; } else { dw = this->getBounds().size.height - 2 * m_iVertMargins; dd = m_iHoriMargins + m_nCollectionHeaderHeight; dv = m_nHoriCellInterval; } for (int i = 0; i < m_rCollectionViewSection.size(); i++) { CollectionViewSection& cvs = m_rCollectionViewSection[i]; unsigned int iSectionHeaderHeight = cvs.nSectionHeaderHeight; DRect sectionHeaderRect; if (m_pCollectionViewOrientation == CACollectionViewOrientationVertical) { sectionHeaderRect = DRect(m_iHoriMargins, dd, dw, iSectionHeaderHeight); } else { sectionHeaderRect = DRect(dd, m_iVertMargins, iSectionHeaderHeight, dw); } if (iSectionHeaderHeight > 0) { CAView* pSectionHeaderView = m_pCollectionViewDataSource->collectionViewSectionViewForHeaderInSection(this, sectionHeaderRect.size, i); if (pSectionHeaderView != NULL) { pSectionHeaderView->setDisplayRange(true); pSectionHeaderView->setFrame(sectionHeaderRect); insertSubview(pSectionHeaderView, 1); } dd += (iSectionHeaderHeight + dv); cvs.pSectionHeaderView = pSectionHeaderView; } dd = calculateAllCells(cvs, i, dd, dv, dw); unsigned int iSectionFooterHeight = cvs.nSectionFooterHeight; DRect sectionFooterRect; if (m_pCollectionViewOrientation == CACollectionViewOrientationVertical) { sectionFooterRect = DRect(m_iHoriMargins, dd, dw, iSectionFooterHeight); } else { sectionFooterRect = DRect(dd, m_iVertMargins, iSectionFooterHeight, dw); } if (iSectionFooterHeight > 0) { CAView* pSectionFooterView = m_pCollectionViewDataSource->collectionViewSectionViewForFooterInSection(this, sectionFooterRect.size, i); if (pSectionFooterView != NULL) { pSectionFooterView->setDisplayRange(true); pSectionFooterView->setFrame(sectionFooterRect); insertSubview(pSectionFooterView, 1); } dd += (iSectionFooterHeight + dv); cvs.pSectionFooterView = pSectionFooterView; } DRect sectionRect = sectionHeaderRect; if (m_pCollectionViewOrientation == CACollectionViewOrientationVertical) { sectionRect.size.height = sectionFooterRect.origin.y + sectionFooterRect.size.height - sectionHeaderRect.origin.y; } else { sectionRect.size.width = sectionFooterRect.origin.x + sectionFooterRect.size.width - sectionHeaderRect.origin.x; } cvs.rSectionRect = sectionRect; } return dd; }
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 CATableView::reloadData() { this->reloadViewSizeData(); this->removeAllSubviews(); float width = this->getBounds().size.width; int y = 0; 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); 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); 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; } this->loadTableCell(); this->updateSectionHeaderAndFooterRects(); this->layoutPullToRefreshView(); this->startDeaccelerateScroll(); }