2013-09-16 20:54:13 +08:00
|
|
|
|
|
|
|
|
2014-03-04 16:51:35 +08:00
|
|
|
#include "UITextTest.h"
|
2013-09-16 20:54:13 +08:00
|
|
|
|
|
|
|
|
2014-03-04 16:51:35 +08:00
|
|
|
// UITextTest
|
2013-09-16 20:54:13 +08:00
|
|
|
|
2014-03-04 16:51:35 +08:00
|
|
|
bool UITextTest::init()
|
2013-09-16 20:54:13 +08:00
|
|
|
{
|
|
|
|
if (UIScene::init())
|
|
|
|
{
|
2014-06-20 11:18:53 +08:00
|
|
|
Size widgetSize = _widget->getContentSize();
|
2013-09-16 20:54:13 +08:00
|
|
|
|
2014-04-02 17:40:09 +08:00
|
|
|
Text* alert = Text::create("Text","fonts/Marker Felt.ttf", 30);
|
2013-09-16 20:54:13 +08:00
|
|
|
alert->setColor(Color3B(159, 168, 176));
|
2014-06-20 11:18:53 +08:00
|
|
|
alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 1.75f));
|
2013-12-23 15:35:35 +08:00
|
|
|
_uiLayer->addChild(alert);
|
2013-09-16 20:54:13 +08:00
|
|
|
|
2014-03-04 16:51:35 +08:00
|
|
|
// Create the text
|
2014-04-02 17:40:09 +08:00
|
|
|
Text* text = Text::create("Text", "AmericanTypewriter", 30);
|
2014-06-20 11:18:53 +08:00
|
|
|
text->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f + text->getContentSize().height / 4.0f));
|
2014-03-04 16:51:35 +08:00
|
|
|
_uiLayer->addChild(text);
|
2013-09-16 20:54:13 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2013-12-23 15:35:35 +08:00
|
|
|
}
|
|
|
|
|
2014-03-04 16:51:35 +08:00
|
|
|
// UITextTest_LineWrap
|
2013-12-23 15:35:35 +08:00
|
|
|
|
2014-03-04 16:51:35 +08:00
|
|
|
bool UITextTest_LineWrap::init()
|
2013-12-23 15:35:35 +08:00
|
|
|
{
|
|
|
|
if (UIScene::init())
|
|
|
|
{
|
2014-06-20 11:18:53 +08:00
|
|
|
Size widgetSize = _widget->getContentSize();
|
2013-12-23 15:35:35 +08:00
|
|
|
|
2014-04-03 15:56:45 +08:00
|
|
|
Text* alert = Text::create("Text line wrap","fonts/Marker Felt.ttf",30);
|
2013-12-23 15:35:35 +08:00
|
|
|
alert->setColor(Color3B(159, 168, 176));
|
2014-06-20 11:18:53 +08:00
|
|
|
alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 1.75f));
|
2013-12-23 15:35:35 +08:00
|
|
|
_uiLayer->addChild(alert);
|
|
|
|
|
|
|
|
// Create the line wrap
|
2014-07-15 11:46:53 +08:00
|
|
|
Text* text = Text::create("TextArea Widget can line wrap","AmericanTypewriter",32);
|
2014-03-28 18:54:06 +08:00
|
|
|
text->ignoreContentAdaptWithSize(false);
|
2014-06-20 14:03:33 +08:00
|
|
|
text->setContentSize(Size(280, 150));
|
2014-03-04 16:51:35 +08:00
|
|
|
text->setTextHorizontalAlignment(TextHAlignment::CENTER);
|
2014-07-15 11:46:53 +08:00
|
|
|
text->setTouchScaleChangeEnabled(true);
|
|
|
|
text->setTouchEnabled(true);
|
|
|
|
text->addTouchEventListener([=](Ref* sender, Widget::TouchEventType type)
|
|
|
|
{
|
|
|
|
if (type == Widget::TouchEventType::ENDED)
|
|
|
|
{
|
|
|
|
if ((int)text->getContentSize().width == 280)
|
|
|
|
{
|
|
|
|
text->setContentSize(Size(380,100));
|
|
|
|
}else
|
|
|
|
{
|
|
|
|
text->setContentSize(Size(280, 150));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2014-06-20 11:18:53 +08:00
|
|
|
text->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - text->getContentSize().height / 8.0f));
|
2014-03-04 16:51:35 +08:00
|
|
|
_uiLayer->addChild(text);
|
2013-12-23 15:35:35 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// UILabelTest_Effect
|
|
|
|
|
2014-06-09 14:34:46 +08:00
|
|
|
|
2013-12-23 15:35:35 +08:00
|
|
|
bool UILabelTest_Effect::init()
|
|
|
|
{
|
|
|
|
if (UIScene::init())
|
|
|
|
{
|
2014-06-20 11:18:53 +08:00
|
|
|
Size widgetSize = _widget->getContentSize();
|
2013-12-23 15:35:35 +08:00
|
|
|
|
2014-03-04 16:51:35 +08:00
|
|
|
Text* alert = Text::create();
|
2014-06-09 14:34:46 +08:00
|
|
|
alert->setString("Label Effect");
|
2014-03-26 23:33:58 +08:00
|
|
|
alert->setFontName("fonts/Marker Felt.ttf");
|
2013-12-23 15:35:35 +08:00
|
|
|
alert->setFontSize(30);
|
|
|
|
alert->setColor(Color3B(159, 168, 176));
|
2014-06-20 11:18:53 +08:00
|
|
|
alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 3.05f));
|
2013-12-23 15:35:35 +08:00
|
|
|
_uiLayer->addChild(alert);
|
|
|
|
|
|
|
|
|
|
|
|
// create the shadow only label
|
2014-03-04 16:51:35 +08:00
|
|
|
Text* shadow_label = Text::create();
|
2013-12-23 15:35:35 +08:00
|
|
|
|
2014-06-09 14:34:46 +08:00
|
|
|
shadow_label->enableShadow();
|
|
|
|
shadow_label->setString("Shadow");
|
2014-06-20 11:18:53 +08:00
|
|
|
shadow_label->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f + shadow_label->getContentSize().height));
|
2013-12-23 15:35:35 +08:00
|
|
|
|
|
|
|
_uiLayer->addChild(shadow_label);
|
|
|
|
|
|
|
|
|
|
|
|
// create the stroke only label
|
2014-06-09 14:34:46 +08:00
|
|
|
Text* glow_label = Text::create();
|
|
|
|
glow_label->setFontName("fonts/Marker Felt.ttf");
|
|
|
|
|
|
|
|
glow_label->setString("Glow");
|
|
|
|
glow_label->enableGlow(Color4B::RED);
|
|
|
|
|
2013-12-23 15:35:35 +08:00
|
|
|
|
2014-06-09 14:34:46 +08:00
|
|
|
glow_label->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
|
2013-12-23 15:35:35 +08:00
|
|
|
|
2014-06-09 14:34:46 +08:00
|
|
|
_uiLayer->addChild(glow_label);
|
2013-12-23 15:35:35 +08:00
|
|
|
|
|
|
|
|
|
|
|
// create the label stroke and shadow
|
2014-06-09 14:34:46 +08:00
|
|
|
Text* outline_label = Text::create();
|
|
|
|
outline_label->enableOutline(Color4B::BLUE, 2);
|
|
|
|
outline_label->setString("Outline");
|
2014-06-20 11:18:53 +08:00
|
|
|
outline_label->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - shadow_label->getContentSize().height));
|
2013-12-23 15:35:35 +08:00
|
|
|
|
2014-06-09 14:34:46 +08:00
|
|
|
_uiLayer->addChild(outline_label);
|
2013-12-23 15:35:35 +08:00
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2014-06-09 14:34:46 +08:00
|
|
|
|
2013-12-23 15:35:35 +08:00
|
|
|
|
2014-03-04 16:51:35 +08:00
|
|
|
// UITextTest_TTF
|
2013-12-23 15:35:35 +08:00
|
|
|
|
2014-03-04 16:51:35 +08:00
|
|
|
bool UITextTest_TTF::init()
|
2013-12-23 15:35:35 +08:00
|
|
|
{
|
|
|
|
if (UIScene::init())
|
|
|
|
{
|
2014-06-20 11:18:53 +08:00
|
|
|
Size widgetSize = _widget->getContentSize();
|
2013-12-23 15:35:35 +08:00
|
|
|
|
2014-04-03 15:56:45 +08:00
|
|
|
Text* alert = Text::create("Text set TTF font","fonts/Marker Felt.ttf",30);
|
2013-12-23 15:35:35 +08:00
|
|
|
alert->setColor(Color3B(159, 168, 176));
|
2014-06-20 11:18:53 +08:00
|
|
|
alert->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getContentSize().height * 1.75f));
|
2013-12-23 15:35:35 +08:00
|
|
|
_uiLayer->addChild(alert);
|
|
|
|
|
2014-03-04 16:51:35 +08:00
|
|
|
// Create the text, and set font with .ttf
|
2014-04-03 15:56:45 +08:00
|
|
|
Text* text = Text::create("Text","fonts/A Damn Mess.ttf",30);
|
2014-06-20 11:18:53 +08:00
|
|
|
text->setPosition(Vec2(widgetSize.width / 2.0f, widgetSize.height / 2.0f + text->getContentSize().height / 4.0f));
|
2014-03-04 16:51:35 +08:00
|
|
|
_uiLayer->addChild(text);
|
2013-12-23 15:35:35 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|