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"
2013-08-13 04:29:54 +08:00
2014-03-05 15:54:40 +08:00
using namespace ui ;
2013-08-13 04:29:54 +08:00
enum {
kTagTileMap = 1 ,
kTagSpriteManager = 1 ,
kTagAnimation1 = 1 ,
kTagBitmapAtlas1 = 1 ,
kTagBitmapAtlas2 = 2 ,
kTagBitmapAtlas3 = 3 ,
} ;
enum {
kTagSprite1 ,
kTagSprite2 ,
kTagSprite3 ,
kTagSprite4 ,
kTagSprite5 ,
kTagSprite6 ,
kTagSprite7 ,
kTagSprite8 ,
} ;
//------------------------------------------------------------------
//
// AtlasDemoNew
//
//------------------------------------------------------------------
enum
{
IDC_NEXT = 100 ,
IDC_BACK ,
IDC_RESTART
} ;
Layer * nextAtlasActionNew ( ) ;
Layer * backAtlasActionNew ( ) ;
Layer * restartAtlasActionNew ( ) ;
static int sceneIdx = - 1 ;
static std : : function < Layer * ( ) > createFunctions [ ] =
{
CL ( LabelFNTColorAndOpacity ) ,
CL ( LabelFNTSpriteActions ) ,
CL ( LabelFNTPadding ) ,
CL ( LabelFNTOffset ) ,
CL ( LabelFNTColor ) ,
CL ( LabelFNTHundredLabels ) ,
CL ( LabelFNTMultiLine ) ,
CL ( LabelFNTandTTFEmpty ) ,
CL ( LabelFNTRetina ) ,
CL ( LabelFNTGlyphDesigner ) ,
CL ( LabelTTFUnicodeChinese ) ,
CL ( LabelFNTUnicodeChinese ) ,
CL ( LabelFNTMultiLineAlignment ) ,
CL ( LabelFNTUNICODELanguages ) ,
CL ( LabelTTFAlignmentNew ) ,
CL ( LabelFNTBounds ) ,
CL ( LabelTTFLongLineWrapping ) ,
CL ( LabelTTFColor ) ,
CL ( LabelTTFFontsTestNew ) ,
CL ( LabelTTFDynamicAlignment ) ,
2014-02-08 17:15:57 +08:00
CL ( LabelTTFCJKWrappingTest ) ,
2013-08-13 04:29:54 +08:00
CL ( LabelTTFUnicodeNew ) ,
2013-12-13 12:42:15 +08:00
CL ( LabelBMFontTestNew ) ,
CL ( LabelTTFDistanceField ) ,
2014-03-05 15:54:40 +08:00
CL ( LabelOutlineAndGlowTest ) ,
CL ( LabelShadowTest ) ,
2014-01-16 16:37:29 +08:00
CL ( LabelCharMapTest ) ,
2014-01-24 15:02:42 +08:00
CL ( LabelCharMapColorTest ) ,
2014-01-23 16:16:30 +08:00
CL ( LabelCrashTest ) ,
2014-03-07 14:58:44 +08:00
CL ( LabelTTFOldNew ) ,
2014-03-10 19:42:43 +08:00
CL ( LabelFontNameTest ) ,
2014-03-18 10:20:25 +08:00
CL ( LabelAlignmentTest ) ,
2014-05-29 14:00:38 +08:00
CL ( LabelIssue4428Test ) ,
2014-06-18 18:01:55 +08:00
CL ( LabelIssue4999Test ) ,
CL ( LabelLineHeightTest ) ,
2014-10-08 18:22:35 +08:00
CL ( LabelAdditionalKerningTest ) ,
2014-11-12 17:24:35 +08:00
CL ( LabelIssue8492Test ) ,
2014-11-27 11:03:11 +08:00
CL ( LabelMultilineWithOutline ) ,
2015-01-09 18:51:30 +08:00
CL ( LabelIssue9255Test ) ,
CL ( LabelSmallDimensionsTest )
2013-08-13 04:29:54 +08:00
} ;
# define MAX_LAYER (sizeof(createFunctions) / sizeof(createFunctions[0]))
Layer * nextAtlasActionNew ( )
{
sceneIdx + + ;
sceneIdx = sceneIdx % MAX_LAYER ;
2013-08-16 16:05:27 +08:00
auto layer = ( createFunctions [ sceneIdx ] ) ( ) ;
2013-08-13 04:29:54 +08:00
return layer ;
}
Layer * backAtlasActionNew ( )
{
sceneIdx - - ;
int total = MAX_LAYER ;
if ( sceneIdx < 0 )
sceneIdx + = total ;
2013-08-16 16:05:27 +08:00
auto layer = ( createFunctions [ sceneIdx ] ) ( ) ;
2013-08-13 04:29:54 +08:00
return layer ;
}
Layer * restartAtlasActionNew ( )
{
2013-08-16 16:05:27 +08:00
auto layer = ( createFunctions [ sceneIdx ] ) ( ) ;
2013-08-13 04:29:54 +08:00
return layer ;
}
void AtlasTestSceneNew : : runThisTest ( )
{
sceneIdx = - 1 ;
2013-08-16 16:05:27 +08:00
auto layer = nextAtlasActionNew ( ) ;
2013-08-13 04:29:54 +08:00
addChild ( layer ) ;
Director : : getInstance ( ) - > replaceScene ( this ) ;
}
AtlasDemoNew : : AtlasDemoNew ( void )
{
}
AtlasDemoNew : : ~ AtlasDemoNew ( void )
{
}
2013-12-19 05:52:10 +08:00
std : : string AtlasDemoNew : : title ( ) const
2013-08-13 04:29:54 +08:00
{
return " No title " ;
}
2013-12-19 05:52:10 +08:00
std : : string AtlasDemoNew : : subtitle ( ) const
2013-08-13 04:29:54 +08:00
{
return " " ;
}
void AtlasDemoNew : : onEnter ( )
{
BaseTest : : onEnter ( ) ;
}
2014-02-20 10:53:49 +08:00
void AtlasDemoNew : : restartCallback ( Ref * sender )
2013-08-13 04:29:54 +08:00
{
2014-08-28 07:31:57 +08:00
auto s = new ( std : : nothrow ) AtlasTestSceneNew ( ) ;
2013-08-13 04:29:54 +08:00
s - > addChild ( restartAtlasActionNew ( ) ) ;
Director : : getInstance ( ) - > replaceScene ( s ) ;
s - > release ( ) ;
}
2014-02-20 10:53:49 +08:00
void AtlasDemoNew : : nextCallback ( Ref * sender )
2013-08-13 04:29:54 +08:00
{
2014-08-28 07:31:57 +08:00
auto s = new ( std : : nothrow ) AtlasTestSceneNew ( ) ;
2013-08-13 04:29:54 +08:00
s - > addChild ( nextAtlasActionNew ( ) ) ;
Director : : getInstance ( ) - > replaceScene ( s ) ;
s - > release ( ) ;
}
2014-02-20 10:53:49 +08:00
void AtlasDemoNew : : backCallback ( Ref * sender )
2013-08-13 04:29:54 +08:00
{
2014-08-28 07:31:57 +08:00
auto s = new ( std : : nothrow ) AtlasTestSceneNew ( ) ;
2013-08-13 04:29:54 +08:00
s - > addChild ( backAtlasActionNew ( ) ) ;
Director : : getInstance ( ) - > replaceScene ( s ) ;
s - > release ( ) ;
}
LabelTTFAlignmentNew : : LabelTTFAlignmentNew ( )
{
2013-08-16 16:05:27 +08:00
auto s = Director : : getInstance ( ) - > getWinSize ( ) ;
2013-08-13 04:29:54 +08:00
2014-03-11 18:26:25 +08:00
TTFConfig config ( " fonts/tahoma.ttf " , 16 ) ;
2014-01-11 22:33:07 +08:00
auto ttf0 = Label : : createWithTTF ( config , " Alignment 0 \n new line " , TextHAlignment : : LEFT ) ;
2014-05-15 01:07:09 +08:00
ttf0 - > setPosition ( Vec2 ( s . width / 2 , ( s . height / 6 ) * 2 - 30 ) ) ;
2013-08-13 04:29:54 +08:00
this - > addChild ( ttf0 ) ;
2014-01-11 22:33:07 +08:00
auto ttf1 = Label : : createWithTTF ( config , " Alignment 1 \n new line " , TextHAlignment : : CENTER ) ;
2014-05-15 01:07:09 +08:00
ttf1 - > setPosition ( Vec2 ( s . width / 2 , ( s . height / 6 ) * 3 - 30 ) ) ;
2013-08-13 04:29:54 +08:00
this - > addChild ( ttf1 ) ;
2014-01-11 22:33:07 +08:00
auto ttf2 = Label : : createWithTTF ( config , " Alignment 2 \n new line " , TextHAlignment : : RIGHT ) ;
2014-05-15 01:07:09 +08:00
ttf2 - > setPosition ( Vec2 ( s . width / 2 , ( s . height / 6 ) * 4 - 30 ) ) ;
2013-08-13 04:29:54 +08:00
this - > addChild ( ttf2 ) ;
}
2013-12-19 05:52:10 +08:00
std : : string LabelTTFAlignmentNew : : title ( ) const
2013-08-13 04:29:54 +08:00
{
return " New Label + TTF " ;
}
2013-12-19 05:52:10 +08:00
std : : string LabelTTFAlignmentNew : : subtitle ( ) const
2013-08-13 04:29:54 +08:00
{
return " Tests alignment values " ;
}
LabelFNTColorAndOpacity : : LabelFNTColorAndOpacity ( )
{
_time = 0 ;
2013-08-16 16:05:27 +08:00
auto col = LayerColor : : create ( Color4B ( 128 , 128 , 128 , 255 ) ) ;
2013-08-13 04:29:54 +08:00
addChild ( col , - 10 ) ;
2014-01-11 22:33:07 +08:00
auto label1 = Label : : createWithBMFont ( " fonts/bitmapFontTest2.fnt " , " Test " ) ;
2013-08-13 04:29:54 +08:00
2014-05-15 01:07:09 +08:00
label1 - > setAnchorPoint ( Vec2 ( 0 , 0 ) ) ;
2013-08-13 04:29:54 +08:00
addChild ( label1 , 0 , kTagBitmapAtlas1 ) ;
2013-08-16 16:05:27 +08:00
auto fade = FadeOut : : create ( 1.0f ) ;
auto fade_in = fade - > reverse ( ) ;
2014-07-10 00:45:27 +08:00
auto seq = Sequence : : create ( fade , fade_in , nullptr ) ;
2013-08-16 16:05:27 +08:00
auto repeat = RepeatForever : : create ( seq ) ;
2013-08-13 04:29:54 +08:00
label1 - > runAction ( repeat ) ;
2014-01-11 22:33:07 +08:00
auto label2 = Label : : createWithBMFont ( " fonts/bitmapFontTest2.fnt " , " Test " ) ;
2013-08-13 04:29:54 +08:00
label2 - > setColor ( Color3B : : RED ) ;
addChild ( label2 , 0 , kTagBitmapAtlas2 ) ;
2014-01-24 15:02:42 +08:00
auto tint = Sequence : : create ( TintTo : : create ( 1 , 255 , 0 , 0 ) ,
TintTo : : create ( 1 , 0 , 255 , 0 ) ,
TintTo : : create ( 1 , 0 , 0 , 255 ) ,
2014-07-10 00:45:27 +08:00
nullptr ) ;
2014-01-24 15:02:42 +08:00
label2 - > runAction ( RepeatForever : : create ( tint ) ) ;
2013-08-13 04:29:54 +08:00
2014-01-11 22:33:07 +08:00
auto label3 = Label : : createWithBMFont ( " fonts/bitmapFontTest2.fnt " , " Test " ) ;
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 ) ;
label1 - > setPosition ( VisibleRect : : leftBottom ( ) ) ;
label2 - > setPosition ( VisibleRect : : center ( ) ) ;
label3 - > setPosition ( VisibleRect : : rightTop ( ) ) ;
2013-08-14 01:12:02 +08:00
2014-10-04 08:11:39 +08:00
schedule ( CC_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 ) ;
2013-08-16 16:05:27 +08:00
auto label1 = ( Label * ) getChildByTag ( kTagBitmapAtlas1 ) ;
2013-08-13 04:29:54 +08:00
label1 - > setString ( string ) ;
2013-08-16 16:05:27 +08:00
auto label2 = ( Label * ) getChildByTag ( kTagBitmapAtlas2 ) ;
2013-08-13 04:29:54 +08:00
label2 - > setString ( string ) ;
2013-08-16 16:05:27 +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
{
return " New Label + .FNT file " ;
}
2013-12-19 05:52:10 +08:00
std : : string LabelFNTColorAndOpacity : : subtitle ( ) const
2013-08-13 04:29:54 +08:00
{
return " Testing opacity + tint " ;
}
LabelFNTSpriteActions : : LabelFNTSpriteActions ( )
{
_time = 0 ;
2014-09-11 15:39:56 +08:00
auto s = Director : : getInstance ( ) - > getWinSize ( ) ;
auto drawNode = DrawNode : : create ( ) ;
drawNode - > drawLine ( Vec2 ( 0 , s . height / 2 ) , Vec2 ( s . width , s . height / 2 ) , Color4F ( 1.0 , 1.0 , 1.0 , 1.0 ) ) ;
drawNode - > drawLine ( Vec2 ( s . width / 2 , 0 ) , Vec2 ( s . width / 2 , s . height ) , Color4F ( 1.0 , 1.0 , 1.0 , 1.0 ) ) ;
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 ) ;
2014-05-15 01:07:09 +08:00
label - > setPosition ( Vec2 ( s . width / 2 , s . height / 2 ) ) ;
2013-08-13 04:29:54 +08:00
2013-10-31 20:17:30 +08:00
auto BChar = ( Sprite * ) label - > getLetter ( 0 ) ;
auto FChar = ( Sprite * ) label - > getLetter ( 7 ) ;
auto AChar = ( Sprite * ) label - > getLetter ( 12 ) ;
2013-08-13 04:29:54 +08:00
2013-08-16 16:05:27 +08:00
auto rotate = RotateBy : : create ( 2 , 360 ) ;
auto rot_4ever = RepeatForever : : create ( rotate ) ;
2013-08-13 04:29:54 +08:00
2013-08-16 16:05:27 +08:00
auto scale = ScaleBy : : create ( 2 , 1.5f ) ;
auto scale_back = scale - > reverse ( ) ;
2014-07-10 00:45:27 +08:00
auto scale_seq = Sequence : : create ( scale , scale_back , nullptr ) ;
2013-08-16 16:05:27 +08:00
auto scale_4ever = RepeatForever : : create ( scale_seq ) ;
2013-08-13 04:29:54 +08:00
2014-05-15 01:07:09 +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 ) ;
2013-08-13 04:29:54 +08:00
2013-08-16 16:05:27 +08:00
auto fade_out = FadeOut : : create ( 1 ) ;
auto fade_in = FadeIn : : create ( 1 ) ;
2014-07-10 00:45:27 +08:00
auto seq = Sequence : : create ( fade_out , fade_in , nullptr ) ;
2013-08-16 16:05:27 +08:00
auto fade_4ever = RepeatForever : : create ( seq ) ;
2013-08-13 04:29:54 +08:00
BChar - > runAction ( rot_4ever ) ;
BChar - > runAction ( scale_4ever ) ;
FChar - > runAction ( jump_4ever ) ;
AChar - > runAction ( fade_4ever ) ;
// 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 ) ;
2014-05-15 01:07:09 +08:00
label2 - > setPosition ( Vec2 ( s . width / 2.0f , 80 ) ) ;
2013-08-13 04:29:54 +08:00
2013-10-31 20:17:30 +08:00
auto lastChar = ( Sprite * ) label2 - > getLetter ( 3 ) ;
2013-08-13 04:29:54 +08:00
lastChar - > runAction ( rot_4ever - > clone ( ) ) ;
2014-10-04 08:11:39 +08:00
schedule ( CC_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 ) ;
2013-08-16 16:05:27 +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
{
return " New Label + .FNT file " ;
}
2013-12-19 05:52:10 +08:00
std : : string LabelFNTSpriteActions : : subtitle ( ) const
2013-08-13 04:29:54 +08:00
{
return " Using fonts as Sprite objects. Some characters should rotate. " ;
}
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 ) ;
2013-08-16 16:05:27 +08:00
auto s = Director : : getInstance ( ) - > getWinSize ( ) ;
2013-08-13 04:29:54 +08:00
2014-05-15 01:07:09 +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
{
return " New Label + .FNT file " ;
}
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 ;
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 ) ;
2014-05-15 01:07:09 +08:00
label - > setPosition ( Vec2 ( s . width / 2 , s . height / 2 + 50 ) ) ;
2013-08-13 04:29:54 +08:00
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 ) ;
2014-05-15 01:07:09 +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 ) ;
2014-05-15 01:07:09 +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
{
return " New Label + .FNT file " ;
}
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 ( )
{
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 ;
2014-01-11 22:33:07 +08:00
label = Label : : createWithBMFont ( " fonts/bitmapFontTest5.fnt " , " Blue " ) ;
2013-08-13 04:29:54 +08:00
label - > setColor ( Color3B : : BLUE ) ;
addChild ( label ) ;
2014-05-15 01:07:09 +08:00
label - > setPosition ( Vec2 ( s . width / 2 , s . height / 4 ) ) ;
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 ) ;
2014-05-15 01:07:09 +08:00
label - > setPosition ( Vec2 ( s . width / 2 , 2 * s . height / 4 ) ) ;
2013-08-13 04:29:54 +08:00
label - > setColor ( Color3B : : RED ) ;
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 ) ;
2014-05-15 01:07:09 +08:00
label - > setPosition ( Vec2 ( s . width / 2 , 3 * s . height / 4 ) ) ;
2013-08-13 04:29:54 +08:00
label - > setColor ( Color3B : : GREEN ) ;
label - > setString ( " Green " ) ;
}
2013-12-19 05:52:10 +08:00
std : : string LabelFNTColor : : title ( ) const
2013-08-13 04:29:54 +08:00
{
return " New Label + .FNT file " ;
}
2013-12-19 05:52:10 +08:00
std : : string LabelFNTColor : : subtitle ( ) const
2013-08-13 04:29:54 +08:00
{
return " Testing color " ;
}
LabelFNTHundredLabels : : LabelFNTHundredLabels ( )
{
// Upper Label
for ( int i = 0 ; i < 100 ; i + + )
{
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 ) ;
2013-08-16 16:05:27 +08:00
auto s = Director : : getInstance ( ) - > getWinSize ( ) ;
2013-08-13 04:29:54 +08:00
2014-05-15 01:07:09 +08:00
auto p = Vec2 ( CCRANDOM_0_1 ( ) * s . width , CCRANDOM_0_1 ( ) * s . height ) ;
2013-08-13 04:29:54 +08:00
label - > setPosition ( p ) ;
}
}
2013-12-19 05:52:10 +08:00
std : : string LabelFNTHundredLabels : : title ( ) const
2013-08-13 04:29:54 +08:00
{
return " New Label + .FNT file " ;
}
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 \n Left " ) ;
2014-05-15 01:07:09 +08:00
label1 - > setAnchorPoint ( Vec2 ( 0 , 0 ) ) ;
2013-08-13 04:29:54 +08:00
addChild ( label1 , 0 , kTagBitmapAtlas1 ) ;
s = label1 - > getContentSize ( ) ;
CCLOG ( " content size: %.2fx%.2f " , s . width , s . height ) ;
// Center
2014-01-11 22:33:07 +08:00
auto label2 = Label : : createWithBMFont ( " fonts/bitmapFontTest3.fnt " , " Multi line \n Center " ) ;
2013-08-13 04:29:54 +08:00
addChild ( label2 , 0 , kTagBitmapAtlas2 ) ;
s = label2 - > getContentSize ( ) ;
CCLOG ( " content size: %.2fx%.2f " , s . width , s . height ) ;
// right
2014-01-11 22:33:07 +08:00
auto label3 = Label : : createWithBMFont ( " fonts/bitmapFontTest3.fnt " , " Multi line \n Right \n Three 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 ( ) ;
CCLOG ( " content size: %.2fx%.2f " , s . width , s . height ) ;
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
{
return " New Label + .FNT file " ;
}
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 ) ;
2014-05-15 01:07:09 +08:00
label1 - > setPosition ( Vec2 ( s . width / 2 , s . height - 100 ) ) ;
2013-08-13 04:29:54 +08:00
// LabelTTF
2014-03-11 18:26:25 +08:00
TTFConfig ttfConfig ( " fonts/arial.ttf " , 24 ) ;
2014-01-11 22:33:07 +08:00
auto label2 = Label : : createWithTTF ( ttfConfig , " " , TextHAlignment : : CENTER , s . width ) ;
2013-08-13 04:29:54 +08:00
addChild ( label2 , 0 , kTagBitmapAtlas2 ) ;
2014-05-15 01:07:09 +08:00
label2 - > setPosition ( Vec2 ( s . width / 2 , s . height / 2 ) ) ;
2014-01-24 15:02:42 +08:00
auto label3 = Label : : createWithCharMap ( " fonts/tuffy_bold_italic-charmap.png " , 48 , 64 , ' ' ) ;
addChild ( label3 , 0 , kTagBitmapAtlas3 ) ;
2014-05-15 01:07:09 +08:00
label3 - > setPosition ( Vec2 ( s . width / 2 , 100 ) ) ;
2013-08-13 04:29:54 +08:00
2014-10-04 08:11:39 +08:00
schedule ( CC_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 )
{
auto label1 = static_cast < Label * > ( getChildByTag ( kTagBitmapAtlas1 ) ) ;
auto label2 = static_cast < Label * > ( getChildByTag ( kTagBitmapAtlas2 ) ) ;
2014-01-24 15:02:42 +08:00
auto label3 = static_cast < Label * > ( getChildByTag ( kTagBitmapAtlas3 ) ) ;
2013-08-13 04:29:54 +08:00
if ( ! setEmpty )
{
label1 - > setString ( " not empty " ) ;
label2 - > setString ( " not empty " ) ;
2014-01-24 15:02:42 +08:00
label3 - > setString ( " hi " ) ;
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 ( " " ) ;
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
{
return " New Label : .FNT file & .TTF file " ;
}
2013-12-19 05:52:10 +08:00
std : : string LabelFNTandTTFEmpty : : subtitle ( ) const
2013-08-13 04:29:54 +08:00
{
2014-01-24 15:02:42 +08:00
return " 3 empty labels: new Label + FNT/TTF/CharMap " ;
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 ) ;
2014-05-15 01:07:09 +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
{
return " New Label + .FNT file " ;
}
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 ( )
{
2013-08-16 16:05:27 +08:00
auto s = Director : : getInstance ( ) - > getWinSize ( ) ;
2013-08-13 04:29:54 +08:00
auto layer = LayerColor : : create ( Color4B ( 128 , 128 , 128 , 255 ) ) ;
addChild ( layer , - 10 ) ;
// LabelBMFont
2014-01-11 22:33:07 +08:00
auto label1 = Label : : createWithBMFont ( " fonts/futura-48.fnt " , " Testing Glyph Designer " ) ;
2013-08-13 04:29:54 +08:00
addChild ( label1 ) ;
2014-05-15 01:07:09 +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 LabelFNTGlyphDesigner : : title ( ) const
2013-08-13 04:29:54 +08:00
{
return " New Label + .FNT file " ;
}
2013-12-19 05:52:10 +08:00
std : : string LabelFNTGlyphDesigner : : subtitle ( ) const
2013-08-13 04:29:54 +08:00
{
return " Testing Glyph Designer: you should see a font with shawdows and outline " ;
}
LabelTTFUnicodeChinese : : LabelTTFUnicodeChinese ( )
{
auto size = Director : : getInstance ( ) - > getWinSize ( ) ;
2013-08-15 21:39:47 +08:00
// Adding "啊" letter at the end of string to make VS2012 happy, otherwise VS will generate errors
// like "Error 3 error C2146: syntax error : missing ')' before identifier 'label'";
2014-06-09 13:41:32 +08:00
TTFConfig ttfConfig ( " fonts/HKYuanMini.ttf " , 28 , GlyphCollection : : CUSTOM , " 美好的一天啊 " ) ;
2014-01-11 22:33:07 +08:00
auto label = Label : : createWithTTF ( ttfConfig , " 美好的一天啊 " , TextHAlignment : : CENTER , size . width ) ;
2014-05-16 08:22:53 +08:00
if ( label ) {
label - > setPosition ( Vec2 ( size . width / 2 , size . height / 2 ) ) ;
this - > addChild ( label ) ;
}
2013-08-13 04:29:54 +08:00
}
2013-12-19 05:52:10 +08:00
std : : string LabelTTFUnicodeChinese : : title ( ) const
2013-08-13 04:29:54 +08:00
{
return " New Label + .TTF file Chinese " ;
}
2013-12-19 05:52:10 +08:00
std : : string LabelTTFUnicodeChinese : : subtitle ( ) const
2013-08-13 04:29:54 +08:00
{
return " Testing new Label + TTF with Chinese character " ;
}
LabelFNTUnicodeChinese : : LabelFNTUnicodeChinese ( )
{
auto size = Director : : getInstance ( ) - > getWinSize ( ) ;
2014-01-11 22:33:07 +08:00
auto label = Label : : createWithBMFont ( " fonts/bitmapFontChinese.fnt " , " 中国 " ) ;
2014-05-15 01:07:09 +08:00
label - > setPosition ( Vec2 ( size . width / 2 , size . height / 2 ) ) ;
2013-08-13 04:29:54 +08:00
this - > addChild ( label ) ;
}
2013-12-19 05:52:10 +08:00
std : : string LabelFNTUnicodeChinese : : title ( ) const
2013-08-13 04:29:54 +08:00
{
return " New Label + .FNT file Chinese " ;
}
2013-12-19 05:52:10 +08:00
std : : string LabelFNTUnicodeChinese : : subtitle ( ) const
2013-08-13 04:29:54 +08:00
{
return " Testing new Label + FNT with Chinese character " ;
}
/// BitmapFontMultiLineAlignmentNew
# 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"
# 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 ;
LabelFNTMultiLineAlignment : : LabelFNTMultiLineAlignment ( )
{
2013-10-23 16:14:03 +08:00
auto listener = EventListenerTouchAllAtOnce : : create ( ) ;
listener - > onTouchesBegan = CC_CALLBACK_2 ( LabelFNTMultiLineAlignment : : onTouchesBegan , this ) ;
listener - > onTouchesMoved = CC_CALLBACK_2 ( LabelFNTMultiLineAlignment : : onTouchesMoved , this ) ;
listener - > onTouchesEnded = CC_CALLBACK_2 ( LabelFNTMultiLineAlignment : : onTouchesEnded , this ) ;
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
2014-01-11 22:33:07 +08:00
this - > _labelShouldRetain = Label : : createWithBMFont ( " fonts/markerFelt.fnt " , LongSentencesExample , TextHAlignment : : CENTER , size . width / 1.5 ) ;
2013-08-13 04:29:54 +08:00
this - > _labelShouldRetain - > retain ( ) ;
this - > _arrowsBarShouldRetain = Sprite : : create ( " Images/arrowsBar.png " ) ;
this - > _arrowsBarShouldRetain - > retain ( ) ;
this - > _arrowsShouldRetain = Sprite : : create ( " Images/arrows.png " ) ;
this - > _arrowsShouldRetain - > retain ( ) ;
MenuItemFont : : setFontSize ( 20 ) ;
auto longSentences = MenuItemFont : : create ( " Long Flowing Sentences " , CC_CALLBACK_1 ( LabelFNTMultiLineAlignment : : stringChanged , this ) ) ;
auto lineBreaks = MenuItemFont : : create ( " Short Sentences With Intentional Line Breaks " , CC_CALLBACK_1 ( LabelFNTMultiLineAlignment : : stringChanged , this ) ) ;
auto mixed = MenuItemFont : : create ( " Long Sentences Mixed With Intentional Line Breaks " , CC_CALLBACK_1 ( LabelFNTMultiLineAlignment : : stringChanged , this ) ) ;
2014-07-10 00:45:27 +08:00
auto stringMenu = Menu : : create ( longSentences , lineBreaks , mixed , nullptr ) ;
2013-08-13 04:29:54 +08:00
stringMenu - > alignItemsVertically ( ) ;
longSentences - > setColor ( Color3B : : RED ) ;
_lastSentenceItem = longSentences ;
longSentences - > setTag ( LongSentences ) ;
lineBreaks - > setTag ( LineBreaks ) ;
mixed - > setTag ( Mixed ) ;
MenuItemFont : : setFontSize ( 30 ) ;
auto left = MenuItemFont : : create ( " Left " , CC_CALLBACK_1 ( LabelFNTMultiLineAlignment : : alignmentChanged , this ) ) ;
auto center = MenuItemFont : : create ( " Center " , CC_CALLBACK_1 ( LabelFNTMultiLineAlignment : : alignmentChanged , this ) ) ;
auto right = MenuItemFont : : create ( " Right " , CC_CALLBACK_1 ( LabelFNTMultiLineAlignment : : alignmentChanged , this ) ) ;
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 ) ;
center - > setColor ( Color3B : : RED ) ;
_lastAlignmentItem = center ;
left - > setTag ( LeftAlign ) ;
center - > setTag ( CenterAlign ) ;
right - > setTag ( RightAlign ) ;
// position the label on the center of the screen
2014-05-15 01:07:09 +08:00
this - > _labelShouldRetain - > setPosition ( Vec2 ( size . width / 2 , size . height / 2 ) ) ;
2013-08-13 04:29:54 +08:00
this - > _arrowsBarShouldRetain - > setVisible ( false ) ;
float arrowsWidth = ( ArrowsMax - ArrowsMin ) * size . width ;
this - > _arrowsBarShouldRetain - > setScaleX ( arrowsWidth / this - > _arrowsBarShouldRetain - > getContentSize ( ) . width ) ;
2014-05-15 01:07:09 +08:00
this - > _arrowsBarShouldRetain - > setPosition ( Vec2 ( ( ( ArrowsMax + ArrowsMin ) / 2 ) * size . width , this - > _labelShouldRetain - > getPosition ( ) . y ) ) ;
2013-08-13 04:29:54 +08:00
this - > snapArrowsToEdge ( ) ;
2014-05-15 01:07:09 +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
this - > addChild ( this - > _labelShouldRetain ) ;
this - > addChild ( this - > _arrowsBarShouldRetain ) ;
this - > addChild ( this - > _arrowsShouldRetain ) ;
this - > addChild ( stringMenu ) ;
this - > addChild ( alignmentMenu ) ;
}
LabelFNTMultiLineAlignment : : ~ LabelFNTMultiLineAlignment ( )
{
this - > _labelShouldRetain - > release ( ) ;
this - > _arrowsBarShouldRetain - > release ( ) ;
this - > _arrowsShouldRetain - > release ( ) ;
}
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 " " ;
}
2014-02-20 10:53:49 +08:00
void LabelFNTMultiLineAlignment : : stringChanged ( cocos2d : : Ref * sender )
2013-08-13 04:29:54 +08:00
{
2013-08-16 16:05:27 +08:00
auto item = ( MenuItemFont * ) sender ;
2013-08-13 04:29:54 +08:00
item - > setColor ( Color3B : : RED ) ;
this - > _lastAlignmentItem - > setColor ( Color3B : : WHITE ) ;
this - > _lastAlignmentItem = item ;
switch ( item - > getTag ( ) )
{
case LongSentences :
this - > _labelShouldRetain - > setString ( LongSentencesExample ) ;
break ;
case LineBreaks :
this - > _labelShouldRetain - > setString ( LineBreaksExample ) ;
break ;
case Mixed :
this - > _labelShouldRetain - > setString ( MixedExample ) ;
break ;
default :
break ;
}
this - > snapArrowsToEdge ( ) ;
}
2014-02-20 10:53:49 +08:00
void LabelFNTMultiLineAlignment : : alignmentChanged ( cocos2d : : Ref * sender )
2013-08-13 04:29:54 +08:00
{
2013-08-16 16:05:27 +08:00
auto item = static_cast < MenuItemFont * > ( sender ) ;
2013-08-13 04:29:54 +08:00
item - > setColor ( Color3B : : RED ) ;
this - > _lastAlignmentItem - > setColor ( Color3B : : WHITE ) ;
this - > _lastAlignmentItem = item ;
switch ( item - > getTag ( ) )
{
case LeftAlign :
this - > _labelShouldRetain - > setAlignment ( TextHAlignment : : LEFT ) ;
break ;
case CenterAlign :
this - > _labelShouldRetain - > setAlignment ( TextHAlignment : : CENTER ) ;
break ;
case RightAlign :
this - > _labelShouldRetain - > setAlignment ( TextHAlignment : : RIGHT ) ;
break ;
default :
break ;
}
this - > snapArrowsToEdge ( ) ;
}
2013-09-03 18:22:03 +08:00
void LabelFNTMultiLineAlignment : : onTouchesBegan ( const std : : vector < Touch * > & touches , cocos2d : : Event * event )
2013-08-13 04:29:54 +08:00
{
2013-09-03 18:22:03 +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
if ( this - > _arrowsShouldRetain - > getBoundingBox ( ) . containsPoint ( location ) )
{
_drag = true ;
this - > _arrowsBarShouldRetain - > setVisible ( true ) ;
}
}
2013-09-03 18:22:03 +08:00
void LabelFNTMultiLineAlignment : : onTouchesEnded ( const std : : vector < Touch * > & touches , cocos2d : : Event * event )
2013-08-13 04:29:54 +08:00
{
_drag = false ;
this - > snapArrowsToEdge ( ) ;
this - > _arrowsBarShouldRetain - > setVisible ( false ) ;
}
2013-09-03 18:22:03 +08:00
void LabelFNTMultiLineAlignment : : onTouchesMoved ( const std : : vector < Touch * > & touches , cocos2d : : Event * event )
2013-08-13 04:29:54 +08:00
{
if ( ! _drag )
{
return ;
}
2013-09-03 18:22:03 +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
2014-05-15 01:07:09 +08:00
this - > _arrowsShouldRetain - > setPosition ( Vec2 ( MAX ( MIN ( location . x , ArrowsMax * winSize . width ) , ArrowsMin * winSize . width ) ,
2013-08-13 04:29:54 +08:00
this - > _arrowsShouldRetain - > getPosition ( ) . y ) ) ;
float labelWidth = fabs ( this - > _arrowsShouldRetain - > getPosition ( ) . x - this - > _labelShouldRetain - > getPosition ( ) . x ) * 2 ;
2014-03-07 15:58:49 +08:00
this - > _labelShouldRetain - > setMaxLineWidth ( labelWidth ) ;
2013-08-13 04:29:54 +08:00
}
void LabelFNTMultiLineAlignment : : snapArrowsToEdge ( )
{
2014-05-15 01:07:09 +08:00
this - > _arrowsShouldRetain - > setPosition ( Vec2 ( this - > _labelShouldRetain - > getPosition ( ) . x + this - > _labelShouldRetain - > getContentSize ( ) . width / 2 ,
2013-08-13 04:29:54 +08:00
this - > _labelShouldRetain - > getPosition ( ) . y ) ) ;
}
/// BMFontUnicodeNew
LabelFNTUNICODELanguages : : LabelFNTUNICODELanguages ( )
{
2013-12-18 16:03:07 +08:00
auto strings = FileUtils : : getInstance ( ) - > getValueMapFromFile ( " fonts/strings.xml " ) ;
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 ) ;
2014-05-15 01:07:09 +08:00
label1 - > setPosition ( Vec2 ( s . width / 2 , s . height / 5 * 3 ) ) ;
2013-08-13 04:29:54 +08:00
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 ) ;
2014-05-15 01:07:09 +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 ) ;
2014-05-15 01:07:09 +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 ) ;
2014-05-15 01:07:09 +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
{
return " New Label + .FNT + UNICODE " ;
}
2013-12-19 05:52:10 +08:00
std : : string LabelFNTUNICODELanguages : : subtitle ( ) const
2013-08-13 04:29:54 +08:00
{
return " You should see 4 differnt labels: \n In Spanish, Chinese, Russian and Korean " ;
}
LabelFNTBounds : : LabelFNTBounds ( )
{
2013-08-16 16:05:27 +08:00
auto s = Director : : getInstance ( ) - > getWinSize ( ) ;
2013-08-13 04:29:54 +08:00
2013-08-16 16:05:27 +08:00
auto layer = LayerColor : : create ( Color4B ( 128 , 128 , 128 , 255 ) ) ;
2013-08-13 04:29:54 +08:00
addChild ( layer , - 10 ) ;
// LabelBMFont
2014-09-11 15:39:56 +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 ) ;
2014-05-15 01:07:09 +08:00
label1 - > setPosition ( Vec2 ( s . width / 2 , s . height / 2 ) ) ;
2013-12-26 16:11:06 +08:00
2014-09-11 15:39:56 +08:00
auto drawNode = DrawNode : : create ( ) ;
2013-08-16 16:05:27 +08:00
auto labelSize = label1 - > getContentSize ( ) ;
auto origin = Director : : getInstance ( ) - > getWinSize ( ) ;
2013-08-13 04:29:54 +08:00
origin . width = origin . width / 2 - ( labelSize . width / 2 ) ;
origin . height = origin . height / 2 - ( labelSize . height / 2 ) ;
2014-05-15 01:07:09 +08:00
Vec2 vertices [ 4 ] =
2013-08-13 04:29:54 +08:00
{
2014-05-15 01:07:09 +08:00
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 )
2013-08-13 04:29:54 +08:00
} ;
2014-09-11 15:39:56 +08:00
drawNode - > drawPoly ( vertices , 4 , true , Color4F ( 1.0 , 1.0 , 1.0 , 1.0 ) ) ;
addChild ( drawNode ) ;
}
std : : string LabelFNTBounds : : title ( ) const
{
return " New Label + .FNT + Bounds " ;
}
std : : string LabelFNTBounds : : subtitle ( ) const
{
return " You should see string enclosed by a box " ;
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 ) ;
2014-01-11 22:33:07 +08:00
auto label1 = Label : : createWithTTF ( ttfConfig , LongSentencesExample , TextHAlignment : : CENTER , size . width ) ;
2014-05-15 01:07:09 +08:00
label1 - > setPosition ( Vec2 ( size . width / 2 , size . height / 2 ) ) ;
label1 - > setAnchorPoint ( Vec2 ( 0.5 , 1.0 ) ) ;
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
{
return " Uses the new Label with TTF. Testing auto-wrapping " ;
}
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
2014-01-11 22:33:07 +08:00
auto label1 = Label : : createWithTTF ( ttfConfig , " Green " , TextHAlignment : : CENTER , size . width ) ;
2014-05-15 01:07:09 +08:00
label1 - > setPosition ( Vec2 ( size . width / 2 , size . height * 0.3f ) ) ;
2014-03-20 20:56:10 +08:00
label1 - > setTextColor ( Color4B : : GREEN ) ;
2013-08-13 04:29:54 +08:00
addChild ( label1 ) ;
// Red
2014-01-11 22:33:07 +08:00
auto label2 = Label : : createWithTTF ( ttfConfig , " Red " , TextHAlignment : : CENTER , size . width ) ;
2014-05-15 01:07:09 +08:00
label2 - > setPosition ( Vec2 ( size . width / 2 , size . height * 0.4f ) ) ;
2014-03-20 20:56:10 +08:00
label2 - > setTextColor ( Color4B : : RED ) ;
2013-08-13 04:29:54 +08:00
addChild ( label2 ) ;
// Blue
2014-01-11 22:33:07 +08:00
auto label3 = Label : : createWithTTF ( ttfConfig , " Blue " , TextHAlignment : : CENTER , size . width ) ;
2014-05-15 01:07:09 +08:00
label3 - > setPosition ( Vec2 ( size . width / 2 , size . height * 0.5f ) ) ;
2014-03-20 20:56:10 +08:00
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
{
return " Uses the new Label with TTF. Testing Color " ;
}
LabelTTFDynamicAlignment : : LabelTTFDynamicAlignment ( )
{
2013-08-16 16:05:27 +08:00
auto size = Director : : getInstance ( ) - > getWinSize ( ) ;
2014-03-11 18:26:25 +08:00
TTFConfig ttfConfig ( " fonts/arial.ttf " , 23 ) ;
2014-01-11 22:33:07 +08:00
_label = Label : : createWithTTF ( ttfConfig , LongSentencesExample , TextHAlignment : : CENTER , size . width ) ;
2014-05-15 01:07:09 +08:00
_label - > setPosition ( Vec2 ( size . width / 2 , size . height / 2 ) ) ;
2013-08-13 04:29:54 +08:00
2013-08-16 16:05:27 +08:00
auto menu = Menu : : create (
2013-08-13 04:29:54 +08:00
MenuItemFont : : create ( " Left " , CC_CALLBACK_1 ( LabelTTFDynamicAlignment : : setAlignmentLeft , this ) ) ,
MenuItemFont : : create ( " Center " , CC_CALLBACK_1 ( LabelTTFDynamicAlignment : : setAlignmentCenter , this ) ) ,
MenuItemFont : : create ( " Right " , CC_CALLBACK_1 ( LabelTTFDynamicAlignment : : setAlignmentRight , this ) ) ,
2014-07-10 00:45:27 +08:00
nullptr ) ;
2013-08-13 04:29:54 +08:00
menu - > alignItemsVerticallyWithPadding ( 4 ) ;
2014-05-15 01:07:09 +08:00
menu - > setPosition ( Vec2 ( 50 , size . height / 4 ) ) ;
2013-08-13 04:29:54 +08:00
addChild ( _label ) ;
this - > addChild ( menu ) ;
}
void LabelTTFDynamicAlignment : : updateAlignment ( )
{
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
{
return " Uses the new Label with TTF. Testing alignment " ;
}
2014-02-08 17:15:57 +08:00
//
// NewLabelTTF Chinese/Japanese/Korean wrapping test
//
LabelTTFCJKWrappingTest : : LabelTTFCJKWrappingTest ( )
{
auto size = Director : : getInstance ( ) - > getWinSize ( ) ;
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 ) ;
drawNode - > drawSegment (
2014-05-15 01:07:09 +08:00
Vec2 ( size . width * 0.1 , size . height * 0.8 ) ,
Vec2 ( size . width * 0.1 , 0 ) , 1 , Color4F ( 1 , 0 , 0 , 1 ) ) ;
2014-02-08 17:15:57 +08:00
drawNode - > drawSegment (
2014-05-15 01:07:09 +08:00
Vec2 ( size . width * 0.85 , size . height * 0.8 ) ,
Vec2 ( size . width * 0.85 , 0 ) , 1 , Color4F ( 1 , 0 , 0 , 1 ) ) ;
2014-02-08 17:15:57 +08:00
2014-06-09 13:41:32 +08:00
TTFConfig ttfConfig ( " fonts/HKYuanMini.ttf " , 25 , GlyphCollection : : DYNAMIC ) ;
2014-02-08 17:15:57 +08:00
auto label1 = Label : : createWithTTF ( ttfConfig ,
2014-02-10 11:21:54 +08:00
" 你好, Cocos2d-x v3的New Label. " , TextHAlignment : : LEFT , size . width * 0.75 ) ;
2014-05-16 08:22:53 +08:00
if ( label1 ) {
label1 - > setTextColor ( Color4B ( 128 , 255 , 255 , 255 ) ) ;
label1 - > setPosition ( Vec2 ( size . width * 0.1 , size . height * 0.6 ) ) ;
label1 - > setAnchorPoint ( Vec2 ( 0 , 0.5 ) ) ;
this - > addChild ( label1 ) ;
}
2014-02-08 17:15:57 +08:00
auto label2 = Label : : createWithTTF ( ttfConfig ,
2014-02-10 11:21:54 +08:00
" 早上好, Cocos2d-x v3的New Label. " , TextHAlignment : : LEFT , size . width * 0.75 ) ;
2014-05-16 08:22:53 +08:00
if ( label2 ) {
label2 - > setTextColor ( Color4B ( 255 , 128 , 255 , 255 ) ) ;
label2 - > setPosition ( Vec2 ( size . width * 0.1 , size . height * 0.4 ) ) ;
label2 - > setAnchorPoint ( Vec2 ( 0 , 0.5 ) ) ;
this - > addChild ( label2 ) ;
}
2014-02-08 17:15:57 +08:00
auto label3 = Label : : createWithTTF ( ttfConfig ,
" 美好的一天啊美好的一天啊美好的一天啊 " , TextHAlignment : : LEFT , size . width * 0.75 ) ;
2014-05-16 08:22:53 +08:00
if ( label3 ) {
label3 - > setTextColor ( Color4B ( 255 , 255 , 128 , 255 ) ) ;
label3 - > setPosition ( Vec2 ( size . width * 0.1 , size . height * 0.2 ) ) ;
label3 - > setAnchorPoint ( Vec2 ( 0 , 0.5 ) ) ;
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 "
" Characters should stay in the correct position " ;
}
2013-08-13 04:29:54 +08:00
//
// NewLabelTTF unicode test
//
LabelTTFUnicodeNew : : LabelTTFUnicodeNew ( )
{
2013-12-18 16:03:07 +08:00
auto strings = FileUtils : : getInstance ( ) - > getValueMapFromFile ( " fonts/strings.xml " ) ;
std : : string chinese = strings [ " chinese1 " ] . asString ( ) ;
2013-08-13 04:29:54 +08:00
2013-12-18 16:03:07 +08:00
// 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 size = Director : : getInstance ( ) - > getWinSize ( ) ;
2013-08-13 04:29:54 +08:00
float vStep = size . height / 9 ;
float vSize = size . height ;
2014-03-11 18:26:25 +08:00
TTFConfig ttfConfig ( " fonts/arial.ttf " , 23 , GlyphCollection : : ASCII ) ;
2013-08-13 04:29:54 +08:00
// Spanish
2014-01-11 22:33:07 +08:00
auto label1 = Label : : createWithTTF ( ttfConfig , " Buen día, ¿cómo te llamas? " , TextHAlignment : : CENTER , size . width ) ;
2014-05-15 01:07:09 +08:00
label1 - > setPosition ( Vec2 ( size . width / 2 , vSize - ( vStep * 4.5 ) ) ) ;
2013-08-13 04:29:54 +08:00
addChild ( label1 ) ;
// German
2014-01-11 22:33:07 +08:00
auto label2 = Label : : createWithTTF ( ttfConfig , " In welcher Straße haben Sie gelebt? " , TextHAlignment : : CENTER , size . width ) ;
2014-05-15 01:07:09 +08:00
label2 - > setPosition ( Vec2 ( size . width / 2 , vSize - ( vStep * 5.5 ) ) ) ;
2013-08-13 04:29:54 +08:00
addChild ( label2 ) ;
// chinese
2014-06-09 13:41:32 +08:00
ttfConfig . fontFilePath = " fonts/HKYuanMini.ttf " ;
2014-01-11 22:33:07 +08:00
ttfConfig . glyphs = GlyphCollection : : CUSTOM ;
ttfConfig . customGlyphs = chinese . c_str ( ) ;
auto label3 = Label : : createWithTTF ( ttfConfig , chinese , TextHAlignment : : CENTER , size . width ) ;
2014-05-16 08:22:53 +08:00
if ( label3 ) {
label3 - > setPosition ( Vec2 ( size . width / 2 , vSize - ( vStep * 6.5 ) ) ) ;
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 " ;
}
LabelTTFFontsTestNew : : LabelTTFFontsTestNew ( )
{
const char * ttfpaths [ ] = {
" fonts/A Damn Mess.ttf " ,
" fonts/Abberancy.ttf " ,
" fonts/Abduction.ttf " ,
" fonts/American Typewriter.ttf " ,
" fonts/Paint Boy.ttf " ,
2014-07-24 16:15:51 +08:00
" fonts/Schwarzwald.ttf " ,
2013-08-13 04:29:54 +08:00
" fonts/Scissor Cuts.ttf " ,
} ;
# define arraysize(ar) (sizeof(ar) / sizeof(ar[0]))
2013-08-16 16:05:27 +08:00
auto size = Director : : getInstance ( ) - > getWinSize ( ) ;
2014-03-11 18:26:25 +08:00
TTFConfig ttfConfig ( ttfpaths [ 0 ] , 20 , GlyphCollection : : NEHE ) ;
2013-11-13 11:22:34 +08:00
for ( size_t i = 0 ; i < arraysize ( ttfpaths ) ; + + i ) {
2014-01-11 22:33:07 +08:00
ttfConfig . fontFilePath = ttfpaths [ i ] ;
auto label = Label : : createWithTTF ( ttfConfig , ttfpaths [ i ] , TextHAlignment : : CENTER , 0 ) ;
2014-03-25 10:57:44 +08:00
if ( label ) {
2014-05-15 01:07:09 +08:00
label - > setPosition ( Vec2 ( size . width / 2 , ( ( size . height * 0.6 ) / arraysize ( ttfpaths ) * i ) + ( size . height / 5 ) ) ) ;
2013-08-13 04:29:54 +08:00
addChild ( label ) ;
} else {
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 " " ;
}
LabelBMFontTestNew : : LabelBMFontTestNew ( )
{
2013-08-16 16:05:27 +08:00
auto size = Director : : getInstance ( ) - > getWinSize ( ) ;
2013-08-13 04:29:54 +08:00
2014-01-11 22:33:07 +08:00
auto label1 = Label : : createWithBMFont ( " fonts/bitmapFontTest2.fnt " , " Hello World, this is testing the new Label using fnt file " , TextHAlignment : : CENTER , size . width ) ;
2014-05-15 01:07:09 +08:00
label1 - > setPosition ( Vec2 ( size . width / 2 , size . height / 2 ) ) ;
2013-08-13 04:29:54 +08:00
addChild ( label1 ) ;
}
2013-12-19 05:52:10 +08:00
std : : string LabelBMFontTestNew : : title ( ) const
2013-08-13 04:29:54 +08:00
{
return " New Label + FNT " ;
}
2013-12-19 05:52:10 +08:00
std : : string LabelBMFontTestNew : : subtitle ( ) const
2013-08-13 04:29:54 +08:00
{
return " Uses the new Label with .FNT file " ;
}
2013-12-13 12:42:15 +08:00
LabelTTFDistanceField : : LabelTTFDistanceField ( )
{
auto size = Director : : getInstance ( ) - > getWinSize ( ) ;
2014-03-11 18:26:25 +08:00
TTFConfig ttfConfig ( " fonts/arial.ttf " , 40 , GlyphCollection : : DYNAMIC , nullptr , true ) ;
2013-12-13 12:42:15 +08:00
2014-01-11 22:33:07 +08:00
auto label1 = Label : : createWithTTF ( ttfConfig , " Distance Field " , TextHAlignment : : CENTER , size . width ) ;
2014-05-15 01:07:09 +08:00
label1 - > setPosition ( Vec2 ( size . width / 2 , size . height * 0.6f ) ) ;
2014-03-20 20:56:10 +08:00
label1 - > setTextColor ( Color4B : : GREEN ) ;
2013-12-13 12:42:15 +08:00
addChild ( label1 ) ;
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 ) ;
label1 - > runAction ( RepeatForever : : create ( action ) ) ;
2014-01-11 22:33:07 +08:00
auto label2 = Label : : createWithTTF ( ttfConfig , " Distance Field " , TextHAlignment : : CENTER , size . width ) ;
2014-05-15 01:07:09 +08:00
label2 - > setPosition ( Vec2 ( size . width / 2 , size . height * 0.3f ) ) ;
2014-03-20 20:56:10 +08:00
label2 - > setTextColor ( Color4B : : RED ) ;
2013-12-13 12:42:15 +08:00
addChild ( label2 ) ;
}
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 ( ) ;
auto bg = LayerColor : : create ( Color4B ( 200 , 191 , 231 , 255 ) ) ;
this - > addChild ( bg ) ;
2014-03-11 18:26:25 +08:00
TTFConfig ttfConfig ( " fonts/arial.ttf " , 40 , GlyphCollection : : DYNAMIC , nullptr , true ) ;
2014-01-11 22:33:07 +08:00
auto label1 = Label : : createWithTTF ( ttfConfig , " Glow " , TextHAlignment : : CENTER , size . width ) ;
2014-05-15 01:07:09 +08:00
label1 - > setPosition ( Vec2 ( size . width / 2 , size . height * 0.7 ) ) ;
2014-03-20 20:56:10 +08:00
label1 - > setTextColor ( Color4B : : GREEN ) ;
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 ;
2014-01-11 22:33:07 +08:00
auto label2 = Label : : createWithTTF ( ttfConfig , " Outline " , TextHAlignment : : CENTER , size . width ) ;
2014-05-15 01:07:09 +08:00
label2 - > setPosition ( Vec2 ( size . width / 2 , size . height * 0.6 ) ) ;
2014-03-20 20:56:10 +08:00
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 ;
auto label3 = Label : : createWithTTF ( ttfConfig , " Outline " , TextHAlignment : : CENTER , size . width ) ;
2014-05-15 01:07:09 +08:00
label3 - > setPosition ( Vec2 ( size . width / 2 , size . height * 0.48 ) ) ;
2014-03-20 20:56:10 +08:00
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 ;
auto label4 = Label : : createWithTTF ( ttfConfig , " Outline " , TextHAlignment : : CENTER , size . width ) ;
2014-05-15 01:07:09 +08:00
label4 - > setPosition ( Vec2 ( size . width / 2 , size . height * 0.36 ) ) ;
2014-03-20 20:56:10 +08:00
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
{
2014-03-05 15:54:40 +08:00
return " New Label " ;
}
std : : string LabelOutlineAndGlowTest : : subtitle ( ) const
{
return " Testing outline and glow of label " ;
}
LabelShadowTest : : LabelShadowTest ( )
{
auto size = Director : : getInstance ( ) - > getWinSize ( ) ;
auto bg = LayerColor : : create ( Color4B ( 200 , 191 , 231 , 255 ) ) ;
this - > addChild ( bg ) ;
2014-03-11 18:26:25 +08:00
TTFConfig ttfConfig ( " fonts/arial.ttf " , 40 , GlyphCollection : : DYNAMIC , nullptr , true ) ;
2014-03-05 15:54:40 +08:00
2014-04-01 14:15:35 +08:00
shadowLabelTTF = Label : : createWithTTF ( ttfConfig , " TTF:Shadow " ) ;
2014-05-15 01:07:09 +08:00
shadowLabelTTF - > setPosition ( Vec2 ( size . width / 2 , size . height * 0.65f ) ) ;
2014-03-20 20:56:10 +08:00
shadowLabelTTF - > setTextColor ( Color4B : : RED ) ;
shadowLabelTTF - > enableShadow ( Color4B : : BLACK ) ;
2014-03-05 15:54:40 +08:00
addChild ( shadowLabelTTF ) ;
2014-04-01 14:15:35 +08:00
shadowLabelOutline = Label : : createWithTTF ( ttfConfig , " TTF:Shadow " ) ;
2014-05-15 01:07:09 +08:00
shadowLabelOutline - > setPosition ( Vec2 ( size . width / 2 , size . height * 0.5f ) ) ;
2014-04-01 14:15:35 +08:00
shadowLabelOutline - > setTextColor ( Color4B : : RED ) ;
shadowLabelOutline - > enableOutline ( Color4B : : YELLOW , 1 ) ;
shadowLabelOutline - > enableShadow ( Color4B : : BLACK ) ;
addChild ( shadowLabelOutline ) ;
2014-03-05 15:54:40 +08:00
shadowLabelBMFont = Label : : createWithBMFont ( " fonts/bitmapFontTest.fnt " , " BMFont:Shadow " ) ;
2014-05-15 01:07:09 +08:00
shadowLabelBMFont - > setPosition ( Vec2 ( size . width / 2 , size . height * 0.35f ) ) ;
2014-03-05 15:54:40 +08:00
shadowLabelBMFont - > setColor ( Color3B : : RED ) ;
2014-03-20 20:56:10 +08:00
shadowLabelBMFont - > enableShadow ( Color4B : : GREEN ) ;
2014-03-05 15:54:40 +08:00
addChild ( shadowLabelBMFont ) ;
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 ) ;
2014-05-12 11:17:06 +08:00
slider - > addEventListener ( CC_CALLBACK_2 ( LabelShadowTest : : sliderEvent , this ) ) ;
2014-03-05 15:54:40 +08:00
addChild ( slider ) ;
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 " ) ;
2014-05-15 01:07:09 +08:00
slider2 - > setPosition ( Vec2 ( size . width * 0.15f , size . height / 2.0 ) ) ;
2014-03-05 15:54:40 +08:00
slider2 - > setRotation ( 90 ) ;
slider2 - > setPercent ( 52 ) ;
2014-05-12 11:17:06 +08:00
slider2 - > addEventListener ( CC_CALLBACK_2 ( LabelShadowTest : : sliderEvent , this ) ) ;
2014-03-05 15:54:40 +08:00
addChild ( slider2 ) ;
}
2014-05-12 11:17:06 +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
{
Slider * slider = ( Slider * ) this - > getChildByTag ( 1 ) ;
Slider * slider2 = ( Slider * ) this - > getChildByTag ( 2 ) ;
auto offset = Size ( slider - > getPercent ( ) - 50 , 50 - slider2 - > getPercent ( ) ) ;
2014-03-20 20:56:10 +08:00
shadowLabelTTF - > enableShadow ( Color4B : : BLACK , offset ) ;
shadowLabelBMFont - > enableShadow ( Color4B : : GREEN , offset ) ;
2014-04-01 14:15:35 +08:00
shadowLabelOutline - > enableShadow ( Color4B : : BLACK , 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 ) ;
label1 - > setPosition ( Vec2 ( 10 , 100 ) ) ;
2014-01-16 16:37:29 +08:00
label1 - > setOpacity ( 200 ) ;
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 ) ;
label2 - > setPosition ( Vec2 ( 10 , 200 ) ) ;
2014-01-16 16:37:29 +08:00
label2 - > setOpacity ( 32 ) ;
2014-10-04 08:11:39 +08:00
schedule ( CC_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 ( )
{
auto label1 = Label : : createWithCharMap ( " fonts/tuffy_bold_italic-charmap.png " , 48 , 64 , ' ' ) ;
addChild ( label1 , 0 , kTagSprite1 ) ;
2014-05-15 01:07:09 +08:00
label1 - > setAnchorPoint ( Vec2 : : ANCHOR_BOTTOM_LEFT ) ;
label1 - > setPosition ( Vec2 ( 10 , 100 ) ) ;
2014-01-24 15:02:42 +08:00
label1 - > setOpacity ( 200 ) ;
auto label2 = Label : : createWithCharMap ( " fonts/tuffy_bold_italic-charmap.png " , 48 , 64 , ' ' ) ;
addChild ( label2 , 0 , kTagSprite2 ) ;
2014-05-15 01:07:09 +08:00
label2 - > setAnchorPoint ( Vec2 : : ANCHOR_BOTTOM_LEFT ) ;
label2 - > setPosition ( Vec2 ( 10 , 200 ) ) ;
2014-01-24 15:02:42 +08:00
label2 - > setColor ( Color3B : : RED ) ;
auto fade = FadeOut : : create ( 1.0f ) ;
auto fade_in = fade - > reverse ( ) ;
auto cb = CallFunc : : create ( CC_CALLBACK_0 ( LabelCharMapColorTest : : actionFinishCallback , this ) ) ;
2014-07-10 00:45:27 +08:00
auto seq = Sequence : : create ( fade , fade_in , cb , nullptr ) ;
2014-01-24 15:02:42 +08:00
auto repeat = RepeatForever : : create ( seq ) ;
label2 - > runAction ( repeat ) ;
_time = 0 ;
2014-10-04 08:11:39 +08:00
schedule ( CC_CALLBACK_1 ( LabelCharMapColorTest : : step , this ) , " step_key " ) ;
2014-01-24 15:02:42 +08:00
}
void LabelCharMapColorTest : : actionFinishCallback ( )
{
CCLOG ( " Action finished " ) ;
}
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 ) ;
label2 - > setString ( string ) ;
}
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 ( ) ;
2014-03-11 18:26:25 +08:00
TTFConfig ttfConfig ( " fonts/arial.ttf " , 40 , GlyphCollection : : DYNAMIC , nullptr , true ) ;
2014-01-16 14:37:07 +08:00
2014-01-16 15:07:20 +08:00
auto label1 = Label : : createWithTTF ( ttfConfig , " Test崩溃123 " , TextHAlignment : : CENTER , size . width ) ;
2014-05-15 01:07:09 +08:00
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
{
2014-01-16 15:07:20 +08:00
return " Not crash and show [Test123] when using unknown character. " ;
2014-01-16 14:37:07 +08:00
}
2014-01-23 16:16:30 +08:00
LabelTTFOldNew : : LabelTTFOldNew ( )
{
auto s = Director : : getInstance ( ) - > getWinSize ( ) ;
2014-01-23 17:11:40 +08:00
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 ) ;
2014-05-15 01:07:09 +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 ) ;
2014-05-15 01:07:09 +08:00
label2 - > setPosition ( Vec2 ( s . width / 2 , delta * 2 ) ) ;
2014-03-06 07:49:08 +08:00
2014-09-11 15:39:56 +08:00
auto drawNode = DrawNode : : create ( ) ;
2014-01-23 16:27:50 +08:00
auto labelSize = label1 - > getContentSize ( ) ;
auto origin = Director : : getInstance ( ) - > getWinSize ( ) ;
origin . width = origin . width / 2 - ( labelSize . width / 2 ) ;
origin . height = origin . height / 2 - ( labelSize . height / 2 ) ;
2014-05-15 01:07:09 +08:00
Vec2 vertices [ 4 ] =
2014-01-23 16:27:50 +08:00
{
2014-05-15 01:07:09 +08:00
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 )
2014-01-23 16:27:50 +08:00
} ;
2014-09-11 15:39:56 +08:00
drawNode - > drawPoly ( vertices , 4 , true , Color4F ( 1.0 , 0.0 , 0.0 , 1.0 ) ) ;
2014-02-10 11:21:54 +08:00
labelSize = label2 - > getContentSize ( ) ;
origin = Director : : getInstance ( ) - > getWinSize ( ) ;
2014-09-11 15:39:56 +08:00
2014-02-10 11:21:54 +08:00
origin . width = origin . width / 2 - ( labelSize . width / 2 ) ;
origin . height = origin . height / 2 - ( labelSize . height / 2 ) ;
2014-09-11 15:39:56 +08:00
2014-05-15 01:07:09 +08:00
Vec2 vertices2 [ 4 ] =
2014-02-10 11:21:54 +08:00
{
2014-05-15 01:07:09 +08:00
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 )
2014-02-10 11:21:54 +08:00
} ;
2014-09-11 15:39:56 +08:00
drawNode - > drawPoly ( vertices2 , 4 , true , Color4F ( 1.0 , 1.0 , 1.0 , 1.0 ) ) ;
2014-01-23 16:27:50 +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 " ) ;
2014-05-15 01:07:09 +08:00
label1 - > setPosition ( Vec2 ( size . width / 2 , size . height * 0.7 ) ) ;
2014-03-10 19:42:43 +08:00
addChild ( label1 ) ;
2014-04-09 23:31:05 +08:00
auto label3 = Label : : createWithSystemFont ( " Marker Felt " , " Marker Felt " , 32 ) ;
2014-05-15 01:07:09 +08:00
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 ) ;
auto s = Director : : getInstance ( ) - > getWinSize ( ) ;
2014-05-15 01:07:09 +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 (
MenuItemFont : : create ( " Left " , CC_CALLBACK_1 ( LabelAlignmentTest : : setAlignmentLeft , this ) ) ,
MenuItemFont : : create ( " Center " , CC_CALLBACK_1 ( LabelAlignmentTest : : setAlignmentCenter , this ) ) ,
MenuItemFont : : create ( " Right " , CC_CALLBACK_1 ( LabelAlignmentTest : : setAlignmentRight , this ) ) ,
2014-07-10 00:45:27 +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 ( 50 , s . height / 2 - 20 ) ) ;
2014-03-07 14:58:44 +08:00
this - > addChild ( menu ) ;
menu = Menu : : create (
MenuItemFont : : create ( " Top " , CC_CALLBACK_1 ( LabelAlignmentTest : : setAlignmentTop , this ) ) ,
MenuItemFont : : create ( " Middle " , CC_CALLBACK_1 ( LabelAlignmentTest : : setAlignmentMiddle , this ) ) ,
MenuItemFont : : create ( " Bottom " , CC_CALLBACK_1 ( LabelAlignmentTest : : setAlignmentBottom , this ) ) ,
2014-07-10 00:45:27 +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 ) ;
_horizAlign = TextHAlignment : : LEFT ;
_vertAlign = TextVAlignment : : TOP ;
2014-03-11 18:26:25 +08:00
TTFConfig ttfConfig ( " fonts/arial.ttf " , 32 ) ;
2014-03-07 14:58:44 +08:00
_label = Label : : create ( ) ;
_label - > setDimensions ( 200 , 160 ) ;
_label - > setAlignment ( _horizAlign , _vertAlign ) ;
_label - > setTTFConfig ( ttfConfig ) ;
_label - > setString ( getCurrentAlignment ( ) ) ;
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 ) ;
}
LabelAlignmentTest : : ~ LabelAlignmentTest ( )
{
}
void LabelAlignmentTest : : setAlignmentLeft ( Ref * sender )
{
_horizAlign = TextHAlignment : : LEFT ;
2014-03-10 19:42:43 +08:00
_label - > setHorizontalAlignment ( _horizAlign ) ;
2014-03-07 14:58:44 +08:00
_label - > setString ( getCurrentAlignment ( ) ) ;
}
void LabelAlignmentTest : : setAlignmentCenter ( Ref * sender )
{
_horizAlign = TextHAlignment : : CENTER ;
2014-03-10 19:42:43 +08:00
_label - > setHorizontalAlignment ( _horizAlign ) ;
2014-03-07 15:58:49 +08:00
_label - > setString ( getCurrentAlignment ( ) ) ;
2014-03-07 14:58:44 +08:00
}
void LabelAlignmentTest : : setAlignmentRight ( Ref * sender )
{
_horizAlign = TextHAlignment : : RIGHT ;
2014-03-10 19:42:43 +08:00
_label - > setHorizontalAlignment ( _horizAlign ) ;
2014-03-07 14:58:44 +08:00
_label - > setString ( getCurrentAlignment ( ) ) ;
}
void LabelAlignmentTest : : setAlignmentTop ( Ref * sender )
{
_vertAlign = TextVAlignment : : TOP ;
2014-03-10 19:42:43 +08:00
_label - > setVerticalAlignment ( _vertAlign ) ;
2014-03-07 14:58:44 +08:00
_label - > setString ( getCurrentAlignment ( ) ) ;
}
void LabelAlignmentTest : : setAlignmentMiddle ( Ref * sender )
{
_vertAlign = TextVAlignment : : CENTER ;
2014-03-10 19:42:43 +08:00
_label - > setVerticalAlignment ( _vertAlign ) ;
2014-03-07 14:58:44 +08:00
_label - > setString ( getCurrentAlignment ( ) ) ;
}
void LabelAlignmentTest : : setAlignmentBottom ( Ref * sender )
{
_vertAlign = TextVAlignment : : BOTTOM ;
2014-03-10 19:42:43 +08:00
_label - > setVerticalAlignment ( _vertAlign ) ;
2014-03-07 14:58:44 +08:00
_label - > setString ( getCurrentAlignment ( ) ) ;
}
const char * LabelAlignmentTest : : getCurrentAlignment ( )
{
2014-07-10 00:45:27 +08:00
const char * vertical = nullptr ;
const char * horizontal = nullptr ;
2014-03-07 14:58:44 +08:00
switch ( _vertAlign ) {
case TextVAlignment : : TOP :
vertical = " Top " ;
break ;
case TextVAlignment : : CENTER :
vertical = " Middle " ;
break ;
case TextVAlignment : : BOTTOM :
vertical = " Bottom " ;
break ;
}
switch ( _horizAlign ) {
case TextHAlignment : : LEFT :
horizontal = " Left " ;
break ;
case TextHAlignment : : CENTER :
horizontal = " Center " ;
break ;
case TextHAlignment : : RIGHT :
horizontal = " Right " ;
break ;
}
return String : : createWithFormat ( " Alignment %s %s " , vertical , horizontal ) - > getCString ( ) ;
}
std : : string LabelAlignmentTest : : title ( ) const
{
return " Testing New Label " ;
}
std : : string LabelAlignmentTest : : subtitle ( ) const
{
return " Select the buttons on the sides to change alignment " ;
}
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 ( ) ;
auto label = Label : : createWithBMFont ( " fonts/bitmapFontTest3.fnt " , " 123 \n 456 " ) ;
2014-05-15 01:07:09 +08:00
label - > setPosition ( Vec2 ( size . width / 2.0f , size . height / 2.0f ) ) ;
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 ( )
{
auto label = Label : : createWithTTF ( " Smaller font test " , " fonts/arial.ttf " , 5 ) ;
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 ( ) ;
auto bg = LayerColor : : create ( Color4B ( 200 , 191 , 231 , 255 ) ) ;
this - > addChild ( bg ) ;
TTFConfig ttfConfig ( " fonts/arial.ttf " , 25 , GlyphCollection : : DYNAMIC , nullptr , false ) ;
label = Label : : createWithTTF ( ttfConfig , " Test \n Line \n Height " ) ;
label - > setPosition ( Vec2 ( size . width / 2 , size . height * 0.5f ) ) ;
label - > setTextColor ( Color4B : : RED ) ;
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 ( ) ) ;
slider - > addEventListener ( CC_CALLBACK_2 ( LabelLineHeightTest : : sliderEvent , this ) ) ;
addChild ( slider ) ;
}
void LabelLineHeightTest : : sliderEvent ( Ref * sender , ui : : Slider : : EventType type )
{
if ( type = = Slider : : EventType : : ON_PERCENTAGE_CHANGED )
{
Slider * slider = ( Slider * ) sender ;
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 ( ) ;
auto bg = LayerColor : : create ( Color4B ( 200 , 191 , 231 , 255 ) ) ;
this - > addChild ( bg ) ;
TTFConfig ttfConfig ( " fonts/arial.ttf " , 40 , GlyphCollection : : DYNAMIC , nullptr , false ) ;
label = Label : : createWithTTF ( ttfConfig , " Test additional kerning " ) ;
label - > setPosition ( Vec2 ( size . width / 2 , size . height * 0.65f ) ) ;
label - > setTextColor ( Color4B : : RED ) ;
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 ) ;
slider - > addEventListener ( CC_CALLBACK_2 ( LabelAdditionalKerningTest : : sliderEvent , this ) ) ;
addChild ( slider ) ;
}
void LabelAdditionalKerningTest : : sliderEvent ( Ref * sender , ui : : Slider : : EventType type )
{
if ( type = = Slider : : EventType : : ON_PERCENTAGE_CHANGED )
{
Slider * slider = ( Slider * ) sender ;
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 " , " 中国中国中国中国中国 " ) ;
label - > setDimensions ( 5 , 100 ) ;
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 ( )
{
2015-01-08 16:57:03 +08:00
auto label = Label : : createWithTTF ( " Multi-line text \n with \n outline feature " , " fonts/arial.ttf " , 24 ) ;
2014-11-12 17:24:35 +08:00
label - > enableOutline ( Color4B : : ORANGE , 1 ) ;
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 ( )
{
Size s = Director : : getInstance ( ) - > getWinSize ( ) ;
auto parent = Node : : create ( ) ;
parent - > setPosition ( s . width / 2 , s . height / 2 ) ;
parent - > setVisible ( false ) ;
this - > addChild ( parent ) ;
auto label = Label : : createWithTTF ( " Crashed!!! " , " fonts/HKYuanMini.ttf " , 24 ) ;
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 ( )
{
auto label = Label : : createWithSystemFont ( " Hello World! " , " fonts/arial.ttf " , 24 , Size ( 30 , 100 ) ) ;
label - > setPosition ( VisibleRect : : center ( ) ) ;
addChild ( label ) ;
}
std : : string LabelSmallDimensionsTest : : title ( ) const
{
return " Test create Label[system font] with small dimensions " ;
}
std : : string LabelSmallDimensionsTest : : subtitle ( ) const
{
return " Program should not dead loop " ;
}