void LoadingBar::setupTexture()
{
    _barRendererTextureSize = _barRenderer->getContentSize();

    switch (_direction)
    {
        case Direction::LEFT:
            _barRenderer->setAnchorPoint(Vec2::ANCHOR_MIDDLE_LEFT);
            break;
        case Direction::RIGHT:
            _barRenderer->setAnchorPoint(Vec2::ANCHOR_MIDDLE_RIGHT);
            break;
    }
    handleSpriteFlipX();

    _barRenderer->setCapInsets(_capInsets);
    this->updateChildrenDisplayedRGBA();

    barRendererScaleChangedWithSize();

    updateContentSizeWithTextureSize(_barRendererTextureSize);

    this->updateProgressBar();
    _barRendererAdaptDirty = true;
}
void LoadingBar::loadTexture(const char* texture,TextureResType texType)
{
    if (!texture || strcmp(texture, "") == 0)
    {
        return;
    }
    _renderBarTexType = texType;
    _textureFile = texture;
    switch (_renderBarTexType)
    {
        case UI_TEX_TYPE_LOCAL:
            if (_scale9Enabled)
            {
                extension::Scale9Sprite* barRendererScale9 = static_cast<extension::Scale9Sprite*>(_barRenderer);
                barRendererScale9->initWithFile(texture);
                barRendererScale9->setCapInsets(_capInsets);
            }
            else
            {
                static_cast<Sprite*>(_barRenderer)->setTexture(texture);
            }
            break;
        case UI_TEX_TYPE_PLIST:
            if (_scale9Enabled)
            {
                extension::Scale9Sprite* barRendererScale9 = static_cast<extension::Scale9Sprite*>(_barRenderer);
                barRendererScale9->initWithSpriteFrameName(texture);
                barRendererScale9->setCapInsets(_capInsets);
            }
            else
            {
                static_cast<Sprite*>(_barRenderer)->setSpriteFrame(texture);
            }
            break;
        default:
            break;
    }
    updateDisplayedColor(getColor());
    updateDisplayedOpacity(getOpacity());
    _barRendererTextureSize = _barRenderer->getContentSize();
    
    switch (_barType)
    {
    case LoadingBarTypeLeft:
        _barRenderer->setAnchorPoint(Point(0.0f,0.5f));
        if (!_scale9Enabled)
        {
            static_cast<Sprite*>(_barRenderer)->setFlippedX(false);
        }
        break;
    case LoadingBarTypeRight:
        _barRenderer->setAnchorPoint(Point(1.0f,0.5f));
        if (!_scale9Enabled)
        {
            static_cast<Sprite*>(_barRenderer)->setFlippedX(true);
        }
        break;
    }
    barRendererScaleChangedWithSize();
}
Exemple #3
0
void LoadingBar::adaptRenderers()
{
    if (_barRendererAdaptDirty)
    {
        barRendererScaleChangedWithSize();
        _barRendererAdaptDirty = false;
    }
}
void LoadingBar::loadTexture(const std::string& texture,TextureResType texType)
{
    if (texture.empty())
    {
        return;
    }
    _renderBarTexType = texType;
    _textureFile = texture;
    switch (_renderBarTexType)
    {
        case TextureResType::LOCAL:
            _barRenderer->initWithFile(texture);
            break;
        case TextureResType::PLIST:
            _barRenderer->initWithSpriteFrameName(texture);
            break;
        default:
            break;
    }
    
    _barRendererTextureSize = _barRenderer->getContentSize();
    
    switch (_direction)
    {
        case Direction::LEFT:
            _barRenderer->setAnchorPoint(Vec2(0.0f,0.5f));
            if (!_scale9Enabled)
            {
                auto innerSprite = _barRenderer->getSprite();
                if (nullptr != innerSprite)
                {
                    innerSprite->setFlippedX(false);
                }
            }
            break;
        case Direction::RIGHT:
            _barRenderer->setAnchorPoint(Vec2(1.0f,0.5f));
            if (!_scale9Enabled)
            {
                auto innerSprite = _barRenderer->getSprite();
                if (nullptr != innerSprite)
                {
                    innerSprite->setFlippedX(true);
                }
            }
            break;
    }
    _barRenderer->setCapInsets(_capInsets);
    this->updateChildrenDisplayedRGBA();

    barRendererScaleChangedWithSize();
    updateContentSizeWithTextureSize(_barRendererTextureSize);
    
    this->updateProgressBar();
    _barRendererAdaptDirty = true;
}
Exemple #5
0
void Slider::adaptRenderers()
{
    if (_barRendererAdaptDirty)
    {
        barRendererScaleChangedWithSize();
        _barRendererAdaptDirty = false;
    }
    if (_progressBarRendererDirty)
    {
        progressBarRendererScaleChangedWithSize();
        _progressBarRendererDirty = false;
    }
}
Exemple #6
0
void UISlider::loadBarTexture(const char* fileName, TextureResType texType)
{
    if (!fileName || strcmp(fileName, "") == 0)
    {
        return;
    }
    m_strTextureFile = fileName;
    m_eBarTexType = texType;
    switch (m_eBarTexType)
    {
        case UI_TEX_TYPE_LOCAL:
            if (m_bScale9Enabled)
            {
                dynamic_cast<CCScale9Sprite*>(m_pBarRenderer)->initWithFile(fileName);
            }
            else
            {
                dynamic_cast<CCSprite*>(m_pBarRenderer)->initWithFile(fileName);
            }
            break;
        case UI_TEX_TYPE_PLIST:
            if (m_bScale9Enabled)
            {
                dynamic_cast<CCScale9Sprite*>(m_pBarRenderer)->initWithSpriteFrameName(fileName);
            }
            else
            {
                dynamic_cast<CCSprite*>(m_pBarRenderer)->initWithSpriteFrameName(fileName);
            }
            break;
        default:
            break;
    }
    if (m_bScale9Enabled)
    {
        dynamic_cast<CCScale9Sprite*>(m_pBarRenderer)->setColor(getColor());
        dynamic_cast<CCScale9Sprite*>(m_pBarRenderer)->setOpacity(getOpacity());
    }
    else
    {
        dynamic_cast<CCSprite*>(m_pBarRenderer)->setColor(getColor());
        dynamic_cast<CCSprite*>(m_pBarRenderer)->setOpacity(getOpacity());
    }
    barRendererScaleChangedWithSize();
}
Exemple #7
0
void LoadingBar::setupTexture()
{
    _barRendererTextureSize = _barRenderer->getContentSize();

    switch (_direction)
    {
        case Direction::LEFT:
            _barRenderer->setAnchorPoint(Vec2(0.0f,0.5f));
            if (!_scale9Enabled)
            {
                auto innerSprite = _barRenderer->getSprite();
                if (nullptr != innerSprite)
                {
                    innerSprite->setFlippedX(false);
                }
            }
            break;
        case Direction::RIGHT:
            _barRenderer->setAnchorPoint(Vec2(1.0f,0.5f));
            if (!_scale9Enabled)
            {
                auto innerSprite = _barRenderer->getSprite();
                if (nullptr != innerSprite)
                {
                    innerSprite->setFlippedX(true);
                }
            }
            break;
    }
    _barRenderer->setCapInsets(_capInsets);
    this->updateChildrenDisplayedRGBA();

    barRendererScaleChangedWithSize();
    updateContentSizeWithTextureSize(_barRendererTextureSize);

    this->updateProgressBar();
    _barRendererAdaptDirty = true;
}
Exemple #8
0
void Slider::loadBarTexture(const char* fileName, TextureResType texType)
{
    if (!fileName || strcmp(fileName, "") == 0)
    {
        return;
    }
    _textureFile = fileName;
    _barTexType = texType;
    switch (_barTexType)
    {
        case UI_TEX_TYPE_LOCAL:
            if (_scale9Enabled)
            {
                static_cast<extension::CCScale9Sprite*>(_barRenderer)->initWithFile(fileName);
            }
            else
            {
                static_cast<CCSprite*>(_barRenderer)->initWithFile(fileName);
            }
            break;
        case UI_TEX_TYPE_PLIST:
            if (_scale9Enabled)
            {
                static_cast<extension::CCScale9Sprite*>(_barRenderer)->initWithSpriteFrameName(fileName);
            }
            else
            {
                static_cast<CCSprite*>(_barRenderer)->initWithSpriteFrameName(fileName);
            }
            break;
        default:
            break;
    }
    updateRGBAToRenderer(_barRenderer);
    barRendererScaleChangedWithSize();
    progressBarRendererScaleChangedWithSize();
}
Exemple #9
0
void UISlider::onSizeChanged()
{
    barRendererScaleChangedWithSize();
    progressBarRendererScaleChangedWithSize();
}
Exemple #10
0
void Slider::onSizeChanged()
{
    Widget::onSizeChanged();
    barRendererScaleChangedWithSize();
    progressBarRendererScaleChangedWithSize();
}
Exemple #11
0
void UILoadingBar::onSizeChanged()
{
    barRendererScaleChangedWithSize();
}
Exemple #12
0
void UILoadingBar::loadTexture(const char* texture,TextureResType texType)
{
    if (!texture || strcmp(texture, "") == 0)
    {
        return;
    }
    m_eRenderBarTexType = texType;
    m_strTextureFile = texture;
    switch (m_eRenderBarTexType)
    {
        case UI_TEX_TYPE_LOCAL:
            if (m_bScale9Enabled)
            {
                dynamic_cast<Scale9Sprite*>(m_pBarRenderer)->initWithFile(texture);
            }
            else
            {
                dynamic_cast<Sprite*>(m_pBarRenderer)->initWithFile(texture);
            }
            break;
        case UI_TEX_TYPE_PLIST:
            if (m_bScale9Enabled)
            {
                dynamic_cast<Scale9Sprite*>(m_pBarRenderer)->initWithSpriteFrameName(texture);
            }
            else
            {
                dynamic_cast<Sprite*>(m_pBarRenderer)->initWithSpriteFrameName(texture);
            }
            break;
        default:
            break;
    }
    if (m_bScale9Enabled)
    {
        dynamic_cast<Scale9Sprite*>(m_pBarRenderer)->setColor(getColor());
        dynamic_cast<Scale9Sprite*>(m_pBarRenderer)->setOpacity(getOpacity());
    }
    else
    {
        dynamic_cast<Sprite*>(m_pBarRenderer)->setColor(getColor());
        dynamic_cast<Sprite*>(m_pBarRenderer)->setOpacity(getOpacity());
    }
    m_barRendererTextureSize.width = m_pBarRenderer->getContentSize().width;
    m_barRendererTextureSize.height = m_pBarRenderer->getContentSize().height;
    
    switch (m_nBarType)
    {
    case LoadingBarTypeLeft:
        m_pBarRenderer->setAnchorPoint(Point(0.0f,0.5f));
        if (!m_bScale9Enabled)
        {
            dynamic_cast<Sprite*>(m_pBarRenderer)->setFlipX(false);
        }
        break;
    case LoadingBarTypeRight:
        m_pBarRenderer->setAnchorPoint(Point(1.0f,0.5f));
        if (!m_bScale9Enabled)
        {
            dynamic_cast<Sprite*>(m_pBarRenderer)->setFlipX(true);
        }
        break;
    }
    barRendererScaleChangedWithSize();
}
void LoadingBar::onSizeChanged()
{
    Widget::onSizeChanged();
    barRendererScaleChangedWithSize();
}