CCTableGridCell* CCTableGridBackPackTest::tableviewDataSource(CCTableGrid* pTable, CCTableGridCell* pCell, unsigned int idx) { CCButton* pIconButton = NULL; if(!pCell) { pCell = new CCTableGridCell(); pCell->autorelease(); CC9Sprite* pBg = CC9Sprite::create("sprite9_btn1.png"); pBg->setContentSize(CCSize(70, 70)); pBg->setPosition(ccp(320 / 4 / 2, 390 / 5 / 2)); pCell->addChild(pBg); pIconButton = CCButton::create("icon.png"); pIconButton->setLongClickSelector(this, longclick_selector(CCTableGridBackPackTest::onItemLongClick)); pIconButton->getTextTTF()->setFontSize(25); pIconButton->setPosition(ccp(320 / 4 / 2, 390 / 5 / 2)); pIconButton->setTextOffset(ccp(-15, -15)); pIconButton->setTag(1); pCell->addChild(pIconButton); } else { pIconButton = (CCButton*) pCell->getChildByTag(1); } if( idx != CC_INVALID_INDEX ) { pIconButton->setVisible(true); pIconButton->getTextTTF()->setString(m_vData[idx].c_str()); pIconButton->setUserTag(idx); } else { pIconButton->setVisible(false); } return pCell; }
CCTableGridCell* CCTableGridBasicTest::tableviewDataSource(CCTableGrid* pTable, CCTableGridCell* pCell, unsigned int idx) { CCButton* pButton = NULL; if(!pCell) { pCell = new CCTableGridCell(); pCell->autorelease(); pButton = CCButton::createWith9Sprite(CCSizeMake(70, 70), "sprite9_btn1.png", "sprite9_btn2.png"); pButton->setPosition(ccp(320 / 4 / 2, 390 / 5 / 2)); pButton->getTextTTF()->setFontSize(25.0f); pButton->setTag(1); pCell->addChild(pButton); } else { pButton = (CCButton*) pCell->getChildByTag(1); } if( idx != CC_INVALID_INDEX ) { pButton->setVisible(true); char buff[64]; sprintf(buff, "%u", idx); pButton->getTextTTF()->setString(buff); pButton->setUserTag(idx); } else { pButton->setVisible(false); } return pCell; }
//============================================================= //============================================================= void CC3DCircleListLayer::initDataCircle(float fEllipseA,float fEllipseB,CCSize itemSize,CCArray* pArray,bool bFlipY) { if(!pArray) return; m_itemSize = itemSize; m_fEllipseA = fEllipseA; m_fEllipseB = fEllipseB; int nAllItemCount = pArray->count(); float fCircleStepDegree = (2*M_PI)/nAllItemCount; float fMoveX = getContentSize().width*0.5; float fMoveY = getContentSize().height*0.5; m_pButtonArray->removeAllObjects(); for(int i=0;i<nAllItemCount;i++) { float fCurDegree = fCircleStepDegree * (i+1); float fCircleX = m_fEllipseA * cosf(fCurDegree); float fCircleY = m_fEllipseB * sinf(fCurDegree); fCircleX += fMoveX; fCircleY += fMoveY; CCSprite* pSprite = (CCSprite*)pArray->objectAtIndex(i); CCScale9Sprite* pScaleSprite = CCScale9Sprite::createWithSpriteFrame(pSprite->displayFrame()); CCButton* pButton = CCButton::create( pScaleSprite); pButton->setTag(i); pButton->setZoomOnTouchDown(false); CCPoint point = ccp(fCircleX,fCircleY); pButton->setPosition(point); CCString* pString = new CCString(); pString->initWithFormat("%f",fCurDegree); pButton->setUserData(pString); pButton->addTargetWithActionForControlEvents(this, cccontrol_selector(CC3DCircleListLayer::clickButton), CCControlEventTouchUpInside); addChild(pButton); m_pButtonArray->addObject(pButton); if(bFlipY) { CCSize buttonSize = pButton->getContentSize(); CCSprite* pFlipYSprite = CCSprite::createWithTexture(pSprite->getTexture()); CCRect oldRect = pSprite->getTextureRect(); pFlipYSprite->setFlipY(true); pFlipYSprite->setOpacity(255*0.5); pFlipYSprite->setAnchorPoint(ccp(0.5,1)); pFlipYSprite->setPosition(ccp(buttonSize.width*0.5,0)); pButton->addChild(pFlipYSprite); } // CCSize buttonSize = pButton->getContentSize(); // char testChr[32]; // sprintf(testChr, "%d",i); // CCLabelTTF* pTestLabel = CCLabelTTF::create(testChr, "Arial", 52); // pTestLabel->setColor(ccRED); // pTestLabel->setPosition(ccp(buttonSize.width*0.5,buttonSize.height*0.5)); // pButton->addChild(pTestLabel); } refreshItemWithMoveDegree(0); }