From 8919204a2e666e12216240a792bfff7a391d4d43 Mon Sep 17 00:00:00 2001 From: Bert Date: Wed, 16 Feb 2011 18:16:00 +0100 Subject: Render thumbnails --- main.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'main.c') diff --git a/main.c b/main.c index 602cc60..f4afcf0 100644 --- a/main.c +++ b/main.c @@ -27,6 +27,7 @@ #include #include +#include "config.h" #include "image.h" #include "options.h" #include "util.h" @@ -38,6 +39,7 @@ typedef enum appmode_e { } appmode_t; void update_title(); +void render_thumbs(); int check_append(const char*); void read_dir_rec(const char*); void run(); @@ -53,6 +55,7 @@ int filecnt, fileidx; size_t filesize; thumb_t *thumbs; +int tvis, tcols, trows; #define TITLE_LEN 256 char win_title[TITLE_LEN]; @@ -137,6 +140,7 @@ int main(int argc, char **argv) { if (options->thumbnails == 2) { mode = MODE_THUMBS; + render_thumbs(); } else { mode = MODE_NORMAL; load_image(); @@ -175,6 +179,35 @@ void update_title() { win_set_title(&win, win_title); } +void render_thumbs() { + int i, cnt, x, y; + + tcols = win.w / (THUMB_SIZE + 10); + trows = win.h / (THUMB_SIZE + 10); + + x = win.w - tcols * (THUMB_SIZE + 10) + 5; + y = win.h - trows * (THUMB_SIZE + 10) + 5; + cnt = MIN(tcols * trows, filecnt); + + win_clear(&win); + + i = 0; + while (i < cnt) { + thumbs[i].x = x + (THUMB_SIZE - thumbs[i].w) / 2; + thumbs[i].y = y + (THUMB_SIZE - thumbs[i].h) / 2; + win_draw_pixmap(&win, thumbs[i].pm, thumbs[i].x, thumbs[i].y, thumbs[i].w, + thumbs[i].h); + if (++i % tcols == 0) { + x = win.w - tcols * (THUMB_SIZE + 10) + 5; + y += THUMB_SIZE + 10; + } else { + x += THUMB_SIZE + 10; + } + } + + win_draw(&win); +} + int check_append(const char *filename) { if (!filename) return 0; -- cgit v1.2.3-54-g00ecf