diff options
author | Andrei Karas <akaras@inbox.ru> | 2013-05-26 23:48:03 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2013-05-26 23:48:03 +0300 |
commit | b4ec5a83cbb42213aef9874fb62bd0911ccbb5a0 (patch) | |
tree | bc1f59e385bc2629791868cc00a781ed37d493a7 /src/gui/sdlfont.cpp | |
parent | 9fe86d302838c62034c0bf6c74d8ca47722bd40b (diff) | |
download | manaplus-b4ec5a83cbb42213aef9874fb62bd0911ccbb5a0.tar.gz manaplus-b4ec5a83cbb42213aef9874fb62bd0911ccbb5a0.tar.bz2 manaplus-b4ec5a83cbb42213aef9874fb62bd0911ccbb5a0.tar.xz manaplus-b4ec5a83cbb42213aef9874fb62bd0911ccbb5a0.zip |
improve temp fix for alpha channel in cached strings in software renderer.
Diffstat (limited to 'src/gui/sdlfont.cpp')
-rw-r--r-- | src/gui/sdlfont.cpp | 71 |
1 files changed, 23 insertions, 48 deletions
diff --git a/src/gui/sdlfont.cpp b/src/gui/sdlfont.cpp index 0d285ad1d..d0e1fc043 100644 --- a/src/gui/sdlfont.cpp +++ b/src/gui/sdlfont.cpp @@ -44,6 +44,8 @@ const unsigned int CACHE_SIZE_SMALL3 = 170; const unsigned int CLEAN_TIME = 7; const int OUTLINE_SIZE = 1; +bool SDLFont::mOpengl(true); + char *strBuf; #ifdef UNITTESTS @@ -92,6 +94,10 @@ bool SDLTextChunkSmall::operator<(const SDLTextChunkSmall &chunk) const return c2.g > color2.g; if (c2.b != color2.b) return c2.b > color2.b; + + if (c.a != color.a && !SDLFont::mOpengl) + return c.a > color.a; + return false; } @@ -318,15 +324,18 @@ SDLFont::SDLFont(std::string filename, mFont(nullptr), mCreateCounter(0), mDeleteCounter(0), - mOpengl(imageHelper->useOpenGL()), mCleanTime(cur_time + CLEAN_TIME) { const ResourceManager *const resman = ResourceManager::getInstance(); - if (fontCounter == 0 && TTF_Init() == -1) + if (fontCounter == 0) { - throw GCN_EXCEPTION("Unable to initialize SDL_ttf: " + - std::string(TTF_GetError())); + mOpengl = imageHelper->useOpenGL(); + if (TTF_Init() == -1) + { + throw GCN_EXCEPTION("Unable to initialize SDL_ttf: " + + std::string(TTF_GetError())); + } } if (!fontCounter) @@ -435,56 +444,22 @@ void SDLFont::drawString(gcn::Graphics *const graphics, const unsigned char chr = text[0]; TextChunkList *const cache = &mCache[chr]; - if (!mOpengl) + std::map<SDLTextChunkSmall, SDLTextChunk*> &search = cache->search; + std::map<SDLTextChunkSmall, SDLTextChunk*>::iterator i + = search.find(SDLTextChunkSmall(text, col, col2)); + if (i != search.end()) { - bool found(false); - SDLTextChunk chunk(text, col, col2); - SDLTextChunk *i1 = cache->start; - while (i1) - { - if (*i1 == chunk) - { - cache->moveToFirst(i1); - found = true; - break; - } - i1 = i1->next; - } - - if (found) + SDLTextChunk *const chunk2 = (*i).second; + cache->moveToFirst(chunk2); + Image *const image = chunk2->img; + if (image) { - Image *const image = cache->start->img; - if (image) - { - image->setAlpha(alpha); - g->drawImage(image, x, y); - } - BLOCK_END("SDLFont::drawString") - return; + image->setAlpha(alpha); + g->drawImage(image, x, y); } } else { - std::map<SDLTextChunkSmall, SDLTextChunk*> &search = cache->search; - std::map<SDLTextChunkSmall, SDLTextChunk*>::iterator i - = search.find(SDLTextChunkSmall(text, col, col2)); - if (i != search.end()) - { - SDLTextChunk *const chunk2 = (*i).second; - - cache->moveToFirst(chunk2); - Image *const image = chunk2->img; - if (image) - { - image->setAlpha(alpha); - g->drawImage(image, x, y); - } - BLOCK_END("SDLFont::drawString") - return; - } - } -// else - { if (cache->size >= CACHE_SIZE) { #ifdef DEBUG_FONT_COUNTERS |