fix side effect of ui::button clone

This commit is contained in:
andyque 2015-04-16 14:38:00 +08:00
parent 29de9d397f
commit 8a9f420735
3 changed files with 232 additions and 153 deletions

View File

@ -899,10 +899,13 @@ void Button::copySpecialProperties(Widget *widget)
setCapInsetsNormalRenderer(button->_capInsetsNormal);
setCapInsetsPressedRenderer(button->_capInsetsPressed);
setCapInsetsDisabledRenderer(button->_capInsetsDisabled);
setTitleText(button->getTitleText());
setTitleFontName(button->getTitleFontName());
setTitleFontSize(button->getTitleFontSize());
setTitleColor(button->getTitleColor());
if(nullptr != button->getTitleRenderer())
{
setTitleText(button->getTitleText());
setTitleFontName(button->getTitleFontName());
setTitleFontSize(button->getTitleFontSize());
setTitleColor(button->getTitleColor());
}
setPressedActionEnabled(button->_pressedActionEnabled);
setZoomScale(button->_zoomScale);
}

View File

@ -19,6 +19,7 @@ UIButtonTests::UIButtonTests()
ADD_TEST_CASE(UIButtonFlipTest);
ADD_TEST_CASE(UIButtonNormalDefaultTest);
ADD_TEST_CASE(UIButtonDisableDefaultTest);
ADD_TEST_CASE(UIButtonCloneTest);
}
// UIButtonTest
@ -1020,6 +1021,67 @@ bool UIButtonDisableDefaultTest::init()
return true;
}
return false;
}
// UIButtonCloneTest
UIButtonCloneTest::UIButtonCloneTest()
: _displayValueLabel(nullptr)
{
}
UIButtonCloneTest::~UIButtonCloneTest()
{
}
bool UIButtonCloneTest::init()
{
if (UIScene::init())
{
Size widgetSize = _widget->getContentSize();
// Add a label in which the button events will be displayed
_displayValueLabel = Text::create("", "fonts/Marker Felt.ttf",32);
_displayValueLabel->setAnchorPoint(Vec2(0.5f, -1.0f));
_displayValueLabel->setPosition(Vec2(widgetSize.width / 2.0f,
widgetSize.height / 2.0f));
_uiLayer->addChild(_displayValueLabel);
// Add the alert
Text* alert = Text::create("This test case shouldn't trigger the Assertion!",
"fonts/Marker Felt.ttf",20);
alert->setColor(Color3B(159, 168, 176));
alert->setPosition(Vec2(widgetSize.width / 2.0f,
widgetSize.height / 2.0f
- alert->getContentSize().height * 1.75f));
_uiLayer->addChild(alert);
// Create the button
Button* button = Button::create("cocosui/animationbuttonnormal.png");
button->setPosition(Vec2(widgetSize.width / 2.0f - 80,
widgetSize.height / 2.0f + 40));
_uiLayer->addChild(button);
CCASSERT(button->getTitleRenderer() == nullptr,
"Button title render must be nullptr ");
auto buttonCopy = (Button*)button->clone();
buttonCopy->setPosition(Vec2(widgetSize.width / 2.0f + 80,
widgetSize.height / 2.0f + 40));
this->addChild(buttonCopy);
CCASSERT(button->getTitleRenderer() == nullptr,
"Original Button title render must be nullptr ");
CCASSERT(buttonCopy->getTitleRenderer() == nullptr,
"Copied Button title render must be nullptr ");
return true;
}
return false;

View File

@ -229,6 +229,20 @@ public:
virtual bool init() override;
protected:
cocos2d::ui::Text* _displayValueLabel;
};
class UIButtonCloneTest : public UIScene
{
public:
CREATE_FUNC(UIButtonCloneTest);
UIButtonCloneTest();
~UIButtonCloneTest();
virtual bool init() override;
protected:
cocos2d::ui::Text* _displayValueLabel;
};