2013-09-08 11:26:38 +08:00
# include "LabelTestNew.h"
2013-08-13 04:29:54 +08:00
# include "../testResource.h"
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 ) ,
CL ( LabelTTFUnicodeNew ) ,
CL ( LabelBMFontTestNew )
} ;
# 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
layer - > autorelease ( ) ;
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
layer - > autorelease ( ) ;
return layer ;
}
Layer * restartAtlasActionNew ( )
{
2013-08-16 16:05:27 +08:00
auto layer = ( createFunctions [ sceneIdx ] ) ( ) ;
2013-08-13 04:29:54 +08:00
layer - > autorelease ( ) ;
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 )
{
}
std : : string AtlasDemoNew : : title ( )
{
return " No title " ;
}
std : : string AtlasDemoNew : : subtitle ( )
{
return " " ;
}
void AtlasDemoNew : : onEnter ( )
{
BaseTest : : onEnter ( ) ;
}
void AtlasDemoNew : : restartCallback ( Object * sender )
{
2013-08-16 16:05:27 +08:00
auto s = new AtlasTestSceneNew ( ) ;
2013-08-13 04:29:54 +08:00
s - > addChild ( restartAtlasActionNew ( ) ) ;
Director : : getInstance ( ) - > replaceScene ( s ) ;
s - > release ( ) ;
}
void AtlasDemoNew : : nextCallback ( Object * sender )
{
2013-08-16 16:05:27 +08:00
auto s = new AtlasTestSceneNew ( ) ;
2013-08-13 04:29:54 +08:00
s - > addChild ( nextAtlasActionNew ( ) ) ;
Director : : getInstance ( ) - > replaceScene ( s ) ;
s - > release ( ) ;
}
void AtlasDemoNew : : backCallback ( Object * sender )
{
2013-08-16 16:05:27 +08:00
auto s = new 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
2013-08-16 16:05:27 +08:00
auto ttf0 = Label : : createWithTTF ( " Alignment 0 \n new line " , " fonts/tahoma.ttf " , 32 ) ;
2013-08-13 04:29:54 +08:00
ttf0 - > setAlignment ( TextHAlignment : : LEFT ) ;
ttf0 - > setPosition ( Point ( s . width / 2 , ( s . height / 6 ) * 2 - 30 ) ) ;
ttf0 - > setAnchorPoint ( Point ( 0.5f , 0.5f ) ) ;
this - > addChild ( ttf0 ) ;
2013-08-16 16:05:27 +08:00
auto ttf1 = Label : : createWithTTF ( " Alignment 1 \n new line " , " fonts/tahoma.ttf " , 32 ) ;
2013-08-13 04:29:54 +08:00
ttf1 - > setAlignment ( TextHAlignment : : CENTER ) ;
ttf1 - > setPosition ( Point ( s . width / 2 , ( s . height / 6 ) * 3 - 30 ) ) ;
ttf1 - > setAnchorPoint ( Point ( 0.5f , 0.5f ) ) ;
this - > addChild ( ttf1 ) ;
2013-08-16 16:05:27 +08:00
auto ttf2 = Label : : createWithTTF ( " Alignment 2 \n new line " , " fonts/tahoma.ttf " , 32 ) ;
2013-08-13 04:29:54 +08:00
ttf1 - > setAlignment ( TextHAlignment : : RIGHT ) ;
ttf2 - > setPosition ( Point ( s . width / 2 , ( s . height / 6 ) * 4 - 30 ) ) ;
ttf2 - > setAnchorPoint ( Point ( 0.5f , 0.5f ) ) ;
this - > addChild ( ttf2 ) ;
}
std : : string LabelTTFAlignmentNew : : title ( )
{
return " New Label + TTF " ;
}
std : : string LabelTTFAlignmentNew : : subtitle ( )
{
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 ) ;
2013-08-16 16:05:27 +08:00
auto label1 = Label : : createWithBMFont ( " Test " , " fonts/bitmapFontTest2.fnt " ) ;
2013-08-13 04:29:54 +08:00
label1 - > setAnchorPoint ( Point ( 0 , 0 ) ) ;
addChild ( label1 , 0 , kTagBitmapAtlas1 ) ;
2013-08-16 16:05:27 +08:00
auto fade = FadeOut : : create ( 1.0f ) ;
auto fade_in = fade - > reverse ( ) ;
auto seq = Sequence : : create ( fade , fade_in , NULL ) ;
auto repeat = RepeatForever : : create ( seq ) ;
2013-08-13 04:29:54 +08:00
label1 - > runAction ( repeat ) ;
2013-08-16 16:05:27 +08:00
auto label2 = Label : : createWithBMFont ( " Test " , " fonts/bitmapFontTest2.fnt " ) ;
2013-08-13 04:29:54 +08:00
label2 - > setAnchorPoint ( Point ( 0.5f , 0.5f ) ) ;
label2 - > setColor ( Color3B : : RED ) ;
addChild ( label2 , 0 , kTagBitmapAtlas2 ) ;
label2 - > runAction ( repeat - > clone ( ) ) ;
2013-08-16 16:05:27 +08:00
auto label3 = Label : : createWithBMFont ( " Test " , " fonts/bitmapFontTest2.fnt " ) ;
2013-08-13 04:29:54 +08:00
label3 - > setAnchorPoint ( Point ( 1 , 1 ) ) ;
addChild ( label3 , 0 , kTagBitmapAtlas3 ) ;
label1 - > setPosition ( VisibleRect : : leftBottom ( ) ) ;
label2 - > setPosition ( VisibleRect : : center ( ) ) ;
label3 - > setPosition ( VisibleRect : : rightTop ( ) ) ;
2013-08-14 01:12:02 +08:00
2013-08-13 04:29:54 +08:00
schedule ( schedule_selector ( LabelFNTColorAndOpacity : : step ) ) ; //:@selector(step:)];
}
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 ) ;
}
std : : string LabelFNTColorAndOpacity : : title ( )
{
return " New Label + .FNT file " ;
}
std : : string LabelFNTColorAndOpacity : : subtitle ( )
{
return " Testing opacity + tint " ;
}
LabelFNTSpriteActions : : LabelFNTSpriteActions ( )
{
_time = 0 ;
// Upper Label
2013-08-16 16:05:27 +08:00
auto label = Label : : createWithBMFont ( " Bitmap Font Atlas " , " fonts/bitmapFontTest.fnt " ) ;
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
label - > setPosition ( Point ( s . width / 2 , s . height / 2 ) ) ;
label - > setAnchorPoint ( Point ( 0.5f , 0.5f ) ) ;
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 ( ) ;
auto scale_seq = Sequence : : create ( scale , scale_back , NULL ) ;
auto scale_4ever = RepeatForever : : create ( scale_seq ) ;
2013-08-13 04:29:54 +08:00
2013-08-16 16:05:27 +08:00
auto jump = JumpBy : : create ( 0.5f , Point : : ZERO , 60 , 1 ) ;
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 ) ;
auto seq = Sequence : : create ( fade_out , fade_in , NULL ) ;
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
2013-08-16 16:05:27 +08:00
auto label2 = Label : : createWithBMFont ( " 00.0 " , " fonts/bitmapFontTest.fnt " ) ;
2013-08-13 04:29:54 +08:00
addChild ( label2 , 0 , kTagBitmapAtlas2 ) ;
label2 - > setPosition ( Point ( s . width / 2.0f , 80 ) ) ;
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 ( ) ) ;
schedule ( schedule_selector ( LabelFNTSpriteActions : : step ) , 0.1f ) ;
}
void LabelFNTSpriteActions : : draw ( )
{
2013-08-16 16:05:27 +08:00
auto s = Director : : getInstance ( ) - > getWinSize ( ) ;
2013-08-13 04:29:54 +08:00
DrawPrimitives : : drawLine ( Point ( 0 , s . height / 2 ) , Point ( s . width , s . height / 2 ) ) ;
DrawPrimitives : : drawLine ( Point ( s . width / 2 , 0 ) , Point ( s . width / 2 , s . height ) ) ;
}
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 ) ;
}
std : : string LabelFNTSpriteActions : : title ( )
{
return " New Label + .FNT file " ;
}
std : : string LabelFNTSpriteActions : : subtitle ( )
{
return " Using fonts as Sprite objects. Some characters should rotate. " ;
}
LabelFNTPadding : : LabelFNTPadding ( )
{
2013-08-16 16:05:27 +08:00
auto label = Label : : createWithBMFont ( " abcdefg " , " fonts/bitmapFontTest4.fnt " ) ;
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
label - > setPosition ( Point ( s . width / 2 , s . height / 2 ) ) ;
label - > setAnchorPoint ( Point ( 0.5f , 0.5f ) ) ;
}
std : : string LabelFNTPadding : : title ( )
{
return " New Label + .FNT file " ;
}
std : : string LabelFNTPadding : : subtitle ( )
{
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
Label * label = NULL ;
label = Label : : createWithBMFont ( " FaFeFiFoFu " , " fonts/bitmapFontTest5.fnt " ) ;
addChild ( label ) ;
label - > setPosition ( Point ( s . width / 2 , s . height / 2 + 50 ) ) ;
label - > setAnchorPoint ( Point ( 0.5f , 0.5f ) ) ;
label = Label : : createWithBMFont ( " fafefifofu " , " fonts/bitmapFontTest5.fnt " ) ;
addChild ( label ) ;
label - > setPosition ( Point ( s . width / 2 , s . height / 2 ) ) ;
label - > setAnchorPoint ( Point ( 0.5f , 0.5f ) ) ;
label = Label : : createWithBMFont ( " aeiou " , " fonts/bitmapFontTest5.fnt " ) ;
addChild ( label ) ;
label - > setPosition ( Point ( s . width / 2 , s . height / 2 - 50 ) ) ;
label - > setAnchorPoint ( Point ( 0.5f , 0.5f ) ) ;
}
std : : string LabelFNTOffset : : title ( )
{
return " New Label + .FNT file " ;
}
std : : string LabelFNTOffset : : subtitle ( )
{
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
Label * label = NULL ;
label = Label : : createWithBMFont ( " Blue " , " fonts/bitmapFontTest5.fnt " ) ;
label - > setColor ( Color3B : : BLUE ) ;
addChild ( label ) ;
label - > setPosition ( Point ( s . width / 2 , s . height / 4 ) ) ;
label - > setAnchorPoint ( Point ( 0.5f , 0.5f ) ) ;
label = Label : : createWithBMFont ( " Red " , " fonts/bitmapFontTest5.fnt " ) ;
addChild ( label ) ;
label - > setPosition ( Point ( s . width / 2 , 2 * s . height / 4 ) ) ;
label - > setAnchorPoint ( Point ( 0.5f , 0.5f ) ) ;
label - > setColor ( Color3B : : RED ) ;
label = Label : : createWithBMFont ( " G " , " fonts/bitmapFontTest5.fnt " ) ;
addChild ( label ) ;
label - > setPosition ( Point ( s . width / 2 , 3 * s . height / 4 ) ) ;
label - > setAnchorPoint ( Point ( 0.5f , 0.5f ) ) ;
label - > setColor ( Color3B : : GREEN ) ;
label - > setString ( " Green " ) ;
}
std : : string LabelFNTColor : : title ( )
{
return " New Label + .FNT file " ;
}
std : : string LabelFNTColor : : subtitle ( )
{
return " Testing color " ;
}
LabelFNTHundredLabels : : LabelFNTHundredLabels ( )
{
// Upper Label
for ( int i = 0 ; i < 100 ; i + + )
{
char str [ 6 ] = { 0 } ;
sprintf ( str , " -%d- " , i ) ;
2013-08-16 16:05:27 +08:00
auto label = Label : : createWithBMFont ( str , " fonts/bitmapFontTest.fnt " ) ;
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
2013-08-16 16:05:27 +08:00
auto p = Point ( CCRANDOM_0_1 ( ) * s . width , CCRANDOM_0_1 ( ) * s . height ) ;
2013-08-13 04:29:54 +08:00
label - > setPosition ( p ) ;
label - > setAnchorPoint ( Point ( 0.5f , 0.5f ) ) ;
}
}
std : : string LabelFNTHundredLabels : : title ( )
{
return " New Label + .FNT file " ;
}
std : : string LabelFNTHundredLabels : : subtitle ( )
{
return " Creating several Labels using the same FNT file; should be fast " ;
}
LabelFNTMultiLine : : LabelFNTMultiLine ( )
{
Size s ;
// Left
2013-08-16 16:05:27 +08:00
auto label1 = Label : : createWithBMFont ( " Multi line \n Left " , " fonts/bitmapFontTest3.fnt " ) ;
2013-08-13 04:29:54 +08:00
label1 - > setAnchorPoint ( Point ( 0 , 0 ) ) ;
addChild ( label1 , 0 , kTagBitmapAtlas1 ) ;
s = label1 - > getContentSize ( ) ;
CCLOG ( " content size: %.2fx%.2f " , s . width , s . height ) ;
// Center
2013-08-16 16:05:27 +08:00
auto label2 = Label : : createWithBMFont ( " Multi line \n Center " , " fonts/bitmapFontTest3.fnt " ) ;
2013-08-13 04:29:54 +08:00
label2 - > setAnchorPoint ( Point ( 0.5f , 0.5f ) ) ;
addChild ( label2 , 0 , kTagBitmapAtlas2 ) ;
s = label2 - > getContentSize ( ) ;
CCLOG ( " content size: %.2fx%.2f " , s . width , s . height ) ;
// right
2013-08-16 16:05:27 +08:00
auto label3 = Label : : createWithBMFont ( " Multi line \n Right \n Three lines Three " , " fonts/bitmapFontTest3.fnt " ) ;
2013-08-13 04:29:54 +08:00
label3 - > setAnchorPoint ( Point ( 1 , 1 ) ) ;
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 ( ) ) ;
}
std : : string LabelFNTMultiLine : : title ( )
{
return " New Label + .FNT file " ;
}
std : : string LabelFNTMultiLine : : subtitle ( )
{
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
float delta = s . height / 4 ;
// LabelBMFont
2013-08-16 16:05:27 +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 ) ;
label1 - > setAnchorPoint ( Point ( 0.5f , 0.5f ) ) ;
label1 - > setPosition ( Point ( s . width / 2 , delta ) ) ;
// LabelTTF
2013-08-16 16:05:27 +08:00
auto label2 = Label : : createWithTTF ( " " , " fonts/arial.ttf " , 48 , s . width , TextHAlignment : : CENTER , GlyphCollection : : NEHE ) ;
2013-08-13 04:29:54 +08:00
addChild ( label2 , 0 , kTagBitmapAtlas2 ) ;
label2 - > setAnchorPoint ( Point ( 0.5f , 0.5f ) ) ;
label2 - > setPosition ( Point ( s . width / 2 , delta * 2 ) ) ;
schedule ( schedule_selector ( LabelFNTandTTFEmpty : : updateStrings ) , 1.0f ) ;
setEmpty = false ;
}
void LabelFNTandTTFEmpty : : updateStrings ( float dt )
{
auto label1 = static_cast < Label * > ( getChildByTag ( kTagBitmapAtlas1 ) ) ;
auto label2 = static_cast < Label * > ( getChildByTag ( kTagBitmapAtlas2 ) ) ;
if ( ! setEmpty )
{
label1 - > setString ( " not empty " ) ;
label2 - > setString ( " not empty " ) ;
setEmpty = true ;
}
else
{
label1 - > setString ( " " ) ;
label2 - > setString ( " " ) ;
setEmpty = false ;
}
}
std : : string LabelFNTandTTFEmpty : : title ( )
{
return " New Label : .FNT file & .TTF file " ;
}
std : : string LabelFNTandTTFEmpty : : subtitle ( )
{
return " 2 empty labels: new Label + .FNT and new Label + .TTF " ;
}
LabelFNTRetina : : LabelFNTRetina ( )
{
2013-08-16 16:05:27 +08:00
auto s = Director : : getInstance ( ) - > getWinSize ( ) ;
2013-08-13 04:29:54 +08:00
// LabelBMFont
auto label1 = Label : : createWithBMFont ( " TESTING RETINA DISPLAY " , " fonts/konqa32.fnt " ) ;
label1 - > setAnchorPoint ( Point ( 0.5f , 0.5f ) ) ;
addChild ( label1 ) ;
label1 - > setPosition ( Point ( s . width / 2 , s . height / 2 ) ) ;
}
std : : string LabelFNTRetina : : title ( )
{
return " New Label + .FNT file " ;
}
std : : string LabelFNTRetina : : subtitle ( )
{
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
auto label1 = Label : : createWithBMFont ( " Testing Glyph Designer " , " fonts/futura-48.fnt " ) ;
label1 - > setAnchorPoint ( Point ( 0.5f , 0.5f ) ) ;
addChild ( label1 ) ;
label1 - > setPosition ( Point ( s . width / 2 , s . height / 2 ) ) ;
}
std : : string LabelFNTGlyphDesigner : : title ( )
{
return " New Label + .FNT file " ;
}
std : : string LabelFNTGlyphDesigner : : subtitle ( )
{
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'";
auto label = Label : : createWithTTF ( " 美好的一天啊 " , " fonts/wt021.ttf " , 55 , size . width , TextHAlignment : : CENTER , GlyphCollection : : CUSTOM , " 美好的一天啊 " ) ;
2013-08-13 04:29:54 +08:00
label - > setAnchorPoint ( Point ( 0.5f , 0.5f ) ) ;
label - > setPosition ( Point ( size . width / 2 , size . height / 2 ) ) ;
this - > addChild ( label ) ;
}
std : : string LabelTTFUnicodeChinese : : title ( )
{
return " New Label + .TTF file Chinese " ;
}
string LabelTTFUnicodeChinese : : subtitle ( )
{
return " Testing new Label + TTF with Chinese character " ;
}
LabelFNTUnicodeChinese : : LabelFNTUnicodeChinese ( )
{
auto size = Director : : getInstance ( ) - > getWinSize ( ) ;
auto label = Label : : createWithBMFont ( " 中国 " , " fonts/bitmapFontChinese.fnt " ) ;
label - > setAnchorPoint ( Point ( 0.5f , 0.5f ) ) ;
label - > setPosition ( Point ( size . width / 2 , size . height / 2 ) ) ;
this - > addChild ( label ) ;
}
string LabelFNTUnicodeChinese : : title ( )
{
return " New Label + .FNT file Chinese " ;
}
string LabelFNTUnicodeChinese : : subtitle ( )
{
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
2013-08-13 06:41:29 +08:00
this - > _labelShouldRetain = Label : : createWithBMFont ( LongSentencesExample , " fonts/markerFelt.fnt " , TextHAlignment : : CENTER , size . width / 1.5 ) ;
//this->_labelShouldRetain = Label::createWithBMFont(LongSentencesExample, "fonts/bitmapFontTest.fnt", TextHAlignment::CENTER, size.width/1.5);
2013-08-13 04:29:54 +08:00
this - > _labelShouldRetain - > setAnchorPoint ( Point ( 0.5f , 0.5f ) ) ;
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 ) ) ;
auto stringMenu = Menu : : create ( longSentences , lineBreaks , mixed , NULL ) ;
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 ) ) ;
auto alignmentMenu = Menu : : create ( left , center , right , NULL ) ;
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
this - > _labelShouldRetain - > setPosition ( Point ( size . width / 2 , size . height / 2 ) ) ;
this - > _arrowsBarShouldRetain - > setVisible ( false ) ;
float arrowsWidth = ( ArrowsMax - ArrowsMin ) * size . width ;
this - > _arrowsBarShouldRetain - > setScaleX ( arrowsWidth / this - > _arrowsBarShouldRetain - > getContentSize ( ) . width ) ;
this - > _arrowsBarShouldRetain - > setPosition ( Point ( ( ( ArrowsMax + ArrowsMin ) / 2 ) * size . width , this - > _labelShouldRetain - > getPosition ( ) . y ) ) ;
this - > snapArrowsToEdge ( ) ;
stringMenu - > setPosition ( Point ( size . width / 2 , size . height - menuItemPaddingCenter ) ) ;
alignmentMenu - > setPosition ( Point ( size . width / 2 , menuItemPaddingCenter + 15 ) ) ;
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 ( ) ;
}
std : : string LabelFNTMultiLineAlignment : : title ( )
{
return " " ;
}
std : : string LabelFNTMultiLineAlignment : : subtitle ( )
{
return " " ;
}
void LabelFNTMultiLineAlignment : : stringChanged ( cocos2d : : Object * sender )
{
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 ( ) ;
}
void LabelFNTMultiLineAlignment : : alignmentChanged ( cocos2d : : Object * sender )
{
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
this - > _arrowsShouldRetain - > setPosition ( Point ( MAX ( MIN ( location . x , ArrowsMax * winSize . width ) , ArrowsMin * winSize . width ) ,
this - > _arrowsShouldRetain - > getPosition ( ) . y ) ) ;
float labelWidth = fabs ( this - > _arrowsShouldRetain - > getPosition ( ) . x - this - > _labelShouldRetain - > getPosition ( ) . x ) * 2 ;
this - > _labelShouldRetain - > setWidth ( labelWidth ) ;
}
void LabelFNTMultiLineAlignment : : snapArrowsToEdge ( )
{
this - > _arrowsShouldRetain - > setPosition ( Point ( this - > _labelShouldRetain - > getPosition ( ) . x + this - > _labelShouldRetain - > getContentSize ( ) . width / 2 ,
this - > _labelShouldRetain - > getPosition ( ) . y ) ) ;
}
/// BMFontUnicodeNew
LabelFNTUNICODELanguages : : LabelFNTUNICODELanguages ( )
{
2013-08-16 16:05:27 +08:00
auto strings = Dictionary : : createWithContentsOfFile ( " fonts/strings.xml " ) ;
2013-08-13 04:29:54 +08:00
const char * chinese = static_cast < String * > ( strings - > objectForKey ( " chinese1 " ) ) - > _string . c_str ( ) ;
const char * japanese = static_cast < String * > ( strings - > objectForKey ( " japanese " ) ) - > _string . c_str ( ) ;
const char * russian = static_cast < String * > ( strings - > objectForKey ( " russian " ) ) - > _string . c_str ( ) ;
const char * spanish = static_cast < String * > ( strings - > objectForKey ( " spanish " ) ) - > _string . c_str ( ) ;
2013-08-16 16:05:27 +08:00
auto s = Director : : getInstance ( ) - > getWinSize ( ) ;
2013-08-13 04:29:54 +08:00
2013-08-13 06:09:28 +08:00
auto label1 = Label : : createWithBMFont ( spanish , " fonts/arial-unicode-26.fnt " , TextHAlignment : : CENTER , 200 ) ;
2013-08-13 04:29:54 +08:00
addChild ( label1 ) ;
label1 - > setAnchorPoint ( Point ( 0.5f , 0.5f ) ) ;
label1 - > setPosition ( Point ( s . width / 2 , s . height / 5 * 3 ) ) ;
auto label2 = Label : : createWithBMFont ( chinese , " fonts/arial-unicode-26.fnt " ) ;
addChild ( label2 ) ;
label2 - > setAnchorPoint ( Point ( 0.5f , 0.5f ) ) ;
label2 - > setPosition ( Point ( s . width / 2 , s . height / 5 * 2.5 ) ) ;
auto label3 = Label : : createWithBMFont ( russian , " fonts/arial-26-en-ru.fnt " ) ;
addChild ( label3 ) ;
label3 - > setAnchorPoint ( Point ( 0.5f , 0.5f ) ) ;
label3 - > setPosition ( Point ( s . width / 2 , s . height / 5 * 2 ) ) ;
auto label4 = Label : : createWithBMFont ( japanese , " fonts/arial-unicode-26.fnt " ) ;
addChild ( label4 ) ;
label4 - > setAnchorPoint ( Point ( 0.5f , 0.5f ) ) ;
label4 - > setPosition ( Point ( s . width / 2 , s . height / 5 * 1.5 ) ) ;
}
std : : string LabelFNTUNICODELanguages : : title ( )
{
return " New Label + .FNT + UNICODE " ;
}
std : : string LabelFNTUNICODELanguages : : subtitle ( )
{
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
2013-08-13 06:09:28 +08:00
label1 = Label : : createWithBMFont ( " Testing Glyph Designer " , " fonts/boundsTestFont.fnt " , TextHAlignment : : CENTER , s . width ) ;
2013-08-13 04:29:54 +08:00
label1 - > setAnchorPoint ( Point ( 0.5f , 0.5f ) ) ;
addChild ( label1 ) ;
label1 - > setPosition ( Point ( s . width / 2 , s . height / 2 ) ) ;
}
string LabelFNTBounds : : title ( )
{
return " New Label + .FNT + Bounds " ;
}
string LabelFNTBounds : : subtitle ( )
{
return " You should see string enclosed by a box " ;
}
void LabelFNTBounds : : draw ( )
{
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 ) ;
Point vertices [ 4 ] =
{
Point ( origin . width , origin . height ) ,
Point ( labelSize . width + origin . width , origin . height ) ,
Point ( labelSize . width + origin . width , labelSize . height + origin . height ) ,
Point ( origin . width , labelSize . height + origin . height )
} ;
DrawPrimitives : : drawPoly ( vertices , 4 , true ) ;
}
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
2013-08-13 06:41:29 +08:00
auto label1 = Label : : createWithTTF ( LongSentencesExample , " fonts/arial.ttf " , 28 , size . width , TextHAlignment : : CENTER , GlyphCollection : : NEHE ) ;
2013-08-13 04:29:54 +08:00
label1 - > setPosition ( Point ( size . width / 2 , size . height / 2 ) ) ;
label1 - > setAnchorPoint ( Point ( 0.5 , 1.0 ) ) ;
addChild ( label1 ) ;
}
std : : string LabelTTFLongLineWrapping : : title ( )
{
return " New Label + .TTF " ;
}
std : : string LabelTTFLongLineWrapping : : subtitle ( )
{
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
// Green
2013-08-13 06:41:29 +08:00
auto label1 = Label : : createWithTTF ( " Green " , " fonts/arial.ttf " , 35 , size . width , TextHAlignment : : CENTER , GlyphCollection : : NEHE ) ;
2013-08-13 04:29:54 +08:00
label1 - > setPosition ( Point ( size . width / 2 , size . height / 5 * 1.5 ) ) ;
label1 - > setColor ( Color3B : : GREEN ) ;
label1 - > setAnchorPoint ( Point ( 0.5 , 0.5 ) ) ;
addChild ( label1 ) ;
// Red
2013-08-13 06:41:29 +08:00
auto label2 = Label : : createWithTTF ( " Red " , " fonts/arial.ttf " , 35 , size . width , TextHAlignment : : CENTER , GlyphCollection : : NEHE ) ;
2013-08-13 04:29:54 +08:00
label2 - > setPosition ( Point ( size . width / 2 , size . height / 5 * 2.0 ) ) ;
label2 - > setColor ( Color3B : : RED ) ;
label2 - > setAnchorPoint ( Point ( 0.5 , 0.5 ) ) ;
addChild ( label2 ) ;
// Blue
2013-08-13 06:41:29 +08:00
auto label3 = Label : : createWithTTF ( " Blue " , " fonts/arial.ttf " , 35 , size . width , TextHAlignment : : CENTER , GlyphCollection : : NEHE ) ;
2013-08-13 04:29:54 +08:00
label3 - > setPosition ( Point ( size . width / 2 , size . height / 5 * 2.5 ) ) ;
label3 - > setColor ( Color3B : : BLUE ) ;
label3 - > setAnchorPoint ( Point ( 0.5 , 0.5 ) ) ;
addChild ( label3 ) ;
}
std : : string LabelTTFColor : : title ( )
{
return " New Label + .TTF " ;
}
std : : string LabelTTFColor : : subtitle ( )
{
return " Uses the new Label with TTF. Testing Color " ;
}
LabelTTFDynamicAlignment : : LabelTTFDynamicAlignment ( )
{
2013-08-16 16:05:27 +08:00
auto size = Director : : getInstance ( ) - > getWinSize ( ) ;
2013-08-13 04:29:54 +08:00
2013-08-13 06:41:29 +08:00
_label = Label : : createWithTTF ( LongSentencesExample , " fonts/arial.ttf " , 45 , size . width , TextHAlignment : : CENTER , GlyphCollection : : NEHE ) ;
2013-08-13 04:29:54 +08:00
_label - > setPosition ( Point ( size . width / 2 , size . height / 2 ) ) ;
_label - > setAnchorPoint ( Point ( 0.5 , 0.5 ) ) ;
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 ) ) ,
NULL ) ;
menu - > alignItemsVerticallyWithPadding ( 4 ) ;
menu - > setPosition ( Point ( 50 , size . height / 4 ) ) ;
addChild ( _label ) ;
this - > addChild ( menu ) ;
}
void LabelTTFDynamicAlignment : : updateAlignment ( )
{
if ( _label )
{
_label - > setAlignment ( _horizAlign ) ;
}
}
void LabelTTFDynamicAlignment : : setAlignmentLeft ( Object * sender )
{
_horizAlign = TextHAlignment : : LEFT ;
this - > updateAlignment ( ) ;
}
void LabelTTFDynamicAlignment : : setAlignmentCenter ( Object * sender )
{
_horizAlign = TextHAlignment : : CENTER ;
this - > updateAlignment ( ) ;
}
void LabelTTFDynamicAlignment : : setAlignmentRight ( Object * sender )
{
_horizAlign = TextHAlignment : : RIGHT ;
this - > updateAlignment ( ) ;
}
std : : string LabelTTFDynamicAlignment : : title ( )
{
return " New Label + .TTF " ;
}
std : : string LabelTTFDynamicAlignment : : subtitle ( )
{
return " Uses the new Label with TTF. Testing alignment " ;
}
//
// NewLabelTTF unicode test
//
LabelTTFUnicodeNew : : LabelTTFUnicodeNew ( )
{
2013-08-16 16:05:27 +08:00
auto strings = Dictionary : : createWithContentsOfFile ( " fonts/strings.xml " ) ;
2013-08-13 04:29:54 +08:00
const char * chinese = static_cast < String * > ( strings - > objectForKey ( " chinese1 " ) ) - > _string . c_str ( ) ;
//const char *russian = static_cast<String*>(strings->objectForKey("russian"))->_string.c_str();
//const char *spanish = static_cast<String*>(strings->objectForKey("spanish"))->_string.c_str();
//const char *japanese = static_cast<String*>(strings->objectForKey("japanese"))->_string.c_str();
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 ;
// Spanish
2013-08-13 06:41:29 +08:00
auto label1 = Label : : createWithTTF ( " Buen día, ¿cómo te llamas? " , " fonts/arial.ttf " , 45 , size . width , TextHAlignment : : CENTER , GlyphCollection : : ASCII ) ;
2013-08-13 04:29:54 +08:00
label1 - > setPosition ( Point ( size . width / 2 , vSize - ( vStep * 4.5 ) ) ) ;
label1 - > setAnchorPoint ( Point ( 0.5 , 0.5 ) ) ;
addChild ( label1 ) ;
// German
2013-08-13 06:41:29 +08:00
auto label2 = Label : : createWithTTF ( " In welcher Straße haben Sie gelebt? " , " fonts/arial.ttf " , 45 , size . width , TextHAlignment : : CENTER , GlyphCollection : : ASCII ) ;
2013-08-13 04:29:54 +08:00
label2 - > setPosition ( Point ( size . width / 2 , vSize - ( vStep * 5.5 ) ) ) ;
label2 - > setAnchorPoint ( Point ( 0.5 , 0.5 ) ) ;
addChild ( label2 ) ;
// chinese
2013-08-13 06:41:29 +08:00
auto label3 = Label : : createWithTTF ( chinese , " fonts/wt021.ttf " , 45 , size . width , TextHAlignment : : CENTER , GlyphCollection : : CUSTOM , chinese ) ;
2013-08-13 04:29:54 +08:00
label3 - > setPosition ( Point ( size . width / 2 , vSize - ( vStep * 6.5 ) ) ) ;
label3 - > setAnchorPoint ( Point ( 0.5 , 0.5 ) ) ;
addChild ( label3 ) ;
}
std : : string LabelTTFUnicodeNew : : title ( )
{
return " New Label + TTF unicode " ;
}
std : : string LabelTTFUnicodeNew : : subtitle ( )
{
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 " ,
" fonts/Schwarzwald Regular.ttf " ,
" 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 ( ) ;
2013-08-13 04:29:54 +08:00
for ( int i = 0 ; i < arraysize ( ttfpaths ) ; + + i ) {
2013-08-13 06:41:29 +08:00
auto label = Label : : createWithTTF ( ttfpaths [ i ] , ttfpaths [ i ] , 40 , 0 , TextHAlignment : : CENTER , GlyphCollection : : NEHE ) ;
2013-08-13 04:29:54 +08:00
if ( label ) {
label - > setPosition ( Point ( size . width / 2 , ( ( size . height * 0.6 ) / arraysize ( ttfpaths ) * i ) + ( size . height / 5 ) ) ) ;
addChild ( label ) ;
label - > setAnchorPoint ( Point ( 0.5 , 0.5 ) ) ;
} else {
log ( " ERROR: Cannot load: %s " , ttfpaths [ i ] ) ;
}
}
}
std : : string LabelTTFFontsTestNew : : title ( )
{
return " New Label + TTF " ;
}
std : : string LabelTTFFontsTestNew : : subtitle ( )
{
return " " ;
}
LabelBMFontTestNew : : LabelBMFontTestNew ( )
{
2013-08-16 16:05:27 +08:00
auto size = Director : : getInstance ( ) - > getWinSize ( ) ;
2013-08-13 04:29:54 +08:00
2013-08-13 06:09:28 +08:00
auto label1 = Label : : createWithBMFont ( " Hello World, this is testing the new Label using fnt file " , " fonts/bitmapFontTest2.fnt " , TextHAlignment : : CENTER , size . width ) ;
2013-08-13 04:29:54 +08:00
label1 - > setPosition ( Point ( size . width / 2 , size . height / 2 ) ) ;
label1 - > setAnchorPoint ( Point ( 0.5 , 0.5 ) ) ;
addChild ( label1 ) ;
}
std : : string LabelBMFontTestNew : : title ( )
{
return " New Label + FNT " ;
}
std : : string LabelBMFontTestNew : : subtitle ( )
{
return " Uses the new Label with .FNT file " ;
}