mirror of https://github.com/axmolengine/axmol.git
193 lines
6.5 KiB
C++
193 lines
6.5 KiB
C++
|
|
|
|
#include "UILabelTest.h"
|
|
|
|
|
|
// UILabelTest
|
|
|
|
bool UILabelTest::init()
|
|
{
|
|
if (UIScene::init())
|
|
{
|
|
Size widgetSize = _widget->getSize();
|
|
|
|
gui::Text* alert = gui::Text::create();
|
|
alert->setText("Label");
|
|
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
|
|
gui::Text* label = gui::Text::create();
|
|
label->setText("Label");
|
|
label->setFontName("AmericanTypewriter");
|
|
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;
|
|
}
|
|
|
|
// UILabelTest_LineWrap
|
|
|
|
bool UILabelTest_LineWrap::init()
|
|
{
|
|
if (UIScene::init())
|
|
{
|
|
Size widgetSize = _widget->getSize();
|
|
|
|
gui::Text* alert = gui::Text::create();
|
|
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
|
|
gui::Text* label = gui::Text::create();
|
|
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();
|
|
|
|
gui::Label* alert = gui::Label::create();
|
|
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
|
|
gui::Label* shadow_label = gui::Label::create();
|
|
|
|
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
|
|
gui::Label* stroke_label = gui::Label::create();
|
|
|
|
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
|
|
gui::Label* strokeAndShadow_label = gui::Label::create();
|
|
|
|
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();
|
|
|
|
gui::Text* alert = gui::Text::create();
|
|
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
|
|
gui::Text* label = gui::Text::create();
|
|
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;
|
|
}
|