Clean up for the new Label stuff

This commit is contained in:
carlo morgantini 2013-08-01 11:02:32 -07:00
parent ba4a48ec7a
commit 972ae78295
2 changed files with 13 additions and 41 deletions

View File

@ -91,7 +91,7 @@ bool FontDefinitionTTF::prepareLetterDefinitions(TextFontPagesDef *pageDefs)
float letterHeight = pPages->getPageAt(cPages)->getLineAt(cLines)->getHeight();
// add this letter definition
LetterDefinition tempDef;
FontLetterDefinition tempDef;
// carloX little hack (this should be done outside the loop)
@ -174,7 +174,7 @@ bool FontDefinitionTTF::initDefinition(const char *fontName, int fontSize, const
return prepareLetterDefinitions(_textImages->getPages());
}
void FontDefinitionTTF::addLetterDefinition(LetterDefinition &defToAdd)
void FontDefinitionTTF::addLetterDefinition(FontLetterDefinition &defToAdd)
{
if (_fontLettersDefinitionUTF16.find(defToAdd.letteCharUTF16) == _fontLettersDefinitionUTF16.end())
{
@ -182,7 +182,7 @@ void FontDefinitionTTF::addLetterDefinition(LetterDefinition &defToAdd)
}
}
LetterDefinition & FontDefinitionTTF::getLetterDefinition(unsigned short int theLetter)
FontLetterDefinition & FontDefinitionTTF::getLetterDefinition(unsigned short int theLetter)
{
return _fontLettersDefinitionUTF16[theLetter];
}
@ -226,30 +226,17 @@ FontAtlas * FontDefinitionTTF::createFontAtlas()
// set the common line height
retAtlas->setCommonLineHeight(getCommonLineHeight() * 0.8);
// add all the letter definitions
std::map<unsigned short, LetterDefinition>::iterator ITER;
for(ITER = _fontLettersDefinitionUTF16.begin(); ITER!=_fontLettersDefinitionUTF16.end(); ++ITER)
{
FontLetterDefinition tempDefinition;
tempDefinition.letteCharUTF16 = (*ITER).second.letteCharUTF16;
tempDefinition.validDefinition = (*ITER).second.validDefinition;
if (tempDefinition.validDefinition)
for( auto &item: _fontLettersDefinitionUTF16 )
{
tempDefinition.U = (*ITER).second.U;
tempDefinition.V = (*ITER).second.V;
tempDefinition.width = (*ITER).second.width;
tempDefinition.height = (*ITER).second.height;
// carloX not useed here tempDefinition.offsetX = (*ITER).second.offsetX;
if ( item.second.validDefinition )
{
FontLetterDefinition tempDefinition = item.second;
tempDefinition.offsetX = 0;
tempDefinition.offsetY = (*ITER).second.offsetY;
tempDefinition.textureID = (*ITER).second.textureID;
tempDefinition.commonLineHeight = (*ITER).second.commonLineHeight;
tempDefinition.anchorX = 0.0f;
tempDefinition.anchorY = 1.0f;
retAtlas->addLetterDefinition(tempDefinition);
}
}
// done here

View File

@ -31,23 +31,8 @@
NS_CC_BEGIN
#define DEFAULT_ATLAS_TEXTURE_SIZE 1024
struct LetterDefinition
{
unsigned short letteCharUTF16;
float U;
float V;
float width;
float height;
float offsetX;
float offsetY;
int textureID;
float commonLineHeight;
bool validDefinition;
};
/**
*/
class CC_DLL FontDefinitionTTF : public Object
@ -55,7 +40,7 @@ class CC_DLL FontDefinitionTTF : public Object
public:
static FontDefinitionTTF* create(const char *fontName, int fontSize, const char *letters, int textureSize = DEFAULT_ATLAS_TEXTURE_SIZE);
LetterDefinition & getLetterDefinition(unsigned short int theLetter);
FontLetterDefinition & getLetterDefinition(unsigned short int theLetter);
Texture2D * getTexture(int index);
int getNumTextures();
Font * getFont() { return _textImages->getFont(); }
@ -69,10 +54,10 @@ private:
bool initDefinition(const char *fontName, int fontSize, const char *letters, int textureSize);
bool prepareLetterDefinitions(TextFontPagesDef *pageDefs);
void addLetterDefinition(LetterDefinition &defToAdd);
void addLetterDefinition(FontLetterDefinition &defToAdd);
TextImage * _textImages;
std::map<unsigned short, LetterDefinition> _fontLettersDefinitionUTF16;
std::map<unsigned short, FontLetterDefinition> _fontLettersDefinitionUTF16;
float _commonLineHeight;
};