diff options
author | Daniel Friesel <derf@finalrewind.org> | 2011-09-30 03:10:07 +0200 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2011-09-30 03:10:07 +0200 |
commit | f933dd396cf0f5cbb5b053d5a8f85fbcfc9761fd (patch) | |
tree | 2cbe398e30ad15ae94f1cdf911485b4f7a4dd4ec /src/thumbnail.c | |
parent | 555f7bccebc92d28a14eb0fd6d29a2a39b8f83e1 (diff) |
Apply changes to thumbnail mode
Diffstat (limited to 'src/thumbnail.c')
-rw-r--r-- | src/thumbnail.c | 173 |
1 files changed, 33 insertions, 140 deletions
diff --git a/src/thumbnail.c b/src/thumbnail.c index 16dbcf3..191fc8e 100644 --- a/src/thumbnail.c +++ b/src/thumbnail.c @@ -31,10 +31,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include "thumbnail.h" #include "md5.h" #include "feh_png.h" +#include "index.h" -static char *create_index_dimension_string(int w, int h); -static char *create_index_size_string(char *file); -static char *create_index_title_string(int num, int w, int h); static gib_list *thumbnails = NULL; static thumbmode_data td; @@ -65,15 +63,15 @@ void init_thumbnail_mode(void) unsigned char trans_bg = 0; int title_area_h = 0; int tw = 0, th = 0; - int fw_name, fw_size, fw_dim, fh; + int fw, fh; int thumbnailcount = 0; feh_file *file = NULL; gib_list *l, *last = NULL; - int lines; + int lineno; int index_image_width, index_image_height; - int x_offset_name = 0, x_offset_dim = 0, x_offset_size = 0; char *s; unsigned int thumb_counter = 0; + gib_list *line, *lines; /* initialize thumbnail mode data */ td.im_main = NULL; @@ -119,9 +117,8 @@ void init_thumbnail_mode(void) /* Work out how tall the font is */ gib_imlib_get_text_size(td.font_main, "W", NULL, &tw, &th, IMLIB_TEXT_TO_RIGHT); - /* For now, allow room for the right number of lines with small gaps */ - td.text_area_h = ((th + 2) * (opt.index_show_name + opt.index_show_size + - opt.index_show_dim)) + 5; + get_index_string_dim(NULL, td.font_main, &fw, &fh); + td.text_area_h = fh + 5; /* This includes the text area for index data */ td.thumb_tot_h = opt.thumb_h + td.text_area_h; @@ -264,34 +261,14 @@ void init_thumbnail_mode(void) td.text_area_w = opt.thumb_w; /* Now draw on the info text */ - if (opt.index_show_name) { - gib_imlib_get_text_size(td.font_main, file->name, NULL, - &fw_name, &fh, IMLIB_TEXT_TO_RIGHT); - if (fw_name > td.text_area_w) - td.text_area_w = fw_name; - } - if (opt.index_show_dim) { - gib_imlib_get_text_size(td.font_main, - create_index_dimension_string(ww, hh), - NULL, &fw_dim, &fh, IMLIB_TEXT_TO_RIGHT); - if (fw_dim > td.text_area_w) - td.text_area_w = fw_dim; - } - if (opt.index_show_size) { - gib_imlib_get_text_size(td.font_main, - create_index_size_string(file->filename), - NULL, &fw_size, &fh, IMLIB_TEXT_TO_RIGHT); - if (fw_size > td.text_area_w) - td.text_area_w = fw_size; + if (opt.index_info) { + get_index_string_dim(file, td.font_main, &fw, &fh); + if (fw > td.text_area_w) + td.text_area_w = fw; } if (td.text_area_w > opt.thumb_w) td.text_area_w += 5; - /* offsets for centering text */ - x_offset_name = (td.text_area_w - fw_name) / 2; - x_offset_dim = (td.text_area_w - fw_dim) / 2; - x_offset_size = (td.text_area_w - fw_size) / 2; - if (td.vertical) { if (td.text_area_w > td.max_column_w) td.max_column_w = td.text_area_w; @@ -332,28 +309,23 @@ void init_thumbnail_mode(void) gib_imlib_free_image_and_decache(im_thumb); - lines = 0; - if (opt.index_show_name) - gib_imlib_text_draw(td.im_main, - td.font_main, NULL, - x + x_offset_name, - y + opt.thumb_h + (lines++ * (th + 2)) + 2, - file->name, IMLIB_TEXT_TO_RIGHT, - 255, 255, 255, 255); - if (opt.index_show_dim) - gib_imlib_text_draw(td.im_main, - td.font_main, NULL, - x + x_offset_dim, - y + opt.thumb_h + (lines++ * (th + 2)) + 2, - create_index_dimension_string(orig_w, orig_h), - IMLIB_TEXT_TO_RIGHT, 255, 255, 255, 255); - if (opt.index_show_size) - gib_imlib_text_draw(td.im_main, - td.font_main, NULL, - x + x_offset_size, - y + opt.thumb_h + (lines++ * (th + 2)) + 2, - create_index_size_string(file->filename), - IMLIB_TEXT_TO_RIGHT, 255, 255, 255, 255); + lineno = 0; + if (opt.index_info) { + line = lines = feh_wrap_string(create_index_string(file), + opt.thumb_w * 3, td.font_main, NULL); + + while (line) { + gib_imlib_get_text_size(td.font_main, (char *) line -> data, + NULL, &fw, &fh, IMLIB_TEXT_TO_RIGHT); + gib_imlib_text_draw(td.im_main, td.font_main, NULL, + x + ((td.text_area_w - fw) >> 1), + y + opt.thumb_h + (lineno++ * (th + 2)) + 2, + (char *) line->data, + IMLIB_TEXT_TO_RIGHT, 255, 255, 255, 255); + line = line->next; + } + gib_list_free_and_data(lines); + } if (td.vertical) y += td.thumb_tot_h; @@ -424,40 +396,6 @@ void init_thumbnail_mode(void) return; } -static char *create_index_size_string(char *file) -{ - static char str[50]; - int size = 0; - double kbs = 0.0; - struct stat st; - - if (stat(file, &st)) - kbs = 0.0; - else { - size = st.st_size; - kbs = (double) size / 1000; - } - - snprintf(str, sizeof(str), "%.2fKb", kbs); - return(str); -} - -static char *create_index_dimension_string(int w, int h) -{ - static char str[50]; - - snprintf(str, sizeof(str), "%dx%d", w, h); - return(str); -} - -static char *create_index_title_string(int num, int w, int h) -{ - static char str[50]; - - snprintf(str, sizeof(str), PACKAGE " index - %d thumbnails, %d by %d pixels", num, w, h); - return(str); -} - feh_thumbnail *feh_thumbnail_new(feh_file * file, int x, int y, int w, int h) { feh_thumbnail *thumb; @@ -606,23 +544,8 @@ void feh_thumbnail_calculate_geometry(void) for (l = filelist; l; l = l->next) { file = FEH_FILE(l->data); td.text_area_w = opt.thumb_w; - if (opt.index_show_name) { - gib_imlib_get_text_size(td.font_main, file->name, NULL, - &fw, &fh, IMLIB_TEXT_TO_RIGHT); - if (fw > td.text_area_w) - td.text_area_w = fw; - } - if (opt.index_show_dim) { - gib_imlib_get_text_size(td.font_main, - create_index_dimension_string(1000, 1000), - NULL, &fw, &fh, IMLIB_TEXT_TO_RIGHT); - if (fw > td.text_area_w) - td.text_area_w = fw; - } - if (opt.index_show_size) { - gib_imlib_get_text_size(td.font_main, - create_index_size_string(file->filename), - NULL, &fw, &fh, IMLIB_TEXT_TO_RIGHT); + if (opt.index_info) { + get_index_string_dim(file, td.font_main, &fw, &fh); if (fw > td.text_area_w) td.text_area_w = fw; } @@ -654,23 +577,8 @@ void feh_thumbnail_calculate_geometry(void) file = FEH_FILE(l->data); td.text_area_w = opt.thumb_w; /* Calc width of text */ - if (opt.index_show_name) { - gib_imlib_get_text_size(td.font_main, file->name, NULL, - &fw, &fh, IMLIB_TEXT_TO_RIGHT); - if (fw > td.text_area_w) - td.text_area_w = fw; - } - if (opt.index_show_dim) { - gib_imlib_get_text_size(td.font_main, - create_index_dimension_string(1000, 1000), - NULL, &fw, &fh, IMLIB_TEXT_TO_RIGHT); - if (fw > td.text_area_w) - td.text_area_w = fw; - } - if (opt.index_show_size) { - gib_imlib_get_text_size(td.font_main, - create_index_size_string(file->filename), - NULL, &fw, &fh, IMLIB_TEXT_TO_RIGHT); + if (opt.index_info) { + get_index_string_dim(file, td.font_main, &fw, &fh); if (fw > td.text_area_w) td.text_area_w = fw; } @@ -697,23 +605,8 @@ void feh_thumbnail_calculate_geometry(void) for (l = filelist; l; l = l->next) { file = FEH_FILE(l->data); td.text_area_w = opt.thumb_w; - if (opt.index_show_name) { - gib_imlib_get_text_size(td.font_main, file->name, NULL, - &fw, &fh, IMLIB_TEXT_TO_RIGHT); - if (fw > td.text_area_w) - td.text_area_w = fw; - } - if (opt.index_show_dim) { - gib_imlib_get_text_size(td.font_main, - create_index_dimension_string(1000, 1000), - NULL, &fw, &fh, IMLIB_TEXT_TO_RIGHT); - if (fw > td.text_area_w) - td.text_area_w = fw; - } - if (opt.index_show_size) { - gib_imlib_get_text_size(td.font_main, - create_index_size_string(file->filename), - NULL, &fw, &fh, IMLIB_TEXT_TO_RIGHT); + if (opt.index_info) { + get_index_string_dim(file, td.font_main, &fw, &fh); if (fw > td.text_area_w) td.text_area_w = fw; } |