void BBProgressBar::updateProgress() { float pv = (m_fCurrent - m_fMin) / (m_fMax - m_fMin); if(m_fMax - m_fMin == 0) pv=0; if(pv<0) pv=0; if(pv>1) pv=1; switch (m_nProgressBarMode) { case BB_PROGRESSBAR_MODE_SCALE: { } break; //基于9格缩放的进度条机制 case BB_PROGRESSBAR_MODE_LAYOUT: { CCSize sizeLayout = m_pBackground->getContentSize(); sizeLayout.width *= pv; CCScale9Sprite* pro = dynamic_cast<CCScale9Sprite*>(m_pProgress); if(pro) { pro->setPreferredSize(sizeLayout); if(m_bHideProgress) pro->setVisible(false); else if(pv>0.01) pro->setVisible(true); else pro->setVisible(false); } if(m_pLabel) { m_pLabel->setString(FORMAT("%d", (int)m_fCurrent)); } } break; case BB_PROGRESSBAR_MODE_CIRCLE: { if(m_pPotentiometer) { m_pPotentiometer->setMaximumValue(m_fMax); m_pPotentiometer->setMinimumValue(m_fMin); m_pPotentiometer->setValue(m_fCurrent); } } break; } };
void resetScroll(){ if(!_scrollBar){ return;} CCSize vs = getViewSize(), cs = getContentSize(); bool vert = getDirection() == kCCScrollViewDirectionVertical; bool v = vert? vs.height < cs.height : vs.width < cs.height; _scrollBar->setVisible(v); CCPoint p = ccp(0, 0), ap = vert? ccp(1,0) : CCPointZero; if(v){ CCSize s = _scrollBar->getPreferredSize(), st = _scrollTrack? _scrollTrack->getPreferredSize() : CCSizeZero; if(vert){ p.x = vs.width + _scrollOffset - (st.width > 0? (st.width - s.width) / 2 : 0); _scrollTrackDelta = st.height > 0? (st.height - s.height) / 2 : 0; s.height = vs.height / cs.height * vs.height - _scrollTrackDelta * 2; }else{ p.y = vs.height + _scrollOffset - (st.height > 0? (st.height - s.height) / 2 : 0); _scrollTrackDelta = st.width > 0? (st.width - s.width) / 2 : 0; s.width = vs.width / cs.width * vs.width - _scrollTrackDelta * 2; } _scrollBar->setAnchorPoint(ap); _scrollBar->setPreferredSize(s); _scrollBar->setPosition(p); //CCLog("LuaTableView vScroll.size=%d,%d vh=%d ch=%d", (int)s.width, (int)s.height, (int)vs.height, (int)cs.height); } if(_scrollTrack){ _scrollTrack->setVisible(v); if(v){ CCSize s = _scrollTrack->getPreferredSize(); if(vert){ p.x = vs.width + _scrollOffset; s.height = vs.height; }else{ p.y = vs.height + _scrollOffset; s.width = vs.width; } _scrollTrack->setAnchorPoint(ap); _scrollTrack->setPreferredSize(s); _scrollTrack->setPosition(p); } } //CCLog("LuaTableView reload vscr=%x visible=%d", _scroller, _scrollBar->isVisible()); updateScroll(); }
void CCAnimate9SpriteProgress::update(float fraction) { CCNode* target = getTarget(); CCScale9Sprite* sprite = (CCScale9Sprite*)target; float width = beginSize.width + fraction * distance; if (capAtMax) width = std::min(width, maxWidth); else while (width - maxWidth > 1e-3) width -= maxWidth; if (width - minWidth < 1e-3) width = minWidth; sprite->setVisible(width > minWidth); sprite->setContentSize(CCSize(width, beginSize.height)); }