working on the new label stuff

This commit is contained in:
carlo morgantini 2013-07-22 14:43:45 -07:00
parent 98c52cd98d
commit 98bb0c26f3
5 changed files with 24 additions and 47 deletions

View File

@ -30,21 +30,30 @@
NS_CC_BEGIN
Label* Label::createWithTTF( const char* label, const char* tttFilePath, int size, GlyphCollection glyphs )
Label* Label::createWithTTF( const char* label, const char* tttFilePath, int fontSize, GlyphCollection glyphs, int lineSize )
{
FontDefinitionTTF *def = CCFontCache::getFontDefinition(tttFilePath, size, glyphs);
FontDefinitionTTF *def = CCFontCache::getFontDefinition(tttFilePath, fontSize, glyphs);
if(!def)
return 0;
StringTTF* l = StringTTF::create(def);
l->setString( label );
return l;
StringTTF* templabel = StringTTF::create(def, kTextAlignmentCenter, lineSize);
if ( templabel )
{
templabel->setText(label, lineSize, kTextAlignmentCenter, false);
return templabel;
}
else
{
CCFontCache::purgeUnusedFonts();
return 0;
}
}
Label* Label::createWithBMFont( const char* label, const char* bmfontFilePath )
Label* Label::createWithBMFont( const char* label, const char* bmfontFilePath, int lineSize )
{
return LabelBMFontNew::create(label, bmfontFilePath);
return LabelBMFontNew::create(label, bmfontFilePath, lineSize);
}
Label::Label()

View File

@ -41,43 +41,12 @@ enum class GlyphCollection {
class CC_DLL Label : public SpriteBatchNode, public LabelProtocol, public RGBAProtocol
{
public:
static Label* createWithTTF( const char* label, const char* tttFilePath, int size, GlyphCollection glyphs = GlyphCollection::NEHE );
static Label* createWithBMFont( const char* label, const char* bmfontFilePath );
static Label* createWithTTF( const char* label, const char* tttFilePath, int fontSize, GlyphCollection glyphs = GlyphCollection::NEHE, int lineSize = 0 );
static Label* createWithBMFont( const char* label, const char* bmfontFilePath, int lineSize = 0 );
virtual ~Label();
Label();
// bool initWithTTF( const char* label, const char* tttFilePath, int size, GlyphCollection glyphs = GlyphCollection::NEHE );
// bool initWithBMFont( const char* label, const char* bmfontFilePath );
// UTF-8 collection
// void setGlyphCollection( const char* glyphCollection );
// virtual void setHorizontalAlignment(TextAlignment alignment);
// virtual void setVerticalAlignment(VerticalTextAlignment alignment);
// virtual void setLineBreakWithoutSpace(bool breakWithoutSpace);
// // Overrides
// virtual void setString(const char *newString) override;
// virtual const char* getString(void) const override;
// virtual bool isOpacityModifyRGB() const override;
// virtual void setOpacityModifyRGB(bool isOpacityModifyRGB) override;
// virtual GLubyte getOpacity() const override;
// virtual GLubyte getDisplayedOpacity() const override;
// virtual void setOpacity(GLubyte opacity) override;
// virtual void updateDisplayedOpacity(GLubyte parentOpacity) override;
// virtual bool isCascadeOpacityEnabled() const override;
// virtual void setCascadeOpacityEnabled(bool cascadeOpacityEnabled) override;
// virtual const Color3B& getColor(void) const override;
// virtual const Color3B& getDisplayedColor() const override;
// virtual void setColor(const Color3B& color) override;
// virtual void updateDisplayedColor(const Color3B& parentColor) override;
// virtual bool isCascadeColorEnabled() const override;
// virtual void setCascadeColorEnabled(bool cascadeColorEnabled) override;
protected:
private:
};
NS_CC_END

View File

@ -39,7 +39,7 @@ StringTTF::StringTTF(FontDefinitionTTF *theDef, TextAlignment alignment) : _cu
_fontDef->retain();
}
StringTTF* StringTTF::create(FontDefinitionTTF *def, TextAlignment alignment)
StringTTF* StringTTF::create(FontDefinitionTTF *def, TextAlignment alignment, int lineSize )
{
StringTTF *ret = new StringTTF(def, alignment);

View File

@ -35,7 +35,7 @@ class StringTTF : public Label, public LabelTextFormatProtocol
{
public:
static StringTTF* create(FontDefinitionTTF *pDefinition, TextAlignment alignment = kTextAlignmentLeft);
static StringTTF* create(FontDefinitionTTF *pDefinition, TextAlignment alignment = kTextAlignmentLeft, int lineSize = 0);
// main interface
bool setText(const char *stringToRender, float lineWidth, TextAlignment alignment = kTextAlignmentLeft, bool lineBreakWithoutSpaces = false);

View File

@ -1701,8 +1701,7 @@ std::string LabelDyamicTest::subtitle()
NewLabelTTFTest::NewLabelTTFTest()
{
Size size = Director::getInstance()->getWinSize();
label = Label::createWithTTF("Hello World", "fonts/arial.ttf", 28, GlyphCollection::NEHE);
label = Label::createWithTTF(LongSentencesExample, "fonts/arial.ttf", 28, GlyphCollection::NEHE, size.width);
label->setPosition( Point(size.width/2, size.height/2) );
label->setAnchorPoint(Point(0.5, 1.0));
label->retain();
@ -1731,7 +1730,7 @@ NewLabelBMFontTest::NewLabelBMFontTest()
{
Size size = Director::getInstance()->getWinSize();
label = Label::createWithBMFont("Hello World", "fonts/bitmapFontTest2.fnt");
label = Label::createWithBMFont("Hello World, this is testing the new Label using fnt file", "fonts/bitmapFontTest2.fnt", size.width);
label->setPosition( Point(size.width/2, size.height/2) );
label->retain();
addChild(label);