From 88791d22692d624755557aa7324617c7ee6418dd Mon Sep 17 00:00:00 2001 From: Colin Clark Date: Wed, 14 Nov 2018 10:15:23 +0000 Subject: [PATCH] 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. --- src/image.c | 41 ++++++++++++++++++++++++++++++++++++++--- src/pixbuf-renderer.c | 9 +++++++-- 2 files changed, 45 insertions(+), 5 deletions(-) diff --git a/src/image.c b/src/image.c index ac57bb44..e66227c1 100644 --- a/src/image.c +++ b/src/image.c @@ -154,8 +154,24 @@ static void image_press_cb(PixbufRenderer *pr, GdkEventButton *event, gpointer d 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 @@ static void image_drag_cb(PixbufRenderer *pr, GdkEventMotion *event, gpointer da 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); diff --git a/src/pixbuf-renderer.c b/src/pixbuf-renderer.c index 12756be7..aded467f 100644 --- a/src/pixbuf-renderer.c +++ b/src/pixbuf-renderer.c @@ -2879,10 +2879,15 @@ gboolean pixbuf_renderer_get_mouse_position(PixbufRenderer *pr, gint *x_pixel_re 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; -- 2.20.1