axmol/cocos/2d/CCFontAtlas.cpp

80 lines
1.4 KiB
C++
Raw Normal View History

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"
#include "CCFont.h"
2013-07-20 01:33:26 +08:00
NS_CC_BEGIN
2013-08-06 08:49:20 +08:00
FontAtlas::FontAtlas(Font &theFont) : _font(theFont)
{
2013-08-06 08:49:20 +08:00
_font.retain();
}
FontAtlas::~FontAtlas()
{
2013-08-06 08:49:20 +08:00
_font.release();
relaseTextures();
}
void FontAtlas::relaseTextures()
{
for( auto &item: _atlasTextures)
{
2013-08-06 07:41:23 +08:00
item.second->release();
}
}
2013-08-06 08:49:20 +08:00
void FontAtlas::addLetterDefinition(const FontLetterDefinition &letterDefinition)
2013-07-20 01:33:26 +08:00
{
_fontLetterDefinitions[letterDefinition.letteCharUTF16] = letterDefinition;
}
2013-08-06 08:49:20 +08:00
bool FontAtlas::getLetterDefinitionForChar(unsigned short letteCharUTF16, FontLetterDefinition &outDefinition)
2013-07-20 01:33:26 +08:00
{
auto outIterator = _fontLetterDefinitions.find(letteCharUTF16);
2013-08-06 08:49:20 +08:00
if (outIterator != _fontLetterDefinitions.end())
{
2013-08-06 08:49:20 +08:00
outDefinition = (*outIterator).second;
return true;
}
else
{
2013-08-06 08:49:20 +08:00
return false;
}
2013-07-20 01:33:26 +08:00
}
2013-08-06 08:49:20 +08:00
void FontAtlas::addTexture(Texture2D &texture, int slot)
2013-07-20 01:33:26 +08:00
{
2013-08-06 08:49:20 +08:00
texture.retain();
_atlasTextures[slot] = &texture;
2013-07-20 01:33:26 +08:00
}
2013-08-06 08:49:20 +08:00
Texture2D & FontAtlas::getTexture(int slot)
2013-07-20 01:33:26 +08:00
{
2013-08-06 08:49:20 +08:00
return *(_atlasTextures[slot]);
2013-07-20 01:33:26 +08:00
}
2013-09-13 11:46:46 +08:00
float FontAtlas::getCommonLineHeight() const
{
return _commonLineHeight;
}
void FontAtlas::setCommonLineHeight(float newHeight)
{
_commonLineHeight = newHeight;
}
2013-09-13 11:46:46 +08:00
Font & FontAtlas::getFont() const
{
return _font;
}
2013-07-20 01:33:26 +08:00
NS_CC_END