2013-07-20 01:33:26 +08:00
|
|
|
//
|
|
|
|
// CCFontAtlas.cpp
|
|
|
|
// cocos2d_libs
|
|
|
|
//
|
|
|
|
// Created by Carlo Morgantini on 7/18/13.
|
|
|
|
//
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "cocos2d.h"
|
|
|
|
#include "CCFontAtlas.h"
|
2013-07-25 01:22:46 +08:00
|
|
|
#include "CCFont.h"
|
2013-07-20 01:33:26 +08:00
|
|
|
|
|
|
|
NS_CC_BEGIN
|
|
|
|
|
|
|
|
std::map<int, FontLetterDefinition> _atlasTextures;
|
|
|
|
std::map<unsigned short, FontLetterDefinition> _fontLettersDefinition;
|
|
|
|
|
|
|
|
|
2013-07-25 01:22:46 +08:00
|
|
|
FontAtlas::FontAtlas(Font *theFont) : _font(theFont)
|
|
|
|
{
|
2013-07-26 08:58:13 +08:00
|
|
|
if (_font)
|
|
|
|
_font->retain();
|
2013-07-25 01:22:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
FontAtlas::~FontAtlas()
|
|
|
|
{
|
|
|
|
_font->release();
|
|
|
|
relaseTextures();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FontAtlas::relaseTextures()
|
|
|
|
{
|
|
|
|
for( auto &item: _atlasTextures)
|
|
|
|
{
|
2013-08-06 07:41:23 +08:00
|
|
|
item.second->release();
|
2013-07-25 01:22:46 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-20 01:33:26 +08:00
|
|
|
void FontAtlas::addLetterDefinition(FontLetterDefinition &letterDefinition)
|
|
|
|
{
|
|
|
|
_fontLetterDefinitions[letterDefinition.letteCharUTF16] = letterDefinition;
|
|
|
|
}
|
|
|
|
|
2013-07-30 04:43:23 +08:00
|
|
|
FontLetterDefinition * FontAtlas::getLetterDefinitionForChar(unsigned short letteCharUTF16)
|
2013-07-20 01:33:26 +08:00
|
|
|
{
|
2013-07-30 04:43:23 +08:00
|
|
|
auto outIterator = _fontLetterDefinitions.find(letteCharUTF16);
|
|
|
|
if (outIterator != _fontLetterDefinitions.end())
|
|
|
|
{
|
|
|
|
return & (*outIterator).second;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2013-07-20 01:33:26 +08:00
|
|
|
}
|
|
|
|
|
2013-08-06 07:41:23 +08:00
|
|
|
void FontAtlas::addTexture(Texture2D *texture, int slot)
|
2013-07-20 01:33:26 +08:00
|
|
|
{
|
2013-08-06 07:41:23 +08:00
|
|
|
texture->retain();
|
2013-08-06 07:35:15 +08:00
|
|
|
_atlasTextures[slot] = texture;
|
2013-07-20 01:33:26 +08:00
|
|
|
}
|
|
|
|
|
2013-08-06 07:41:23 +08:00
|
|
|
Texture2D * FontAtlas::getTexture(int slot)
|
2013-07-20 01:33:26 +08:00
|
|
|
{
|
|
|
|
return _atlasTextures[slot];
|
|
|
|
}
|
|
|
|
|
2013-07-25 01:22:46 +08:00
|
|
|
float FontAtlas::getCommonLineHeight()
|
|
|
|
{
|
|
|
|
return _commonLineHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FontAtlas::setCommonLineHeight(float newHeight)
|
|
|
|
{
|
|
|
|
_commonLineHeight = newHeight;
|
|
|
|
}
|
|
|
|
|
|
|
|
Font * FontAtlas::getFont()
|
|
|
|
{
|
|
|
|
return _font;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-07-20 01:33:26 +08:00
|
|
|
NS_CC_END
|