Merge pull request from andyque/addInterfaceToUI

add getTitleRenderer interface to UIButton
This commit is contained in:
minggo 2014-09-17 11:31:16 +08:00
commit 32ed437e6d
8 changed files with 111 additions and 5 deletions

View File

@ -690,6 +690,11 @@ void Button::setTitleFontName(const std::string& fontName)
}
_fontName = fontName;
}
Label* Button::getTitleRenderer()const
{
return _titleRenderer;
}
const std::string& Button::getTitleFontName() const
{

View File

@ -174,6 +174,12 @@ public:
//override "getVirtualRenderer" method of widget.
virtual Node* getVirtualRenderer() override;
/**
* Return the inner title renderer of Button
* @since v3.3
*/
Label* getTitleRenderer()const;
/**
* Returns the "class name" of widget.
@ -190,10 +196,12 @@ public:
const std::string& getTitleFontName() const;
/** When user pressed the button, the button will zoom to a scale.
* The final scale of the button equals (button original scale + _zoomScale)
* @since v3.3
*/
void setZoomScale(float scale);
/**
* @brief Return a zoom scale
* @since v3.3
*/
float getZoomScale()const;

View File

@ -510,14 +510,28 @@ public:
int getActionTag()const;
/**
*@brief Allow widget touch events to propagate to its parents. Set false will disable propagation
* @brief Allow widget touch events to propagate to its parents. Set false will disable propagation
* @since v3.3
*/
void setPropagateTouchEvents(bool isPropagate);
bool isPropagateTouchEvents()const;
/**
*@brief Specify widget to swallow touches or not
* Return whether the widget is propagate touch events to its parents or not
* @since v3.3
*/
bool isPropagateTouchEvents()const;
/**
* @brief Specify widget to swallow touches or not
* @since v3.3
*/
void setSwallowTouches(bool swallow);
/**
* Return whether the widget is swallowing touch or not
* @since v3.3
*/
bool isSwallowTouches()const;
/**

View File

@ -89,7 +89,7 @@ g_guisTests[] =
UISceneManager* sceneManager = UISceneManager::sharedUISceneManager();
sceneManager->setCurrentUISceneId(kUIButtonTest);
sceneManager->setMinUISceneId(kUIButtonTest);
sceneManager->setMaxUISceneId(kUIButtonIgnoreContentSizeTest);
sceneManager->setMaxUISceneId(kUIButtonTitleEffectTest);
Scene* scene = sceneManager->currentUIScene();
Director::getInstance()->replaceScene(scene);
}

View File

@ -712,3 +712,67 @@ bool UIButtonIgnoreContentSizeTest::init()
return false;
}
// UIButtonTitleEffectTest
UIButtonTitleEffectTest::UIButtonTitleEffectTest()
: _displayValueLabel(nullptr)
{
}
UIButtonTitleEffectTest::~UIButtonTitleEffectTest()
{
}
bool UIButtonTitleEffectTest::init()
{
if (UIScene::init())
{
Size widgetSize = _widget->getContentSize();
// Add a label in which the button events will be displayed
_displayValueLabel = Text::create("Button Title Effect", "fonts/Marker Felt.ttf",32);
_displayValueLabel->setAnchorPoint(Vec2(0.5f, -1.0f));
_displayValueLabel->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f + 20));
_uiLayer->addChild(_displayValueLabel);
// Add the alert
Text* alert = Text::create("Button","fonts/Marker Felt.ttf",30);
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
auto button = Button::create("cocosui/animationbuttonnormal.png",
"cocosui/animationbuttonpressed.png");
button->setNormalizedPosition(Vec2(0.3, 0.5));
button->setTitleText("PLAY GAME");
button->setTitleFontName("fonts/Marker Felt.ttf");
button->setZoomScale(0.3);
button->setScale(2.0);
button->setPressedActionEnabled(true);
Label *title = button->getTitleRenderer();
button->setTitleColor(Color3B::RED);
title->enableShadow(Color4B::BLACK,Size(2,-2));
_uiLayer->addChild(button);
// Create the button
auto button2 = Button::create("cocosui/animationbuttonnormal.png",
"cocosui/animationbuttonpressed.png");
button2->setNormalizedPosition(Vec2(0.8, 0.5));
button2->setTitleText("PLAY GAME");
auto title2 = button2->getTitleRenderer();
title2->enableOutline(Color4B::GREEN, 3);
_uiLayer->addChild(button2);
return true;
}
return false;
}

View File

@ -141,4 +141,16 @@ protected:
UI_SCENE_CREATE_FUNC(UIButtonIgnoreContentSizeTest)
Text* _displayValueLabel;
};
class UIButtonTitleEffectTest : public UIScene
{
public:
UIButtonTitleEffectTest();
~UIButtonTitleEffectTest();
bool init();
protected:
UI_SCENE_CREATE_FUNC(UIButtonTitleEffectTest)
Text* _displayValueLabel;
};
#endif /* defined(__TestCpp__UIButtonTest__) */

View File

@ -41,6 +41,7 @@ static const char* s_testArray[] =
"UIButtonTestZoomScale",
"UIButtonTextOnly",
"UIButtonIgnoreContentSizeTest",
"UIButtonTitleEffectTest",
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) || (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) || (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_TIZEN) || (CC_TARGET_PLATFORM == CC_PLATFORM_WP8)
"UIEditBoxTest",
@ -202,7 +203,8 @@ Scene *UISceneManager::currentUIScene()
return UIButtonTextOnly::sceneWithTitle(s_testArray[_currentUISceneId]);
case kUIButtonIgnoreContentSizeTest:
return UIButtonIgnoreContentSizeTest::sceneWithTitle(s_testArray[_currentUISceneId]);
case kUIButtonTitleEffectTest:
return UIButtonTitleEffectTest::sceneWithTitle(s_testArray[_currentUISceneId]);
case kUICheckBoxTest:
return UICheckBoxTest::sceneWithTitle(s_testArray[_currentUISceneId]);

View File

@ -40,6 +40,7 @@ enum
kUIButtonTestZoomScale,
kUIButtonTextOnly,
kUIButtonIgnoreContentSizeTest,
kUIButtonTitleEffectTest,
kUIEditBoxTest,
kUICheckBoxTest,
kUISliderTest,