CCounter* CCounter::create(CCArray* presenters, int digit) { CCounter* counter = new CCounter(); counter->init(presenters, digit); counter->autorelease(); return counter; }
void CCounterImage::_updata() { int nTotalWidth = 0; int nCounter = 0; int nAmount = _vecNumber.size(); for(int i = 0 ;i < nAmount;i++){ CCounter* counter = dynamic_cast<CCounter*>(_vecNumber[i]); if(counter) nTotalWidth += /*counter->getCurrDigit()->getContentSize().width*/_cellNumberWidth; else{ nTotalWidth += _vecNumber[i]->getContentSize().width; } } int nWidth = 0; for(int i = nAmount-1 ;i >= 0; i--){ CCounter* counter = dynamic_cast<CCounter*>(_vecNumber[i]); if(counter) { nWidth += /*counter->getCurrDigit()->getContentSize().width*/_cellNumberWidth/2; counter->setPositionX(-nTotalWidth/2 + nWidth); nWidth += /*counter->getCurrDigit()->getContentSize().width*/_cellNumberWidth/2; }else { nWidth += _vecNumber[i]->getContentSize().width/2; _vecNumber[i]->setPositionX(-nTotalWidth/2 + nWidth); nWidth += _vecNumber[i]->getContentSize().width/2; } //nWidth += counter->getCurrDigit()->getContentSize().width; } _totalWidth = nTotalWidth; }
void CProfiler::startCounter(const char* szCounterName) { CCounter* pCounter = m_mapCounters[szCounterName]; if ( !pCounter || !pCounter->isWasStarted() ) LOG(INFO) + szCounterName + " : START"; if ( !pCounter ) m_mapCounters[szCounterName] = new CCounter(); else pCounter->start(); }
void CProfiler::startCreatedCounter(const char* szCounterName) { CCounter* pCounter = m_mapCounters[szCounterName]; if ( !pCounter ) return; if ( !pCounter->isWasStarted() ) LOG(INFO) + szCounterName + " : START"; pCounter->start(); }
void CProfiler::flushCounter(const char* szCounterName, const char* msg) { CCounter* pCounter = m_mapCounters[szCounterName]; if ( !pCounter ){ LOG(ERROR) + szCounterName + " : Cannot find counter."; return; } common::CTimeInterval oInterval = pCounter->flush(); LOG(INFO) + szCounterName + (msg && *msg ? " - " : "" ) + (msg && *msg ? msg : "" ) + " (" + oInterval.toString() + ") : STOP"; }
void CProfiler::stopCounter(const char* szCounterName, bool bDestroy /*=false*/) { CCounter* pCounter = m_mapCounters[szCounterName]; if ( !pCounter ){ LOG(ERROR) + szCounterName + " : Cannot find counter."; return; } if ( bDestroy || !pCounter->isGlobal() ) { common::CTimeInterval oInterval = pCounter->stop(); LOG(INFO) + szCounterName + " (" + oInterval.toString() + ") : STOP"; m_mapCounters.erase(szCounterName); }else pCounter->stop(); }
bool CCounterImage::init(const VEC_NUMFILENAME& vecNumFileName,int number, char* pDelim, bool bpListLoad) { //int fontSize = 16; //CCLabelTTF* goldLabel = CCLabelTTF::create("金币:", "Thonburi", fontSize); //this->addChild(goldLabel); //CCSize goldLabelSize = goldLabel->getContentSize(); _delim = pDelim; CCString str; int nCounter = 0; for(int i = 0 ;i < _SCORE_NUM_MAX_;i++){ int count = vecNumFileName.size(); CCArray* presenters = CCArray::createWithCapacity(count); for(int j = 0;j < count;j++){ str.initWithFormat(vecNumFileName[j].c_str()); CCSprite* p = NULL; if(bpListLoad) p = CCSprite::createWithSpriteFrameName(str.getCString()); else p = CCSprite::create(str.getCString()); presenters->addObject(p); } CCounter* counter = CCounter::create(presenters); //counter->setPosition(ccp(/*goldLabelSize.width*0.8+*/31 * i, 0)); this->addChild(counter, 0, i); if(_delim){ if(i % 3 == 0 && i > 0){ CCSprite* p = NULL; p = CCSprite::create(_delim); if(p == NULL) p = CCSprite::createWithSpriteFrameName(_delim); p->setVisible(false); p->setPositionY(p->getContentSize().height/2 - counter->getCurrDigit()->getContentSize().height/2); this->addChild(p, 0, eDelimStartIndex + nCounter); nCounter++; } } } this->setNumber(number); return true; }
void CCounterImage::setNumber(int number,bool bAni,unsigned int ceiling) { number = MIN(ceiling, number); number = MAX(number, 0); _number = number; for(int i = 0 ;i < _SCORE_NUM_MAX_;i++){ CCounter* counter = (CCounter*)this->getChildByTag(i); counter->setVisible(false); } int nAmountDot = _SCORE_NUM_MAX_%3 > 0 ? _SCORE_NUM_MAX_/3 : _SCORE_NUM_MAX_/3 - 1; for (int i = 0; i < nAmountDot; ++i) { this->getChildByTag(eDelimStartIndex + i)->setVisible(false); } _vecNumber.clear(); int nAmount = CStringUtil::ToString(_number).size(); int nCounter = 0; int nIndex = 0; for(int i = nAmount - 1; i >= 0;i--){ if(_delim && nCounter > 0 && nCounter % 3 == 0){ CCNode* pDot = this->getChildByTag(eDelimStartIndex + nIndex); pDot->setVisible(true); _vecNumber.push_back(pDot); nIndex ++; } CCounter* counter = (CCounter*)this->getChildByTag(i); int digit = _number / (int)(pow(10.0, nAmount-i-1)) % 10; counter->setDigit(digit,bAni); counter->setVisible(true); _vecNumber.push_back(counter); nCounter++; } _updata(); }