void MessageView::CCListView_cellForRow(CCListView *listView, CCListViewProtrolData *data) { // 背景 CCSprite* cellBg = CCSprite::create("bg_listview_item.png") ; const float cell_width = cellBg->getContentSize().width+15 ; const float cell_height = cellBg->getContentSize().height+10 ; CCListViewCell* cell = CCListViewCell::node() ; cell->setContentSize(CCSizeMake(cell_width, cell_height)) ; cell->setOpacity(0) ; // cell->setSelectionColor(ccc4(255, 0, 0, 255)) ; cell->setSelectionColor(ccc4(103, 102, 204, 255)) ; data->cell = cell ; CCNode* cellNode = CCNode::create() ; cellNode->setContentSize(CCSizeMake(cell_width, cell_height)) ; cellNode->setAnchorPoint(ccp(0, 0)) ; cellNode->setPosition(ccp(0, 0)) ; cell->addChild(cellNode) ; // 背景 cellBg->setAnchorPoint(ccp(0.5, 0.5)) ; cellBg->setPosition(ccp(cell_width*0.5, cell_height*0.5)) ; cellNode->addChild(cellBg) ; // icon CCSprite* iconMsg = CCSprite::create("icon_msg.png") ; iconMsg->setAnchorPoint(ccp(0, 0.5)) ; iconMsg->setPosition(ccp(20, cell_height*0.5)) ; cellNode->addChild(iconMsg, 1) ; // 主题 CCLabelTTF* themeLabel = CCLabelTTF::create("蛇年贺新春,免费拿九玩币","font01.ttf", 24.0f,CCSizeMake(cell_width, 50), kCCTextAlignmentLeft, kCCVerticalTextAlignmentCenter) ; themeLabel->setColor(ccc3(255, 215, 0)) ; themeLabel->setAnchorPoint(ccp(0, 1)) ; themeLabel->setPosition(ccp(120, cell_height-8)) ; cellNode->addChild(themeLabel, 1) ; // 内容 CCLabelTTF* contentLabel = CCLabelTTF::create("蛇年贺新春,免费拿九玩币,蛇年贺新春,免费拿九玩币","font01.ttf", 20.0f,CCSizeMake(cell_width, 50), kCCTextAlignmentLeft, kCCVerticalTextAlignmentCenter) ; contentLabel->setAnchorPoint(ccp(0, 0)) ; contentLabel->setPosition(ccp(120, 8)) ; cellNode->addChild(contentLabel, 1) ; }
void CCTextureWatcher::CCListView_cellForRow(CCListView *listView, CCListViewProtrolData *data) { m_nCurrnetPage = data->nRow + 1; CCListViewCell *cell = CCListViewCell::node(); cell->setOpacity(0); cell->setContentSize(m_pList->getContentSize()); cell->setSelectionColor(ccc4(0, 0, 0, 0)); data->cell = cell; CCSize listItemSize = CCSize(m_pList->getContentSize().width / NUM_PER_PAGE, m_pList->getContentSize().height); CCSize size = CCSize(listItemSize.width * 0.9, listItemSize.height * 0.6); sprintf(m_pszString, "%d/%d", m_nCurrnetPage, m_nTotalPage); m_labelPage->setString(m_pszString); float offX = 0, offY = 0, offsetX = 0, offsetY = 0; CC_UNUSED_PARAM(offsetY); int nCount = 0; int nStart = (m_nCurrnetPage - 1) * NUM_PER_PAGE; int nEnd = nStart + NUM_PER_PAGE; CCDictElement* pElement = NULL; CCDICT_FOREACH(m_pTextures, pElement) { if (nCount >= nStart && nCount < nEnd) { string key = pElement->getStrKey(); CCTexture2D* textrue = (CCTexture2D*)pElement->getObject(); //textrue = m_pTextures->objectForKey(*it); if (textrue) { // reference count sprintf(m_pszString, "[%d]", textrue->retainCount() - 2); CCLabelTTF *labelCount = CCLabelTTF::labelWithString(m_pszString, "Arial", 16); if (textrue->retainCount() - 2 > 0) { labelCount->setColor(ccc3(0, 255, 0)); } else { labelCount->setColor(ccc3(255, 0, 0)); } offX = offsetX + listItemSize.width * 0.5 - labelCount->getContentSize().width * 0.5; offY = (listItemSize.height - size.height) * 0.5 - labelCount->getContentSize().height; labelCount->setPosition(ccp(offX, offY)); labelCount->setAnchorPoint(ccp(0, 0)); cell->addChild(labelCount); // texture size sprintf(m_pszString, "%.0f*%.0f", textrue->getContentSize().width, textrue->getContentSize().height); CCLabelTTF *labelSize = CCLabelTTF::labelWithString(m_pszString, "Arial", 16); offX = offsetX + listItemSize.width * 0.5; offY = (listItemSize.height - size.height) * 0.5 + size.height; labelSize->setPosition(ccp(offX, offY)); labelSize->setAnchorPoint(ccp(0.5, 0)); cell->addChild(labelSize); // texture name int len = key.length(); int pos = 0; pos = key.rfind('\\') + 1; int pos2 = key.rfind('/') + 1; pos = pos > pos2 ? pos : pos2; string name = key.substr(pos, len - pos); sprintf(m_pszString, "%s", name.c_str()); CCSize dimensions = CCSizeMake(listItemSize.width * 0.9, labelSize->getContentSize().height); CCLabelTTF *labelName = CCLabelTTF::labelWithString(m_pszString, dimensions, CCTextAlignmentCenter, "Arial", 16); offX = offsetX + listItemSize.width * 0.5; offY = offY + labelName->getContentSize().height; labelName->setPosition(ccp(offX, offY)); labelName->setAnchorPoint(ccp(0.5, 0)); cell->addChild(labelName); CCSprite *sprite = CCSprite::spriteWithTexture(textrue); sprite->setAnchorPoint(ccp(0, 0)); CCSize spriteSize = sprite->getContentSize(); float scale; if (spriteSize.width < size.width && spriteSize.height < size.height) { scale = 1; } else if (spriteSize.width * size.height >= spriteSize.height * size.width) { scale = size.width / spriteSize.width; } else { scale = size.height / spriteSize.height; } sprite->setScale(scale); spriteSize.width *= scale; spriteSize.height *= scale; offX = offsetX + (listItemSize.width - spriteSize.width) * 0.5; offY = (listItemSize.height - spriteSize.height) * 0.5; sprite->setPosition(ccp(offX, offY)); cell->addChild(sprite); offsetX += listItemSize.width; } } ++nCount; } }