Exemplo n.º 1
0
void Button::setScale9Enabled(bool able)
{
    if (_scale9Enabled == able)
    {
        return;
    }

    _scale9Enabled = able;

    _buttonNormalRenderer->setScale9Enabled(_scale9Enabled);
    _buttonClickedRenderer->setScale9Enabled(_scale9Enabled);
    _buttonDisableRenderer->setScale9Enabled(_scale9Enabled);

    if (_scale9Enabled)
    {
        bool ignoreBefore = _ignoreSize;
        ignoreContentAdaptWithSize(false);
        _prevIgnoreSize = ignoreBefore;
    }
    else
    {
        ignoreContentAdaptWithSize(_prevIgnoreSize);
    }

    setCapInsetsNormalRenderer(_capInsetsNormal);
    setCapInsetsPressedRenderer(_capInsetsPressed);
    setCapInsetsDisabledRenderer(_capInsetsDisabled);

    _brightStyle = BrightStyle::NONE;
    setBright(_bright);

    _normalTextureAdaptDirty = true;
    _pressedTextureAdaptDirty = true;
    _disabledTextureAdaptDirty = true;
}
Exemplo n.º 2
0
void UIButton::setScale9Enabled(bool able)
{
    if (_scale9Enabled == able)
    {
        return;
    }
    _brightStyle = BRIGHT_NONE;
    _scale9Enabled = able;

    
    _renderer->removeChild(_buttonNormalRenderer, true);
    _renderer->removeChild(_buttonClickedRenderer, true);
    _renderer->removeChild(_buttonDisableRenderer, true);
    
    _buttonNormalRenderer = NULL;
    _buttonClickedRenderer = NULL;
    _buttonDisableRenderer = NULL;
    if (_scale9Enabled)
    {
        _buttonNormalRenderer = Scale9Sprite::create();
        _buttonClickedRenderer = Scale9Sprite::create();
        _buttonDisableRenderer = Scale9Sprite::create();
    }
    else
    {
        _buttonNormalRenderer = CCSprite::create();
        _buttonClickedRenderer = CCSprite::create();
        _buttonDisableRenderer = CCSprite::create();
    }

    loadTextureNormal(_normalFileName.c_str(), _normalTexType);
    loadTexturePressed(_clickedFileName.c_str(), _pressedTexType);
    loadTextureDisabled(_disabledFileName.c_str(), _disabledTexType);
    _renderer->addChild(_buttonNormalRenderer,NORMALRENDERERZ);
    _renderer->addChild(_buttonClickedRenderer,PRESSEDRENDERERZ);
    _renderer->addChild(_buttonDisableRenderer,DISABLEDRENDERERZ);
    if (_scale9Enabled)
    {
        bool ignoreBefore = _ignoreSize;
        ignoreContentAdaptWithSize(false);
        _prevIgnoreSize = ignoreBefore;
    }
    else
    {
        ignoreContentAdaptWithSize(_prevIgnoreSize);
    }
    setCapInsetsNormalRenderer(_capInsetsNormal);
    setCapInsetsPressedRenderer(_capInsetsPressed);
    setCapInsetsDisabledRenderer(_capInsetsDisabled);
    setBright(_bright);
}
Exemplo n.º 3
0
void UIButton::setScale9Enabled(bool able)
{
    if (m_bScale9Enabled == able)
    {
        return;
    }
    m_eBrightStyle = BRIGHT_NONE;
    m_bScale9Enabled = able;

    
    m_pRenderer->removeChild(m_pButtonNormalRenderer, true);
    m_pRenderer->removeChild(m_pButtonClickedRenderer, true);
    m_pRenderer->removeChild(m_pButtonDisableRenderer, true);
    
    m_pButtonNormalRenderer = NULL;
    m_pButtonClickedRenderer = NULL;
    m_pButtonDisableRenderer = NULL;
    if (m_bScale9Enabled)
    {
        m_pButtonNormalRenderer = CCScale9Sprite::create();
        m_pButtonClickedRenderer = CCScale9Sprite::create();
        m_pButtonDisableRenderer = CCScale9Sprite::create();
    }
    else
    {
        m_pButtonNormalRenderer = CCSprite::create();
        m_pButtonClickedRenderer = CCSprite::create();
        m_pButtonDisableRenderer = CCSprite::create();
    }

    loadTextureNormal(m_strNormalFileName.c_str(), m_eNormalTexType);
    loadTexturePressed(m_strClickedFileName.c_str(), m_ePressedTexType);
    loadTextureDisabled(m_strDisabledFileName.c_str(), m_eDisabledTexType);
    m_pRenderer->addChild(m_pButtonNormalRenderer,NORMALRENDERERZ);
    m_pRenderer->addChild(m_pButtonClickedRenderer,PRESSEDRENDERERZ);
    m_pRenderer->addChild(m_pButtonDisableRenderer,DISABLEDRENDERERZ);
    if (m_bScale9Enabled)
    {
        bool ignoreBefore = m_bIgnoreSize;
        ignoreContentAdaptWithSize(false);
        m_bPrevIgnoreSize = ignoreBefore;
    }
    else
    {
        ignoreContentAdaptWithSize(m_bPrevIgnoreSize);
    }
    setCapInsetsNormalRenderer(m_capInsetsNormal);
    setCapInsetsPressedRenderer(m_capInsetsPressed);
    setCapInsetsDisabledRenderer(m_capInsetsDisabled);
    setBright(m_bBright);
}
Exemplo n.º 4
0
void Button::setScale9Enabled(bool able)
{
    if (_scale9Enabled == able)
    {
        return;
    }
    _brightStyle = BrightStyle::NONE;
    _scale9Enabled = able;
    removeProtectedChild(_buttonNormalRenderer);
    removeProtectedChild(_buttonClickedRenderer);
    removeProtectedChild(_buttonDisableRenderer);
    _buttonNormalRenderer = nullptr;
    _buttonClickedRenderer = nullptr;
    _buttonDisableRenderer = nullptr;
    if (_scale9Enabled)
    {
        _buttonNormalRenderer = extension::Scale9Sprite::create();
        _buttonClickedRenderer = extension::Scale9Sprite::create();
        _buttonDisableRenderer = extension::Scale9Sprite::create();
    }
    else
    {
        _buttonNormalRenderer = Sprite::create();
        _buttonClickedRenderer = Sprite::create();
        _buttonDisableRenderer = Sprite::create();
    }

    loadTextureNormal(_normalFileName, _normalTexType);
    loadTexturePressed(_clickedFileName, _pressedTexType);
    loadTextureDisabled(_disabledFileName, _disabledTexType);
    addProtectedChild(_buttonNormalRenderer, NORMAL_RENDERER_Z, -1);
    addProtectedChild(_buttonClickedRenderer, PRESSED_RENDERER_Z, -1);
    addProtectedChild(_buttonDisableRenderer, DISABLED_RENDERER_Z, -1);
    if (_scale9Enabled)
    {
        bool ignoreBefore = _ignoreSize;
        ignoreContentAdaptWithSize(false);
        _prevIgnoreSize = ignoreBefore;
    }
    else
    {
        ignoreContentAdaptWithSize(_prevIgnoreSize);
    }
    setCapInsetsNormalRenderer(_capInsetsNormal);
    setCapInsetsPressedRenderer(_capInsetsPressed);
    setCapInsetsDisabledRenderer(_capInsetsDisabled);
    setBright(_bright);
}
Exemplo n.º 5
0
void Button::copySpecialProperties(Widget *widget)
{
    Button* button = dynamic_cast<Button*>(widget);
    if (button)
    {
        _prevIgnoreSize = button->_prevIgnoreSize;
        setScale9Enabled(button->_scale9Enabled);

        // clone the inner sprite: https://github.com/cocos2d/cocos2d-x/issues/16924
        button->_buttonNormalRenderer->copyTo(_buttonNormalRenderer);
        _normalFileName = button->_normalFileName;
        _normalTextureSize = button->_normalTextureSize;
        _normalTexType = button->_normalTexType;
        _normalTextureLoaded = button->_normalTextureLoaded;
        setupNormalTexture(!_normalFileName.empty());

        button->_buttonClickedRenderer->copyTo(_buttonClickedRenderer);
        _clickedFileName = button->_clickedFileName;
        _pressedTextureSize = button->_pressedTextureSize;
        _pressedTexType = button->_pressedTexType;
        _pressedTextureLoaded = button->_pressedTextureLoaded;
        setupPressedTexture(!_clickedFileName.empty());

        button->_buttonDisabledRenderer->copyTo(_buttonDisabledRenderer);
        _disabledFileName = button->_disabledFileName;
        _disabledTextureSize = button->_disabledTextureSize;
        _disabledTexType = button->_disabledTexType;
        _disabledTextureLoaded = button->_disabledTextureLoaded;
        setupDisabledTexture(!_disabledFileName.empty());

        setCapInsetsNormalRenderer(button->_capInsetsNormal);
        setCapInsetsPressedRenderer(button->_capInsetsPressed);
        setCapInsetsDisabledRenderer(button->_capInsetsDisabled);
        if(nullptr != button->getTitleRenderer())
        {
            setTitleText(button->getTitleText());
            setTitleFontName(button->getTitleFontName());
            setTitleFontSize(button->getTitleFontSize());
            setTitleColor(button->getTitleColor());
        }
        setPressedActionEnabled(button->_pressedActionEnabled);
        setZoomScale(button->_zoomScale);
    }

}
Exemplo n.º 6
0
void Button::copySpecialProperties(Widget *widget)
{
    Button* button = dynamic_cast<Button*>(widget);
    if (button)
    {   
        _prevIgnoreSize = button->_prevIgnoreSize;
        setScale9Enabled(button->_scale9Enabled);
        loadTextureNormal(button->_normalFileName.c_str(), button->_normalTexType);
        loadTexturePressed(button->_clickedFileName.c_str(), button->_pressedTexType);
        loadTextureDisabled(button->_disabledFileName.c_str(), button->_disabledTexType);
        setCapInsetsNormalRenderer(button->_capInsetsNormal);
        setCapInsetsPressedRenderer(button->_capInsetsPressed);
        setCapInsetsDisabledRenderer(button->_capInsetsDisabled);
        setTitleText(button->getTitleText());
        setTitleFontName(button->getTitleFontName());
        setTitleFontSize(button->getTitleFontSize());
        setTitleColor(button->getTitleColor());
        setPressedActionEnabled(button->_pressedActionEnabled);
    }
}
Exemplo n.º 7
0
void Button::copySpecialProperties(Widget *widget)
{
    Button* button = dynamic_cast<Button*>(widget);
    if (button)
    {
        _prevIgnoreSize = button->_prevIgnoreSize;
        setScale9Enabled(button->_scale9Enabled);
        auto normalSprite = button->_buttonNormalRenderer->getSprite();
        if (nullptr != normalSprite)
        {
            loadTextureNormal(normalSprite->getSpriteFrame());
        }
        auto clickedSprite = button->_buttonClickedRenderer->getSprite();
        if (nullptr != clickedSprite)
        {
            loadTexturePressed(clickedSprite->getSpriteFrame());
        }
        auto disabledSprite = button->_buttonDisableRenderer->getSprite();
        if (nullptr != disabledSprite)
        {
            loadTextureDisabled(disabledSprite->getSpriteFrame());
        }
        setCapInsetsNormalRenderer(button->_capInsetsNormal);
        setCapInsetsPressedRenderer(button->_capInsetsPressed);
        setCapInsetsDisabledRenderer(button->_capInsetsDisabled);
        if(nullptr != button->getTitleRenderer())
        {
            setTitleText(button->getTitleText());
            setTitleFontName(button->getTitleFontName());
            setTitleFontSize(button->getTitleFontSize());
            setTitleColor(button->getTitleColor());
        }
        setPressedActionEnabled(button->_pressedActionEnabled);
        setZoomScale(button->_zoomScale);
    }

}
Exemplo n.º 8
0
void Button::setCapInsets(const Rect &capInsets)
{
    setCapInsetsNormalRenderer(capInsets);
    setCapInsetsPressedRenderer(capInsets);
    setCapInsetsDisabledRenderer(capInsets);
}
Exemplo n.º 9
0
void UIButton::setCapInsets(const cocos2d::Rect &capInsets)
{
    setCapInsetsNormalRenderer(capInsets);
    setCapInsetsPressedRenderer(capInsets);
    setCapInsetsDisabledRenderer(capInsets);
}