From fba30a68493fc749311db6e99ee9881b1fad5af0 Mon Sep 17 00:00:00 2001 From: Petr Baudis Date: Sun, 2 Oct 2011 20:20:28 +0200 Subject: [PATCH] [wip] draw_images(): Clean up pixel/character and box handling --- src/viewer/text/draw.c | 38 +++++++++++++++++--------------------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/src/viewer/text/draw.c b/src/viewer/text/draw.c index f257d1ec..f0b566af 100644 --- a/src/viewer/text/draw.c +++ b/src/viewer/text/draw.c @@ -173,7 +173,12 @@ draw_images(struct session *ses, struct document_view *doc_view, struct view_sta struct terminal *term = ses->tab->term; int chw, chh; int i, cnt = 1; - struct box vs_box; + /* @vs_pixbox is a bounding box representing the viewport in + * the document (coordinates relative to document top left), while + * @win_pixbox is a bounding box representing the screen tab window. + * "Pixbox" means that the dimensions aren't characters but pixels. */ + struct box win_pixbox; + struct box vs_pixbox; assert(document && term); if_assert_failed return; @@ -183,20 +188,15 @@ draw_images(struct session *ses, struct document_view *doc_view, struct view_sta chh = term->yres / term->height; //printf("RES %d/%d->%d %d/%d->%d\n", term->xres, term->width, chw, term->yres, term->height, chh); - /* @vs_box is a bounding box representing the viewport in the document - * (coordinates relative to document top left), while - * @win_box is a bounding box representing the screen tab window. */ - copy_box(&vs_box, win_box); - vs_box.x = vs->x; - vs_box.y = vs->y; + set_box(&win_pixbox, win_box->x * chw, win_box->y * chh, win_box->width * chw, win_box->height * chh); + set_box(&vs_pixbox, vs->x * chw, vs->y * chh, win_pixbox.width, win_pixbox.height); //printf("ni %d\n", document->nimages); for (i = 0; i < document->nimages; i++) { struct image *img = &document->images[i]; struct cache_entry *cached; - /* XXX: x,y in chars, width,height in pixels */ - struct box screen_img; + struct box img_pixbox; /* Fetch cache entry. */ cached = get_redirected_cache_entry(img->uri); @@ -213,20 +213,16 @@ draw_images(struct session *ses, struct document_view *doc_view, struct view_sta if (img->h < 0) img->h = h; } - set_box(&screen_img, img->pos.x - vs_box.x, img->pos.y - vs_box.y, img->w, img->h); + set_box(&img_pixbox, img->pos.x * chw, img->pos.y * chh, img->w, img->h); - //printf("imgpos %d %d,%d\n", i, img->pos.x, img->pos.y); + if (is_in_box(&vs_pixbox, img_pixbox.x, img_pixbox.y)) { + /* Arrange the image in the tab window bounding box. */ + img_pixbox.x = win_pixbox.x + img_pixbox.x - vs_pixbox.x; + img_pixbox.y = win_pixbox.y + img_pixbox.y - vs_pixbox.y; + img_pixbox.width = int_min(img_pixbox.width, win_pixbox.width - img_pixbox.x); + img_pixbox.height = int_min(img_pixbox.height, win_pixbox.height - img_pixbox.y); - if (is_in_box(&vs_box, img->pos.x, img->pos.y)) { - struct box pixel_box; - - /* Trim image by bounding box. */ - screen_img.width = int_min(screen_img.width, (win_box->width - screen_img.x) * chw); - screen_img.height = int_min(screen_img.height, (win_box->height - screen_img.y) * chh); - /* Create box. */ - set_box(&pixel_box, (win_box->x + screen_img.x) * chw, (win_box->y + screen_img.y) * chh, screen_img.width, screen_img.height); - - show_image(term, cnt++, &pixel_box, cached); + show_image(term, cnt++, &img_pixbox, cached); } } -- 2.11.4.GIT