2014-03-04 16:51:35 +08:00
|
|
|
#include "UITextTest.h"
|
2013-09-16 20:54:13 +08:00
|
|
|
|
2015-04-09 08:37:30 +08:00
|
|
|
USING_NS_CC;
|
|
|
|
USING_NS_CC_EXT;
|
|
|
|
using namespace cocos2d::ui;
|
|
|
|
|
2015-04-03 14:31:03 +08:00
|
|
|
UITextTests::UITextTests()
|
|
|
|
{
|
|
|
|
ADD_TEST_CASE(UITextTest);
|
|
|
|
ADD_TEST_CASE(UITextTest_LineWrap);
|
|
|
|
ADD_TEST_CASE(UILabelTest_Effect);
|
|
|
|
ADD_TEST_CASE(UITextTest_TTF);
|
|
|
|
ADD_TEST_CASE(UITextTest_IgnoreConentSize);
|
2015-12-10 13:17:31 +08:00
|
|
|
ADD_TEST_CASE(UITextTest_Clone);
|
2016-07-09 07:59:44 +08:00
|
|
|
ADD_TEST_CASE(Issue16073Test);
|
2015-04-03 14:31:03 +08:00
|
|
|
}
|
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();
|
2015-04-10 14:18:16 +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));
|
2015-04-10 14:18:16 +08:00
|
|
|
alert->setPosition(Vec2(widgetSize.width / 2.0f,
|
|
|
|
widgetSize.height / 2.0f
|
|
|
|
- alert->getContentSize().height * 1.75f));
|
|
|
|
_uiLayer->addChild(alert);
|
|
|
|
|
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);
|
2015-04-10 14:18:16 +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);
|
2015-04-10 14:18:16 +08:00
|
|
|
|
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();
|
2015-04-10 14:18:16 +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));
|
2015-04-10 14:18:16 +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);
|
2015-04-10 14:18:16 +08:00
|
|
|
|
2013-12-23 15:35:35 +08:00
|
|
|
// Create the line wrap
|
2015-04-10 14:18:16 +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));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2015-04-10 14:18:16 +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);
|
2015-04-10 14:18:16 +08:00
|
|
|
|
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();
|
2015-04-10 14:18:16 +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));
|
2015-04-10 14:18:16 +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);
|
2015-04-10 14:18:16 +08:00
|
|
|
|
|
|
|
|
2013-12-23 15:35:35 +08:00
|
|
|
// create the shadow only label
|
2014-03-04 16:51:35 +08:00
|
|
|
Text* shadow_label = Text::create();
|
2015-04-10 14:18:16 +08:00
|
|
|
|
2014-06-09 14:34:46 +08:00
|
|
|
shadow_label->enableShadow();
|
|
|
|
shadow_label->setString("Shadow");
|
2015-04-10 14:18:16 +08:00
|
|
|
shadow_label->setFontName("fonts/Marker Felt.ttf");
|
|
|
|
shadow_label->setPosition(Vec2(widgetSize.width / 2.0f,
|
|
|
|
widgetSize.height / 2.0f
|
|
|
|
+ shadow_label->getContentSize().height + 20));
|
|
|
|
|
2013-12-23 15:35:35 +08:00
|
|
|
_uiLayer->addChild(shadow_label);
|
2015-04-10 14:18:16 +08:00
|
|
|
|
|
|
|
|
2013-12-23 15:35:35 +08:00
|
|
|
// 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);
|
|
|
|
|
2015-04-10 14:18:16 +08:00
|
|
|
|
|
|
|
glow_label->setPosition(Vec2(widgetSize.width / 2.0f,
|
|
|
|
widgetSize.height / 2.0f - 20));
|
|
|
|
|
2014-06-09 14:34:46 +08:00
|
|
|
_uiLayer->addChild(glow_label);
|
2015-04-10 14:18:16 +08:00
|
|
|
|
|
|
|
|
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->setString("Outline");
|
2015-04-10 15:30:18 +08:00
|
|
|
CCLOG("content size without outline: %f %f",
|
|
|
|
outline_label->getContentSize().width,
|
|
|
|
outline_label->getContentSize().height);
|
|
|
|
outline_label->enableOutline(Color4B::GREEN, 4);
|
2015-04-10 14:18:16 +08:00
|
|
|
outline_label->setPosition(Vec2(widgetSize.width / 2.0f,
|
|
|
|
widgetSize.height / 2.0f
|
|
|
|
- shadow_label->getContentSize().height - 50));
|
|
|
|
|
2014-06-09 14:34:46 +08:00
|
|
|
_uiLayer->addChild(outline_label);
|
2015-04-10 15:30:18 +08:00
|
|
|
CCLOG("content size after applying outline: %f %f",
|
|
|
|
outline_label->getContentSize().width,
|
|
|
|
outline_label->getContentSize().height);
|
2015-04-10 14:18:16 +08:00
|
|
|
|
|
|
|
//create buttons to disable effect and add
|
|
|
|
auto disableOutlineBtn= Button::create();
|
|
|
|
disableOutlineBtn->setTitleText("Disable outline");
|
|
|
|
disableOutlineBtn->setTitleFontName("fonts/Marker Felt.ttf");
|
|
|
|
disableOutlineBtn->setPosition(Vec2(widgetSize.width * 0.3,
|
|
|
|
widgetSize.height * 0.7));
|
|
|
|
disableOutlineBtn->setPressedActionEnabled(true);
|
|
|
|
disableOutlineBtn->addClickEventListener([=](Ref*){
|
|
|
|
outline_label->disableEffect(LabelEffect::OUTLINE);
|
2015-04-10 15:30:18 +08:00
|
|
|
CCLOG("content size after disable outline: %f %f",
|
|
|
|
outline_label->getContentSize().width,
|
|
|
|
outline_label->getContentSize().height);
|
2015-04-10 14:18:16 +08:00
|
|
|
});
|
|
|
|
this->addChild(disableOutlineBtn);
|
|
|
|
|
|
|
|
auto buttonWidth = disableOutlineBtn->getContentSize().width;
|
|
|
|
|
|
|
|
auto disableGlowBtn = (Button*)disableOutlineBtn->clone();
|
|
|
|
disableGlowBtn->setPosition(disableOutlineBtn->getPosition()
|
|
|
|
+ Vec2(buttonWidth + 40,0));
|
|
|
|
disableGlowBtn->setTitleText("Disable Glow");
|
|
|
|
disableGlowBtn->addClickEventListener([=](Ref*){
|
|
|
|
glow_label->disableEffect(LabelEffect::GLOW);
|
|
|
|
});
|
|
|
|
this->addChild(disableGlowBtn);
|
|
|
|
|
|
|
|
auto disableShadowBtn = (Button*)disableGlowBtn->clone();
|
|
|
|
disableShadowBtn->setPosition(disableGlowBtn->getPosition()
|
|
|
|
+ Vec2(buttonWidth + 40,0));
|
|
|
|
disableShadowBtn->setTitleText("Disable Shadow");
|
|
|
|
disableShadowBtn->addClickEventListener([=](Ref*){
|
|
|
|
shadow_label->disableEffect(LabelEffect::SHADOW);
|
|
|
|
});
|
|
|
|
this->addChild(disableShadowBtn);
|
|
|
|
|
|
|
|
|
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();
|
2015-04-10 14:18:16 +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));
|
2015-04-10 14:18:16 +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);
|
2015-04-10 14:18:16 +08:00
|
|
|
|
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);
|
2015-04-10 14:18:16 +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);
|
2015-04-10 14:18:16 +08:00
|
|
|
|
2014-11-26 15:05:20 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// UITextTest_IgnoreConentSize
|
|
|
|
|
|
|
|
bool UITextTest_IgnoreConentSize::init()
|
|
|
|
{
|
|
|
|
if (UIScene::init())
|
|
|
|
{
|
|
|
|
Size widgetSize = _widget->getContentSize();
|
2015-04-10 14:18:16 +08:00
|
|
|
|
2017-02-23 16:14:39 +08:00
|
|
|
Text* leftText = Text::create("ignore content",
|
2014-11-26 15:05:20 +08:00
|
|
|
"fonts/Marker Felt.ttf",10);
|
|
|
|
leftText->setPosition(Vec2(widgetSize.width / 2.0f - 50,
|
|
|
|
widgetSize.height / 2.0f));
|
|
|
|
leftText->ignoreContentAdaptWithSize(false);
|
|
|
|
leftText->setTextAreaSize(Size(60,60));
|
2015-06-23 10:38:43 +08:00
|
|
|
leftText->setString("Text line with break\nText line with break\nText line with break\nText line with break\n");
|
2014-11-26 15:05:20 +08:00
|
|
|
leftText->setTouchScaleChangeEnabled(true);
|
|
|
|
leftText->setTouchEnabled(true);
|
|
|
|
_uiLayer->addChild(leftText);
|
2015-04-10 14:18:16 +08:00
|
|
|
|
|
|
|
|
2017-02-23 16:14:39 +08:00
|
|
|
Text* rightText = Text::create("ignore content",
|
2014-11-26 15:05:20 +08:00
|
|
|
"fonts/Marker Felt.ttf",10);
|
|
|
|
rightText->setPosition(Vec2(widgetSize.width / 2.0f + 50,
|
|
|
|
widgetSize.height / 2.0f));
|
2015-06-23 10:38:43 +08:00
|
|
|
rightText->setString("Text line with break\nText line with break\nText line with break\nText line with break\n");
|
2015-04-10 14:18:16 +08:00
|
|
|
//note:setTextAreaSize must be used with ignoreContentAdaptWithSize(false)
|
2014-11-26 15:05:20 +08:00
|
|
|
rightText->setTextAreaSize(Size(100,30));
|
|
|
|
rightText->ignoreContentAdaptWithSize(false);
|
|
|
|
_uiLayer->addChild(rightText);
|
2015-04-10 14:18:16 +08:00
|
|
|
|
|
|
|
|
2014-11-26 15:05:20 +08:00
|
|
|
auto halighButton = Button::create();
|
|
|
|
halighButton->setTitleText("Alignment Right");
|
|
|
|
halighButton->addClickEventListener([=](Ref*){
|
|
|
|
leftText->setTextHorizontalAlignment(TextHAlignment::RIGHT);
|
|
|
|
rightText->setTextHorizontalAlignment(TextHAlignment::RIGHT);
|
|
|
|
});
|
|
|
|
halighButton->setPosition(Vec2(widgetSize.width/2 - 50,
|
|
|
|
widgetSize.height/2 - 50));
|
|
|
|
_uiLayer->addChild(halighButton);
|
2015-04-10 14:18:16 +08:00
|
|
|
|
2013-12-23 15:35:35 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2015-12-10 13:17:31 +08:00
|
|
|
|
|
|
|
// UITextTest_IgnoreConentSize
|
|
|
|
|
|
|
|
bool UITextTest_Clone::init()
|
|
|
|
{
|
|
|
|
if (UIScene::init())
|
|
|
|
{
|
|
|
|
Size widgetSize = _widget->getContentSize();
|
|
|
|
|
2017-02-23 16:14:39 +08:00
|
|
|
Text* singleText = Text::create("ignore content",
|
2015-12-10 13:17:31 +08:00
|
|
|
"fonts/Marker Felt.ttf", 30);
|
|
|
|
singleText->setPosition(Vec2(widgetSize.width / 2.0f - 80,
|
|
|
|
widgetSize.height / 2.0f));
|
|
|
|
singleText->setString("CHUKONG");
|
|
|
|
singleText->setTouchScaleChangeEnabled(true);
|
|
|
|
singleText->setTouchEnabled(true);
|
|
|
|
singleText->enableOutline(Color4B(255,0,0,100), 10);
|
|
|
|
singleText->enableShadow(Color4B::YELLOW, Size(2,-2), 0);
|
|
|
|
_uiLayer->addChild(singleText);
|
|
|
|
|
|
|
|
auto cloneText = singleText->clone();
|
|
|
|
cloneText->setPosition(Vec2(widgetSize.width / 2.0f + 80,
|
|
|
|
widgetSize.height / 2.0f));
|
|
|
|
_uiLayer->addChild(cloneText);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-07-09 07:59:44 +08:00
|
|
|
// Issue16073Test
|
|
|
|
|
|
|
|
bool Issue16073Test::init()
|
|
|
|
{
|
|
|
|
if (UIScene::init())
|
|
|
|
{
|
|
|
|
Size widgetSize = _widget->getContentSize();
|
|
|
|
|
|
|
|
Text* singleText = Text::create("mwhahaha\360", "Verdana", 40);
|
|
|
|
|
|
|
|
singleText->setPosition(Vec2(widgetSize.width / 2.0f - 80,
|
|
|
|
widgetSize.height / 2.0f));
|
|
|
|
_uiLayer->addChild(singleText);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|