Mercurial > hg > forks > geeqie
changeset 2862:f105ca657cb3
Bug fix #251: Crop simulation
https://github.com/BestImageViewer/geeqie/issues/251
If the drawn rectangle started or ended outside the image area,
incorrect coordinates were returned.
The coordinates of the enclosed part of the image are now returned.
author | Colin Clark <colin.clark@cclark.uk> |
---|---|
date | Wed, 14 Nov 2018 10:15:23 +0000 |
parents | 727f2f8edf74 |
children | 4b92a65f8367 |
files | src/image.c src/pixbuf-renderer.c |
diffstat | 2 files changed, 45 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/src/image.c Thu Nov 08 12:26:09 2018 +0000 +++ b/src/image.c Wed Nov 14 10:15:23 2018 +0000 @@ -154,8 +154,24 @@ pixbuf_start_x = event->x; pixbuf_start_y = event->y; - image_start_x = x_pixel; - image_start_y = y_pixel; + + if (x_pixel == -1) + { + image_start_x = 0; + } + else + { + image_start_x = x_pixel; + } + + if (y_pixel == -1) + { + image_start_y = 0; + } + else + { + image_start_y = y_pixel; + } } if (rect_id) @@ -180,13 +196,32 @@ gint rect_height; GdkPixbuf *rect_pixbuf; gint x_pixel, y_pixel; + gint image_x_pixel, image_y_pixel; if (options->draw_rectangle) { pixbuf_renderer_get_image_size(pr, &width, &height); pixbuf_renderer_get_mouse_position(pr, &x_pixel, &y_pixel); - switch_coords_orientation(imd, x_pixel, y_pixel, width, height); + + if (x_pixel == -1) + { + image_x_pixel = width; + } + else + { + image_x_pixel = x_pixel; + } + if (y_pixel == -1) + { + image_y_pixel = height; + } + else + { + image_y_pixel = y_pixel; + } + + switch_coords_orientation(imd, image_x_pixel, image_y_pixel, width, height); if (rect_id) { pixbuf_renderer_overlay_remove((PixbufRenderer *)imd->pr, rect_id);
--- a/src/pixbuf-renderer.c Thu Nov 08 12:26:09 2018 +0000 +++ b/src/pixbuf-renderer.c Wed Nov 14 10:15:23 2018 +0000 @@ -2879,10 +2879,15 @@ x_pixel_clamped = CLAMP(x_pixel, 0, pr->image_width - 1); y_pixel_clamped = CLAMP(y_pixel, 0, pr->image_height - 1); - if(x_pixel != x_pixel_clamped || y_pixel != y_pixel_clamped) + if (x_pixel != x_pixel_clamped) { /* mouse is not on pr */ - x_pixel = y_pixel = -1; + x_pixel = -1; + } + if (y_pixel != y_pixel_clamped) + { + /* mouse is not on pr */ + y_pixel = -1; } *x_pixel_return = x_pixel;