diff options
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/truetypefont.cpp | 17 | ||||
-rw-r--r-- | src/gui/truetypefont.h | 3 |
2 files changed, 19 insertions, 1 deletions
diff --git a/src/gui/truetypefont.cpp b/src/gui/truetypefont.cpp index 5243a175..fe507489 100644 --- a/src/gui/truetypefont.cpp +++ b/src/gui/truetypefont.cpp @@ -1,6 +1,7 @@ /* * The Mana World * Copyright (C) 2004-2010 The Mana World Development Team + * Copyright (C) 2009 Aethyra Development Team * * This file is part of The Mana World. * @@ -42,6 +43,11 @@ class TextChunk delete img; } + bool operator==(const std::string &str) const + { + return (str == text); + } + bool operator==(const TextChunk &chunk) const { return (chunk.text == text && chunk.color == color); @@ -162,6 +168,17 @@ void TrueTypeFont::drawString(gcn::Graphics *graphics, int TrueTypeFont::getWidth(const std::string &text) const { + for (CacheIterator i = mCache.begin(); i != mCache.end(); i++) + { + if ((*i) == text) + { + // Raise priority: move it to front + // Assumption is that TTF::draw will be called next + mCache.splice(mCache.begin(), mCache, i); + return i->img->getWidth(); + } + } + int w, h; TTF_SizeUTF8(mFont, text.c_str(), &w, &h); return w; diff --git a/src/gui/truetypefont.h b/src/gui/truetypefont.h index 9211a7dc..45e1ec70 100644 --- a/src/gui/truetypefont.h +++ b/src/gui/truetypefont.h @@ -1,6 +1,7 @@ /* * The Mana World * Copyright (C) 2004-2010 The Mana World Development Team + * Copyright (C) 2009 Aethyra Development Team * * This file is part of The Mana World. * @@ -75,7 +76,7 @@ class TrueTypeFont : public gcn::Font TTF_Font *mFont; // Word surfaces cache - std::list<TextChunk> mCache; + mutable std::list<TextChunk> mCache; }; #endif |