2011-07-29 15:57:27 +08:00
|
|
|
#include "FontTest.h"
|
|
|
|
#include "../testResource.h"
|
|
|
|
|
|
|
|
enum {
|
2012-04-19 14:35:52 +08:00
|
|
|
kTagLabel1,
|
|
|
|
kTagLabel2,
|
|
|
|
kTagLabel3,
|
|
|
|
kTagLabel4,
|
2013-04-24 14:49:52 +08:00
|
|
|
|
|
|
|
kTagColor1,
|
|
|
|
kTagColor2,
|
|
|
|
kTagColor3,
|
2011-07-29 15:57:27 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static int fontIdx = 0;
|
2011-10-20 14:56:39 +08:00
|
|
|
|
2011-07-29 15:57:27 +08:00
|
|
|
static std::string fontList[] =
|
|
|
|
{
|
2013-11-25 23:00:53 +08:00
|
|
|
#if ((CC_TARGET_PLATFORM == CC_PLATFORM_IOS) || (CC_TARGET_PLATFORM == CC_PLATFORM_MAC))
|
2012-10-15 12:03:15 +08:00
|
|
|
// custom ttf files are defined in Test-info.plist
|
2011-10-20 14:56:39 +08:00
|
|
|
"American Typewriter",
|
2012-04-19 14:35:52 +08:00
|
|
|
"Marker Felt",
|
2012-10-15 12:03:15 +08:00
|
|
|
"A Damn Mess",
|
|
|
|
"Abberancy",
|
|
|
|
"Abduction",
|
|
|
|
"Paint Boy",
|
|
|
|
"Schwarzwald Regular",
|
|
|
|
"Scissor Cuts",
|
|
|
|
#else
|
2012-04-19 14:35:52 +08:00
|
|
|
"fonts/A Damn Mess.ttf",
|
|
|
|
"fonts/Abberancy.ttf",
|
|
|
|
"fonts/Abduction.ttf",
|
|
|
|
"fonts/Paint Boy.ttf",
|
|
|
|
"fonts/Schwarzwald Regular.ttf",
|
|
|
|
"fonts/Scissor Cuts.ttf",
|
2012-10-15 12:03:15 +08:00
|
|
|
#endif
|
2011-07-29 15:57:27 +08:00
|
|
|
};
|
|
|
|
|
2012-06-15 15:10:40 +08:00
|
|
|
static int fontCount = sizeof(fontList) / sizeof(*fontList);
|
|
|
|
|
|
|
|
static int vAlignIdx = 0;
|
2013-07-27 07:04:21 +08:00
|
|
|
static TextVAlignment verticalAlignment[] =
|
2012-06-15 15:10:40 +08:00
|
|
|
{
|
2013-07-27 07:04:21 +08:00
|
|
|
TextVAlignment::TOP,
|
|
|
|
TextVAlignment::CENTER,
|
|
|
|
TextVAlignment::BOTTOM,
|
2012-06-15 15:10:40 +08:00
|
|
|
};
|
2012-06-12 11:16:31 +08:00
|
|
|
static int vAlignCount = sizeof(verticalAlignment) / sizeof(*verticalAlignment);
|
|
|
|
|
2011-07-29 15:57:27 +08:00
|
|
|
static const char* nextAction(void)
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
fontIdx++;
|
2012-06-15 15:10:40 +08:00
|
|
|
if(fontIdx >= fontCount) {
|
|
|
|
fontIdx = 0;
|
|
|
|
vAlignIdx = (vAlignIdx + 1) % vAlignCount;
|
2012-06-12 11:16:31 +08:00
|
|
|
}
|
2012-04-19 14:35:52 +08:00
|
|
|
return fontList[fontIdx].c_str();
|
2011-07-29 15:57:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static const char* backAction(void)
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
fontIdx--;
|
2012-06-15 15:10:40 +08:00
|
|
|
if( fontIdx < 0 ) {
|
|
|
|
fontIdx = fontCount - 1;
|
|
|
|
vAlignIdx--;
|
|
|
|
if(vAlignIdx < 0)
|
|
|
|
vAlignIdx = vAlignCount - 1;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2011-07-29 15:57:27 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
return fontList[fontIdx].c_str();
|
2011-07-29 15:57:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static const char* restartAction(void)
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return fontList[fontIdx].c_str();
|
2011-07-29 15:57:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FontTest::FontTest()
|
2013-06-07 08:12:28 +08:00
|
|
|
: BaseTest()
|
2011-07-29 15:57:27 +08:00
|
|
|
{
|
|
|
|
showFont(restartAction());
|
|
|
|
}
|
|
|
|
|
|
|
|
void FontTest::showFont(const char *pFont)
|
|
|
|
{
|
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 blockSize = Size(s.width/3, 200);
|
2012-08-01 15:30:12 +08:00
|
|
|
float fontSize = 26;
|
2012-06-12 11:16:31 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
removeChildByTag(kTagLabel1, true);
|
|
|
|
removeChildByTag(kTagLabel2, true);
|
|
|
|
removeChildByTag(kTagLabel3, true);
|
|
|
|
removeChildByTag(kTagLabel4, true);
|
2013-04-24 14:49:52 +08:00
|
|
|
removeChildByTag(kTagColor1, true);
|
|
|
|
removeChildByTag(kTagColor2, true);
|
|
|
|
removeChildByTag(kTagColor3, true);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2014-04-09 23:31:05 +08:00
|
|
|
auto top = Label::createWithSystemFont(pFont, pFont, 24);
|
|
|
|
auto left = Label::createWithSystemFont("alignment left", pFont, fontSize,
|
2013-07-27 07:04:21 +08:00
|
|
|
blockSize, TextHAlignment::LEFT, verticalAlignment[vAlignIdx]);
|
2014-04-09 23:31:05 +08:00
|
|
|
auto center = Label::createWithSystemFont("alignment center", pFont, fontSize,
|
2013-07-27 07:04:21 +08:00
|
|
|
blockSize, TextHAlignment::CENTER, verticalAlignment[vAlignIdx]);
|
2014-04-09 23:31:05 +08:00
|
|
|
auto right = Label::createWithSystemFont("alignment right", pFont, fontSize,
|
2013-07-27 07:04:21 +08:00
|
|
|
blockSize, TextHAlignment::RIGHT, verticalAlignment[vAlignIdx]);
|
2012-06-15 15:10:40 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto leftColor = LayerColor::create(Color4B(100, 100, 100, 255), blockSize.width, blockSize.height);
|
|
|
|
auto centerColor = LayerColor::create(Color4B(200, 100, 100, 255), blockSize.width, blockSize.height);
|
|
|
|
auto rightColor = LayerColor::create(Color4B(100, 100, 200, 255), blockSize.width, blockSize.height);
|
2012-06-15 15:10:40 +08:00
|
|
|
|
|
|
|
leftColor->ignoreAnchorPointForPosition(false);
|
|
|
|
centerColor->ignoreAnchorPointForPosition(false);
|
|
|
|
rightColor->ignoreAnchorPointForPosition(false);
|
|
|
|
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
top->setAnchorPoint(Vec2(0.5, 1));
|
|
|
|
left->setAnchorPoint(Vec2(0,0.5));
|
|
|
|
leftColor->setAnchorPoint(Vec2(0,0.5));
|
|
|
|
center->setAnchorPoint(Vec2(0,0.5));
|
|
|
|
centerColor->setAnchorPoint(Vec2(0,0.5));
|
|
|
|
right->setAnchorPoint(Vec2(0,0.5));
|
|
|
|
rightColor->setAnchorPoint(Vec2(0,0.5));
|
|
|
|
|
|
|
|
top->setPosition(Vec2(s.width/2,s.height-20));
|
|
|
|
left->setPosition(Vec2(0,s.height/2));
|
2012-06-15 15:10:40 +08:00
|
|
|
leftColor->setPosition(left->getPosition());
|
2014-05-15 01:07:09 +08:00
|
|
|
center->setPosition(Vec2(blockSize.width, s.height/2));
|
2012-06-15 15:10:40 +08:00
|
|
|
centerColor->setPosition(center->getPosition());
|
2014-05-15 01:07:09 +08:00
|
|
|
right->setPosition(Vec2(blockSize.width*2, s.height/2));
|
2012-06-15 15:10:40 +08:00
|
|
|
rightColor->setPosition(right->getPosition());
|
|
|
|
|
2013-04-24 14:49:52 +08:00
|
|
|
this->addChild(leftColor, -1, kTagColor1);
|
2012-06-15 15:10:40 +08:00
|
|
|
this->addChild(left, 0, kTagLabel1);
|
2013-04-24 14:49:52 +08:00
|
|
|
this->addChild(rightColor, -1, kTagColor2);
|
2012-06-15 15:10:40 +08:00
|
|
|
this->addChild(right, 0, kTagLabel2);
|
2013-04-24 14:49:52 +08:00
|
|
|
this->addChild(centerColor, -1, kTagColor3);
|
2012-06-15 15:10:40 +08:00
|
|
|
this->addChild(center, 0, kTagLabel3);
|
2012-06-12 11:16:31 +08:00
|
|
|
this->addChild(top, 0, kTagLabel4);
|
2011-07-29 15:57:27 +08:00
|
|
|
}
|
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
void FontTest::backCallback(Ref* sender)
|
2011-07-29 15:57:27 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
showFont(backAction());
|
2011-07-29 15:57:27 +08:00
|
|
|
}
|
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
void FontTest::nextCallback(Ref* sender)
|
2011-07-29 15:57:27 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
showFont(nextAction());
|
2011-07-29 15:57:27 +08:00
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string FontTest::title() const
|
2011-07-29 15:57:27 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "Font test";
|
2011-07-29 15:57:27 +08:00
|
|
|
}
|
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
void FontTest::restartCallback(Ref* sender)
|
2011-07-29 15:57:27 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
showFont(restartAction());
|
2011-07-29 15:57:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
///---------------------------------------
|
|
|
|
//
|
|
|
|
// DirectorTestScene
|
|
|
|
//
|
|
|
|
///---------------------------------------
|
|
|
|
void FontTestScene::runThisTest()
|
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto layer = FontTest::create();
|
2013-07-23 08:25:44 +08:00
|
|
|
addChild(layer);
|
2011-07-29 15:57:27 +08:00
|
|
|
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->replaceScene(this);
|
2011-07-29 15:57:27 +08:00
|
|
|
}
|