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,
|
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[] =
|
|
|
|
{
|
2011-10-20 14:56:39 +08:00
|
|
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
|
|
|
|
"American Typewriter",
|
2012-04-19 14:35:52 +08:00
|
|
|
"Marker Felt",
|
2011-10-20 14:56:39 +08:00
|
|
|
#endif
|
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",
|
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;
|
|
|
|
static CCVerticalTextAlignment verticalAlignment[] =
|
|
|
|
{
|
|
|
|
kCCVerticalTextAlignmentTop,
|
|
|
|
kCCVerticalTextAlignmentCenter,
|
|
|
|
kCCVerticalTextAlignmentBottom,
|
|
|
|
};
|
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()
|
|
|
|
{
|
2012-06-12 11:16:31 +08:00
|
|
|
CCSize s = CCDirector::sharedDirector()->getWinSize();
|
2012-06-14 15:13:16 +08:00
|
|
|
CCMenuItemImage *item1 = CCMenuItemImage::create(s_pPathB1, s_pPathB2, this, menu_selector(FontTest::backCallback));
|
|
|
|
CCMenuItemImage *item2 = CCMenuItemImage::create(s_pPathR1, s_pPathR2, this, menu_selector(FontTest::restartCallback));
|
|
|
|
CCMenuItemImage *item3 = CCMenuItemImage::create(s_pPathF1, s_pPathF2, this, menu_selector(FontTest::nextCallback));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
CCMenu *menu = CCMenu::create(item1, item2, item3, NULL);
|
2012-04-19 14:35:52 +08:00
|
|
|
menu->setPosition(CCPointZero);
|
2012-06-12 11:16:31 +08:00
|
|
|
item1->setPosition(ccp( s.width/2 - item2->getContentSize().width*2, item2->getContentSize().height/2));
|
|
|
|
item2->setPosition(ccp( s.width/2, item2->getContentSize().height/2));
|
|
|
|
item3->setPosition(ccp( s.width/2 + item2->getContentSize().width*2, item2->getContentSize().height/2));
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(menu, 1);
|
2011-07-29 15:57:27 +08:00
|
|
|
|
|
|
|
showFont(restartAction());
|
|
|
|
}
|
|
|
|
|
|
|
|
void FontTest::showFont(const char *pFont)
|
|
|
|
{
|
2012-06-15 15:10:40 +08:00
|
|
|
CCSize s = CCDirector::sharedDirector()->getWinSize();
|
|
|
|
|
|
|
|
CCSize blockSize = CCSizeMake(s.width/3, 200);
|
2012-06-12 11:16:31 +08:00
|
|
|
CCFloat fontSize = 26;
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
removeChildByTag(kTagLabel1, true);
|
|
|
|
removeChildByTag(kTagLabel2, true);
|
|
|
|
removeChildByTag(kTagLabel3, true);
|
|
|
|
removeChildByTag(kTagLabel4, true);
|
|
|
|
|
2012-06-15 15:10:40 +08:00
|
|
|
CCLabelTTF *top = CCLabelTTF::create(pFont, pFont, 24);
|
2012-08-01 13:24:23 +08:00
|
|
|
CCLabelTTF *left = CCLabelTTF::create("alignment left", pFont, fontSize,
|
|
|
|
blockSize, kCCTextAlignmentLeft, verticalAlignment[vAlignIdx]);
|
|
|
|
CCLabelTTF *center = CCLabelTTF::create("alignment center", pFont, fontSize,
|
|
|
|
blockSize, kCCTextAlignmentCenter, verticalAlignment[vAlignIdx]);
|
|
|
|
CCLabelTTF *right = CCLabelTTF::create("alignment right", pFont, fontSize,
|
|
|
|
blockSize, kCCTextAlignmentRight, verticalAlignment[vAlignIdx]);
|
2012-06-15 15:10:40 +08:00
|
|
|
|
|
|
|
CCLayerColor *leftColor = CCLayerColor::create(ccc4(100, 100, 100, 255), blockSize.width, blockSize.height);
|
|
|
|
CCLayerColor *centerColor = CCLayerColor::create(ccc4(200, 100, 100, 255), blockSize.width, blockSize.height);
|
|
|
|
CCLayerColor *rightColor = CCLayerColor::create(ccc4(100, 100, 200, 255), blockSize.width, blockSize.height);
|
|
|
|
|
|
|
|
leftColor->ignoreAnchorPointForPosition(false);
|
|
|
|
centerColor->ignoreAnchorPointForPosition(false);
|
|
|
|
rightColor->ignoreAnchorPointForPosition(false);
|
|
|
|
|
|
|
|
|
|
|
|
top->setAnchorPoint(ccp(0.5, 1));
|
|
|
|
left->setAnchorPoint(ccp(0,0.5));
|
|
|
|
leftColor->setAnchorPoint(ccp(0,0.5));
|
|
|
|
center->setAnchorPoint(ccp(0,0.5));
|
|
|
|
centerColor->setAnchorPoint(ccp(0,0.5));
|
|
|
|
right->setAnchorPoint(ccp(0,0.5));
|
|
|
|
rightColor->setAnchorPoint(ccp(0,0.5));
|
|
|
|
|
|
|
|
top->setPosition(ccp(s.width/2,s.height-20));
|
|
|
|
left->setPosition(ccp(0,s.height/2));
|
|
|
|
leftColor->setPosition(left->getPosition());
|
|
|
|
center->setPosition(ccp(blockSize.width, s.height/2));
|
|
|
|
centerColor->setPosition(center->getPosition());
|
|
|
|
right->setPosition(ccp(blockSize.width*2, s.height/2));
|
|
|
|
rightColor->setPosition(right->getPosition());
|
|
|
|
|
|
|
|
this->addChild(leftColor, -1);
|
|
|
|
this->addChild(left, 0, kTagLabel1);
|
|
|
|
this->addChild(rightColor, -1);
|
|
|
|
this->addChild(right, 0, kTagLabel2);
|
|
|
|
this->addChild(centerColor, -1);
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
void FontTest::backCallback(CCObject* pSender)
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
showFont(backAction());
|
2011-07-29 15:57:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void FontTest::nextCallback(CCObject* pSender)
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
showFont(nextAction());
|
2011-07-29 15:57:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string FontTest::title()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return "Font test";
|
2011-07-29 15:57:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void FontTest::restartCallback(CCObject* pSender)
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
showFont(restartAction());
|
2011-07-29 15:57:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
///---------------------------------------
|
|
|
|
//
|
|
|
|
// DirectorTestScene
|
|
|
|
//
|
|
|
|
///---------------------------------------
|
|
|
|
void FontTestScene::runThisTest()
|
|
|
|
{
|
2012-06-14 15:13:16 +08:00
|
|
|
CCLayer* pLayer = FontTest::create();
|
2012-04-19 14:35:52 +08:00
|
|
|
addChild(pLayer);
|
2011-07-29 15:57:27 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
CCDirector::sharedDirector()->replaceScene(this);
|
2011-07-29 15:57:27 +08:00
|
|
|
}
|