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; } }
void CATableView::update(float fDelta) { CAScrollView::update(fDelta); CCRect rect = this->getBounds(); rect.origin.y -= rect.size.height/2; rect.size.height *= 2; std::deque<CATableViewCell*>::iterator itr; for (itr=m_pTableCells.begin(); itr!=m_pTableCells.end(); itr++) { CATableViewCell* cell = *itr; CCPoint point = cell->getCenterOrigin(); point = m_pContainer->convertToWorldSpace(point); point = this->convertToNodeSpace(point); if (rect.containsPoint(point)) { cell->setVisible(true); } else { cell->setVisible(false); } } }
void CATableView::clearData() { 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(); m_rSectionRectss.clear(); m_rTableCellRectss.clear(); std::set<CATableViewCell*>::iterator itr2; for (itr2=m_pSelectedTableCells.begin(); itr2!=m_pSelectedTableCells.end(); itr2++) { CATableViewCell* cell = *itr2; cell->setControlStateNormal(); } m_pSelectedTableCells.clear(); m_pTableCells.clear(); }
CATableViewCell* RootViewController::tableCellAtIndex(CATableView *table, unsigned int section, unsigned int row) { CATableViewCell* cell = table->dequeueReusableCellWithIdentifier("aaa"); if (cell == NULL) { cell = CATableViewCell::create("aaa"); //cell->setBackGroundView(NULL); } CCString* str = CCString::createWithFormat("CELL - %u", row); CCLabelTTF* ttf = CCLabelTTF::create(str->getCString(), "Arial", 40); ttf->setColor(ccBLACK); ttf->setFrame(CCRect(10, 60, 0, 0)); cell->addSubview(ttf); // CALabel* label = CALabel::create(CCRect(0, 0, 600, 100)); // label->setOpacity(128); // label->setVerticalTextAlignmet(kCCVerticalTextAlignmentCenter); // label->setCenterOrigin(CCPoint(300, 60)); // label->setText(str->getCString()); // cell->addSubview(label); return cell; }
void CATableView::update(float fDelta) { CAScrollView::update(fDelta); CCRect rect = this->getBounds(); rect.origin.y -= rect.size.height * 0.1f; rect.size.height *= 1.2f; std::deque<CATableViewCell*>::iterator itr; for (itr=m_pTableCells.begin(); itr!=m_pTableCells.end(); itr++) { CATableViewCell* cell = *itr; CCRect cellRect = cell->getFrame(); cellRect.origin = m_pContainer->convertToWorldSpace(cellRect.origin); cellRect.origin = this->convertToNodeSpace(cellRect.origin); if (rect.intersectsRect(cellRect)) { cell->setVisible(true); } else { cell->setVisible(false); } } }
CATableViewCell* CAPickerView::tableCellAtIndex(CATableView* table, const CCSize& cellSize, unsigned int section, unsigned int row) { if (m_dataSource && !m_tableViews.empty()) { CATableViewCell* cell = table->dequeueReusableCellWithIdentifier("CrossApp"); if (cell == NULL) { cell = CATableViewCell::create("CrossApp"); cell->setBackgroundView(NULL); } else { cell->removeSubviewByTag(100); } size_t component = m_tableViews.getIndex(table); CAView* view = viewForRowInComponent((unsigned int)component, row, cellSize); if (view) { view->setTag(100); cell->addSubview(view); } return cell; } return NULL; }
CATableViewCell* CATableViewCell::create(const std::string& reuseIdentifier) { CATableViewCell* cell = new CATableViewCell(); if (cell && cell->initWithReuseIdentifier(reuseIdentifier)) { cell->autorelease(); return cell; } CC_SAFE_DELETE(cell); return NULL; }
CATableViewCell* CAAlertView::tableCellAtIndex(CATableView* table, unsigned int section, unsigned int row) { CATableViewCell* cell = table->dequeueReusableCellWithIdentifier("cellID"); if (cell == NULL) { cell = CATableViewCell::create("cellID"); cell->addSubview(m_vAllBtn[row]); m_vAllBtn[row]->setCenterOrigin(m_vAllBtn[row]->getBounds().size / 2); } return cell; }
CATableViewCell* CATableView::dequeueReusableCellWithIdentifier(const char* reuseIdentifier) { CATableViewCell* cell = NULL; if (!m_pFreedTableCells[reuseIdentifier].empty()) { cell = m_pFreedTableCells[reuseIdentifier].back(); cell->retain()->autorelease(); m_pFreedTableCells[reuseIdentifier].eraseObject(cell); } return cell; }
CATableViewCell* ExtensionsTest::tableCellAtIndex(CATableView* table, const CCSize& cellSize, unsigned int section, unsigned int row) { CADipSize _size = cellSize; Info* p_List = (Info*)personList.getValue(row); CATableViewCell* cell = table->dequeueReusableCellWithIdentifier("CrossApp"); if (cell == NULL) { cell = CATableViewCell::create("CrossApp"); CALabel* p_Name = CALabel::createWithCenter(CADipRect(_size.width*0.1, _size.height*0.5, _size.width*0.2, _size.height)); p_Name->setTag(NAME); p_Name->setText(p_List->name.c_str()); p_Name->setFontSize(_px(30)); p_Name->setColor(CAColor_blueStyle); p_Name->setTextAlignment(CATextAlignmentCenter); p_Name->setVerticalTextAlignmet(CAVerticalTextAlignmentCenter); cell->addSubview(p_Name); CALabel* p_Num = CALabel::createWithCenter(CADipRect(_size.width*0.3, _size.height*0.5, _size.width*0.2, _size.height)); p_Num->setTag(NUM); p_Num->setText(p_List->num.c_str()); p_Num->setFontSize(_px(30)); p_Num->setColor(CAColor_blueStyle); p_Num->setTextAlignment(CATextAlignmentCenter); p_Num->setVerticalTextAlignmet(CAVerticalTextAlignmentCenter); cell->addSubview(p_Num); CALabel* p_Gender = CALabel::createWithCenter(CADipRect(_size.width*0.5, _size.height*0.5, _size.width*0.2, _size.height)); p_Gender->setTag(GENDER); p_Gender->setText(p_List->gender.c_str()); p_Gender->setFontSize(_px(30)); p_Gender->setColor(CAColor_blueStyle); p_Gender->setTextAlignment(CATextAlignmentCenter); p_Gender->setVerticalTextAlignmet(CAVerticalTextAlignmentCenter); cell->addSubview(p_Gender); CALabel* p_Occupation = CALabel::createWithCenter(CADipRect(_size.width*0.8, _size.height*0.5, _size.width*0.3, _size.height)); p_Occupation->setTag(OCCUPATION); p_Occupation->setText(p_List->occupation.c_str()); p_Occupation->setFontSize(_px(30)); p_Occupation->setColor(CAColor_blueStyle); p_Occupation->setTextAlignment(CATextAlignmentCenter); p_Occupation->setVerticalTextAlignmet(CAVerticalTextAlignmentCenter); cell->addSubview(p_Occupation); } CALabel* p_Name = (CALabel*)cell->getSubviewByTag(NAME); p_Name->setText(p_List->name.c_str()); CALabel* p_Num = (CALabel*)cell->getSubviewByTag(NUM); p_Num->setText(p_List->num.c_str()); CALabel* p_Gender = (CALabel*)cell->getSubviewByTag(GENDER); p_Gender->setText(p_List->gender.c_str()); CALabel* p_Occupation = (CALabel*)cell->getSubviewByTag(OCCUPATION); p_Occupation->setText(p_List->occupation.c_str()); return cell; }
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(); }
bool CATableView::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) { CCPoint point = m_pContainer->convertTouchToNodeSpace(pTouch); 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); if (cell->getFrame().containsPoint(point) && cell->isVisible()) { CC_BREAK_IF(cell->getControlState() == CAControlStateDisabled); if (m_pHighlightedTableCells) { m_pHighlightedTableCells->setControlStateNormal(); } m_pHighlightedTableCells = cell; CC_BREAK_IF(cell->getControlState() == CAControlStateSelected); CCDelayTime* delayTime = CCDelayTime::create(0.05f); CCCallFunc* func = CCCallFunc::create(cell, callfunc_selector(CATableViewCell::setControlStateHighlighted)); CCSequence* actions = CCSequence::create(delayTime, func, NULL); m_pContainer->runAction(actions); break; } } } return true; }
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); } } }
CATableViewCell* PageMenu::tableCellAtIndex(CATableView *table, unsigned int section, unsigned int row) { CATableViewCell* cell = table->dequeueReusableCellWithIdentifier("aaa"); if (cell == NULL) { cell = CATableViewCell::create("aaa"); cell->setBackGroundViewForState(CAControlStateSelected, CAView::createWithColor(ccc4(89, 104, 109, 255))); cell->setBackGroundViewForState(CAControlStateHighlighted, CAView::createWithColor(ccc4(89, 104, 109, 255))); cell->setBackGroundViewForState(CAControlStateNormal, CAView::createWithColor(ccc4(0, 0, 0, 0))); } cell->removeAllSubviews(); if ( row < m_bookData.m_vecMenu.size() ) { MenuCell *pIcon = new MenuCell( this ); pIcon->LoadFromBookMenuData( &m_bookData.m_vecMenu[row] ); pIcon->UpdateStatus( BookDB::Instance()->GetBookMenuDownloadStatus( &m_bookData , row ) , BookDB::Instance()->GetBookMenuReadStatus( &m_bookData , row ) ); cell->addSubview(pIcon); pIcon->release(); m_vecMenuCell[row] = pIcon; } return cell; }
CATableViewCell* MenuViewController::tableCellAtIndex(CATableView* table, const DSize& cellSize, unsigned int section, unsigned int row) { DSize _size = cellSize; CATableViewCell* cell = table->dequeueReusableCellWithIdentifier("CrossApp"); if (cell == NULL) { cell = CATableViewCell::create("CrossApp"); cell->setBackgroundView(NULL); CALabel* test = CALabel::createWithCenter(DRect(_size.width/2+30, _size.height/2, _size.width, _size.height)); test->setTextAlignment(CATextAlignmentLeft); test->setVerticalTextAlignmet(CAVerticalTextAlignmentCenter); test->setFontSize(_px(32)); test->setColor(CAColor_white); test->setTag(100); cell->addSubview(test); CAImageView* arrow = CAImageView::createWithCenter(DRect(_size.width-64,_size.height/2,64,64)); arrow->setTag(101); cell->addSubview(arrow); } CALabel* test = (CALabel*)cell->getSubviewByTag(100); test->setText(unicode_to_utf8(menuList[row]));// menuList[row]); CAImageView* arrow = (CAImageView*)cell->getSubviewByTag(101); arrow->setImage(CAImage::create("source_material/cell_btn_right.png")); return cell; }
void CATableView::ccTouchEnded(CCTouch *pTouch, CCEvent *pEvent) { CAScrollView::ccTouchEnded(pTouch, pEvent); if (m_pHighlightedTableCells) { this->stopActionByTag(0xffff); CATableViewCell* deselectedCell = NULL; CATableViewCell* selectedCell = m_pHighlightedTableCells; m_pHighlightedTableCells = NULL; if (m_pSelectedTableCells.count(selectedCell) > 0 && m_bAllowsMultipleSelection) { deselectedCell = selectedCell; selectedCell = NULL; m_pSelectedTableCells.erase(deselectedCell); } else { if (m_pSelectedTableCells.size() > 0 && m_bAllowsMultipleSelection == false) { deselectedCell = *m_pSelectedTableCells.begin(); m_pSelectedTableCells.clear(); } m_pSelectedTableCells.insert(selectedCell); } if (deselectedCell) { deselectedCell->setControlStateNormal(); if (m_pTableViewDelegate) { m_pTableViewDelegate->tableViewDidDeselectRowAtIndexPath(this, deselectedCell->getSection(), deselectedCell->getRow()); } } if (selectedCell) { selectedCell->setControlStateSelected(); if (m_pTableViewDelegate) { m_pTableViewDelegate->tableViewDidSelectRowAtIndexPath(this, selectedCell->getSection(), selectedCell->getRow()); } } } if (m_pTableViewDelegate) { if (m_pTablePullDownView && m_pContainer->getFrame().origin.y > m_nTablePullViewHeight) { m_pTableViewDelegate->tableViewDidShowPullDownView(this); } if (m_pTablePullUpView && this->getBounds().size.height - (m_pContainer->getFrame().origin.y + m_pContainer->getFrame().size.height) > m_nTablePullViewHeight) { m_pTableViewDelegate->tableViewDidShowPullUpView(this); } } }
bool CATableView::ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent) { if (m_pTouches->count() > 0) return false; if (!CAScrollView::ccTouchBegan(pTouch, pEvent)) return false; if (m_bAllowsSelection && this->isScrollWindowNotOutSide() == false) { CCPoint point = m_pContainer->convertTouchToNodeSpace(pTouch); std::deque<CATableViewCell*>::iterator itr; for (itr=m_pTableCells.begin(); itr!=m_pTableCells.end(); itr++) { CATableViewCell* cell = *itr; if (cell->getFrame().containsPoint(point)) { CC_BREAK_IF(cell->isDisabled()); m_pHighlightedTableCells = cell; CC_BREAK_IF(cell->isSelected()); CCDelayTime* delayTime = CCDelayTime::create(0.1f); CCCallFunc* func = CCCallFunc::create(cell, callfunc_selector(CATableViewCell::setControlStateHighlighted)); CCSequence* actions = CCSequence::create(delayTime, func, NULL); actions->setTag(0xffff); this->runAction(actions); break; } } } m_tBeginPoint = pTouch->getLocation(); return true; }
CATableViewCell* FirstViewController::tableCellAtIndex(CATableView* table, const CCSize& cellSize, unsigned int section, unsigned int row) { CADipSize _size = cellSize; CATableViewCell* cell = table->dequeueReusableCellWithIdentifier("CrossApp"); if (cell == NULL) { cell = CATableViewCell::create("CrossApp"); CALabel* test = CALabel::createWithCenter(CADipRect(_size.width*0.5, _size.height*0.5, _size.width*0.8, _size.height)); test->setColor(ccc4(51, 204, 255, 255)); test->setTextAlignment(CATextAlignmentCenter); test->setVerticalTextAlignmet(CAVerticalTextAlignmentCenter); test->setFontSize(_px(40)); test->setTag(100); cell->addSubview(test); } CALabel* test = (CALabel*)cell->getSubviewByTag(100); test->setText(testList.at(row)); return cell; }
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 CAPickerView::visit() { if (m_dataSource) { for (int i = 0; i < m_tableViews.size(); i++) { // cycle data CATableView* tableView = (CATableView*)m_tableViews.at(i); CCPoint offset = tableView->getContentOffset(); unsigned int component = (unsigned int)m_tableViews.getIndex(tableView); int row = m_dataSource->numberOfRowsInComponent(this, component); int row_height = m_dataSource->rowHeightForComponent(this, component); if (row > m_displayRow[component]) { if (offset.y < 0) { offset.y += row * 2 * row_height; tableView->setContentOffset(offset, false); } else if (offset.y > row_height * m_componentsIndex[component].size() - tableView->getFrame().size.height) { offset.y -= row * 2 * row_height; tableView->setContentOffset(offset, false); } } // set opacity int offset_y = abs((int)offset.y); int remainder = offset_y % row_height; int index = offset_y / row_height; if (remainder >= row_height * 0.5) { index++; } for (int i=index-1; i<index + m_displayRow[component] + 2; i++) { CATableViewCell* cell = tableView->cellForRowAtIndexPath(0, i); if (cell) { float y = cell->getFrameOrigin().y - offset_y + cell->getFrame().size.height/2; float mid = tableView->getFrame().size.height/2; float length = fabs(mid - y); float op = (fabs(length - mid))/mid; op = powf(op, 2); op = MAX(op, 0.1f); cell->setAlpha(op); } } // fixed position in the middle if (!tableView->isDecelerating() && !tableView->isTracking()) { if (remainder > row_height/2) { index++; offset.y = index * row_height; tableView->setContentOffset(offset, true); } else if (remainder > 0) { offset.y = index * row_height; tableView->setContentOffset(offset, true); } else { // set selected when stop scrolling. int selected = index + m_displayRow[component]/2; if (m_selected[component] != selected) { m_selected[component] = selected; if (m_delegate) { m_delegate->didSelectRow(this, m_componentsIndex[component][m_selected[component]], component); } } } } } } CAView::visit(); }