summaryrefslogtreecommitdiff
path: root/src/gui/sdlfont.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2012-12-27 22:12:10 +0300
committerAndrei Karas <akaras@inbox.ru>2012-12-27 23:15:06 +0300
commit8714a174353529061c8c8d088d7246c4bd81000d (patch)
tree800067371dc1e4e425980afb9b54cf56f034ffa8 /src/gui/sdlfont.cpp
parentdee02b54a28994e78bd7e738ac0b49df9f59d67f (diff)
downloadplus-8714a174353529061c8c8d088d7246c4bd81000d.tar.gz
plus-8714a174353529061c8c8d088d7246c4bd81000d.tar.bz2
plus-8714a174353529061c8c8d088d7246c4bd81000d.tar.xz
plus-8714a174353529061c8c8d088d7246c4bd81000d.zip
Change outline function to better quality but slower.
Also add function to create 32 bit surfaces.
Diffstat (limited to 'src/gui/sdlfont.cpp')
-rw-r--r--src/gui/sdlfont.cpp34
1 files changed, 29 insertions, 5 deletions
diff --git a/src/gui/sdlfont.cpp b/src/gui/sdlfont.cpp
index 30c16a4c3..d195278fa 100644
--- a/src/gui/sdlfont.cpp
+++ b/src/gui/sdlfont.cpp
@@ -35,6 +35,8 @@
#include <guichan/exception.hpp>
+#include <SDL_gfxBlitFunc.h>
+
#include "debug.h"
const unsigned int CACHE_SIZE = 256;
@@ -92,11 +94,21 @@ class SDLTextChunk final
|| color.b != color2.b)
{ // outlining
SDL_Color sdlCol2;
+ const SDL_PixelFormat * const format = surface->format;
+ SDL_Surface *background = imageHelper->create32BitSurface(
+ surface->w, surface->h);
+ if (!background)
+ {
+ img = nullptr;
+ SDL_FreeSurface(surface);
+ BLOCK_END("SDLTextChunk::generate")
+ return;
+ }
sdlCol2.b = static_cast<uint8_t>(color2.b);
sdlCol2.r = static_cast<uint8_t>(color2.r);
sdlCol2.g = static_cast<uint8_t>(color2.g);
SDL_Surface *const surface2 = TTF_RenderUTF8_Blended(
- font2, strBuf, sdlCol2);
+ font, strBuf, sdlCol2);
if (!surface2)
{
img = nullptr;
@@ -106,13 +118,25 @@ class SDLTextChunk final
}
SDL_Rect rect =
{
- OUTLINE_SIZE, OUTLINE_SIZE,
- surface2->w, surface2->h
+ OUTLINE_SIZE, 0,
+ surface->w, surface->h
};
+// SDL_SetAlpha(surface2, 0, SDL_ALPHA_OPAQUE);
+ SDL_gfxBlitRGBA(surface2, nullptr, background, &rect);
+ rect.x = -OUTLINE_SIZE;
+ SDL_gfxBlitRGBA(surface2, nullptr, background, &rect);
+ rect.x = 0;
+ rect.y = -OUTLINE_SIZE;
+ SDL_gfxBlitRGBA(surface2, nullptr, background, &rect);
+ rect.y = OUTLINE_SIZE;
+ SDL_gfxBlitRGBA(surface2, nullptr, background, &rect);
+ rect.x = 0;
+ rect.y = 0;
// SDL_SetAlpha(surface, 0, SDL_ALPHA_OPAQUE);
- SDL_BlitSurface(surface, nullptr, surface2, &rect);
+ SDL_gfxBlitRGBA(surface, nullptr, background, &rect);
SDL_FreeSurface(surface);
- surface = surface2;
+ SDL_FreeSurface(surface2);
+ surface = background;
}
img = imageHelper->createTextSurface(surface, alpha);
SDL_FreeSurface(surface);