summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2011-08-23 09:23:16 +0200
committerDaniel Friesel <derf@finalrewind.org>2011-08-23 09:23:16 +0200
commita4794cb4196effcca4b3c7e1253a46f641c46107 (patch)
tree1006bcf081887df851ad49eb0ff1ae5518d329ab /src
parent4d205d73df95b78ed7517de755ba19e79d07c175 (diff)
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.
Diffstat (limited to 'src')
-rw-r--r--src/feh.h4
-rw-r--r--src/imlib.c60
-rw-r--r--src/options.c4
-rw-r--r--src/options.h4
4 files changed, 32 insertions, 40 deletions
diff --git a/src/feh.h b/src/feh.h
index 6af425c..b25b3cc 100644
--- a/src/feh.h
+++ b/src/feh.h
@@ -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
diff --git a/src/imlib.c b/src/imlib.c
index d12852c..3259e4d 100644
--- a/src/imlib.c
+++ b/src/imlib.c
@@ -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);
diff --git a/src/options.c b/src/options.c
index 4c832a0..13aaa95 100644
--- a/src/options.c
+++ b/src/options.c
@@ -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;
diff --git a/src/options.h b/src/options.h
index bfcb94c..2ca655e 100644
--- a/src/options.h
+++ b/src/options.h
@@ -27,9 +27,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#ifndef OPTIONS_H
#define OPTIONS_H
-#define ZOOM_MODE_FILL 1
-#define ZOOM_MODE_MAX 2
-
struct __fehoptions {
unsigned char multiwindow;
unsigned char montage;
@@ -72,6 +69,7 @@ struct __fehoptions {
unsigned char cache_thumbnails;
unsigned char cycle_once;
unsigned char hold_actions[10];
+ unsigned char text_bg;
char *output_file;
char *output_dir;