diff options
author | Andrei Karas <akaras@inbox.ru> | 2013-05-19 17:48:34 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2013-05-19 17:48:34 +0300 |
commit | 3203c6bd824cd8ac4e86374afafe01e45d358a40 (patch) | |
tree | 39b922bedf17bc2629d9b00da84a4024332c6243 /src | |
parent | e7c83487949d173e230e8868ef5410a1ac5a9398 (diff) | |
download | plus-3203c6bd824cd8ac4e86374afafe01e45d358a40.tar.gz plus-3203c6bd824cd8ac4e86374afafe01e45d358a40.tar.bz2 plus-3203c6bd824cd8ac4e86374afafe01e45d358a40.tar.xz plus-3203c6bd824cd8ac4e86374afafe01e45d358a40.zip |
improve SDLFont class.
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/sdlfont.cpp | 45 | ||||
-rw-r--r-- | src/gui/sdlfont.h | 24 |
2 files changed, 18 insertions, 51 deletions
diff --git a/src/gui/sdlfont.cpp b/src/gui/sdlfont.cpp index 0b4f57baa..7df00260a 100644 --- a/src/gui/sdlfont.cpp +++ b/src/gui/sdlfont.cpp @@ -152,7 +152,7 @@ void SDLTextChunk::generate(TTF_Font *const font, const float alpha) || color.b != color2.b) { // outlining SDL_Color sdlCol2; - SDL_Surface *background = imageHelper->create32BitSurface( + SDL_Surface *const background = imageHelper->create32BitSurface( width, height); if (!background) { @@ -314,7 +314,9 @@ void TextChunkList::clear() static int fontCounter; -SDLFont::SDLFont(std::string filename, const int size, const int style) : +SDLFont::SDLFont(std::string filename, + const int size, + const int style) : mFont(nullptr), mCreateCounter(0), mDeleteCounter(0), @@ -369,7 +371,9 @@ SDLFont::~SDLFont() } } -void SDLFont::loadFont(std::string filename, const int size, const int style) +void SDLFont::loadFont(std::string filename, + const int size, + const int style) { const ResourceManager *const resman = ResourceManager::getInstance(); @@ -421,7 +425,7 @@ void SDLFont::drawString(gcn::Graphics *const graphics, return; gcn::Color col = g->getColor(); - gcn::Color col2 = g->getColor2(); + const gcn::Color col2 = g->getColor2(); const float alpha = static_cast<float>(col.a) / 255.0f; /* The alpha value is ignored at string generation so avoid caching the @@ -506,37 +510,6 @@ int SDLFont::getWidth(const std::string &text) const return 0; } -/* -#ifdef DEBUG_FONT - int cnt = 0; -#endif - - SDLTextChunk *i = cache->start; - while (i) - { - if (i->text == text) - { - // Raise priority: move it to front - // Assumption is that TTF::draw will be called next - cache->moveToFirst(i); - const Image *const image = i->img; - if (image) - return image->getWidth(); - else - return 0; - } - i = i->next; -#ifdef DEBUG_FONT - cnt ++; -#endif - } - -#ifdef DEBUG_FONT - logger->log(std::string("getWidth: ").append(text).append( - ", iterations: ").append(toString(cnt))); -#endif -*/ - // if string was not drawed int w, h; getSafeUtf8String(text, strBuf); @@ -591,7 +564,7 @@ void SDLFont::doClean() } } -TextChunkList *SDLFont::getCache() +TextChunkList *SDLFont::getCache() const { return mCache; } diff --git a/src/gui/sdlfont.h b/src/gui/sdlfont.h index f7fa15d6b..09b93f87a 100644 --- a/src/gui/sdlfont.h +++ b/src/gui/sdlfont.h @@ -114,36 +114,30 @@ class TextChunkList final class SDLFont final : public gcn::Font { public: - /** - * Constructor. - * - * @param filename Font filename. - * @param size Font size. - */ - SDLFont(std::string filename, const int size, const int style = 0); + SDLFont(std::string filename, + const int size, + const int style = 0); A_DELETE_COPY(SDLFont) - /** - * Destructor. - */ ~SDLFont(); - void loadFont(std::string filename, const int size, + void loadFont(std::string filename, + const int size, const int style = 0); - virtual int getWidth(const std::string &text) const A_WARN_UNUSED; + int getWidth(const std::string &text) const override A_WARN_UNUSED; - virtual int getHeight() const A_WARN_UNUSED; + int getHeight() const override A_WARN_UNUSED; - TextChunkList *getCache() A_WARN_UNUSED; + TextChunkList *getCache() const A_WARN_UNUSED; /** * @see Font::drawString */ void drawString(gcn::Graphics *const graphics, const std::string &text, - const int x, const int y); + const int x, const int y) override; void clear(); |