axmol/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextTest/UITextTest.cpp

195 lines
6.6 KiB
C++
Raw Normal View History

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
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
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);
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");
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
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();
Text* leftText = Text::create("ignore conent",
"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));
leftText->setString("Text line with break\nText line with break\nText line with break\nText line with break\n");
leftText->setTouchScaleChangeEnabled(true);
leftText->setTouchEnabled(true);
_uiLayer->addChild(leftText);
Text* rightText = Text::create("ignore conent",
"fonts/Marker Felt.ttf",10);
rightText->setPosition(Vec2(widgetSize.width / 2.0f + 50,
widgetSize.height / 2.0f));
rightText->setString("Text line with break\nText line with break\nText line with break\nText line with break\n");
//note: setTextAreaSize must be used with ignoreContentAdaptWithSize(false)
rightText->setTextAreaSize(Size(100,30));
rightText->ignoreContentAdaptWithSize(false);
_uiLayer->addChild(rightText);
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);
2013-12-23 15:35:35 +08:00
return true;
}
return false;
}