summaryrefslogtreecommitdiff
path: root/src/gui/sdlfont.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2013-04-25 16:28:43 +0300
committerAndrei Karas <akaras@inbox.ru>2013-04-25 16:35:59 +0300
commit684171f30e61ab2c594324a3ff78d0d2df6defb3 (patch)
tree993b60b0e0511670e5f35420351a3ada78b153f3 /src/gui/sdlfont.cpp
parenta2af9029410b20748b053bf0ca6f78ee27efef9e (diff)
downloadplus-684171f30e61ab2c594324a3ff78d0d2df6defb3.tar.gz
plus-684171f30e61ab2c594324a3ff78d0d2df6defb3.tar.bz2
plus-684171f30e61ab2c594324a3ff78d0d2df6defb3.tar.xz
plus-684171f30e61ab2c594324a3ff78d0d2df6defb3.zip
add in sdlfont map support also for calculating string widths.
Diffstat (limited to 'src/gui/sdlfont.cpp')
-rw-r--r--src/gui/sdlfont.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/gui/sdlfont.cpp b/src/gui/sdlfont.cpp
index 37174d8e9..4e71de061 100644
--- a/src/gui/sdlfont.cpp
+++ b/src/gui/sdlfont.cpp
@@ -226,6 +226,7 @@ void TextChunkList::insertFirst(SDLTextChunk *const item)
start = item;
size ++;
search[SDLTextChunkSmall(item->text, item->color, item->color2)] = item;
+ searchWidth[item->text] = item;
}
void TextChunkList::moveToFirst(SDLTextChunk *item)
@@ -261,6 +262,7 @@ void TextChunkList::removeBack()
start = nullptr;
search.erase(SDLTextChunkSmall(oldEnd->text,
oldEnd->color, oldEnd->color2));
+ searchWidth.erase(oldEnd->text);
delete oldEnd;
size --;
}
@@ -276,6 +278,7 @@ void TextChunkList::removeBack(int n)
item = item->prev;
search.erase(SDLTextChunkSmall(oldEnd->text,
oldEnd->color, oldEnd->color2));
+ searchWidth.erase(oldEnd->text);
delete oldEnd;
size --;
}
@@ -294,6 +297,7 @@ void TextChunkList::removeBack(int n)
void TextChunkList::clear()
{
search.clear();
+ searchWidth.clear();
SDLTextChunk *item = start;
while (item)
{
@@ -487,6 +491,20 @@ int SDLFont::getWidth(const std::string &text) const
const unsigned char chr = text[0];
TextChunkList *const cache = &mCache[chr];
+ std::map<std::string, SDLTextChunk*> &search = cache->searchWidth;
+ std::map<std::string, SDLTextChunk*>::iterator i = search.find(text);
+ if (i != search.end())
+ {
+ SDLTextChunk *const chunk = (*i).second;
+ cache->moveToFirst(chunk);
+ const Image *const image = chunk->img;
+ if (image)
+ return image->getWidth();
+ else
+ return 0;
+ }
+
+/*
#ifdef DEBUG_FONT
int cnt = 0;
#endif
@@ -515,7 +533,9 @@ int SDLFont::getWidth(const std::string &text) const
logger->log(std::string("getWidth: ").append(text).append(
", iterations: ").append(toString(cnt)));
#endif
+*/
+ // if string was not drawed
int w, h;
getSafeUtf8String(text, strBuf);
TTF_SizeUTF8(mFont, strBuf, &w, &h);