summaryrefslogtreecommitdiff
path: root/src/gui/truetypefont.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui/truetypefont.cpp')
-rw-r--r--src/gui/truetypefont.cpp48
1 files changed, 20 insertions, 28 deletions
diff --git a/src/gui/truetypefont.cpp b/src/gui/truetypefont.cpp
index 1132c3b5..7c72e2f5 100644
--- a/src/gui/truetypefont.cpp
+++ b/src/gui/truetypefont.cpp
@@ -1,30 +1,28 @@
/*
* The Mana World
- * Copyright 2004 The Mana World Development Team
+ * Copyright (C) 2004 The Mana World Development Team
*
* This file is part of The Mana World.
*
- * The Mana World is free software; you can redistribute it and/or modify
+ * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* any later version.
*
- * The Mana World is distributed in the hope that it will be useful,
+ * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with The Mana World; if not, write to the Free Software
+ * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include "truetypefont.h"
-
-#include <list>
-
#include <guichan/exception.hpp>
+#include "truetypefont.h"
+
#include "../graphics.h"
#include "../resources/image.h"
@@ -45,8 +43,7 @@ class TextChunk
bool operator==(const TextChunk &chunk) const
{
- return (
- chunk.text == text && chunk.color == color);
+ return (chunk.text == text && chunk.color == color);
}
void generate(TTF_Font *font)
@@ -75,14 +72,11 @@ class TextChunk
gcn::Color color;
};
-
-// Word surfaces cache
-static std::list<TextChunk> cache;
typedef std::list<TextChunk>::iterator CacheIterator;
static int fontCounter;
-TrueTypeFont::TrueTypeFont(const std::string& filename, int size)
+TrueTypeFont::TrueTypeFont(const std::string &filename, int size)
{
if (fontCounter == 0 && TTF_Init() == -1)
{
@@ -93,7 +87,7 @@ TrueTypeFont::TrueTypeFont(const std::string& filename, int size)
++fontCounter;
mFont = TTF_OpenFont(filename.c_str(), size);
- if (mFont == NULL)
+ if (!mFont)
{
throw GCN_EXCEPTION("SDLTrueTypeFont::SDLTrueTypeFont: " +
std::string(TTF_GetError()));
@@ -112,13 +106,11 @@ TrueTypeFont::~TrueTypeFont()
}
void TrueTypeFont::drawString(gcn::Graphics *graphics,
- const std::string &text,
- int x, int y)
+ const std::string &text,
+ int x, int y)
{
if (text.empty())
- {
return;
- }
Graphics *g = dynamic_cast<Graphics *>(graphics);
@@ -139,12 +131,12 @@ void TrueTypeFont::drawString(gcn::Graphics *graphics,
bool found = false;
- for (CacheIterator i = cache.begin(); i != cache.end(); i++)
+ for (CacheIterator i = mCache.begin(); i != mCache.end(); ++i)
{
if (chunk == (*i))
{
// Raise priority: move it to front
- cache.splice(cache.begin(), cache, i);
+ mCache.splice(mCache.begin(), mCache, i);
found = true;
break;
}
@@ -153,19 +145,19 @@ void TrueTypeFont::drawString(gcn::Graphics *graphics,
// Surface not found
if (!found)
{
- if (cache.size() >= CACHE_SIZE)
+ if (mCache.size() >= CACHE_SIZE)
{
- cache.pop_back();
+ mCache.pop_back();
}
- cache.push_front(chunk);
- cache.front().generate(mFont);
+ mCache.push_front(chunk);
+ mCache.front().generate(mFont);
}
- cache.front().img->setAlpha(alpha);
- g->drawImage(cache.front().img, x, y);
+ mCache.front().img->setAlpha(alpha);
+ g->drawImage(mCache.front().img, x, y);
}
-int TrueTypeFont::getWidth(const std::string& text) const
+int TrueTypeFont::getWidth(const std::string &text) const
{
int w, h;
TTF_SizeUTF8(mFont, text.c_str(), &w, &h);