From e645959d2dc85ee6a50d9927df3d9f6e374c8317 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Wed, 20 Jul 2011 02:57:47 +0300 Subject: Improve perfomance in creation SDL font surfaces. --- src/gui/sdlfont.cpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'src/gui') diff --git a/src/gui/sdlfont.cpp b/src/gui/sdlfont.cpp index 9cbee4e89..a0f8699f8 100644 --- a/src/gui/sdlfont.cpp +++ b/src/gui/sdlfont.cpp @@ -64,7 +64,7 @@ class SDLTextChunk return (chunk.text == text && chunk.color == color); } - void generate(TTF_Font *font) + void generate(TTF_Font *font, float alpha) { SDL_Color sdlCol; sdlCol.b = static_cast(color.b); @@ -83,7 +83,8 @@ class SDLTextChunk return; } - img = Image::load(surface); + img = Image::createTextSurface(surface, alpha); +// img = Image::load(surface); SDL_FreeSurface(surface); } @@ -243,7 +244,7 @@ void SDLFont::drawString(gcn::Graphics *graphics, mCreateCounter ++; #endif cache->push_front(chunk); - cache->front().generate(mFont); + cache->front().generate(mFont, alpha); if (!mCleanTime) { @@ -254,9 +255,13 @@ void SDLFont::drawString(gcn::Graphics *graphics, doClean(); mCleanTime = cur_time + CLEAN_TIME; } + if (cache->front().img) + { +// cache->front().img->setAlpha(alpha); + g->drawImage(cache->front().img, x, y); + } } - - if (cache->front().img) + else if (cache->front().img) { cache->front().img->setAlpha(alpha); g->drawImage(cache->front().img, x, y); @@ -271,9 +276,9 @@ void SDLFont::createSDLTextChunk(SDLTextChunk *chunk) const float alpha = static_cast(chunk->color.a) / 255.0f; chunk->color.a = 255; - chunk->generate(mFont); - if (chunk->img) - chunk->img->setAlpha(alpha); + chunk->generate(mFont, alpha); +// if (chunk->img) +// chunk->img->setAlpha(alpha); } int SDLFont::getWidth(const std::string &text) const -- cgit v1.2.3-70-g09d2