mirror of https://github.com/axmolengine/axmol.git
Merge pull request #8081 from andyque/addInterfaceToUI
add getTitleRenderer interface to UIButton
This commit is contained in:
commit
32ed437e6d
|
@ -690,6 +690,11 @@ void Button::setTitleFontName(const std::string& fontName)
|
||||||
}
|
}
|
||||||
_fontName = fontName;
|
_fontName = fontName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Label* Button::getTitleRenderer()const
|
||||||
|
{
|
||||||
|
return _titleRenderer;
|
||||||
|
}
|
||||||
|
|
||||||
const std::string& Button::getTitleFontName() const
|
const std::string& Button::getTitleFontName() const
|
||||||
{
|
{
|
||||||
|
|
|
@ -174,6 +174,12 @@ public:
|
||||||
|
|
||||||
//override "getVirtualRenderer" method of widget.
|
//override "getVirtualRenderer" method of widget.
|
||||||
virtual Node* getVirtualRenderer() override;
|
virtual Node* getVirtualRenderer() override;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the inner title renderer of Button
|
||||||
|
* @since v3.3
|
||||||
|
*/
|
||||||
|
Label* getTitleRenderer()const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the "class name" of widget.
|
* Returns the "class name" of widget.
|
||||||
|
@ -190,10 +196,12 @@ public:
|
||||||
const std::string& getTitleFontName() const;
|
const std::string& getTitleFontName() const;
|
||||||
/** When user pressed the button, the button will zoom to a scale.
|
/** When user pressed the button, the button will zoom to a scale.
|
||||||
* The final scale of the button equals (button original scale + _zoomScale)
|
* The final scale of the button equals (button original scale + _zoomScale)
|
||||||
|
* @since v3.3
|
||||||
*/
|
*/
|
||||||
void setZoomScale(float scale);
|
void setZoomScale(float scale);
|
||||||
/**
|
/**
|
||||||
* @brief Return a zoom scale
|
* @brief Return a zoom scale
|
||||||
|
* @since v3.3
|
||||||
*/
|
*/
|
||||||
float getZoomScale()const;
|
float getZoomScale()const;
|
||||||
|
|
||||||
|
|
|
@ -510,14 +510,28 @@ public:
|
||||||
int getActionTag()const;
|
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);
|
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);
|
void setSwallowTouches(bool swallow);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return whether the widget is swallowing touch or not
|
||||||
|
* @since v3.3
|
||||||
|
*/
|
||||||
bool isSwallowTouches()const;
|
bool isSwallowTouches()const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -89,7 +89,7 @@ g_guisTests[] =
|
||||||
UISceneManager* sceneManager = UISceneManager::sharedUISceneManager();
|
UISceneManager* sceneManager = UISceneManager::sharedUISceneManager();
|
||||||
sceneManager->setCurrentUISceneId(kUIButtonTest);
|
sceneManager->setCurrentUISceneId(kUIButtonTest);
|
||||||
sceneManager->setMinUISceneId(kUIButtonTest);
|
sceneManager->setMinUISceneId(kUIButtonTest);
|
||||||
sceneManager->setMaxUISceneId(kUIButtonIgnoreContentSizeTest);
|
sceneManager->setMaxUISceneId(kUIButtonTitleEffectTest);
|
||||||
Scene* scene = sceneManager->currentUIScene();
|
Scene* scene = sceneManager->currentUIScene();
|
||||||
Director::getInstance()->replaceScene(scene);
|
Director::getInstance()->replaceScene(scene);
|
||||||
}
|
}
|
||||||
|
|
|
@ -712,3 +712,67 @@ bool UIButtonIgnoreContentSizeTest::init()
|
||||||
return false;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -141,4 +141,16 @@ protected:
|
||||||
UI_SCENE_CREATE_FUNC(UIButtonIgnoreContentSizeTest)
|
UI_SCENE_CREATE_FUNC(UIButtonIgnoreContentSizeTest)
|
||||||
Text* _displayValueLabel;
|
Text* _displayValueLabel;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class UIButtonTitleEffectTest : public UIScene
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
UIButtonTitleEffectTest();
|
||||||
|
~UIButtonTitleEffectTest();
|
||||||
|
bool init();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
UI_SCENE_CREATE_FUNC(UIButtonTitleEffectTest)
|
||||||
|
Text* _displayValueLabel;
|
||||||
|
};
|
||||||
#endif /* defined(__TestCpp__UIButtonTest__) */
|
#endif /* defined(__TestCpp__UIButtonTest__) */
|
||||||
|
|
|
@ -41,6 +41,7 @@ static const char* s_testArray[] =
|
||||||
"UIButtonTestZoomScale",
|
"UIButtonTestZoomScale",
|
||||||
"UIButtonTextOnly",
|
"UIButtonTextOnly",
|
||||||
"UIButtonIgnoreContentSizeTest",
|
"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)
|
#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",
|
"UIEditBoxTest",
|
||||||
|
@ -202,7 +203,8 @@ Scene *UISceneManager::currentUIScene()
|
||||||
return UIButtonTextOnly::sceneWithTitle(s_testArray[_currentUISceneId]);
|
return UIButtonTextOnly::sceneWithTitle(s_testArray[_currentUISceneId]);
|
||||||
case kUIButtonIgnoreContentSizeTest:
|
case kUIButtonIgnoreContentSizeTest:
|
||||||
return UIButtonIgnoreContentSizeTest::sceneWithTitle(s_testArray[_currentUISceneId]);
|
return UIButtonIgnoreContentSizeTest::sceneWithTitle(s_testArray[_currentUISceneId]);
|
||||||
|
case kUIButtonTitleEffectTest:
|
||||||
|
return UIButtonTitleEffectTest::sceneWithTitle(s_testArray[_currentUISceneId]);
|
||||||
case kUICheckBoxTest:
|
case kUICheckBoxTest:
|
||||||
return UICheckBoxTest::sceneWithTitle(s_testArray[_currentUISceneId]);
|
return UICheckBoxTest::sceneWithTitle(s_testArray[_currentUISceneId]);
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,7 @@ enum
|
||||||
kUIButtonTestZoomScale,
|
kUIButtonTestZoomScale,
|
||||||
kUIButtonTextOnly,
|
kUIButtonTextOnly,
|
||||||
kUIButtonIgnoreContentSizeTest,
|
kUIButtonIgnoreContentSizeTest,
|
||||||
|
kUIButtonTitleEffectTest,
|
||||||
kUIEditBoxTest,
|
kUIEditBoxTest,
|
||||||
kUICheckBoxTest,
|
kUICheckBoxTest,
|
||||||
kUISliderTest,
|
kUISliderTest,
|
||||||
|
|
Loading…
Reference in New Issue