mirror of https://github.com/axmolengine/axmol.git
alignment added to new label creation
This commit is contained in:
parent
d15d84c05f
commit
35b5e30190
|
@ -30,7 +30,7 @@
|
|||
|
||||
NS_CC_BEGIN
|
||||
|
||||
Label* Label::createWithTTF( const char* label, const char* fontFilePath, int fontSize, int lineSize, GlyphCollection glyphs, const char *customGlyphs )
|
||||
Label* Label::createWithTTF( const char* label, const char* fontFilePath, int fontSize, int lineSize, TextHAlignment alignment, GlyphCollection glyphs, const char *customGlyphs )
|
||||
{
|
||||
|
||||
FontAtlas *tempAtlas = FontAtlasCache::getFontAtlasTTF(fontFilePath, fontSize, glyphs, customGlyphs);
|
||||
|
@ -38,11 +38,11 @@ Label* Label::createWithTTF( const char* label, const char* fontFilePath, int fo
|
|||
return nullptr;
|
||||
|
||||
// create the actual label
|
||||
Label* templabel = Label::create(tempAtlas, TextHAlignment::CENTER, lineSize);
|
||||
Label* templabel = Label::create(tempAtlas, alignment, lineSize);
|
||||
|
||||
if (templabel)
|
||||
{
|
||||
templabel->setText(label, lineSize, TextHAlignment::CENTER, false);
|
||||
templabel->setText(label, lineSize, alignment, false);
|
||||
return templabel;
|
||||
}
|
||||
|
||||
|
|
|
@ -51,7 +51,7 @@ class CC_DLL Label : public SpriteBatchNode, public LabelProtocol, public RGBAPr
|
|||
{
|
||||
public:
|
||||
|
||||
static Label* createWithTTF( const char* label, const char* fontFilePath, int fontSize, int lineSize = 0, GlyphCollection glyphs = GlyphCollection::NEHE, const char *customGlyphs = 0 );
|
||||
static Label* createWithTTF( const char* label, const char* fontFilePath, int fontSize, int lineSize = 0, TextHAlignment alignment = TextHAlignment::CENTER, GlyphCollection glyphs = GlyphCollection::NEHE, const char *customGlyphs = 0 );
|
||||
static Label* createWithBMFont( const char* label, const char* bmfontFilePath, TextHAlignment alignment = TextHAlignment::CENTER, int lineSize = 0 );
|
||||
|
||||
Label(FontAtlas *pAtlas, TextHAlignment alignment);
|
||||
|
|
|
@ -505,7 +505,7 @@ LabelFNTandTTFEmpty::LabelFNTandTTFEmpty()
|
|||
label1->setPosition(Point(s.width/2, delta));
|
||||
|
||||
// LabelTTF
|
||||
Label* label2 = Label::createWithTTF("", "fonts/arial.ttf", 48, s.width, GlyphCollection::NEHE);
|
||||
Label* label2 = Label::createWithTTF("", "fonts/arial.ttf", 48, s.width, TextHAlignment::CENTER,GlyphCollection::NEHE);
|
||||
addChild(label2, 0, kTagBitmapAtlas2);
|
||||
label2->setAnchorPoint(Point(0.5f, 0.5f));
|
||||
label2->setPosition(Point(s.width/2, delta * 2));
|
||||
|
@ -596,7 +596,7 @@ std::string LabelFNTGlyphDesigner::subtitle()
|
|||
LabelTTFUnicodeChinese::LabelTTFUnicodeChinese()
|
||||
{
|
||||
auto size = Director::getInstance()->getWinSize();
|
||||
auto label = Label::createWithTTF("美好的-天", "fonts/wt021.ttf", 55, size.width, GlyphCollection::CUSTOM, "美好的-天");
|
||||
auto label = Label::createWithTTF("美好的-天", "fonts/wt021.ttf", 55, size.width, TextHAlignment::CENTER, GlyphCollection::CUSTOM, "美好的-天");
|
||||
label->setAnchorPoint(Point(0.5f, 0.5f));
|
||||
label->setPosition(Point(size.width / 2, size.height /2));
|
||||
this->addChild(label);
|
||||
|
@ -660,8 +660,8 @@ LabelFNTMultiLineAlignment::LabelFNTMultiLineAlignment()
|
|||
Size size = Director::getInstance()->getWinSize();
|
||||
|
||||
// create and initialize a Label
|
||||
//this->_labelShouldRetain = Label::createWithBMFont(LongSentencesExample, "fonts/markerFelt.fnt", size.width/1.5);
|
||||
this->_labelShouldRetain = Label::createWithBMFont(LongSentencesExample, "fonts/bitmapFontTest.fnt", TextHAlignment::CENTER, size.width/1.5);
|
||||
this->_labelShouldRetain = Label::createWithBMFont(LongSentencesExample, "fonts/markerFelt.fnt", TextHAlignment::CENTER, size.width/1.5);
|
||||
//this->_labelShouldRetain = Label::createWithBMFont(LongSentencesExample, "fonts/bitmapFontTest.fnt", TextHAlignment::CENTER, size.width/1.5);
|
||||
this->_labelShouldRetain->setAnchorPoint(Point(0.5f, 0.5f));
|
||||
this->_labelShouldRetain->retain();
|
||||
|
||||
|
@ -923,7 +923,7 @@ LabelTTFLongLineWrapping::LabelTTFLongLineWrapping()
|
|||
Size size = Director::getInstance()->getWinSize();
|
||||
|
||||
// Long sentence
|
||||
auto label1 = Label::createWithTTF(LongSentencesExample, "fonts/arial.ttf", 28, size.width, GlyphCollection::NEHE);
|
||||
auto label1 = Label::createWithTTF(LongSentencesExample, "fonts/arial.ttf", 28, size.width, TextHAlignment::CENTER, GlyphCollection::NEHE);
|
||||
label1->setPosition( Point(size.width/2, size.height/2) );
|
||||
label1->setAnchorPoint(Point(0.5, 1.0));
|
||||
addChild(label1);
|
||||
|
@ -944,21 +944,21 @@ LabelTTFColor::LabelTTFColor()
|
|||
Size size = Director::getInstance()->getWinSize();
|
||||
|
||||
// Green
|
||||
auto label1 = Label::createWithTTF("Green", "fonts/arial.ttf", 35, size.width, GlyphCollection::NEHE);
|
||||
auto label1 = Label::createWithTTF("Green", "fonts/arial.ttf", 35, size.width, TextHAlignment::CENTER, GlyphCollection::NEHE);
|
||||
label1->setPosition( Point(size.width/2, size.height/5 * 1.5) );
|
||||
label1->setColor( Color3B::GREEN );
|
||||
label1->setAnchorPoint(Point(0.5, 0.5));
|
||||
addChild(label1);
|
||||
|
||||
// Red
|
||||
auto label2 = Label::createWithTTF("Red", "fonts/arial.ttf", 35, size.width, GlyphCollection::NEHE);
|
||||
auto label2 = Label::createWithTTF("Red", "fonts/arial.ttf", 35, size.width, TextHAlignment::CENTER, GlyphCollection::NEHE);
|
||||
label2->setPosition( Point(size.width/2, size.height/5 * 2.0) );
|
||||
label2->setColor( Color3B::RED );
|
||||
label2->setAnchorPoint(Point(0.5, 0.5));
|
||||
addChild(label2);
|
||||
|
||||
// Blue
|
||||
auto label3 = Label::createWithTTF("Blue", "fonts/arial.ttf", 35, size.width, GlyphCollection::NEHE);
|
||||
auto label3 = Label::createWithTTF("Blue", "fonts/arial.ttf", 35, size.width, TextHAlignment::CENTER, GlyphCollection::NEHE);
|
||||
label3->setPosition( Point(size.width/2, size.height/5 * 2.5) );
|
||||
label3->setColor( Color3B::BLUE );
|
||||
label3->setAnchorPoint(Point(0.5, 0.5));
|
||||
|
@ -979,7 +979,7 @@ LabelTTFDynamicAlignment::LabelTTFDynamicAlignment()
|
|||
{
|
||||
Size size = Director::getInstance()->getWinSize();
|
||||
|
||||
_label = Label::createWithTTF(LongSentencesExample, "fonts/arial.ttf", 45, size.width, GlyphCollection::NEHE);
|
||||
_label = Label::createWithTTF(LongSentencesExample, "fonts/arial.ttf", 45, size.width, TextHAlignment::CENTER, GlyphCollection::NEHE);
|
||||
_label->setPosition( Point(size.width/2, size.height/2) );
|
||||
_label->setAnchorPoint(Point(0.5, 0.5));
|
||||
|
||||
|
@ -1053,19 +1053,19 @@ LabelTTFUnicodeNew::LabelTTFUnicodeNew()
|
|||
|
||||
|
||||
// Spanish
|
||||
auto label1 = Label::createWithTTF("Buen día, ¿cómo te llamas?", "fonts/arial.ttf", 45, size.width, GlyphCollection::ASCII);
|
||||
auto label1 = Label::createWithTTF("Buen día, ¿cómo te llamas?", "fonts/arial.ttf", 45, size.width, TextHAlignment::CENTER, GlyphCollection::ASCII);
|
||||
label1->setPosition( Point(size.width/2, vSize - (vStep * 4.5)) );
|
||||
label1->setAnchorPoint(Point(0.5, 0.5));
|
||||
addChild(label1);
|
||||
|
||||
// German
|
||||
auto label2 = Label::createWithTTF("In welcher Straße haben Sie gelebt?", "fonts/arial.ttf", 45, size.width, GlyphCollection::ASCII);
|
||||
auto label2 = Label::createWithTTF("In welcher Straße haben Sie gelebt?", "fonts/arial.ttf", 45, size.width, TextHAlignment::CENTER, GlyphCollection::ASCII);
|
||||
label2->setPosition( Point(size.width/2, vSize - (vStep * 5.5)) );
|
||||
label2->setAnchorPoint(Point(0.5, 0.5));
|
||||
addChild(label2);
|
||||
|
||||
// chinese
|
||||
auto label3 = Label::createWithTTF(chinese, "fonts/wt021.ttf", 45, size.width, GlyphCollection::CUSTOM, chinese);
|
||||
auto label3 = Label::createWithTTF(chinese, "fonts/wt021.ttf", 45, size.width, TextHAlignment::CENTER, GlyphCollection::CUSTOM, chinese);
|
||||
label3->setPosition( Point(size.width/2, vSize - (vStep * 6.5)) );
|
||||
label3->setAnchorPoint(Point(0.5, 0.5));
|
||||
addChild(label3);
|
||||
|
@ -1097,7 +1097,7 @@ LabelTTFFontsTestNew::LabelTTFFontsTestNew()
|
|||
Size size = Director::getInstance()->getWinSize();
|
||||
|
||||
for(int i=0;i < arraysize(ttfpaths); ++i) {
|
||||
auto label = Label::createWithTTF( ttfpaths[i], ttfpaths[i], 40, 0, GlyphCollection::NEHE);
|
||||
auto label = Label::createWithTTF( ttfpaths[i], ttfpaths[i], 40, 0, TextHAlignment::CENTER, GlyphCollection::NEHE);
|
||||
if( label ) {
|
||||
|
||||
label->setPosition( Point(size.width/2, ((size.height * 0.6)/arraysize(ttfpaths) * i) + (size.height/5)));
|
||||
|
|
Loading…
Reference in New Issue