2012-03-22 11:48:37 +08:00
# include "LabelTest.h"
# include "../testResource.h"
2010-09-07 11:47:54 +08:00
enum {
2012-04-19 14:35:52 +08:00
kTagTileMap = 1 ,
kTagSpriteManager = 1 ,
kTagAnimation1 = 1 ,
kTagBitmapAtlas1 = 1 ,
kTagBitmapAtlas2 = 2 ,
kTagBitmapAtlas3 = 3 ,
2010-09-07 11:47:54 +08:00
} ;
enum {
2012-04-19 14:35:52 +08:00
kTagSprite1 ,
kTagSprite2 ,
kTagSprite3 ,
kTagSprite4 ,
kTagSprite5 ,
kTagSprite6 ,
kTagSprite7 ,
kTagSprite8 ,
2012-03-22 11:48:37 +08:00
} ;
2010-09-07 11:47:54 +08:00
//------------------------------------------------------------------
//
// AtlasDemo
//
//------------------------------------------------------------------
2012-03-22 11:48:37 +08:00
2010-09-07 11:47:54 +08:00
enum
{
2012-04-19 14:35:52 +08:00
IDC_NEXT = 100 ,
IDC_BACK ,
IDC_RESTART
2010-09-07 11:47:54 +08:00
} ;
2011-07-08 15:57:46 +08:00
CCLayer * nextAtlasAction ( ) ;
CCLayer * backAtlasAction ( ) ;
CCLayer * restartAtlasAction ( ) ;
2012-03-22 11:48:37 +08:00
static int sceneIdx = - 1 ;
2012-11-20 18:17:47 +08:00
# define MAX_LAYER 27
2010-09-07 11:47:54 +08:00
CCLayer * createAtlasLayer ( int nIndex )
{
2012-04-19 14:35:52 +08:00
switch ( nIndex )
{
case 0 : return new LabelAtlasTest ( ) ;
case 1 : return new LabelAtlasColorTest ( ) ;
case 2 : return new Atlas3 ( ) ;
case 3 : return new Atlas4 ( ) ;
case 4 : return new Atlas5 ( ) ;
case 5 : return new Atlas6 ( ) ;
case 6 : return new AtlasBitmapColor ( ) ;
case 7 : return new AtlasFastBitmap ( ) ;
2011-02-23 16:47:25 +08:00
case 8 : return new BitmapFontMultiLine ( ) ;
2012-03-22 11:48:37 +08:00
case 9 : return new LabelsEmpty ( ) ;
case 10 : return new LabelBMFontHD ( ) ;
case 11 : return new LabelAtlasHD ( ) ;
2011-02-23 16:47:25 +08:00
case 12 : return new LabelGlyphDesigner ( ) ;
// Not a label test. Should be moved to Atlas test
case 13 : return new Atlas1 ( ) ;
2012-04-19 14:35:52 +08:00
case 14 : return new LabelTTFTest ( ) ;
case 15 : return new LabelTTFMultiline ( ) ;
case 16 : return new LabelTTFChinese ( ) ;
2012-01-18 18:43:41 +08:00
case 17 : return new LabelBMFontChinese ( ) ;
2012-04-19 14:35:52 +08:00
case 18 : return new BitmapFontMultiLineAlignment ( ) ;
case 19 : return new LabelTTFA8Test ( ) ;
case 20 : return new BMFontOneAtlas ( ) ;
case 21 : return new BMFontUnicode ( ) ;
2012-06-12 14:33:53 +08:00
case 22 : return new BMFontInit ( ) ;
case 23 : return new TTFFontInit ( ) ;
case 24 : return new Issue1343 ( ) ;
case 25 : return new LabelTTFAlignment ( ) ;
2012-11-20 18:17:47 +08:00
case 26 : return new LabelBMFontBounds ( ) ;
2012-04-19 14:35:52 +08:00
}
2010-09-07 11:47:54 +08:00
2012-04-19 14:35:52 +08:00
return NULL ;
2010-09-07 11:47:54 +08:00
}
CCLayer * nextAtlasAction ( )
{
2012-04-19 14:35:52 +08:00
sceneIdx + + ;
sceneIdx = sceneIdx % MAX_LAYER ;
2010-09-07 11:47:54 +08:00
2012-04-19 14:35:52 +08:00
CCLayer * pLayer = createAtlasLayer ( sceneIdx ) ;
pLayer - > autorelease ( ) ;
2010-09-07 11:47:54 +08:00
2012-04-19 14:35:52 +08:00
return pLayer ;
2010-09-07 11:47:54 +08:00
}
CCLayer * backAtlasAction ( )
{
2012-04-19 14:35:52 +08:00
sceneIdx - - ;
int total = MAX_LAYER ;
if ( sceneIdx < 0 )
sceneIdx + = total ;
CCLayer * pLayer = createAtlasLayer ( sceneIdx ) ;
pLayer - > autorelease ( ) ;
2010-09-07 11:47:54 +08:00
2012-04-19 14:35:52 +08:00
return pLayer ;
2010-09-07 11:47:54 +08:00
}
CCLayer * restartAtlasAction ( )
{
2012-04-19 14:35:52 +08:00
CCLayer * pLayer = createAtlasLayer ( sceneIdx ) ;
pLayer - > autorelease ( ) ;
2010-09-07 11:47:54 +08:00
2012-04-19 14:35:52 +08:00
return pLayer ;
2012-03-22 11:48:37 +08:00
}
AtlasDemo : : AtlasDemo ( void )
{
}
AtlasDemo : : ~ AtlasDemo ( void )
{
}
2010-09-07 11:47:54 +08:00
std : : string AtlasDemo : : title ( )
{
2012-04-19 14:35:52 +08:00
return " No title " ;
2010-09-07 11:47:54 +08:00
}
std : : string AtlasDemo : : subtitle ( )
{
2012-04-19 14:35:52 +08:00
return " " ;
2010-09-07 11:47:54 +08:00
}
void AtlasDemo : : onEnter ( )
{
2012-04-19 14:35:52 +08:00
CCLayer : : onEnter ( ) ;
2010-09-07 11:47:54 +08:00
2012-04-19 14:35:52 +08:00
CCSize s = CCDirector : : sharedDirector ( ) - > getWinSize ( ) ;
2010-09-07 11:47:54 +08:00
2012-06-14 15:13:16 +08:00
CCLabelTTF * label = CCLabelTTF : : create ( title ( ) . c_str ( ) , " Arial " , 28 ) ;
2012-04-19 14:35:52 +08:00
addChild ( label , 1 ) ;
label - > setPosition ( ccp ( s . width / 2 , s . height - 50 ) ) ;
2010-09-07 11:47:54 +08:00
2012-04-19 14:35:52 +08:00
std : : string strSubtitle = subtitle ( ) ;
if ( ! strSubtitle . empty ( ) )
{
2012-06-14 15:13:16 +08:00
CCLabelTTF * l = CCLabelTTF : : create ( strSubtitle . c_str ( ) , " Thonburi " , 16 ) ;
2012-04-19 14:35:52 +08:00
addChild ( l , 1 ) ;
l - > setPosition ( ccp ( s . width / 2 , s . height - 80 ) ) ;
}
2010-09-07 11:47:54 +08:00
2012-06-14 15:13:16 +08:00
CCMenuItemImage * item1 = CCMenuItemImage : : create ( s_pPathB1 , s_pPathB2 , this , menu_selector ( AtlasDemo : : backCallback ) ) ;
CCMenuItemImage * item2 = CCMenuItemImage : : create ( s_pPathR1 , s_pPathR2 , this , menu_selector ( AtlasDemo : : restartCallback ) ) ;
CCMenuItemImage * item3 = CCMenuItemImage : : create ( s_pPathF1 , s_pPathF2 , this , menu_selector ( AtlasDemo : : nextCallback ) ) ;
2010-09-07 11:47:54 +08:00
2012-06-14 15:13:16 +08:00
CCMenu * menu = CCMenu : : create ( item1 , item2 , item3 , NULL ) ;
2010-09-07 11:47:54 +08:00
2012-04-19 14:35:52 +08:00
menu - > setPosition ( CCPointZero ) ;
2012-10-23 17:48:50 +08:00
item1 - > setPosition ( ccp ( VisibleRect : : center ( ) . x - item2 - > getContentSize ( ) . width * 2 , VisibleRect : : bottom ( ) . y + item2 - > getContentSize ( ) . height / 2 ) ) ;
item2 - > setPosition ( ccp ( VisibleRect : : center ( ) . x , VisibleRect : : bottom ( ) . y + item2 - > getContentSize ( ) . height / 2 ) ) ;
item3 - > setPosition ( ccp ( VisibleRect : : center ( ) . x + item2 - > getContentSize ( ) . width * 2 , VisibleRect : : bottom ( ) . y + item2 - > getContentSize ( ) . height / 2 ) ) ; ;
2012-04-19 14:35:52 +08:00
addChild ( menu , 1 ) ;
2010-09-07 11:47:54 +08:00
}
2011-03-07 17:11:57 +08:00
void AtlasDemo : : restartCallback ( CCObject * pSender )
2010-09-07 11:47:54 +08:00
{
2012-04-19 14:35:52 +08:00
CCScene * s = new AtlasTestScene ( ) ;
s - > addChild ( restartAtlasAction ( ) ) ;
2010-09-07 11:47:54 +08:00
2012-04-19 14:35:52 +08:00
CCDirector : : sharedDirector ( ) - > replaceScene ( s ) ;
2010-09-07 11:47:54 +08:00
s - > release ( ) ;
}
2011-03-07 17:11:57 +08:00
void AtlasDemo : : nextCallback ( CCObject * pSender )
2010-09-07 11:47:54 +08:00
{
2012-04-19 14:35:52 +08:00
CCScene * s = new AtlasTestScene ( ) ;
s - > addChild ( nextAtlasAction ( ) ) ;
CCDirector : : sharedDirector ( ) - > replaceScene ( s ) ;
2010-09-07 11:47:54 +08:00
s - > release ( ) ;
}
2011-03-07 17:11:57 +08:00
void AtlasDemo : : backCallback ( CCObject * pSender )
2010-09-07 11:47:54 +08:00
{
2012-04-19 14:35:52 +08:00
CCScene * s = new AtlasTestScene ( ) ;
s - > addChild ( backAtlasAction ( ) ) ;
CCDirector : : sharedDirector ( ) - > replaceScene ( s ) ;
2010-09-07 11:47:54 +08:00
s - > release ( ) ;
}
2012-03-22 11:48:37 +08:00
2010-09-07 11:47:54 +08:00
//------------------------------------------------------------------
//
// Atlas1
//
//------------------------------------------------------------------
Atlas1 : : Atlas1 ( )
{
2012-06-27 14:21:29 +08:00
m_textureAtlas = CCTextureAtlas : : create ( s_AtlasTest , 3 ) ; m_textureAtlas - > retain ( ) ;
2012-04-19 14:35:52 +08:00
CCSize s = CCDirector : : sharedDirector ( ) - > getWinSize ( ) ;
//
// Notice: u,v tex coordinates are inverted
//
ccV3F_C4B_T2F_Quad quads [ ] =
{
{
{ { 0 , 0 , 0 } , ccc4 ( 0 , 0 , 255 , 255 ) , { 0.0f , 1.0f } , } , // bottom left
{ { s . width , 0 , 0 } , ccc4 ( 0 , 0 , 255 , 0 ) , { 1.0f , 1.0f } , } , // bottom right
{ { 0 , s . height , 0 } , ccc4 ( 0 , 0 , 255 , 0 ) , { 0.0f , 0.0f } , } , // top left
{ { s . width , s . height , 0 } , { 0 , 0 , 255 , 255 } , { 1.0f , 0.0f } , } , // top right
} ,
{
{ { 40 , 40 , 0 } , ccc4 ( 255 , 255 , 255 , 255 ) , { 0.0f , 0.2f } , } , // bottom left
{ { 120 , 80 , 0 } , ccc4 ( 255 , 0 , 0 , 255 ) , { 0.5f , 0.2f } , } , // bottom right
{ { 40 , 160 , 0 } , ccc4 ( 255 , 255 , 255 , 255 ) , { 0.0f , 0.0f } , } , // top left
{ { 160 , 160 , 0 } , ccc4 ( 0 , 255 , 0 , 255 ) , { 0.5f , 0.0f } , } , // top right
} ,
{
{ { s . width / 2 , 40 , 0 } , ccc4 ( 255 , 0 , 0 , 255 ) , { 0.0f , 1.0f } , } , // bottom left
{ { s . width , 40 , 0 } , ccc4 ( 0 , 255 , 0 , 255 ) , { 1.0f , 1.0f } , } , // bottom right
{ { s . width / 2 - 50 , 200 , 0 } , ccc4 ( 0 , 0 , 255 , 255 ) , { 0.0f , 0.0f } , } , // top left
{ { s . width , 100 , 0 } , ccc4 ( 255 , 255 , 0 , 255 ) , { 1.0f , 0.0f } , } , // top right
} ,
} ;
for ( int i = 0 ; i < 3 ; i + + )
{
m_textureAtlas - > updateQuad ( & quads [ i ] , i ) ;
}
2012-03-22 11:48:37 +08:00
}
2010-09-07 11:47:54 +08:00
Atlas1 : : ~ Atlas1 ( )
{
2012-04-19 14:35:52 +08:00
m_textureAtlas - > release ( ) ;
2012-03-22 11:48:37 +08:00
}
2010-09-07 11:47:54 +08:00
void Atlas1 : : draw ( )
{
2012-04-19 14:35:52 +08:00
// GL_VERTEX_ARRAY, GL_COLOR_ARRAY, GL_TEXTURE_COORD_ARRAY
// GL_TEXTURE_2D
2010-09-07 11:47:54 +08:00
2012-04-19 14:35:52 +08:00
m_textureAtlas - > drawQuads ( ) ;
2010-09-07 11:47:54 +08:00
2012-04-19 14:35:52 +08:00
// [textureAtlas drawNumberOfQuads:3];
2012-03-22 11:48:37 +08:00
}
2010-09-07 11:47:54 +08:00
std : : string Atlas1 : : title ( )
{
2012-04-19 14:35:52 +08:00
return " CCTextureAtlas " ;
2012-03-22 11:48:37 +08:00
}
std : : string Atlas1 : : subtitle ( )
{
2012-04-19 14:35:52 +08:00
return " Manual creation of CCTextureAtlas " ;
2012-03-22 11:48:37 +08:00
}
2010-09-07 11:47:54 +08:00
//------------------------------------------------------------------
//
// LabelAtlasTest
//
//------------------------------------------------------------------
LabelAtlasTest : : LabelAtlasTest ( )
{
2012-04-19 14:35:52 +08:00
m_time = 0 ;
2010-09-07 11:47:54 +08:00
2012-06-14 15:13:16 +08:00
CCLabelAtlas * label1 = CCLabelAtlas : : create ( " 123 Test " , " fonts/tuffy_bold_italic-charmap.plist " ) ;
2012-04-19 14:35:52 +08:00
addChild ( label1 , 0 , kTagSprite1 ) ;
label1 - > setPosition ( ccp ( 10 , 100 ) ) ;
label1 - > setOpacity ( 200 ) ;
2010-09-07 11:47:54 +08:00
2012-06-14 15:13:16 +08:00
CCLabelAtlas * label2 = CCLabelAtlas : : create ( " 0123456789 " , " fonts/tuffy_bold_italic-charmap.plist " ) ;
2012-04-19 14:35:52 +08:00
addChild ( label2 , 0 , kTagSprite2 ) ;
label2 - > setPosition ( ccp ( 10 , 200 ) ) ;
label2 - > setOpacity ( 32 ) ;
2010-09-07 11:47:54 +08:00
2012-04-19 14:35:52 +08:00
schedule ( schedule_selector ( LabelAtlasTest : : step ) ) ;
2010-09-07 11:47:54 +08:00
}
2012-06-08 13:55:28 +08:00
void LabelAtlasTest : : step ( float dt )
2010-09-07 11:47:54 +08:00
{
2012-04-19 14:35:52 +08:00
m_time + = dt ;
2010-09-07 11:47:54 +08:00
char string [ 12 ] = { 0 } ;
sprintf ( string , " %2.2f Test " , m_time ) ;
2012-04-19 14:35:52 +08:00
//string.format("%2.2f Test", m_time);
2010-09-07 11:47:54 +08:00
2012-04-19 14:35:52 +08:00
CCLabelAtlas * label1 = ( CCLabelAtlas * ) getChildByTag ( kTagSprite1 ) ;
label1 - > setString ( string ) ;
2010-09-07 11:47:54 +08:00
2012-04-19 14:35:52 +08:00
CCLabelAtlas * label2 = ( CCLabelAtlas * ) getChildByTag ( kTagSprite2 ) ;
2010-09-07 11:47:54 +08:00
sprintf ( string , " %d " , ( int ) m_time ) ;
2012-04-19 14:35:52 +08:00
//string.format("%d", (int)m_time);
label2 - > setString ( string ) ;
2010-09-07 11:47:54 +08:00
}
std : : string LabelAtlasTest : : title ( )
{
2012-04-19 14:35:52 +08:00
return " LabelAtlas " ;
2012-03-22 11:48:37 +08:00
}
std : : string LabelAtlasTest : : subtitle ( )
{
2012-04-19 14:35:52 +08:00
return " Updating label should be fast " ;
2012-03-22 11:48:37 +08:00
}
2010-09-07 11:47:54 +08:00
//------------------------------------------------------------------
//
// LabelAtlasColorTest
//
//------------------------------------------------------------------
2012-03-22 11:48:37 +08:00
LabelAtlasColorTest : : LabelAtlasColorTest ( )
{
2012-06-14 15:13:16 +08:00
CCLabelAtlas * label1 = CCLabelAtlas : : create ( " 123 Test " , " fonts/tuffy_bold_italic-charmap.png " , 48 , 64 , ' ' ) ;
2012-04-19 14:35:52 +08:00
addChild ( label1 , 0 , kTagSprite1 ) ;
label1 - > setPosition ( ccp ( 10 , 100 ) ) ;
label1 - > setOpacity ( 200 ) ;
2012-06-14 15:13:16 +08:00
CCLabelAtlas * label2 = CCLabelAtlas : : create ( " 0123456789 " , " fonts/tuffy_bold_italic-charmap.png " , 48 , 64 , ' ' ) ;
2012-04-19 14:35:52 +08:00
addChild ( label2 , 0 , kTagSprite2 ) ;
label2 - > setPosition ( ccp ( 10 , 200 ) ) ;
label2 - > setColor ( ccRED ) ;
2012-03-22 11:48:37 +08:00
2012-06-14 15:13:16 +08:00
CCActionInterval * fade = CCFadeOut : : create ( 1.0f ) ;
2012-04-19 14:35:52 +08:00
CCActionInterval * fade_in = fade - > reverse ( ) ;
2013-02-28 15:57:15 +08:00
CCCallFunc * cb = CCCallFunc : : create ( this , callfunc_selector ( LabelAtlasColorTest : : actionFinishCallback ) ) ;
CCSequence * seq = CCSequence : : create ( fade , fade_in , cb , NULL ) ;
2012-12-10 14:12:56 +08:00
CCAction * repeat = CCRepeatForever : : create ( seq ) ;
2012-04-19 14:35:52 +08:00
label2 - > runAction ( repeat ) ;
2012-03-22 11:48:37 +08:00
2012-04-19 14:35:52 +08:00
m_time = 0 ;
schedule ( schedule_selector ( LabelAtlasColorTest : : step ) ) ; //:@selector(step:)];
2012-03-22 11:48:37 +08:00
}
2013-02-28 15:57:15 +08:00
void LabelAtlasColorTest : : actionFinishCallback ( )
{
CCLOG ( " Action finished " ) ;
}
2012-06-08 13:55:28 +08:00
void LabelAtlasColorTest : : step ( float dt )
2012-03-22 11:48:37 +08:00
{
2012-04-19 14:35:52 +08:00
m_time + = dt ;
2012-03-22 11:48:37 +08:00
char string [ 12 ] = { 0 } ;
sprintf ( string , " %2.2f Test " , m_time ) ;
2012-06-14 16:05:58 +08:00
//std::string string = std::string::createWithFormat("%2.2f Test", m_time);
2012-04-19 14:35:52 +08:00
CCLabelAtlas * label1 = ( CCLabelAtlas * ) getChildByTag ( kTagSprite1 ) ;
label1 - > setString ( string ) ;
CCLabelAtlas * label2 = ( CCLabelAtlas * ) getChildByTag ( kTagSprite2 ) ;
2012-03-22 11:48:37 +08:00
sprintf ( string , " %d " , ( int ) m_time ) ;
2012-04-19 14:35:52 +08:00
label2 - > setString ( string ) ;
2012-03-22 11:48:37 +08:00
}
std : : string LabelAtlasColorTest : : title ( )
{
2012-04-19 14:35:52 +08:00
return " CCLabelAtlas " ;
2012-03-22 11:48:37 +08:00
}
std : : string LabelAtlasColorTest : : subtitle ( )
{
2012-04-19 14:35:52 +08:00
return " Opacity + Color should work at the same time " ;
2012-03-22 11:48:37 +08:00
}
2012-06-12 14:33:53 +08:00
//------------------------------------------------------------------
//
// LabelTTFAlignment
//
//------------------------------------------------------------------
LabelTTFAlignment : : LabelTTFAlignment ( )
{
2012-06-15 15:10:40 +08:00
CCSize s = CCDirector : : sharedDirector ( ) - > getWinSize ( ) ;
2012-08-01 13:24:23 +08:00
CCLabelTTF * ttf0 = CCLabelTTF : : create ( " Alignment 0 \n new line " , " Helvetica " , 12 ,
CCSizeMake ( 256 , 32 ) , kCCTextAlignmentLeft ) ;
2012-06-15 15:10:40 +08:00
ttf0 - > setPosition ( ccp ( s . width / 2 , ( s . height / 6 ) * 2 ) ) ;
ttf0 - > setAnchorPoint ( ccp ( 0.5f , 0.5f ) ) ;
this - > addChild ( ttf0 ) ;
2012-08-01 13:24:23 +08:00
CCLabelTTF * ttf1 = CCLabelTTF : : create ( " Alignment 1 \n new line " , " Helvetica " , 12 ,
CCSizeMake ( 245 , 32 ) , kCCTextAlignmentCenter ) ;
2012-06-15 15:10:40 +08:00
ttf1 - > setPosition ( ccp ( s . width / 2 , ( s . height / 6 ) * 3 ) ) ;
ttf1 - > setAnchorPoint ( ccp ( 0.5f , 0.5f ) ) ;
this - > addChild ( ttf1 ) ;
2012-08-01 13:24:23 +08:00
CCLabelTTF * ttf2 = CCLabelTTF : : create ( " Alignment 2 \n new line " , " Helvetica " , 12 ,
CCSizeMake ( 245 , 32 ) , kCCTextAlignmentRight ) ;
2012-06-15 15:10:40 +08:00
ttf2 - > setPosition ( ccp ( s . width / 2 , ( s . height / 6 ) * 4 ) ) ;
ttf2 - > setAnchorPoint ( ccp ( 0.5f , 0.5f ) ) ;
2012-06-12 14:33:53 +08:00
this - > addChild ( ttf2 ) ;
}
std : : string LabelTTFAlignment : : title ( )
{
return " CCLabelTTF alignment " ;
}
std : : string LabelTTFAlignment : : subtitle ( )
{
return " Tests alignment values " ;
}
2010-09-07 11:47:54 +08:00
//------------------------------------------------------------------
//
// Atlas3
2012-03-22 11:48:37 +08:00
//
// Use any of these editors to generate BMFonts:
// http://glyphdesigner.71squared.com/ (Commercial, Mac OS X)
// http://www.n4te.com/hiero/hiero.jnlp (Free, Java)
// http://slick.cokeandcode.com/demos/hiero.jnlp (Free, Java)
// http://www.angelcode.com/products/bmfont/ (Free, Windows only)
2010-09-07 11:47:54 +08:00
//
//------------------------------------------------------------------
Atlas3 : : Atlas3 ( )
{
2012-04-19 14:35:52 +08:00
m_time = 0 ;
2012-06-14 15:13:16 +08:00
CCLayerColor * col = CCLayerColor : : create ( ccc4 ( 128 , 128 , 128 , 255 ) ) ;
2012-04-19 14:35:52 +08:00
addChild ( col , - 10 ) ;
2012-06-14 15:13:16 +08:00
CCLabelBMFont * label1 = CCLabelBMFont : : create ( " Test " , " fonts/bitmapFontTest2.fnt " ) ;
2012-04-19 14:35:52 +08:00
// testing anchors
label1 - > setAnchorPoint ( ccp ( 0 , 0 ) ) ;
addChild ( label1 , 0 , kTagBitmapAtlas1 ) ;
2012-06-14 15:13:16 +08:00
CCActionInterval * fade = CCFadeOut : : create ( 1.0f ) ;
2012-04-19 14:35:52 +08:00
CCActionInterval * fade_in = fade - > reverse ( ) ;
2012-12-10 14:12:56 +08:00
CCSequence * seq = CCSequence : : create ( fade , fade_in , NULL ) ;
CCAction * repeat = CCRepeatForever : : create ( seq ) ;
2012-04-19 14:35:52 +08:00
label1 - > runAction ( repeat ) ;
// VERY IMPORTANT
// color and opacity work OK because bitmapFontAltas2 loads a BMP image (not a PNG image)
// If you want to use both opacity and color, it is recommended to use NON premultiplied images like BMP images
// Of course, you can also tell XCode not to compress PNG images, but I think it doesn't work as expected
2012-06-14 15:13:16 +08:00
CCLabelBMFont * label2 = CCLabelBMFont : : create ( " Test " , " fonts/bitmapFontTest2.fnt " ) ;
2012-04-19 14:35:52 +08:00
// testing anchors
label2 - > setAnchorPoint ( ccp ( 0.5f , 0.5f ) ) ;
label2 - > setColor ( ccRED ) ;
addChild ( label2 , 0 , kTagBitmapAtlas2 ) ;
label2 - > runAction ( ( CCAction * ) ( repeat - > copy ( ) - > autorelease ( ) ) ) ;
2012-06-14 15:13:16 +08:00
CCLabelBMFont * label3 = CCLabelBMFont : : create ( " Test " , " fonts/bitmapFontTest2.fnt " ) ;
2012-04-19 14:35:52 +08:00
// testing anchors
label3 - > setAnchorPoint ( ccp ( 1 , 1 ) ) ;
addChild ( label3 , 0 , kTagBitmapAtlas3 ) ;
2013-01-28 20:34:52 +08:00
2012-10-23 17:48:50 +08:00
label1 - > setPosition ( VisibleRect : : leftBottom ( ) ) ;
label2 - > setPosition ( VisibleRect : : center ( ) ) ;
label3 - > setPosition ( VisibleRect : : rightTop ( ) ) ;
2012-04-19 14:35:52 +08:00
schedule ( schedule_selector ( Atlas3 : : step ) ) ; //:@selector(step:)];
2010-09-07 11:47:54 +08:00
}
2012-06-08 13:55:28 +08:00
void Atlas3 : : step ( float dt )
2010-09-07 11:47:54 +08:00
{
2012-04-19 14:35:52 +08:00
m_time + = dt ;
//std::string string;
2010-09-07 11:47:54 +08:00
char string [ 15 ] = { 0 } ;
sprintf ( string , " %2.2f Test j " , m_time ) ;
2012-04-19 14:35:52 +08:00
//string.format("%2.2f Test j", m_time);
CCLabelBMFont * label1 = ( CCLabelBMFont * ) getChildByTag ( kTagBitmapAtlas1 ) ;
label1 - > setString ( string ) ;
CCLabelBMFont * label2 = ( CCLabelBMFont * ) getChildByTag ( kTagBitmapAtlas2 ) ;
label2 - > setString ( string ) ;
CCLabelBMFont * label3 = ( CCLabelBMFont * ) getChildByTag ( kTagBitmapAtlas3 ) ;
label3 - > setString ( string ) ;
2010-09-07 11:47:54 +08:00
}
std : : string Atlas3 : : title ( )
{
2012-04-19 14:35:52 +08:00
return " CCLabelBMFont " ;
2012-03-22 11:48:37 +08:00
}
2010-09-07 11:47:54 +08:00
std : : string Atlas3 : : subtitle ( )
{
2012-04-19 14:35:52 +08:00
return " Testing alignment. Testing opacity + tint " ;
2012-03-22 11:48:37 +08:00
}
2010-09-07 11:47:54 +08:00
//------------------------------------------------------------------
//
// Atlas4
2012-03-22 11:48:37 +08:00
//
// Use any of these editors to generate BMFonts:
// http://glyphdesigner.71squared.com/ (Commercial, Mac OS X)
// http://www.n4te.com/hiero/hiero.jnlp (Free, Java)
// http://slick.cokeandcode.com/demos/hiero.jnlp (Free, Java)
2011-07-08 15:57:46 +08:00
// http://www.angelcode.com/products/bmfont/ (Free, Windows only)
2010-09-07 11:47:54 +08:00
//
//------------------------------------------------------------------
Atlas4 : : Atlas4 ( )
{
2012-04-19 14:35:52 +08:00
m_time = 0 ;
// Upper Label
2012-06-14 15:13:16 +08:00
CCLabelBMFont * label = CCLabelBMFont : : create ( " Bitmap Font Atlas " , " fonts/bitmapFontTest.fnt " ) ;
2012-04-19 14:35:52 +08:00
addChild ( label ) ;
CCSize s = CCDirector : : sharedDirector ( ) - > getWinSize ( ) ;
label - > setPosition ( ccp ( s . width / 2 , s . height / 2 ) ) ;
label - > setAnchorPoint ( ccp ( 0.5f , 0.5f ) ) ;
CCSprite * BChar = ( CCSprite * ) label - > getChildByTag ( 0 ) ;
CCSprite * FChar = ( CCSprite * ) label - > getChildByTag ( 7 ) ;
CCSprite * AChar = ( CCSprite * ) label - > getChildByTag ( 12 ) ;
2012-06-14 15:13:16 +08:00
CCActionInterval * rotate = CCRotateBy : : create ( 2 , 360 ) ;
CCAction * rot_4ever = CCRepeatForever : : create ( rotate ) ;
2012-04-19 14:35:52 +08:00
2012-06-14 15:13:16 +08:00
CCActionInterval * scale = CCScaleBy : : create ( 2 , 1.5f ) ;
2012-04-19 14:35:52 +08:00
CCActionInterval * scale_back = scale - > reverse ( ) ;
2012-12-10 14:12:56 +08:00
CCSequence * scale_seq = CCSequence : : create ( scale , scale_back , NULL ) ;
CCAction * scale_4ever = CCRepeatForever : : create ( scale_seq ) ;
2012-04-19 14:35:52 +08:00
2012-06-14 15:13:16 +08:00
CCActionInterval * jump = CCJumpBy : : create ( 0.5f , CCPointZero , 60 , 1 ) ;
CCAction * jump_4ever = CCRepeatForever : : create ( jump ) ;
2012-04-19 14:35:52 +08:00
2012-06-14 15:13:16 +08:00
CCActionInterval * fade_out = CCFadeOut : : create ( 1 ) ;
CCActionInterval * fade_in = CCFadeIn : : create ( 1 ) ;
2012-12-10 14:12:56 +08:00
CCSequence * seq = CCSequence : : create ( fade_out , fade_in , NULL ) ;
CCAction * fade_4ever = CCRepeatForever : : create ( seq ) ;
2012-04-19 14:35:52 +08:00
BChar - > runAction ( rot_4ever ) ;
BChar - > runAction ( scale_4ever ) ;
FChar - > runAction ( jump_4ever ) ;
AChar - > runAction ( fade_4ever ) ;
// Bottom Label
2012-06-14 15:13:16 +08:00
CCLabelBMFont * label2 = CCLabelBMFont : : create ( " 00.0 " , " fonts/bitmapFontTest.fnt " ) ;
2012-04-19 14:35:52 +08:00
addChild ( label2 , 0 , kTagBitmapAtlas2 ) ;
label2 - > setPosition ( ccp ( s . width / 2.0f , 80 ) ) ;
CCSprite * lastChar = ( CCSprite * ) label2 - > getChildByTag ( 3 ) ;
lastChar - > runAction ( ( CCAction * ) ( rot_4ever - > copy ( ) - > autorelease ( ) ) ) ;
schedule ( schedule_selector ( Atlas4 : : step ) , 0.1f ) ;
2010-09-07 11:47:54 +08:00
}
void Atlas4 : : draw ( )
{
2012-04-19 14:35:52 +08:00
CCSize s = CCDirector : : sharedDirector ( ) - > getWinSize ( ) ;
ccDrawLine ( ccp ( 0 , s . height / 2 ) , ccp ( s . width , s . height / 2 ) ) ;
ccDrawLine ( ccp ( s . width / 2 , 0 ) , ccp ( s . width / 2 , s . height ) ) ;
2010-09-07 11:47:54 +08:00
}
2012-06-08 13:55:28 +08:00
void Atlas4 : : step ( float dt )
2010-09-07 11:47:54 +08:00
{
2012-04-19 14:35:52 +08:00
m_time + = dt ;
2010-09-07 11:47:54 +08:00
char string [ 10 ] = { 0 } ;
sprintf ( string , " %04.1f " , m_time ) ;
2012-04-19 14:35:52 +08:00
// std::string string;
// string.format("%04.1f", m_time);
CCLabelBMFont * label1 = ( CCLabelBMFont * ) getChildByTag ( kTagBitmapAtlas2 ) ;
label1 - > setString ( string ) ;
2010-09-07 11:47:54 +08:00
}
std : : string Atlas4 : : title ( )
{
2012-04-19 14:35:52 +08:00
return " CCLabelBMFont " ;
2012-03-22 11:48:37 +08:00
}
2010-09-07 11:47:54 +08:00
std : : string Atlas4 : : subtitle ( )
{
2012-04-19 14:35:52 +08:00
return " Using fonts as CCSprite objects. Some characters should rotate. " ;
2012-03-22 11:48:37 +08:00
}
2010-09-07 11:47:54 +08:00
//------------------------------------------------------------------
//
// Atlas5
2012-03-22 11:48:37 +08:00
//
// Use any of these editors to generate BMFonts:
// http://glyphdesigner.71squared.com/ (Commercial, Mac OS X)
// http://www.n4te.com/hiero/hiero.jnlp (Free, Java)
// http://slick.cokeandcode.com/demos/hiero.jnlp (Free, Java)
2011-07-08 15:57:46 +08:00
// http://www.angelcode.com/products/bmfont/ (Free, Windows only)
2010-09-07 11:47:54 +08:00
//
//------------------------------------------------------------------
Atlas5 : : Atlas5 ( )
{
2012-06-14 15:13:16 +08:00
CCLabelBMFont * label = CCLabelBMFont : : create ( " abcdefg " , " fonts/bitmapFontTest4.fnt " ) ;
2012-04-19 14:35:52 +08:00
addChild ( label ) ;
CCSize s = CCDirector : : sharedDirector ( ) - > getWinSize ( ) ;
label - > setPosition ( ccp ( s . width / 2 , s . height / 2 ) ) ;
label - > setAnchorPoint ( ccp ( 0.5f , 0.5f ) ) ;
2010-09-07 11:47:54 +08:00
}
std : : string Atlas5 : : title ( )
{
2012-04-19 14:35:52 +08:00
return " CCLabelBMFont " ;
2012-03-22 11:48:37 +08:00
}
2010-09-07 11:47:54 +08:00
std : : string Atlas5 : : subtitle ( )
2012-03-22 11:48:37 +08:00
{
2012-04-19 14:35:52 +08:00
return " Testing padding " ;
2012-03-22 11:48:37 +08:00
}
2010-09-07 11:47:54 +08:00
//------------------------------------------------------------------
//
// Atlas6
2012-03-22 11:48:37 +08:00
//
// Use any of these editors to generate BMFonts:
// http://glyphdesigner.71squared.com/ (Commercial, Mac OS X)
// http://www.n4te.com/hiero/hiero.jnlp (Free, Java)
// http://slick.cokeandcode.com/demos/hiero.jnlp (Free, Java)
2011-07-08 15:57:46 +08:00
// http://www.angelcode.com/products/bmfont/ (Free, Windows only)
2010-09-07 11:47:54 +08:00
//
//------------------------------------------------------------------
Atlas6 : : Atlas6 ( )
{
2012-04-19 14:35:52 +08:00
CCSize s = CCDirector : : sharedDirector ( ) - > getWinSize ( ) ;
2010-09-07 11:47:54 +08:00
2012-04-19 14:35:52 +08:00
CCLabelBMFont * label = NULL ;
2012-06-14 15:13:16 +08:00
label = CCLabelBMFont : : create ( " FaFeFiFoFu " , " fonts/bitmapFontTest5.fnt " ) ;
2012-04-19 14:35:52 +08:00
addChild ( label ) ;
label - > setPosition ( ccp ( s . width / 2 , s . height / 2 + 50 ) ) ;
label - > setAnchorPoint ( ccp ( 0.5f , 0.5f ) ) ;
2012-06-14 15:13:16 +08:00
label = CCLabelBMFont : : create ( " fafefifofu " , " fonts/bitmapFontTest5.fnt " ) ;
2012-04-19 14:35:52 +08:00
addChild ( label ) ;
label - > setPosition ( ccp ( s . width / 2 , s . height / 2 ) ) ;
label - > setAnchorPoint ( ccp ( 0.5f , 0.5f ) ) ;
2010-09-07 11:47:54 +08:00
2012-06-14 15:13:16 +08:00
label = CCLabelBMFont : : create ( " aeiou " , " fonts/bitmapFontTest5.fnt " ) ;
2012-04-19 14:35:52 +08:00
addChild ( label ) ;
label - > setPosition ( ccp ( s . width / 2 , s . height / 2 - 50 ) ) ;
label - > setAnchorPoint ( ccp ( 0.5f , 0.5f ) ) ;
2010-09-07 11:47:54 +08:00
}
std : : string Atlas6 : : title ( )
{
2012-04-19 14:35:52 +08:00
return " CCLabelBMFont " ;
2012-03-22 11:48:37 +08:00
}
2010-09-07 11:47:54 +08:00
std : : string Atlas6 : : subtitle ( )
2012-03-22 11:48:37 +08:00
{
2012-04-19 14:35:52 +08:00
return " Rendering should be OK. Testing offset " ;
2012-03-22 11:48:37 +08:00
}
2010-09-07 11:47:54 +08:00
//------------------------------------------------------------------
//
// AtlasBitmapColor
2012-03-22 11:48:37 +08:00
//
// Use any of these editors to generate BMFonts:
// http://glyphdesigner.71squared.com/ (Commercial, Mac OS X)
// http://www.n4te.com/hiero/hiero.jnlp (Free, Java)
// http://slick.cokeandcode.com/demos/hiero.jnlp (Free, Java)
2011-07-08 15:57:46 +08:00
// http://www.angelcode.com/products/bmfont/ (Free, Windows only)
2010-09-07 11:47:54 +08:00
//
//------------------------------------------------------------------
2012-03-22 11:48:37 +08:00
AtlasBitmapColor : : AtlasBitmapColor ( )
{
2012-04-19 14:35:52 +08:00
CCSize s = CCDirector : : sharedDirector ( ) - > getWinSize ( ) ;
CCLabelBMFont * label = NULL ;
2012-06-14 15:13:16 +08:00
label = CCLabelBMFont : : create ( " Blue " , " fonts/bitmapFontTest5.fnt " ) ;
2012-04-19 14:35:52 +08:00
label - > setColor ( ccBLUE ) ;
addChild ( label ) ;
label - > setPosition ( ccp ( s . width / 2 , s . height / 4 ) ) ;
label - > setAnchorPoint ( ccp ( 0.5f , 0.5f ) ) ;
2012-06-14 15:13:16 +08:00
label = CCLabelBMFont : : create ( " Red " , " fonts/bitmapFontTest5.fnt " ) ;
2012-04-19 14:35:52 +08:00
addChild ( label ) ;
label - > setPosition ( ccp ( s . width / 2 , 2 * s . height / 4 ) ) ;
label - > setAnchorPoint ( ccp ( 0.5f , 0.5f ) ) ;
label - > setColor ( ccRED ) ;
2012-06-14 15:13:16 +08:00
label = CCLabelBMFont : : create ( " G " , " fonts/bitmapFontTest5.fnt " ) ;
2012-04-19 14:35:52 +08:00
addChild ( label ) ;
label - > setPosition ( ccp ( s . width / 2 , 3 * s . height / 4 ) ) ;
label - > setAnchorPoint ( ccp ( 0.5f , 0.5f ) ) ;
label - > setColor ( ccGREEN ) ;
label - > setString ( " Green " ) ;
2012-03-22 11:48:37 +08:00
}
std : : string AtlasBitmapColor : : title ( )
{
2012-04-19 14:35:52 +08:00
return " CCLabelBMFont " ;
2012-03-22 11:48:37 +08:00
}
std : : string AtlasBitmapColor : : subtitle ( )
{
2012-04-19 14:35:52 +08:00
return " Testing color " ;
2012-03-22 11:48:37 +08:00
}
2010-09-07 11:47:54 +08:00
//------------------------------------------------------------------
//
// AtlasFastBitmap
2012-03-22 11:48:37 +08:00
//
// Use any of these editors to generate BMFonts:
// http://glyphdesigner.71squared.com/ (Commercial, Mac OS X)
// http://www.n4te.com/hiero/hiero.jnlp (Free, Java)
// http://slick.cokeandcode.com/demos/hiero.jnlp (Free, Java)
2011-07-08 15:57:46 +08:00
// http://www.angelcode.com/products/bmfont/ (Free, Windows only)
2010-09-07 11:47:54 +08:00
//
//------------------------------------------------------------------
AtlasFastBitmap : : AtlasFastBitmap ( )
{
2012-04-19 14:35:52 +08:00
// Upper Label
for ( int i = 0 ; i < 100 ; i + + )
{
2010-09-07 11:47:54 +08:00
char str [ 6 ] = { 0 } ;
sprintf ( str , " -%d- " , i ) ;
2012-06-14 15:13:16 +08:00
CCLabelBMFont * label = CCLabelBMFont : : create ( str , " fonts/bitmapFontTest.fnt " ) ;
2012-04-19 14:35:52 +08:00
addChild ( label ) ;
CCSize s = CCDirector : : sharedDirector ( ) - > getWinSize ( ) ;
2010-09-07 11:47:54 +08:00
2012-04-19 14:35:52 +08:00
CCPoint p = ccp ( CCRANDOM_0_1 ( ) * s . width , CCRANDOM_0_1 ( ) * s . height ) ;
label - > setPosition ( p ) ;
label - > setAnchorPoint ( ccp ( 0.5f , 0.5f ) ) ;
}
2010-09-07 11:47:54 +08:00
}
std : : string AtlasFastBitmap : : title ( )
{
2012-04-19 14:35:52 +08:00
return " CCLabelBMFont " ;
2012-03-22 11:48:37 +08:00
}
2010-09-07 11:47:54 +08:00
std : : string AtlasFastBitmap : : subtitle ( )
{
2012-04-19 14:35:52 +08:00
return " Creating several CCLabelBMFont with the same .fnt file should be fast " ;
2012-03-22 11:48:37 +08:00
}
2011-02-23 16:47:25 +08:00
//------------------------------------------------------------------
//
// BitmapFontMultiLine
2012-03-22 11:48:37 +08:00
//
// Use any of these editors to generate BMFonts:
// http://glyphdesigner.71squared.com/ (Commercial, Mac OS X)
// http://www.n4te.com/hiero/hiero.jnlp (Free, Java)
// http://slick.cokeandcode.com/demos/hiero.jnlp (Free, Java)
2011-07-08 15:57:46 +08:00
// http://www.angelcode.com/products/bmfont/ (Free, Windows only)
2011-02-23 16:47:25 +08:00
//
2012-03-22 11:48:37 +08:00
//------------------------------------------------------------------
BitmapFontMultiLine : : BitmapFontMultiLine ( )
{
CCSize s ;
// Left
2012-06-14 15:13:16 +08:00
CCLabelBMFont * label1 = CCLabelBMFont : : create ( " Multi line \n Left " , " fonts/bitmapFontTest3.fnt " ) ;
2012-03-22 11:48:37 +08:00
label1 - > setAnchorPoint ( ccp ( 0 , 0 ) ) ;
addChild ( label1 , 0 , kTagBitmapAtlas1 ) ;
s = label1 - > getContentSize ( ) ;
CCLOG ( " content size: %.2fx%.2f " , s . width , s . height ) ;
// Center
2012-06-14 15:13:16 +08:00
CCLabelBMFont * label2 = CCLabelBMFont : : create ( " Multi line \n Center " , " fonts/bitmapFontTest3.fnt " ) ;
2012-03-22 11:48:37 +08:00
label2 - > setAnchorPoint ( ccp ( 0.5f , 0.5f ) ) ;
addChild ( label2 , 0 , kTagBitmapAtlas2 ) ;
s = label2 - > getContentSize ( ) ;
CCLOG ( " content size: %.2fx%.2f " , s . width , s . height ) ;
// right
2012-06-14 15:13:16 +08:00
CCLabelBMFont * label3 = CCLabelBMFont : : create ( " Multi line \n Right \n Three lines Three " , " fonts/bitmapFontTest3.fnt " ) ;
2012-03-22 11:48:37 +08:00
label3 - > setAnchorPoint ( ccp ( 1 , 1 ) ) ;
addChild ( label3 , 0 , kTagBitmapAtlas3 ) ;
s = label3 - > getContentSize ( ) ;
CCLOG ( " content size: %.2fx%.2f " , s . width , s . height ) ;
2012-10-23 17:48:50 +08:00
label1 - > setPosition ( VisibleRect : : leftBottom ( ) ) ;
label2 - > setPosition ( VisibleRect : : center ( ) ) ;
label3 - > setPosition ( VisibleRect : : rightTop ( ) ) ;
2012-03-22 11:48:37 +08:00
}
std : : string BitmapFontMultiLine : : title ( )
{
return " CCLabelBMFont " ;
}
std : : string BitmapFontMultiLine : : subtitle ( )
{
return " Multiline + anchor point " ;
}
2011-02-23 16:47:25 +08:00
//------------------------------------------------------------------
//
// LabelsEmpty
//
2012-03-22 11:48:37 +08:00
//------------------------------------------------------------------
LabelsEmpty : : LabelsEmpty ( )
{
CCSize s = CCDirector : : sharedDirector ( ) - > getWinSize ( ) ;
// CCLabelBMFont
2012-06-14 15:13:16 +08:00
CCLabelBMFont * label1 = CCLabelBMFont : : create ( " " , " fonts/bitmapFontTest3.fnt " ) ;
2012-03-22 11:48:37 +08:00
addChild ( label1 , 0 , kTagBitmapAtlas1 ) ;
label1 - > setPosition ( ccp ( s . width / 2 , s . height - 100 ) ) ;
// CCLabelTTF
2012-06-14 15:13:16 +08:00
CCLabelTTF * label2 = CCLabelTTF : : create ( " " , " Arial " , 24 ) ;
2012-03-22 11:48:37 +08:00
addChild ( label2 , 0 , kTagBitmapAtlas2 ) ;
label2 - > setPosition ( ccp ( s . width / 2 , s . height / 2 ) ) ;
// CCLabelAtlas
2012-06-14 15:13:16 +08:00
CCLabelAtlas * label3 = CCLabelAtlas : : create ( " " , " fonts/tuffy_bold_italic-charmap.png " , 48 , 64 , ' ' ) ;
2012-03-22 11:48:37 +08:00
addChild ( label3 , 0 , kTagBitmapAtlas3 ) ;
label3 - > setPosition ( ccp ( s . width / 2 , 0 + 100 ) ) ;
schedule ( schedule_selector ( LabelsEmpty : : updateStrings ) , 1.0f ) ;
setEmpty = false ;
}
2012-06-08 13:55:28 +08:00
void LabelsEmpty : : updateStrings ( float dt )
2012-03-22 11:48:37 +08:00
{
CCLabelBMFont * label1 = ( CCLabelBMFont * ) getChildByTag ( kTagBitmapAtlas1 ) ;
CCLabelTTF * label2 = ( CCLabelTTF * ) getChildByTag ( kTagBitmapAtlas2 ) ;
CCLabelAtlas * label3 = ( CCLabelAtlas * ) getChildByTag ( kTagBitmapAtlas3 ) ;
if ( ! setEmpty )
{
label1 - > setString ( " not empty " ) ;
label2 - > setString ( " not empty " ) ;
label3 - > setString ( " hi " ) ;
setEmpty = true ;
}
else
{
label1 - > setString ( " " ) ;
label2 - > setString ( " " ) ;
label3 - > setString ( " " ) ;
setEmpty = false ;
}
}
std : : string LabelsEmpty : : title ( )
{
return " Testing empty labels " ;
}
std : : string LabelsEmpty : : subtitle ( )
{
return " 3 empty labels: LabelAtlas, LabelTTF and LabelBMFont " ;
}
2011-02-23 16:47:25 +08:00
//------------------------------------------------------------------
//
// LabelBMFontHD
//
2012-03-22 11:48:37 +08:00
//------------------------------------------------------------------
LabelBMFontHD : : LabelBMFontHD ( )
{
CCSize s = CCDirector : : sharedDirector ( ) - > getWinSize ( ) ;
// CCLabelBMFont
2012-06-14 15:13:16 +08:00
CCLabelBMFont * label1 = CCLabelBMFont : : create ( " TESTING RETINA DISPLAY " , " fonts/konqa32.fnt " ) ;
2012-03-22 11:48:37 +08:00
addChild ( label1 ) ;
label1 - > setPosition ( ccp ( s . width / 2 , s . height / 2 ) ) ;
}
std : : string LabelBMFontHD : : title ( )
{
return " Testing Retina Display BMFont " ;
}
std : : string LabelBMFontHD : : subtitle ( )
{
return " loading arista16 or arista16-hd " ;
}
2011-02-23 16:47:25 +08:00
//------------------------------------------------------------------
//
// LabelAtlasHD
//
2012-03-22 11:48:37 +08:00
//------------------------------------------------------------------
LabelAtlasHD : : LabelAtlasHD ( )
{
CCSize s = CCDirector : : sharedDirector ( ) - > getWinSize ( ) ;
// CCLabelBMFont
2012-06-14 15:13:16 +08:00
CCLabelAtlas * label1 = CCLabelAtlas : : create ( " TESTING RETINA DISPLAY " , " fonts/larabie-16.plist " ) ;
2012-03-22 11:48:37 +08:00
label1 - > setAnchorPoint ( ccp ( 0.5f , 0.5f ) ) ;
addChild ( label1 ) ;
label1 - > setPosition ( ccp ( s . width / 2 , s . height / 2 ) ) ;
}
std : : string LabelAtlasHD : : title ( )
{
return " LabelAtlas with Retina Display " ;
}
std : : string LabelAtlasHD : : subtitle ( )
{
return " loading larabie-16 / larabie-16-hd " ;
}
2011-02-23 16:47:25 +08:00
//------------------------------------------------------------------
//
// LabelGlyphDesigner
//
2012-03-22 11:48:37 +08:00
//------------------------------------------------------------------
LabelGlyphDesigner : : LabelGlyphDesigner ( )
{
CCSize s = CCDirector : : sharedDirector ( ) - > getWinSize ( ) ;
2012-06-14 15:13:16 +08:00
CCLayerColor * layer = CCLayerColor : : create ( ccc4 ( 128 , 128 , 128 , 255 ) ) ;
2012-03-22 11:48:37 +08:00
addChild ( layer , - 10 ) ;
// CCLabelBMFont
2012-06-14 15:13:16 +08:00
CCLabelBMFont * label1 = CCLabelBMFont : : create ( " Testing Glyph Designer " , " fonts/futura-48.fnt " ) ;
2012-03-22 11:48:37 +08:00
addChild ( label1 ) ;
label1 - > setPosition ( ccp ( s . width / 2 , s . height / 2 ) ) ;
}
std : : string LabelGlyphDesigner : : title ( )
{
return " Testing Glyph Designer " ;
}
std : : string LabelGlyphDesigner : : subtitle ( )
{
return " You should see a font with shawdows and outline " ;
}
void AtlasTestScene : : runThisTest ( )
{
2013-02-28 15:57:15 +08:00
sceneIdx = - 1 ;
2012-03-22 11:48:37 +08:00
CCLayer * pLayer = nextAtlasAction ( ) ;
addChild ( pLayer ) ;
CCDirector : : sharedDirector ( ) - > replaceScene ( this ) ;
}
2011-07-06 14:56:05 +08:00
//------------------------------------------------------------------
//
// LabelTTFTest
//
2012-03-22 11:48:37 +08:00
//------------------------------------------------------------------
LabelTTFTest : : LabelTTFTest ( )
{
2012-06-15 15:10:40 +08:00
CCSize blockSize = CCSizeMake ( 200 , 160 ) ;
CCSize s = CCDirector : : sharedDirector ( ) - > getWinSize ( ) ;
CCLayerColor * colorLayer = CCLayerColor : : create ( ccc4 ( 100 , 100 , 100 , 255 ) , blockSize . width , blockSize . height ) ;
colorLayer - > setAnchorPoint ( ccp ( 0 , 0 ) ) ;
colorLayer - > setPosition ( ccp ( ( s . width - blockSize . width ) / 2 , ( s . height - blockSize . height ) / 2 ) ) ;
this - > addChild ( colorLayer ) ;
CCMenuItemFont : : setFontSize ( 30 ) ;
CCMenu * menu = CCMenu : : create (
CCMenuItemFont : : create ( " Left " , this , menu_selector ( LabelTTFTest : : setAlignmentLeft ) ) ,
CCMenuItemFont : : create ( " Center " , this , menu_selector ( LabelTTFTest : : setAlignmentCenter ) ) ,
CCMenuItemFont : : create ( " Right " , this , menu_selector ( LabelTTFTest : : setAlignmentRight ) ) ,
NULL ) ;
menu - > alignItemsVerticallyWithPadding ( 4 ) ;
menu - > setPosition ( ccp ( 50 , s . height / 2 - 20 ) ) ;
this - > addChild ( menu ) ;
menu = CCMenu : : create (
CCMenuItemFont : : create ( " Top " , this , menu_selector ( LabelTTFTest : : setAlignmentTop ) ) ,
CCMenuItemFont : : create ( " Middle " , this , menu_selector ( LabelTTFTest : : setAlignmentMiddle ) ) ,
CCMenuItemFont : : create ( " Bottom " , this , menu_selector ( LabelTTFTest : : setAlignmentBottom ) ) ,
NULL ) ;
menu - > alignItemsVerticallyWithPadding ( 4 ) ;
menu - > setPosition ( ccp ( s . width - 50 , s . height / 2 - 20 ) ) ;
this - > addChild ( menu ) ;
m_plabel = NULL ;
m_eHorizAlign = kCCTextAlignmentLeft ;
m_eVertAlign = kCCVerticalTextAlignmentTop ;
2012-06-12 14:33:53 +08:00
this - > updateAlignment ( ) ;
}
LabelTTFTest : : ~ LabelTTFTest ( )
{
CC_SAFE_RELEASE ( m_plabel ) ;
}
2012-06-15 15:10:40 +08:00
void LabelTTFTest : : updateAlignment ( )
{
CCSize blockSize = CCSizeMake ( 200 , 160 ) ;
CCSize s = CCDirector : : sharedDirector ( ) - > getWinSize ( ) ;
2012-06-12 14:33:53 +08:00
if ( m_plabel )
{
m_plabel - > removeFromParentAndCleanup ( true ) ;
2012-06-15 15:10:40 +08:00
}
2012-08-01 13:24:23 +08:00
m_plabel = CCLabelTTF : : create ( this - > getCurrentAlignment ( ) , " Marker Felt " , 32 ,
blockSize , m_eHorizAlign , m_eVertAlign ) ;
2012-06-15 15:10:40 +08:00
m_plabel - > retain ( ) ;
m_plabel - > setAnchorPoint ( ccp ( 0 , 0 ) ) ;
m_plabel - > setPosition ( ccp ( ( s . width - blockSize . width ) / 2 , ( s . height - blockSize . height ) / 2 ) ) ;
this - > addChild ( m_plabel ) ;
}
void LabelTTFTest : : setAlignmentLeft ( CCObject * pSender )
{
m_eHorizAlign = kCCTextAlignmentLeft ;
this - > updateAlignment ( ) ;
}
void LabelTTFTest : : setAlignmentCenter ( CCObject * pSender )
{
m_eHorizAlign = kCCTextAlignmentCenter ;
this - > updateAlignment ( ) ;
}
void LabelTTFTest : : setAlignmentRight ( CCObject * pSender )
{
m_eHorizAlign = kCCTextAlignmentRight ;
this - > updateAlignment ( ) ;
}
void LabelTTFTest : : setAlignmentTop ( CCObject * pSender )
{
m_eVertAlign = kCCVerticalTextAlignmentTop ;
this - > updateAlignment ( ) ;
}
void LabelTTFTest : : setAlignmentMiddle ( CCObject * pSender )
{
m_eVertAlign = kCCVerticalTextAlignmentCenter ;
this - > updateAlignment ( ) ;
}
void LabelTTFTest : : setAlignmentBottom ( CCObject * pSender )
{
m_eVertAlign = kCCVerticalTextAlignmentBottom ;
this - > updateAlignment ( ) ;
}
const char * LabelTTFTest : : getCurrentAlignment ( )
{
const char * vertical = NULL ;
const char * horizontal = NULL ;
switch ( m_eVertAlign ) {
case kCCVerticalTextAlignmentTop :
vertical = " Top " ;
break ;
case kCCVerticalTextAlignmentCenter :
vertical = " Middle " ;
break ;
case kCCVerticalTextAlignmentBottom :
vertical = " Bottom " ;
break ;
}
switch ( m_eHorizAlign ) {
case kCCTextAlignmentLeft :
horizontal = " Left " ;
break ;
case kCCTextAlignmentCenter :
horizontal = " Center " ;
break ;
case kCCTextAlignmentRight :
horizontal = " Right " ;
break ;
}
return CCString : : createWithFormat ( " Alignment %s %s " , vertical , horizontal ) - > getCString ( ) ;
2012-03-22 11:48:37 +08:00
}
string LabelTTFTest : : title ( )
{
2012-04-19 14:35:52 +08:00
return " Testing CCLabelTTF " ;
2012-03-22 11:48:37 +08:00
}
string LabelTTFTest : : subtitle ( )
{
2012-06-12 14:33:53 +08:00
return " Select the buttons on the sides to change alignment " ;
2012-03-22 11:48:37 +08:00
}
LabelTTFMultiline : : LabelTTFMultiline ( )
{
2012-04-19 14:35:52 +08:00
CCSize s = CCDirector : : sharedDirector ( ) - > getWinSize ( ) ;
2012-03-22 11:48:37 +08:00
2012-06-14 15:13:16 +08:00
CCLabelTTF * center = CCLabelTTF : : create ( " word wrap \" testing \" (bla0) bla1 'bla2' [bla3] (bla4) {bla5} {bla6} [bla7] (bla8) [bla9] 'bla0' \" bla1 \" " ,
2012-08-01 13:24:23 +08:00
" Paint Boy " ,
32 ,
CCSizeMake ( s . width / 2 , 200 ) ,
kCCTextAlignmentCenter ,
kCCVerticalTextAlignmentTop ) ;
2012-06-12 14:33:53 +08:00
2012-04-19 14:35:52 +08:00
center - > setPosition ( ccp ( s . width / 2 , 150 ) ) ;
2012-03-22 11:48:37 +08:00
2012-04-19 14:35:52 +08:00
addChild ( center ) ;
2012-03-22 11:48:37 +08:00
}
string LabelTTFMultiline : : title ( )
{
2012-04-19 14:35:52 +08:00
return " Testing CCLabelTTF Word Wrap " ;
2012-03-22 11:48:37 +08:00
}
string LabelTTFMultiline : : subtitle ( )
{
2012-06-12 14:33:53 +08:00
return " Word wrap using CCLabelTTF and a custom TTF font " ;
2012-03-22 11:48:37 +08:00
}
LabelTTFChinese : : LabelTTFChinese ( )
{
2012-04-19 14:35:52 +08:00
CCSize size = CCDirector : : sharedDirector ( ) - > getWinSize ( ) ;
2012-06-14 15:13:16 +08:00
CCLabelTTF * pLable = CCLabelTTF : : create ( " 中国 " , " Marker Felt " , 30 ) ;
2012-04-19 14:35:52 +08:00
pLable - > setPosition ( ccp ( size . width / 2 , size . height / 2 ) ) ;
this - > addChild ( pLable ) ;
2012-03-22 11:48:37 +08:00
}
string LabelTTFChinese : : title ( )
{
2012-04-19 14:35:52 +08:00
return " Testing CCLabelTTF with Chinese character " ;
2012-03-22 11:48:37 +08:00
}
2012-01-18 18:43:41 +08:00
LabelBMFontChinese : : LabelBMFontChinese ( )
{
2012-03-22 11:48:37 +08:00
CCSize size = CCDirector : : sharedDirector ( ) - > getWinSize ( ) ;
2012-06-14 15:13:16 +08:00
CCLabelBMFont * pLable = CCLabelBMFont : : create ( " 中国 " , " fonts/bitmapFontChinese.fnt " ) ;
2012-03-22 11:48:37 +08:00
pLable - > setPosition ( ccp ( size . width / 2 , size . height / 2 ) ) ;
2012-01-18 18:43:41 +08:00
this - > addChild ( pLable ) ;
}
2012-03-22 11:48:37 +08:00
string LabelBMFontChinese : : title ( )
{
return " Testing CCLabelBMFont with Chinese character " ;
}
/// BitmapFontMultiLineAlignment
# 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 ;
BitmapFontMultiLineAlignment : : BitmapFontMultiLineAlignment ( )
{
2012-06-15 15:10:40 +08:00
this - > setTouchEnabled ( true ) ;
2012-03-22 11:48:37 +08:00
2012-04-19 14:35:52 +08:00
// ask director the the window size
CCSize size = CCDirector : : sharedDirector ( ) - > getWinSize ( ) ;
2012-03-22 11:48:37 +08:00
2012-04-19 14:35:52 +08:00
// create and initialize a Label
2012-06-14 15:13:16 +08:00
this - > m_pLabelShouldRetain = CCLabelBMFont : : create ( LongSentencesExample , " fonts/markerFelt.fnt " , size . width / 1.5 , kCCTextAlignmentCenter ) ;
2012-04-19 14:35:52 +08:00
this - > m_pLabelShouldRetain - > retain ( ) ;
2012-03-22 11:48:37 +08:00
2012-06-14 15:13:16 +08:00
this - > m_pArrowsBarShouldRetain = CCSprite : : create ( " Images/arrowsBar.png " ) ;
2012-04-19 14:35:52 +08:00
this - > m_pArrowsBarShouldRetain - > retain ( ) ;
2012-06-14 15:13:16 +08:00
this - > m_pArrowsShouldRetain = CCSprite : : create ( " Images/arrows.png " ) ;
2012-04-19 14:35:52 +08:00
this - > m_pArrowsShouldRetain - > retain ( ) ;
2012-03-22 11:48:37 +08:00
2012-04-19 14:35:52 +08:00
CCMenuItemFont : : setFontSize ( 20 ) ;
2012-06-14 15:13:16 +08:00
CCMenuItemFont * longSentences = CCMenuItemFont : : create ( " Long Flowing Sentences " , this , menu_selector ( BitmapFontMultiLineAlignment : : stringChanged ) ) ;
CCMenuItemFont * lineBreaks = CCMenuItemFont : : create ( " Short Sentences With Intentional Line Breaks " , this , menu_selector ( BitmapFontMultiLineAlignment : : stringChanged ) ) ;
CCMenuItemFont * mixed = CCMenuItemFont : : create ( " Long Sentences Mixed With Intentional Line Breaks " , this , menu_selector ( BitmapFontMultiLineAlignment : : stringChanged ) ) ;
CCMenu * stringMenu = CCMenu : : create ( longSentences , lineBreaks , mixed , NULL ) ;
2012-04-19 14:35:52 +08:00
stringMenu - > alignItemsVertically ( ) ;
2012-03-22 11:48:37 +08:00
2012-04-19 14:35:52 +08:00
longSentences - > setColor ( ccRED ) ;
m_pLastSentenceItem = longSentences ;
2012-07-24 11:32:02 +08:00
longSentences - > setTag ( LongSentences ) ;
2012-04-19 14:35:52 +08:00
lineBreaks - > setTag ( LineBreaks ) ;
mixed - > setTag ( Mixed ) ;
2012-03-22 11:48:37 +08:00
2012-04-19 14:35:52 +08:00
CCMenuItemFont : : setFontSize ( 30 ) ;
2012-03-22 11:48:37 +08:00
2012-06-14 15:13:16 +08:00
CCMenuItemFont * left = CCMenuItemFont : : create ( " Left " , this , menu_selector ( BitmapFontMultiLineAlignment : : alignmentChanged ) ) ;
CCMenuItemFont * center = CCMenuItemFont : : create ( " Center " , this , menu_selector ( BitmapFontMultiLineAlignment : : alignmentChanged ) ) ;
CCMenuItemFont * right = CCMenuItemFont : : create ( " Right " , this , menu_selector ( BitmapFontMultiLineAlignment : : alignmentChanged ) ) ;
CCMenu * alignmentMenu = CCMenu : : create ( left , center , right , NULL ) ;
2012-04-19 14:35:52 +08:00
alignmentMenu - > alignItemsHorizontallyWithPadding ( alignmentItemPadding ) ;
2012-03-22 11:48:37 +08:00
2012-04-19 14:35:52 +08:00
center - > setColor ( ccRED ) ;
m_pLastAlignmentItem = center ;
left - > setTag ( LeftAlign ) ;
center - > setTag ( CenterAlign ) ;
right - > setTag ( RightAlign ) ;
2012-03-22 11:48:37 +08:00
2012-04-19 14:35:52 +08:00
// position the label on the center of the screen
this - > m_pLabelShouldRetain - > setPosition ( ccp ( size . width / 2 , size . height / 2 ) ) ;
2012-03-22 11:48:37 +08:00
2012-06-15 16:47:30 +08:00
this - > m_pArrowsBarShouldRetain - > setVisible ( false ) ;
2012-03-22 11:48:37 +08:00
2012-04-19 14:35:52 +08:00
float arrowsWidth = ( ArrowsMax - ArrowsMin ) * size . width ;
this - > m_pArrowsBarShouldRetain - > setScaleX ( arrowsWidth / this - > m_pArrowsBarShouldRetain - > getContentSize ( ) . width ) ;
this - > m_pArrowsBarShouldRetain - > setPosition ( ccp ( ( ( ArrowsMax + ArrowsMin ) / 2 ) * size . width , this - > m_pLabelShouldRetain - > getPosition ( ) . y ) ) ;
2012-03-22 11:48:37 +08:00
2012-04-19 14:35:52 +08:00
this - > snapArrowsToEdge ( ) ;
2012-03-22 11:48:37 +08:00
2012-04-19 14:35:52 +08:00
stringMenu - > setPosition ( ccp ( size . width / 2 , size . height - menuItemPaddingCenter ) ) ;
alignmentMenu - > setPosition ( ccp ( size . width / 2 , menuItemPaddingCenter + 15 ) ) ;
2012-03-22 11:48:37 +08:00
2012-04-19 14:35:52 +08:00
this - > addChild ( this - > m_pLabelShouldRetain ) ;
this - > addChild ( this - > m_pArrowsBarShouldRetain ) ;
this - > addChild ( this - > m_pArrowsShouldRetain ) ;
this - > addChild ( stringMenu ) ;
this - > addChild ( alignmentMenu ) ;
2012-03-22 11:48:37 +08:00
}
BitmapFontMultiLineAlignment : : ~ BitmapFontMultiLineAlignment ( )
{
2012-04-19 14:35:52 +08:00
this - > m_pLabelShouldRetain - > release ( ) ;
this - > m_pArrowsBarShouldRetain - > release ( ) ;
this - > m_pArrowsShouldRetain - > release ( ) ;
2012-03-22 11:48:37 +08:00
}
std : : string BitmapFontMultiLineAlignment : : title ( )
{
2012-04-19 14:35:52 +08:00
return " " ;
2012-03-22 11:48:37 +08:00
}
std : : string BitmapFontMultiLineAlignment : : subtitle ( )
{
2012-04-19 14:35:52 +08:00
return " " ;
2012-03-22 11:48:37 +08:00
}
void BitmapFontMultiLineAlignment : : stringChanged ( cocos2d : : CCObject * sender )
{
2012-04-19 14:35:52 +08:00
CCMenuItemFont * item = ( CCMenuItemFont * ) sender ;
item - > setColor ( ccRED ) ;
this - > m_pLastAlignmentItem - > setColor ( ccWHITE ) ;
this - > m_pLastAlignmentItem = item ;
2012-03-22 11:48:37 +08:00
2012-04-19 14:35:52 +08:00
switch ( item - > getTag ( ) )
{
case LongSentences :
this - > m_pLabelShouldRetain - > setString ( LongSentencesExample ) ;
break ;
case LineBreaks :
this - > m_pLabelShouldRetain - > setString ( LineBreaksExample ) ;
break ;
case Mixed :
this - > m_pLabelShouldRetain - > setString ( MixedExample ) ;
break ;
default :
break ;
}
2012-03-22 11:48:37 +08:00
2012-04-19 14:35:52 +08:00
this - > snapArrowsToEdge ( ) ;
2012-03-22 11:48:37 +08:00
}
void BitmapFontMultiLineAlignment : : alignmentChanged ( cocos2d : : CCObject * sender )
{
2012-04-19 14:35:52 +08:00
CCMenuItemFont * item = ( CCMenuItemFont * ) sender ;
item - > setColor ( ccRED ) ;
this - > m_pLastAlignmentItem - > setColor ( ccWHITE ) ;
this - > m_pLastAlignmentItem = item ;
2012-03-22 11:48:37 +08:00
2012-04-19 14:35:52 +08:00
switch ( item - > getTag ( ) )
{
case LeftAlign :
2012-06-08 17:34:15 +08:00
this - > m_pLabelShouldRetain - > setAlignment ( kCCTextAlignmentLeft ) ;
2012-04-19 14:35:52 +08:00
break ;
case CenterAlign :
2012-06-08 17:34:15 +08:00
this - > m_pLabelShouldRetain - > setAlignment ( kCCTextAlignmentCenter ) ;
2012-04-19 14:35:52 +08:00
break ;
case RightAlign :
2012-06-08 17:34:15 +08:00
this - > m_pLabelShouldRetain - > setAlignment ( kCCTextAlignmentRight ) ;
2012-04-19 14:35:52 +08:00
break ;
default :
break ;
}
2012-03-22 11:48:37 +08:00
2012-04-19 14:35:52 +08:00
this - > snapArrowsToEdge ( ) ;
2012-03-22 11:48:37 +08:00
}
void BitmapFontMultiLineAlignment : : ccTouchesBegan ( cocos2d : : CCSet * pTouches , cocos2d : : CCEvent * pEvent )
{
2012-04-19 14:35:52 +08:00
CCTouch * touch = ( CCTouch * ) pTouches - > anyObject ( ) ;
2012-07-31 17:41:53 +08:00
CCPoint location = touch - > getLocationInView ( ) ;
2012-03-22 11:48:37 +08:00
2012-08-01 15:30:12 +08:00
if ( this - > m_pArrowsShouldRetain - > boundingBox ( ) . containsPoint ( location ) )
2012-04-19 14:35:52 +08:00
{
m_drag = true ;
2012-06-15 16:47:30 +08:00
this - > m_pArrowsBarShouldRetain - > setVisible ( true ) ;
2012-04-19 14:35:52 +08:00
}
2012-03-22 11:48:37 +08:00
}
void BitmapFontMultiLineAlignment : : ccTouchesEnded ( cocos2d : : CCSet * pTouches , cocos2d : : CCEvent * pEvent )
{
2012-04-19 14:35:52 +08:00
m_drag = false ;
this - > snapArrowsToEdge ( ) ;
2012-03-22 11:48:37 +08:00
2012-06-15 16:47:30 +08:00
this - > m_pArrowsBarShouldRetain - > setVisible ( false ) ;
2012-03-22 11:48:37 +08:00
}
void BitmapFontMultiLineAlignment : : ccTouchesMoved ( cocos2d : : CCSet * pTouches , cocos2d : : CCEvent * pEvent )
{
2012-04-19 14:35:52 +08:00
if ( ! m_drag )
{
return ;
}
2012-03-22 11:48:37 +08:00
2012-04-19 14:35:52 +08:00
CCTouch * touch = ( CCTouch * ) pTouches - > anyObject ( ) ;
2012-07-31 17:41:53 +08:00
CCPoint location = touch - > getLocationInView ( ) ;
2012-03-22 11:48:37 +08:00
2012-04-19 14:35:52 +08:00
CCSize winSize = CCDirector : : sharedDirector ( ) - > getWinSize ( ) ;
2012-03-22 11:48:37 +08:00
2012-04-19 14:35:52 +08:00
this - > m_pArrowsShouldRetain - > setPosition ( ccp ( MAX ( MIN ( location . x , ArrowsMax * winSize . width ) , ArrowsMin * winSize . width ) ,
this - > m_pArrowsShouldRetain - > getPosition ( ) . y ) ) ;
2012-03-22 11:48:37 +08:00
2012-04-19 14:35:52 +08:00
float labelWidth = fabs ( this - > m_pArrowsShouldRetain - > getPosition ( ) . x - this - > m_pLabelShouldRetain - > getPosition ( ) . x ) * 2 ;
2012-03-22 11:48:37 +08:00
2012-04-19 14:35:52 +08:00
this - > m_pLabelShouldRetain - > setWidth ( labelWidth ) ;
2012-03-22 11:48:37 +08:00
}
void BitmapFontMultiLineAlignment : : snapArrowsToEdge ( )
{
2012-04-19 14:35:52 +08:00
this - > m_pArrowsShouldRetain - > setPosition ( ccp ( this - > m_pLabelShouldRetain - > getPosition ( ) . x + this - > m_pLabelShouldRetain - > getContentSize ( ) . width / 2 ,
this - > m_pLabelShouldRetain - > getPosition ( ) . y ) ) ;
2012-03-22 11:48:37 +08:00
}
/// LabelTTFA8Test
LabelTTFA8Test : : LabelTTFA8Test ( )
{
2012-04-19 14:35:52 +08:00
CCSize s = CCDirector : : sharedDirector ( ) - > getWinSize ( ) ;
2012-03-22 11:48:37 +08:00
2012-06-14 15:13:16 +08:00
CCLayerColor * layer = CCLayerColor : : create ( ccc4 ( 128 , 128 , 128 , 255 ) ) ;
2012-04-19 14:35:52 +08:00
addChild ( layer , - 10 ) ;
2012-03-22 11:48:37 +08:00
2012-04-19 14:35:52 +08:00
// CCLabelBMFont
2012-06-14 15:13:16 +08:00
CCLabelTTF * label1 = CCLabelTTF : : create ( " Testing A8 Format " , " Marker Felt " , 48 ) ;
2012-04-19 14:35:52 +08:00
addChild ( label1 ) ;
label1 - > setColor ( ccRED ) ;
label1 - > setPosition ( ccp ( s . width / 2 , s . height / 2 ) ) ;
2012-03-22 11:48:37 +08:00
2012-06-14 15:13:16 +08:00
CCFadeOut * fadeOut = CCFadeOut : : create ( 2 ) ;
CCFadeIn * fadeIn = CCFadeIn : : create ( 2 ) ;
2012-12-10 14:12:56 +08:00
CCSequence * seq = CCSequence : : create ( fadeOut , fadeIn , NULL ) ;
CCRepeatForever * forever = CCRepeatForever : : create ( seq ) ;
2012-04-19 14:35:52 +08:00
label1 - > runAction ( forever ) ;
2012-03-22 11:48:37 +08:00
}
std : : string LabelTTFA8Test : : title ( )
{
2012-04-19 14:35:52 +08:00
return " Testing A8 Format " ;
2012-03-22 11:48:37 +08:00
}
std : : string LabelTTFA8Test : : subtitle ( )
{
2012-04-19 14:35:52 +08:00
return " RED label, fading In and Out in the center of the screen " ;
2012-03-22 11:48:37 +08:00
}
/// BMFontOneAtlas
BMFontOneAtlas : : BMFontOneAtlas ( )
{
2012-04-19 14:35:52 +08:00
CCSize s = CCDirector : : sharedDirector ( ) - > getWinSize ( ) ;
2012-03-22 11:48:37 +08:00
2012-06-14 15:13:16 +08:00
CCLabelBMFont * label1 = CCLabelBMFont : : create ( " This is Helvetica " , " fonts/helvetica-32.fnt " , kCCLabelAutomaticWidth , kCCTextAlignmentLeft , CCPointZero ) ;
2012-03-22 11:48:37 +08:00
addChild ( label1 ) ;
2012-04-19 14:35:52 +08:00
label1 - > setPosition ( ccp ( s . width / 2 , s . height / 3 * 2 ) ) ;
2012-03-22 11:48:37 +08:00
2012-06-14 15:13:16 +08:00
CCLabelBMFont * label2 = CCLabelBMFont : : create ( " And this is Geneva " , " fonts/geneva-32.fnt " , kCCLabelAutomaticWidth , kCCTextAlignmentLeft , ccp ( 0 , 128 ) ) ;
2012-04-19 14:35:52 +08:00
addChild ( label2 ) ;
label2 - > setPosition ( ccp ( s . width / 2 , s . height / 3 * 1 ) ) ;
2012-03-22 11:48:37 +08:00
}
std : : string BMFontOneAtlas : : title ( )
{
2012-04-19 14:35:52 +08:00
return " CCLabelBMFont with one texture " ;
2012-03-22 11:48:37 +08:00
}
std : : string BMFontOneAtlas : : subtitle ( )
{
2012-04-19 14:35:52 +08:00
return " Using 2 .fnt definitions that share the same texture atlas. " ;
2012-03-22 11:48:37 +08:00
}
/// BMFontUnicode
BMFontUnicode : : BMFontUnicode ( )
{
2012-07-23 22:49:11 +08:00
CCDictionary * strings = CCDictionary : : createWithContentsOfFile ( " fonts/strings.xml " ) ;
2012-04-19 14:35:52 +08:00
const char * chinese = ( ( CCString * ) strings - > objectForKey ( " chinese1 " ) ) - > m_sString . c_str ( ) ;
const char * japanese = ( ( CCString * ) strings - > objectForKey ( " japanese " ) ) - > m_sString . c_str ( ) ;
const char * spanish = ( ( CCString * ) strings - > objectForKey ( " spanish " ) ) - > m_sString . c_str ( ) ;
2012-03-22 11:48:37 +08:00
2012-04-19 14:35:52 +08:00
CCSize s = CCDirector : : sharedDirector ( ) - > getWinSize ( ) ;
2012-03-22 11:48:37 +08:00
2012-06-14 15:13:16 +08:00
CCLabelBMFont * label1 = CCLabelBMFont : : create ( spanish , " fonts/arial-unicode-26.fnt " , 200 , kCCTextAlignmentLeft ) ;
2012-03-22 11:48:37 +08:00
addChild ( label1 ) ;
2012-04-19 14:35:52 +08:00
label1 - > setPosition ( ccp ( s . width / 2 , s . height / 4 * 3 ) ) ;
2012-03-22 11:48:37 +08:00
2012-06-14 15:13:16 +08:00
CCLabelBMFont * label2 = CCLabelBMFont : : create ( chinese , " fonts/arial-unicode-26.fnt " ) ;
2012-04-19 14:35:52 +08:00
addChild ( label2 ) ;
label2 - > setPosition ( ccp ( s . width / 2 , s . height / 4 * 2 ) ) ;
2012-03-22 11:48:37 +08:00
2012-06-14 15:13:16 +08:00
CCLabelBMFont * label3 = CCLabelBMFont : : create ( japanese , " fonts/arial-unicode-26.fnt " ) ;
2012-04-19 14:35:52 +08:00
addChild ( label3 ) ;
label3 - > setPosition ( ccp ( s . width / 2 , s . height / 4 * 1 ) ) ;
2012-03-22 11:48:37 +08:00
}
std : : string BMFontUnicode : : title ( )
{
2012-04-19 14:35:52 +08:00
return " CCLabelBMFont with Unicode support " ;
2012-03-22 11:48:37 +08:00
}
std : : string BMFontUnicode : : subtitle ( )
{
2012-04-19 14:35:52 +08:00
return " You should see 3 differnt labels: In Spanish, Chinese and Korean " ;
2012-06-15 15:10:40 +08:00
}
// BMFontInit
BMFontInit : : BMFontInit ( )
{
CCSize s = CCDirector : : sharedDirector ( ) - > getWinSize ( ) ;
CCLabelBMFont * bmFont = new CCLabelBMFont ( ) ;
bmFont - > init ( ) ;
bmFont - > autorelease ( ) ;
//CCLabelBMFont* bmFont = [CCLabelBMFont create:@"Foo" fntFile:@"arial-unicode-26.fnt"];
bmFont - > setFntFile ( " fonts/helvetica-32.fnt " ) ;
bmFont - > setString ( " It is working! " ) ;
this - > addChild ( bmFont ) ;
bmFont - > setPosition ( ccp ( s . width / 2 , s . height / 4 * 2 ) ) ;
}
2012-06-12 14:33:53 +08:00
std : : string BMFontInit : : title ( )
{
return " CCLabelBMFont init " ;
}
std : : string BMFontInit : : subtitle ( )
{
return " Test for support of init method without parameters. " ;
2012-06-15 15:10:40 +08:00
}
// TTFFontInit
TTFFontInit : : TTFFontInit ( )
{
CCSize s = CCDirector : : sharedDirector ( ) - > getWinSize ( ) ;
CCLabelTTF * font = new CCLabelTTF ( ) ;
font - > init ( ) ;
font - > autorelease ( ) ;
font - > setFontName ( " Marker Felt " ) ;
font - > setFontSize ( 48 ) ;
font - > setString ( " It is working! " ) ;
this - > addChild ( font ) ;
font - > setPosition ( ccp ( s . width / 2 , s . height / 4 * 2 ) ) ;
}
2012-06-12 14:33:53 +08:00
std : : string TTFFontInit : : title ( )
{
return " CCLabelTTF init " ;
}
std : : string TTFFontInit : : subtitle ( )
{
return " Test for support of init method without parameters. " ;
}
2012-06-15 15:10:40 +08:00
// Issue1343
Issue1343 : : Issue1343 ( )
{
CCSize s = CCDirector : : sharedDirector ( ) - > getWinSize ( ) ;
CCLabelBMFont * bmFont = new CCLabelBMFont ( ) ;
bmFont - > init ( ) ;
bmFont - > setFntFile ( " fonts/font-issue1343.fnt " ) ;
bmFont - > setString ( " ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyz.,' " ) ;
this - > addChild ( bmFont ) ;
bmFont - > release ( ) ;
bmFont - > setScale ( 0.3f ) ;
bmFont - > setPosition ( ccp ( s . width / 2 , s . height / 4 * 2 ) ) ;
}
2012-06-12 14:33:53 +08:00
std : : string Issue1343 : : title ( )
{
return " Issue 1343 " ;
}
std : : string Issue1343 : : subtitle ( )
{
return " You should see: ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyz.,' " ;
2012-03-22 11:48:37 +08:00
}
2012-06-12 14:33:53 +08:00
2012-11-20 18:17:47 +08:00
LabelBMFontBounds : : LabelBMFontBounds ( )
{
CCSize s = CCDirector : : sharedDirector ( ) - > getWinSize ( ) ;
CCLayerColor * layer = CCLayerColor : : create ( ccc4 ( 128 , 128 , 128 , 255 ) ) ;
addChild ( layer , - 10 ) ;
// CCLabelBMFont
label1 = CCLabelBMFont : : create ( " Testing Glyph Designer " , " fonts/boundsTestFont.fnt " ) ;
addChild ( label1 ) ;
label1 - > setPosition ( ccp ( s . width / 2 , s . height / 2 ) ) ;
}
string LabelBMFontBounds : : title ( )
{
return " Testing LabelBMFont Bounds " ;
}
string LabelBMFontBounds : : subtitle ( )
{
return " You should see string enclosed by a box " ;
}
void LabelBMFontBounds : : draw ( )
{
CCSize labelSize = label1 - > getContentSize ( ) ;
CCSize origin = CCDirector : : sharedDirector ( ) - > getWinSize ( ) ;
origin . width = origin . width / 2 - ( labelSize . width / 2 ) ;
origin . height = origin . height / 2 - ( labelSize . height / 2 ) ;
CCPoint vertices [ 4 ] =
{
ccp ( origin . width , origin . height ) ,
ccp ( labelSize . width + origin . width , origin . height ) ,
ccp ( labelSize . width + origin . width , labelSize . height + origin . height ) ,
ccp ( origin . width , labelSize . height + origin . height )
} ;
ccDrawPoly ( vertices , 4 , true ) ;
}