summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2013-05-26 23:48:03 +0300
committerAndrei Karas <akaras@inbox.ru>2013-05-26 23:48:03 +0300
commitb4ec5a83cbb42213aef9874fb62bd0911ccbb5a0 (patch)
treebc1f59e385bc2629791868cc00a781ed37d493a7
parent9fe86d302838c62034c0bf6c74d8ca47722bd40b (diff)
downloadmanaverse-b4ec5a83cbb42213aef9874fb62bd0911ccbb5a0.tar.gz
manaverse-b4ec5a83cbb42213aef9874fb62bd0911ccbb5a0.tar.bz2
manaverse-b4ec5a83cbb42213aef9874fb62bd0911ccbb5a0.tar.xz
manaverse-b4ec5a83cbb42213aef9874fb62bd0911ccbb5a0.zip
improve temp fix for alpha channel in cached strings in software renderer.
-rw-r--r--src/gui/sdlfont.cpp71
-rw-r--r--src/gui/sdlfont.h3
2 files changed, 25 insertions, 49 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
diff --git a/src/gui/sdlfont.h b/src/gui/sdlfont.h
index 52d617518..30b4d2fa4 100644
--- a/src/gui/sdlfont.h
+++ b/src/gui/sdlfont.h
@@ -151,11 +151,12 @@ class SDLFont final : public gcn::Font
int getDeleteCounter() const A_WARN_UNUSED
{ return mDeleteCounter; }
+ static bool mOpengl;
+
private:
TTF_Font *mFont;
unsigned mCreateCounter;
unsigned mDeleteCounter;
- bool mOpengl;
// Word surfaces cache
int mCleanTime;