summaryrefslogtreecommitdiff
path: root/meme/gui.c
diff options
context:
space:
mode:
authorWerner Almesberger <werner@almesberger.net>2016-02-14 20:38:28 (GMT)
committerWerner Almesberger <werner@almesberger.net>2016-02-14 20:38:28 (GMT)
commit5551daea48a8e1363e67a2a77de7b6b9c0acfa14 (patch)
tree68e884d89c2fe4d4f65e1d9ced1484139bf3811b /meme/gui.c
parent929702e4c0dbacdd0874a789b632044cc80dfd81 (diff)
downloadmisc-5551daea48a8e1363e67a2a77de7b6b9c0acfa14.zip
misc-5551daea48a8e1363e67a2a77de7b6b9c0acfa14.tar.gz
misc-5551daea48a8e1363e67a2a77de7b6b9c0acfa14.tar.bz2
meme/: use adaptive outline instead of rectangle for marker text
Diffstat (limited to 'meme/gui.c')
-rw-r--r--meme/gui.c47
1 files changed, 37 insertions, 10 deletions
diff --git a/meme/gui.c b/meme/gui.c
index 6c048ff..2ecdafe 100644
--- a/meme/gui.c
+++ b/meme/gui.c
@@ -975,27 +975,54 @@ static void marker_line(void *user, int xa, int ya, int xb, int yb,
}
+#define TEXT_BG_RGBA 0xffffffff
+#define TEXT_BORDER_RGBA 0xffffffc0
+#define MASK_GB 0x00ffff00 /* works with RGBA and ABGR */
+
+
+static void text_with_outline(SDL_Surface *s, const SDL_Surface *t,
+ Sint16 x, Sint16 y)
+{
+ Uint16 ix, iy;
+ int8_t dx, dy;
+ Uint32 col;
+ uint8_t v, v2;
+
+ for (iy = 0; iy != t->h; iy++)
+ for (ix = 0; ix != t->w; ix++) {
+ col = get_pixel(t, ix, iy, TEXT_BG_RGBA);
+ if ((col ^ TEXT_BG_RGBA) & MASK_GB) {
+ v = col >> 16;
+ v2 = (255 + v) >> 1;
+ pixelRGBA(s, x + ix, y + iy, v, v2, v, 255);
+ continue;
+ }
+ col = TEXT_BG_RGBA;
+ for (dy = -1; dy <= 1; dy++)
+ for (dx = -1; dx <= 1; dx++)
+ if (dx || dy)
+ col &= get_pixel(t,
+ ix + dx, iy + dy,
+ TEXT_BG_RGBA);
+ if ((col ^ TEXT_BG_RGBA) & MASK_GB)
+ pixelColor(s, x + ix, y + iy, TEXT_BORDER_RGBA);
+ }
+}
+
+
static void marker_text(void *user, int x, int y, float nx, float ny,
const char *txt)
{
SDL_Surface *s = user;
Sint16 xx, yy;
SDL_Surface *t;
- SDL_Rect r;
if (coord(x, y, &xx, &yy) <= 0)
return;
t = text(txt);
- r.x = xx + TEXT_OFFSET_X + TEXT_DIST * nx;
- r.y = yy + TEXT_OFFSET_Y + TEXT_DIST * ny;
-
- r.w = t->w;
- r.h = t->h;
- if (SDL_BlitSurface(t, NULL, s, &r)) {
- fprintf(stderr, "SDL_BlitSurface: %s \n", SDL_GetError());
- exit(1);
- }
+ text_with_outline(s, t, xx + TEXT_OFFSET_X + TEXT_DIST * nx,
+ yy + TEXT_OFFSET_Y + TEXT_DIST * ny);
SDL_FreeSurface(t);
}