mirror of https://github.com/axmolengine/axmol.git
parent
45f9edcdc3
commit
f9268c8054
|
@ -12,25 +12,19 @@
|
|||
NS_CC_BEGIN
|
||||
|
||||
|
||||
LabelFontDefinition::LabelFontDefinition():_textImages(0), _commonLineHeight(0)
|
||||
LabelFontDefinition* LabelFontDefinition::create(const char *fontName, int fontSize, const char *letters, int textureSize, bool debugOutput)
|
||||
{
|
||||
LabelFontDefinition *ret = new LabelFontDefinition;
|
||||
ret->init( fontName, fontSize, letters, textureSize, debugOutput);
|
||||
return ret;
|
||||
}
|
||||
|
||||
LabelFontDefinition::~LabelFontDefinition()
|
||||
{
|
||||
if (_textImages)
|
||||
{
|
||||
delete _textImages;
|
||||
}
|
||||
}
|
||||
|
||||
bool LabelFontDefinition::createFontDefinition(char *fontName, int fontSize, char *letters, int textureSize, bool debugOutput)
|
||||
{
|
||||
bool LabelFontDefinition::init(const char *fontName, int fontSize, const char *letters, int textureSize, bool debugOutput)
|
||||
{
|
||||
// constants
|
||||
float LINE_PADDING = 1.9;
|
||||
float PIXEL_PADDING = 1.0;
|
||||
|
||||
|
||||
|
||||
// preare texture/image stuff
|
||||
_textImages = new TextImage();
|
||||
if (!_textImages)
|
||||
|
@ -116,6 +110,18 @@ bool LabelFontDefinition::createFontDefinition(char *fontName, int fontSize, cha
|
|||
return true;
|
||||
}
|
||||
|
||||
LabelFontDefinition::LabelFontDefinition():_textImages(0), _commonLineHeight(0)
|
||||
{
|
||||
}
|
||||
|
||||
LabelFontDefinition::~LabelFontDefinition()
|
||||
{
|
||||
if (_textImages)
|
||||
{
|
||||
delete _textImages;
|
||||
}
|
||||
}
|
||||
|
||||
void LabelFontDefinition::addLetterDef(LetterDefinition &defToAdd)
|
||||
{
|
||||
if (_fontLettersDefinitionUTF8.find(defToAdd.letteCharUTF8) == _fontLettersDefinitionUTF8.end())
|
||||
|
|
|
@ -43,18 +43,25 @@ struct LetterDefinition
|
|||
float commonLineHeight;
|
||||
};
|
||||
|
||||
/**
|
||||
*/
|
||||
class LabelFontDefinition
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
static LabelFontDefinition* create(const char *fontName, int fontSize, const char *letters, int textureSize = 512, bool debugOutput = false);
|
||||
|
||||
LabelFontDefinition();
|
||||
~LabelFontDefinition();
|
||||
|
||||
bool init(const char *fontName, int fontSize, const char *letters, int textureSize, bool debugOutput);
|
||||
|
||||
|
||||
bool createFontDefinition(char *fontName, int fontSize, char *letters, int textureSize = 512, bool debugOutput = false);
|
||||
LetterDefinition & getLetterDefinition(unsigned short int theLetter);
|
||||
Texture2D * getTexture(int index);
|
||||
Font * getFont() { return _textImages->getFont(); }
|
||||
float getCommonLineHeight() { return _commonLineHeight; }
|
||||
|
||||
Font * getFont() { return _textImages->getFont(); }
|
||||
float getCommonLineHeight() const { return _commonLineHeight; }
|
||||
|
||||
private:
|
||||
|
||||
|
|
|
@ -12,11 +12,20 @@
|
|||
|
||||
NS_CC_BEGIN
|
||||
|
||||
StringTTF::StringTTF(LabelFontDefinition *theDef, TextAlignment alignment) : _currentUTF8String(0),
|
||||
_fontDef(theDef),
|
||||
_alignment(alignment),
|
||||
_lineBreakWithoutSpaces(false),
|
||||
_advances(0)
|
||||
StringTTF* StringTTF::create(LabelFontDefinition *def, TextAlignment alignment)
|
||||
{
|
||||
StringTTF *ret = new StringTTF(def, alignment);
|
||||
if( ! ret->init() )
|
||||
return NULL;
|
||||
return ret;
|
||||
}
|
||||
|
||||
StringTTF::StringTTF(LabelFontDefinition *theDef, TextAlignment alignment) :
|
||||
_currentUTF8String(0),
|
||||
_fontDef(theDef),
|
||||
_alignment(alignment),
|
||||
_lineBreakWithoutSpaces(false),
|
||||
_advances(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -35,7 +44,12 @@ StringTTF::~StringTTF()
|
|||
}
|
||||
}
|
||||
|
||||
bool StringTTF::setText(char *pStringToRender, float lineWidth, TextAlignment alignment, bool lineBreakWithoutSpaces)
|
||||
bool StringTTF::init()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool StringTTF::setText(const char *stringToRender, float lineWidth, TextAlignment alignment, bool lineBreakWithoutSpaces)
|
||||
{
|
||||
if (!_fontDef)
|
||||
return false;
|
||||
|
@ -59,7 +73,7 @@ bool StringTTF::setText(char *pStringToRender, float lineWidth, TextAlignment al
|
|||
return false;
|
||||
|
||||
int numLetter = 0;
|
||||
unsigned short int *pUTF8Text = pFont->getUTF8Text(pStringToRender, numLetter);
|
||||
unsigned short int *pUTF8Text = pFont->getUTF8Text(stringToRender, numLetter);
|
||||
setCurrentString(pUTF8Text);
|
||||
|
||||
// align text
|
||||
|
|
|
@ -34,11 +34,14 @@ NS_CC_BEGIN
|
|||
class StringTTF : public Node , public LabelTextFormatProtocol, public RGBAProtocol
|
||||
{
|
||||
public:
|
||||
|
||||
static StringTTF* create(LabelFontDefinition *pDefinition, TextAlignment alignment = kTextAlignmentLeft);
|
||||
|
||||
StringTTF(LabelFontDefinition *pDefinition, TextAlignment alignment = kTextAlignmentLeft);
|
||||
~StringTTF();
|
||||
|
||||
bool init();
|
||||
|
||||
bool setText(char *pStringToRender, float lineWidth, TextAlignment alignment = kTextAlignmentLeft, bool lineBreakWithoutSpaces = false);
|
||||
bool setText(const char *pStringToRender, float lineWidth, TextAlignment alignment = kTextAlignmentLeft, bool lineBreakWithoutSpaces = false);
|
||||
|
||||
// main interface
|
||||
virtual void setAlignment(TextAlignment alignment);
|
||||
|
|
|
@ -1659,13 +1659,13 @@ LabelDyamicTest::LabelDyamicTest()
|
|||
{
|
||||
Size size = Director::sharedDirector()->getWinSize();
|
||||
|
||||
const char *pFontName = "MarkerFelt-Thin";
|
||||
const char *pFontGlyphs = "abcdefghilmnopqrstuvzxywABCDEFGHILMNOPQRSTUVZXYW0123456789,. ";
|
||||
LabelFontDefinition *pDef = new LabelFontDefinition;
|
||||
const char *fontName = "MarkerFelt-Thin";
|
||||
const char *fontGlyphs = "abcdefghilmnopqrstuvzxywABCDEFGHILMNOPQRSTUVZXYW0123456789,. ";
|
||||
|
||||
LabelFontDefinition *def= LabelFontDefinition::create(fontName, 30, fontGlyphs);
|
||||
|
||||
pDef->createFontDefinition((char *)pFontName, 30, (char *) pFontGlyphs);
|
||||
StringTTF *pTestString = new StringTTF(pDef);
|
||||
pTestString->setText( (char *)LongSentencesExample, size.width, kTextAlignmentCenter, false);
|
||||
StringTTF *pTestString = StringTTF::create(def);
|
||||
pTestString->setText( LongSentencesExample, size.width, kTextAlignmentCenter, false);
|
||||
addChild(pTestString);
|
||||
|
||||
pTestString->setPosition(Point(0, size.height/2));
|
||||
|
|
Loading…
Reference in New Issue