2018-01-29 16:25:32 +08:00
|
|
|
|
/****************************************************************************
|
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
2022-10-01 16:24:52 +08:00
|
|
|
|
https://axmolengine.github.io/
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
2018-01-29 16:25:32 +08:00
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
|
furnished to do so, subject to the following conditions:
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
2018-01-29 16:25:32 +08:00
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
|
all copies or substantial portions of the Software.
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
2018-01-29 16:25:32 +08:00
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
|
THE SOFTWARE.
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
2013-09-08 11:26:38 +08:00
|
|
|
|
#include "LabelTestNew.h"
|
2013-08-13 04:29:54 +08:00
|
|
|
|
#include "../testResource.h"
|
2014-04-30 08:37:36 +08:00
|
|
|
|
#include "renderer/CCRenderer.h"
|
2015-08-05 14:12:02 +08:00
|
|
|
|
#include "2d/CCFontAtlasCache.h"
|
2013-08-13 04:29:54 +08:00
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
|
USING_NS_AX;
|
2014-03-05 15:54:40 +08:00
|
|
|
|
using namespace ui;
|
2015-11-19 16:06:13 +08:00
|
|
|
|
using namespace extension;
|
2014-03-05 15:54:40 +08:00
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
|
enum
|
|
|
|
|
{
|
|
|
|
|
kTagTileMap = 1,
|
2013-08-13 04:29:54 +08:00
|
|
|
|
kTagSpriteManager = 1,
|
2021-12-28 16:06:23 +08:00
|
|
|
|
kTagAnimation1 = 1,
|
|
|
|
|
kTagBitmapAtlas1 = 1,
|
|
|
|
|
kTagBitmapAtlas2 = 2,
|
|
|
|
|
kTagBitmapAtlas3 = 3,
|
2013-08-13 04:29:54 +08:00
|
|
|
|
};
|
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
|
enum
|
|
|
|
|
{
|
2013-08-13 04:29:54 +08:00
|
|
|
|
kTagSprite1,
|
|
|
|
|
kTagSprite2,
|
|
|
|
|
kTagSprite3,
|
|
|
|
|
kTagSprite4,
|
|
|
|
|
kTagSprite5,
|
|
|
|
|
kTagSprite6,
|
|
|
|
|
kTagSprite7,
|
|
|
|
|
kTagSprite8,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// AtlasDemoNew
|
|
|
|
|
//
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
|
2015-04-03 14:31:03 +08:00
|
|
|
|
NewLabelTests::NewLabelTests()
|
2013-08-13 04:29:54 +08:00
|
|
|
|
{
|
2020-09-17 11:49:47 +08:00
|
|
|
|
ADD_TEST_CASE(LabelIssue20523);
|
2015-08-25 17:50:47 +08:00
|
|
|
|
ADD_TEST_CASE(LabelFNTGlyphDesigner);
|
2015-04-03 14:31:03 +08:00
|
|
|
|
ADD_TEST_CASE(LabelFNTColor);
|
2015-07-20 11:10:17 +08:00
|
|
|
|
ADD_TEST_CASE(LabelFNTOpacity);
|
2015-08-25 17:50:47 +08:00
|
|
|
|
ADD_TEST_CASE(LabelFNTColorAndOpacity);
|
|
|
|
|
ADD_TEST_CASE(LabelFNTSpriteActions);
|
2015-04-03 14:31:03 +08:00
|
|
|
|
ADD_TEST_CASE(LabelFNTMultiLine);
|
|
|
|
|
ADD_TEST_CASE(LabelFNTRetina);
|
|
|
|
|
ADD_TEST_CASE(LabelFNTMultiLineAlignment);
|
2018-01-10 17:01:19 +08:00
|
|
|
|
ADD_TEST_CASE(LabelFNTMultiLineAlignmentUNICODE);
|
2015-04-03 14:31:03 +08:00
|
|
|
|
ADD_TEST_CASE(LabelFNTUNICODELanguages);
|
|
|
|
|
ADD_TEST_CASE(LabelFNTBounds);
|
2015-08-25 17:50:47 +08:00
|
|
|
|
ADD_TEST_CASE(LabelFNTandTTFEmpty);
|
|
|
|
|
ADD_TEST_CASE(LabelFNTHundredLabels);
|
|
|
|
|
ADD_TEST_CASE(LabelFNTPadding);
|
|
|
|
|
ADD_TEST_CASE(LabelFNTOffset);
|
2020-01-06 09:35:52 +08:00
|
|
|
|
ADD_TEST_CASE(LabelFNTMultiFontAtlasNoRotation);
|
|
|
|
|
ADD_TEST_CASE(LabelFNTMultiFontAtlasWithRotation);
|
2015-08-25 17:50:47 +08:00
|
|
|
|
|
|
|
|
|
ADD_TEST_CASE(LabelTTFFontsTestNew);
|
2015-04-03 14:31:03 +08:00
|
|
|
|
ADD_TEST_CASE(LabelTTFLongLineWrapping);
|
2015-08-25 17:50:47 +08:00
|
|
|
|
ADD_TEST_CASE(LabelTTFCJKWrappingTest);
|
2015-04-03 14:31:03 +08:00
|
|
|
|
ADD_TEST_CASE(LabelTTFColor);
|
|
|
|
|
ADD_TEST_CASE(LabelTTFDynamicAlignment);
|
2017-02-06 16:41:52 +08:00
|
|
|
|
ADD_TEST_CASE(LabelTTFEmoji);
|
2015-08-25 17:50:47 +08:00
|
|
|
|
ADD_TEST_CASE(LabelAlignmentTest);
|
2015-04-03 14:31:03 +08:00
|
|
|
|
ADD_TEST_CASE(LabelTTFUnicodeNew);
|
|
|
|
|
ADD_TEST_CASE(LabelTTFDistanceField);
|
|
|
|
|
ADD_TEST_CASE(LabelOutlineAndGlowTest);
|
2015-08-25 17:50:47 +08:00
|
|
|
|
ADD_TEST_CASE(LabelMultilineWithOutline);
|
2015-04-03 14:31:03 +08:00
|
|
|
|
ADD_TEST_CASE(LabelShadowTest);
|
|
|
|
|
ADD_TEST_CASE(LabelLineHeightTest);
|
|
|
|
|
ADD_TEST_CASE(LabelAdditionalKerningTest);
|
2015-08-25 17:50:47 +08:00
|
|
|
|
ADD_TEST_CASE(LabelAddChildTest);
|
2015-04-03 14:31:03 +08:00
|
|
|
|
ADD_TEST_CASE(LabelSmallDimensionsTest);
|
2015-08-25 17:50:47 +08:00
|
|
|
|
|
|
|
|
|
ADD_TEST_CASE(LabelCharMapTest);
|
|
|
|
|
ADD_TEST_CASE(LabelCharMapColorTest);
|
|
|
|
|
|
2015-04-03 14:31:03 +08:00
|
|
|
|
ADD_TEST_CASE(LabelSystemFontColor);
|
2015-08-25 17:50:47 +08:00
|
|
|
|
ADD_TEST_CASE(LabelTTFOldNew);
|
|
|
|
|
ADD_TEST_CASE(LabelFontNameTest);
|
|
|
|
|
|
|
|
|
|
ADD_TEST_CASE(LabelCrashTest);
|
|
|
|
|
ADD_TEST_CASE(LabelIssue12775Test);
|
|
|
|
|
ADD_TEST_CASE(LabelIssue11585Test);
|
2015-04-30 16:11:59 +08:00
|
|
|
|
ADD_TEST_CASE(LabelIssue10773Test);
|
2015-05-07 11:48:55 +08:00
|
|
|
|
ADD_TEST_CASE(LabelIssue11576Test);
|
2015-05-06 17:17:30 +08:00
|
|
|
|
ADD_TEST_CASE(LabelIssue11699Test);
|
2015-06-19 13:39:19 +08:00
|
|
|
|
ADD_TEST_CASE(LabelIssue12409Test);
|
2015-08-25 17:50:47 +08:00
|
|
|
|
ADD_TEST_CASE(LabelIssue10089Test);
|
|
|
|
|
ADD_TEST_CASE(LabelIssue9255Test);
|
|
|
|
|
ADD_TEST_CASE(LabelIssue8492Test);
|
|
|
|
|
ADD_TEST_CASE(LabelIssue4428Test);
|
|
|
|
|
ADD_TEST_CASE(LabelIssue4999Test);
|
2015-07-29 16:30:07 +08:00
|
|
|
|
ADD_TEST_CASE(LabelIssue10688Test);
|
2015-08-05 14:12:02 +08:00
|
|
|
|
ADD_TEST_CASE(LabelIssue13202Test);
|
2015-08-05 23:46:41 +08:00
|
|
|
|
ADD_TEST_CASE(LabelIssue9500Test);
|
2015-11-19 16:06:13 +08:00
|
|
|
|
ADD_TEST_CASE(LabelWrapByWordTest);
|
|
|
|
|
ADD_TEST_CASE(LabelWrapByCharTest);
|
2018-03-13 09:40:24 +08:00
|
|
|
|
ADD_TEST_CASE(LabelWrapNoBreakSpaceTest);
|
2015-11-19 16:06:13 +08:00
|
|
|
|
ADD_TEST_CASE(LabelShrinkByWordTest);
|
|
|
|
|
ADD_TEST_CASE(LabelShrinkByCharTest);
|
|
|
|
|
ADD_TEST_CASE(LabelResizeTest);
|
|
|
|
|
ADD_TEST_CASE(LabelToggleTypeTest);
|
|
|
|
|
ADD_TEST_CASE(LabelSystemFontTest);
|
|
|
|
|
ADD_TEST_CASE(LabelCharMapFontTest);
|
2015-12-16 14:59:33 +08:00
|
|
|
|
ADD_TEST_CASE(LabelIssue13846Test);
|
2016-01-20 12:41:31 +08:00
|
|
|
|
|
|
|
|
|
ADD_TEST_CASE(LabelRichText);
|
|
|
|
|
ADD_TEST_CASE(LabelStrikethrough);
|
|
|
|
|
ADD_TEST_CASE(LabelUnderline);
|
|
|
|
|
ADD_TEST_CASE(LabelUnderlineMultiline);
|
|
|
|
|
ADD_TEST_CASE(LabelItalics);
|
|
|
|
|
ADD_TEST_CASE(LabelBold);
|
2016-02-26 17:15:24 +08:00
|
|
|
|
|
|
|
|
|
ADD_TEST_CASE(LabelLocalizationTest);
|
2016-06-18 08:23:59 +08:00
|
|
|
|
|
|
|
|
|
ADD_TEST_CASE(LabelIssue15214);
|
2016-08-14 00:38:42 +08:00
|
|
|
|
ADD_TEST_CASE(LabelIssue16293);
|
2016-09-01 11:20:13 +08:00
|
|
|
|
ADD_TEST_CASE(LabelIssue16471);
|
2016-12-16 14:56:36 +08:00
|
|
|
|
ADD_TEST_CASE(LabelIssue16717);
|
2017-02-13 13:58:32 +08:00
|
|
|
|
ADD_TEST_CASE(LabelIssueLineGap);
|
2017-06-07 16:56:02 +08:00
|
|
|
|
ADD_TEST_CASE(LabelIssue17902);
|
2018-08-06 14:27:47 +08:00
|
|
|
|
ADD_TEST_CASE(LabelLetterColorsTest);
|
2013-08-13 04:29:54 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
LabelFNTColorAndOpacity::LabelFNTColorAndOpacity()
|
|
|
|
|
{
|
|
|
|
|
_time = 0;
|
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
|
auto col = LayerColor::create(Color4B(128, 128, 128, 255));
|
2013-08-13 04:29:54 +08:00
|
|
|
|
addChild(col, -10);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
2014-01-11 22:33:07 +08:00
|
|
|
|
auto label1 = Label::createWithBMFont("fonts/bitmapFontTest2.fnt", "Test");
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
|
|
|
|
label1->setAnchorPoint(Vec2(0, 0));
|
2013-08-13 04:29:54 +08:00
|
|
|
|
addChild(label1, 0, kTagBitmapAtlas1);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
auto fade = FadeOut::create(1.0f);
|
2013-08-16 16:05:27 +08:00
|
|
|
|
auto fade_in = fade->reverse();
|
2021-12-28 16:06:23 +08:00
|
|
|
|
auto seq = Sequence::create(fade, fade_in, nullptr);
|
|
|
|
|
auto repeat = RepeatForever::create(seq);
|
2013-08-13 04:29:54 +08:00
|
|
|
|
label1->runAction(repeat);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
2014-01-11 22:33:07 +08:00
|
|
|
|
auto label2 = Label::createWithBMFont("fonts/bitmapFontTest2.fnt", "Test");
|
2021-12-28 16:06:23 +08:00
|
|
|
|
label2->setColor(Color3B::RED);
|
2013-08-13 04:29:54 +08:00
|
|
|
|
addChild(label2, 0, kTagBitmapAtlas2);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
auto tint = Sequence::create(TintTo::create(1, 255, 0, 0), TintTo::create(1, 0, 255, 0),
|
|
|
|
|
TintTo::create(1, 0, 0, 255), nullptr);
|
|
|
|
|
label2->runAction(RepeatForever::create(tint));
|
|
|
|
|
|
2014-01-11 22:33:07 +08:00
|
|
|
|
auto label3 = Label::createWithBMFont("fonts/bitmapFontTest2.fnt", "Test");
|
2021-12-28 16:06:23 +08:00
|
|
|
|
label3->setAnchorPoint(Vec2(1, 1));
|
2013-08-13 04:29:54 +08:00
|
|
|
|
addChild(label3, 0, kTagBitmapAtlas3);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
|
|
|
|
label1->setPosition(VisibleRect::leftBottom());
|
|
|
|
|
label2->setPosition(VisibleRect::center());
|
|
|
|
|
label3->setPosition(VisibleRect::rightTop());
|
|
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
|
schedule(AX_CALLBACK_1(LabelFNTColorAndOpacity::step, this), "step_key");
|
2013-08-13 04:29:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void LabelFNTColorAndOpacity::step(float dt)
|
|
|
|
|
{
|
|
|
|
|
_time += dt;
|
|
|
|
|
char string[15] = {0};
|
|
|
|
|
sprintf(string, "%2.2f Test j", _time);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
|
|
|
|
auto label1 = (Label*)getChildByTag(kTagBitmapAtlas1);
|
2013-08-13 04:29:54 +08:00
|
|
|
|
label1->setString(string);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
|
|
|
|
auto label2 = (Label*)getChildByTag(kTagBitmapAtlas2);
|
2013-08-13 04:29:54 +08:00
|
|
|
|
label2->setString(string);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
|
|
|
|
auto label3 = (Label*)getChildByTag(kTagBitmapAtlas3);
|
2013-08-13 04:29:54 +08:00
|
|
|
|
label3->setString(string);
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
|
std::string LabelFNTColorAndOpacity::title() const
|
2013-08-13 04:29:54 +08:00
|
|
|
|
{
|
2015-08-25 17:50:47 +08:00
|
|
|
|
return "New Label + Bitmap font";
|
2013-08-13 04:29:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
|
std::string LabelFNTColorAndOpacity::subtitle() const
|
2013-08-13 04:29:54 +08:00
|
|
|
|
{
|
2015-08-25 17:50:47 +08:00
|
|
|
|
return "Testing fade/tint action";
|
2013-08-13 04:29:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LabelFNTSpriteActions::LabelFNTSpriteActions()
|
|
|
|
|
{
|
|
|
|
|
_time = 0;
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
2014-09-11 15:39:56 +08:00
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
2014-09-11 15:39:56 +08:00
|
|
|
|
auto drawNode = DrawNode::create();
|
2021-12-28 16:06:23 +08:00
|
|
|
|
drawNode->drawLine(Vec2(0.0f, s.height / 2), Vec2(s.width, s.height / 2), Color4F(1.0f, 1.0f, 1.0f, 1.0f));
|
|
|
|
|
drawNode->drawLine(Vec2(s.width / 2, 0.0f), Vec2(s.width / 2, s.height), Color4F(1.0f, 1.0f, 1.0f, 1.0f));
|
2014-09-11 15:39:56 +08:00
|
|
|
|
addChild(drawNode, -1);
|
2013-08-13 04:29:54 +08:00
|
|
|
|
|
|
|
|
|
// Upper Label
|
2014-01-11 22:33:07 +08:00
|
|
|
|
auto label = Label::createWithBMFont("fonts/bitmapFontTest.fnt", "Bitmap Font Atlas");
|
2013-08-13 04:29:54 +08:00
|
|
|
|
addChild(label);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
|
|
|
|
label->setPosition(Vec2(s.width / 2, s.height / 2));
|
|
|
|
|
|
|
|
|
|
auto BChar = (Sprite*)label->getLetter(0);
|
|
|
|
|
auto FChar = (Sprite*)label->getLetter(7);
|
|
|
|
|
auto AChar = (Sprite*)label->getLetter(12);
|
|
|
|
|
|
|
|
|
|
auto rotate = RotateBy::create(2, 360);
|
2013-08-16 16:05:27 +08:00
|
|
|
|
auto rot_4ever = RepeatForever::create(rotate);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
|
|
|
|
auto scale = ScaleBy::create(2, 1.5f);
|
|
|
|
|
auto scale_back = scale->reverse();
|
|
|
|
|
auto scale_seq = Sequence::create(scale, scale_back, nullptr);
|
2013-08-16 16:05:27 +08:00
|
|
|
|
auto scale_4ever = RepeatForever::create(scale_seq);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
|
|
|
|
auto jump = JumpBy::create(0.5f, Vec2::ZERO, 60, 1);
|
2013-08-16 16:05:27 +08:00
|
|
|
|
auto jump_4ever = RepeatForever::create(jump);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
|
|
|
|
auto fade_out = FadeOut::create(1);
|
|
|
|
|
auto fade_in = FadeIn::create(1);
|
|
|
|
|
auto seq = Sequence::create(fade_out, fade_in, nullptr);
|
2013-08-16 16:05:27 +08:00
|
|
|
|
auto fade_4ever = RepeatForever::create(seq);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
2013-08-13 04:29:54 +08:00
|
|
|
|
BChar->runAction(rot_4ever);
|
|
|
|
|
BChar->runAction(scale_4ever);
|
|
|
|
|
FChar->runAction(jump_4ever);
|
|
|
|
|
AChar->runAction(fade_4ever);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
2013-08-13 04:29:54 +08:00
|
|
|
|
// Bottom Label
|
2014-01-11 22:33:07 +08:00
|
|
|
|
auto label2 = Label::createWithBMFont("fonts/bitmapFontTest.fnt", "00.0");
|
2013-08-13 04:29:54 +08:00
|
|
|
|
addChild(label2, 0, kTagBitmapAtlas2);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
label2->setPosition(Vec2(s.width / 2.0f, 80.0f));
|
|
|
|
|
|
|
|
|
|
auto lastChar = (Sprite*)label2->getLetter(3);
|
|
|
|
|
lastChar->runAction(rot_4ever->clone());
|
|
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
|
schedule(AX_CALLBACK_1(LabelFNTSpriteActions::step, this), 0.1f, "step_key");
|
2013-08-13 04:29:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void LabelFNTSpriteActions::step(float dt)
|
|
|
|
|
{
|
|
|
|
|
_time += dt;
|
|
|
|
|
char string[10] = {0};
|
|
|
|
|
sprintf(string, "%04.1f", _time);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
auto label1 = (Label*)getChildByTag(kTagBitmapAtlas2);
|
2013-08-13 04:29:54 +08:00
|
|
|
|
label1->setString(string);
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
|
std::string LabelFNTSpriteActions::title() const
|
2013-08-13 04:29:54 +08:00
|
|
|
|
{
|
2015-08-25 17:50:47 +08:00
|
|
|
|
return "New Label + Bitmap font";
|
2013-08-13 04:29:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
|
std::string LabelFNTSpriteActions::subtitle() const
|
2013-08-13 04:29:54 +08:00
|
|
|
|
{
|
2015-08-25 17:50:47 +08:00
|
|
|
|
return "Testing run action on the specified character";
|
2013-08-13 04:29:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LabelFNTPadding::LabelFNTPadding()
|
|
|
|
|
{
|
2014-01-11 22:33:07 +08:00
|
|
|
|
auto label = Label::createWithBMFont("fonts/bitmapFontTest4.fnt", "abcdefg");
|
2013-08-13 04:29:54 +08:00
|
|
|
|
addChild(label);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
|
|
|
|
label->setPosition(Vec2(s.width / 2, s.height / 2));
|
2013-08-13 04:29:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
|
std::string LabelFNTPadding::title() const
|
2013-08-13 04:29:54 +08:00
|
|
|
|
{
|
2015-08-25 17:50:47 +08:00
|
|
|
|
return "New Label + Bitmap font";
|
2013-08-13 04:29:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
|
std::string LabelFNTPadding::subtitle() const
|
2013-08-13 04:29:54 +08:00
|
|
|
|
{
|
|
|
|
|
return "Testing padding";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LabelFNTOffset::LabelFNTOffset()
|
|
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2013-08-13 04:29:54 +08:00
|
|
|
|
|
2014-03-25 10:57:44 +08:00
|
|
|
|
Label* label = nullptr;
|
2021-12-28 16:06:23 +08:00
|
|
|
|
label = Label::createWithBMFont("fonts/bitmapFontTest5.fnt", "FaFeFiFoFu");
|
2013-08-13 04:29:54 +08:00
|
|
|
|
addChild(label);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
label->setPosition(Vec2(s.width / 2, s.height / 2 + 50));
|
|
|
|
|
|
2014-01-11 22:33:07 +08:00
|
|
|
|
label = Label::createWithBMFont("fonts/bitmapFontTest5.fnt", "fafefifofu");
|
2013-08-13 04:29:54 +08:00
|
|
|
|
addChild(label);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
label->setPosition(Vec2(s.width / 2, s.height / 2));
|
2013-08-13 04:29:54 +08:00
|
|
|
|
|
2014-01-11 22:33:07 +08:00
|
|
|
|
label = Label::createWithBMFont("fonts/bitmapFontTest5.fnt", "aeiou");
|
2013-08-13 04:29:54 +08:00
|
|
|
|
addChild(label);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
label->setPosition(Vec2(s.width / 2, s.height / 2 - 50));
|
2013-08-13 04:29:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
|
std::string LabelFNTOffset::title() const
|
2013-08-13 04:29:54 +08:00
|
|
|
|
{
|
2015-08-25 17:50:47 +08:00
|
|
|
|
return "New Label + Bitmap font";
|
2013-08-13 04:29:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
|
std::string LabelFNTOffset::subtitle() const
|
2013-08-13 04:29:54 +08:00
|
|
|
|
{
|
|
|
|
|
return "Rendering should be OK. Testing offset";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LabelFNTColor::LabelFNTColor()
|
|
|
|
|
{
|
2015-08-25 17:50:47 +08:00
|
|
|
|
auto winSize = Director::getInstance()->getWinSize();
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
2015-08-25 17:50:47 +08:00
|
|
|
|
auto label = Label::createWithBMFont("fonts/bitmapFontTest5.fnt", "Blue");
|
2021-12-28 16:06:23 +08:00
|
|
|
|
label->setColor(Color3B::BLUE);
|
2013-08-13 04:29:54 +08:00
|
|
|
|
addChild(label);
|
2015-08-25 17:50:47 +08:00
|
|
|
|
label->setPosition(winSize.width / 2, winSize.height * 0.7f);
|
2013-08-13 04:29:54 +08:00
|
|
|
|
|
2014-01-11 22:33:07 +08:00
|
|
|
|
label = Label::createWithBMFont("fonts/bitmapFontTest5.fnt", "Red");
|
2013-08-13 04:29:54 +08:00
|
|
|
|
addChild(label);
|
2015-08-25 17:50:47 +08:00
|
|
|
|
label->setPosition(winSize.width / 2, winSize.height * 0.5f);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
label->setColor(Color3B::RED);
|
2013-08-13 04:29:54 +08:00
|
|
|
|
|
2014-01-11 22:33:07 +08:00
|
|
|
|
label = Label::createWithBMFont("fonts/bitmapFontTest5.fnt", "Green");
|
2013-08-13 04:29:54 +08:00
|
|
|
|
addChild(label);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
label->setPosition(winSize.width / 2, winSize.height * 0.3f);
|
|
|
|
|
label->setColor(Color3B::GREEN);
|
2013-08-13 04:29:54 +08:00
|
|
|
|
label->setString("Green");
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
|
std::string LabelFNTColor::title() const
|
2013-08-13 04:29:54 +08:00
|
|
|
|
{
|
2015-08-25 17:50:47 +08:00
|
|
|
|
return "New Label + Bitmap font";
|
2013-08-13 04:29:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
|
std::string LabelFNTColor::subtitle() const
|
2013-08-13 04:29:54 +08:00
|
|
|
|
{
|
|
|
|
|
return "Testing color";
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-20 11:10:17 +08:00
|
|
|
|
LabelFNTOpacity::LabelFNTOpacity()
|
|
|
|
|
{
|
2015-08-25 17:50:47 +08:00
|
|
|
|
auto winSize = Director::getInstance()->getWinSize();
|
2015-07-20 11:10:17 +08:00
|
|
|
|
|
|
|
|
|
auto label = Label::createWithBMFont("fonts/bitmapFontTest5.fnt", "Opacity 100");
|
|
|
|
|
label->setOpacity(100);
|
|
|
|
|
addChild(label);
|
2015-08-25 17:50:47 +08:00
|
|
|
|
label->setPosition(winSize.width / 2, winSize.height * 0.6f);
|
2015-07-20 11:10:17 +08:00
|
|
|
|
|
|
|
|
|
label = Label::createWithBMFont("fonts/bitmapFontTest5.fnt", "Opacity 200");
|
|
|
|
|
label->setOpacity(200);
|
|
|
|
|
addChild(label);
|
2015-08-25 17:50:47 +08:00
|
|
|
|
label->setPosition(winSize.width / 2, winSize.height * 0.4f);
|
2015-07-20 11:10:17 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelFNTOpacity::title() const
|
|
|
|
|
{
|
2015-08-25 17:50:47 +08:00
|
|
|
|
return "New Label + Bitmap font";
|
2015-07-20 11:10:17 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelFNTOpacity::subtitle() const
|
|
|
|
|
{
|
|
|
|
|
return "Testing opacity";
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-13 04:29:54 +08:00
|
|
|
|
LabelFNTHundredLabels::LabelFNTHundredLabels()
|
|
|
|
|
{
|
|
|
|
|
// Upper Label
|
2021-12-28 16:06:23 +08:00
|
|
|
|
for (int i = 0; i < 100; i++)
|
2013-08-13 04:29:54 +08:00
|
|
|
|
{
|
|
|
|
|
char str[6] = {0};
|
|
|
|
|
sprintf(str, "-%d-", i);
|
2014-01-11 22:33:07 +08:00
|
|
|
|
auto label = Label::createWithBMFont("fonts/bitmapFontTest.fnt", str);
|
2013-08-13 04:29:54 +08:00
|
|
|
|
addChild(label);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2013-08-13 04:29:54 +08:00
|
|
|
|
|
2022-07-16 10:43:05 +08:00
|
|
|
|
auto p = Vec2(AXRANDOM_0_1() * s.width, AXRANDOM_0_1() * s.height);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
label->setPosition(p);
|
2013-08-13 04:29:54 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
|
std::string LabelFNTHundredLabels::title() const
|
2013-08-13 04:29:54 +08:00
|
|
|
|
{
|
2015-08-25 17:50:47 +08:00
|
|
|
|
return "New Label + Bitmap font";
|
2013-08-13 04:29:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
|
std::string LabelFNTHundredLabels::subtitle() const
|
2013-08-13 04:29:54 +08:00
|
|
|
|
{
|
|
|
|
|
return "Creating several Labels using the same FNT file; should be fast";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LabelFNTMultiLine::LabelFNTMultiLine()
|
|
|
|
|
{
|
|
|
|
|
Size s;
|
|
|
|
|
|
|
|
|
|
// Left
|
2014-01-11 22:33:07 +08:00
|
|
|
|
auto label1 = Label::createWithBMFont("fonts/bitmapFontTest3.fnt", " Multi line\nLeft");
|
2021-12-28 16:06:23 +08:00
|
|
|
|
label1->setAnchorPoint(Vec2(0, 0));
|
2013-08-13 04:29:54 +08:00
|
|
|
|
addChild(label1, 0, kTagBitmapAtlas1);
|
|
|
|
|
|
|
|
|
|
s = label1->getContentSize();
|
2022-07-16 10:43:05 +08:00
|
|
|
|
AXLOG("content size: %.2fx%.2f", s.width, s.height);
|
2013-08-13 04:29:54 +08:00
|
|
|
|
|
|
|
|
|
// Center
|
2021-12-28 16:06:23 +08:00
|
|
|
|
auto label2 = Label::createWithBMFont("fonts/bitmapFontTest3.fnt", "Multi line\nCenter");
|
2013-08-13 04:29:54 +08:00
|
|
|
|
addChild(label2, 0, kTagBitmapAtlas2);
|
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
|
s = label2->getContentSize();
|
2022-07-16 10:43:05 +08:00
|
|
|
|
AXLOG("content size: %.2fx%.2f", s.width, s.height);
|
2013-08-13 04:29:54 +08:00
|
|
|
|
|
|
|
|
|
// right
|
2014-01-11 22:33:07 +08:00
|
|
|
|
auto label3 = Label::createWithBMFont("fonts/bitmapFontTest3.fnt", "Multi line\nRight\nThree lines Three");
|
2014-05-15 01:07:09 +08:00
|
|
|
|
label3->setAnchorPoint(Vec2(1, 1));
|
2013-08-13 04:29:54 +08:00
|
|
|
|
addChild(label3, 0, kTagBitmapAtlas3);
|
|
|
|
|
|
|
|
|
|
s = label3->getContentSize();
|
2022-07-16 10:43:05 +08:00
|
|
|
|
AXLOG("content size: %.2fx%.2f", s.width, s.height);
|
2013-08-13 04:29:54 +08:00
|
|
|
|
|
|
|
|
|
label1->setPosition(VisibleRect::leftBottom());
|
|
|
|
|
label2->setPosition(VisibleRect::center());
|
|
|
|
|
label3->setPosition(VisibleRect::rightTop());
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
|
std::string LabelFNTMultiLine::title() const
|
2013-08-13 04:29:54 +08:00
|
|
|
|
{
|
2015-08-25 17:50:47 +08:00
|
|
|
|
return "New Label + Bitmap font";
|
2013-08-13 04:29:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
|
std::string LabelFNTMultiLine::subtitle() const
|
2013-08-13 04:29:54 +08:00
|
|
|
|
{
|
|
|
|
|
return "Multiline + anchor point";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LabelFNTandTTFEmpty::LabelFNTandTTFEmpty()
|
|
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2013-08-13 04:29:54 +08:00
|
|
|
|
|
|
|
|
|
// LabelBMFont
|
2014-01-11 22:33:07 +08:00
|
|
|
|
auto label1 = Label::createWithBMFont("fonts/bitmapFontTest3.fnt", "", TextHAlignment::CENTER, s.width);
|
2013-08-13 04:29:54 +08:00
|
|
|
|
addChild(label1, 0, kTagBitmapAtlas1);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
label1->setPosition(Vec2(s.width / 2, s.height - 100));
|
2013-08-13 04:29:54 +08:00
|
|
|
|
|
|
|
|
|
// LabelTTF
|
2021-12-28 16:06:23 +08:00
|
|
|
|
TTFConfig ttfConfig("fonts/arial.ttf", 24);
|
|
|
|
|
auto label2 = Label::createWithTTF(ttfConfig, "", TextHAlignment::CENTER, s.width);
|
2013-08-13 04:29:54 +08:00
|
|
|
|
addChild(label2, 0, kTagBitmapAtlas2);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
label2->setPosition(Vec2(s.width / 2, s.height / 2));
|
|
|
|
|
|
2015-06-11 17:16:44 +08:00
|
|
|
|
auto label3 = Label::createWithCharMap("fonts/tuffy_bold_italic-charmap.plist");
|
2014-01-24 15:02:42 +08:00
|
|
|
|
addChild(label3, 0, kTagBitmapAtlas3);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
label3->setPosition(Vec2(s.width / 2, 100.0f));
|
2013-08-13 04:29:54 +08:00
|
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
|
schedule(AX_CALLBACK_1(LabelFNTandTTFEmpty::updateStrings, this), 1.0f, "update_strings_key");
|
2013-08-13 04:29:54 +08:00
|
|
|
|
|
|
|
|
|
setEmpty = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void LabelFNTandTTFEmpty::updateStrings(float dt)
|
|
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
|
auto label1 = static_cast<Label*>(getChildByTag(kTagBitmapAtlas1));
|
|
|
|
|
auto label2 = static_cast<Label*>(getChildByTag(kTagBitmapAtlas2));
|
|
|
|
|
auto label3 = static_cast<Label*>(getChildByTag(kTagBitmapAtlas3));
|
2013-08-13 04:29:54 +08:00
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
|
if (!setEmpty)
|
2013-08-13 04:29:54 +08:00
|
|
|
|
{
|
|
|
|
|
label1->setString("not empty");
|
|
|
|
|
label2->setString("not empty");
|
2014-01-24 15:02:42 +08:00
|
|
|
|
label3->setString("hi");
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
2013-08-13 04:29:54 +08:00
|
|
|
|
setEmpty = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
label1->setString("");
|
|
|
|
|
label2->setString("");
|
2014-01-24 15:02:42 +08:00
|
|
|
|
label3->setString("");
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
2013-08-13 04:29:54 +08:00
|
|
|
|
setEmpty = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
|
std::string LabelFNTandTTFEmpty::title() const
|
2013-08-13 04:29:54 +08:00
|
|
|
|
{
|
2015-08-25 17:50:47 +08:00
|
|
|
|
return "New Label + FNT/TTF/CharMap";
|
2013-08-13 04:29:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
|
std::string LabelFNTandTTFEmpty::subtitle() const
|
2013-08-13 04:29:54 +08:00
|
|
|
|
{
|
2015-08-25 17:50:47 +08:00
|
|
|
|
return "Testing empty string.";
|
2013-08-13 04:29:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LabelFNTRetina::LabelFNTRetina()
|
|
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2013-08-13 04:29:54 +08:00
|
|
|
|
|
|
|
|
|
// LabelBMFont
|
2014-01-11 22:33:07 +08:00
|
|
|
|
auto label1 = Label::createWithBMFont("fonts/konqa32.fnt", "TESTING RETINA DISPLAY");
|
2013-08-13 04:29:54 +08:00
|
|
|
|
addChild(label1);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
label1->setPosition(Vec2(s.width / 2, s.height / 2));
|
2013-08-13 04:29:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
|
std::string LabelFNTRetina::title() const
|
2013-08-13 04:29:54 +08:00
|
|
|
|
{
|
2015-08-25 17:50:47 +08:00
|
|
|
|
return "New Label + Bitmap font";
|
2013-08-13 04:29:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
|
std::string LabelFNTRetina::subtitle() const
|
2013-08-13 04:29:54 +08:00
|
|
|
|
{
|
|
|
|
|
return "loading arista16 or arista16-hd";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LabelFNTGlyphDesigner::LabelFNTGlyphDesigner()
|
|
|
|
|
{
|
2015-08-25 17:50:47 +08:00
|
|
|
|
auto winSize = Director::getInstance()->getWinSize();
|
2013-08-13 04:29:54 +08:00
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
|
auto layer = LayerColor::create(Color4B(128, 128, 128, 255));
|
2013-08-13 04:29:54 +08:00
|
|
|
|
addChild(layer, -10);
|
|
|
|
|
|
2014-01-11 22:33:07 +08:00
|
|
|
|
auto label1 = Label::createWithBMFont("fonts/futura-48.fnt", "Testing Glyph Designer");
|
2015-12-03 14:21:00 +08:00
|
|
|
|
// Demo for reloadFontAtlasFNT function, after it been called, all UI widget
|
|
|
|
|
// use the special font must reset font, because the old one is invalid.
|
|
|
|
|
FontAtlasCache::reloadFontAtlasFNT("fonts/futura-48.fnt");
|
|
|
|
|
label1->setBMFontFilePath("fonts/futura-48.fnt");
|
2013-08-13 04:29:54 +08:00
|
|
|
|
addChild(label1);
|
2015-08-25 17:50:47 +08:00
|
|
|
|
label1->setPosition(Vec2(winSize.width / 2, winSize.height * 0.4f));
|
|
|
|
|
|
|
|
|
|
auto label2 = Label::createWithBMFont("fonts/bitmapFontTest2.fnt", "Hello World");
|
|
|
|
|
label2->setPosition(Vec2(winSize.width / 2, winSize.height * 0.6f));
|
|
|
|
|
addChild(label2);
|
2013-08-13 04:29:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
|
std::string LabelFNTGlyphDesigner::title() const
|
2013-08-13 04:29:54 +08:00
|
|
|
|
{
|
2015-08-25 17:50:47 +08:00
|
|
|
|
return "New Label + Bitmap font";
|
2013-08-13 04:29:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
|
std::string LabelFNTGlyphDesigner::subtitle() const
|
2013-08-13 04:29:54 +08:00
|
|
|
|
{
|
2015-08-25 17:50:47 +08:00
|
|
|
|
return "Testing Glyph Designer";
|
2013-08-13 04:29:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// BitmapFontMultiLineAlignmentNew
|
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
|
#define LongSentencesExample \
|
|
|
|
|
"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore " \
|
|
|
|
|
"magna aliqua."
|
|
|
|
|
#define LineBreaksExample "Lorem ipsum dolor\nsit amet\nconsectetur adipisicing elit\nblah\nblah"
|
|
|
|
|
#define MixedExample \
|
|
|
|
|
"ABC\nLorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt\nDEF"
|
2013-08-13 04:29:54 +08:00
|
|
|
|
|
|
|
|
|
#define ArrowsMax 0.95
|
|
|
|
|
#define ArrowsMin 0.7
|
|
|
|
|
|
|
|
|
|
#define LeftAlign 0
|
|
|
|
|
#define CenterAlign 1
|
|
|
|
|
#define RightAlign 2
|
|
|
|
|
|
|
|
|
|
#define LongSentences 0
|
|
|
|
|
#define LineBreaks 1
|
|
|
|
|
#define Mixed 2
|
|
|
|
|
|
|
|
|
|
static float alignmentItemPadding = 50;
|
|
|
|
|
static float menuItemPaddingCenter = 50;
|
|
|
|
|
|
2018-01-10 17:01:19 +08:00
|
|
|
|
bool LabelFNTMultiLineAlignment::init()
|
2013-08-13 04:29:54 +08:00
|
|
|
|
{
|
2018-01-10 17:01:19 +08:00
|
|
|
|
if (!AtlasDemoNew::init())
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
|
auto listener = EventListenerTouchAllAtOnce::create();
|
2022-07-15 19:17:01 +08:00
|
|
|
|
listener->onTouchesBegan = AX_CALLBACK_2(LabelFNTMultiLineAlignment::onTouchesBegan, this);
|
|
|
|
|
listener->onTouchesMoved = AX_CALLBACK_2(LabelFNTMultiLineAlignment::onTouchesMoved, this);
|
|
|
|
|
listener->onTouchesEnded = AX_CALLBACK_2(LabelFNTMultiLineAlignment::onTouchesEnded, this);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
2013-10-26 15:04:01 +08:00
|
|
|
|
_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
|
2013-08-13 04:29:54 +08:00
|
|
|
|
// ask director the the window size
|
2013-08-16 16:05:27 +08:00
|
|
|
|
auto size = Director::getInstance()->getWinSize();
|
2013-08-13 04:29:54 +08:00
|
|
|
|
|
|
|
|
|
// create and initialize a Label
|
2021-12-28 16:06:23 +08:00
|
|
|
|
this->_label = Label::createWithBMFont("fonts/markerFelt.fnt", "", TextHAlignment::CENTER, size.width / 1.5);
|
2013-08-13 04:29:54 +08:00
|
|
|
|
|
2018-01-10 17:01:19 +08:00
|
|
|
|
this->_arrowsBar = Sprite::create("Images/arrowsBar.png");
|
2021-12-28 16:06:23 +08:00
|
|
|
|
this->_arrows = Sprite::create("Images/arrows.png");
|
2013-08-13 04:29:54 +08:00
|
|
|
|
|
|
|
|
|
MenuItemFont::setFontSize(20);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
auto longSentences =
|
2022-07-15 19:17:01 +08:00
|
|
|
|
MenuItemFont::create("Long Flowing Sentences", AX_CALLBACK_1(LabelFNTMultiLineAlignment::stringChanged, this));
|
2021-12-28 16:06:23 +08:00
|
|
|
|
auto lineBreaks = MenuItemFont::create("Short Sentences With Intentional Line Breaks",
|
2022-07-15 19:17:01 +08:00
|
|
|
|
AX_CALLBACK_1(LabelFNTMultiLineAlignment::stringChanged, this));
|
2021-12-28 16:06:23 +08:00
|
|
|
|
auto mixed = MenuItemFont::create("Long Sentences Mixed With Intentional Line Breaks",
|
2022-07-15 19:17:01 +08:00
|
|
|
|
AX_CALLBACK_1(LabelFNTMultiLineAlignment::stringChanged, this));
|
2021-12-28 16:06:23 +08:00
|
|
|
|
auto stringMenu = Menu::create(longSentences, lineBreaks, mixed, nullptr);
|
2013-08-13 04:29:54 +08:00
|
|
|
|
stringMenu->alignItemsVertically();
|
|
|
|
|
|
|
|
|
|
longSentences->setTag(LongSentences);
|
|
|
|
|
lineBreaks->setTag(LineBreaks);
|
|
|
|
|
mixed->setTag(Mixed);
|
|
|
|
|
|
2022-08-08 13:18:33 +08:00
|
|
|
|
_menuItems.emplace_back(longSentences);
|
|
|
|
|
_menuItems.emplace_back(lineBreaks);
|
|
|
|
|
_menuItems.emplace_back(mixed);
|
2018-01-10 17:01:19 +08:00
|
|
|
|
|
2013-08-13 04:29:54 +08:00
|
|
|
|
MenuItemFont::setFontSize(30);
|
|
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
|
auto left = MenuItemFont::create("Left", AX_CALLBACK_1(LabelFNTMultiLineAlignment::alignmentChanged, this));
|
|
|
|
|
auto center = MenuItemFont::create("Center", AX_CALLBACK_1(LabelFNTMultiLineAlignment::alignmentChanged, this));
|
|
|
|
|
auto right = MenuItemFont::create("Right", AX_CALLBACK_1(LabelFNTMultiLineAlignment::alignmentChanged, this));
|
2018-01-10 17:01:19 +08:00
|
|
|
|
|
2014-07-10 00:45:27 +08:00
|
|
|
|
auto alignmentMenu = Menu::create(left, center, right, nullptr);
|
2013-08-13 04:29:54 +08:00
|
|
|
|
alignmentMenu->alignItemsHorizontallyWithPadding(alignmentItemPadding);
|
|
|
|
|
|
|
|
|
|
left->setTag(LeftAlign);
|
|
|
|
|
center->setTag(CenterAlign);
|
|
|
|
|
right->setTag(RightAlign);
|
|
|
|
|
|
|
|
|
|
// position the label on the center of the screen
|
2021-12-28 16:06:23 +08:00
|
|
|
|
this->_label->setPosition(Vec2(size.width / 2, size.height / 2));
|
2013-08-13 04:29:54 +08:00
|
|
|
|
|
2018-01-10 17:01:19 +08:00
|
|
|
|
this->_arrowsBar->setVisible(false);
|
2013-08-13 04:29:54 +08:00
|
|
|
|
|
|
|
|
|
float arrowsWidth = (ArrowsMax - ArrowsMin) * size.width;
|
2018-01-10 17:01:19 +08:00
|
|
|
|
this->_arrowsBar->setScaleX(arrowsWidth / this->_arrowsBar->getContentSize().width);
|
|
|
|
|
this->_arrowsBar->setPosition(Vec2(((ArrowsMax + ArrowsMin) / 2) * size.width, this->_label->getPosition().y));
|
2013-08-13 04:29:54 +08:00
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
|
stringMenu->setPosition(Vec2(size.width / 2, size.height - menuItemPaddingCenter));
|
|
|
|
|
alignmentMenu->setPosition(Vec2(size.width / 2, menuItemPaddingCenter + 15));
|
2013-08-13 04:29:54 +08:00
|
|
|
|
|
2018-01-10 17:01:19 +08:00
|
|
|
|
this->selectSentenceItem(longSentences);
|
|
|
|
|
this->selectAlignmentItem(center);
|
|
|
|
|
this->snapArrowsToEdge();
|
|
|
|
|
|
|
|
|
|
this->addChild(this->_label);
|
|
|
|
|
this->addChild(this->_arrowsBar);
|
|
|
|
|
this->addChild(this->_arrows);
|
2013-08-13 04:29:54 +08:00
|
|
|
|
this->addChild(stringMenu);
|
|
|
|
|
this->addChild(alignmentMenu);
|
|
|
|
|
|
2018-01-10 17:01:19 +08:00
|
|
|
|
return true;
|
2013-08-13 04:29:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
|
std::string LabelFNTMultiLineAlignment::title() const
|
2013-08-13 04:29:54 +08:00
|
|
|
|
{
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
|
std::string LabelFNTMultiLineAlignment::subtitle() const
|
2013-08-13 04:29:54 +08:00
|
|
|
|
{
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-18 19:17:36 +08:00
|
|
|
|
void LabelFNTMultiLineAlignment::selectAlignmentItem(ax::MenuItemFont* item)
|
2013-08-13 04:29:54 +08:00
|
|
|
|
{
|
2018-01-10 17:01:19 +08:00
|
|
|
|
if (this->_lastAlignmentItem && this->_lastAlignmentItem != item)
|
|
|
|
|
{
|
|
|
|
|
this->_lastAlignmentItem->setColor(Color3B::WHITE);
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-13 04:29:54 +08:00
|
|
|
|
this->_lastAlignmentItem = item;
|
2018-01-10 17:01:19 +08:00
|
|
|
|
item->setColor(Color3B::RED);
|
2013-08-13 04:29:54 +08:00
|
|
|
|
|
2018-01-10 17:01:19 +08:00
|
|
|
|
switch (item->getTag())
|
2013-08-13 04:29:54 +08:00
|
|
|
|
{
|
2018-01-10 17:01:19 +08:00
|
|
|
|
case LeftAlign:
|
|
|
|
|
this->_label->setAlignment(TextHAlignment::LEFT);
|
2013-08-13 04:29:54 +08:00
|
|
|
|
break;
|
2018-01-10 17:01:19 +08:00
|
|
|
|
case CenterAlign:
|
|
|
|
|
this->_label->setAlignment(TextHAlignment::CENTER);
|
2013-08-13 04:29:54 +08:00
|
|
|
|
break;
|
2018-01-10 17:01:19 +08:00
|
|
|
|
case RightAlign:
|
|
|
|
|
this->_label->setAlignment(TextHAlignment::RIGHT);
|
2013-08-13 04:29:54 +08:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-18 19:17:36 +08:00
|
|
|
|
void LabelFNTMultiLineAlignment::selectSentenceItem(ax::MenuItemFont* item)
|
2013-08-13 04:29:54 +08:00
|
|
|
|
{
|
2018-01-10 17:01:19 +08:00
|
|
|
|
if (this->_lastSentenceItem && this->_lastSentenceItem != item)
|
|
|
|
|
{
|
|
|
|
|
this->_lastSentenceItem->setColor(Color3B::WHITE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this->_lastSentenceItem = item;
|
2013-08-13 04:29:54 +08:00
|
|
|
|
item->setColor(Color3B::RED);
|
|
|
|
|
|
2018-01-10 17:01:19 +08:00
|
|
|
|
auto str = this->getItemString(item);
|
|
|
|
|
this->_label->setString(str);
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-18 19:17:36 +08:00
|
|
|
|
std::string LabelFNTMultiLineAlignment::getItemString(ax::MenuItemFont* item)
|
2018-01-10 17:01:19 +08:00
|
|
|
|
{
|
|
|
|
|
std::string str;
|
|
|
|
|
|
|
|
|
|
switch (item->getTag())
|
2013-08-13 04:29:54 +08:00
|
|
|
|
{
|
2018-01-10 17:01:19 +08:00
|
|
|
|
case LongSentences:
|
|
|
|
|
str = LongSentencesExample;
|
2013-08-13 04:29:54 +08:00
|
|
|
|
break;
|
2018-01-10 17:01:19 +08:00
|
|
|
|
case LineBreaks:
|
|
|
|
|
str = LineBreaksExample;
|
2013-08-13 04:29:54 +08:00
|
|
|
|
break;
|
2018-01-10 17:01:19 +08:00
|
|
|
|
case Mixed:
|
|
|
|
|
str = MixedExample;
|
2013-08-13 04:29:54 +08:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-10 17:01:19 +08:00
|
|
|
|
return str;
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-18 19:17:36 +08:00
|
|
|
|
void LabelFNTMultiLineAlignment::stringChanged(ax::Ref* sender)
|
2018-01-10 17:01:19 +08:00
|
|
|
|
{
|
|
|
|
|
auto item = (MenuItemFont*)sender;
|
|
|
|
|
|
|
|
|
|
selectSentenceItem(item);
|
|
|
|
|
|
|
|
|
|
this->snapArrowsToEdge();
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-18 19:17:36 +08:00
|
|
|
|
void LabelFNTMultiLineAlignment::alignmentChanged(ax::Ref* sender)
|
2018-01-10 17:01:19 +08:00
|
|
|
|
{
|
|
|
|
|
auto item = static_cast<MenuItemFont*>(sender);
|
|
|
|
|
|
|
|
|
|
selectAlignmentItem(item);
|
|
|
|
|
|
2013-08-13 04:29:54 +08:00
|
|
|
|
this->snapArrowsToEdge();
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-18 19:17:36 +08:00
|
|
|
|
void LabelFNTMultiLineAlignment::onTouchesBegan(const std::vector<Touch*>& touches, ax::Event* event)
|
2013-08-13 04:29:54 +08:00
|
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
|
auto touch = touches[0];
|
2013-08-16 16:05:27 +08:00
|
|
|
|
auto location = touch->getLocationInView();
|
2013-08-13 04:29:54 +08:00
|
|
|
|
|
2018-01-10 17:01:19 +08:00
|
|
|
|
if (this->_arrows->getBoundingBox().containsPoint(location))
|
2013-08-13 04:29:54 +08:00
|
|
|
|
{
|
|
|
|
|
_drag = true;
|
2018-01-10 17:01:19 +08:00
|
|
|
|
this->_arrowsBar->setVisible(true);
|
2013-08-13 04:29:54 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-18 19:17:36 +08:00
|
|
|
|
void LabelFNTMultiLineAlignment::onTouchesEnded(const std::vector<Touch*>& touches, ax::Event* event)
|
2013-08-13 04:29:54 +08:00
|
|
|
|
{
|
|
|
|
|
_drag = false;
|
|
|
|
|
this->snapArrowsToEdge();
|
|
|
|
|
|
2018-01-10 17:01:19 +08:00
|
|
|
|
this->_arrowsBar->setVisible(false);
|
2013-08-13 04:29:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-10-18 19:17:36 +08:00
|
|
|
|
void LabelFNTMultiLineAlignment::onTouchesMoved(const std::vector<Touch*>& touches, ax::Event* event)
|
2013-08-13 04:29:54 +08:00
|
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
|
if (!_drag)
|
2013-08-13 04:29:54 +08:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
|
auto touch = touches[0];
|
2013-08-16 16:05:27 +08:00
|
|
|
|
auto location = touch->getLocationInView();
|
2013-08-13 04:29:54 +08:00
|
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
|
auto winSize = Director::getInstance()->getWinSize();
|
2013-08-13 04:29:54 +08:00
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
|
this->_arrows->setPosition(Vec2(MAX(MIN(location.x, ArrowsMax * winSize.width), ArrowsMin * winSize.width),
|
|
|
|
|
this->_arrows->getPosition().y));
|
2013-08-13 04:29:54 +08:00
|
|
|
|
|
2018-01-10 17:01:19 +08:00
|
|
|
|
float labelWidth = fabs(this->_arrows->getPosition().x - this->_label->getPosition().x) * 2;
|
2013-08-13 04:29:54 +08:00
|
|
|
|
|
2018-01-10 17:01:19 +08:00
|
|
|
|
this->_label->setMaxLineWidth(labelWidth);
|
2013-08-13 04:29:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void LabelFNTMultiLineAlignment::snapArrowsToEdge()
|
|
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
|
this->_arrows->setPosition(
|
|
|
|
|
Vec2(this->_label->getPosition().x + this->_label->getContentSize().width / 2, this->_label->getPosition().y));
|
2018-01-10 17:01:19 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// LabelFNTMultiLineAlignmentUNICODE
|
|
|
|
|
|
|
|
|
|
bool LabelFNTMultiLineAlignmentUNICODE::init()
|
|
|
|
|
{
|
|
|
|
|
if (!LabelFNTMultiLineAlignment::init())
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this->_menuItems[0]->setString("French");
|
|
|
|
|
this->_menuItems[1]->setString("Spanish");
|
|
|
|
|
this->_menuItems[2]->setString("Ukrainian");
|
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
|
auto ttfConfig = this->_label->getTTFConfig();
|
|
|
|
|
ttfConfig.fontSize = 20;
|
2018-01-10 17:01:19 +08:00
|
|
|
|
ttfConfig.fontFilePath = "fonts/tahoma.ttf";
|
|
|
|
|
this->_label->setTTFConfig(ttfConfig);
|
|
|
|
|
|
|
|
|
|
this->selectSentenceItem(this->_menuItems[0]);
|
|
|
|
|
this->snapArrowsToEdge();
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelFNTMultiLineAlignmentUNICODE::title() const
|
|
|
|
|
{
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelFNTMultiLineAlignmentUNICODE::subtitle() const
|
|
|
|
|
{
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-18 19:17:36 +08:00
|
|
|
|
std::string LabelFNTMultiLineAlignmentUNICODE::getItemString(ax::MenuItemFont* item)
|
2018-01-10 17:01:19 +08:00
|
|
|
|
{
|
|
|
|
|
std::string str;
|
|
|
|
|
|
|
|
|
|
auto strings = FileUtils::getInstance()->getValueMapFromFile("strings/LabelFNTMultiLineAlignmentUNICODE.xml");
|
|
|
|
|
|
|
|
|
|
switch (item->getTag())
|
|
|
|
|
{
|
|
|
|
|
case LongSentences:
|
|
|
|
|
str = strings["french"].asString();
|
|
|
|
|
break;
|
|
|
|
|
case LineBreaks:
|
|
|
|
|
str = strings["spanish"].asString();
|
|
|
|
|
break;
|
|
|
|
|
case Mixed:
|
|
|
|
|
str = strings["ukrainian"].asString();
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return str;
|
2013-08-13 04:29:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// BMFontUnicodeNew
|
|
|
|
|
LabelFNTUNICODELanguages::LabelFNTUNICODELanguages()
|
|
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
|
auto strings = FileUtils::getInstance()->getValueMapFromFile("strings/LabelFNTUNICODELanguages.xml");
|
2013-12-18 16:03:07 +08:00
|
|
|
|
std::string chinese = strings["chinese1"].asString();
|
|
|
|
|
std::string russian = strings["russian"].asString();
|
|
|
|
|
std::string spanish = strings["spanish"].asString();
|
|
|
|
|
std::string japanese = strings["japanese"].asString();
|
2013-08-13 04:29:54 +08:00
|
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2013-08-13 04:29:54 +08:00
|
|
|
|
|
2014-01-11 22:33:07 +08:00
|
|
|
|
auto label1 = Label::createWithBMFont("fonts/arial-unicode-26.fnt", spanish, TextHAlignment::CENTER, 200);
|
2013-08-13 04:29:54 +08:00
|
|
|
|
addChild(label1);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
label1->setPosition(Vec2(s.width / 2, s.height / 5 * 3));
|
|
|
|
|
|
2014-01-11 22:33:07 +08:00
|
|
|
|
auto label2 = Label::createWithBMFont("fonts/arial-unicode-26.fnt", chinese);
|
2013-08-13 04:29:54 +08:00
|
|
|
|
addChild(label2);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
label2->setPosition(Vec2(s.width / 2, s.height / 5 * 2.5));
|
2013-08-13 04:29:54 +08:00
|
|
|
|
|
2014-01-11 22:33:07 +08:00
|
|
|
|
auto label3 = Label::createWithBMFont("fonts/arial-26-en-ru.fnt", russian);
|
2013-08-13 04:29:54 +08:00
|
|
|
|
addChild(label3);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
label3->setPosition(Vec2(s.width / 2, s.height / 5 * 2));
|
2013-08-13 04:29:54 +08:00
|
|
|
|
|
2014-01-11 22:33:07 +08:00
|
|
|
|
auto label4 = Label::createWithBMFont("fonts/arial-unicode-26.fnt", japanese);
|
2013-08-13 04:29:54 +08:00
|
|
|
|
addChild(label4);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
label4->setPosition(Vec2(s.width / 2, s.height / 5 * 1.5));
|
2013-08-13 04:29:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
|
std::string LabelFNTUNICODELanguages::title() const
|
2013-08-13 04:29:54 +08:00
|
|
|
|
{
|
2015-08-25 17:50:47 +08:00
|
|
|
|
return "New Label + Bitmap font";
|
2013-08-13 04:29:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
|
std::string LabelFNTUNICODELanguages::subtitle() const
|
2013-08-13 04:29:54 +08:00
|
|
|
|
{
|
2015-08-25 17:50:47 +08:00
|
|
|
|
return "Testing Unicode.You should see 4 different labels:In Spanish, Chinese, Russian and Japanese";
|
2013-08-13 04:29:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LabelFNTBounds::LabelFNTBounds()
|
|
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
|
|
|
|
auto layer = LayerColor::create(Color4B(128, 128, 128, 255));
|
2013-08-13 04:29:54 +08:00
|
|
|
|
addChild(layer, -10);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
2013-08-13 04:29:54 +08:00
|
|
|
|
// LabelBMFont
|
2021-12-28 16:06:23 +08:00
|
|
|
|
auto label1 =
|
|
|
|
|
Label::createWithBMFont("fonts/boundsTestFont.fnt", "Testing Glyph Designer", TextHAlignment::CENTER, s.width);
|
2013-08-13 04:29:54 +08:00
|
|
|
|
addChild(label1);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
label1->setPosition(Vec2(s.width / 2, s.height / 2));
|
2013-12-26 16:11:06 +08:00
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
|
auto drawNode = DrawNode::create();
|
2013-08-16 16:05:27 +08:00
|
|
|
|
auto labelSize = label1->getContentSize();
|
|
|
|
|
auto origin = Director::getInstance()->getWinSize();
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
|
|
|
|
origin.width = origin.width / 2 - (labelSize.width / 2);
|
2013-08-13 04:29:54 +08:00
|
|
|
|
origin.height = origin.height / 2 - (labelSize.height / 2);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
|
|
|
|
Vec2 vertices[4] = {Vec2(origin.width, origin.height), Vec2(labelSize.width + origin.width, origin.height),
|
|
|
|
|
Vec2(labelSize.width + origin.width, labelSize.height + origin.height),
|
|
|
|
|
Vec2(origin.width, labelSize.height + origin.height)};
|
2019-09-24 11:31:35 +08:00
|
|
|
|
drawNode->drawPoly(vertices, 4, true, Color4F(1.0f, 1.0f, 1.0f, 1.0f));
|
2014-09-11 15:39:56 +08:00
|
|
|
|
addChild(drawNode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelFNTBounds::title() const
|
|
|
|
|
{
|
2015-08-25 17:50:47 +08:00
|
|
|
|
return "New Label + Bitmap font";
|
2014-09-11 15:39:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelFNTBounds::subtitle() const
|
|
|
|
|
{
|
2015-08-25 17:50:47 +08:00
|
|
|
|
return "Testing bounding-box";
|
2013-08-13 04:29:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-01-06 09:35:52 +08:00
|
|
|
|
LabelFNTMultiFontAtlasNoRotation::LabelFNTMultiFontAtlasNoRotation()
|
|
|
|
|
{
|
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
|
|
|
|
|
|
auto label1 = Label::createWithBMFont("fonts/helvetica-32.fnt", "This is Helvetica");
|
|
|
|
|
addChild(label1);
|
|
|
|
|
label1->setPosition(Vec2(s.width / 2, s.height / 3 * 2));
|
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
|
auto label2 = Label::createWithBMFont("fonts/geneva-32.fnt", "And this is Geneva", TextHAlignment::LEFT, 0,
|
|
|
|
|
Rect(0, 128, 0, 0), false);
|
2020-01-06 09:35:52 +08:00
|
|
|
|
addChild(label2);
|
|
|
|
|
label2->setPosition(Vec2(s.width / 2, s.height / 3 * 1));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelFNTMultiFontAtlasNoRotation::title() const
|
|
|
|
|
{
|
|
|
|
|
return "New Label + Multi-BM Font Atlas Test1";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelFNTMultiFontAtlasNoRotation::subtitle() const
|
|
|
|
|
{
|
|
|
|
|
return "Using 2 .fnt definitions that share the same texture atlas.";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LabelFNTMultiFontAtlasWithRotation::LabelFNTMultiFontAtlasWithRotation()
|
|
|
|
|
{
|
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
|
|
|
|
|
|
auto spriteCache = SpriteFrameCache::getInstance();
|
|
|
|
|
spriteCache->addSpriteFramesWithFile("fonts/bmfont-rotated-test.plist");
|
|
|
|
|
|
|
|
|
|
// Label BMFont
|
2021-12-28 16:06:23 +08:00
|
|
|
|
auto label1 = Label::createWithBMFont("fonts/helvetica-regular-32.fnt", "Helvetica with SubTextureKey",
|
|
|
|
|
TextHAlignment::CENTER, 0, "helvetica-regular-32.png");
|
2020-01-06 09:35:52 +08:00
|
|
|
|
label1->setPosition(Vec2(s.width / 2, s.height / 3 * 2));
|
|
|
|
|
this->addChild(label1);
|
|
|
|
|
|
|
|
|
|
const auto frame = spriteCache->getSpriteFrameByName("geneva-regular-32.png");
|
2021-12-28 16:06:23 +08:00
|
|
|
|
auto label2 = Label::createWithBMFont("fonts/geneva-regular-32.fnt", "Geneva with Rect and Rotated",
|
|
|
|
|
TextHAlignment::CENTER, 0, frame->getRectInPixels(), frame->isRotated());
|
2020-01-06 09:35:52 +08:00
|
|
|
|
label2->setPosition(Vec2(s.width / 2, s.height / 3 * 1));
|
|
|
|
|
this->addChild(label2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelFNTMultiFontAtlasWithRotation::title() const
|
|
|
|
|
{
|
|
|
|
|
return "New Label + Multi-BM Font Atlas Test2";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelFNTMultiFontAtlasWithRotation::subtitle() const
|
|
|
|
|
{
|
|
|
|
|
return "Using 2 .fnt definitions that share a PLIST texture atlas (rotated).";
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-13 04:29:54 +08:00
|
|
|
|
LabelTTFLongLineWrapping::LabelTTFLongLineWrapping()
|
|
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
|
auto size = Director::getInstance()->getWinSize();
|
2013-08-13 04:29:54 +08:00
|
|
|
|
|
|
|
|
|
// Long sentence
|
2014-03-11 18:26:25 +08:00
|
|
|
|
TTFConfig ttfConfig("fonts/arial.ttf", 14);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
auto label1 = Label::createWithTTF(ttfConfig, LongSentencesExample, TextHAlignment::CENTER, size.width);
|
|
|
|
|
label1->setPosition(Vec2(size.width / 2, size.height / 2));
|
2019-09-24 11:31:35 +08:00
|
|
|
|
label1->setAnchorPoint(Vec2(0.5f, 1.0f));
|
2013-08-13 04:29:54 +08:00
|
|
|
|
addChild(label1);
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
|
std::string LabelTTFLongLineWrapping::title() const
|
2013-08-13 04:29:54 +08:00
|
|
|
|
{
|
|
|
|
|
return "New Label + .TTF";
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
|
std::string LabelTTFLongLineWrapping::subtitle() const
|
2013-08-13 04:29:54 +08:00
|
|
|
|
{
|
2015-08-25 17:50:47 +08:00
|
|
|
|
return "Testing auto-wrapping";
|
2013-08-13 04:29:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LabelTTFColor::LabelTTFColor()
|
|
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
|
auto size = Director::getInstance()->getWinSize();
|
2013-08-13 04:29:54 +08:00
|
|
|
|
|
2014-03-11 18:26:25 +08:00
|
|
|
|
TTFConfig ttfConfig("fonts/arial.ttf", 18);
|
2013-08-13 04:29:54 +08:00
|
|
|
|
// Green
|
2021-12-28 16:06:23 +08:00
|
|
|
|
auto label1 = Label::createWithTTF(ttfConfig, "Green", TextHAlignment::CENTER, size.width);
|
|
|
|
|
label1->setPosition(size.width / 2, size.height * 0.5f);
|
|
|
|
|
label1->setTextColor(Color4B::GREEN);
|
2013-08-13 04:29:54 +08:00
|
|
|
|
addChild(label1);
|
|
|
|
|
|
|
|
|
|
// Red
|
2021-12-28 16:06:23 +08:00
|
|
|
|
auto label2 = Label::createWithTTF(ttfConfig, "Red", TextHAlignment::CENTER, size.width);
|
|
|
|
|
label2->setPosition(size.width / 2, size.height * 0.65f);
|
|
|
|
|
label2->setTextColor(Color4B::RED);
|
2013-08-13 04:29:54 +08:00
|
|
|
|
addChild(label2);
|
|
|
|
|
|
|
|
|
|
// Blue
|
2021-12-28 16:06:23 +08:00
|
|
|
|
auto label3 = Label::createWithTTF(ttfConfig, "Blue", TextHAlignment::CENTER, size.width);
|
|
|
|
|
label3->setPosition(size.width / 2, size.height * 0.35f);
|
|
|
|
|
label3->setTextColor(Color4B::BLUE);
|
2013-08-13 04:29:54 +08:00
|
|
|
|
addChild(label3);
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
|
std::string LabelTTFColor::title() const
|
2013-08-13 04:29:54 +08:00
|
|
|
|
{
|
|
|
|
|
return "New Label + .TTF";
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
|
std::string LabelTTFColor::subtitle() const
|
2013-08-13 04:29:54 +08:00
|
|
|
|
{
|
2015-08-25 17:50:47 +08:00
|
|
|
|
return "Testing Color";
|
2013-08-13 04:29:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LabelTTFDynamicAlignment::LabelTTFDynamicAlignment()
|
|
|
|
|
{
|
2015-08-25 17:50:47 +08:00
|
|
|
|
auto winSize = Director::getInstance()->getWinSize();
|
|
|
|
|
|
2014-03-11 18:26:25 +08:00
|
|
|
|
TTFConfig ttfConfig("fonts/arial.ttf", 23);
|
2015-08-25 17:50:47 +08:00
|
|
|
|
_label = Label::createWithTTF(ttfConfig, LongSentencesExample, TextHAlignment::CENTER, winSize.width);
|
|
|
|
|
_label->setPosition(winSize.width / 2, winSize.height / 2);
|
|
|
|
|
addChild(_label);
|
|
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
|
auto menu = Menu::create(
|
2022-07-15 19:17:01 +08:00
|
|
|
|
MenuItemFont::create("Left", AX_CALLBACK_1(LabelTTFDynamicAlignment::setAlignmentLeft, this)),
|
|
|
|
|
MenuItemFont::create("Center", AX_CALLBACK_1(LabelTTFDynamicAlignment::setAlignmentCenter, this)),
|
|
|
|
|
MenuItemFont::create("Right", AX_CALLBACK_1(LabelTTFDynamicAlignment::setAlignmentRight, this)), nullptr);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
2015-08-25 17:50:47 +08:00
|
|
|
|
menu->alignItemsHorizontallyWithPadding(20);
|
|
|
|
|
menu->setPosition(winSize.width / 2, winSize.height * 0.25f);
|
|
|
|
|
addChild(menu);
|
2013-08-13 04:29:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
|
void LabelTTFDynamicAlignment::updateAlignment()
|
2013-08-13 04:29:54 +08:00
|
|
|
|
{
|
|
|
|
|
if (_label)
|
|
|
|
|
{
|
|
|
|
|
_label->setAlignment(_horizAlign);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
|
void LabelTTFDynamicAlignment::setAlignmentLeft(Ref* sender)
|
2013-08-13 04:29:54 +08:00
|
|
|
|
{
|
|
|
|
|
_horizAlign = TextHAlignment::LEFT;
|
|
|
|
|
this->updateAlignment();
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
|
void LabelTTFDynamicAlignment::setAlignmentCenter(Ref* sender)
|
2013-08-13 04:29:54 +08:00
|
|
|
|
{
|
|
|
|
|
_horizAlign = TextHAlignment::CENTER;
|
|
|
|
|
this->updateAlignment();
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
|
void LabelTTFDynamicAlignment::setAlignmentRight(Ref* sender)
|
2013-08-13 04:29:54 +08:00
|
|
|
|
{
|
|
|
|
|
_horizAlign = TextHAlignment::RIGHT;
|
|
|
|
|
this->updateAlignment();
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
|
std::string LabelTTFDynamicAlignment::title() const
|
2013-08-13 04:29:54 +08:00
|
|
|
|
{
|
|
|
|
|
return "New Label + .TTF";
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
|
std::string LabelTTFDynamicAlignment::subtitle() const
|
2013-08-13 04:29:54 +08:00
|
|
|
|
{
|
2015-08-25 17:50:47 +08:00
|
|
|
|
return "Testing text alignment";
|
2013-08-13 04:29:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
2014-02-08 17:15:57 +08:00
|
|
|
|
//
|
|
|
|
|
// NewLabelTTF Chinese/Japanese/Korean wrapping test
|
|
|
|
|
//
|
|
|
|
|
LabelTTFCJKWrappingTest::LabelTTFCJKWrappingTest()
|
|
|
|
|
{
|
|
|
|
|
auto size = Director::getInstance()->getWinSize();
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
2014-02-08 17:15:57 +08:00
|
|
|
|
auto drawNode = DrawNode::create();
|
2014-05-15 01:07:09 +08:00
|
|
|
|
drawNode->setAnchorPoint(Vec2(0, 0));
|
2014-02-08 17:15:57 +08:00
|
|
|
|
this->addChild(drawNode);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
drawNode->drawSegment(Vec2(size.width * 0.1f, size.height * 0.8f), Vec2(size.width * 0.1, 0.0f), 1,
|
|
|
|
|
Color4F(1.0f, 0.0f, 0.0f, 1.0f));
|
|
|
|
|
drawNode->drawSegment(Vec2(size.width * 0.85f, size.height * 0.8f), Vec2(size.width * 0.85f, 0.0f), 1,
|
|
|
|
|
Color4F(1.0f, 0.0f, 0.0f, 1.0f));
|
|
|
|
|
|
2014-06-09 13:41:32 +08:00
|
|
|
|
TTFConfig ttfConfig("fonts/HKYuanMini.ttf", 25, GlyphCollection::DYNAMIC);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
auto label1 =
|
|
|
|
|
Label::createWithTTF(ttfConfig, "你好,Cocos2d-x v3的New Label.", TextHAlignment::LEFT, size.width * 0.75f);
|
|
|
|
|
if (label1)
|
|
|
|
|
{
|
2014-05-16 08:22:53 +08:00
|
|
|
|
label1->setTextColor(Color4B(128, 255, 255, 255));
|
2019-09-24 11:31:35 +08:00
|
|
|
|
label1->setPosition(Vec2(size.width * 0.1f, size.height * 0.6f));
|
|
|
|
|
label1->setAnchorPoint(Vec2(0.0f, 0.5f));
|
2014-05-16 08:22:53 +08:00
|
|
|
|
this->addChild(label1);
|
2015-12-03 14:21:00 +08:00
|
|
|
|
// Demo for unloadFontAtlasTTF function, after it been called, all UI widget
|
|
|
|
|
// use the special font must reset font, because the old one is invalid.
|
|
|
|
|
FontAtlasCache::unloadFontAtlasTTF("fonts/HKYuanMini.ttf");
|
|
|
|
|
label1->setTTFConfig(ttfConfig);
|
2014-05-16 08:22:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
|
auto label2 =
|
|
|
|
|
Label::createWithTTF(ttfConfig, "早上好,Cocos2d-x v3的New Label.", TextHAlignment::LEFT, size.width * 0.75f);
|
|
|
|
|
if (label2)
|
|
|
|
|
{
|
2014-05-16 08:22:53 +08:00
|
|
|
|
label2->setTextColor(Color4B(255, 128, 255, 255));
|
2019-09-24 11:31:35 +08:00
|
|
|
|
label2->setPosition(Vec2(size.width * 0.1f, size.height * 0.4f));
|
|
|
|
|
label2->setAnchorPoint(Vec2(0.0f, 0.5f));
|
2014-05-16 08:22:53 +08:00
|
|
|
|
this->addChild(label2);
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
|
auto label3 = Label::createWithTTF(ttfConfig, "美好的一天啊美好的一天啊美好的一天啊", TextHAlignment::LEFT,
|
|
|
|
|
size.width * 0.75f);
|
|
|
|
|
if (label3)
|
|
|
|
|
{
|
2014-05-16 08:22:53 +08:00
|
|
|
|
label3->setTextColor(Color4B(255, 255, 128, 255));
|
2019-09-24 11:31:35 +08:00
|
|
|
|
label3->setPosition(Vec2(size.width * 0.1f, size.height * 0.2f));
|
|
|
|
|
label3->setAnchorPoint(Vec2(0.0f, 0.5f));
|
2014-05-16 08:22:53 +08:00
|
|
|
|
this->addChild(label3);
|
|
|
|
|
}
|
2014-02-08 17:15:57 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelTTFCJKWrappingTest::title() const
|
|
|
|
|
{
|
|
|
|
|
return "New Label + .TTF";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelTTFCJKWrappingTest::subtitle() const
|
|
|
|
|
{
|
|
|
|
|
return "New Label with CJK + ASCII characters\n"
|
2021-12-28 16:06:23 +08:00
|
|
|
|
"Characters should stay in the correct position";
|
2014-02-08 17:15:57 +08:00
|
|
|
|
}
|
|
|
|
|
|
2013-08-13 04:29:54 +08:00
|
|
|
|
//
|
|
|
|
|
// NewLabelTTF unicode test
|
|
|
|
|
//
|
|
|
|
|
LabelTTFUnicodeNew::LabelTTFUnicodeNew()
|
|
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
|
auto strings = FileUtils::getInstance()->getValueMapFromFile("strings/LabelFNTUNICODELanguages.xml");
|
|
|
|
|
std::string chinese = strings["chinese1"].asString();
|
|
|
|
|
auto winSize = Director::getInstance()->getWinSize();
|
2015-08-25 17:50:47 +08:00
|
|
|
|
|
2013-08-13 04:29:54 +08:00
|
|
|
|
// Spanish
|
2015-08-25 17:50:47 +08:00
|
|
|
|
auto label1 = Label::createWithTTF("Buen día, ¿cómo te llamas?", "fonts/arial.ttf", 23);
|
|
|
|
|
label1->setPosition(winSize.width / 2, winSize.height * 0.65f);
|
2013-08-13 04:29:54 +08:00
|
|
|
|
addChild(label1);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
2013-08-13 04:29:54 +08:00
|
|
|
|
// German
|
2015-08-25 17:50:47 +08:00
|
|
|
|
auto label2 = Label::createWithTTF("In welcher Straße haben Sie gelebt?", "fonts/arial.ttf", 23);
|
|
|
|
|
label2->setPosition(winSize.width / 2, winSize.height * 0.5f);
|
2013-08-13 04:29:54 +08:00
|
|
|
|
addChild(label2);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
2015-08-25 17:50:47 +08:00
|
|
|
|
// Chinese
|
|
|
|
|
auto label3 = Label::createWithTTF(chinese, "fonts/HKYuanMini.ttf", 24);
|
|
|
|
|
label3->setPosition(winSize.width / 2, winSize.height * 0.35f);
|
|
|
|
|
addChild(label3);
|
2013-08-13 04:29:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
|
std::string LabelTTFUnicodeNew::title() const
|
2013-08-13 04:29:54 +08:00
|
|
|
|
{
|
|
|
|
|
return "New Label + TTF unicode";
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
|
std::string LabelTTFUnicodeNew::subtitle() const
|
2013-08-13 04:29:54 +08:00
|
|
|
|
{
|
|
|
|
|
return "Uses the new Label with TTF. Testing unicode";
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-06 16:41:52 +08:00
|
|
|
|
//
|
|
|
|
|
// LabelTTFEmoji emoji test
|
|
|
|
|
//
|
|
|
|
|
LabelTTFEmoji::LabelTTFEmoji()
|
|
|
|
|
{
|
|
|
|
|
std::string emojiString = FileUtils::getInstance()->getStringFromFile("fonts/emoji.txt");
|
2021-12-28 16:06:23 +08:00
|
|
|
|
auto winSize = Director::getInstance()->getWinSize();
|
|
|
|
|
|
2017-02-06 16:41:52 +08:00
|
|
|
|
auto label = Label::createWithTTF(emojiString, "fonts/NotoEmoji-Regular.ttf", 23);
|
|
|
|
|
label->setPosition(winSize.width / 2, winSize.height / 2);
|
|
|
|
|
label->setDimensions(winSize.width, winSize.height);
|
2022-10-18 19:17:36 +08:00
|
|
|
|
label->setVerticalAlignment(ax::TextVAlignment::CENTER);
|
|
|
|
|
label->setHorizontalAlignment(ax::TextHAlignment::CENTER);
|
2017-02-06 16:41:52 +08:00
|
|
|
|
addChild(label);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelTTFEmoji::title() const
|
|
|
|
|
{
|
|
|
|
|
return "New Label + Emoji";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelTTFEmoji::subtitle() const
|
|
|
|
|
{
|
|
|
|
|
return "Uses the new Label with TTF. Testing Emoji";
|
|
|
|
|
}
|
|
|
|
|
|
2013-08-13 04:29:54 +08:00
|
|
|
|
LabelTTFFontsTestNew::LabelTTFFontsTestNew()
|
|
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
|
const char* ttfpaths[] = {
|
|
|
|
|
"fonts/A Damn Mess.ttf", "fonts/Abberancy.ttf", "fonts/Abduction.ttf", "fonts/American Typewriter.ttf",
|
|
|
|
|
"fonts/Paint Boy.ttf", "fonts/Schwarzwald.ttf", "fonts/Scissor Cuts.ttf",
|
2013-08-13 04:29:54 +08:00
|
|
|
|
};
|
|
|
|
|
|
2015-08-25 17:50:47 +08:00
|
|
|
|
int fontCount = sizeof(ttfpaths) / sizeof(ttfpaths[0]);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
auto size = Director::getInstance()->getWinSize();
|
|
|
|
|
TTFConfig ttfConfig(ttfpaths[0], 20, GlyphCollection::NEHE);
|
2015-08-25 17:50:47 +08:00
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
|
for (int i = 0; i < fontCount; ++i)
|
|
|
|
|
{
|
2014-01-11 22:33:07 +08:00
|
|
|
|
ttfConfig.fontFilePath = ttfpaths[i];
|
2021-12-28 16:06:23 +08:00
|
|
|
|
auto label = Label::createWithTTF(ttfConfig, ttfpaths[i], TextHAlignment::CENTER, 0);
|
|
|
|
|
if (label)
|
|
|
|
|
{
|
2015-08-25 17:50:47 +08:00
|
|
|
|
label->setPosition(size.width / 2, ((size.height * 0.6) / fontCount * i) + (size.height / 4));
|
2013-08-13 04:29:54 +08:00
|
|
|
|
addChild(label);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2013-08-13 04:29:54 +08:00
|
|
|
|
log("ERROR: Cannot load: %s", ttfpaths[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
|
std::string LabelTTFFontsTestNew::title() const
|
2013-08-13 04:29:54 +08:00
|
|
|
|
{
|
|
|
|
|
return "New Label + TTF";
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
|
std::string LabelTTFFontsTestNew::subtitle() const
|
2013-08-13 04:29:54 +08:00
|
|
|
|
{
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-13 12:42:15 +08:00
|
|
|
|
LabelTTFDistanceField::LabelTTFDistanceField()
|
|
|
|
|
{
|
|
|
|
|
auto size = Director::getInstance()->getWinSize();
|
2021-12-28 16:06:23 +08:00
|
|
|
|
TTFConfig ttfConfig("fonts/arial.ttf", 40, GlyphCollection::DYNAMIC, nullptr, true);
|
2013-12-13 12:42:15 +08:00
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
|
auto label1 = Label::createWithTTF(ttfConfig, "Distance Field", TextHAlignment::CENTER, size.width);
|
|
|
|
|
label1->setPosition(Vec2(size.width / 2, size.height * 0.6f));
|
|
|
|
|
label1->setTextColor(Color4B::GREEN);
|
2013-12-13 12:42:15 +08:00
|
|
|
|
addChild(label1);
|
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
|
auto action = Sequence::create(DelayTime::create(1.0f), ScaleTo::create(6.0f, 5.0f, 5.0f),
|
|
|
|
|
ScaleTo::create(6.0f, 1.0f, 1.0f), nullptr);
|
2013-12-13 12:42:15 +08:00
|
|
|
|
label1->runAction(RepeatForever::create(action));
|
|
|
|
|
|
2016-10-14 17:14:15 +08:00
|
|
|
|
// Draw the label border
|
|
|
|
|
auto& labelContentSize = label1->getContentSize();
|
2021-12-28 16:06:23 +08:00
|
|
|
|
auto borderDraw = DrawNode::create();
|
2016-10-14 17:14:15 +08:00
|
|
|
|
label1->addChild(borderDraw);
|
|
|
|
|
borderDraw->clear();
|
|
|
|
|
borderDraw->setLineWidth(1);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
Vec2 vertices[4] = {Vec2::ZERO, Vec2(labelContentSize.width, 0.0f),
|
|
|
|
|
Vec2(labelContentSize.width, labelContentSize.height), Vec2(0.0f, labelContentSize.height)};
|
2016-10-14 17:14:15 +08:00
|
|
|
|
borderDraw->drawPoly(vertices, 4, true, Color4F::RED);
|
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
|
auto label2 = Label::createWithTTF(ttfConfig, "Distance Field", TextHAlignment::CENTER, size.width);
|
|
|
|
|
label2->setPosition(Vec2(size.width / 2, size.height * 0.3f));
|
|
|
|
|
label2->setTextColor(Color4B::RED);
|
2013-12-13 12:42:15 +08:00
|
|
|
|
addChild(label2);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
2016-10-14 17:14:15 +08:00
|
|
|
|
// Draw the label border
|
|
|
|
|
auto& labelContentSize2 = label2->getContentSize();
|
2021-12-28 16:06:23 +08:00
|
|
|
|
auto borderDraw2 = DrawNode::create();
|
2016-10-14 17:14:15 +08:00
|
|
|
|
label2->addChild(borderDraw2);
|
|
|
|
|
borderDraw2->clear();
|
|
|
|
|
borderDraw2->setLineWidth(1);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
Vec2 vertices2[4] = {Vec2::ZERO, Vec2(labelContentSize2.width, 0.0f),
|
|
|
|
|
Vec2(labelContentSize2.width, labelContentSize2.height), Vec2(0.0f, labelContentSize2.height)};
|
2016-10-14 17:14:15 +08:00
|
|
|
|
borderDraw2->drawPoly(vertices2, 4, true, Color4F::GREEN);
|
2013-12-13 12:42:15 +08:00
|
|
|
|
}
|
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
|
std::string LabelTTFDistanceField::title() const
|
2013-12-13 12:42:15 +08:00
|
|
|
|
{
|
|
|
|
|
return "New Label + .TTF";
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
|
std::string LabelTTFDistanceField::subtitle() const
|
2013-12-13 12:42:15 +08:00
|
|
|
|
{
|
|
|
|
|
return "Testing rendering base on DistanceField";
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-05 15:54:40 +08:00
|
|
|
|
LabelOutlineAndGlowTest::LabelOutlineAndGlowTest()
|
2013-12-13 12:42:15 +08:00
|
|
|
|
{
|
|
|
|
|
auto size = Director::getInstance()->getWinSize();
|
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
|
auto bg = LayerColor::create(Color4B(200, 191, 231, 255));
|
2013-12-13 12:42:15 +08:00
|
|
|
|
this->addChild(bg);
|
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
|
TTFConfig ttfConfig("fonts/arial.ttf", 40, GlyphCollection::DYNAMIC, nullptr, true);
|
2014-01-11 22:33:07 +08:00
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
|
auto label1 = Label::createWithTTF(ttfConfig, "Glow", TextHAlignment::CENTER, size.width);
|
|
|
|
|
label1->setPosition(Vec2(size.width / 2, size.height * 0.7));
|
|
|
|
|
label1->setTextColor(Color4B::GREEN);
|
2014-03-20 20:56:10 +08:00
|
|
|
|
label1->enableGlow(Color4B::YELLOW);
|
2013-12-13 12:42:15 +08:00
|
|
|
|
addChild(label1);
|
|
|
|
|
|
2014-03-05 15:54:40 +08:00
|
|
|
|
ttfConfig.outlineSize = 1;
|
2021-12-28 16:06:23 +08:00
|
|
|
|
auto label2 = Label::createWithTTF(ttfConfig, "Outline", TextHAlignment::CENTER, size.width);
|
|
|
|
|
label2->setPosition(Vec2(size.width / 2, size.height * 0.6));
|
|
|
|
|
label2->setTextColor(Color4B::RED);
|
2014-03-05 15:54:40 +08:00
|
|
|
|
label2->enableOutline(Color4B::BLUE);
|
2013-12-13 12:42:15 +08:00
|
|
|
|
addChild(label2);
|
|
|
|
|
|
2014-03-05 15:54:40 +08:00
|
|
|
|
ttfConfig.outlineSize = 2;
|
2021-12-28 16:06:23 +08:00
|
|
|
|
auto label3 = Label::createWithTTF(ttfConfig, "Outline", TextHAlignment::CENTER, size.width);
|
|
|
|
|
label3->setPosition(Vec2(size.width / 2, size.height * 0.48));
|
|
|
|
|
label3->setTextColor(Color4B::RED);
|
2014-03-05 15:54:40 +08:00
|
|
|
|
label3->enableOutline(Color4B::BLUE);
|
2013-12-13 12:42:15 +08:00
|
|
|
|
addChild(label3);
|
|
|
|
|
|
2014-03-05 15:54:40 +08:00
|
|
|
|
ttfConfig.outlineSize = 3;
|
2021-12-28 16:06:23 +08:00
|
|
|
|
auto label4 = Label::createWithTTF(ttfConfig, "Outline", TextHAlignment::CENTER, size.width);
|
|
|
|
|
label4->setPosition(Vec2(size.width / 2, size.height * 0.36));
|
|
|
|
|
label4->setTextColor(Color4B::RED);
|
2014-03-05 15:54:40 +08:00
|
|
|
|
label4->enableOutline(Color4B::BLUE);
|
|
|
|
|
addChild(label4);
|
2013-12-13 12:42:15 +08:00
|
|
|
|
}
|
|
|
|
|
|
2014-03-05 15:54:40 +08:00
|
|
|
|
std::string LabelOutlineAndGlowTest::title() const
|
2013-12-13 12:42:15 +08:00
|
|
|
|
{
|
2015-08-25 17:50:47 +08:00
|
|
|
|
return "New Label + .TTF";
|
2014-03-05 15:54:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelOutlineAndGlowTest::subtitle() const
|
|
|
|
|
{
|
|
|
|
|
return "Testing outline and glow of label";
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
|
LabelShadowTest::LabelShadowTest() {}
|
2014-03-05 15:54:40 +08:00
|
|
|
|
|
2016-12-16 14:56:36 +08:00
|
|
|
|
void LabelShadowTest::onEnter()
|
|
|
|
|
{
|
|
|
|
|
AtlasDemoNew::onEnter();
|
2014-03-05 15:54:40 +08:00
|
|
|
|
|
2016-12-16 14:56:36 +08:00
|
|
|
|
auto size = Director::getInstance()->getWinSize();
|
2014-04-01 14:15:35 +08:00
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
|
auto bg = LayerColor::create(Color4B(200, 191, 231, 255));
|
2016-12-16 14:56:36 +08:00
|
|
|
|
this->addChild(bg);
|
2014-03-05 15:54:40 +08:00
|
|
|
|
|
|
|
|
|
auto slider = ui::Slider::create();
|
|
|
|
|
slider->setTag(1);
|
|
|
|
|
slider->setTouchEnabled(true);
|
2014-03-11 17:13:54 +08:00
|
|
|
|
slider->loadBarTexture("cocosui/sliderTrack.png");
|
|
|
|
|
slider->loadSlidBallTextures("cocosui/sliderThumb.png", "cocosui/sliderThumb.png", "");
|
|
|
|
|
slider->loadProgressBarTexture("cocosui/sliderProgress.png");
|
2014-06-20 11:18:53 +08:00
|
|
|
|
slider->setPosition(Vec2(size.width / 2.0f, size.height * 0.15f + slider->getContentSize().height * 2.0f));
|
2014-03-05 15:54:40 +08:00
|
|
|
|
slider->setPercent(52);
|
2022-07-15 19:17:01 +08:00
|
|
|
|
slider->addEventListener(AX_CALLBACK_2(LabelShadowTest::sliderEvent, this));
|
2016-12-16 14:56:36 +08:00
|
|
|
|
addChild(slider, 999);
|
2014-03-05 15:54:40 +08:00
|
|
|
|
|
|
|
|
|
auto slider2 = ui::Slider::create();
|
|
|
|
|
slider2->setTag(2);
|
|
|
|
|
slider2->setTouchEnabled(true);
|
2014-03-11 17:13:54 +08:00
|
|
|
|
slider2->loadBarTexture("cocosui/sliderTrack.png");
|
|
|
|
|
slider2->loadSlidBallTextures("cocosui/sliderThumb.png", "cocosui/sliderThumb.png", "");
|
|
|
|
|
slider2->loadProgressBarTexture("cocosui/sliderProgress.png");
|
2019-09-24 11:31:35 +08:00
|
|
|
|
slider2->setPosition(Vec2(size.width * 0.15f, size.height / 2.0f));
|
2014-03-05 15:54:40 +08:00
|
|
|
|
slider2->setRotation(90);
|
|
|
|
|
slider2->setPercent(52);
|
2022-07-15 19:17:01 +08:00
|
|
|
|
slider2->addEventListener(AX_CALLBACK_2(LabelShadowTest::sliderEvent, this));
|
2016-12-16 14:56:36 +08:00
|
|
|
|
addChild(slider2, 999);
|
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
|
float subtitleY = _subtitleLabel->getPosition().y;
|
2016-12-16 14:56:36 +08:00
|
|
|
|
float horizontalSliderY = slider->getPosition().y;
|
2021-12-28 16:06:23 +08:00
|
|
|
|
float step = (subtitleY - horizontalSliderY) / 4;
|
2016-12-16 14:56:36 +08:00
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
|
TTFConfig ttfConfig("fonts/arial.ttf", 40, GlyphCollection::DYNAMIC, nullptr, true);
|
2016-12-16 14:56:36 +08:00
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
|
shadowLabelTTF = Label::createWithTTF(ttfConfig, "TTF:Shadow");
|
|
|
|
|
shadowLabelTTF->setPosition(Vec2(size.width / 2, horizontalSliderY + step * (0.5f + 3)));
|
|
|
|
|
shadowLabelTTF->setTextColor(Color4B::RED);
|
2016-12-16 14:56:36 +08:00
|
|
|
|
shadowLabelTTF->enableShadow(Color4B::BLACK);
|
|
|
|
|
addChild(shadowLabelTTF);
|
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
|
shadowLabelOutline = Label::createWithTTF(ttfConfig, "TTF:Shadow");
|
|
|
|
|
shadowLabelOutline->setPosition(Vec2(size.width / 2, horizontalSliderY + step * (0.5f + 2)));
|
|
|
|
|
shadowLabelOutline->setTextColor(Color4B::RED);
|
|
|
|
|
shadowLabelOutline->enableOutline(Color4B::YELLOW, 1);
|
2016-12-16 14:56:36 +08:00
|
|
|
|
shadowLabelOutline->enableShadow(Color4B::GREEN);
|
|
|
|
|
addChild(shadowLabelOutline);
|
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
|
shadowLabelGrow = Label::createWithTTF(ttfConfig, "TTF:Shadow");
|
|
|
|
|
shadowLabelGrow->setPosition(Vec2(size.width / 2, horizontalSliderY + step * (0.5f + 1)));
|
|
|
|
|
shadowLabelGrow->setTextColor(Color4B::RED);
|
2016-12-16 14:56:36 +08:00
|
|
|
|
shadowLabelGrow->enableGlow(Color4B::YELLOW);
|
|
|
|
|
shadowLabelGrow->enableShadow(Color4B::BLUE);
|
|
|
|
|
addChild(shadowLabelGrow);
|
|
|
|
|
|
|
|
|
|
shadowLabelBMFont = Label::createWithBMFont("fonts/bitmapFontTest.fnt", "BMFont:Shadow");
|
2021-12-28 16:06:23 +08:00
|
|
|
|
shadowLabelBMFont->setPosition(Vec2(size.width / 2, horizontalSliderY + step * 0.5f));
|
|
|
|
|
shadowLabelBMFont->setColor(Color3B::RED);
|
2016-12-16 14:56:36 +08:00
|
|
|
|
shadowLabelBMFont->enableShadow(Color4B::GREEN);
|
|
|
|
|
addChild(shadowLabelBMFont);
|
2014-03-05 15:54:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
|
void LabelShadowTest::sliderEvent(Ref* pSender, ui::Slider::EventType type)
|
2014-03-05 15:54:40 +08:00
|
|
|
|
{
|
2014-05-12 11:17:06 +08:00
|
|
|
|
if (type == Slider::EventType::ON_PERCENTAGE_CHANGED)
|
2014-03-05 15:54:40 +08:00
|
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
|
Slider* slider = (Slider*)this->getChildByTag(1);
|
|
|
|
|
Slider* slider2 = (Slider*)this->getChildByTag(2);
|
|
|
|
|
|
|
|
|
|
auto offset = Size(slider->getPercent() - 50, 50 - slider2->getPercent());
|
|
|
|
|
shadowLabelTTF->enableShadow(Color4B::BLACK, offset);
|
|
|
|
|
shadowLabelBMFont->enableShadow(Color4B::GREEN, offset);
|
|
|
|
|
shadowLabelOutline->enableShadow(Color4B::GREEN, offset);
|
|
|
|
|
shadowLabelGrow->enableShadow(Color4B::BLUE, offset);
|
2014-03-05 15:54:40 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelShadowTest::title() const
|
|
|
|
|
{
|
|
|
|
|
return "New Label";
|
2013-12-13 12:42:15 +08:00
|
|
|
|
}
|
|
|
|
|
|
2014-03-05 15:54:40 +08:00
|
|
|
|
std::string LabelShadowTest::subtitle() const
|
2013-12-13 12:42:15 +08:00
|
|
|
|
{
|
2014-03-05 15:54:40 +08:00
|
|
|
|
return "Testing shadow of label";
|
2013-12-13 12:42:15 +08:00
|
|
|
|
}
|
2014-01-16 14:37:07 +08:00
|
|
|
|
|
2014-01-16 16:37:29 +08:00
|
|
|
|
LabelCharMapTest::LabelCharMapTest()
|
|
|
|
|
{
|
|
|
|
|
_time = 0.0f;
|
|
|
|
|
|
|
|
|
|
auto label1 = Label::createWithCharMap("fonts/tuffy_bold_italic-charmap.plist");
|
|
|
|
|
addChild(label1, 0, kTagSprite1);
|
2014-05-15 01:07:09 +08:00
|
|
|
|
label1->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
label1->setPosition(Vec2(10, 100));
|
|
|
|
|
label1->setOpacity(200);
|
2014-01-16 16:37:29 +08:00
|
|
|
|
|
|
|
|
|
auto label2 = Label::createWithCharMap("fonts/tuffy_bold_italic-charmap.plist");
|
|
|
|
|
addChild(label2, 0, kTagSprite2);
|
2014-05-15 01:07:09 +08:00
|
|
|
|
label2->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
label2->setPosition(Vec2(10, 200));
|
|
|
|
|
label2->setOpacity(32);
|
2014-01-16 16:37:29 +08:00
|
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
|
schedule(AX_CALLBACK_1(LabelCharMapTest::step, this), "step_key");
|
2014-01-16 16:37:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void LabelCharMapTest::step(float dt)
|
|
|
|
|
{
|
|
|
|
|
_time += dt;
|
|
|
|
|
char string[12] = {0};
|
|
|
|
|
sprintf(string, "%2.2f Test", _time);
|
|
|
|
|
|
|
|
|
|
auto label1 = (Label*)getChildByTag(kTagSprite1);
|
|
|
|
|
label1->setString(string);
|
|
|
|
|
|
|
|
|
|
auto label2 = (Label*)getChildByTag(kTagSprite2);
|
|
|
|
|
sprintf(string, "%d", (int)_time);
|
|
|
|
|
label2->setString(string);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelCharMapTest::title() const
|
|
|
|
|
{
|
|
|
|
|
return "New Label + char map file";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelCharMapTest::subtitle() const
|
|
|
|
|
{
|
|
|
|
|
return "Updating label should be fast.";
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-24 15:02:42 +08:00
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// LabelCharMapColorTest
|
|
|
|
|
//
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
|
LabelCharMapColorTest::LabelCharMapColorTest()
|
|
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
|
auto label1 = Label::createWithCharMap("fonts/tuffy_bold_italic-charmap.plist");
|
2014-01-24 15:02:42 +08:00
|
|
|
|
addChild(label1, 0, kTagSprite1);
|
2014-05-15 01:07:09 +08:00
|
|
|
|
label1->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
label1->setPosition(Vec2(10, 100));
|
|
|
|
|
label1->setOpacity(200);
|
2014-01-24 15:02:42 +08:00
|
|
|
|
|
2015-06-11 17:16:44 +08:00
|
|
|
|
auto label2 = Label::createWithCharMap("fonts/tuffy_bold_italic-charmap.plist");
|
2014-01-24 15:02:42 +08:00
|
|
|
|
addChild(label2, 0, kTagSprite2);
|
2014-05-15 01:07:09 +08:00
|
|
|
|
label2->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
label2->setPosition(Vec2(10, 200));
|
|
|
|
|
label2->setColor(Color3B::RED);
|
2014-01-24 15:02:42 +08:00
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
|
auto fade = FadeOut::create(1.0f);
|
2014-01-24 15:02:42 +08:00
|
|
|
|
auto fade_in = fade->reverse();
|
2022-07-15 19:17:01 +08:00
|
|
|
|
auto cb = CallFunc::create(AX_CALLBACK_0(LabelCharMapColorTest::actionFinishCallback, this));
|
2021-12-28 16:06:23 +08:00
|
|
|
|
auto seq = Sequence::create(fade, fade_in, cb, nullptr);
|
|
|
|
|
auto repeat = RepeatForever::create(seq);
|
|
|
|
|
label2->runAction(repeat);
|
2014-01-24 15:02:42 +08:00
|
|
|
|
|
|
|
|
|
_time = 0;
|
|
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
|
schedule(AX_CALLBACK_1(LabelCharMapColorTest::step, this), "step_key");
|
2014-01-24 15:02:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void LabelCharMapColorTest::actionFinishCallback()
|
|
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
|
AXLOG("Action finished");
|
2014-01-24 15:02:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void LabelCharMapColorTest::step(float dt)
|
|
|
|
|
{
|
|
|
|
|
_time += dt;
|
|
|
|
|
char string[12] = {0};
|
|
|
|
|
sprintf(string, "%2.2f Test", _time);
|
|
|
|
|
auto label1 = (Label*)getChildByTag(kTagSprite1);
|
|
|
|
|
label1->setString(string);
|
|
|
|
|
|
|
|
|
|
auto label2 = (Label*)getChildByTag(kTagSprite2);
|
|
|
|
|
sprintf(string, "%d", (int)_time);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
label2->setString(string);
|
2014-01-24 15:02:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelCharMapColorTest::title() const
|
|
|
|
|
{
|
|
|
|
|
return "New Label + CharMap";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelCharMapColorTest::subtitle() const
|
|
|
|
|
{
|
|
|
|
|
return "Opacity + Color should work at the same time";
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-16 14:37:07 +08:00
|
|
|
|
LabelCrashTest::LabelCrashTest()
|
|
|
|
|
{
|
|
|
|
|
auto size = Director::getInstance()->getWinSize();
|
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
|
TTFConfig ttfConfig("fonts/arial.ttf", 40, GlyphCollection::DYNAMIC, nullptr, true);
|
2014-01-16 14:37:07 +08:00
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
|
auto label1 = Label::createWithTTF(ttfConfig, "Test崩溃123", TextHAlignment::CENTER, size.width);
|
|
|
|
|
label1->setPosition(Vec2(size.width / 2, size.height / 2));
|
2014-01-16 14:37:07 +08:00
|
|
|
|
addChild(label1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelCrashTest::title() const
|
|
|
|
|
{
|
|
|
|
|
return "New Label Crash Test";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelCrashTest::subtitle() const
|
|
|
|
|
{
|
2015-08-25 17:50:47 +08:00
|
|
|
|
return "Not crash when use character that is not contained in font.";
|
2014-01-16 14:37:07 +08:00
|
|
|
|
}
|
2014-01-23 16:16:30 +08:00
|
|
|
|
|
|
|
|
|
LabelTTFOldNew::LabelTTFOldNew()
|
|
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
|
float delta = s.height / 4;
|
2014-01-23 16:16:30 +08:00
|
|
|
|
|
2014-04-09 23:31:05 +08:00
|
|
|
|
auto label1 = Label::createWithSystemFont("Cocos2d-x Label Test", "arial", 24);
|
2014-01-23 17:11:40 +08:00
|
|
|
|
addChild(label1, 0, kTagBitmapAtlas1);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
label1->setPosition(Vec2(s.width / 2, delta * 2));
|
2014-01-23 17:11:40 +08:00
|
|
|
|
label1->setColor(Color3B::RED);
|
2014-01-23 16:16:30 +08:00
|
|
|
|
|
2014-03-11 18:26:25 +08:00
|
|
|
|
TTFConfig ttfConfig("fonts/arial.ttf", 24);
|
2014-03-07 15:58:49 +08:00
|
|
|
|
auto label2 = Label::createWithTTF(ttfConfig, "Cocos2d-x Label Test");
|
2014-01-23 16:16:30 +08:00
|
|
|
|
addChild(label2, 0, kTagBitmapAtlas2);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
label2->setPosition(Vec2(s.width / 2, delta * 2));
|
2014-03-06 07:49:08 +08:00
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
|
auto drawNode = DrawNode::create();
|
2014-01-23 16:27:50 +08:00
|
|
|
|
auto labelSize = label1->getContentSize();
|
|
|
|
|
auto origin = Director::getInstance()->getWinSize();
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
|
|
|
|
origin.width = origin.width / 2 - (labelSize.width / 2);
|
2014-01-23 16:27:50 +08:00
|
|
|
|
origin.height = origin.height / 2 - (labelSize.height / 2);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
|
|
|
|
Vec2 vertices[4] = {Vec2(origin.width, origin.height), Vec2(labelSize.width + origin.width, origin.height),
|
|
|
|
|
Vec2(labelSize.width + origin.width, labelSize.height + origin.height),
|
|
|
|
|
Vec2(origin.width, labelSize.height + origin.height)};
|
2019-09-24 11:31:35 +08:00
|
|
|
|
drawNode->drawPoly(vertices, 4, true, Color4F(1.0f, 0.0f, 0.0f, 1.0f));
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
2014-02-10 11:21:54 +08:00
|
|
|
|
labelSize = label2->getContentSize();
|
|
|
|
|
origin = Director::getInstance()->getWinSize();
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
|
|
|
|
origin.width = origin.width / 2 - (labelSize.width / 2);
|
2014-02-10 11:21:54 +08:00
|
|
|
|
origin.height = origin.height / 2 - (labelSize.height / 2);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
|
|
|
|
Vec2 vertices2[4] = {Vec2(origin.width, origin.height), Vec2(labelSize.width + origin.width, origin.height),
|
|
|
|
|
Vec2(labelSize.width + origin.width, labelSize.height + origin.height),
|
|
|
|
|
Vec2(origin.width, labelSize.height + origin.height)};
|
2019-09-24 11:31:35 +08:00
|
|
|
|
drawNode->drawPoly(vertices2, 4, true, Color4F(1.0f, 1.0f, 1.0f, 1.0f));
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
2014-09-11 15:39:56 +08:00
|
|
|
|
addChild(drawNode);
|
2014-01-23 16:27:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2014-01-23 16:16:30 +08:00
|
|
|
|
std::string LabelTTFOldNew::title() const
|
|
|
|
|
{
|
|
|
|
|
return "New / Old TTF";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelTTFOldNew::subtitle() const
|
|
|
|
|
{
|
|
|
|
|
return "Comparison between old(red) and new(white) TTF label";
|
|
|
|
|
}
|
2014-03-07 14:58:44 +08:00
|
|
|
|
|
2014-03-10 19:42:43 +08:00
|
|
|
|
LabelFontNameTest::LabelFontNameTest()
|
|
|
|
|
{
|
|
|
|
|
auto size = Director::getInstance()->getWinSize();
|
|
|
|
|
|
|
|
|
|
auto label1 = Label::create();
|
|
|
|
|
label1->setString("Default Font");
|
2021-12-28 16:06:23 +08:00
|
|
|
|
label1->setPosition(Vec2(size.width / 2, size.height * 0.7));
|
2014-03-10 19:42:43 +08:00
|
|
|
|
addChild(label1);
|
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
|
auto label3 = Label::createWithSystemFont("Marker Felt", "Marker Felt", 32);
|
|
|
|
|
label3->setPosition(Vec2(size.width / 2, size.height * 0.5));
|
2014-03-10 19:42:43 +08:00
|
|
|
|
addChild(label3);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelFontNameTest::title() const
|
|
|
|
|
{
|
|
|
|
|
return "New Label Test";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelFontNameTest::subtitle() const
|
|
|
|
|
{
|
|
|
|
|
return "create label by font name,compatible with old labelTTF";
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-07 14:58:44 +08:00
|
|
|
|
LabelAlignmentTest::LabelAlignmentTest()
|
|
|
|
|
{
|
|
|
|
|
auto blockSize = Size(200, 160);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2014-03-07 14:58:44 +08:00
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
|
auto pos = Vec2((s.width - blockSize.width) / 2, (s.height - blockSize.height) / 2);
|
2014-03-07 14:58:44 +08:00
|
|
|
|
auto colorLayer = LayerColor::create(Color4B(100, 100, 100, 255), blockSize.width, blockSize.height);
|
2014-05-15 01:07:09 +08:00
|
|
|
|
colorLayer->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT);
|
2014-03-07 14:58:44 +08:00
|
|
|
|
colorLayer->setPosition(pos);
|
|
|
|
|
|
|
|
|
|
this->addChild(colorLayer);
|
|
|
|
|
|
|
|
|
|
MenuItemFont::setFontSize(30);
|
|
|
|
|
auto menu = Menu::create(
|
2022-07-15 19:17:01 +08:00
|
|
|
|
MenuItemFont::create("Left", AX_CALLBACK_1(LabelAlignmentTest::setAlignmentLeft, this)),
|
|
|
|
|
MenuItemFont::create("Center", AX_CALLBACK_1(LabelAlignmentTest::setAlignmentCenter, this)),
|
|
|
|
|
MenuItemFont::create("Right", AX_CALLBACK_1(LabelAlignmentTest::setAlignmentRight, this)), nullptr);
|
2014-03-07 14:58:44 +08:00
|
|
|
|
menu->alignItemsVerticallyWithPadding(4);
|
2019-09-24 11:31:35 +08:00
|
|
|
|
menu->setPosition(Vec2(50.0f, s.height / 2 - 20));
|
2014-03-07 14:58:44 +08:00
|
|
|
|
this->addChild(menu);
|
|
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
|
menu = Menu::create(MenuItemFont::create("Top", AX_CALLBACK_1(LabelAlignmentTest::setAlignmentTop, this)),
|
|
|
|
|
MenuItemFont::create("Middle", AX_CALLBACK_1(LabelAlignmentTest::setAlignmentMiddle, this)),
|
|
|
|
|
MenuItemFont::create("Bottom", AX_CALLBACK_1(LabelAlignmentTest::setAlignmentBottom, this)),
|
2021-12-28 16:06:23 +08:00
|
|
|
|
nullptr);
|
2014-03-07 14:58:44 +08:00
|
|
|
|
menu->alignItemsVerticallyWithPadding(4);
|
2014-05-15 01:07:09 +08:00
|
|
|
|
menu->setPosition(Vec2(s.width - 50, s.height / 2 - 20));
|
2014-03-07 14:58:44 +08:00
|
|
|
|
this->addChild(menu);
|
|
|
|
|
|
2015-07-24 21:34:59 +08:00
|
|
|
|
TTFConfig ttfConfig("fonts/arial.ttf", 50);
|
|
|
|
|
_label = Label::createWithTTF(ttfConfig, "abc efg hijk lmn opq rst uvw xyz");
|
|
|
|
|
_label->setDimensions(200, 160);
|
2014-05-15 01:07:09 +08:00
|
|
|
|
_label->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT);
|
2014-03-07 14:58:44 +08:00
|
|
|
|
_label->setPosition(pos);
|
|
|
|
|
addChild(_label);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void LabelAlignmentTest::setAlignmentLeft(Ref* sender)
|
|
|
|
|
{
|
2015-07-24 21:34:59 +08:00
|
|
|
|
_label->setHorizontalAlignment(TextHAlignment::LEFT);
|
2014-03-07 14:58:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void LabelAlignmentTest::setAlignmentCenter(Ref* sender)
|
|
|
|
|
{
|
2015-07-24 21:34:59 +08:00
|
|
|
|
_label->setHorizontalAlignment(TextHAlignment::CENTER);
|
2014-03-07 14:58:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void LabelAlignmentTest::setAlignmentRight(Ref* sender)
|
|
|
|
|
{
|
2015-07-24 21:34:59 +08:00
|
|
|
|
_label->setHorizontalAlignment(TextHAlignment::RIGHT);
|
2014-03-07 14:58:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void LabelAlignmentTest::setAlignmentTop(Ref* sender)
|
|
|
|
|
{
|
2015-07-24 21:34:59 +08:00
|
|
|
|
_label->setVerticalAlignment(TextVAlignment::TOP);
|
2014-03-07 14:58:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void LabelAlignmentTest::setAlignmentMiddle(Ref* sender)
|
|
|
|
|
{
|
2015-07-24 21:34:59 +08:00
|
|
|
|
_label->setVerticalAlignment(TextVAlignment::CENTER);
|
2014-03-07 14:58:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void LabelAlignmentTest::setAlignmentBottom(Ref* sender)
|
|
|
|
|
{
|
2015-07-24 21:34:59 +08:00
|
|
|
|
_label->setVerticalAlignment(TextVAlignment::BOTTOM);
|
2014-03-07 14:58:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelAlignmentTest::title() const
|
|
|
|
|
{
|
|
|
|
|
return "Testing New Label";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelAlignmentTest::subtitle() const
|
|
|
|
|
{
|
2015-07-24 21:34:59 +08:00
|
|
|
|
return "Test text alignment";
|
2014-03-07 14:58:44 +08:00
|
|
|
|
}
|
2014-03-18 10:20:25 +08:00
|
|
|
|
|
2014-03-18 10:26:45 +08:00
|
|
|
|
LabelIssue4428Test::LabelIssue4428Test()
|
2014-03-18 10:20:25 +08:00
|
|
|
|
{
|
|
|
|
|
auto size = Director::getInstance()->getWinSize();
|
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
|
auto label = Label::createWithBMFont("fonts/bitmapFontTest3.fnt", "123\n456");
|
|
|
|
|
label->setPosition(Vec2(size.width / 2.0f, size.height / 2.0f));
|
2014-05-15 01:07:09 +08:00
|
|
|
|
label->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT);
|
2014-03-18 10:20:25 +08:00
|
|
|
|
addChild(label);
|
|
|
|
|
|
|
|
|
|
int len = label->getStringLength();
|
|
|
|
|
for (int i = 0; i < len; ++i)
|
|
|
|
|
{
|
|
|
|
|
auto sprite = label->getLetter(i);
|
|
|
|
|
if (sprite != nullptr)
|
|
|
|
|
{
|
|
|
|
|
sprite->setFlippedY(true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-18 10:26:45 +08:00
|
|
|
|
std::string LabelIssue4428Test::title() const
|
2014-03-18 10:20:25 +08:00
|
|
|
|
{
|
2014-03-18 10:26:45 +08:00
|
|
|
|
return "New Label Bugs Test";
|
2014-03-18 10:20:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
2014-03-18 10:26:45 +08:00
|
|
|
|
std::string LabelIssue4428Test::subtitle() const
|
2014-03-18 10:20:25 +08:00
|
|
|
|
{
|
|
|
|
|
return "Reorder issue #4428.The label should be flipped vertically.";
|
|
|
|
|
}
|
2014-05-29 14:00:38 +08:00
|
|
|
|
|
|
|
|
|
LabelIssue4999Test::LabelIssue4999Test()
|
|
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
|
auto label = Label::createWithTTF("Smaller font test", "fonts/arial.ttf", 5);
|
2014-05-29 14:00:38 +08:00
|
|
|
|
label->setPosition(VisibleRect::center());
|
|
|
|
|
label->setAnchorPoint(Vec2::ANCHOR_MIDDLE);
|
|
|
|
|
addChild(label);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelIssue4999Test::title() const
|
|
|
|
|
{
|
|
|
|
|
return "New Label Bugs Test";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelIssue4999Test::subtitle() const
|
|
|
|
|
{
|
|
|
|
|
return "Reorder issue #4999.The label should be display cleanly.";
|
|
|
|
|
}
|
2014-06-18 18:01:55 +08:00
|
|
|
|
|
|
|
|
|
LabelLineHeightTest::LabelLineHeightTest()
|
|
|
|
|
{
|
|
|
|
|
auto size = Director::getInstance()->getWinSize();
|
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
|
auto bg = LayerColor::create(Color4B(200, 191, 231, 255));
|
2014-06-18 18:01:55 +08:00
|
|
|
|
this->addChild(bg);
|
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
|
TTFConfig ttfConfig("fonts/arial.ttf", 25, GlyphCollection::DYNAMIC, nullptr, false);
|
2014-06-18 18:01:55 +08:00
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
|
label = Label::createWithTTF(ttfConfig, "Test\nLine\nHeight");
|
|
|
|
|
label->setPosition(Vec2(size.width / 2, size.height * 0.5f));
|
|
|
|
|
label->setTextColor(Color4B::RED);
|
2014-06-18 18:01:55 +08:00
|
|
|
|
addChild(label);
|
|
|
|
|
|
|
|
|
|
auto slider = ui::Slider::create();
|
|
|
|
|
slider->setTouchEnabled(true);
|
|
|
|
|
slider->loadBarTexture("cocosui/sliderTrack.png");
|
|
|
|
|
slider->loadSlidBallTextures("cocosui/sliderThumb.png", "cocosui/sliderThumb.png", "");
|
|
|
|
|
slider->loadProgressBarTexture("cocosui/sliderProgress.png");
|
2014-06-20 11:18:53 +08:00
|
|
|
|
slider->setPosition(Vec2(size.width / 2.0f, size.height * 0.15f + slider->getContentSize().height * 2.0f));
|
2014-06-18 18:01:55 +08:00
|
|
|
|
slider->setPercent(label->getLineHeight());
|
2022-07-15 19:17:01 +08:00
|
|
|
|
slider->addEventListener(AX_CALLBACK_2(LabelLineHeightTest::sliderEvent, this));
|
2014-06-18 18:01:55 +08:00
|
|
|
|
addChild(slider);
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
|
void LabelLineHeightTest::sliderEvent(Ref* sender, ui::Slider::EventType type)
|
2014-06-18 18:01:55 +08:00
|
|
|
|
{
|
|
|
|
|
if (type == Slider::EventType::ON_PERCENTAGE_CHANGED)
|
|
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
|
Slider* slider = (Slider*)sender;
|
2014-06-18 18:01:55 +08:00
|
|
|
|
label->setLineHeight(slider->getPercent());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelLineHeightTest::title() const
|
|
|
|
|
{
|
|
|
|
|
return "New Label";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelLineHeightTest::subtitle() const
|
|
|
|
|
{
|
|
|
|
|
return "Testing line height of label";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LabelAdditionalKerningTest::LabelAdditionalKerningTest()
|
|
|
|
|
{
|
|
|
|
|
auto size = Director::getInstance()->getWinSize();
|
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
|
auto bg = LayerColor::create(Color4B(200, 191, 231, 255));
|
2014-06-18 18:01:55 +08:00
|
|
|
|
this->addChild(bg);
|
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
|
TTFConfig ttfConfig("fonts/arial.ttf", 40, GlyphCollection::DYNAMIC, nullptr, false);
|
2014-06-18 18:01:55 +08:00
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
|
label = Label::createWithTTF(ttfConfig, "Test additional kerning");
|
|
|
|
|
label->setPosition(size.width / 2, size.height * 0.5f);
|
|
|
|
|
label->setTextColor(Color4B::RED);
|
2014-06-18 18:01:55 +08:00
|
|
|
|
addChild(label);
|
|
|
|
|
|
|
|
|
|
auto slider = ui::Slider::create();
|
|
|
|
|
slider->setTouchEnabled(true);
|
|
|
|
|
slider->loadBarTexture("cocosui/sliderTrack.png");
|
|
|
|
|
slider->loadSlidBallTextures("cocosui/sliderThumb.png", "cocosui/sliderThumb.png", "");
|
|
|
|
|
slider->loadProgressBarTexture("cocosui/sliderProgress.png");
|
2014-06-20 11:18:53 +08:00
|
|
|
|
slider->setPosition(Vec2(size.width / 2.0f, size.height * 0.15f + slider->getContentSize().height * 2.0f));
|
2014-06-18 18:01:55 +08:00
|
|
|
|
slider->setPercent(0);
|
2022-07-15 19:17:01 +08:00
|
|
|
|
slider->addEventListener(AX_CALLBACK_2(LabelAdditionalKerningTest::sliderEvent, this));
|
2014-06-18 18:01:55 +08:00
|
|
|
|
addChild(slider);
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
|
void LabelAdditionalKerningTest::sliderEvent(Ref* sender, ui::Slider::EventType type)
|
2014-06-18 18:01:55 +08:00
|
|
|
|
{
|
|
|
|
|
if (type == Slider::EventType::ON_PERCENTAGE_CHANGED)
|
|
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
|
Slider* slider = (Slider*)sender;
|
2014-06-18 18:01:55 +08:00
|
|
|
|
label->setAdditionalKerning(slider->getPercent());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelAdditionalKerningTest::title() const
|
|
|
|
|
{
|
|
|
|
|
return "New Label";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelAdditionalKerningTest::subtitle() const
|
|
|
|
|
{
|
|
|
|
|
return "Testing additional kerning of label";
|
2014-06-19 19:45:24 +08:00
|
|
|
|
}
|
2014-10-08 18:22:35 +08:00
|
|
|
|
|
|
|
|
|
LabelIssue8492Test::LabelIssue8492Test()
|
|
|
|
|
{
|
|
|
|
|
auto label = Label::createWithBMFont("fonts/bitmapFontChinese.fnt", "中国中国中国中国中国");
|
2021-12-28 16:06:23 +08:00
|
|
|
|
label->setDimensions(5, 100);
|
2014-10-08 18:22:35 +08:00
|
|
|
|
label->setPosition(VisibleRect::center());
|
|
|
|
|
addChild(label);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelIssue8492Test::title() const
|
|
|
|
|
{
|
|
|
|
|
return "Reorder issue #8492";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelIssue8492Test::subtitle() const
|
|
|
|
|
{
|
|
|
|
|
return "Work fine when dimensions are not enough to fit one character";
|
|
|
|
|
}
|
2014-11-12 17:24:35 +08:00
|
|
|
|
|
|
|
|
|
LabelMultilineWithOutline::LabelMultilineWithOutline()
|
|
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
|
auto label = Label::createWithTTF("Multi-line text\nwith\noutline feature", "fonts/arial.ttf", 24);
|
|
|
|
|
label->enableOutline(Color4B::ORANGE, 1);
|
2014-11-12 17:24:35 +08:00
|
|
|
|
label->setPosition(VisibleRect::center());
|
|
|
|
|
addChild(label);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelMultilineWithOutline::title() const
|
|
|
|
|
{
|
|
|
|
|
return "Reorder issue #9095";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelMultilineWithOutline::subtitle() const
|
|
|
|
|
{
|
|
|
|
|
return "end in string 'outline feature'";
|
|
|
|
|
}
|
2014-11-27 11:03:11 +08:00
|
|
|
|
|
|
|
|
|
LabelIssue9255Test::LabelIssue9255Test()
|
|
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
|
Size s = Director::getInstance()->getWinSize();
|
2014-11-27 11:03:11 +08:00
|
|
|
|
auto parent = Node::create();
|
2021-12-28 16:06:23 +08:00
|
|
|
|
parent->setPosition(s.width / 2, s.height / 2);
|
2014-11-27 11:03:11 +08:00
|
|
|
|
parent->setVisible(false);
|
|
|
|
|
this->addChild(parent);
|
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
|
auto label = Label::createWithTTF("Crashed!!!", "fonts/HKYuanMini.ttf", 24);
|
2014-11-27 11:03:11 +08:00
|
|
|
|
label->setPosition(VisibleRect::center());
|
|
|
|
|
parent->addChild(label);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelIssue9255Test::title() const
|
|
|
|
|
{
|
|
|
|
|
return "Test for Issue #9255";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelIssue9255Test::subtitle() const
|
|
|
|
|
{
|
|
|
|
|
return "switch to desktop and switch back. Crashed!!!";
|
|
|
|
|
}
|
2015-01-09 18:51:30 +08:00
|
|
|
|
|
|
|
|
|
LabelSmallDimensionsTest::LabelSmallDimensionsTest()
|
|
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
|
auto label = Label::createWithSystemFont("Hello World!", "fonts/arial.ttf", 24, Size(30.0f, 100.0f));
|
2015-01-09 18:51:30 +08:00
|
|
|
|
label->setPosition(VisibleRect::center());
|
|
|
|
|
addChild(label);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelSmallDimensionsTest::title() const
|
|
|
|
|
{
|
2015-08-25 17:50:47 +08:00
|
|
|
|
return "New Label + System font";
|
2015-01-09 18:51:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelSmallDimensionsTest::subtitle() const
|
|
|
|
|
{
|
2015-08-25 17:50:47 +08:00
|
|
|
|
return "Testing create Label with small dimensions.Program should not dead loop";
|
2015-01-09 18:51:30 +08:00
|
|
|
|
}
|
2015-01-20 12:01:51 +08:00
|
|
|
|
|
|
|
|
|
LabelIssue10089Test::LabelIssue10089Test()
|
|
|
|
|
{
|
|
|
|
|
auto center = VisibleRect::center();
|
|
|
|
|
|
|
|
|
|
auto labelA = Label::createWithSystemFont("create label with system font", "fonts/arial.ttf", 24);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
auto size = labelA->getContentSize();
|
2015-01-20 12:01:51 +08:00
|
|
|
|
labelA->setDimensions(size.width, size.height);
|
|
|
|
|
labelA->setPosition(center.x, center.y + 50);
|
|
|
|
|
addChild(labelA);
|
|
|
|
|
|
|
|
|
|
auto labelB = Label::createWithTTF("create label with TTF", "fonts/arial.ttf", 24);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
size = labelB->getContentSize();
|
2015-01-20 12:01:51 +08:00
|
|
|
|
labelB->setDimensions(size.width, size.height);
|
|
|
|
|
labelB->setPosition(center.x, center.y - 50);
|
|
|
|
|
addChild(labelB);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelIssue10089Test::title() const
|
|
|
|
|
{
|
|
|
|
|
return "Test for Issue #10089";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelIssue10089Test::subtitle() const
|
|
|
|
|
{
|
|
|
|
|
return "Should be able to see two single-line text";
|
|
|
|
|
}
|
2015-01-20 16:50:50 +08:00
|
|
|
|
|
|
|
|
|
LabelSystemFontColor::LabelSystemFontColor()
|
|
|
|
|
{
|
|
|
|
|
auto size = Director::getInstance()->getWinSize();
|
|
|
|
|
|
|
|
|
|
auto label1 = Label::createWithSystemFont("Color4B::Red", "fonts/arial.ttf", 20);
|
|
|
|
|
label1->setPosition(Vec2(size.width / 2, size.height * 0.3f));
|
|
|
|
|
label1->setTextColor(Color4B::RED);
|
|
|
|
|
addChild(label1);
|
|
|
|
|
|
|
|
|
|
auto label2 = Label::createWithSystemFont("Color4B::Green", "fonts/arial.ttf", 20);
|
|
|
|
|
label2->setPosition(Vec2(size.width / 2, size.height * 0.4f));
|
|
|
|
|
label2->setTextColor(Color4B::GREEN);
|
|
|
|
|
addChild(label2);
|
|
|
|
|
|
|
|
|
|
auto label3 = Label::createWithSystemFont("Color4B::Blue", "fonts/arial.ttf", 20);
|
|
|
|
|
label3->setPosition(Vec2(size.width / 2, size.height * 0.5f));
|
|
|
|
|
label3->setTextColor(Color4B::BLUE);
|
|
|
|
|
addChild(label3);
|
|
|
|
|
|
|
|
|
|
auto label4 = Label::createWithSystemFont("Color4B(0, 0, 255, 100)", "fonts/arial.ttf", 20);
|
|
|
|
|
label4->setPosition(Vec2(size.width / 2, size.height * 0.6f));
|
|
|
|
|
label4->setTextColor(Color4B(0, 0, 255, 100));
|
|
|
|
|
addChild(label4);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelSystemFontColor::title() const
|
|
|
|
|
{
|
|
|
|
|
return "New Label + system font";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelSystemFontColor::subtitle() const
|
|
|
|
|
{
|
|
|
|
|
return "Testing text color of system font";
|
|
|
|
|
}
|
2015-04-30 16:11:59 +08:00
|
|
|
|
|
|
|
|
|
LabelIssue10773Test::LabelIssue10773Test()
|
|
|
|
|
{
|
|
|
|
|
auto center = VisibleRect::center();
|
|
|
|
|
|
|
|
|
|
auto label = Label::createWithTTF("create label with TTF", "fonts/arial.ttf", 24);
|
|
|
|
|
label->getLetter(5);
|
|
|
|
|
label->setString("Hi");
|
|
|
|
|
label->setPosition(center.x, center.y);
|
|
|
|
|
addChild(label);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelIssue10773Test::title() const
|
|
|
|
|
{
|
|
|
|
|
return "Test for Issue #10773";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelIssue10773Test::subtitle() const
|
|
|
|
|
{
|
|
|
|
|
return "Should not crash!";
|
|
|
|
|
}
|
2015-05-04 10:09:14 +08:00
|
|
|
|
|
2015-05-07 11:48:55 +08:00
|
|
|
|
LabelIssue11576Test::LabelIssue11576Test()
|
2015-05-04 10:09:14 +08:00
|
|
|
|
{
|
|
|
|
|
auto center = VisibleRect::center();
|
|
|
|
|
|
|
|
|
|
auto label = Label::createWithTTF("abcdefg", "fonts/arial.ttf", 24);
|
|
|
|
|
for (int index = 0; index < label->getStringLength(); ++index)
|
|
|
|
|
{
|
|
|
|
|
label->getLetter(index);
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
|
this->runAction(Sequence::create(DelayTime::create(2.0f),
|
|
|
|
|
CallFunc::create([label]() { label->setString("Hello World!"); }), nullptr));
|
2015-05-04 10:09:14 +08:00
|
|
|
|
|
|
|
|
|
label->setPosition(center.x, center.y);
|
|
|
|
|
addChild(label);
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-07 11:48:55 +08:00
|
|
|
|
std::string LabelIssue11576Test::title() const
|
2015-05-04 10:09:14 +08:00
|
|
|
|
{
|
2015-05-07 11:48:55 +08:00
|
|
|
|
return "Test for Issue #11576";
|
2015-05-04 10:09:14 +08:00
|
|
|
|
}
|
|
|
|
|
|
2015-05-07 11:48:55 +08:00
|
|
|
|
std::string LabelIssue11576Test::subtitle() const
|
2015-05-04 10:09:14 +08:00
|
|
|
|
{
|
|
|
|
|
return "You should see another string displayed correctly after 2 seconds.";
|
|
|
|
|
}
|
2015-05-06 17:17:30 +08:00
|
|
|
|
|
|
|
|
|
LabelIssue11699Test::LabelIssue11699Test()
|
|
|
|
|
{
|
|
|
|
|
auto center = VisibleRect::center();
|
|
|
|
|
|
|
|
|
|
auto label = Label::createWithTTF("中国", "fonts/HKYuanMini.ttf", 150);
|
|
|
|
|
label->enableOutline(Color4B::RED, 2);
|
|
|
|
|
label->setPosition(center.x, center.y);
|
|
|
|
|
addChild(label);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelIssue11699Test::title() const
|
|
|
|
|
{
|
|
|
|
|
return "Test for Issue #11699";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelIssue11699Test::subtitle() const
|
|
|
|
|
{
|
|
|
|
|
return "Outline should match with the characters exactly.";
|
|
|
|
|
}
|
2015-06-11 17:16:44 +08:00
|
|
|
|
|
2015-06-19 13:39:19 +08:00
|
|
|
|
LabelIssue12409Test::LabelIssue12409Test()
|
|
|
|
|
{
|
|
|
|
|
auto center = VisibleRect::center();
|
|
|
|
|
|
|
|
|
|
auto label = Label::createWithTTF("abcdefghijklmn", "fonts/arial.ttf", 30);
|
|
|
|
|
label->setWidth(70);
|
|
|
|
|
label->setLineBreakWithoutSpace(true);
|
|
|
|
|
label->setPosition(center.x, center.y);
|
|
|
|
|
addChild(label);
|
|
|
|
|
|
|
|
|
|
auto labelSize = label->getContentSize();
|
2021-12-28 16:06:23 +08:00
|
|
|
|
auto winSize = Director::getInstance()->getWinSize();
|
2015-06-19 13:39:19 +08:00
|
|
|
|
Vec2 labelOrigin;
|
2021-12-28 16:06:23 +08:00
|
|
|
|
labelOrigin.x = winSize.width / 2 - (labelSize.width / 2);
|
|
|
|
|
labelOrigin.y = winSize.height / 2 - (labelSize.height / 2);
|
|
|
|
|
Vec2 vertices[4] = {Vec2(labelOrigin.x, labelOrigin.y), Vec2(labelOrigin.x + labelSize.width, labelOrigin.y),
|
|
|
|
|
Vec2(labelOrigin.x + labelSize.width, labelOrigin.y + labelSize.height),
|
|
|
|
|
Vec2(labelOrigin.x, labelOrigin.y + labelSize.height)};
|
2015-06-19 13:39:19 +08:00
|
|
|
|
|
|
|
|
|
auto drawNode = DrawNode::create();
|
|
|
|
|
drawNode->drawPoly(vertices, 4, true, Color4F::WHITE);
|
|
|
|
|
addChild(drawNode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelIssue12409Test::title() const
|
|
|
|
|
{
|
|
|
|
|
return "Test for Issue #12409";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelIssue12409Test::subtitle() const
|
|
|
|
|
{
|
|
|
|
|
return "Testing auto-wrapping without space.";
|
|
|
|
|
}
|
2015-07-07 15:41:54 +08:00
|
|
|
|
|
|
|
|
|
LabelAddChildTest::LabelAddChildTest()
|
|
|
|
|
{
|
|
|
|
|
auto center = VisibleRect::center();
|
|
|
|
|
|
|
|
|
|
auto label = Label::createWithTTF("Label with child node:", "fonts/arial.ttf", 24);
|
|
|
|
|
label->setPosition(center.x, center.y);
|
|
|
|
|
addChild(label);
|
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
|
auto jump = JumpBy::create(1.0f, Vec2::ZERO, 60, 1);
|
2015-07-07 15:41:54 +08:00
|
|
|
|
auto jump_4ever = RepeatForever::create(jump);
|
|
|
|
|
label->runAction(jump_4ever);
|
|
|
|
|
|
|
|
|
|
auto spite = Sprite::create("Images/SpookyPeas.png");
|
|
|
|
|
spite->setAnchorPoint(Vec2::ANCHOR_MIDDLE_LEFT);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
spite->setPosition(label->getContentSize().width, label->getContentSize().height / 2);
|
2015-07-07 15:41:54 +08:00
|
|
|
|
label->addChild(spite);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelAddChildTest::title() const
|
|
|
|
|
{
|
|
|
|
|
return "Label support add child nodes";
|
|
|
|
|
}
|
2015-07-13 15:38:33 +08:00
|
|
|
|
|
|
|
|
|
LabelIssue12775Test::LabelIssue12775Test()
|
|
|
|
|
{
|
|
|
|
|
auto center = VisibleRect::center();
|
|
|
|
|
|
|
|
|
|
auto label = Label::createWithTTF("Hello", "fonts/xingkai-incomplete.ttf", 30);
|
|
|
|
|
label->setPosition(center.x, center.y);
|
|
|
|
|
addChild(label);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelIssue12775Test::title() const
|
|
|
|
|
{
|
|
|
|
|
return "Test for Issue #12775";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelIssue12775Test::subtitle() const
|
|
|
|
|
{
|
|
|
|
|
return "Should not crash if the font not contain a Unicode charmap.";
|
|
|
|
|
}
|
2015-07-15 20:17:05 +08:00
|
|
|
|
|
|
|
|
|
LabelIssue11585Test::LabelIssue11585Test()
|
|
|
|
|
{
|
|
|
|
|
auto center = VisibleRect::center();
|
|
|
|
|
|
|
|
|
|
auto label = Label::createWithTTF("Hello World", "fonts/arial.ttf", 24);
|
|
|
|
|
label->setPosition(center.x, center.y);
|
|
|
|
|
addChild(label);
|
|
|
|
|
|
|
|
|
|
label->getLetter(0)->setColor(Color3B::RED);
|
|
|
|
|
label->getLetter(1)->setColor(Color3B::GREEN);
|
|
|
|
|
label->getLetter(2)->setColor(Color3B::BLUE);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
auto action = RepeatForever::create(Sequence::create(FadeOut::create(2), FadeIn::create(2), nullptr));
|
2015-07-15 20:17:05 +08:00
|
|
|
|
label->runAction(action);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelIssue11585Test::title() const
|
|
|
|
|
{
|
|
|
|
|
return "Test for Issue #11585";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelIssue11585Test::subtitle() const
|
|
|
|
|
{
|
|
|
|
|
return "The color of letter should not be overridden by fade action.";
|
|
|
|
|
}
|
2015-07-21 17:09:27 +08:00
|
|
|
|
|
2015-07-29 16:30:07 +08:00
|
|
|
|
LabelIssue10688Test::LabelIssue10688Test()
|
|
|
|
|
{
|
|
|
|
|
auto center = VisibleRect::center();
|
|
|
|
|
|
|
|
|
|
auto label = Label::createWithTTF("Glow MenuItemLabel", "fonts/arial.ttf", 30);
|
|
|
|
|
label->setTextColor(Color4B::RED);
|
|
|
|
|
label->enableGlow(Color4B::YELLOW);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
auto menuItem1 = MenuItemLabel::create(label, [](Ref*) {});
|
2015-07-29 16:30:07 +08:00
|
|
|
|
menuItem1->setAnchorPoint(Vec2::ANCHOR_MIDDLE_LEFT);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
menuItem1->setPosition(center.x - label->getContentSize().width / 2, center.y);
|
2015-07-29 16:30:07 +08:00
|
|
|
|
|
|
|
|
|
auto menu = Menu::create(menuItem1, NULL);
|
|
|
|
|
menu->setPosition(Vec2::ZERO);
|
|
|
|
|
this->addChild(menu);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelIssue10688Test::title() const
|
|
|
|
|
{
|
|
|
|
|
return "Test for Issue #10688";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelIssue10688Test::subtitle() const
|
|
|
|
|
{
|
|
|
|
|
return "The MenuItemLabel should be displayed in the middle of the screen.";
|
|
|
|
|
}
|
2015-08-05 14:12:02 +08:00
|
|
|
|
|
|
|
|
|
LabelIssue13202Test::LabelIssue13202Test()
|
|
|
|
|
{
|
|
|
|
|
auto center = VisibleRect::center();
|
|
|
|
|
|
|
|
|
|
auto label = Label::createWithTTF("asdfghjklzxcvbnmqwertyuiop", "fonts/arial.ttf", 150);
|
|
|
|
|
label->setPosition(center);
|
|
|
|
|
addChild(label);
|
|
|
|
|
|
|
|
|
|
label->getContentSize();
|
|
|
|
|
label->setString("A");
|
2021-12-28 16:06:23 +08:00
|
|
|
|
this->scheduleOnce([](float dt) { FontAtlasCache::purgeCachedData(); }, 0.15f, "FontAtlasCache::purgeCachedData");
|
2015-08-05 14:12:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelIssue13202Test::title() const
|
|
|
|
|
{
|
|
|
|
|
return "Test for Issue #13202";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelIssue13202Test::subtitle() const
|
|
|
|
|
{
|
|
|
|
|
return "FontAtlasCache::purgeCachedData should not cause crash.";
|
|
|
|
|
}
|
2015-08-05 23:46:41 +08:00
|
|
|
|
|
|
|
|
|
LabelIssue9500Test::LabelIssue9500Test()
|
|
|
|
|
{
|
|
|
|
|
auto center = VisibleRect::center();
|
|
|
|
|
|
|
|
|
|
auto label = Label::createWithTTF("Spaces should not be lost", "fonts/Fingerpop.ttf", 20);
|
|
|
|
|
label->setPosition(center);
|
|
|
|
|
addChild(label);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelIssue9500Test::title() const
|
|
|
|
|
{
|
|
|
|
|
return "Test for Issue #9500";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelIssue9500Test::subtitle() const
|
|
|
|
|
{
|
|
|
|
|
return "Spaces should not be lost if label created with Fingerpop.ttf";
|
|
|
|
|
}
|
2015-11-19 16:06:13 +08:00
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
|
ControlStepper* LabelLayoutBaseTest::makeControlStepper()
|
2015-11-19 16:06:13 +08:00
|
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
|
auto minusSprite = Sprite::create("extensions/stepper-minus.png");
|
|
|
|
|
auto plusSprite = Sprite::create("extensions/stepper-plus.png");
|
|
|
|
|
|
2015-11-19 16:06:13 +08:00
|
|
|
|
return ControlStepper::create(minusSprite, plusSprite);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LabelLayoutBaseTest::LabelLayoutBaseTest()
|
|
|
|
|
{
|
|
|
|
|
auto size = Director::getInstance()->getVisibleSize();
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
2015-11-19 16:06:13 +08:00
|
|
|
|
this->initTestLabel(size);
|
|
|
|
|
|
|
|
|
|
this->initFontSizeChange(size);
|
|
|
|
|
this->initToggleLabelTypeOption(size);
|
|
|
|
|
|
|
|
|
|
this->initWrapOption(size);
|
|
|
|
|
|
|
|
|
|
this->initAlignmentOption(size);
|
|
|
|
|
|
|
|
|
|
this->initDrawNode(size);
|
|
|
|
|
|
|
|
|
|
this->initSliders(size);
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-18 19:17:36 +08:00
|
|
|
|
void LabelLayoutBaseTest::initFontSizeChange(const ax::Size& size)
|
2015-11-19 16:06:13 +08:00
|
|
|
|
{
|
|
|
|
|
auto fontSizeLabel = Label::createWithSystemFont("font size:20", "Arial", 10);
|
|
|
|
|
fontSizeLabel->setName("fontSize");
|
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
|
ControlStepper* stepper = this->makeControlStepper();
|
|
|
|
|
stepper->setPosition(size.width * 0.5 - stepper->getContentSize().width / 2, size.height * 0.8);
|
2015-11-19 16:06:13 +08:00
|
|
|
|
stepper->setValue(20);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
stepper->addTargetWithActionForControlEvents(this, cccontrol_selector(LabelLayoutBaseTest::valueChanged),
|
2015-11-19 16:06:13 +08:00
|
|
|
|
Control::EventType::VALUE_CHANGED);
|
|
|
|
|
this->addChild(stepper);
|
|
|
|
|
stepper->setName("stepper");
|
|
|
|
|
stepper->setScale(0.5);
|
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
|
fontSizeLabel->setPosition(
|
|
|
|
|
stepper->getPosition() -
|
|
|
|
|
Vec2(stepper->getContentSize().width / 2 + fontSizeLabel->getContentSize().width / 2, 0.0f));
|
2015-11-19 16:06:13 +08:00
|
|
|
|
this->addChild(fontSizeLabel);
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-18 19:17:36 +08:00
|
|
|
|
void LabelLayoutBaseTest::initWrapOption(const ax::Size& size)
|
2015-11-19 16:06:13 +08:00
|
|
|
|
{
|
|
|
|
|
auto label = Label::createWithSystemFont("Enable Wrap:", "Arial", 10);
|
|
|
|
|
label->setColor(Color3B::WHITE);
|
|
|
|
|
label->setPosition(Vec2(size.width * 0.8f - 100, size.height * 0.8f));
|
|
|
|
|
this->addChild(label);
|
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
|
CheckBox* checkBox = CheckBox::create("cocosui/check_box_normal.png", "cocosui/check_box_normal_press.png",
|
|
|
|
|
"cocosui/check_box_active.png", "cocosui/check_box_normal_disable.png",
|
2015-11-19 16:06:13 +08:00
|
|
|
|
"cocosui/check_box_active_disable.png");
|
|
|
|
|
checkBox->setPosition(Vec2(size.width * 0.8f - 55, size.height * 0.8f));
|
|
|
|
|
checkBox->setScale(0.5);
|
|
|
|
|
checkBox->setSelected(true);
|
|
|
|
|
checkBox->setName("toggleWrap");
|
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
|
checkBox->addEventListener([=](Ref* ref, CheckBox::EventType event) {
|
|
|
|
|
if (event == CheckBox::EventType::SELECTED)
|
|
|
|
|
{
|
2015-11-19 16:06:13 +08:00
|
|
|
|
_label->enableWrap(true);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2015-11-19 16:06:13 +08:00
|
|
|
|
_label->enableWrap(false);
|
|
|
|
|
}
|
|
|
|
|
this->updateDrawNodeSize(_label->getContentSize());
|
|
|
|
|
});
|
|
|
|
|
this->addChild(checkBox);
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-18 19:17:36 +08:00
|
|
|
|
void LabelLayoutBaseTest::initToggleLabelTypeOption(const ax::Size& size)
|
2015-11-19 16:06:13 +08:00
|
|
|
|
{
|
|
|
|
|
auto label = Label::createWithSystemFont("Toggle Label Type:", "Arial", 10);
|
|
|
|
|
label->setColor(Color3B::WHITE);
|
|
|
|
|
label->setPosition(Vec2(size.width * 0.8f + 15, size.height * 0.8f));
|
|
|
|
|
this->addChild(label);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
|
|
|
|
CheckBox* checkBox = CheckBox::create("cocosui/check_box_normal.png", "cocosui/check_box_normal_press.png",
|
|
|
|
|
"cocosui/check_box_active.png", "cocosui/check_box_normal_disable.png",
|
2015-11-19 16:06:13 +08:00
|
|
|
|
"cocosui/check_box_active_disable.png");
|
|
|
|
|
checkBox->setPosition(Vec2(size.width * 0.8f + 70, size.height * 0.8f));
|
|
|
|
|
checkBox->setScale(0.5);
|
|
|
|
|
checkBox->setName("toggleType");
|
|
|
|
|
checkBox->setSelected(true);
|
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
|
auto stepper = (ControlStepper*)this->getChildByName("stepper");
|
2015-11-19 16:06:13 +08:00
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
|
checkBox->addEventListener([=](Ref* ref, CheckBox::EventType event) {
|
|
|
|
|
float fontSize = stepper->getValue();
|
2015-11-19 16:06:13 +08:00
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
|
if (event == CheckBox::EventType::SELECTED)
|
|
|
|
|
{
|
|
|
|
|
_labelType = 0;
|
|
|
|
|
auto ttfConfig = _label->getTTFConfig();
|
2015-11-19 16:06:13 +08:00
|
|
|
|
ttfConfig.fontSize = fontSize;
|
|
|
|
|
_label->setTTFConfig(ttfConfig);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2015-11-19 16:06:13 +08:00
|
|
|
|
_labelType = 1;
|
|
|
|
|
_label->setBMFontFilePath("fonts/enligsh-chinese.fnt");
|
|
|
|
|
_label->setBMFontSize(fontSize);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
this->addChild(checkBox);
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-18 19:17:36 +08:00
|
|
|
|
void LabelLayoutBaseTest::initAlignmentOption(const ax::Size& size)
|
2015-11-19 16:06:13 +08:00
|
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
|
// add text alignment settings
|
2015-11-19 16:06:13 +08:00
|
|
|
|
MenuItemFont::setFontSize(30);
|
|
|
|
|
auto menu = Menu::create(
|
2022-07-15 19:17:01 +08:00
|
|
|
|
MenuItemFont::create("Left", AX_CALLBACK_1(LabelLayoutBaseTest::setAlignmentLeft, this)),
|
|
|
|
|
MenuItemFont::create("Center", AX_CALLBACK_1(LabelLayoutBaseTest::setAlignmentCenter, this)),
|
|
|
|
|
MenuItemFont::create("Right", AX_CALLBACK_1(LabelLayoutBaseTest::setAlignmentRight, this)), nullptr);
|
2015-11-19 16:06:13 +08:00
|
|
|
|
menu->alignItemsVerticallyWithPadding(4);
|
2019-09-24 11:31:35 +08:00
|
|
|
|
menu->setPosition(Vec2(50.0f, size.height / 2 - 20));
|
2015-11-19 16:06:13 +08:00
|
|
|
|
this->addChild(menu);
|
|
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
|
menu = Menu::create(MenuItemFont::create("Top", AX_CALLBACK_1(LabelLayoutBaseTest::setAlignmentTop, this)),
|
|
|
|
|
MenuItemFont::create("Middle", AX_CALLBACK_1(LabelLayoutBaseTest::setAlignmentMiddle, this)),
|
|
|
|
|
MenuItemFont::create("Bottom", AX_CALLBACK_1(LabelLayoutBaseTest::setAlignmentBottom, this)),
|
2021-12-28 16:06:23 +08:00
|
|
|
|
nullptr);
|
2015-11-19 16:06:13 +08:00
|
|
|
|
menu->alignItemsVerticallyWithPadding(4);
|
|
|
|
|
menu->setPosition(Vec2(size.width - 50, size.height / 2 - 20));
|
|
|
|
|
this->addChild(menu);
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-18 19:17:36 +08:00
|
|
|
|
void LabelLayoutBaseTest::initSliders(const ax::Size& size)
|
2015-11-19 16:06:13 +08:00
|
|
|
|
{
|
|
|
|
|
auto slider = ui::Slider::create();
|
|
|
|
|
slider->setTag(1);
|
|
|
|
|
slider->setTouchEnabled(true);
|
|
|
|
|
slider->loadBarTexture("cocosui/sliderTrack.png");
|
|
|
|
|
slider->loadSlidBallTextures("cocosui/sliderThumb.png", "cocosui/sliderThumb.png", "");
|
|
|
|
|
slider->loadProgressBarTexture("cocosui/sliderProgress.png");
|
|
|
|
|
slider->setPosition(Vec2(size.width / 2.0f, size.height * 0.15f + slider->getContentSize().height * 2.0f - 5));
|
|
|
|
|
slider->setPercent(52);
|
|
|
|
|
addChild(slider);
|
|
|
|
|
|
|
|
|
|
auto slider2 = ui::Slider::create();
|
|
|
|
|
slider2->setTag(2);
|
|
|
|
|
slider2->setTouchEnabled(true);
|
|
|
|
|
slider2->loadBarTexture("cocosui/sliderTrack.png");
|
|
|
|
|
slider2->loadSlidBallTextures("cocosui/sliderThumb.png", "cocosui/sliderThumb.png", "");
|
|
|
|
|
slider2->loadProgressBarTexture("cocosui/sliderProgress.png");
|
2019-09-24 11:31:35 +08:00
|
|
|
|
slider2->setPosition(Vec2(size.width * 0.2f, size.height / 2.0f));
|
2015-11-19 16:06:13 +08:00
|
|
|
|
slider2->setRotation(90);
|
|
|
|
|
slider2->setPercent(52);
|
|
|
|
|
addChild(slider2);
|
|
|
|
|
auto winSize = Director::getInstance()->getVisibleSize();
|
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
|
slider->addEventListener([=](Ref* ref, Slider::EventType event) {
|
|
|
|
|
float percent = slider->getPercent();
|
|
|
|
|
auto labelSize = _label->getContentSize();
|
2015-11-19 16:06:13 +08:00
|
|
|
|
auto drawNodeSize = Size(percent / 100.0 * winSize.width, labelSize.height);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
if (drawNodeSize.width <= 0)
|
|
|
|
|
{
|
2015-11-19 16:06:13 +08:00
|
|
|
|
drawNodeSize.width = 0.1f;
|
|
|
|
|
}
|
|
|
|
|
_label->setDimensions(drawNodeSize.width, drawNodeSize.height);
|
|
|
|
|
this->updateDrawNodeSize(drawNodeSize);
|
|
|
|
|
});
|
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
|
slider2->addEventListener([=](Ref* ref, Slider::EventType event) {
|
|
|
|
|
float percent = slider2->getPercent();
|
|
|
|
|
auto labelSize = _label->getContentSize();
|
|
|
|
|
auto drawNodeSize = Size(labelSize.width, percent / 100.0 * winSize.height);
|
|
|
|
|
if (drawNodeSize.height <= 0)
|
|
|
|
|
{
|
2015-11-19 16:06:13 +08:00
|
|
|
|
drawNodeSize.height = 0.1f;
|
|
|
|
|
}
|
|
|
|
|
_label->setDimensions(drawNodeSize.width, drawNodeSize.height);
|
|
|
|
|
this->updateDrawNodeSize(drawNodeSize);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-18 19:17:36 +08:00
|
|
|
|
void LabelLayoutBaseTest::initTestLabel(const ax::Size& size)
|
2015-11-19 16:06:13 +08:00
|
|
|
|
{
|
|
|
|
|
auto center = VisibleRect::center();
|
|
|
|
|
_label = Label::createWithTTF("五六七八This is a very long sentence一二三四.", "fonts/HKYuanMini.ttf", 20);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
_label->setDimensions(size.width / 2, size.height / 2);
|
2015-11-19 16:06:13 +08:00
|
|
|
|
_label->setPosition(center);
|
|
|
|
|
_label->setName("Label");
|
|
|
|
|
_label->setString("五六七八This is a very long sentence一二三.");
|
|
|
|
|
addChild(_label);
|
|
|
|
|
_labelType = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-18 19:17:36 +08:00
|
|
|
|
void LabelLayoutBaseTest::initDrawNode(const ax::Size& size)
|
2015-11-19 16:06:13 +08:00
|
|
|
|
{
|
|
|
|
|
_drawNode = DrawNode::create();
|
|
|
|
|
|
|
|
|
|
_drawNode->setTag(3);
|
|
|
|
|
addChild(_drawNode);
|
|
|
|
|
this->updateDrawNodeSize(_label->getContentSize());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void LabelLayoutBaseTest::setAlignmentLeft(Ref* sender)
|
|
|
|
|
{
|
|
|
|
|
_label->setHorizontalAlignment(TextHAlignment::LEFT);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void LabelLayoutBaseTest::setAlignmentCenter(Ref* sender)
|
|
|
|
|
{
|
|
|
|
|
_label->setHorizontalAlignment(TextHAlignment::CENTER);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void LabelLayoutBaseTest::setAlignmentRight(Ref* sender)
|
|
|
|
|
{
|
|
|
|
|
_label->setHorizontalAlignment(TextHAlignment::RIGHT);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void LabelLayoutBaseTest::setAlignmentTop(Ref* sender)
|
|
|
|
|
{
|
|
|
|
|
_label->setVerticalAlignment(TextVAlignment::TOP);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void LabelLayoutBaseTest::setAlignmentMiddle(Ref* sender)
|
|
|
|
|
{
|
|
|
|
|
_label->setVerticalAlignment(TextVAlignment::CENTER);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void LabelLayoutBaseTest::setAlignmentBottom(Ref* sender)
|
|
|
|
|
{
|
|
|
|
|
_label->setVerticalAlignment(TextVAlignment::BOTTOM);
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-18 19:17:36 +08:00
|
|
|
|
void LabelLayoutBaseTest::valueChanged(ax::Ref* sender, ax::extension::Control::EventType controlEvent)
|
2015-11-19 16:06:13 +08:00
|
|
|
|
{
|
|
|
|
|
ControlStepper* pControl = (ControlStepper*)sender;
|
|
|
|
|
// Change value of label.
|
|
|
|
|
auto fontSizeLabel = (Label*)this->getChildByName("fontSize");
|
2021-12-28 16:06:23 +08:00
|
|
|
|
float fontSize = (float)pControl->getValue();
|
2015-11-19 16:06:13 +08:00
|
|
|
|
fontSizeLabel->setString(StringUtils::format("font size:%d", (int)fontSize));
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
|
|
|
|
if (_labelType == 0)
|
|
|
|
|
{
|
|
|
|
|
auto ttfConfig = _label->getTTFConfig();
|
2015-11-19 16:06:13 +08:00
|
|
|
|
ttfConfig.fontSize = fontSize;
|
|
|
|
|
_label->setTTFConfig(ttfConfig);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
}
|
|
|
|
|
else if (_labelType == 1)
|
|
|
|
|
{
|
2015-11-19 16:06:13 +08:00
|
|
|
|
_label->setBMFontSize(fontSize);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
}
|
|
|
|
|
else if (_labelType == 2)
|
|
|
|
|
{
|
2016-06-15 10:43:15 +08:00
|
|
|
|
_label->setSystemFontSize(fontSize);
|
2015-11-19 16:06:13 +08:00
|
|
|
|
}
|
|
|
|
|
this->updateDrawNodeSize(_label->getContentSize());
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
|
|
|
|
// FIXME::When calling getLetter, the label Overflow feature will be invalid.
|
|
|
|
|
// auto letterSprite = _label->getLetter(1);
|
|
|
|
|
// auto moveBy = ScaleBy::create(1.0,2.0);
|
|
|
|
|
// letterSprite->stopAllActions();
|
|
|
|
|
// letterSprite->runAction(Sequence::create(moveBy, moveBy->clone()->reverse(), nullptr ));
|
|
|
|
|
//
|
2022-07-16 10:43:05 +08:00
|
|
|
|
// AXLOG("label line height = %f", _label->getLineHeight());
|
2015-11-19 16:06:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-10-18 19:17:36 +08:00
|
|
|
|
void LabelLayoutBaseTest::updateDrawNodeSize(const ax::Size& drawNodeSize)
|
2015-11-19 16:06:13 +08:00
|
|
|
|
{
|
|
|
|
|
auto origin = Director::getInstance()->getWinSize();
|
|
|
|
|
auto labelSize = _label->getContentSize();
|
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
|
origin.width = origin.width / 2 - (labelSize.width / 2);
|
2015-11-19 16:06:13 +08:00
|
|
|
|
origin.height = origin.height / 2 - (labelSize.height / 2);
|
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
|
Vec2 vertices[4] = {Vec2(origin.width, origin.height), Vec2(drawNodeSize.width + origin.width, origin.height),
|
|
|
|
|
Vec2(drawNodeSize.width + origin.width, drawNodeSize.height + origin.height),
|
|
|
|
|
Vec2(origin.width, drawNodeSize.height + origin.height)};
|
2015-11-19 16:06:13 +08:00
|
|
|
|
_drawNode->clear();
|
2019-09-24 11:31:35 +08:00
|
|
|
|
_drawNode->drawLine(vertices[0], vertices[1], Color4F(1.0f, 1.0f, 1.0f, 1.0f));
|
|
|
|
|
_drawNode->drawLine(vertices[0], vertices[3], Color4F(1.0f, 1.0f, 1.0f, 1.0f));
|
|
|
|
|
_drawNode->drawLine(vertices[2], vertices[3], Color4F(1.0f, 1.0f, 1.0f, 1.0f));
|
|
|
|
|
_drawNode->drawLine(vertices[1], vertices[2], Color4F(1.0f, 1.0f, 1.0f, 1.0f));
|
2015-11-19 16:06:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LabelWrapByWordTest::LabelWrapByWordTest()
|
|
|
|
|
{
|
|
|
|
|
_label->setLineSpacing(5);
|
|
|
|
|
_label->setAdditionalKerning(2);
|
|
|
|
|
_label->setVerticalAlignment(TextVAlignment::CENTER);
|
|
|
|
|
_label->setOverflow(Label::Overflow::CLAMP);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelWrapByWordTest::title() const
|
|
|
|
|
{
|
|
|
|
|
return "Clamp content Test: Word Wrap";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelWrapByWordTest::subtitle() const
|
|
|
|
|
{
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LabelWrapByCharTest::LabelWrapByCharTest()
|
|
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
|
_label->setLineBreakWithoutSpace(true);
|
2015-11-19 18:14:46 +08:00
|
|
|
|
_label->setString("五六七八This \nis a very long sentence一二三四.");
|
2015-11-19 16:06:13 +08:00
|
|
|
|
_label->setLineSpacing(5);
|
|
|
|
|
_label->setAdditionalKerning(2);
|
|
|
|
|
_label->setVerticalAlignment(TextVAlignment::TOP);
|
|
|
|
|
_label->setOverflow(Label::Overflow::CLAMP);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelWrapByCharTest::title() const
|
|
|
|
|
{
|
|
|
|
|
return "Clamp content Test: Char Wrap";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelWrapByCharTest::subtitle() const
|
|
|
|
|
{
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-13 09:40:24 +08:00
|
|
|
|
/////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
LabelWrapNoBreakSpaceTest::LabelWrapNoBreakSpaceTest()
|
|
|
|
|
{
|
|
|
|
|
_label->setLineBreakWithoutSpace(false);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
const char* no_break_space_utf8 = "\xC2\xA0"; // 0xA0 - no-break space
|
|
|
|
|
auto str = StringUtils::format(
|
|
|
|
|
"The price is $%s1.25. \n\nthe space between \"$\" and \"1.25\" is a no break space.", no_break_space_utf8);
|
2018-03-13 09:40:24 +08:00
|
|
|
|
_label->setString(str);
|
|
|
|
|
_label->setVerticalAlignment(TextVAlignment::TOP);
|
2018-04-25 09:50:53 +08:00
|
|
|
|
_label->setOverflow(Label::Overflow::CLAMP);
|
2018-03-13 09:40:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelWrapNoBreakSpaceTest::title() const
|
|
|
|
|
{
|
|
|
|
|
return "Wrap Test: No break space";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelWrapNoBreakSpaceTest::subtitle() const
|
|
|
|
|
{
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////
|
|
|
|
|
|
2015-11-19 16:06:13 +08:00
|
|
|
|
LabelShrinkByWordTest::LabelShrinkByWordTest()
|
|
|
|
|
{
|
|
|
|
|
_label->setLineSpacing(5);
|
|
|
|
|
_label->setAdditionalKerning(2);
|
|
|
|
|
_label->setString("This is Hello World hehe I love 一二三");
|
|
|
|
|
_label->setVerticalAlignment(TextVAlignment::TOP);
|
|
|
|
|
_label->setOverflow(Label::Overflow::SHRINK);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelShrinkByWordTest::title() const
|
|
|
|
|
{
|
|
|
|
|
return "Shrink content Test: Word Wrap";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelShrinkByWordTest::subtitle() const
|
|
|
|
|
{
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LabelShrinkByCharTest::LabelShrinkByCharTest()
|
|
|
|
|
{
|
|
|
|
|
_label->setLineSpacing(5);
|
|
|
|
|
_label->setAdditionalKerning(2);
|
|
|
|
|
_label->setLineBreakWithoutSpace(true);
|
|
|
|
|
_label->setString("This is Hello World hehe I love 一二三");
|
|
|
|
|
_label->setVerticalAlignment(TextVAlignment::CENTER);
|
|
|
|
|
_label->setOverflow(Label::Overflow::SHRINK);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelShrinkByCharTest::title() const
|
|
|
|
|
{
|
|
|
|
|
return "Shrink content Test: Char Wrap";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelShrinkByCharTest::subtitle() const
|
|
|
|
|
{
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LabelResizeTest::LabelResizeTest()
|
|
|
|
|
{
|
|
|
|
|
_label->setLineSpacing(5);
|
|
|
|
|
_label->setAdditionalKerning(2);
|
|
|
|
|
_label->setVerticalAlignment(TextVAlignment::TOP);
|
|
|
|
|
_label->setOverflow(Label::Overflow::RESIZE_HEIGHT);
|
|
|
|
|
|
|
|
|
|
this->updateDrawNodeSize(_label->getContentSize());
|
|
|
|
|
|
|
|
|
|
auto slider1 = (ui::Slider*)this->getChildByTag(1);
|
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
|
auto slider2 = (ui::Slider*)this->getChildByTag(2);
|
|
|
|
|
slider2->setVisible(false);
|
|
|
|
|
|
2015-11-19 16:06:13 +08:00
|
|
|
|
auto winSize = Director::getInstance()->getVisibleSize();
|
2021-12-28 16:06:23 +08:00
|
|
|
|
slider1->addEventListener([=](Ref* ref, Slider::EventType event) {
|
|
|
|
|
float percent = slider1->getPercent();
|
|
|
|
|
auto drawNodeSize = Size(percent / 100.0 * winSize.width, _label->getContentSize().height);
|
|
|
|
|
if (drawNodeSize.height <= 0)
|
|
|
|
|
{
|
2015-11-19 16:06:13 +08:00
|
|
|
|
drawNodeSize.height = 0.1f;
|
|
|
|
|
}
|
|
|
|
|
_label->setDimensions(drawNodeSize.width, drawNodeSize.height);
|
|
|
|
|
this->updateDrawNodeSize(drawNodeSize);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
auto stepper = (ControlStepper*)this->getChildByName("stepper");
|
|
|
|
|
stepper->setValue(12);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
2015-11-23 17:47:30 +08:00
|
|
|
|
auto label = Label::createWithSystemFont("Char Line break:", "Arial", 10);
|
2015-11-19 16:06:13 +08:00
|
|
|
|
label->setColor(Color3B::WHITE);
|
|
|
|
|
label->setPosition(Vec2(winSize.width * 0.1f, winSize.height * 0.8f));
|
|
|
|
|
this->addChild(label);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
|
|
|
|
CheckBox* checkBox = CheckBox::create("cocosui/check_box_normal.png", "cocosui/check_box_normal_press.png",
|
|
|
|
|
"cocosui/check_box_active.png", "cocosui/check_box_normal_disable.png",
|
2015-11-19 16:06:13 +08:00
|
|
|
|
"cocosui/check_box_active_disable.png");
|
2021-12-28 16:06:23 +08:00
|
|
|
|
checkBox->setPosition(Vec2(winSize.width * 0.2f, winSize.height * 0.8f));
|
2015-11-19 16:06:13 +08:00
|
|
|
|
checkBox->setScale(0.5);
|
|
|
|
|
checkBox->setSelected(false);
|
|
|
|
|
checkBox->setName("LineBreak");
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
|
|
|
|
checkBox->addEventListener([=](Ref* ref, CheckBox::EventType event) {
|
|
|
|
|
if (event == CheckBox::EventType::SELECTED)
|
|
|
|
|
{
|
2015-11-19 16:06:13 +08:00
|
|
|
|
_label->setLineBreakWithoutSpace(true);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2015-11-19 16:06:13 +08:00
|
|
|
|
_label->setLineBreakWithoutSpace(false);
|
|
|
|
|
}
|
|
|
|
|
this->updateDrawNodeSize(_label->getContentSize());
|
|
|
|
|
});
|
|
|
|
|
this->addChild(checkBox);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelResizeTest::title() const
|
|
|
|
|
{
|
|
|
|
|
return "Resize content Test";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelResizeTest::subtitle() const
|
|
|
|
|
{
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LabelToggleTypeTest::LabelToggleTypeTest()
|
|
|
|
|
{
|
|
|
|
|
_label->setLineSpacing(5);
|
|
|
|
|
_label->setAdditionalKerning(2);
|
|
|
|
|
_label->setVerticalAlignment(TextVAlignment::CENTER);
|
2016-01-05 09:51:37 +08:00
|
|
|
|
_label->setOverflow(Label::Overflow::NONE);
|
2015-11-19 16:06:13 +08:00
|
|
|
|
|
|
|
|
|
this->updateDrawNodeSize(_label->getContentSize());
|
|
|
|
|
|
|
|
|
|
auto slider1 = (ui::Slider*)this->getChildByTag(1);
|
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
|
auto slider2 = (ui::Slider*)this->getChildByTag(2);
|
|
|
|
|
slider2->setVisible(false);
|
2015-11-19 16:06:13 +08:00
|
|
|
|
|
|
|
|
|
auto winSize = Director::getInstance()->getVisibleSize();
|
2021-12-28 16:06:23 +08:00
|
|
|
|
slider1->addEventListener([=](Ref* ref, Slider::EventType event) {
|
|
|
|
|
float percent = slider1->getPercent();
|
|
|
|
|
auto drawNodeSize = Size(percent / 100.0 * winSize.width, _label->getContentSize().height);
|
|
|
|
|
if (drawNodeSize.height <= 0)
|
|
|
|
|
{
|
2015-11-19 16:06:13 +08:00
|
|
|
|
drawNodeSize.height = 0.1f;
|
|
|
|
|
}
|
|
|
|
|
_label->setDimensions(drawNodeSize.width, drawNodeSize.height);
|
|
|
|
|
this->updateDrawNodeSize(drawNodeSize);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
auto stepper = (ControlStepper*)this->getChildByName("stepper");
|
|
|
|
|
stepper->setValue(12);
|
|
|
|
|
|
2015-11-23 17:47:30 +08:00
|
|
|
|
auto label = Label::createWithSystemFont("Char Line break:", "Arial", 10);
|
2015-11-19 16:06:13 +08:00
|
|
|
|
label->setColor(Color3B::WHITE);
|
|
|
|
|
label->setPosition(Vec2(winSize.width * 0.1f, winSize.height * 0.8f));
|
|
|
|
|
this->addChild(label);
|
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
|
CheckBox* checkBox = CheckBox::create("cocosui/check_box_normal.png", "cocosui/check_box_normal_press.png",
|
|
|
|
|
"cocosui/check_box_active.png", "cocosui/check_box_normal_disable.png",
|
2015-11-19 16:06:13 +08:00
|
|
|
|
"cocosui/check_box_active_disable.png");
|
2021-12-28 16:06:23 +08:00
|
|
|
|
checkBox->setPosition(Vec2(winSize.width * 0.2f, winSize.height * 0.8f));
|
2015-11-19 16:06:13 +08:00
|
|
|
|
checkBox->setScale(0.5);
|
|
|
|
|
checkBox->setSelected(false);
|
|
|
|
|
checkBox->setName("LineBreak");
|
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
|
checkBox->addEventListener([=](Ref* ref, CheckBox::EventType event) {
|
|
|
|
|
if (event == CheckBox::EventType::SELECTED)
|
|
|
|
|
{
|
2015-11-19 16:06:13 +08:00
|
|
|
|
_label->setLineBreakWithoutSpace(true);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2015-11-19 16:06:13 +08:00
|
|
|
|
_label->setLineBreakWithoutSpace(false);
|
|
|
|
|
}
|
|
|
|
|
this->updateDrawNodeSize(_label->getContentSize());
|
|
|
|
|
});
|
|
|
|
|
this->addChild(checkBox);
|
|
|
|
|
|
|
|
|
|
this->initToggleCheckboxes();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void LabelToggleTypeTest::initToggleCheckboxes()
|
|
|
|
|
{
|
|
|
|
|
const float BUTTON_WIDTH = 100;
|
2021-12-28 16:06:23 +08:00
|
|
|
|
float startPosX = 0;
|
|
|
|
|
Size winSize = Director::getInstance()->getVisibleSize();
|
2015-11-19 16:06:13 +08:00
|
|
|
|
|
|
|
|
|
// Create a radio button group
|
|
|
|
|
auto radioButtonGroup = RadioButtonGroup::create();
|
|
|
|
|
this->addChild(radioButtonGroup);
|
|
|
|
|
|
|
|
|
|
// Create the radio buttons
|
2021-12-28 16:06:23 +08:00
|
|
|
|
static const int NUMBER_OF_BUTTONS = 4;
|
|
|
|
|
startPosX = winSize.width / 2.0f - (NUMBER_OF_BUTTONS - 1) * 0.5 * BUTTON_WIDTH - 30;
|
2015-11-19 16:06:13 +08:00
|
|
|
|
std::vector<std::string> labelTypes = {"Normal", "Clamp", "Shrink", "RESIZE"};
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
|
|
|
|
for (int i = 0; i < NUMBER_OF_BUTTONS; ++i)
|
2015-11-19 16:06:13 +08:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
RadioButton* radioButton = RadioButton::create("cocosui/radio_button_off.png", "cocosui/radio_button_on.png");
|
2021-12-28 16:06:23 +08:00
|
|
|
|
float posX = startPosX + BUTTON_WIDTH * i;
|
2015-11-19 16:06:13 +08:00
|
|
|
|
radioButton->setPosition(Vec2(posX, winSize.height / 2.0f + 70));
|
|
|
|
|
radioButton->setScale(1.2f);
|
2022-07-15 19:17:01 +08:00
|
|
|
|
radioButton->addEventListener(AX_CALLBACK_2(LabelToggleTypeTest::onChangedRadioButtonSelect, this));
|
2015-11-19 16:06:13 +08:00
|
|
|
|
radioButton->setTag(i);
|
|
|
|
|
radioButtonGroup->addRadioButton(radioButton);
|
|
|
|
|
this->addChild(radioButton);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
2015-11-19 16:06:13 +08:00
|
|
|
|
auto label = Label::createWithSystemFont(labelTypes.at(i), "Arial", 20);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
label->setPosition(radioButton->getPosition() + Vec2(50.0f, 0.0f));
|
2015-11-19 16:06:13 +08:00
|
|
|
|
this->addChild(label);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelToggleTypeTest::title() const
|
|
|
|
|
{
|
|
|
|
|
return "Toggle Label Type Test";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelToggleTypeTest::subtitle() const
|
|
|
|
|
{
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void LabelToggleTypeTest::onChangedRadioButtonSelect(RadioButton* radioButton, RadioButton::EventType type)
|
|
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
|
if (radioButton == nullptr)
|
2015-11-19 16:06:13 +08:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
2015-11-19 16:06:13 +08:00
|
|
|
|
switch (type)
|
|
|
|
|
{
|
|
|
|
|
case RadioButton::EventType::SELECTED:
|
|
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
|
switch (radioButton->getTag())
|
|
|
|
|
{
|
|
|
|
|
case 0:
|
|
|
|
|
_label->setOverflow(Label::Overflow::NONE);
|
|
|
|
|
break;
|
|
|
|
|
case 1:
|
|
|
|
|
_label->setOverflow(Label::Overflow::CLAMP);
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
_label->setOverflow(Label::Overflow::SHRINK);
|
|
|
|
|
break;
|
|
|
|
|
case 3:
|
|
|
|
|
_label->setOverflow(Label::Overflow::RESIZE_HEIGHT);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
2015-11-19 16:06:13 +08:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
auto checkbox = (CheckBox*)(this->getChildByName("toggleWrap"));
|
|
|
|
|
checkbox->setSelected(_label->isWrapEnabled());
|
|
|
|
|
this->updateDrawNodeSize(_label->getContentSize());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LabelSystemFontTest::LabelSystemFontTest()
|
|
|
|
|
{
|
|
|
|
|
_label->setLineSpacing(5);
|
|
|
|
|
_label->setVerticalAlignment(TextVAlignment::CENTER);
|
2016-06-15 10:43:15 +08:00
|
|
|
|
_label->setOverflow(Label::Overflow::NONE);
|
|
|
|
|
_label->setSystemFontName("Hiragino Sans GB");
|
|
|
|
|
_label->setSystemFontSize(20);
|
|
|
|
|
_label->enableOutline(Color4B::RED, 1.0);
|
|
|
|
|
_label->setString("This is a very\n 我爱你中国\n long sentence");
|
|
|
|
|
_labelType = 2;
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
2015-11-20 16:39:48 +08:00
|
|
|
|
auto stepper = (ControlStepper*)this->getChildByName("stepper");
|
2016-06-15 10:43:15 +08:00
|
|
|
|
stepper->setEnabled(true);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
2015-11-20 16:39:48 +08:00
|
|
|
|
auto checkbox = (CheckBox*)(this->getChildByName("toggleType"));
|
|
|
|
|
checkbox->setEnabled(false);
|
2015-11-19 16:06:13 +08:00
|
|
|
|
|
|
|
|
|
this->updateDrawNodeSize(_label->getContentSize());
|
|
|
|
|
|
|
|
|
|
auto slider1 = (ui::Slider*)this->getChildByTag(1);
|
|
|
|
|
|
|
|
|
|
auto winSize = Director::getInstance()->getVisibleSize();
|
2021-12-28 16:06:23 +08:00
|
|
|
|
slider1->addEventListener([=](Ref* ref, Slider::EventType event) {
|
|
|
|
|
float percent = slider1->getPercent();
|
|
|
|
|
auto drawNodeSize = Size(percent / 100.0 * winSize.width, _label->getContentSize().height);
|
|
|
|
|
if (drawNodeSize.height <= 0)
|
|
|
|
|
{
|
2015-11-19 16:06:13 +08:00
|
|
|
|
drawNodeSize.height = 0.1f;
|
|
|
|
|
}
|
|
|
|
|
_label->setDimensions(drawNodeSize.width, drawNodeSize.height);
|
|
|
|
|
this->updateDrawNodeSize(drawNodeSize);
|
|
|
|
|
});
|
|
|
|
|
|
2015-11-23 17:47:30 +08:00
|
|
|
|
auto label = Label::createWithSystemFont("char Line break:", "Arial", 10);
|
2015-11-19 16:06:13 +08:00
|
|
|
|
label->setColor(Color3B::WHITE);
|
|
|
|
|
label->setPosition(Vec2(winSize.width * 0.1f, winSize.height * 0.8f));
|
|
|
|
|
this->addChild(label);
|
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
|
CheckBox* checkBox = CheckBox::create("cocosui/check_box_normal.png", "cocosui/check_box_normal_press.png",
|
|
|
|
|
"cocosui/check_box_active.png", "cocosui/check_box_normal_disable.png",
|
2015-11-19 16:06:13 +08:00
|
|
|
|
"cocosui/check_box_active_disable.png");
|
2021-12-28 16:06:23 +08:00
|
|
|
|
checkBox->setPosition(Vec2(winSize.width * 0.2f, winSize.height * 0.8f));
|
2015-11-19 16:06:13 +08:00
|
|
|
|
checkBox->setScale(0.5);
|
|
|
|
|
checkBox->setSelected(false);
|
|
|
|
|
checkBox->setName("LineBreak");
|
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
|
checkBox->addEventListener([=](Ref* ref, CheckBox::EventType event) {
|
|
|
|
|
if (event == CheckBox::EventType::SELECTED)
|
|
|
|
|
{
|
2015-11-19 16:06:13 +08:00
|
|
|
|
_label->setLineBreakWithoutSpace(true);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2015-11-19 16:06:13 +08:00
|
|
|
|
_label->setLineBreakWithoutSpace(false);
|
|
|
|
|
}
|
|
|
|
|
this->updateDrawNodeSize(_label->getContentSize());
|
|
|
|
|
});
|
|
|
|
|
this->addChild(checkBox);
|
|
|
|
|
|
|
|
|
|
this->initToggleCheckboxes();
|
2016-06-15 10:43:15 +08:00
|
|
|
|
|
|
|
|
|
auto checkboxToggleWrap = (CheckBox*)(this->getChildByName("toggleWrap"));
|
|
|
|
|
checkboxToggleWrap->setEnabled(true);
|
2015-11-19 16:06:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void LabelSystemFontTest::initToggleCheckboxes()
|
|
|
|
|
{
|
|
|
|
|
const float BUTTON_WIDTH = 100;
|
2021-12-28 16:06:23 +08:00
|
|
|
|
float startPosX = 0;
|
|
|
|
|
Size winSize = Director::getInstance()->getVisibleSize();
|
2015-11-19 16:06:13 +08:00
|
|
|
|
|
|
|
|
|
// Create a radio button group
|
|
|
|
|
auto radioButtonGroup = RadioButtonGroup::create();
|
|
|
|
|
this->addChild(radioButtonGroup);
|
|
|
|
|
|
|
|
|
|
// Create the radio buttons
|
2021-12-28 16:06:23 +08:00
|
|
|
|
static const int NUMBER_OF_BUTTONS = 4;
|
|
|
|
|
startPosX = winSize.width / 2.0f - (NUMBER_OF_BUTTONS - 1) * 0.5 * BUTTON_WIDTH - 30;
|
2015-11-19 16:06:13 +08:00
|
|
|
|
std::vector<std::string> labelTypes = {"Normal", "Clamp", "Shrink", "RESIZE"};
|
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
|
for (int i = 0; i < NUMBER_OF_BUTTONS; ++i)
|
2015-11-19 16:06:13 +08:00
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
RadioButton* radioButton = RadioButton::create("cocosui/radio_button_off.png", "cocosui/radio_button_on.png");
|
2021-12-28 16:06:23 +08:00
|
|
|
|
float posX = startPosX + BUTTON_WIDTH * i;
|
2015-11-19 16:06:13 +08:00
|
|
|
|
radioButton->setPosition(Vec2(posX, winSize.height / 2.0f + 70));
|
|
|
|
|
radioButton->setScale(1.2f);
|
2022-07-15 19:17:01 +08:00
|
|
|
|
radioButton->addEventListener(AX_CALLBACK_2(LabelSystemFontTest::onChangedRadioButtonSelect, this));
|
2015-11-19 16:06:13 +08:00
|
|
|
|
radioButton->setTag(i);
|
|
|
|
|
radioButtonGroup->addRadioButton(radioButton);
|
|
|
|
|
this->addChild(radioButton);
|
|
|
|
|
|
|
|
|
|
auto label = Label::createWithSystemFont(labelTypes.at(i), "Arial", 20);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
label->setPosition(radioButton->getPosition() + Vec2(50.0f, 0.0f));
|
2015-11-19 16:06:13 +08:00
|
|
|
|
this->addChild(label);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelSystemFontTest::title() const
|
|
|
|
|
{
|
|
|
|
|
return "System Font Test";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelSystemFontTest::subtitle() const
|
|
|
|
|
{
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void LabelSystemFontTest::onChangedRadioButtonSelect(RadioButton* radioButton, RadioButton::EventType type)
|
|
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
|
if (radioButton == nullptr)
|
2015-11-19 16:06:13 +08:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (type)
|
|
|
|
|
{
|
|
|
|
|
case RadioButton::EventType::SELECTED:
|
|
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
|
switch (radioButton->getTag())
|
|
|
|
|
{
|
|
|
|
|
case 0:
|
|
|
|
|
_label->setOverflow(Label::Overflow::NONE);
|
|
|
|
|
break;
|
|
|
|
|
case 1:
|
|
|
|
|
_label->setOverflow(Label::Overflow::CLAMP);
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
_label->setOverflow(Label::Overflow::SHRINK);
|
|
|
|
|
break;
|
|
|
|
|
case 3:
|
|
|
|
|
_label->setOverflow(Label::Overflow::RESIZE_HEIGHT);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
2015-11-19 16:06:13 +08:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
this->updateDrawNodeSize(_label->getContentSize());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LabelCharMapFontTest::LabelCharMapFontTest()
|
|
|
|
|
{
|
|
|
|
|
_label->setLineSpacing(5);
|
|
|
|
|
_label->setVerticalAlignment(TextVAlignment::CENTER);
|
2016-01-05 09:51:37 +08:00
|
|
|
|
_label->setOverflow(Label::Overflow::NONE);
|
2015-11-19 16:06:13 +08:00
|
|
|
|
_label->setCharMap("fonts/tuffy_bold_italic-charmap.plist");
|
|
|
|
|
_label->setString("Hello World, This is a char map test.");
|
|
|
|
|
_label->setScale(0.5f);
|
|
|
|
|
|
|
|
|
|
auto stepper = (ControlStepper*)this->getChildByName("stepper");
|
2016-06-15 10:43:15 +08:00
|
|
|
|
stepper->setEnabled(true);
|
2015-11-19 16:06:13 +08:00
|
|
|
|
|
|
|
|
|
auto checkbox = (CheckBox*)(this->getChildByName("toggleType"));
|
|
|
|
|
checkbox->setEnabled(false);
|
|
|
|
|
|
|
|
|
|
this->updateDrawNodeSize(_label->getContentSize());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelCharMapFontTest::title() const
|
|
|
|
|
{
|
|
|
|
|
return "CharMap Font Test";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelCharMapFontTest::subtitle() const
|
|
|
|
|
{
|
|
|
|
|
return "";
|
|
|
|
|
}
|
2015-12-16 14:59:33 +08:00
|
|
|
|
|
|
|
|
|
LabelIssue13846Test::LabelIssue13846Test()
|
|
|
|
|
{
|
|
|
|
|
auto center = VisibleRect::center();
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
2015-12-16 14:59:33 +08:00
|
|
|
|
auto label = Label::createWithTTF("12345", "fonts/arial.ttf", 26);
|
|
|
|
|
label->setPosition(center);
|
|
|
|
|
addChild(label);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
2015-12-16 14:59:33 +08:00
|
|
|
|
label->getLetter(2)->setVisible(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelIssue13846Test::title() const
|
|
|
|
|
{
|
|
|
|
|
return "Test for Issue #13846";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelIssue13846Test::subtitle() const
|
|
|
|
|
{
|
2017-03-20 11:45:17 +08:00
|
|
|
|
return "Test hide label's letter,the label should display '12 45' as expected";
|
2015-12-16 14:59:33 +08:00
|
|
|
|
}
|
2016-01-20 12:41:31 +08:00
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
LabelRichText::LabelRichText()
|
|
|
|
|
{
|
|
|
|
|
auto center = VisibleRect::center();
|
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
|
auto richText2 = RichText::createWithXML(
|
|
|
|
|
"Mixing <b>UIRichText</b> with non <i>UIWidget</i> code. For more samples, see the UIRichTextTest.cpp file");
|
2016-01-20 12:41:31 +08:00
|
|
|
|
if (richText2)
|
|
|
|
|
{
|
|
|
|
|
richText2->ignoreContentAdaptWithSize(false);
|
2019-09-24 11:31:35 +08:00
|
|
|
|
richText2->setContentSize(Size(400.0f, 400.0f));
|
2018-04-25 09:50:53 +08:00
|
|
|
|
richText2->setPosition(center);
|
2016-01-20 12:41:31 +08:00
|
|
|
|
|
|
|
|
|
addChild(richText2);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelRichText::title() const
|
|
|
|
|
{
|
|
|
|
|
return "RichText";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelRichText::subtitle() const
|
|
|
|
|
{
|
|
|
|
|
return "Testing RichText";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LabelItalics::LabelItalics()
|
|
|
|
|
{
|
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
|
|
|
|
|
|
// LabelBMFont
|
2021-12-28 16:06:23 +08:00
|
|
|
|
auto label1 =
|
|
|
|
|
Label::createWithBMFont("fonts/bitmapFontTest2.fnt", "hello non-italics", TextHAlignment::CENTER, s.width);
|
2016-01-20 12:41:31 +08:00
|
|
|
|
addChild(label1, 0, kTagBitmapAtlas1);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
label1->setPosition(Vec2(s.width / 2, s.height * 4 / 6));
|
2016-01-20 12:41:31 +08:00
|
|
|
|
// you can enable italics by calling this method
|
|
|
|
|
|
|
|
|
|
_label1a = Label::createWithBMFont("fonts/bitmapFontTest2.fnt", "hello italics", TextHAlignment::CENTER, s.width);
|
|
|
|
|
addChild(_label1a, 0, kTagBitmapAtlas1);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
_label1a->setPosition(Vec2(s.width / 2, s.height * 3 / 6));
|
2016-01-20 12:41:31 +08:00
|
|
|
|
// you can enable italics by calling this method
|
|
|
|
|
_label1a->enableItalics();
|
|
|
|
|
|
|
|
|
|
// LabelTTF
|
2021-12-28 16:06:23 +08:00
|
|
|
|
TTFConfig ttfConfig("fonts/arial.ttf", 24);
|
|
|
|
|
auto label2 = Label::createWithTTF(ttfConfig, "hello non-italics", TextHAlignment::CENTER, s.width);
|
2016-01-20 12:41:31 +08:00
|
|
|
|
addChild(label2, 0, kTagBitmapAtlas2);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
label2->setPosition(Vec2(s.width / 2, s.height * 2 / 6));
|
2016-01-20 12:41:31 +08:00
|
|
|
|
|
|
|
|
|
// or by setting the italics parameter on TTFConfig
|
|
|
|
|
ttfConfig.italics = true;
|
2021-12-28 16:06:23 +08:00
|
|
|
|
_label2a = Label::createWithTTF(ttfConfig, "hello italics", TextHAlignment::CENTER, s.width);
|
2016-01-20 12:41:31 +08:00
|
|
|
|
addChild(_label2a, 0, kTagBitmapAtlas2);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
_label2a->setPosition(Vec2(s.width / 2, s.height * 1 / 6));
|
2016-01-20 12:41:31 +08:00
|
|
|
|
|
2022-10-18 19:17:36 +08:00
|
|
|
|
auto menuItem = MenuItemFont::create("disable italics", [&](ax::Ref* sender) {
|
2016-01-20 12:41:31 +08:00
|
|
|
|
_label2a->disableEffect(LabelEffect::ITALICS);
|
|
|
|
|
_label1a->disableEffect(LabelEffect::ITALICS);
|
|
|
|
|
});
|
|
|
|
|
menuItem->setFontSizeObj(12);
|
|
|
|
|
auto menu = Menu::createWithItem(menuItem);
|
|
|
|
|
addChild(menu);
|
|
|
|
|
auto winSize = Director::getInstance()->getWinSize();
|
|
|
|
|
menu->setPosition(winSize.width * 0.9, winSize.height * 0.25f);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelItalics::title() const
|
|
|
|
|
{
|
|
|
|
|
return "Testing Italics";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelItalics::subtitle() const
|
|
|
|
|
{
|
|
|
|
|
return "italics on TTF and BMfont";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
|
|
LabelBold::LabelBold()
|
|
|
|
|
{
|
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
|
|
|
|
|
|
// LabelBMFont
|
2021-12-28 16:06:23 +08:00
|
|
|
|
auto label1 =
|
|
|
|
|
Label::createWithBMFont("fonts/bitmapFontTest2.fnt", "hello non-bold", TextHAlignment::CENTER, s.width);
|
2016-01-20 12:41:31 +08:00
|
|
|
|
addChild(label1, 0, kTagBitmapAtlas1);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
label1->setPosition(Vec2(s.width / 2, s.height * 4 / 6));
|
2016-01-20 12:41:31 +08:00
|
|
|
|
// you can enable italics by calling this method
|
|
|
|
|
|
|
|
|
|
_label1a = Label::createWithBMFont("fonts/bitmapFontTest2.fnt", "hello bold", TextHAlignment::CENTER, s.width);
|
|
|
|
|
addChild(_label1a, 0, kTagBitmapAtlas1);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
_label1a->setPosition(Vec2(s.width / 2, s.height * 3 / 6));
|
2016-01-20 12:41:31 +08:00
|
|
|
|
// you can enable italics by calling this method
|
|
|
|
|
_label1a->enableBold();
|
|
|
|
|
|
|
|
|
|
// LabelTTF
|
2021-12-28 16:06:23 +08:00
|
|
|
|
TTFConfig ttfConfig("fonts/arial.ttf", 24);
|
|
|
|
|
auto label2 = Label::createWithTTF(ttfConfig, "hello non-bold", TextHAlignment::CENTER, s.width);
|
2016-01-20 12:41:31 +08:00
|
|
|
|
addChild(label2, 0, kTagBitmapAtlas2);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
label2->setPosition(Vec2(s.width / 2, s.height * 2 / 6));
|
2016-01-20 12:41:31 +08:00
|
|
|
|
|
|
|
|
|
// or by setting the italics parameter on TTFConfig
|
|
|
|
|
ttfConfig.bold = true;
|
2021-12-28 16:06:23 +08:00
|
|
|
|
_label2a = Label::createWithTTF(ttfConfig, "hello bold", TextHAlignment::CENTER, s.width);
|
2016-01-20 12:41:31 +08:00
|
|
|
|
addChild(_label2a, 0, kTagBitmapAtlas2);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
_label2a->setPosition(Vec2(s.width / 2, s.height * 1 / 6));
|
2016-01-20 12:41:31 +08:00
|
|
|
|
|
2022-10-18 19:17:36 +08:00
|
|
|
|
auto menuItem = MenuItemFont::create("disable bold", [&](ax::Ref* sender) {
|
2016-01-20 12:41:31 +08:00
|
|
|
|
_label2a->disableEffect(LabelEffect::BOLD);
|
|
|
|
|
_label1a->disableEffect(LabelEffect::BOLD);
|
|
|
|
|
});
|
|
|
|
|
menuItem->setFontSizeObj(12);
|
|
|
|
|
auto menu = Menu::createWithItem(menuItem);
|
|
|
|
|
addChild(menu);
|
|
|
|
|
auto winSize = Director::getInstance()->getWinSize();
|
|
|
|
|
menu->setPosition(winSize.width * 0.9, winSize.height * 0.25f);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelBold::title() const
|
|
|
|
|
{
|
|
|
|
|
return "Testing Bold";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelBold::subtitle() const
|
|
|
|
|
{
|
|
|
|
|
return "Bold on TTF and BMfont";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
|
|
LabelUnderline::LabelUnderline()
|
|
|
|
|
{
|
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
|
|
|
|
|
|
// LabelBMFont
|
2021-12-28 16:06:23 +08:00
|
|
|
|
auto label1 =
|
|
|
|
|
Label::createWithBMFont("fonts/bitmapFontTest2.fnt", "hello non-underline", TextHAlignment::CENTER, s.width);
|
2016-01-20 12:41:31 +08:00
|
|
|
|
addChild(label1, 0, kTagBitmapAtlas1);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
label1->setPosition(Vec2(s.width / 2, s.height * 4 / 6));
|
2016-01-20 12:41:31 +08:00
|
|
|
|
// you can enable italics by calling this method
|
|
|
|
|
|
|
|
|
|
_label1a = Label::createWithBMFont("fonts/bitmapFontTest2.fnt", "hello underline", TextHAlignment::CENTER, s.width);
|
|
|
|
|
addChild(_label1a, 0, kTagBitmapAtlas1);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
_label1a->setPosition(Vec2(s.width / 2, s.height * 3 / 6));
|
2016-01-20 12:41:31 +08:00
|
|
|
|
// you can enable underline by calling this method
|
|
|
|
|
_label1a->enableUnderline();
|
|
|
|
|
|
|
|
|
|
// LabelTTF
|
2021-12-28 16:06:23 +08:00
|
|
|
|
TTFConfig ttfConfig("fonts/arial.ttf", 24);
|
|
|
|
|
auto label2 = Label::createWithTTF(ttfConfig, "hello non-underline", TextHAlignment::CENTER, s.width);
|
2016-01-20 12:41:31 +08:00
|
|
|
|
addChild(label2, 0, kTagBitmapAtlas2);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
label2->setPosition(Vec2(s.width / 2, s.height * 2 / 6));
|
2016-01-20 12:41:31 +08:00
|
|
|
|
|
|
|
|
|
// or by setting the italics parameter on TTFConfig
|
|
|
|
|
ttfConfig.underline = true;
|
2021-12-28 16:06:23 +08:00
|
|
|
|
_label2a = Label::createWithTTF(ttfConfig, "hello underline", TextHAlignment::CENTER, s.width);
|
2016-01-20 12:41:31 +08:00
|
|
|
|
addChild(_label2a, 0, kTagBitmapAtlas2);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
_label2a->setPosition(Vec2(s.width / 2, s.height * 1 / 6));
|
2016-01-20 12:41:31 +08:00
|
|
|
|
|
2022-10-18 19:17:36 +08:00
|
|
|
|
auto menuItem = MenuItemFont::create("disable underline", [&](ax::Ref* sender) {
|
2016-01-20 12:41:31 +08:00
|
|
|
|
_label2a->disableEffect(LabelEffect::UNDERLINE);
|
|
|
|
|
_label1a->disableEffect(LabelEffect::UNDERLINE);
|
|
|
|
|
});
|
|
|
|
|
menuItem->setFontSizeObj(12);
|
|
|
|
|
auto menu = Menu::createWithItem(menuItem);
|
|
|
|
|
addChild(menu);
|
|
|
|
|
auto winSize = Director::getInstance()->getWinSize();
|
|
|
|
|
menu->setPosition(winSize.width * 0.9, winSize.height * 0.25f);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelUnderline::title() const
|
|
|
|
|
{
|
|
|
|
|
return "Testing Underline";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelUnderline::subtitle() const
|
|
|
|
|
{
|
|
|
|
|
return "Underline on TTF and BMfont";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
|
|
LabelUnderlineMultiline::LabelUnderlineMultiline()
|
|
|
|
|
{
|
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
|
|
|
|
|
|
// bmfont
|
2021-12-28 16:06:23 +08:00
|
|
|
|
_label1a = Label::createWithBMFont("fonts/bitmapFontTest5.fnt", "hello underline\nand multiline",
|
|
|
|
|
TextHAlignment::CENTER, s.width);
|
2016-01-20 12:41:31 +08:00
|
|
|
|
addChild(_label1a, 0, kTagBitmapAtlas1);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
_label1a->setPosition(Vec2(s.width / 2, s.height * 2 / 3));
|
2016-01-20 12:41:31 +08:00
|
|
|
|
// you can enable underline by calling this method
|
|
|
|
|
_label1a->enableUnderline();
|
|
|
|
|
|
|
|
|
|
// ttf
|
2021-12-28 16:06:23 +08:00
|
|
|
|
TTFConfig ttfConfig("fonts/arial.ttf", 24);
|
2016-01-20 12:41:31 +08:00
|
|
|
|
ttfConfig.underline = true;
|
|
|
|
|
_label2a = Label::createWithTTF(ttfConfig, "hello\nunderline\nwith multiline", TextHAlignment::LEFT, s.width);
|
|
|
|
|
addChild(_label2a, 0, kTagBitmapAtlas2);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
_label2a->setPosition(Vec2(s.width / 2, s.height * 1 / 3));
|
2016-01-20 12:41:31 +08:00
|
|
|
|
|
2022-10-18 19:17:36 +08:00
|
|
|
|
auto menuItem = MenuItemFont::create("disable underline", [&](ax::Ref* sender) {
|
2016-01-20 12:41:31 +08:00
|
|
|
|
_label2a->disableEffect(LabelEffect::UNDERLINE);
|
|
|
|
|
_label1a->disableEffect(LabelEffect::UNDERLINE);
|
|
|
|
|
});
|
|
|
|
|
menuItem->setFontSizeObj(12);
|
|
|
|
|
auto menu = Menu::createWithItem(menuItem);
|
|
|
|
|
addChild(menu);
|
|
|
|
|
auto winSize = Director::getInstance()->getWinSize();
|
|
|
|
|
menu->setPosition(winSize.width * 0.9, winSize.height * 0.25f);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelUnderlineMultiline::title() const
|
|
|
|
|
{
|
|
|
|
|
return "Testing Underline + multiline";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelUnderlineMultiline::subtitle() const
|
|
|
|
|
{
|
|
|
|
|
return "Underline on TTF and BMfont with multiline";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
///
|
|
|
|
|
|
|
|
|
|
LabelStrikethrough::LabelStrikethrough()
|
|
|
|
|
{
|
|
|
|
|
auto s = Director::getInstance()->getWinSize();
|
|
|
|
|
|
|
|
|
|
// bmfont
|
2021-12-28 16:06:23 +08:00
|
|
|
|
_label1a = Label::createWithBMFont("fonts/bitmapFontTest4.fnt", "hello strikethrough\nand multiline",
|
|
|
|
|
TextHAlignment::LEFT, s.width);
|
2016-01-20 12:41:31 +08:00
|
|
|
|
addChild(_label1a, 0, kTagBitmapAtlas1);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
_label1a->setPosition(Vec2(s.width / 2, s.height * 2 / 3));
|
2016-01-20 12:41:31 +08:00
|
|
|
|
// you can enable underline by calling this method
|
|
|
|
|
_label1a->enableStrikethrough();
|
|
|
|
|
|
|
|
|
|
// ttf
|
2021-12-28 16:06:23 +08:00
|
|
|
|
TTFConfig ttfConfig("fonts/arial.ttf", 24);
|
2016-01-20 12:41:31 +08:00
|
|
|
|
ttfConfig.strikethrough = true;
|
|
|
|
|
_label2a = Label::createWithTTF(ttfConfig, "hello\nstrikethrough\nwith multiline", TextHAlignment::RIGHT, s.width);
|
|
|
|
|
addChild(_label2a, 0, kTagBitmapAtlas2);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
_label2a->setPosition(Vec2(s.width / 2, s.height * 1 / 3));
|
2016-01-20 12:41:31 +08:00
|
|
|
|
|
2022-10-18 19:17:36 +08:00
|
|
|
|
auto menuItem = MenuItemFont::create("disable underline", [&](ax::Ref* sender) {
|
2016-01-20 12:41:31 +08:00
|
|
|
|
_label2a->disableEffect(LabelEffect::STRIKETHROUGH);
|
|
|
|
|
_label1a->disableEffect(LabelEffect::STRIKETHROUGH);
|
|
|
|
|
});
|
|
|
|
|
menuItem->setFontSizeObj(12);
|
|
|
|
|
auto menu = Menu::createWithItem(menuItem);
|
|
|
|
|
addChild(menu);
|
|
|
|
|
auto winSize = Director::getInstance()->getWinSize();
|
|
|
|
|
menu->setPosition(winSize.width * 0.9, winSize.height * 0.25f);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelStrikethrough::title() const
|
|
|
|
|
{
|
|
|
|
|
return "Testing Strikethrough + multiline";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelStrikethrough::subtitle() const
|
|
|
|
|
{
|
|
|
|
|
return "Strikethrough on TTF and BMfont with multiline";
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-26 17:15:24 +08:00
|
|
|
|
LabelLocalizationTest::LabelLocalizationTest()
|
|
|
|
|
{
|
2019-05-09 16:30:19 +08:00
|
|
|
|
_localizationJson = cocostudio::JsonLocalizationManager::getInstance();
|
|
|
|
|
_localizationJson->initLanguageData("configs/en-US.lang.json");
|
|
|
|
|
|
|
|
|
|
_localizationBin = cocostudio::BinLocalizationManager::getInstance();
|
|
|
|
|
_localizationBin->initLanguageData("configs/ENGLISH.lang.csb");
|
|
|
|
|
|
|
|
|
|
const float BUTTON_WIDTH = 100;
|
2021-12-28 16:06:23 +08:00
|
|
|
|
float startPosX = 0;
|
|
|
|
|
Size winSize = Director::getInstance()->getVisibleSize();
|
2019-05-09 16:30:19 +08:00
|
|
|
|
|
|
|
|
|
// Create a radio button group
|
|
|
|
|
auto radioButtonGroup = RadioButtonGroup::create();
|
|
|
|
|
this->addChild(radioButtonGroup);
|
|
|
|
|
|
|
|
|
|
// Create the radio buttons
|
2021-12-28 16:06:23 +08:00
|
|
|
|
const int NUMBER_OF_BUTTONS = 3;
|
|
|
|
|
startPosX = winSize.width / 2.0f - (NUMBER_OF_BUTTONS - 1) * 0.5 * BUTTON_WIDTH - 30;
|
|
|
|
|
std::vector<std::string> labelTypes = {"English", "Chinese", "Japanese"};
|
2019-05-09 16:30:19 +08:00
|
|
|
|
|
|
|
|
|
for (int i = 0; i < NUMBER_OF_BUTTONS; ++i)
|
|
|
|
|
{
|
|
|
|
|
RadioButton* radioButton = RadioButton::create("cocosui/radio_button_off.png", "cocosui/radio_button_on.png");
|
2021-12-28 16:06:23 +08:00
|
|
|
|
float posX = startPosX + BUTTON_WIDTH * i;
|
2019-05-09 16:30:19 +08:00
|
|
|
|
radioButton->setPosition(Vec2(posX, winSize.height / 2.0f + 70));
|
|
|
|
|
radioButton->setScale(1.2f);
|
2022-07-15 19:17:01 +08:00
|
|
|
|
radioButton->addEventListener(AX_CALLBACK_2(LabelLocalizationTest::onChangedRadioButtonSelect, this));
|
2019-05-09 16:30:19 +08:00
|
|
|
|
radioButton->setTag(i);
|
|
|
|
|
radioButtonGroup->addRadioButton(radioButton);
|
|
|
|
|
this->addChild(radioButton);
|
|
|
|
|
|
|
|
|
|
auto label = Label::createWithSystemFont(labelTypes.at(i), "Arial", 20);
|
2019-09-24 11:31:35 +08:00
|
|
|
|
label->setPosition(radioButton->getPosition() + Vec2(50.0f, 0.0f));
|
2019-05-09 16:30:19 +08:00
|
|
|
|
this->addChild(label);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_label1 = Label::createWithSystemFont(_localizationJson->getLocalizationString("Text Label"), "Arial", 24);
|
|
|
|
|
addChild(_label1, 0);
|
|
|
|
|
_label1->setPosition(Vec2(winSize.width / 2, winSize.height * 1 / 3));
|
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
|
Label* label = Label::createWithSystemFont("From json data :", "Arial", 24);
|
2019-09-24 11:31:35 +08:00
|
|
|
|
label->setAnchorPoint(Vec2(0.0f, 0.5f));
|
2019-05-09 16:30:19 +08:00
|
|
|
|
addChild(label, 0);
|
2019-09-24 11:31:35 +08:00
|
|
|
|
label->setPosition(Vec2(20.0f, winSize.height * 1 / 3 + 24));
|
2019-05-09 16:30:19 +08:00
|
|
|
|
|
|
|
|
|
_label2 = Label::createWithSystemFont(_localizationBin->getLocalizationString("Text Label"), "Arial", 24);
|
|
|
|
|
addChild(_label2, 0);
|
|
|
|
|
_label2->setPosition(Vec2(winSize.width / 2, winSize.height * 1 / 2));
|
|
|
|
|
|
|
|
|
|
label = Label::createWithSystemFont("From binary data :", "Arial", 24);
|
2019-09-24 11:31:35 +08:00
|
|
|
|
label->setAnchorPoint(Vec2(0.0f, 0.5f));
|
2019-05-09 16:30:19 +08:00
|
|
|
|
addChild(label, 0);
|
2019-09-24 11:31:35 +08:00
|
|
|
|
label->setPosition(Vec2(20.0f, winSize.height * 1 / 2 + 24));
|
2016-02-26 17:15:24 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelLocalizationTest::title() const
|
|
|
|
|
{
|
|
|
|
|
return "Localization Test";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelLocalizationTest::subtitle() const
|
|
|
|
|
{
|
|
|
|
|
return "Change language selected and see label change";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void LabelLocalizationTest::onChangedRadioButtonSelect(RadioButton* radioButton, RadioButton::EventType type)
|
|
|
|
|
{
|
|
|
|
|
if (radioButton == nullptr)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (type)
|
|
|
|
|
{
|
|
|
|
|
case RadioButton::EventType::SELECTED:
|
|
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
|
switch (radioButton->getTag())
|
|
|
|
|
{
|
2016-02-26 17:15:24 +08:00
|
|
|
|
case 0:
|
|
|
|
|
_localizationJson->initLanguageData("configs/en-US.lang.json");
|
|
|
|
|
_label1->setString(_localizationJson->getLocalizationString("Text Label"));
|
|
|
|
|
_localizationBin->initLanguageData("configs/ENGLISH.lang.csb");
|
2016-12-13 16:33:11 +08:00
|
|
|
|
_label2->setString(_localizationBin->getLocalizationString("Text Label"));
|
2016-02-26 17:15:24 +08:00
|
|
|
|
break;
|
|
|
|
|
case 1:
|
|
|
|
|
_localizationJson->initLanguageData("configs/zh-CN.lang.json");
|
|
|
|
|
_label1->setString(_localizationJson->getLocalizationString("Text Label"));
|
|
|
|
|
_localizationBin->initLanguageData("configs/CHINESE.lang.csb");
|
2016-12-13 16:33:11 +08:00
|
|
|
|
_label2->setString(_localizationBin->getLocalizationString("Text Label"));
|
2016-02-26 17:15:24 +08:00
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
_localizationJson->initLanguageData("configs/ja-JP.lang.json");
|
|
|
|
|
_label1->setString(_localizationJson->getLocalizationString("Text Label"));
|
|
|
|
|
_localizationBin->initLanguageData("configs/JAPANESE.lang.csb");
|
2016-12-13 16:33:11 +08:00
|
|
|
|
_label2->setString(_localizationBin->getLocalizationString("Text Label"));
|
2016-02-26 17:15:24 +08:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-06-18 08:23:59 +08:00
|
|
|
|
|
2016-09-01 11:20:13 +08:00
|
|
|
|
//
|
|
|
|
|
// LabelIssue15214
|
|
|
|
|
//
|
2016-06-18 08:23:59 +08:00
|
|
|
|
LabelIssue15214::LabelIssue15214()
|
|
|
|
|
{
|
|
|
|
|
auto size = Director::getInstance()->getVisibleSize();
|
2016-09-01 11:20:13 +08:00
|
|
|
|
|
|
|
|
|
// 1
|
|
|
|
|
Label* label = Label::createWithTTF("TTF with setColor()", "fonts/arial.ttf", 24.0f);
|
2016-06-18 08:23:59 +08:00
|
|
|
|
label->enableUnderline();
|
2022-10-18 19:17:36 +08:00
|
|
|
|
label->setColor(ax::Color3B::BLUE);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
label->setPosition(size.width / 2, size.height / 5 * 4);
|
2016-06-18 08:23:59 +08:00
|
|
|
|
this->addChild(label);
|
2016-09-01 11:20:13 +08:00
|
|
|
|
|
|
|
|
|
// 2
|
|
|
|
|
Label* label2 = Label::createWithSystemFont("System with setColor()", "Verdana", 24.0f);
|
|
|
|
|
label2->enableUnderline();
|
2022-10-18 19:17:36 +08:00
|
|
|
|
label2->setColor(ax::Color3B::BLUE);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
label2->setPosition(size.width / 2, size.height / 5 * 3);
|
2016-09-01 11:20:13 +08:00
|
|
|
|
this->addChild(label2);
|
|
|
|
|
|
|
|
|
|
// 3
|
|
|
|
|
Label* label3 = Label::createWithTTF("TTF with setTextColor()", "fonts/arial.ttf", 24.0f);
|
|
|
|
|
label3->enableUnderline();
|
|
|
|
|
label3->setTextColor(Color4B::BLUE);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
label3->setPosition(size.width / 2, size.height / 5 * 2);
|
2016-09-01 11:20:13 +08:00
|
|
|
|
this->addChild(label3);
|
|
|
|
|
|
|
|
|
|
// 4
|
|
|
|
|
Label* label4 = Label::createWithSystemFont("System with setTextColor()", "Verdana", 24.0f);
|
|
|
|
|
label4->enableUnderline();
|
|
|
|
|
label4->setTextColor(Color4B::BLUE);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
label4->setPosition(size.width / 2, size.height / 5 * 1);
|
2016-09-01 11:20:13 +08:00
|
|
|
|
this->addChild(label4);
|
2016-06-18 08:23:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelIssue15214::title() const
|
|
|
|
|
{
|
2016-09-01 11:20:13 +08:00
|
|
|
|
return "Github Issue 15214";
|
2016-06-18 08:23:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelIssue15214::subtitle() const
|
|
|
|
|
{
|
2016-09-01 16:59:40 +08:00
|
|
|
|
return "Font + underline: same color with setColor()";
|
2016-06-18 08:23:59 +08:00
|
|
|
|
}
|
2016-08-14 00:38:42 +08:00
|
|
|
|
|
2016-09-01 11:20:13 +08:00
|
|
|
|
//
|
|
|
|
|
// LabelIssue16293
|
|
|
|
|
//
|
2016-08-14 00:38:42 +08:00
|
|
|
|
LabelIssue16293::LabelIssue16293()
|
|
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
|
auto size = Director::getInstance()->getVisibleSize();
|
|
|
|
|
Label* label = Label::createWithTTF(
|
|
|
|
|
"012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789", "fonts/arial.ttf",
|
|
|
|
|
12);
|
|
|
|
|
label->setPosition(size.width / 2, size.height / 2);
|
2016-08-14 00:38:42 +08:00
|
|
|
|
this->addChild(label);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelIssue16293::title() const
|
|
|
|
|
{
|
2016-09-01 11:20:13 +08:00
|
|
|
|
return "Github Issue 16293";
|
2016-08-14 00:38:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelIssue16293::subtitle() const
|
|
|
|
|
{
|
|
|
|
|
return "No TextureAtlas resizes";
|
|
|
|
|
}
|
2016-09-01 11:20:13 +08:00
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// LabelIssue16471
|
|
|
|
|
//
|
|
|
|
|
LabelIssue16471::LabelIssue16471()
|
|
|
|
|
{
|
|
|
|
|
auto size = Director::getInstance()->getVisibleSize();
|
|
|
|
|
|
|
|
|
|
auto node = Node::create();
|
|
|
|
|
addChild(node, 100);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
node->setPosition(size.width / 2, size.height / 2);
|
2016-09-01 11:20:13 +08:00
|
|
|
|
|
|
|
|
|
// Used Google Translate to translate from Chinese:
|
|
|
|
|
// Here is set to false then textLabel: TextColor valid
|
|
|
|
|
// set to true testLabel: setTextColor invalid
|
|
|
|
|
// Original:
|
|
|
|
|
// 此处设置为false则testLabel:setTextColor有效
|
|
|
|
|
// 设置为true则testLabel:setTextColor无效
|
|
|
|
|
// if set false then testLabel:setTextColor is useful
|
|
|
|
|
node->setCascadeColorEnabled(true);
|
|
|
|
|
Label* label = Label::createWithTTF("Should be Yellow", "fonts/arial.ttf", 12);
|
|
|
|
|
label->setTextColor(Color4B::YELLOW);
|
|
|
|
|
node->addChild(label);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelIssue16471::title() const
|
|
|
|
|
{
|
|
|
|
|
return "Github Issue 16471";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelIssue16471::subtitle() const
|
|
|
|
|
{
|
|
|
|
|
return "Label should be yellow";
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-16 14:56:36 +08:00
|
|
|
|
//
|
|
|
|
|
// LabelIssue16717
|
|
|
|
|
//
|
|
|
|
|
LabelIssue16717::LabelIssue16717()
|
|
|
|
|
{
|
|
|
|
|
auto bg = Sprite::create("cocosui/Hello.png");
|
|
|
|
|
bg->setPosition(VisibleRect::center());
|
|
|
|
|
addChild(bg);
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
auto label = Label::createWithTTF("Hello World", "fonts/arial.ttf", 70);
|
2019-09-24 11:31:35 +08:00
|
|
|
|
label->setPosition(VisibleRect::center() + Vec2(0.0f, 40.0f));
|
2021-12-28 16:06:23 +08:00
|
|
|
|
label->enableOutline(Color4B(0, 255, 0, 100), 10); // Set 100 alpha for outline
|
|
|
|
|
label->setTextColor(Color4B(0, 0, 255, 100)); // Also set 100 alpha for text
|
2016-12-16 14:56:36 +08:00
|
|
|
|
addChild(label);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
auto label = Label::createWithTTF("Hello World", "fonts/arial.ttf", 70);
|
2019-09-24 11:31:35 +08:00
|
|
|
|
label->setPosition(VisibleRect::center() + Vec2(0.0f, -40.0f));
|
2021-12-28 16:06:23 +08:00
|
|
|
|
label->enableOutline(Color4B(0, 255, 0, 100), 10); // Set 100 alpha for outline
|
|
|
|
|
label->setTextColor(Color4B(0, 255, 0, 100)); // Also set 100 alpha for text
|
2016-12-16 14:56:36 +08:00
|
|
|
|
addChild(label);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelIssue16717::title() const
|
|
|
|
|
{
|
|
|
|
|
return "Github Issue 16717";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelIssue16717::subtitle() const
|
|
|
|
|
{
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-13 13:58:32 +08:00
|
|
|
|
//
|
|
|
|
|
// LabelIssueLineGap
|
|
|
|
|
//
|
|
|
|
|
LabelIssueLineGap::LabelIssueLineGap()
|
|
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
2017-02-13 13:58:32 +08:00
|
|
|
|
auto size = Director::getInstance()->getWinSize();
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
2017-02-13 13:58:32 +08:00
|
|
|
|
auto label1 = Label::createWithTTF("test \ntest", "fonts/FingerpopGap.ttf", 30);
|
|
|
|
|
label1->setPosition(Vec2(size.width / 3, size.height / 2));
|
|
|
|
|
addChild(label1);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
2017-02-13 13:58:32 +08:00
|
|
|
|
auto label2 = Label::createWithSystemFont("test \ntest", "fonts/FingerpopGap.ttf", 30);
|
2021-12-28 16:06:23 +08:00
|
|
|
|
label2->setPosition(Vec2(size.width / 3 * 1.8, size.height / 2));
|
2017-02-13 13:58:32 +08:00
|
|
|
|
addChild(label2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelIssueLineGap::title() const
|
|
|
|
|
{
|
|
|
|
|
return "Label line gap issue";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelIssueLineGap::subtitle() const
|
|
|
|
|
{
|
|
|
|
|
return "two label must have exactly the same position and distance between lines";
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-07 16:56:02 +08:00
|
|
|
|
//
|
|
|
|
|
// LabelIssue17902
|
|
|
|
|
//
|
|
|
|
|
LabelIssue17902::LabelIssue17902()
|
|
|
|
|
{
|
|
|
|
|
auto center = VisibleRect::center();
|
2021-12-28 16:06:23 +08:00
|
|
|
|
|
2017-06-07 16:56:02 +08:00
|
|
|
|
auto label = Label::createWithTTF("abcdefg\nhijklmn", "fonts/arial.ttf", 26);
|
|
|
|
|
label->setLineHeight(40);
|
|
|
|
|
label->setPosition(center);
|
|
|
|
|
addChild(label);
|
|
|
|
|
|
2022-07-15 19:17:01 +08:00
|
|
|
|
scheduleOnce(AX_CALLBACK_0(LabelIssue17902::purgeCachedData, this), 1.0f, "purge_cached_data");
|
2017-06-07 16:56:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void LabelIssue17902::purgeCachedData()
|
|
|
|
|
{
|
|
|
|
|
FontAtlasCache::purgeCachedData();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelIssue17902::title() const
|
|
|
|
|
{
|
|
|
|
|
return "Github Issue 17902";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelIssue17902::subtitle() const
|
|
|
|
|
{
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-17 11:49:47 +08:00
|
|
|
|
//
|
|
|
|
|
// LabelIssue20523
|
|
|
|
|
//
|
|
|
|
|
LabelIssue20523::LabelIssue20523()
|
|
|
|
|
{
|
2021-12-28 16:06:23 +08:00
|
|
|
|
auto size = Director::getInstance()->getWinSize();
|
2020-09-17 11:49:47 +08:00
|
|
|
|
auto _crashingLabel = Label::createWithTTF("0", "fonts/Marker Felt.ttf", 120);
|
|
|
|
|
_crashingLabel->setPosition(Vec2(size.width / 2, size.height / 2));
|
2022-10-18 19:17:36 +08:00
|
|
|
|
_crashingLabel->setColor(ax::Color3B(200, 200, 200));
|
2020-09-17 11:49:47 +08:00
|
|
|
|
addChild(_crashingLabel, 1);
|
|
|
|
|
//_crashingLabel->setWidth(size.width);
|
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
|
this->schedule(
|
|
|
|
|
[this, _crashingLabel](float) {
|
2020-09-17 11:49:47 +08:00
|
|
|
|
++_i;
|
|
|
|
|
_crashingLabel->setString(std::to_string(_i));
|
2021-12-28 16:06:23 +08:00
|
|
|
|
},
|
2022-07-15 19:17:01 +08:00
|
|
|
|
1, AX_REPEAT_FOREVER, 0, "repeat");
|
2020-09-17 11:49:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelIssue20523::title() const
|
|
|
|
|
{
|
|
|
|
|
return "Github Issue 20523";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string LabelIssue20523::subtitle() const
|
|
|
|
|
{
|
|
|
|
|
return "Should not crash after 7 seconds";
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-06 14:27:47 +08:00
|
|
|
|
//
|
|
|
|
|
// LabelLetterColorsTest
|
|
|
|
|
//
|
2021-12-28 16:06:23 +08:00
|
|
|
|
LabelLetterColorsTest::LabelLetterColorsTest()
|
|
|
|
|
{
|
2018-08-06 14:27:47 +08:00
|
|
|
|
auto center = VisibleRect::center();
|
|
|
|
|
|
|
|
|
|
auto label = Label::createWithTTF("", "fonts/arial.ttf", 24);
|
|
|
|
|
label->setPosition(center.x, center.y);
|
|
|
|
|
addChild(label);
|
|
|
|
|
|
|
|
|
|
label->setString("1\n2\n3");
|
|
|
|
|
setLetterColors(label, Color3B::RED);
|
|
|
|
|
|
|
|
|
|
label->setString("abcd\ne"); // Must not crash at here.
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
|
std::string LabelLetterColorsTest::title() const
|
|
|
|
|
{
|
2018-08-06 14:27:47 +08:00
|
|
|
|
return "Test for letter colors";
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-28 16:06:23 +08:00
|
|
|
|
std::string LabelLetterColorsTest::subtitle() const
|
|
|
|
|
{
|
2018-08-06 14:27:47 +08:00
|
|
|
|
return "Should not crash!";
|
|
|
|
|
}
|
2017-02-13 13:58:32 +08:00
|
|
|
|
|
2022-10-18 19:17:36 +08:00
|
|
|
|
void LabelLetterColorsTest::setLetterColors(ax::Label* label, const ax::Color3B& color)
|
2021-12-28 16:06:23 +08:00
|
|
|
|
{
|
2018-08-06 14:27:47 +08:00
|
|
|
|
int n = label->getStringLength();
|
2021-12-28 16:06:23 +08:00
|
|
|
|
for (int i = 0; i < n; ++i)
|
|
|
|
|
{
|
2018-08-06 14:27:47 +08:00
|
|
|
|
Sprite* letter = label->getLetter(i);
|
|
|
|
|
if (letter != nullptr)
|
|
|
|
|
letter->setColor(color);
|
|
|
|
|
}
|
|
|
|
|
}
|