void NDUITableLayer::MoveSection(unsigned int sectionIndex, int moveLen) { if (moveLen == 0) return; NDUISectionTitle* sectionTitle = m_sectionTitles.at(sectionIndex); CGRect sectionRect = sectionTitle->GetFrameRect(); sectionTitle->SetFrameRect(CGRectMake(sectionRect.origin.x, sectionRect.origin.y + moveLen, sectionRect.size.width, sectionRect.size.height)); NDUIRecttangle* background = m_backgrounds.at(sectionIndex); CGRect bkgRect = background->GetFrameRect(); background->SetFrameRect(CGRectMake(bkgRect.origin.x, bkgRect.origin.y + moveLen, bkgRect.size.width, bkgRect.size.height)); if (m_scrollBarVisibled) { NDUIVerticalScrollBar* scrollBar = m_scrollBars.at(sectionIndex); CGRect sbRect = scrollBar->GetFrameRect(); scrollBar->SetFrameRect(CGRectMake(sbRect.origin.x, sbRect.origin.y + moveLen, sbRect.size.width, sbRect.size.height)); } NDSection* section = m_dataSource->Section(sectionIndex); for (unsigned int j = 0; j < section->Count(); j++) { NDUINode* uiNode = section->Cell(j); CGRect nodeRect = uiNode->GetFrameRect(); uiNode->SetFrameRect(CGRectMake(nodeRect.origin.x, nodeRect.origin.y + moveLen, nodeRect.size.width, nodeRect.size.height)); } }
void CUIDialog::SetUIText(const char* text, int nTag) { NDUINode* node = (NDUINode*)this->GetChild(nTag); if (!node || !node->IsKindOfClass(RUNTIME_CLASS(NDUIText))) { return; } CCRect rect = node->GetFrameRect(); unsigned int uiFontSize = ((NDUIText*)node)->GetFontSize(); ccColor4B color = ((NDUIText*)node)->GetFontColor(); this->RemoveChild(nTag, true); if (!text || 0 == strlen(text)) { NDUIText *uitext = new NDUIText; uitext->Initialization(false); uitext->SetFrameRect(rect); uitext->SetFontSize(uiFontSize); uitext->SetFontColor(color); uitext->SetTag(nTag); this->AddChild(uitext); uitext->SetVisible(this->IsVisibled()); return; } NDUIText* uitext = NDUITextBuilder::DefaultBuilder()->Build( text, uiFontSize, rect.size, color, false, false); uitext->SetFrameRect(rect); uitext->SetTag(nTag); uitext->SetFontSize(uiFontSize); uitext->SetFontColor(color); this->AddChild(uitext); uitext->SetVisible(this->IsVisibled()); }
void CUIDialog::AddOpt(const char* text, int nAction) { if (!text) { return; } NDUINode* node = (NDUINode*)this->GetChild(ID_TASKCHAT_CTRL_PICTURE_7); if (!node || !node->IsKindOfClass(RUNTIME_CLASS(NDUIImage))) { return; } CCRect rectNode = node->GetFrameRect(); //CCSize winsize = CCDirector::sharedDirector()->getWinSizeInPixels(); float fScale = ANDROID_SCALE; CCRect rect; cocos2d::CCLog("tzq fScale = %05f, x = %05f, y = %05f, w = %05f, h = %05f, m_uiOptHeight = %u", fScale, rectNode.origin.x, rectNode.origin.y, rectNode.size.width, rectNode.size.height, m_uiOptHeight); rect.origin = ccpAdd(rectNode.origin, ccp(0, m_vUiOpt.size() * m_uiOptHeight)); rect.size = CCSizeMake(rectNode.size.width*1.1, m_uiOptHeight); CUIDlgOptBtn *uiOpt = new CUIDlgOptBtn; uiOpt->Initialization(); uiOpt->SetFrameRect(rect); uiOpt->SetBoundRect(rect); //uiOpt->SetLinkTextFontSize(13*fScale); uiOpt->SetLinkTextFontSize(12); uiOpt->SetLinkTextColor(ccc4(255, 255, 0, 255)); uiOpt->SetLinkText(text); uiOpt->SetDelegate(this); this->AddChild(uiOpt); m_vUiOpt.push_back(uiOpt); m_vId.push_back(nAction); }
void NDUITableLayer::OnSectionTitleClick(NDUISectionTitle* sectionTitle) { if (m_dataSource) { for (unsigned int i = 0; i < m_sectionTitles.size(); i++) { NDUISectionTitle* section = m_sectionTitles.at(i); if (sectionTitle == section) { if (i == m_curSectionIndex && i+1 < m_sectionTitles.size()) m_curSectionIndex = i+1; else m_curSectionIndex = i; m_curSection = m_dataSource->Section(m_curSectionIndex); } } for (unsigned int i = 0; i < m_sectionTitles.size(); i++) { NDUISectionTitle* section = m_sectionTitles.at(i); if (i == m_curSectionIndex) { section->OnTouchDown(true); } else { section->OnTouchDown(false); } } for (unsigned int i = 0 ; i <= m_curSectionIndex; i++) { CGRect sectionTitleRect = m_sectionTitles.at(i)->GetFrameRect(); this->MoveSection(i, i * m_sectionTitlesHeight - sectionTitleRect.origin.y); } CGRect rect = this->GetFrameRect(); for (unsigned int i = m_dataSource->Count() -1 ; i > m_curSectionIndex; i--) { CGRect sectionTitleRect = m_sectionTitles.at(i)->GetFrameRect(); this->MoveSection(i, rect.size.height - sectionTitleRect.origin.y - sectionTitleRect.size.height); rect = CGRectMake(rect.origin.x, rect.origin.y, rect.size.width, rect.size.height - sectionTitleRect.size.height); } //set enable draw for (unsigned int i = 0 ; i < m_dataSource->Count(); i++) { NDUIRecttangle* background = m_backgrounds.at(i); if (i == m_curSectionIndex) background->EnableDraw(true); else background->EnableDraw(false); NDSection* section = m_dataSource->Section(i); for (unsigned int j = 0; j < section->Count(); j++) { NDUINode* uiNode = section->Cell(j); if (i == m_curSectionIndex && CGRectIntersectsRect(background->GetFrameRect(), uiNode->GetFrameRect())) uiNode->EnableDraw(true); else uiNode->EnableDraw(false); } } //set focus this->SetFocusOnCell(m_curSection->GetFocusCellIndex()); } }
CGRect NDUITableLayer::GetCellRectWithIndex(unsigned int sectionIndex, unsigned int cellIndex) { CGRect rect = CGRectZero; NDSection* section = m_dataSource->Section(sectionIndex); if (section) { //get rect.origin.x int row = section->Count() / section->GetColumnCount() + 1; int columnIndex = cellIndex / row; CGFloat cellWitdh; if (m_scrollBarVisibled) { cellWitdh = (this->GetFrameRect().size.width - m_scrollBarWidth) / section->GetColumnCount(); } else { cellWitdh = this->GetFrameRect().size.width / section->GetColumnCount(); } rect.origin.x = columnIndex * cellWitdh + m_cellsLeftDistance; //get rect.origin.y if (m_sectionTitleVisibled) { rect.origin.y = (sectionIndex + 1) * m_sectionTitlesHeight; } if (section->IsUseCellHeight()) { rect.origin.y += m_cellsInterval; for (unsigned int i = 0; i < cellIndex; i++) { NDUINode* uiNode = section->Cell(i); if (uiNode) { rect.origin.y += uiNode->GetFrameRect().size.height + m_cellsInterval; } } } else { int rowIndex = cellIndex / section->GetColumnCount(); rect.origin.y += rowIndex * (section->GetRowHeight() + m_cellsInterval) + m_cellsInterval; } //get rect.size.width rect.size.width = cellWitdh - m_cellsLeftDistance - m_cellsRightDistance; //get rect.size.height if (section->IsUseCellHeight()) { NDUINode* uiNode = section->Cell(cellIndex); rect.size.height = uiNode->GetFrameRect().size.height; } else { rect.size.height = section->GetRowHeight(); } } return rect; }
bool NDUITableLayer::TouchMoved(NDTouch* touch) { NDUILayer::TouchMoved(touch); if (m_sectionTitleVisibled) { for (unsigned int i = 0; i < m_sectionTitles.size(); i++) { NDUISectionTitle* sectionTitle = m_sectionTitles.at(i); CGRect rect = sectionTitle->GetScreenRect(); if (CGRectContainsPoint(rect, m_beginTouch)) return false; } } //this->SetFocusOnCell(m_curSection->GetFocusCellIndex()); if (m_curSection) { CGPoint prePos = touch->GetPreviousLocation(); CGPoint curPos = touch->GetLocation(); CGFloat subValue = curPos.y - prePos.y; if (m_sectionTitles.size() > m_curSectionIndex) { NDUISectionTitle* sectionTitle = m_sectionTitles.at(m_curSectionIndex); CGRect sectionTitleRect = sectionTitle->GetFrameRect(); if (m_curSection->Count() > 0) { if (subValue > 0) { NDUINode* firstCell = m_curSection->Cell(0); if (m_sectionTitleVisibled) { if (firstCell->GetFrameRect().origin.y + subValue > sectionTitle->GetFrameRect().origin.y + sectionTitle->GetFrameRect().size.height) { subValue = sectionTitle->GetFrameRect().origin.y + sectionTitle->GetFrameRect().size.height - firstCell->GetFrameRect().origin.y + m_cellsInterval; } } else { if (firstCell->GetFrameRect().origin.y + subValue > sectionTitle->GetFrameRect().origin.y) { subValue = sectionTitle->GetFrameRect().origin.y - firstCell->GetFrameRect().origin.y + m_cellsInterval; } } if (subValue <= 0) return false; } else { NDUINode* lastCell = m_curSection->Cell(m_curSection->Count() - 1); CGFloat sectionBottom = this->GetFrameRect().size.height; if (m_curSectionIndex + 1 < m_dataSource->Count()) { NDUISectionTitle* nextSectionTitle = m_sectionTitles.at(m_curSectionIndex + 1); sectionBottom = nextSectionTitle->GetFrameRect().origin.y - m_cellsInterval; } if (lastCell->GetFrameRect().origin.y + lastCell->GetFrameRect().size.height + subValue < sectionBottom) { subValue = sectionBottom - lastCell->GetFrameRect().origin.y - lastCell->GetFrameRect().size.height - m_cellsInterval; } if (subValue >= 0) return false; } } } if (m_backgrounds.size() > m_curSectionIndex) { NDUIRecttangle* cellBackground = m_backgrounds.at(m_curSectionIndex); for (unsigned int i = 0; i < m_curSection->Count(); i++) { NDUINode* uiNode = m_curSection->Cell(i); CGRect nodeRect = uiNode->GetFrameRect(); uiNode->SetFrameRect(CGRectMake(nodeRect.origin.x, nodeRect.origin.y + subValue, nodeRect.size.width, nodeRect.size.height)); bool bDraw = CGRectIntersectsRect(cellBackground->GetFrameRect(), uiNode->GetFrameRect()); uiNode->EnableDraw(bDraw); } } if (m_scrollBars.size() > m_curSectionIndex) { if (m_scrollBarVisibled) { NDUIVerticalScrollBar* scrollBar = m_scrollBars.at(m_curSectionIndex); scrollBar->SetCurrentContentY(scrollBar->GetCurrentContentY() - subValue); } } } return true; }