2018-01-29 16:25:32 +08:00
/****************************************************************************
Copyright ( c ) 2017 - 2018 Xiamen Yaji Software Co . , Ltd .
http : //www.cocos2d-x.org
Permission is hereby granted , free of charge , to any person obtaining a copy
of this software and associated documentation files ( the " Software " ) , to deal
in the Software without restriction , including without limitation the rights
to use , copy , modify , merge , publish , distribute , sublicense , and / or sell
copies of the Software , and to permit persons to whom the Software is
furnished to do so , subject to the following conditions :
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software .
THE SOFTWARE IS PROVIDED " AS IS " , WITHOUT WARRANTY OF ANY KIND , EXPRESS OR
IMPLIED , INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY ,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT . IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM , DAMAGES OR OTHER
LIABILITY , WHETHER IN AN ACTION OF CONTRACT , TORT OR OTHERWISE , ARISING FROM ,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2013-12-25 14:52:49 +08:00
# include "LabelTest.h"
2012-03-22 11:48:37 +08:00
# include "../testResource.h"
2014-10-04 08:11:39 +08:00
# include "cocos2d.h"
2012-03-22 11:48:37 +08:00
2015-04-09 08:37:30 +08:00
USING_NS_CC ;
2014-03-31 17:21:56 +08:00
# if defined(__GNUC__) && ((__GNUC__ >= 4) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1)))
# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
# elif _MSC_VER >= 1400 //vs 2005 or higher
# pragma warning (push)
# pragma warning (disable: 4996)
# endif
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
} ;
2015-04-03 14:31:03 +08:00
LabelTests : : LabelTests ( )
{
ADD_TEST_CASE ( LabelAtlasTest ) ;
ADD_TEST_CASE ( LabelAtlasColorTest ) ;
ADD_TEST_CASE ( Atlas3 ) ;
ADD_TEST_CASE ( Atlas4 ) ;
ADD_TEST_CASE ( Atlas5 ) ;
ADD_TEST_CASE ( Atlas6 ) ;
ADD_TEST_CASE ( AtlasBitmapColor ) ;
ADD_TEST_CASE ( AtlasFastBitmap ) ;
ADD_TEST_CASE ( BitmapFontMultiLine ) ;
ADD_TEST_CASE ( LabelsEmpty ) ;
ADD_TEST_CASE ( LabelBMFontHD ) ;
ADD_TEST_CASE ( LabelAtlasHD ) ;
ADD_TEST_CASE ( LabelGlyphDesigner ) ;
ADD_TEST_CASE ( LabelTTFTest ) ;
ADD_TEST_CASE ( LabelTTFMultiline ) ;
ADD_TEST_CASE ( LabelTTFChinese ) ;
ADD_TEST_CASE ( LabelBMFontChinese ) ;
ADD_TEST_CASE ( BitmapFontMultiLineAlignment ) ;
ADD_TEST_CASE ( LabelTTFOpacityTest ) ;
ADD_TEST_CASE ( BMFontOneAtlas ) ;
ADD_TEST_CASE ( BMFontUnicode ) ;
ADD_TEST_CASE ( BMFontInit ) ;
ADD_TEST_CASE ( TTFFontInit ) ;
ADD_TEST_CASE ( Issue1343 ) ;
ADD_TEST_CASE ( LabelTTFAlignment ) ;
ADD_TEST_CASE ( LabelBMFontBounds ) ;
ADD_TEST_CASE ( TTFFontShadowAndStroke ) ;
2013-07-23 08:25:44 +08:00
// should be moved to another test
2015-04-03 14:31:03 +08:00
ADD_TEST_CASE ( Atlas1 ) ;
ADD_TEST_CASE ( LabelBMFontCrashTest ) ;
ADD_TEST_CASE ( LabelBMFontBinaryFormat ) ;
2010-09-07 11:47:54 +08:00
}
//------------------------------------------------------------------
//
// Atlas1
//
//------------------------------------------------------------------
Atlas1 : : Atlas1 ( )
{
2014-05-10 09:39:25 +08:00
setGLProgram ( GLProgramCache : : getInstance ( ) - > getProgram ( GLProgram : : SHADER_NAME_POSITION_TEXTURE ) ) ;
2013-06-20 14:17:10 +08:00
_textureAtlas = TextureAtlas : : create ( s_AtlasTest , 3 ) ; _textureAtlas - > retain ( ) ;
2012-04-19 14:35:52 +08:00
2013-08-16 16:05:27 +08:00
auto s = Director : : getInstance ( ) - > getWinSize ( ) ;
2012-04-19 14:35:52 +08:00
//
// Notice: u,v tex coordinates are inverted
//
2013-07-05 16:49:22 +08:00
V3F_C4B_T2F_Quad quads [ ] =
2012-04-19 14:35:52 +08:00
{
{
2014-05-15 01:07:09 +08:00
{ Vec3 ( 0 , 0 , 0 ) , Color4B ( 0 , 0 , 255 , 255 ) , Tex2F ( 0.0f , 1.0f ) , } , // bottom left
{ Vec3 ( s . width , 0 , 0 ) , Color4B ( 0 , 0 , 255 , 0 ) , Tex2F ( 1.0f , 1.0f ) , } , // bottom right
{ Vec3 ( 0 , s . height , 0 ) , Color4B ( 0 , 0 , 255 , 0 ) , Tex2F ( 0.0f , 0.0f ) , } , // top left
{ Vec3 ( s . width , s . height , 0 ) , Color4B ( 0 , 0 , 255 , 255 ) , Tex2F ( 1.0f , 0.0f ) , } , // top right
2012-04-19 14:35:52 +08:00
} ,
{
2014-05-15 01:07:09 +08:00
{ Vec3 ( 40 , 40 , 0 ) , Color4B ( 255 , 255 , 255 , 255 ) , Tex2F ( 0.0f , 0.2f ) , } , // bottom left
{ Vec3 ( 120 , 80 , 0 ) , Color4B ( 255 , 0 , 0 , 255 ) , Tex2F ( 0.5f , 0.2f ) , } , // bottom right
{ Vec3 ( 40 , 160 , 0 ) , Color4B ( 255 , 255 , 255 , 255 ) , Tex2F ( 0.0f , 0.0f ) , } , // top left
{ Vec3 ( 160 , 160 , 0 ) , Color4B ( 0 , 255 , 0 , 255 ) , Tex2F ( 0.5f , 0.0f ) , } , // top right
2012-04-19 14:35:52 +08:00
} ,
{
2014-05-15 01:07:09 +08:00
{ Vec3 ( s . width / 2 , 40 , 0 ) , Color4B ( 255 , 0 , 0 , 255 ) , Tex2F ( 0.0f , 1.0f ) , } , // bottom left
{ Vec3 ( s . width , 40 , 0 ) , Color4B ( 0 , 255 , 0 , 255 ) , Tex2F ( 1.0f , 1.0f ) , } , // bottom right
{ Vec3 ( s . width / 2 - 50 , 200 , 0 ) , Color4B ( 0 , 0 , 255 , 255 ) , Tex2F ( 0.0f , 0.0f ) , } , // top left
{ Vec3 ( s . width , 100 , 0 ) , Color4B ( 255 , 255 , 0 , 255 ) , Tex2F ( 1.0f , 0.0f ) , } , // top right
2012-04-19 14:35:52 +08:00
} ,
} ;
for ( int i = 0 ; i < 3 ; i + + )
{
2013-06-15 14:03:30 +08:00
_textureAtlas - > updateQuad ( & quads [ i ] , i ) ;
2012-04-19 14:35:52 +08:00
}
2012-03-22 11:48:37 +08:00
}
2010-09-07 11:47:54 +08:00
Atlas1 : : ~ Atlas1 ( )
{
2013-06-15 14:03:30 +08:00
_textureAtlas - > release ( ) ;
2012-03-22 11:48:37 +08:00
}
2010-09-07 11:47:54 +08:00
2014-05-31 07:42:05 +08:00
void Atlas1 : : draw ( Renderer * renderer , const Mat4 & transform , uint32_t flags )
2010-09-07 11:47:54 +08:00
{
2014-01-19 03:35:27 +08:00
_customCommand . init ( _globalZOrder ) ;
2014-05-31 07:42:05 +08:00
_customCommand . func = CC_CALLBACK_0 ( Atlas1 : : onDraw , this , transform , flags ) ;
2014-03-01 08:10:48 +08:00
renderer - > addCommand ( & _customCommand ) ;
2012-03-22 11:48:37 +08:00
}
2010-09-07 11:47:54 +08:00
2014-05-31 07:42:05 +08:00
void Atlas1 : : onDraw ( const Mat4 & transform , uint32_t flags )
2013-12-25 14:52:49 +08:00
{
2014-05-09 07:42:36 +08:00
getGLProgram ( ) - > use ( ) ;
getGLProgram ( ) - > setUniformsForBuiltins ( transform ) ;
2013-12-25 14:52:49 +08:00
_textureAtlas - > drawQuads ( ) ;
}
2013-12-19 05:52:10 +08:00
std : : string Atlas1 : : title ( ) const
2010-09-07 11:47:54 +08:00
{
2012-04-19 14:35:52 +08:00
return " CCTextureAtlas " ;
2012-03-22 11:48:37 +08:00
}
2013-12-19 05:52:10 +08:00
std : : string Atlas1 : : subtitle ( ) const
2012-03-22 11:48:37 +08:00
{
2013-06-20 14:17:10 +08:00
return " Manual creation of TextureAtlas " ;
2012-03-22 11:48:37 +08:00
}
2010-09-07 11:47:54 +08:00
//------------------------------------------------------------------
//
// LabelAtlasTest
//
//------------------------------------------------------------------
LabelAtlasTest : : LabelAtlasTest ( )
{
2013-06-15 14:03:30 +08:00
_time = 0 ;
2010-09-07 11:47:54 +08:00
2013-08-16 16:05:27 +08:00
auto label1 = LabelAtlas : : create ( " 123 Test " , " fonts/tuffy_bold_italic-charmap.plist " ) ;
2012-04-19 14:35:52 +08:00
addChild ( label1 , 0 , kTagSprite1 ) ;
2014-05-15 01:07:09 +08:00
label1 - > setPosition ( Vec2 ( 10 , 100 ) ) ;
2012-04-19 14:35:52 +08:00
label1 - > setOpacity ( 200 ) ;
2010-09-07 11:47:54 +08:00
2013-08-16 16:05:27 +08:00
auto label2 = LabelAtlas : : create ( " 0123456789 " , " fonts/tuffy_bold_italic-charmap.plist " ) ;
2012-04-19 14:35:52 +08:00
addChild ( label2 , 0 , kTagSprite2 ) ;
2014-05-15 01:07:09 +08:00
label2 - > setPosition ( Vec2 ( 10 , 200 ) ) ;
2012-04-19 14:35:52 +08:00
label2 - > setOpacity ( 32 ) ;
2010-09-07 11:47:54 +08:00
2014-10-04 08:11:39 +08:00
schedule ( CC_CALLBACK_1 ( LabelAtlasTest : : step , this ) , " step_key " ) ;
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
{
2013-06-15 14:03:30 +08:00
_time + = dt ;
2010-09-07 11:47:54 +08:00
char string [ 12 ] = { 0 } ;
2013-06-15 14:03:30 +08:00
sprintf ( string , " %2.2f Test " , _time ) ;
//string.format("%2.2f Test", _time);
2010-09-07 11:47:54 +08:00
2013-08-16 16:05:27 +08:00
auto label1 = ( LabelAtlas * ) getChildByTag ( kTagSprite1 ) ;
2012-04-19 14:35:52 +08:00
label1 - > setString ( string ) ;
2010-09-07 11:47:54 +08:00
2013-08-16 16:05:27 +08:00
auto label2 = ( LabelAtlas * ) getChildByTag ( kTagSprite2 ) ;
2013-06-15 14:03:30 +08:00
sprintf ( string , " %d " , ( int ) _time ) ;
//string.format("%d", (int)_time);
2012-04-19 14:35:52 +08:00
label2 - > setString ( string ) ;
2010-09-07 11:47:54 +08:00
}
2013-12-19 05:52:10 +08:00
std : : string LabelAtlasTest : : title ( ) const
2010-09-07 11:47:54 +08:00
{
2012-04-19 14:35:52 +08:00
return " LabelAtlas " ;
2012-03-22 11:48:37 +08:00
}
2013-12-19 05:52:10 +08:00
std : : string LabelAtlasTest : : subtitle ( ) const
2012-03-22 11:48:37 +08:00
{
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 ( )
{
2013-08-16 16:05:27 +08:00
auto label1 = LabelAtlas : : create ( " 123 Test " , " fonts/tuffy_bold_italic-charmap.png " , 48 , 64 , ' ' ) ;
2012-04-19 14:35:52 +08:00
addChild ( label1 , 0 , kTagSprite1 ) ;
2014-05-15 01:07:09 +08:00
label1 - > setPosition ( Vec2 ( 10 , 100 ) ) ;
2012-04-19 14:35:52 +08:00
label1 - > setOpacity ( 200 ) ;
2013-08-16 16:05:27 +08:00
auto label2 = LabelAtlas : : create ( " 0123456789 " , " fonts/tuffy_bold_italic-charmap.png " , 48 , 64 , ' ' ) ;
2012-04-19 14:35:52 +08:00
addChild ( label2 , 0 , kTagSprite2 ) ;
2014-05-15 01:07:09 +08:00
label2 - > setPosition ( Vec2 ( 10 , 200 ) ) ;
2013-07-08 18:11:32 +08:00
label2 - > setColor ( Color3B : : RED ) ;
2012-03-22 11:48:37 +08:00
2013-08-16 16:05:27 +08:00
auto fade = FadeOut : : create ( 1.0f ) ;
auto fade_in = fade - > reverse ( ) ;
auto cb = CallFunc : : create ( CC_CALLBACK_0 ( LabelAtlasColorTest : : actionFinishCallback , this ) ) ;
2014-07-10 00:45:27 +08:00
auto seq = Sequence : : create ( fade , fade_in , cb , nullptr ) ;
2013-08-16 16:05:27 +08:00
auto repeat = RepeatForever : : create ( seq ) ;
2012-04-19 14:35:52 +08:00
label2 - > runAction ( repeat ) ;
2012-03-22 11:48:37 +08:00
2013-06-15 14:03:30 +08:00
_time = 0 ;
2012-04-19 14:35:52 +08:00
2014-10-04 08:11:39 +08:00
schedule ( CC_CALLBACK_1 ( LabelAtlasColorTest : : step , this ) , " step_key " ) ;
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
{
2013-06-15 14:03:30 +08:00
_time + = dt ;
2012-03-22 11:48:37 +08:00
char string [ 12 ] = { 0 } ;
2013-06-15 14:03:30 +08:00
sprintf ( string , " %2.2f Test " , _time ) ;
//std::string string = std::string::createWithFormat("%2.2f Test", _time);
2013-08-16 16:05:27 +08:00
auto label1 = ( LabelAtlas * ) getChildByTag ( kTagSprite1 ) ;
2012-04-19 14:35:52 +08:00
label1 - > setString ( string ) ;
2013-08-16 16:05:27 +08:00
auto label2 = ( LabelAtlas * ) getChildByTag ( kTagSprite2 ) ;
2013-06-15 14:03:30 +08:00
sprintf ( string , " %d " , ( int ) _time ) ;
2012-04-19 14:35:52 +08:00
label2 - > setString ( string ) ;
2012-03-22 11:48:37 +08:00
}
2013-12-19 05:52:10 +08:00
std : : string LabelAtlasColorTest : : title ( ) const
2012-03-22 11:48:37 +08:00
{
2012-04-19 14:35:52 +08:00
return " CCLabelAtlas " ;
2012-03-22 11:48:37 +08:00
}
2013-12-19 05:52:10 +08:00
std : : string LabelAtlasColorTest : : subtitle ( ) const
2012-03-22 11:48:37 +08:00
{
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 ( )
{
2013-08-16 16:05:27 +08:00
auto s = Director : : getInstance ( ) - > getWinSize ( ) ;
2012-06-15 15:10:40 +08:00
2013-08-16 16:05:27 +08:00
auto ttf0 = LabelTTF : : create ( " Alignment 0 \n new line " , " Helvetica " , 12 ,
2013-07-27 07:04:21 +08:00
Size ( 256 , 32 ) , TextHAlignment : : LEFT ) ;
2013-08-14 01:12:02 +08:00
2014-05-15 01:07:09 +08:00
ttf0 - > setPosition ( Vec2 ( s . width / 2 , ( s . height / 6 ) * 2 ) ) ;
ttf0 - > setAnchorPoint ( Vec2 : : ANCHOR_MIDDLE ) ;
2012-06-15 15:10:40 +08:00
this - > addChild ( ttf0 ) ;
2013-08-14 01:12:02 +08:00
2013-08-16 16:05:27 +08:00
auto ttf1 = LabelTTF : : create ( " Alignment 1 \n new line " , " Helvetica " , 12 ,
2013-08-14 01:12:02 +08:00
Size ( 245 , 32 ) , TextHAlignment : : CENTER ) ;
2014-05-15 01:07:09 +08:00
ttf1 - > setPosition ( Vec2 ( s . width / 2 , ( s . height / 6 ) * 3 ) ) ;
ttf1 - > setAnchorPoint ( Vec2 : : ANCHOR_MIDDLE ) ;
2012-06-15 15:10:40 +08:00
this - > addChild ( ttf1 ) ;
2013-08-16 16:05:27 +08:00
auto ttf2 = LabelTTF : : create ( " Alignment 2 \n new line " , " Helvetica " , 12 ,
2013-07-27 07:04:21 +08:00
Size ( 245 , 32 ) , TextHAlignment : : RIGHT ) ;
2014-05-15 01:07:09 +08:00
ttf2 - > setPosition ( Vec2 ( s . width / 2 , ( s . height / 6 ) * 4 ) ) ;
ttf2 - > setAnchorPoint ( Vec2 : : ANCHOR_MIDDLE ) ;
2012-06-12 14:33:53 +08:00
this - > addChild ( ttf2 ) ;
}
2013-12-19 05:52:10 +08:00
std : : string LabelTTFAlignment : : title ( ) const
2012-06-12 14:33:53 +08:00
{
return " CCLabelTTF alignment " ;
}
2013-12-19 05:52:10 +08:00
std : : string LabelTTFAlignment : : subtitle ( ) const
2012-06-12 14:33:53 +08:00
{
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 ( )
{
2013-06-15 14:03:30 +08:00
_time = 0 ;
2012-04-19 14:35:52 +08:00
2013-08-16 16:05:27 +08:00
auto col = LayerColor : : create ( Color4B ( 128 , 128 , 128 , 255 ) ) ;
2012-04-19 14:35:52 +08:00
addChild ( col , - 10 ) ;
2013-08-16 16:05:27 +08:00
auto label1 = LabelBMFont : : create ( " Test " , " fonts/bitmapFontTest2.fnt " ) ;
2012-04-19 14:35:52 +08:00
// testing anchors
2014-05-15 01:07:09 +08:00
label1 - > setAnchorPoint ( Vec2 : : ANCHOR_BOTTOM_LEFT ) ;
2012-04-19 14:35:52 +08:00
addChild ( label1 , 0 , kTagBitmapAtlas1 ) ;
2013-08-16 16:05:27 +08:00
auto fade = FadeOut : : create ( 1.0f ) ;
auto fade_in = fade - > reverse ( ) ;
2014-03-31 17:38:54 +08:00
auto seq = Sequence : : create ( fade , fade_in , nullptr ) ;
2013-08-16 16:05:27 +08:00
auto repeat = RepeatForever : : 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
2013-08-16 16:05:27 +08:00
auto label2 = LabelBMFont : : create ( " Test " , " fonts/bitmapFontTest2.fnt " ) ;
2012-04-19 14:35:52 +08:00
// testing anchors
2014-05-15 01:07:09 +08:00
label2 - > setAnchorPoint ( Vec2 : : ANCHOR_MIDDLE ) ;
2013-07-08 18:11:32 +08:00
label2 - > setColor ( Color3B : : RED ) ;
2012-04-19 14:35:52 +08:00
addChild ( label2 , 0 , kTagBitmapAtlas2 ) ;
2014-01-24 15:02:42 +08:00
auto tint = Sequence : : create ( TintTo : : create ( 1 , 255 , 0 , 0 ) ,
TintTo : : create ( 1 , 0 , 255 , 0 ) ,
TintTo : : create ( 1 , 0 , 0 , 255 ) ,
2014-07-10 00:45:27 +08:00
nullptr ) ;
2014-01-24 15:02:42 +08:00
label2 - > runAction ( RepeatForever : : create ( tint ) ) ;
2012-04-19 14:35:52 +08:00
2013-08-16 16:05:27 +08:00
auto label3 = LabelBMFont : : create ( " Test " , " fonts/bitmapFontTest2.fnt " ) ;
2012-04-19 14:35:52 +08:00
// testing anchors
2014-05-15 01:07:09 +08:00
label3 - > setAnchorPoint ( Vec2 : : ANCHOR_TOP_RIGHT ) ;
2012-04-19 14:35:52 +08:00
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
2014-10-04 08:11:39 +08:00
schedule ( CC_CALLBACK_1 ( Atlas3 : : step , this ) , " step_key " ) ;
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
{
2013-06-15 14:03:30 +08:00
_time + = dt ;
2012-04-19 14:35:52 +08:00
//std::string string;
2010-09-07 11:47:54 +08:00
char string [ 15 ] = { 0 } ;
2013-06-15 14:03:30 +08:00
sprintf ( string , " %2.2f Test j " , _time ) ;
//string.format("%2.2f Test j", _time);
2012-04-19 14:35:52 +08:00
2013-08-16 16:05:27 +08:00
auto label1 = ( LabelBMFont * ) getChildByTag ( kTagBitmapAtlas1 ) ;
2012-04-19 14:35:52 +08:00
label1 - > setString ( string ) ;
2013-08-16 16:05:27 +08:00
auto label2 = ( LabelBMFont * ) getChildByTag ( kTagBitmapAtlas2 ) ;
2012-04-19 14:35:52 +08:00
label2 - > setString ( string ) ;
2013-08-16 16:05:27 +08:00
auto label3 = ( LabelBMFont * ) getChildByTag ( kTagBitmapAtlas3 ) ;
2012-04-19 14:35:52 +08:00
label3 - > setString ( string ) ;
2010-09-07 11:47:54 +08:00
}
2013-12-19 05:52:10 +08:00
std : : string Atlas3 : : title ( ) const
2010-09-07 11:47:54 +08:00
{
2012-04-19 14:35:52 +08:00
return " CCLabelBMFont " ;
2012-03-22 11:48:37 +08:00
}
2013-12-19 05:52:10 +08:00
std : : string Atlas3 : : subtitle ( ) const
2010-09-07 11:47:54 +08:00
{
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 ( )
{
2013-06-15 14:03:30 +08:00
_time = 0 ;
2012-04-19 14:35:52 +08:00
2014-09-11 15:39:56 +08:00
auto s = Director : : getInstance ( ) - > getWinSize ( ) ;
auto drawNode = DrawNode : : create ( ) ;
drawNode - > drawLine ( Vec2 ( 0 , s . height / 2 ) , Vec2 ( s . width , s . height / 2 ) , Color4F ( 1.0 , 1.0 , 1.0 , 1.0 ) ) ;
drawNode - > drawLine ( Vec2 ( s . width / 2 , 0 ) , Vec2 ( s . width / 2 , s . height ) , Color4F ( 1.0 , 1.0 , 1.0 , 1.0 ) ) ;
addChild ( drawNode , - 1 ) ;
2012-04-19 14:35:52 +08:00
// Upper Label
2013-08-16 16:05:27 +08:00
auto label = LabelBMFont : : create ( " Bitmap Font Atlas " , " fonts/bitmapFontTest.fnt " ) ;
2012-04-19 14:35:52 +08:00
addChild ( label ) ;
2014-05-15 01:07:09 +08:00
label - > setPosition ( Vec2 ( s . width / 2 , s . height / 2 ) ) ;
label - > setAnchorPoint ( Vec2 : : ANCHOR_MIDDLE ) ;
2012-04-19 14:35:52 +08:00
2013-08-16 16:05:27 +08:00
auto BChar = ( Sprite * ) label - > getChildByTag ( 0 ) ;
auto FChar = ( Sprite * ) label - > getChildByTag ( 7 ) ;
auto AChar = ( Sprite * ) label - > getChildByTag ( 12 ) ;
2012-04-19 14:35:52 +08:00
2013-08-16 16:05:27 +08:00
auto rotate = RotateBy : : create ( 2 , 360 ) ;
auto rot_4ever = RepeatForever : : create ( rotate ) ;
2012-04-19 14:35:52 +08:00
2013-08-16 16:05:27 +08:00
auto scale = ScaleBy : : create ( 2 , 1.5f ) ;
auto scale_back = scale - > reverse ( ) ;
2014-07-10 00:45:27 +08:00
auto scale_seq = Sequence : : create ( scale , scale_back , nullptr ) ;
2013-08-16 16:05:27 +08:00
auto scale_4ever = RepeatForever : : create ( scale_seq ) ;
2012-04-19 14:35:52 +08:00
2014-05-15 01:07:09 +08:00
auto jump = JumpBy : : create ( 0.5f , Vec2 : : ZERO , 60 , 1 ) ;
2013-08-16 16:05:27 +08:00
auto jump_4ever = RepeatForever : : create ( jump ) ;
2012-04-19 14:35:52 +08:00
2013-08-16 16:05:27 +08:00
auto fade_out = FadeOut : : create ( 1 ) ;
auto fade_in = FadeIn : : create ( 1 ) ;
2014-07-10 00:45:27 +08:00
auto seq = Sequence : : create ( fade_out , fade_in , nullptr ) ;
2013-08-16 16:05:27 +08:00
auto fade_4ever = RepeatForever : : create ( seq ) ;
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
2013-08-16 16:05:27 +08:00
auto label2 = LabelBMFont : : create ( " 00.0 " , " fonts/bitmapFontTest.fnt " ) ;
2012-04-19 14:35:52 +08:00
addChild ( label2 , 0 , kTagBitmapAtlas2 ) ;
2014-05-15 01:07:09 +08:00
label2 - > setPosition ( Vec2 ( s . width / 2.0f , 80 ) ) ;
2012-04-19 14:35:52 +08:00
2013-08-16 16:05:27 +08:00
auto lastChar = ( Sprite * ) label2 - > getChildByTag ( 3 ) ;
2013-06-19 07:12:28 +08:00
lastChar - > runAction ( rot_4ever - > clone ( ) ) ;
2012-04-19 14:35:52 +08:00
2014-10-04 08:11:39 +08:00
schedule ( CC_CALLBACK_1 ( Atlas4 : : step , this ) , 0.1f , " step_key " ) ;
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
{
2013-06-15 14:03:30 +08:00
_time + = dt ;
2010-09-07 11:47:54 +08:00
char string [ 10 ] = { 0 } ;
2013-06-15 14:03:30 +08:00
sprintf ( string , " %04.1f " , _time ) ;
2012-04-19 14:35:52 +08:00
// std::string string;
2013-06-15 14:03:30 +08:00
// string.format("%04.1f", _time);
2012-04-19 14:35:52 +08:00
2013-08-16 16:05:27 +08:00
auto label1 = ( LabelBMFont * ) getChildByTag ( kTagBitmapAtlas2 ) ;
2012-04-19 14:35:52 +08:00
label1 - > setString ( string ) ;
2010-09-07 11:47:54 +08:00
}
2013-12-19 05:52:10 +08:00
std : : string Atlas4 : : title ( ) const
2010-09-07 11:47:54 +08:00
{
2012-04-19 14:35:52 +08:00
return " CCLabelBMFont " ;
2012-03-22 11:48:37 +08:00
}
2013-12-19 05:52:10 +08:00
std : : string Atlas4 : : subtitle ( ) const
2010-09-07 11:47:54 +08:00
{
2013-06-20 14:17:10 +08:00
return " Using fonts as Sprite 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 ( )
{
2013-08-16 16:05:27 +08:00
auto label = LabelBMFont : : create ( " abcdefg " , " fonts/bitmapFontTest4.fnt " ) ;
2012-04-19 14:35:52 +08:00
addChild ( label ) ;
2013-08-16 16:05:27 +08:00
auto s = Director : : getInstance ( ) - > getWinSize ( ) ;
2012-04-19 14:35:52 +08:00
2014-05-15 01:07:09 +08:00
label - > setPosition ( Vec2 ( s . width / 2 , s . height / 2 ) ) ;
label - > setAnchorPoint ( Vec2 : : ANCHOR_MIDDLE ) ;
2010-09-07 11:47:54 +08:00
}
2013-12-19 05:52:10 +08:00
std : : string Atlas5 : : title ( ) const
2010-09-07 11:47:54 +08:00
{
2012-04-19 14:35:52 +08:00
return " CCLabelBMFont " ;
2012-03-22 11:48:37 +08:00
}
2013-12-19 05:52:10 +08:00
std : : string Atlas5 : : subtitle ( ) const
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 ( )
{
2013-08-16 16:05:27 +08:00
auto s = Director : : getInstance ( ) - > getWinSize ( ) ;
2010-09-07 11:47:54 +08:00
2014-07-10 00:45:27 +08:00
LabelBMFont * label = nullptr ;
2013-06-20 14:17:10 +08:00
label = LabelBMFont : : create ( " FaFeFiFoFu " , " fonts/bitmapFontTest5.fnt " ) ;
2012-04-19 14:35:52 +08:00
addChild ( label ) ;
2014-05-15 01:07:09 +08:00
label - > setPosition ( Vec2 ( s . width / 2 , s . height / 2 + 50 ) ) ;
label - > setAnchorPoint ( Vec2 : : ANCHOR_MIDDLE ) ;
2012-04-19 14:35:52 +08:00
2013-06-20 14:17:10 +08:00
label = LabelBMFont : : create ( " fafefifofu " , " fonts/bitmapFontTest5.fnt " ) ;
2012-04-19 14:35:52 +08:00
addChild ( label ) ;
2014-05-15 01:07:09 +08:00
label - > setPosition ( Vec2 ( s . width / 2 , s . height / 2 ) ) ;
label - > setAnchorPoint ( Vec2 : : ANCHOR_MIDDLE ) ;
2010-09-07 11:47:54 +08:00
2013-06-20 14:17:10 +08:00
label = LabelBMFont : : create ( " aeiou " , " fonts/bitmapFontTest5.fnt " ) ;
2012-04-19 14:35:52 +08:00
addChild ( label ) ;
2014-05-15 01:07:09 +08:00
label - > setPosition ( Vec2 ( s . width / 2 , s . height / 2 - 50 ) ) ;
label - > setAnchorPoint ( Vec2 : : ANCHOR_MIDDLE ) ;
2010-09-07 11:47:54 +08:00
}
2013-12-19 05:52:10 +08:00
std : : string Atlas6 : : title ( ) const
2010-09-07 11:47:54 +08:00
{
2012-04-19 14:35:52 +08:00
return " CCLabelBMFont " ;
2012-03-22 11:48:37 +08:00
}
2013-12-19 05:52:10 +08:00
std : : string Atlas6 : : subtitle ( ) const
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 ( )
{
2013-08-16 16:05:27 +08:00
auto s = Director : : getInstance ( ) - > getWinSize ( ) ;
2012-04-19 14:35:52 +08:00
2014-03-31 17:38:54 +08:00
LabelBMFont * label = nullptr ;
2013-06-20 14:17:10 +08:00
label = LabelBMFont : : create ( " Blue " , " fonts/bitmapFontTest5.fnt " ) ;
2013-07-08 18:11:32 +08:00
label - > setColor ( Color3B : : BLUE ) ;
2012-04-19 14:35:52 +08:00
addChild ( label ) ;
2014-05-15 01:07:09 +08:00
label - > setPosition ( Vec2 ( s . width / 2 , s . height / 4 ) ) ;
label - > setAnchorPoint ( Vec2 : : ANCHOR_MIDDLE ) ;
2012-04-19 14:35:52 +08:00
2013-06-20 14:17:10 +08:00
label = LabelBMFont : : create ( " Red " , " fonts/bitmapFontTest5.fnt " ) ;
2012-04-19 14:35:52 +08:00
addChild ( label ) ;
2014-05-15 01:07:09 +08:00
label - > setPosition ( Vec2 ( s . width / 2 , 2 * s . height / 4 ) ) ;
label - > setAnchorPoint ( Vec2 : : ANCHOR_MIDDLE ) ;
2013-07-08 18:11:32 +08:00
label - > setColor ( Color3B : : RED ) ;
2012-04-19 14:35:52 +08:00
2013-06-20 14:17:10 +08:00
label = LabelBMFont : : create ( " G " , " fonts/bitmapFontTest5.fnt " ) ;
2012-04-19 14:35:52 +08:00
addChild ( label ) ;
2014-05-15 01:07:09 +08:00
label - > setPosition ( Vec2 ( s . width / 2 , 3 * s . height / 4 ) ) ;
label - > setAnchorPoint ( Vec2 : : ANCHOR_MIDDLE ) ;
2013-07-08 18:11:32 +08:00
label - > setColor ( Color3B : : GREEN ) ;
2012-04-19 14:35:52 +08:00
label - > setString ( " Green " ) ;
2012-03-22 11:48:37 +08:00
}
2013-12-19 05:52:10 +08:00
std : : string AtlasBitmapColor : : title ( ) const
2012-03-22 11:48:37 +08:00
{
2012-04-19 14:35:52 +08:00
return " CCLabelBMFont " ;
2012-03-22 11:48:37 +08:00
}
2013-12-19 05:52:10 +08:00
std : : string AtlasBitmapColor : : subtitle ( ) const
2012-03-22 11:48:37 +08:00
{
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 ) ;
2013-08-16 16:05:27 +08:00
auto label = LabelBMFont : : create ( str , " fonts/bitmapFontTest.fnt " ) ;
2012-04-19 14:35:52 +08:00
addChild ( label ) ;
2013-08-16 16:05:27 +08:00
auto s = Director : : getInstance ( ) - > getWinSize ( ) ;
2010-09-07 11:47:54 +08:00
2014-05-15 01:07:09 +08:00
auto p = Vec2 ( CCRANDOM_0_1 ( ) * s . width , CCRANDOM_0_1 ( ) * s . height ) ;
2012-04-19 14:35:52 +08:00
label - > setPosition ( p ) ;
2014-05-15 01:07:09 +08:00
label - > setAnchorPoint ( Vec2 : : ANCHOR_MIDDLE ) ;
2012-04-19 14:35:52 +08:00
}
2010-09-07 11:47:54 +08:00
}
2013-12-19 05:52:10 +08:00
std : : string AtlasFastBitmap : : title ( ) const
2010-09-07 11:47:54 +08:00
{
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
2013-12-19 05:52:10 +08:00
std : : string AtlasFastBitmap : : subtitle ( ) const
2010-09-07 11:47:54 +08:00
{
2013-06-20 14:17:10 +08:00
return " Creating several LabelBMFont 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 ( )
{
2013-06-20 14:17:10 +08:00
Size s ;
2012-03-22 11:48:37 +08:00
// Left
2013-08-16 16:05:27 +08:00
auto label1 = LabelBMFont : : create ( " Multi line \n Left " , " fonts/bitmapFontTest3.fnt " ) ;
2014-05-15 01:07:09 +08:00
label1 - > setAnchorPoint ( Vec2 : : ANCHOR_BOTTOM_LEFT ) ;
2012-03-22 11:48:37 +08:00
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 = LabelBMFont : : create ( " Multi line \n Center " , " fonts/bitmapFontTest3.fnt " ) ;
2014-05-15 01:07:09 +08:00
label2 - > setAnchorPoint ( Vec2 : : ANCHOR_MIDDLE ) ;
2012-03-22 11:48:37 +08:00
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 = LabelBMFont : : create ( " Multi line \n Right \n Three lines Three " , " fonts/bitmapFontTest3.fnt " ) ;
2014-05-15 01:07:09 +08:00
label3 - > setAnchorPoint ( Vec2 : : ANCHOR_TOP_RIGHT ) ;
2012-03-22 11:48:37 +08:00
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
}
2013-12-19 05:52:10 +08:00
std : : string BitmapFontMultiLine : : title ( ) const
2012-03-22 11:48:37 +08:00
{
return " CCLabelBMFont " ;
}
2013-12-19 05:52:10 +08:00
std : : string BitmapFontMultiLine : : subtitle ( ) const
2012-03-22 11:48:37 +08:00
{
return " Multiline + anchor point " ;
}
2011-02-23 16:47:25 +08:00
//------------------------------------------------------------------
//
// LabelsEmpty
//
2012-03-22 11:48:37 +08:00
//------------------------------------------------------------------
LabelsEmpty : : LabelsEmpty ( )
{
2013-08-16 16:05:27 +08:00
auto s = Director : : getInstance ( ) - > getWinSize ( ) ;
2012-03-22 11:48:37 +08:00
2013-06-20 14:17:10 +08:00
// LabelBMFont
2013-08-16 16:05:27 +08:00
auto label1 = LabelBMFont : : create ( " " , " fonts/bitmapFontTest3.fnt " ) ;
2012-03-22 11:48:37 +08:00
addChild ( label1 , 0 , kTagBitmapAtlas1 ) ;
2014-05-15 01:07:09 +08:00
label1 - > setPosition ( Vec2 ( s . width / 2 , s . height - 100 ) ) ;
2012-03-22 11:48:37 +08:00
2013-06-20 14:17:10 +08:00
// LabelTTF
2014-04-01 14:49:02 +08:00
auto label2 = LabelTTF : : create ( " " , " Arial " , 24 ) ;
2012-03-22 11:48:37 +08:00
addChild ( label2 , 0 , kTagBitmapAtlas2 ) ;
2014-05-15 01:07:09 +08:00
label2 - > setPosition ( Vec2 ( s . width / 2 , s . height / 2 ) ) ;
2012-03-22 11:48:37 +08:00
2013-06-20 14:17:10 +08:00
// LabelAtlas
2013-08-16 16:05:27 +08:00
auto label3 = LabelAtlas : : create ( " " , " fonts/tuffy_bold_italic-charmap.png " , 48 , 64 , ' ' ) ;
2012-03-22 11:48:37 +08:00
addChild ( label3 , 0 , kTagBitmapAtlas3 ) ;
2014-05-15 01:07:09 +08:00
label3 - > setPosition ( Vec2 ( s . width / 2 , 0 + 100 ) ) ;
2012-03-22 11:48:37 +08:00
2014-10-04 08:11:39 +08:00
schedule ( CC_CALLBACK_1 ( LabelsEmpty : : updateStrings , this ) , 1.0f , " update_strings_key " ) ;
2012-03-22 11:48:37 +08:00
setEmpty = false ;
}
2012-06-08 13:55:28 +08:00
void LabelsEmpty : : updateStrings ( float dt )
2012-03-22 11:48:37 +08:00
{
2013-07-23 08:25:44 +08:00
auto label1 = static_cast < LabelBMFont * > ( getChildByTag ( kTagBitmapAtlas1 ) ) ;
auto label2 = static_cast < LabelTTF * > ( getChildByTag ( kTagBitmapAtlas2 ) ) ;
auto label3 = static_cast < LabelAtlas * > ( getChildByTag ( kTagBitmapAtlas3 ) ) ;
2012-03-22 11:48:37 +08:00
if ( ! setEmpty )
{
label1 - > setString ( " not empty " ) ;
label2 - > setString ( " not empty " ) ;
label3 - > setString ( " hi " ) ;
setEmpty = true ;
}
else
{
label1 - > setString ( " " ) ;
label2 - > setString ( " " ) ;
label3 - > setString ( " " ) ;
setEmpty = false ;
}
}
2013-12-19 05:52:10 +08:00
std : : string LabelsEmpty : : title ( ) const
2012-03-22 11:48:37 +08:00
{
return " Testing empty labels " ;
}
2013-12-19 05:52:10 +08:00
std : : string LabelsEmpty : : subtitle ( ) const
2012-03-22 11:48:37 +08:00
{
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 ( )
{
2013-08-16 16:05:27 +08:00
auto s = Director : : getInstance ( ) - > getWinSize ( ) ;
2012-03-22 11:48:37 +08:00
2013-06-20 14:17:10 +08:00
// LabelBMFont
2013-07-23 08:25:44 +08:00
auto label1 = LabelBMFont : : create ( " TESTING RETINA DISPLAY " , " fonts/konqa32.fnt " ) ;
2012-03-22 11:48:37 +08:00
addChild ( label1 ) ;
2014-05-15 01:07:09 +08:00
label1 - > setPosition ( Vec2 ( s . width / 2 , s . height / 2 ) ) ;
2012-03-22 11:48:37 +08:00
}
2013-12-19 05:52:10 +08:00
std : : string LabelBMFontHD : : title ( ) const
2012-03-22 11:48:37 +08:00
{
return " Testing Retina Display BMFont " ;
}
2013-12-19 05:52:10 +08:00
std : : string LabelBMFontHD : : subtitle ( ) const
2012-03-22 11:48:37 +08:00
{
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 ( )
{
2013-08-16 16:05:27 +08:00
auto s = Director : : getInstance ( ) - > getWinSize ( ) ;
2012-03-22 11:48:37 +08:00
2013-06-20 14:17:10 +08:00
// LabelBMFont
2013-07-23 08:25:44 +08:00
auto label1 = LabelAtlas : : create ( " TESTING RETINA DISPLAY " , " fonts/larabie-16.plist " ) ;
2014-05-15 01:07:09 +08:00
label1 - > setAnchorPoint ( Vec2 : : ANCHOR_MIDDLE ) ;
2012-03-22 11:48:37 +08:00
addChild ( label1 ) ;
2014-05-15 01:07:09 +08:00
label1 - > setPosition ( Vec2 ( s . width / 2 , s . height / 2 ) ) ;
2012-03-22 11:48:37 +08:00
}
2013-12-19 05:52:10 +08:00
std : : string LabelAtlasHD : : title ( ) const
2012-03-22 11:48:37 +08:00
{
return " LabelAtlas with Retina Display " ;
}
2013-12-19 05:52:10 +08:00
std : : string LabelAtlasHD : : subtitle ( ) const
2012-03-22 11:48:37 +08:00
{
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 ( )
{
2013-08-16 16:05:27 +08:00
auto s = Director : : getInstance ( ) - > getWinSize ( ) ;
2012-03-22 11:48:37 +08:00
2013-07-23 08:25:44 +08:00
auto layer = LayerColor : : create ( Color4B ( 128 , 128 , 128 , 255 ) ) ;
2012-03-22 11:48:37 +08:00
addChild ( layer , - 10 ) ;
2013-06-20 14:17:10 +08:00
// LabelBMFont
2013-07-23 08:25:44 +08:00
auto label1 = LabelBMFont : : create ( " Testing Glyph Designer " , " fonts/futura-48.fnt " ) ;
2012-03-22 11:48:37 +08:00
addChild ( label1 ) ;
2014-05-15 01:07:09 +08:00
label1 - > setPosition ( Vec2 ( s . width / 2 , s . height / 2 ) ) ;
2012-03-22 11:48:37 +08:00
}
2013-12-19 05:52:10 +08:00
std : : string LabelGlyphDesigner : : title ( ) const
2012-03-22 11:48:37 +08:00
{
return " Testing Glyph Designer " ;
}
2013-12-19 05:52:10 +08:00
std : : string LabelGlyphDesigner : : subtitle ( ) const
2012-03-22 11:48:37 +08:00
{
2017-02-10 10:35:52 +08:00
return " You should see a font with shadows and outline " ;
2012-03-22 11:48:37 +08:00
}
2011-07-06 14:56:05 +08:00
//------------------------------------------------------------------
//
// LabelTTFTest
//
2012-03-22 11:48:37 +08:00
//------------------------------------------------------------------
LabelTTFTest : : LabelTTFTest ( )
{
2013-08-16 16:05:27 +08:00
auto blockSize = Size ( 200 , 160 ) ;
auto s = Director : : getInstance ( ) - > getWinSize ( ) ;
2012-06-15 15:10:40 +08:00
2013-07-23 08:25:44 +08:00
auto colorLayer = LayerColor : : create ( Color4B ( 100 , 100 , 100 , 255 ) , blockSize . width , blockSize . height ) ;
2014-05-15 01:07:09 +08:00
colorLayer - > setAnchorPoint ( Vec2 : : ANCHOR_BOTTOM_LEFT ) ;
colorLayer - > setPosition ( Vec2 ( ( s . width - blockSize . width ) / 2 , ( s . height - blockSize . height ) / 2 ) ) ;
2012-06-15 15:10:40 +08:00
this - > addChild ( colorLayer ) ;
2013-06-20 14:17:10 +08:00
MenuItemFont : : setFontSize ( 30 ) ;
2013-08-16 16:05:27 +08:00
auto menu = Menu : : create (
2013-06-20 14:17:10 +08:00
MenuItemFont : : create ( " Left " , CC_CALLBACK_1 ( LabelTTFTest : : setAlignmentLeft , this ) ) ,
MenuItemFont : : create ( " Center " , CC_CALLBACK_1 ( LabelTTFTest : : setAlignmentCenter , this ) ) ,
MenuItemFont : : create ( " Right " , CC_CALLBACK_1 ( LabelTTFTest : : setAlignmentRight , this ) ) ,
2014-07-10 00:45:27 +08:00
nullptr ) ;
2012-06-15 15:10:40 +08:00
menu - > alignItemsVerticallyWithPadding ( 4 ) ;
2014-05-15 01:07:09 +08:00
menu - > setPosition ( Vec2 ( 50 , s . height / 2 - 20 ) ) ;
2012-06-15 15:10:40 +08:00
this - > addChild ( menu ) ;
2013-06-20 14:17:10 +08:00
menu = Menu : : create (
MenuItemFont : : create ( " Top " , CC_CALLBACK_1 ( LabelTTFTest : : setAlignmentTop , this ) ) ,
MenuItemFont : : create ( " Middle " , CC_CALLBACK_1 ( LabelTTFTest : : setAlignmentMiddle , this ) ) ,
MenuItemFont : : create ( " Bottom " , CC_CALLBACK_1 ( LabelTTFTest : : setAlignmentBottom , this ) ) ,
2014-07-10 00:45:27 +08:00
nullptr ) ;
2012-06-15 15:10:40 +08:00
menu - > alignItemsVerticallyWithPadding ( 4 ) ;
2014-05-15 01:07:09 +08:00
menu - > setPosition ( Vec2 ( s . width - 50 , s . height / 2 - 20 ) ) ;
2012-06-15 15:10:40 +08:00
this - > addChild ( menu ) ;
2014-03-31 17:21:56 +08:00
_label = nullptr ;
2013-07-27 07:04:21 +08:00
_horizAlign = TextHAlignment : : LEFT ;
_vertAlign = TextVAlignment : : TOP ;
2012-06-15 15:10:40 +08:00
2012-06-12 14:33:53 +08:00
this - > updateAlignment ( ) ;
}
LabelTTFTest : : ~ LabelTTFTest ( )
{
2014-03-31 17:21:56 +08:00
CC_SAFE_RELEASE ( _label ) ;
2012-06-12 14:33:53 +08:00
}
2012-06-15 15:10:40 +08:00
void LabelTTFTest : : updateAlignment ( )
{
2013-08-16 16:05:27 +08:00
auto blockSize = Size ( 200 , 160 ) ;
auto s = Director : : getInstance ( ) - > getWinSize ( ) ;
2012-06-15 15:10:40 +08:00
2014-03-31 17:21:56 +08:00
if ( _label )
2012-06-12 14:33:53 +08:00
{
2014-03-31 17:21:56 +08:00
_label - > removeFromParentAndCleanup ( true ) ;
2012-06-15 15:10:40 +08:00
}
2013-03-21 09:00:55 +08:00
2014-03-31 17:21:56 +08:00
CC_SAFE_RELEASE ( _label ) ;
2013-03-21 09:00:55 +08:00
2014-04-01 14:49:02 +08:00
_label = LabelTTF : : create ( this - > getCurrentAlignment ( ) , " Marker Felt " , 32 ,
2013-06-15 14:03:30 +08:00
blockSize , _horizAlign , _vertAlign ) ;
2014-03-31 17:21:56 +08:00
_label - > retain ( ) ;
2012-06-15 15:10:40 +08:00
2014-05-15 01:07:09 +08:00
_label - > setAnchorPoint ( Vec2 : : ANCHOR_BOTTOM_LEFT ) ;
_label - > setPosition ( Vec2 ( ( s . width - blockSize . width ) / 2 , ( s . height - blockSize . height ) / 2 ) ) ;
2012-06-15 15:10:40 +08:00
2014-03-31 17:21:56 +08:00
this - > addChild ( _label ) ;
2012-06-15 15:10:40 +08:00
}
2014-02-20 10:53:49 +08:00
void LabelTTFTest : : setAlignmentLeft ( Ref * sender )
2012-06-15 15:10:40 +08:00
{
2013-07-27 07:04:21 +08:00
_horizAlign = TextHAlignment : : LEFT ;
2012-06-15 15:10:40 +08:00
this - > updateAlignment ( ) ;
}
2014-02-20 10:53:49 +08:00
void LabelTTFTest : : setAlignmentCenter ( Ref * sender )
2012-06-15 15:10:40 +08:00
{
2013-07-27 07:04:21 +08:00
_horizAlign = TextHAlignment : : CENTER ;
2012-06-15 15:10:40 +08:00
this - > updateAlignment ( ) ;
}
2014-02-20 10:53:49 +08:00
void LabelTTFTest : : setAlignmentRight ( Ref * sender )
2012-06-15 15:10:40 +08:00
{
2013-07-27 07:04:21 +08:00
_horizAlign = TextHAlignment : : RIGHT ;
2012-06-15 15:10:40 +08:00
this - > updateAlignment ( ) ;
}
2014-02-20 10:53:49 +08:00
void LabelTTFTest : : setAlignmentTop ( Ref * sender )
2012-06-15 15:10:40 +08:00
{
2013-07-27 07:04:21 +08:00
_vertAlign = TextVAlignment : : TOP ;
2012-06-15 15:10:40 +08:00
this - > updateAlignment ( ) ;
}
2014-02-20 10:53:49 +08:00
void LabelTTFTest : : setAlignmentMiddle ( Ref * sender )
2012-06-15 15:10:40 +08:00
{
2013-07-27 07:04:21 +08:00
_vertAlign = TextVAlignment : : CENTER ;
2012-06-15 15:10:40 +08:00
this - > updateAlignment ( ) ;
}
2014-02-20 10:53:49 +08:00
void LabelTTFTest : : setAlignmentBottom ( Ref * sender )
2012-06-15 15:10:40 +08:00
{
2013-07-27 07:04:21 +08:00
_vertAlign = TextVAlignment : : BOTTOM ;
2012-06-15 15:10:40 +08:00
this - > updateAlignment ( ) ;
}
const char * LabelTTFTest : : getCurrentAlignment ( )
{
2014-07-10 00:45:27 +08:00
const char * vertical = nullptr ;
const char * horizontal = nullptr ;
2013-06-15 14:03:30 +08:00
switch ( _vertAlign ) {
2013-07-27 07:04:21 +08:00
case TextVAlignment : : TOP :
2012-06-15 15:10:40 +08:00
vertical = " Top " ;
break ;
2013-07-27 07:04:21 +08:00
case TextVAlignment : : CENTER :
2012-06-15 15:10:40 +08:00
vertical = " Middle " ;
break ;
2013-07-27 07:04:21 +08:00
case TextVAlignment : : BOTTOM :
2012-06-15 15:10:40 +08:00
vertical = " Bottom " ;
break ;
}
2013-06-15 14:03:30 +08:00
switch ( _horizAlign ) {
2013-07-27 07:04:21 +08:00
case TextHAlignment : : LEFT :
2012-06-15 15:10:40 +08:00
horizontal = " Left " ;
break ;
2013-07-27 07:04:21 +08:00
case TextHAlignment : : CENTER :
2012-06-15 15:10:40 +08:00
horizontal = " Center " ;
break ;
2013-07-27 07:04:21 +08:00
case TextHAlignment : : RIGHT :
2012-06-15 15:10:40 +08:00
horizontal = " Right " ;
break ;
}
2013-06-20 14:17:10 +08:00
return String : : createWithFormat ( " Alignment %s %s " , vertical , horizontal ) - > getCString ( ) ;
2012-03-22 11:48:37 +08:00
}
2013-12-19 05:52:10 +08:00
std : : string LabelTTFTest : : title ( ) const
2012-03-22 11:48:37 +08:00
{
2013-06-20 14:17:10 +08:00
return " Testing LabelTTF " ;
2012-03-22 11:48:37 +08:00
}
2013-12-19 05:52:10 +08:00
std : : string LabelTTFTest : : subtitle ( ) const
2012-03-22 11:48:37 +08:00
{
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 ( )
{
2013-08-16 16:05:27 +08:00
auto s = Director : : getInstance ( ) - > getWinSize ( ) ;
2012-03-22 11:48:37 +08:00
2013-08-16 16:05:27 +08:00
auto center = LabelTTF : : 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 ,
2013-07-12 14:30:26 +08:00
Size ( s . width / 2 , 200 ) ,
2013-07-27 07:04:21 +08:00
TextHAlignment : : CENTER ,
TextVAlignment : : TOP ) ;
2012-06-12 14:33:53 +08:00
2014-05-15 01:07:09 +08:00
center - > setPosition ( Vec2 ( 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
}
2013-12-19 05:52:10 +08:00
std : : string LabelTTFMultiline : : title ( ) const
2012-03-22 11:48:37 +08:00
{
2013-06-20 14:17:10 +08:00
return " Testing LabelTTF Word Wrap " ;
2012-03-22 11:48:37 +08:00
}
2013-12-19 05:52:10 +08:00
std : : string LabelTTFMultiline : : subtitle ( ) const
2012-03-22 11:48:37 +08:00
{
2013-06-20 14:17:10 +08:00
return " Word wrap using LabelTTF and a custom TTF font " ;
2012-03-22 11:48:37 +08:00
}
LabelTTFChinese : : LabelTTFChinese ( )
{
2013-07-23 08:25:44 +08:00
auto size = Director : : getInstance ( ) - > getWinSize ( ) ;
2014-04-01 14:49:02 +08:00
auto label = LabelTTF : : create ( " 中国 " , " Marker Felt " , 30 ) ;
2014-05-15 01:07:09 +08:00
label - > setPosition ( Vec2 ( size . width / 2 , size . height / 2 ) ) ;
2013-07-23 08:25:44 +08:00
this - > addChild ( label ) ;
2012-03-22 11:48:37 +08:00
}
2013-12-19 05:52:10 +08:00
std : : string LabelTTFChinese : : title ( ) const
2012-03-22 11:48:37 +08:00
{
2013-06-20 14:17:10 +08:00
return " Testing LabelTTF with Chinese character " ;
2012-03-22 11:48:37 +08:00
}
2012-01-18 18:43:41 +08:00
LabelBMFontChinese : : LabelBMFontChinese ( )
{
2013-07-23 08:25:44 +08:00
auto size = Director : : getInstance ( ) - > getWinSize ( ) ;
auto label = LabelBMFont : : create ( " 中国 " , " fonts/bitmapFontChinese.fnt " ) ;
2014-05-15 01:07:09 +08:00
label - > setPosition ( Vec2 ( size . width / 2 , size . height / 2 ) ) ;
2013-07-23 08:25:44 +08:00
this - > addChild ( label ) ;
2012-01-18 18:43:41 +08:00
}
2013-12-19 05:52:10 +08:00
std : : string LabelBMFontChinese : : title ( ) const
2012-03-22 11:48:37 +08:00
{
2013-06-20 14:17:10 +08:00
return " Testing LabelBMFont with Chinese character " ;
2012-03-22 11:48:37 +08:00
}
/// 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 ( )
{
2013-10-23 16:14:03 +08:00
auto listener = EventListenerTouchAllAtOnce : : create ( ) ;
listener - > onTouchesBegan = CC_CALLBACK_2 ( BitmapFontMultiLineAlignment : : onTouchesBegan , this ) ;
listener - > onTouchesMoved = CC_CALLBACK_2 ( BitmapFontMultiLineAlignment : : onTouchesMoved , this ) ;
listener - > onTouchesEnded = CC_CALLBACK_2 ( BitmapFontMultiLineAlignment : : onTouchesEnded , this ) ;
2013-10-26 15:04:01 +08:00
_eventDispatcher - > addEventListenerWithSceneGraphPriority ( listener , this ) ;
2013-10-23 16:14:03 +08:00
2012-04-19 14:35:52 +08:00
// ask director the the window size
2013-08-16 16:05:27 +08:00
auto size = Director : : getInstance ( ) - > getWinSize ( ) ;
2012-03-22 11:48:37 +08:00
2012-04-19 14:35:52 +08:00
// create and initialize a Label
2014-03-31 17:21:56 +08:00
_labelShouldRetain = LabelBMFont : : create ( LongSentencesExample , " fonts/markerFelt.fnt " , size . width / 1.5 , TextHAlignment : : CENTER ) ;
_labelShouldRetain - > retain ( ) ;
2012-03-22 11:48:37 +08:00
2014-03-31 17:21:56 +08:00
_arrowsBarShouldRetain = Sprite : : create ( " Images/arrowsBar.png " ) ;
_arrowsBarShouldRetain - > retain ( ) ;
_arrowsShouldRetain = Sprite : : create ( " Images/arrows.png " ) ;
_arrowsShouldRetain - > retain ( ) ;
2012-03-22 11:48:37 +08:00
2013-06-20 14:17:10 +08:00
MenuItemFont : : setFontSize ( 20 ) ;
2013-07-23 08:25:44 +08:00
auto longSentences = MenuItemFont : : create ( " Long Flowing Sentences " , CC_CALLBACK_1 ( BitmapFontMultiLineAlignment : : stringChanged , this ) ) ;
auto lineBreaks = MenuItemFont : : create ( " Short Sentences With Intentional Line Breaks " , CC_CALLBACK_1 ( BitmapFontMultiLineAlignment : : stringChanged , this ) ) ;
auto mixed = MenuItemFont : : create ( " Long Sentences Mixed With Intentional Line Breaks " , CC_CALLBACK_1 ( BitmapFontMultiLineAlignment : : stringChanged , this ) ) ;
2014-07-10 00:45:27 +08:00
auto stringMenu = Menu : : create ( longSentences , lineBreaks , mixed , nullptr ) ;
2012-04-19 14:35:52 +08:00
stringMenu - > alignItemsVertically ( ) ;
2012-03-22 11:48:37 +08:00
2013-07-08 18:11:32 +08:00
longSentences - > setColor ( Color3B : : RED ) ;
2013-06-15 14:03:30 +08:00
_lastSentenceItem = 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
2013-06-20 14:17:10 +08:00
MenuItemFont : : setFontSize ( 30 ) ;
2012-03-22 11:48:37 +08:00
2013-07-23 08:25:44 +08:00
auto left = MenuItemFont : : create ( " Left " , CC_CALLBACK_1 ( BitmapFontMultiLineAlignment : : alignmentChanged , this ) ) ;
auto center = MenuItemFont : : create ( " Center " , CC_CALLBACK_1 ( BitmapFontMultiLineAlignment : : alignmentChanged , this ) ) ;
auto right = MenuItemFont : : create ( " Right " , CC_CALLBACK_1 ( BitmapFontMultiLineAlignment : : alignmentChanged , this ) ) ;
2014-07-10 00:45:27 +08:00
auto alignmentMenu = Menu : : create ( left , center , right , nullptr ) ;
2012-04-19 14:35:52 +08:00
alignmentMenu - > alignItemsHorizontallyWithPadding ( alignmentItemPadding ) ;
2012-03-22 11:48:37 +08:00
2013-07-08 18:11:32 +08:00
center - > setColor ( Color3B : : RED ) ;
2013-06-15 14:03:30 +08:00
_lastAlignmentItem = center ;
2012-04-19 14:35:52 +08:00
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
2014-05-15 01:07:09 +08:00
_labelShouldRetain - > setPosition ( Vec2 ( size . width / 2 , size . height / 2 ) ) ;
2012-03-22 11:48:37 +08:00
2014-03-31 17:21:56 +08:00
_arrowsBarShouldRetain - > setVisible ( false ) ;
2012-03-22 11:48:37 +08:00
2012-04-19 14:35:52 +08:00
float arrowsWidth = ( ArrowsMax - ArrowsMin ) * size . width ;
2014-03-31 17:21:56 +08:00
_arrowsBarShouldRetain - > setScaleX ( arrowsWidth / this - > _arrowsBarShouldRetain - > getContentSize ( ) . width ) ;
2014-05-15 01:07:09 +08:00
_arrowsBarShouldRetain - > setPosition ( Vec2 ( ( ( ArrowsMax + ArrowsMin ) / 2 ) * size . width , this - > _labelShouldRetain - > 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
2014-05-15 01:07:09 +08:00
stringMenu - > setPosition ( Vec2 ( size . width / 2 , size . height - menuItemPaddingCenter ) ) ;
alignmentMenu - > setPosition ( Vec2 ( size . width / 2 , menuItemPaddingCenter + 15 ) ) ;
2012-03-22 11:48:37 +08:00
2014-03-31 17:21:56 +08:00
addChild ( _labelShouldRetain ) ;
addChild ( _arrowsBarShouldRetain ) ;
addChild ( _arrowsShouldRetain ) ;
addChild ( stringMenu ) ;
addChild ( alignmentMenu ) ;
2012-03-22 11:48:37 +08:00
}
BitmapFontMultiLineAlignment : : ~ BitmapFontMultiLineAlignment ( )
{
2013-06-15 14:03:30 +08:00
this - > _labelShouldRetain - > release ( ) ;
this - > _arrowsBarShouldRetain - > release ( ) ;
this - > _arrowsShouldRetain - > release ( ) ;
2012-03-22 11:48:37 +08:00
}
2013-12-19 05:52:10 +08:00
std : : string BitmapFontMultiLineAlignment : : title ( ) const
2012-03-22 11:48:37 +08:00
{
2012-04-19 14:35:52 +08:00
return " " ;
2012-03-22 11:48:37 +08:00
}
2013-12-19 05:52:10 +08:00
std : : string BitmapFontMultiLineAlignment : : subtitle ( ) const
2012-03-22 11:48:37 +08:00
{
2012-04-19 14:35:52 +08:00
return " " ;
2012-03-22 11:48:37 +08:00
}
2014-02-20 10:53:49 +08:00
void BitmapFontMultiLineAlignment : : stringChanged ( cocos2d : : Ref * sender )
2012-03-22 11:48:37 +08:00
{
2013-08-16 16:05:27 +08:00
auto item = ( MenuItemFont * ) sender ;
2013-07-08 18:11:32 +08:00
item - > setColor ( Color3B : : RED ) ;
this - > _lastAlignmentItem - > setColor ( Color3B : : WHITE ) ;
2013-06-15 14:03:30 +08:00
this - > _lastAlignmentItem = item ;
2012-03-22 11:48:37 +08:00
2012-04-19 14:35:52 +08:00
switch ( item - > getTag ( ) )
{
case LongSentences :
2014-03-31 17:31:04 +08:00
_labelShouldRetain - > setString ( LongSentencesExample ) ;
2012-04-19 14:35:52 +08:00
break ;
case LineBreaks :
2014-03-31 17:31:04 +08:00
_labelShouldRetain - > setString ( LineBreaksExample ) ;
2012-04-19 14:35:52 +08:00
break ;
case Mixed :
2014-03-31 17:31:04 +08:00
_labelShouldRetain - > setString ( MixedExample ) ;
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
}
2014-02-20 10:53:49 +08:00
void BitmapFontMultiLineAlignment : : alignmentChanged ( cocos2d : : Ref * sender )
2012-03-22 11:48:37 +08:00
{
2013-08-16 16:05:27 +08:00
auto item = static_cast < MenuItemFont * > ( sender ) ;
2013-07-08 18:11:32 +08:00
item - > setColor ( Color3B : : RED ) ;
this - > _lastAlignmentItem - > setColor ( Color3B : : WHITE ) ;
2013-06-15 14:03:30 +08:00
this - > _lastAlignmentItem = item ;
2012-03-22 11:48:37 +08:00
2012-04-19 14:35:52 +08:00
switch ( item - > getTag ( ) )
{
case LeftAlign :
2014-03-31 17:31:04 +08:00
_labelShouldRetain - > setAlignment ( TextHAlignment : : LEFT ) ;
2012-04-19 14:35:52 +08:00
break ;
case CenterAlign :
2014-03-31 17:31:04 +08:00
_labelShouldRetain - > setAlignment ( TextHAlignment : : CENTER ) ;
2012-04-19 14:35:52 +08:00
break ;
case RightAlign :
2014-03-31 17:31:04 +08:00
_labelShouldRetain - > setAlignment ( TextHAlignment : : RIGHT ) ;
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
}
2013-09-03 18:22:03 +08:00
void BitmapFontMultiLineAlignment : : onTouchesBegan ( const std : : vector < Touch * > & touches , cocos2d : : Event * event )
2012-03-22 11:48:37 +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 ( ) ;
2012-03-22 11:48:37 +08:00
2013-07-17 09:16:04 +08:00
if ( this - > _arrowsShouldRetain - > getBoundingBox ( ) . containsPoint ( location ) )
2012-04-19 14:35:52 +08:00
{
2013-06-15 14:03:30 +08:00
_drag = true ;
this - > _arrowsBarShouldRetain - > setVisible ( true ) ;
2012-04-19 14:35:52 +08:00
}
2012-03-22 11:48:37 +08:00
}
2013-09-03 18:22:03 +08:00
void BitmapFontMultiLineAlignment : : onTouchesEnded ( const std : : vector < Touch * > & touches , cocos2d : : Event * event )
2012-03-22 11:48:37 +08:00
{
2013-06-15 14:03:30 +08:00
_drag = false ;
2012-04-19 14:35:52 +08:00
this - > snapArrowsToEdge ( ) ;
2012-03-22 11:48:37 +08:00
2013-06-15 14:03:30 +08:00
this - > _arrowsBarShouldRetain - > setVisible ( false ) ;
2012-03-22 11:48:37 +08:00
}
2013-09-03 18:22:03 +08:00
void BitmapFontMultiLineAlignment : : onTouchesMoved ( const std : : vector < Touch * > & touches , cocos2d : : Event * event )
2012-03-22 11:48:37 +08:00
{
2013-06-15 14:03:30 +08:00
if ( ! _drag )
2012-04-19 14:35:52 +08:00
{
return ;
}
2012-03-22 11:48:37 +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 ( ) ;
2012-03-22 11:48:37 +08:00
2013-08-16 16:05:27 +08:00
auto winSize = Director : : getInstance ( ) - > getWinSize ( ) ;
2012-03-22 11:48:37 +08:00
2014-05-15 01:07:09 +08:00
this - > _arrowsShouldRetain - > setPosition ( Vec2 ( MAX ( MIN ( location . x , ArrowsMax * winSize . width ) , ArrowsMin * winSize . width ) ,
2013-06-15 14:03:30 +08:00
this - > _arrowsShouldRetain - > getPosition ( ) . y ) ) ;
2012-03-22 11:48:37 +08:00
2013-06-15 14:03:30 +08:00
float labelWidth = fabs ( this - > _arrowsShouldRetain - > getPosition ( ) . x - this - > _labelShouldRetain - > getPosition ( ) . x ) * 2 ;
2012-03-22 11:48:37 +08:00
2014-03-31 17:38:54 +08:00
_labelShouldRetain - > setWidth ( labelWidth ) ;
2012-03-22 11:48:37 +08:00
}
void BitmapFontMultiLineAlignment : : snapArrowsToEdge ( )
{
2014-05-15 01:07:09 +08:00
this - > _arrowsShouldRetain - > setPosition ( Vec2 ( this - > _labelShouldRetain - > getPosition ( ) . x + this - > _labelShouldRetain - > getContentSize ( ) . width / 2 ,
2013-06-15 14:03:30 +08:00
this - > _labelShouldRetain - > getPosition ( ) . y ) ) ;
2012-03-22 11:48:37 +08:00
}
2014-10-20 14:58:15 +08:00
/// LabelTTFOpacityTest
LabelTTFOpacityTest : : LabelTTFOpacityTest ( )
2012-03-22 11:48:37 +08:00
{
2013-08-16 16:05:27 +08:00
auto s = Director : : getInstance ( ) - > getWinSize ( ) ;
2012-03-22 11:48:37 +08:00
2013-08-16 16:05:27 +08:00
auto layer = LayerColor : : create ( Color4B ( 128 , 128 , 128 , 255 ) ) ;
2012-04-19 14:35:52 +08:00
addChild ( layer , - 10 ) ;
2012-03-22 11:48:37 +08:00
2014-10-20 14:58:15 +08:00
auto label1 = LabelTTF : : create ( " Testing opacity " , " Marker Felt " , 48 ) ;
2012-04-19 14:35:52 +08:00
addChild ( label1 ) ;
2014-10-20 14:58:15 +08:00
label1 - > setFontFillColor ( Color3B : : RED ) ;
2014-05-15 01:07:09 +08:00
label1 - > setPosition ( Vec2 ( s . width / 2 , s . height / 2 ) ) ;
2012-03-22 11:48:37 +08:00
2013-07-23 08:25:44 +08:00
auto fadeOut = FadeOut : : create ( 2 ) ;
auto fadeIn = FadeIn : : create ( 2 ) ;
2014-07-10 00:45:27 +08:00
auto seq = Sequence : : create ( fadeOut , fadeIn , nullptr ) ;
2013-07-23 08:25:44 +08:00
auto forever = RepeatForever : : create ( seq ) ;
2012-04-19 14:35:52 +08:00
label1 - > runAction ( forever ) ;
2012-03-22 11:48:37 +08:00
}
2014-10-20 14:58:15 +08:00
std : : string LabelTTFOpacityTest : : title ( ) const
2012-03-22 11:48:37 +08:00
{
2014-10-20 14:58:15 +08:00
return " Testing opacity " ;
2012-03-22 11:48:37 +08:00
}
2014-10-20 14:58:15 +08:00
std : : string LabelTTFOpacityTest : : subtitle ( ) const
2012-03-22 11:48:37 +08:00
{
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 ( )
{
2013-08-16 16:05:27 +08:00
auto s = Director : : getInstance ( ) - > getWinSize ( ) ;
2012-03-22 11:48:37 +08:00
2014-02-20 22:33:52 +08:00
auto label1 = LabelBMFont : : create ( " This is Helvetica " , " fonts/helvetica-32.fnt " ) ;
2012-03-22 11:48:37 +08:00
addChild ( label1 ) ;
2014-05-15 01:07:09 +08:00
label1 - > setPosition ( Vec2 ( s . width / 2 , s . height / 3 * 2 ) ) ;
2012-03-22 11:48:37 +08:00
2014-05-15 01:07:09 +08:00
auto label2 = LabelBMFont : : create ( " And this is Geneva " , " fonts/geneva-32.fnt " , 0 , TextHAlignment : : LEFT , Vec2 ( 0 , 128 ) ) ;
2012-04-19 14:35:52 +08:00
addChild ( label2 ) ;
2014-05-15 01:07:09 +08:00
label2 - > setPosition ( Vec2 ( s . width / 2 , s . height / 3 * 1 ) ) ;
2012-03-22 11:48:37 +08:00
}
2013-12-19 05:52:10 +08:00
std : : string BMFontOneAtlas : : title ( ) const
2012-03-22 11:48:37 +08:00
{
2012-04-19 14:35:52 +08:00
return " CCLabelBMFont with one texture " ;
2012-03-22 11:48:37 +08:00
}
2013-12-19 05:52:10 +08:00
std : : string BMFontOneAtlas : : subtitle ( ) const
2012-03-22 11:48:37 +08:00
{
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 ( )
{
2018-04-25 09:50:53 +08:00
auto strings = FileUtils : : getInstance ( ) - > getValueMapFromFile ( " strings/LabelFNTUNICODELanguages.xml " ) ;
2013-12-18 16:03:07 +08:00
std : : string chinese = strings [ " chinese1 " ] . asString ( ) ;
std : : string russian = strings [ " russian " ] . asString ( ) ;
std : : string spanish = strings [ " spanish " ] . asString ( ) ;
std : : string japanese = strings [ " japanese " ] . asString ( ) ;
2012-03-22 11:48:37 +08:00
2013-08-16 16:05:27 +08:00
auto s = Director : : getInstance ( ) - > getWinSize ( ) ;
2012-03-22 11:48:37 +08:00
2013-07-27 07:04:21 +08:00
auto label1 = LabelBMFont : : create ( spanish , " fonts/arial-unicode-26.fnt " , 200 , TextHAlignment : : LEFT ) ;
2012-03-22 11:48:37 +08:00
addChild ( label1 ) ;
2014-05-15 01:07:09 +08:00
label1 - > setPosition ( Vec2 ( s . width / 2 , s . height / 5 * 4 ) ) ;
2012-03-22 11:48:37 +08:00
2013-07-23 08:25:44 +08:00
auto label2 = LabelBMFont : : create ( chinese , " fonts/arial-unicode-26.fnt " ) ;
2012-04-19 14:35:52 +08:00
addChild ( label2 ) ;
2014-05-15 01:07:09 +08:00
label2 - > setPosition ( Vec2 ( s . width / 2 , s . height / 5 * 3 ) ) ;
2012-03-22 11:48:37 +08:00
2013-07-23 08:25:44 +08:00
auto label3 = LabelBMFont : : create ( russian , " fonts/arial-26-en-ru.fnt " ) ;
2012-04-19 14:35:52 +08:00
addChild ( label3 ) ;
2014-05-15 01:07:09 +08:00
label3 - > setPosition ( Vec2 ( s . width / 2 , s . height / 5 * 2 ) ) ;
2013-05-04 20:28:24 +08:00
2013-07-23 08:25:44 +08:00
auto label4 = LabelBMFont : : create ( japanese , " fonts/arial-unicode-26.fnt " ) ;
2013-05-04 20:28:24 +08:00
addChild ( label4 ) ;
2014-05-15 01:07:09 +08:00
label4 - > setPosition ( Vec2 ( s . width / 2 , s . height / 5 * 1 ) ) ;
2012-03-22 11:48:37 +08:00
}
2013-12-19 05:52:10 +08:00
std : : string BMFontUnicode : : title ( ) const
2012-03-22 11:48:37 +08:00
{
2012-04-19 14:35:52 +08:00
return " CCLabelBMFont with Unicode support " ;
2012-03-22 11:48:37 +08:00
}
2013-12-19 05:52:10 +08:00
std : : string BMFontUnicode : : subtitle ( ) const
2012-03-22 11:48:37 +08:00
{
2017-02-24 12:45:41 +08:00
return " You should see 4 different labels: \n In Spanish, Chinese, Russian and Korean " ;
2012-06-15 15:10:40 +08:00
}
// BMFontInit
BMFontInit : : BMFontInit ( )
{
2013-08-16 16:05:27 +08:00
auto s = Director : : getInstance ( ) - > getWinSize ( ) ;
2012-06-15 15:10:40 +08:00
2013-08-16 16:05:27 +08:00
auto bmFont = LabelBMFont : : create ( ) ;
2013-07-23 08:25:44 +08:00
2012-06-15 15:10:40 +08:00
bmFont - > setFntFile ( " fonts/helvetica-32.fnt " ) ;
bmFont - > setString ( " It is working! " ) ;
this - > addChild ( bmFont ) ;
2014-05-15 01:07:09 +08:00
bmFont - > setPosition ( Vec2 ( s . width / 2 , s . height / 4 * 2 ) ) ;
2012-06-15 15:10:40 +08:00
}
2013-12-19 05:52:10 +08:00
std : : string BMFontInit : : title ( ) const
2012-06-12 14:33:53 +08:00
{
2013-07-23 08:25:44 +08:00
return " LabelBMFont create() " ;
2012-06-12 14:33:53 +08:00
}
2013-12-19 05:52:10 +08:00
std : : string BMFontInit : : subtitle ( ) const
2012-06-12 14:33:53 +08:00
{
2017-02-10 10:35:52 +08:00
return " Testing LabelBMFont::create() without params " ;
2012-06-15 15:10:40 +08:00
}
// TTFFontInit
TTFFontInit : : TTFFontInit ( )
{
2013-08-16 16:05:27 +08:00
auto s = Director : : getInstance ( ) - > getWinSize ( ) ;
2012-06-15 15:10:40 +08:00
2013-08-16 16:05:27 +08:00
auto font = LabelTTF : : create ( ) ;
2013-07-23 08:25:44 +08:00
2014-04-01 14:49:02 +08:00
font - > setFontName ( " Marker Felt " ) ;
2012-06-15 15:10:40 +08:00
font - > setFontSize ( 48 ) ;
font - > setString ( " It is working! " ) ;
this - > addChild ( font ) ;
2014-05-15 01:07:09 +08:00
font - > setPosition ( Vec2 ( s . width / 2 , s . height / 4 * 2 ) ) ;
2012-06-15 15:10:40 +08:00
}
2013-12-19 05:52:10 +08:00
std : : string TTFFontInit : : title ( ) const
2012-06-12 14:33:53 +08:00
{
2013-07-23 08:25:44 +08:00
return " LabelTTF create() " ;
2012-06-12 14:33:53 +08:00
}
2013-12-19 05:52:10 +08:00
std : : string TTFFontInit : : subtitle ( ) const
2012-06-12 14:33:53 +08:00
{
2017-02-10 10:35:52 +08:00
return " Testing LabelTTF::create() without params " ;
2012-06-12 14:33:53 +08:00
}
2012-06-15 15:10:40 +08:00
2013-04-26 09:22:26 +08:00
TTFFontShadowAndStroke : : TTFFontShadowAndStroke ( )
{
2013-08-16 16:05:27 +08:00
auto layer = LayerColor : : create ( Color4B ( 0 , 190 , 0 , 255 ) ) ;
2013-04-26 09:22:26 +08:00
addChild ( layer , - 10 ) ;
2013-08-16 16:05:27 +08:00
auto s = Director : : getInstance ( ) - > getWinSize ( ) ;
2013-06-08 07:33:01 +08:00
2013-07-07 21:08:14 +08:00
Color3B tintColorRed ( 255 , 0 , 0 ) ;
Color3B tintColorYellow ( 255 , 255 , 0 ) ;
Color3B tintColorBlue ( 0 , 0 , 255 ) ;
2014-03-24 17:05:24 +08:00
Color3B strokeColor ( 0 , 0 , 255 ) ;
2013-07-07 21:08:14 +08:00
Color3B strokeShadowColor ( 255 , 0 , 0 ) ;
2013-04-26 09:22:26 +08:00
2013-06-20 14:17:10 +08:00
Size shadowOffset ( 12.0 , 12.0 ) ;
2013-05-04 01:07:37 +08:00
2013-07-05 16:49:22 +08:00
FontDefinition shadowTextDef ;
2013-06-15 14:03:30 +08:00
shadowTextDef . _fontSize = 20 ;
2014-04-01 14:49:02 +08:00
shadowTextDef . _fontName = std : : string ( " Marker Felt " ) ;
2013-05-04 01:07:37 +08:00
2013-06-15 14:03:30 +08:00
shadowTextDef . _shadow . _shadowEnabled = true ;
shadowTextDef . _shadow . _shadowOffset = shadowOffset ;
shadowTextDef . _shadow . _shadowOpacity = 1.0 ;
shadowTextDef . _shadow . _shadowBlur = 1.0 ;
shadowTextDef . _fontFillColor = tintColorRed ;
2013-05-01 07:36:14 +08:00
2013-06-08 07:33:01 +08:00
// shadow only label
2013-08-16 16:05:27 +08:00
auto fontShadow = LabelTTF : : createWithFontDefinition ( " Shadow Only Red Text " , shadowTextDef ) ;
2013-05-01 07:36:14 +08:00
// add label to the scene
2013-04-26 09:22:26 +08:00
this - > addChild ( fontShadow ) ;
2014-05-15 01:07:09 +08:00
fontShadow - > setPosition ( Vec2 ( s . width / 2 , s . height / 4 * 2.5 ) ) ;
2013-05-01 07:36:14 +08:00
2013-07-23 08:25:44 +08:00
2013-06-08 07:33:01 +08:00
// create the stroke only label
2013-07-05 16:49:22 +08:00
FontDefinition strokeTextDef ;
2013-06-15 14:03:30 +08:00
strokeTextDef . _fontSize = 20 ;
2014-04-01 14:49:02 +08:00
strokeTextDef . _fontName = std : : string ( " Marker Felt " ) ;
2013-05-04 01:07:37 +08:00
2013-06-15 14:03:30 +08:00
strokeTextDef . _stroke . _strokeEnabled = true ;
strokeTextDef . _stroke . _strokeColor = strokeColor ;
strokeTextDef . _stroke . _strokeSize = 1.5 ;
2013-05-01 07:36:14 +08:00
2013-06-15 14:03:30 +08:00
strokeTextDef . _fontFillColor = tintColorYellow ;
2013-05-04 01:07:37 +08:00
2013-06-08 07:33:01 +08:00
// stroke only label
2013-08-16 16:05:27 +08:00
auto fontStroke = LabelTTF : : createWithFontDefinition ( " Stroke Only Yellow Text " , strokeTextDef ) ;
2013-05-01 07:36:14 +08:00
// add label to the scene
2013-04-26 09:22:26 +08:00
this - > addChild ( fontStroke ) ;
2014-05-15 01:07:09 +08:00
fontStroke - > setPosition ( Vec2 ( s . width / 2 , s . height / 4 * 1.8 ) ) ;
2013-04-26 09:22:26 +08:00
2013-05-04 01:07:37 +08:00
// create the label stroke and shadow
2013-07-05 16:49:22 +08:00
FontDefinition strokeShaodwTextDef ;
2013-06-15 14:03:30 +08:00
strokeShaodwTextDef . _fontSize = 20 ;
2014-04-01 14:49:02 +08:00
strokeShaodwTextDef . _fontName = std : : string ( " Marker Felt " ) ;
2013-05-04 01:07:37 +08:00
2013-06-15 14:03:30 +08:00
strokeShaodwTextDef . _stroke . _strokeEnabled = true ;
strokeShaodwTextDef . _stroke . _strokeColor = strokeShadowColor ;
strokeShaodwTextDef . _stroke . _strokeSize = 1.5 ;
2013-05-01 07:36:14 +08:00
2013-06-15 14:03:30 +08:00
strokeShaodwTextDef . _shadow . _shadowEnabled = true ;
strokeShaodwTextDef . _shadow . _shadowOffset = shadowOffset ;
strokeShaodwTextDef . _shadow . _shadowOpacity = 1.0 ;
strokeShaodwTextDef . _shadow . _shadowBlur = 1.0 ;
2013-05-01 07:36:14 +08:00
2013-05-09 01:22:04 +08:00
2013-06-15 14:03:30 +08:00
strokeShaodwTextDef . _fontFillColor = tintColorBlue ;
2013-06-08 07:33:01 +08:00
// shadow + stroke label
2015-01-29 11:55:49 +08:00
auto fontStrokeAndShadow = LabelTTF : : createWithFontDefinition ( " Stroke & Shadow Blue Text " , strokeShaodwTextDef ) ;
2013-05-01 07:36:14 +08:00
// add label to the scene
2013-04-26 09:22:26 +08:00
this - > addChild ( fontStrokeAndShadow ) ;
2014-05-15 01:07:09 +08:00
fontStrokeAndShadow - > setPosition ( Vec2 ( s . width / 2 , s . height / 4 * 1.1 ) ) ;
2014-03-24 17:39:23 +08:00
auto buttonBG = MenuItemImage : : create ( " cocosui/animationbuttonnormal.png " , " cocosui/animationbuttonpressed.png " ) ;
2014-05-15 01:07:09 +08:00
buttonBG - > setAnchorPoint ( Vec2 : : ANCHOR_MIDDLE_LEFT ) ;
2014-03-24 17:39:23 +08:00
buttonBG - > setPosition ( VisibleRect : : left ( ) ) ;
// create the label stroke and shadow
strokeShaodwTextDef . _fontSize = 18 ;
strokeShaodwTextDef . _fontName = " Marker Felt " ;
strokeShaodwTextDef . _stroke . _strokeEnabled = true ;
strokeShaodwTextDef . _stroke . _strokeColor = Color3B : : BLACK ;
strokeShaodwTextDef . _stroke . _strokeSize = 3.0f ;
strokeShaodwTextDef . _shadow . _shadowEnabled = false ;
strokeShaodwTextDef . _shadow . _shadowOffset = Size ( 1 , 1 ) ;
strokeShaodwTextDef . _shadow . _shadowOpacity = 1.0 ;
strokeShaodwTextDef . _shadow . _shadowBlur = 0.5f ;
strokeShaodwTextDef . _fontFillColor = Color3B : : WHITE ;
// shadow + stroke label
fontStrokeAndShadow = LabelTTF : : createWithFontDefinition ( " Test " , strokeShaodwTextDef ) ;
// add label to the scene
buttonBG - > addChild ( fontStrokeAndShadow ) ;
2014-05-15 01:07:09 +08:00
fontStrokeAndShadow - > setPosition ( Vec2 ( buttonBG - > getContentSize ( ) . width / 2 , buttonBG - > getContentSize ( ) . height / 2 ) ) ;
2014-03-24 17:39:23 +08:00
auto menu = Menu : : create ( buttonBG , nullptr ) ;
2014-05-15 01:07:09 +08:00
menu - > setAnchorPoint ( Vec2 : : ANCHOR_BOTTOM_LEFT ) ;
menu - > setPosition ( Vec2 : : ZERO ) ;
2014-03-24 17:39:23 +08:00
addChild ( menu ) ;
2013-04-26 09:22:26 +08:00
}
2013-12-19 05:52:10 +08:00
std : : string TTFFontShadowAndStroke : : title ( ) const
2013-04-26 09:22:26 +08:00
{
return " CCLabelTTF shadows + stroke " ;
}
2013-12-19 05:52:10 +08:00
std : : string TTFFontShadowAndStroke : : subtitle ( ) const
2013-04-26 09:22:26 +08:00
{
return " Test for support of TTF label with stroke and shadow " ;
}
2012-06-15 15:10:40 +08:00
// Issue1343
Issue1343 : : Issue1343 ( )
{
2013-08-16 16:05:27 +08:00
auto s = Director : : getInstance ( ) - > getWinSize ( ) ;
2012-06-15 15:10:40 +08:00
2013-08-16 16:05:27 +08:00
auto bmFont = LabelBMFont : : create ( ) ;
2013-07-23 08:25:44 +08:00
2012-06-15 15:10:40 +08:00
bmFont - > setFntFile ( " fonts/font-issue1343.fnt " ) ;
bmFont - > setString ( " ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyz.,' " ) ;
2013-07-23 08:25:44 +08:00
2012-06-15 15:10:40 +08:00
this - > addChild ( bmFont ) ;
2013-07-23 08:25:44 +08:00
bmFont - > setScale ( 0.3f ) ;
2014-05-15 01:07:09 +08:00
bmFont - > setPosition ( Vec2 ( s . width / 2 , s . height / 4 * 2 ) ) ;
2012-06-15 15:10:40 +08:00
}
2013-12-19 05:52:10 +08:00
std : : string Issue1343 : : title ( ) const
2012-06-12 14:33:53 +08:00
{
return " Issue 1343 " ;
}
2013-12-19 05:52:10 +08:00
std : : string Issue1343 : : subtitle ( ) const
2012-06-12 14:33:53 +08:00
{
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 ( )
{
2013-08-16 16:05:27 +08:00
auto s = Director : : getInstance ( ) - > getWinSize ( ) ;
2012-11-20 18:17:47 +08:00
2013-08-16 16:05:27 +08:00
auto layer = LayerColor : : create ( Color4B ( 128 , 128 , 128 , 255 ) ) ;
2012-11-20 18:17:47 +08:00
addChild ( layer , - 10 ) ;
2013-06-20 14:17:10 +08:00
// LabelBMFont
2014-09-11 15:39:56 +08:00
auto label1 = LabelBMFont : : create ( " Testing Glyph Designer " , " fonts/boundsTestFont.fnt " ) ;
2012-11-20 18:17:47 +08:00
addChild ( label1 ) ;
2014-05-15 01:07:09 +08:00
label1 - > setPosition ( Vec2 ( s . width / 2 , s . height / 2 ) ) ;
2014-09-11 15:39:56 +08:00
auto drawNode = DrawNode : : create ( ) ;
2013-08-16 16:05:27 +08:00
auto labelSize = label1 - > getContentSize ( ) ;
auto origin = Director : : getInstance ( ) - > getWinSize ( ) ;
2012-11-20 18:17:47 +08:00
origin . width = origin . width / 2 - ( labelSize . width / 2 ) ;
origin . height = origin . height / 2 - ( labelSize . height / 2 ) ;
2014-05-15 01:07:09 +08:00
Vec2 vertices [ 4 ] =
2012-11-20 18:17:47 +08:00
{
2014-05-15 01:07:09 +08:00
Vec2 ( origin . width , origin . height ) ,
Vec2 ( labelSize . width + origin . width , origin . height ) ,
Vec2 ( labelSize . width + origin . width , labelSize . height + origin . height ) ,
Vec2 ( origin . width , labelSize . height + origin . height )
2012-11-20 18:17:47 +08:00
} ;
2014-09-11 15:39:56 +08:00
drawNode - > drawPoly ( vertices , 4 , true , Color4F ( 1.0 , 1.0 , 1.0 , 1.0 ) ) ;
addChild ( drawNode ) ;
}
2014-03-06 07:49:08 +08:00
2014-09-11 15:39:56 +08:00
std : : string LabelBMFontBounds : : title ( ) const
{
return " Testing LabelBMFont Bounds " ;
}
std : : string LabelBMFontBounds : : subtitle ( ) const
{
return " You should see string enclosed by a box " ;
2012-11-20 18:17:47 +08:00
}
2013-08-21 14:56:43 +08:00
// LabelBMFontCrashTest
void LabelBMFontCrashTest : : onEnter ( )
{
AtlasDemo : : onEnter ( ) ;
auto winSize = Director : : getInstance ( ) - > getWinSize ( ) ;
//Create a label and add it
2014-08-28 07:31:57 +08:00
auto label1 = new ( std : : nothrow ) LabelBMFont ( ) ;
2013-08-21 14:56:43 +08:00
label1 - > initWithString ( " test " , " fonts/bitmapFontTest2.fnt " ) ;
this - > addChild ( label1 ) ;
// Visit will call draw where the function "ccGLBindVAO(m_uVAOname);" will be invoked.
label1 - > visit ( ) ;
// Remove this label
label1 - > removeFromParentAndCleanup ( true ) ;
label1 - > release ( ) ;
// Create a new label and add it (then crashes)
auto label2 = LabelBMFont : : create ( " test 2 " , " fonts/bitmapFontTest.fnt " ) ;
2014-05-15 01:07:09 +08:00
label2 - > setPosition ( Vec2 ( winSize . width / 2 , winSize . height / 2 ) ) ;
2013-08-21 14:56:43 +08:00
this - > addChild ( label2 ) ;
}
2013-12-19 05:52:10 +08:00
std : : string LabelBMFontCrashTest : : title ( ) const
2013-08-21 14:56:43 +08:00
{
return " LabelBMFont Crash Test " ;
}
2013-12-19 05:52:10 +08:00
std : : string LabelBMFontCrashTest : : subtitle ( ) const
2013-08-21 14:56:43 +08:00
{
return " Should not crash. " ;
}
2013-12-29 03:00:07 +08:00
// LabelBMFontBinaryFormat
LabelBMFontBinaryFormat : : LabelBMFontBinaryFormat ( )
{
auto s = Director : : getInstance ( ) - > getWinSize ( ) ;
auto bmFont = LabelBMFont : : create ( ) ;
bmFont - > setFntFile ( " fonts/Roboto.bmf.fnt " ) ;
bmFont - > setString ( " It is working! " ) ;
this - > addChild ( bmFont ) ;
2014-05-15 01:07:09 +08:00
bmFont - > setPosition ( Vec2 ( s . width / 2 , s . height / 4 * 2 ) ) ;
2013-12-29 03:00:07 +08:00
}
std : : string LabelBMFontBinaryFormat : : title ( ) const
{
return " LabelBMFont Binary FNT File " ;
}
std : : string LabelBMFontBinaryFormat : : subtitle ( ) const
{
return " This label uses font file in AngelCode binary format " ;
}
2014-03-31 17:21:56 +08:00
# if defined(__GNUC__) && ((__GNUC__ >= 4) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1)))
# pragma GCC diagnostic warning "-Wdeprecated-declarations"
# elif _MSC_VER >= 1400 //vs 2005 or higher
# pragma warning (pop)
# endif