Beispiel #1
0
void UILoadingBar::barRendererScaleChangedWithSize()
{
    if (m_bIgnoreSize)
    {
        if (!m_bScale9Enabled)
        {
            m_fTotalLength = m_barRendererTextureSize.width;
            m_pBarRenderer->setScale(1.0f);
            m_size = m_barRendererTextureSize;
        }
    }
    else
    {
        m_fTotalLength = m_size.width;
        if (m_bScale9Enabled)
        {
            setScale9Scale();
        }
        else
        {
            
            Size textureSize = m_pBarRenderer->getContentSize();
            if (textureSize.width <= 0.0f || textureSize.height <= 0.0f)
            {
                m_pBarRenderer->setScale(1.0f);
                return;
            }
            float scaleX = m_size.width / textureSize.width;
            float scaleY = m_size.height / textureSize.height;
            m_pBarRenderer->setScaleX(scaleX);
            m_pBarRenderer->setScaleY(scaleY);
        }
    }
    m_pBarRenderer->setPosition(Point(-m_fTotalLength * 0.5f, 0.0f));
}
Beispiel #2
0
void LoadingBar::setPercent(int percent)
{
    if ( percent < 0 || percent > 100)
    {
        return;
    }
    if (_totalLength <= 0)
    {
        return;
    }
    _percent = percent;
    float res = _percent / 100.0f;
    
    if (_scale9Enabled)
    {
        setScale9Scale();
    }
    else
    {
        Sprite* spriteRenderer = static_cast<Sprite*>(_barRenderer);
        Rect rect = spriteRenderer->getTextureRect();
        rect.size.width = _barRendererTextureSize.width * res;
        spriteRenderer->setTextureRect(rect, spriteRenderer->isTextureRectRotated(), rect.size);
    }
}
Beispiel #3
0
void LoadingBar::updateProgressBar()
{
    if (_scale9Enabled)
    {
        setScale9Scale();
    }
    else
    {
        float res = _percent / 100.0f;
        Rect rect = _barRenderer->getTextureRect();
        rect.size.width = _barRendererTextureSize.width * res;
        _barRenderer->setTextureRect(rect, _barRenderer->isTextureRectRotated(), rect.size);
    }
}
Beispiel #4
0
void LoadingBar::barRendererScaleChangedWithSize()
{
    if (_unifySize)
    {
        //_barRenderer->setPreferredSize(_contentSize);
        _totalLength = _contentSize.width;
        this->setPercent(_percent);
    }
    else if (_ignoreSize)
    {
        if (!_scale9Enabled)
        {
            _totalLength = _barRendererTextureSize.width;
            _barRenderer->setScale(1.0f);
        }
    }
    else
    {
        _totalLength = _contentSize.width;
        if (_scale9Enabled)
        {
            setScale9Scale();
        }
        else
        {
            
            Size textureSize = _barRendererTextureSize;
            if (textureSize.width <= 0.0f || textureSize.height <= 0.0f)
            {
                _barRenderer->setScale(1.0f);
                return;
            }
            float scaleX = _contentSize.width / textureSize.width;
            float scaleY = _contentSize.height / textureSize.height;
            _barRenderer->setScaleX(scaleX);
            _barRenderer->setScaleY(scaleY);
        }
    }
    switch (_direction)
    {
        case Direction::LEFT:
            _barRenderer->setPosition(Vec2(0.0f,_contentSize.height*0.5f));
            break;
        case Direction::RIGHT:
            _barRenderer->setPosition(Vec2(_totalLength,_contentSize.height*0.5f));
            break;
        default:
            break;
    }
}
Beispiel #5
0
void UILoadingBar::barRendererScaleChangedWithSize()
{
    if (m_bIgnoreSize)
    {
        if (!m_bScale9Enabled)
        {
            m_fTotalLength = m_barRendererTextureSize.width;
            m_pBarRenderer->setScale(1.0f);
            m_size = m_barRendererTextureSize;
        }
    }
    else
    {
        m_fTotalLength = m_size.width;
        if (m_bScale9Enabled)
        {
            setScale9Scale();
        }
        else
        {
            
            CCSize textureSize = m_pBarRenderer->getContentSize();
            if (textureSize.width <= 0.0f || textureSize.height <= 0.0f)
            {
                m_pBarRenderer->setScale(1.0f);
                return;
            }
            float scaleX = m_size.width / textureSize.width;
            float scaleY = m_size.height / textureSize.height;
            m_pBarRenderer->setScaleX(scaleX);
            m_pBarRenderer->setScaleY(scaleY);
        }
    }
    switch (m_nBarType)
    {
        case LoadingBarTypeLeft:
            m_pBarRenderer->setPosition(ccp(-m_fTotalLength * 0.5f, 0.0f));
            break;
        case LoadingBarTypeRight:
            m_pBarRenderer->setPosition(ccp(m_fTotalLength * 0.5f, 0.0f));
            break;
        default:
            break;
    }
}
Beispiel #6
0
void UILoadingBar::barRendererScaleChangedWithSize()
{
    if (_ignoreSize)
    {
        if (!_scale9Enabled)
        {
            _totalLength = _barRendererTextureSize.width;
            _barRenderer->setScale(1.0f);
            _size = _barRendererTextureSize;
        }
    }
    else
    {
        _totalLength = _size.width;
        if (_scale9Enabled)
        {
            setScale9Scale();
        }
        else
        {
            
            Size textureSize = _barRenderer->getContentSize();
            if (textureSize.width <= 0.0f || textureSize.height <= 0.0f)
            {
                _barRenderer->setScale(1.0f);
                return;
            }
            float scaleX = _size.width / textureSize.width;
            float scaleY = _size.height / textureSize.height;
            _barRenderer->setScaleX(scaleX);
            _barRenderer->setScaleY(scaleY);
        }
    }
    switch (_barType)
    {
        case LoadingBarTypeLeft:
            _barRenderer->setPosition(Point(-_totalLength * 0.5f, 0.0f));
            break;
        case LoadingBarTypeRight:
            _barRenderer->setPosition(Point(_totalLength * 0.5f, 0.0f));
            break;
        default:
            break;
    }
}
void LoadingBar::updateProgressBar()
{
    if (_scale9Enabled)
    {
        setScale9Scale();
    }
    else
    {
        Sprite* innerSprite = _barRenderer->getSprite();
        if (nullptr != innerSprite)
        {
            float res = _percent / 100.0f;
            Rect rect = innerSprite->getTextureRect();
            rect.size.width = _barRendererTextureSize.width * res;
            innerSprite->setTextureRect(rect, innerSprite->isTextureRectRotated(), rect.size);
        }
    }
}
Beispiel #8
0
void UILoadingBar::setPercent(int percent)
{
    if ( percent < 0 || percent > 100)
    {
        return;
    }
    if (m_fTotalLength <= 0)
    {
        return;
    }
    m_nPercent = percent;
    float res = m_nPercent/100.0;
    
    int x = 0, y = 0;
    switch (m_eRenderBarTexType)
    {
        case UI_TEX_TYPE_PLIST:
        {
            Sprite* barNode = DYNAMIC_CAST_Sprite;
            if (barNode)
            {
                Point to = barNode->getTextureRect().origin;
                x = to.x;
                y = to.y;
            }
            break;
        }
        default:
            break;
    }
    if (m_bScale9Enabled)
    {
        setScale9Scale();
    }
    else
    {
        dynamic_cast<Sprite*>(m_pBarRenderer)->setTextureRect(Rect(x, y, m_barRendererTextureSize.width * res, m_barRendererTextureSize.height));
    }
}
Beispiel #9
0
void UILoadingBar::setPercent(int percent)
{
    if ( percent < 0 || percent > 100)
    {
        return;
    }
    if (_totalLength <= 0)
    {
        return;
    }
    _percent = percent;
    float res = _percent/100.0;
    
    int x = 0, y = 0;
    switch (_renderBarTexType)
    {
        case UI_TEX_TYPE_PLIST:
        {
            cocos2d::Sprite* barNode = DYNAMIC_CAST_CCSPRITE;
            if (barNode)
            {
                cocos2d::Point to = barNode->getTextureRect().origin;
                x = to.x;
                y = to.y;
            }
            break;
        }
        default:
            break;
    }
    if (_scale9Enabled)
    {
        setScale9Scale();
    }
    else
    {
        dynamic_cast<cocos2d::Sprite*>(_barRenderer)->setTextureRect(cocos2d::Rect(x, y, _barRendererTextureSize.width * res, _barRendererTextureSize.height));
    }
}