axmol/tests/Classes/ExtensionsTest/CocoStudioGUITest/UILabelTest/UILabelTest.cpp

193 lines
6.5 KiB
C++
Raw Normal View History

2013-09-16 20:54:13 +08:00
#include "UILabelTest.h"
// UILabelTest
bool UILabelTest::init()
{
if (UIScene::init())
{
2013-12-23 15:35:35 +08:00
Size widgetSize = _widget->getSize();
2013-09-16 20:54:13 +08:00
ui::Text* alert = ui::Text::create();
2013-09-16 20:54:13 +08:00
alert->setText("Label");
2013-12-23 15:35:35 +08:00
alert->setFontName("Marker Felt");
2013-09-16 20:54:13 +08:00
alert->setFontSize(30);
alert->setColor(Color3B(159, 168, 176));
2013-12-23 15:35:35 +08:00
alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 1.75f));
_uiLayer->addChild(alert);
2013-09-16 20:54:13 +08:00
// Create the label
ui::Text* label = ui::Text::create();
2013-09-16 20:54:13 +08:00
label->setText("Label");
label->setFontName("AmericanTypewriter");
label->setFontSize(30);
2013-12-23 15:35:35 +08:00
label->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f + label->getSize().height / 4.0f));
_uiLayer->addChild(label);
2013-09-16 20:54:13 +08:00
return true;
}
return false;
2013-12-23 15:35:35 +08:00
}
// UILabelTest_LineWrap
bool UILabelTest_LineWrap::init()
{
if (UIScene::init())
{
Size widgetSize = _widget->getSize();
ui::Text* alert = ui::Text::create();
2013-12-23 15:35:35 +08:00
alert->setText("Label line wrap");
alert->setFontName("Marker Felt");
alert->setFontSize(30);
alert->setColor(Color3B(159, 168, 176));
alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 1.75f));
_uiLayer->addChild(alert);
// Create the line wrap
ui::Text* label = ui::Text::create();
2013-12-23 15:35:35 +08:00
label->setTextAreaSize(Size(280, 150));
label->setTextHorizontalAlignment(TextHAlignment::CENTER);
label->setText("Label can line wrap");
label->setFontName("AmericanTypewriter");
label->setFontSize(32);
label->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - label->getSize().height / 8.0f));
_uiLayer->addChild(label);
return true;
}
return false;
}
/*
// UILabelTest_Effect
bool UILabelTest_Effect::init()
{
if (UIScene::init())
{
Size widgetSize = _widget->getSize();
ui::Label* alert = ui::Label::create();
2013-12-23 15:35:35 +08:00
alert->setText("Label Effect");
alert->setFontName("Marker Felt");
alert->setFontSize(30);
alert->setColor(Color3B(159, 168, 176));
alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 3.05f));
_uiLayer->addChild(alert);
// create the shadow only label
ui::Label* shadow_label = ui::Label::create();
2013-12-23 15:35:35 +08:00
Color3B tintColorRed = { 255, 0, 0 };
Size shadowOffset(12.0f, 12.0f);
FontDefinition shadowTextDef;
shadowTextDef._fontSize = 20;
shadowTextDef._fontName = std::string("Marker Felt");
shadowTextDef._shadow._shadowEnabled = true;
shadowTextDef._shadow._shadowOffset = shadowOffset;
shadowTextDef._shadow._shadowOpacity = 1.0f;
shadowTextDef._shadow._shadowBlur = 1.0f;
shadowTextDef._fontFillColor = tintColorRed;
shadow_label->setTextDefinition(shadowTextDef);
shadow_label->setText("Shadow");
shadow_label->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f + shadow_label->getSize().height));
_uiLayer->addChild(shadow_label);
// create the stroke only label
ui::Label* stroke_label = ui::Label::create();
2013-12-23 15:35:35 +08:00
Color3B tintColorYellow = { 255, 255, 0 };
Color3B strokeColor = { 0, 10, 255 };
FontDefinition strokeTextDef;
strokeTextDef._fontSize = 20;
strokeTextDef._fontName = std::string("Marker Felt");
strokeTextDef._stroke._strokeEnabled = true;
strokeTextDef._stroke._strokeColor = strokeColor;
strokeTextDef._stroke._strokeSize = 1.5f;
strokeTextDef._fontFillColor = tintColorYellow;
stroke_label->setTextDefinition(strokeTextDef);
stroke_label->setText("Stroke");
stroke_label->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f));
_uiLayer->addChild(stroke_label);
// create the label stroke and shadow
ui::Label* strokeAndShadow_label = ui::Label::create();
2013-12-23 15:35:35 +08:00
Color3B tintColorBlue = { 0, 0, 255 };
Color3B strokeShadowColor = { 255, 0, 0 };
FontDefinition strokeShaodwTextDef;
strokeShaodwTextDef._fontSize = 20;
strokeShaodwTextDef._fontName = std::string("Marker Felt");
strokeShaodwTextDef._stroke._strokeEnabled = true;
strokeShaodwTextDef._stroke._strokeColor = strokeShadowColor;
strokeShaodwTextDef._stroke._strokeSize = 1.5f;
strokeShaodwTextDef._shadow._shadowEnabled = true;
strokeShaodwTextDef._shadow._shadowOffset = shadowOffset;
strokeShaodwTextDef._shadow._shadowOpacity = 1.0f;
strokeShaodwTextDef._shadow._shadowBlur = 1.0f;
strokeShaodwTextDef._fontFillColor = tintColorBlue;
strokeAndShadow_label->setTextDefinition(strokeShaodwTextDef);
// strokeAndShadow_label->setFontFillColor(tintColorRed);
strokeAndShadow_label->setText("Stroke and Shadow");
strokeAndShadow_label->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - shadow_label->getSize().height));
_uiLayer->addChild(strokeAndShadow_label);
return true;
}
return false;
}
*/
// UILabelTest_TTF
bool UILabelTest_TTF::init()
{
if (UIScene::init())
{
Size widgetSize = _widget->getSize();
ui::Text* alert = ui::Text::create();
2013-12-23 15:35:35 +08:00
alert->setText("Label set TTF font");
alert->setFontName("Marker Felt");
alert->setFontSize(30);
alert->setColor(Color3B(159, 168, 176));
alert->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f - alert->getSize().height * 1.75f));
_uiLayer->addChild(alert);
// Create the label
ui::Text* label = ui::Text::create();
2013-12-23 15:35:35 +08:00
label->setText("Label");
label->setFontName("fonts/A Damn Mess.ttf");
label->setFontSize(30);
label->setPosition(Point(widgetSize.width / 2.0f, widgetSize.height / 2.0f + label->getSize().height / 4.0f));
_uiLayer->addChild(label);
return true;
}
return false;
}