Commit a4794cb4 authored by Birte Kristina Friesel's avatar Birte Kristina Friesel
Browse files

Add --draw-tinted option to draw overlay text on a semi-transparent background (closes #60, #61)

By default, feh draws white text with a black drop-shadow, which is well
readable in most, but not all cases.  The --draw-tinted option draws a
semi-transparent black box around all texts.  This improves readability, but
does not look as nice, so it won't become default behaviour.

It was suggested to use #7f7f7f7f for the background, but I decided that
for small images surrounded by a black border.
parent 4d205d73
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -2,6 +2,9 @@ git HEAD

    * Reload image after executing an action with the hold-action flag set
      <https://github.com/derf/feh/issues/59>
    * Add --draw-tinted options to make overlay text (filename, caption etc.)
      better readable
      <https://github.com/derf/feh/issues/60>

Tue, 16 Aug 2011 22:48:06 +0200  Daniel Friesel <derf@finalrewind.org>

+6 −0
Original line number Diff line number Diff line
@@ -199,6 +199,12 @@ Draw the defined actions and what they do at the top-left of the image.
.
Draw the filename at the top-left of the image.
.
.It Cm --draw-tinted
.
Show overlay texts
.Pq as created by Cm --draw-filename No et al
on a semi-transparent background to improve their readability
.
.It Cm -f , --filelist Ar file
.
This option is similar to the playlists used by music software.  If
+4 −0
Original line number Diff line number Diff line
@@ -93,6 +93,10 @@ enum bgmode_type { BG_MODE_NONE = 0, BG_MODE_TILE, BG_MODE_CENTER,
	BG_MODE_SCALE, BG_MODE_FILL, BG_MODE_MAX
};

enum zoom_mode { ZOOM_MODE_FILL, ZOOM_MODE_MAX };

enum text_bg { TEXT_BG_CLEAR = 0, TEXT_BG_TINTED };

enum slide_change { SLIDE_NEXT, SLIDE_PREV, SLIDE_RAND, SLIDE_FIRST, SLIDE_LAST,
	SLIDE_JUMP_FWD,
	SLIDE_JUMP_BACK
+23 −37
Original line number Diff line number Diff line
@@ -319,13 +319,29 @@ char *feh_http_load_image(char *url)

#endif				/* HAVE_LIBCURL */

void feh_imlib_image_fill_text_bg(Imlib_Image im, int w, int h)
{
	static DATA8 atab[256];
	memset(atab, 0, sizeof(atab));

	gib_imlib_image_set_has_alpha(im, 1);

	gib_imlib_apply_color_modifier_to_rectangle(im, 0, 0, w, h, NULL, NULL,
			NULL, atab);

	if (opt.text_bg == TEXT_BG_CLEAR)
		gib_imlib_image_fill_rectangle(im, 0, 0, w, h, 0, 0, 0, 0);
	else
		gib_imlib_image_fill_rectangle(im, 0, 0, w, h, 0, 0, 0, 127);
}


void feh_draw_zoom(winwidget w)
{
	static Imlib_Font fn = NULL;
	int tw = 0, th = 0;
	Imlib_Image im = NULL;
	char buf[100];
	static DATA8 atab[256];

	if (!w->im)
		return;
@@ -342,8 +358,6 @@ void feh_draw_zoom(winwidget w)
		return;
	}

	memset(atab, 0, sizeof(atab));

	snprintf(buf, sizeof(buf), "%.0f%%, %dx%d", w->zoom * 100,
			(int) (w->im_w * w->zoom), (int) (w->im_h * w->zoom));

@@ -356,9 +370,7 @@ void feh_draw_zoom(winwidget w)
	if (!im)
		eprintf("Couldn't create image. Out of memory?");

	gib_imlib_image_set_has_alpha(im, 1);
	gib_imlib_apply_color_modifier_to_rectangle(im, 0, 0, tw, th, NULL, NULL, NULL, atab);
	gib_imlib_image_fill_rectangle(im, 0, 0, tw, th, 0, 0, 0, 0);
	feh_imlib_image_fill_text_bg(im, tw, th);

	gib_imlib_text_draw(im, fn, NULL, 2, 2, buf, IMLIB_TEXT_TO_RIGHT, 0, 0, 0, 255);
	gib_imlib_text_draw(im, fn, NULL, 1, 1, buf, IMLIB_TEXT_TO_RIGHT, 255, 255, 255, 255);
@@ -394,7 +406,6 @@ void feh_draw_errstr(winwidget w)
	static Imlib_Font fn = NULL;
	int tw = 0, th = 0;
	Imlib_Image im = NULL;
	static DATA8 atab[256];

	if (!w->im)
		return;
@@ -408,8 +419,6 @@ void feh_draw_errstr(winwidget w)
	if (!fn)
		eprintf("Unable to draw error message. Dying to be safe.");

	memset(atab, 0, sizeof(atab));

	/* Work out how high the font is */
	gib_imlib_get_text_size(fn, w->errstr, NULL, &tw, &th, IMLIB_TEXT_TO_RIGHT);

@@ -419,9 +428,7 @@ void feh_draw_errstr(winwidget w)
	if (!im)
		eprintf("Couldn't create errstr image. Out of memory?");

	gib_imlib_image_set_has_alpha(im, 1);
	gib_imlib_apply_color_modifier_to_rectangle(im, 0, 0, tw, th, NULL, NULL, NULL, atab);
	gib_imlib_image_fill_rectangle(im, 0, 0, tw, th, 0, 0, 0, 0);
	feh_imlib_image_fill_text_bg(im, tw, th);

	gib_imlib_text_draw(im, fn, NULL, 2, 2, w->errstr, IMLIB_TEXT_TO_RIGHT, 0, 0, 0, 255);
	gib_imlib_text_draw(im, fn, NULL, 1, 1, w->errstr, IMLIB_TEXT_TO_RIGHT, 255, 0, 0, 255);
@@ -436,7 +443,6 @@ void feh_draw_filename(winwidget w)
	static Imlib_Font fn = NULL;
	int tw = 0, th = 0, nw = 0;
	Imlib_Image im = NULL;
	static DATA8 atab[256];
	char *s = NULL;
	int len = 0;

@@ -459,8 +465,6 @@ void feh_draw_filename(winwidget w)
		return;
	}

	memset(atab, 0, sizeof(atab));

	/* Work out how high the font is */
	gib_imlib_get_text_size(fn, FEH_FILE(w->file->data)->filename, NULL, &tw,
			&th, IMLIB_TEXT_TO_RIGHT);
@@ -484,10 +488,7 @@ void feh_draw_filename(winwidget w)
	if (!im)
		eprintf("Couldn't create image. Out of memory?");

	gib_imlib_image_set_has_alpha(im, 1);
	gib_imlib_apply_color_modifier_to_rectangle(im, 0, 0, tw, 2 * th, NULL,
			NULL, NULL, atab);
	gib_imlib_image_fill_rectangle(im, 0, 0, tw, 2 * th, 0, 0, 0, 0);
	feh_imlib_image_fill_text_bg(im, tw, 2 * th);

	gib_imlib_text_draw(im, fn, NULL, 2, 2, FEH_FILE(w->file->data)->filename,
			IMLIB_TEXT_TO_RIGHT, 0, 0, 0, 255);
@@ -511,7 +512,6 @@ void feh_draw_info(winwidget w)
	static Imlib_Font fn = NULL;
	int tw = 0, th = 0;
	Imlib_Image im = NULL;
	static DATA8 atab[256];
	int no_lines = 0;
	char *info_cmd;
	char info_buf[256];
@@ -538,8 +538,6 @@ void feh_draw_info(winwidget w)

	info_cmd = feh_printf(opt.info_cmd, FEH_FILE(w->file->data));

	memset(atab, 0, sizeof(atab));

	gib_imlib_get_text_size(fn, "w", NULL, &tw, &th, IMLIB_TEXT_TO_RIGHT);

	info_pipe = popen(info_cmd, "r");
@@ -548,9 +546,7 @@ void feh_draw_info(winwidget w)
	if (!im)
		eprintf("Couldn't create image. Out of memory?");

	gib_imlib_image_set_has_alpha(im, 1);
	gib_imlib_apply_color_modifier_to_rectangle(im, 0, 0, 290 * tw, 20 * th, NULL, NULL, NULL, atab);
	gib_imlib_image_fill_rectangle(im, 0, 0, 290 * tw, 20 * th, 0, 0, 0, 0);
	feh_imlib_image_fill_text_bg(im, 290 * tw, 20 * th);

	if (!info_pipe) {
		gib_imlib_text_draw(im, fn, NULL, 2, 2,
@@ -622,7 +618,6 @@ void feh_draw_caption(winwidget w)
	int tw = 0, th = 0, ww, hh;
	int x, y;
	Imlib_Image im = NULL;
	static DATA8 atab[256];
	char *p;
	gib_list *lines, *l;
	static gib_style *caption_style = NULL;
@@ -683,8 +678,6 @@ void feh_draw_caption(winwidget w)
		return;
	}

	memset(atab, 0, sizeof(atab));

	if (*(file->caption) == '\0') {
		p = estrdup("Caption entry mode - Hit ESC to cancel");
		lines = feh_wrap_string(p, w->w, fn, NULL);
@@ -718,9 +711,7 @@ void feh_draw_caption(winwidget w)
	if (!im)
		eprintf("Couldn't create image. Out of memory?");

	gib_imlib_image_set_has_alpha(im, 1);
	gib_imlib_apply_color_modifier_to_rectangle(im, 0, 0, tw, th, NULL, NULL, NULL, atab);
	gib_imlib_image_fill_rectangle(im, 0, 0, tw, th, 0, 0, 0, 0);
	feh_imlib_image_fill_text_bg(im, tw, th);

	l = lines;
	x = 0;
@@ -973,7 +964,6 @@ void feh_draw_actions(winwidget w)
	int max_tw = 0;
	int line_th = 0;
	Imlib_Image im = NULL;
	static DATA8 atab[256];
	int i = 0;
	int num_actions = 0;
	int cur_action = 0;
@@ -1011,8 +1001,6 @@ void feh_draw_actions(winwidget w)
		return;
	}

	memset(atab, 0, sizeof(atab));

	gib_imlib_get_text_size(fn, "defined actions:", NULL, &tw, &th, IMLIB_TEXT_TO_RIGHT);
/* Check for the widest line */
	max_tw = tw;
@@ -1045,9 +1033,7 @@ void feh_draw_actions(winwidget w)
	if (!im)
		eprintf("Couldn't create image. Out of memory?");

	gib_imlib_image_set_has_alpha(im, 1);
	gib_imlib_apply_color_modifier_to_rectangle(im, 0, 0, tw, th, NULL, NULL, NULL, atab);
	gib_imlib_image_fill_rectangle(im, 0, 0, tw, th, 0, 0, 0, 0);
	feh_imlib_image_fill_text_bg(im, tw, th);

	gib_imlib_text_draw(im, fn, NULL, 2, 2, "defined actions:", IMLIB_TEXT_TO_RIGHT, 0, 0, 0, 255);
	gib_imlib_text_draw(im, fn, NULL, 1, 1, "defined actions:", IMLIB_TEXT_TO_RIGHT, 255, 255, 255, 255);
+4 −0
Original line number Diff line number Diff line
@@ -362,6 +362,7 @@ static void feh_parse_option_array(int argc, char **argv, int finalrun)
		{"no-rotate-ctrl-mask", 0, 0, 226},
		{"no-blur-ctrl-mask", 0, 0, 227},
		{"menu-ctrl-mask", 0, 0, 228},
		{"draw-tinted"   , 0, 0, 229},

		{"output"        , 1, 0, 'o'},
		{"output-only"   , 1, 0, 'O'},
@@ -757,6 +758,9 @@ static void feh_parse_option_array(int argc, char **argv, int finalrun)
		case 228:
			opt.menu_ctrl_mask = 1;
			break;
		case 229:
			opt.text_bg = TEXT_BG_TINTED;
			break;
		case 230:
			opt.index_show_name = atoi(optarg);
			break;
Loading