CCListViewCell *CCListViewCell::node(void) { CCListViewCell *pRet = new CCListViewCell(); pRet->initWithColorWidthHeight(ccc4(255, 255, 255, 255), 0, 0); pRet->autorelease(); return pRet; }
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 NewsScene::CCListView_cellForRow(CCListView *listView, CCListViewProtrolData *data) { CCSize listItemSize = CCSize(list->getContentSize().width, 119); News *item = (News*) this->listNews.at(data->nRow); CCListViewCell *cell = CCListViewCell::node(); cell->setOpacity(255); cell->setColor(ccc3(255, 255, 255)); cell->setContentSize(listItemSize); data->cell = cell; CCSprite *sprBackground; sprBackground = CCSprite::create("background_informacoes.png"); if(item->url_link.empty()) { sprBackground = CCSprite::create("background_informacoes2.png"); } sprBackground->setAnchorPoint(ccp(0,0)); sprBackground->setScale(1); sprBackground->setPosition(ccp(0,0)); cell->addChild(sprBackground); int margem = 25; int recuo = 15; int titleLines = 1; int textLines = 6; int titleFontSize =18; int textFontSize =12; CCSprite * img = getImageFromURL(item->imagem.c_str()); if (img->boundingBox().size.width > 0 && img->boundingBox().size.height > 0) { img->setAnchorPoint(ccp(0,0)); img->setScale(0.35); img->setPosition(ccp(10,margem-4)); cell->addChild(img); recuo = 130; } CCLabelTTF * labelTitle; // if(bold) labelTitle = CCLabelTTF::criar(item->titulo.c_str(), CCSizeMake(cell->getContentSize().width-margem, titleFontSize*titleLines), kCCTextAlignmentLeft, "LucidaGrandeBold", titleFontSize); // else // labelTitle = CCLabelTTF::create(datatext, "Lucida Grande", size); labelTitle->setPosition(ccp(10, cell->getContentSize().height-titleFontSize*titleLines-7)); labelTitle->setAnchorPoint(ccp(0,0)); labelTitle->setColor(ccc3(80, 80, 80)); cell->addChild(labelTitle); CCLabelTTF *labelDesc; labelDesc = CCLabelTTF::criar(item->texto.c_str(), CCSizeMake(cell->getContentSize().width-recuo-margem, textFontSize*textLines-4), kCCTextAlignmentLeft, "Lucida Grande", textFontSize); labelDesc->setPosition(ccp(recuo, margem)); labelDesc->setAnchorPoint(ccp(0,0)); labelDesc->setColor(ccc3(100, 100, 100)); cell->addChild(labelDesc); // CCSprite *img = getImageFromURL("http://clientes.farofastudios.com.br/Einstein/admin/v2/imagens/1396547632556.png"); // labelDesc->setPosition(ccp(0, cell->getContentSize().height - 20 )); // labelDesc->setAnchorPoint(ccp(0,0)); // labelDesc->setColor(ccc3(255, 255, 255)); // cell->addChild(labelDesc); }
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; } }