[gnome-photos] tool-crop: Restrain the selection when changing aspect ratios



commit 4f3adb0e61475bfff5bbb40d8926be97f9a2503f
Author: Katarina Gresova <gresova11 gmail com>
Date:   Thu Mar 30 00:54:50 2017 +0200

    tool-crop: Restrain the selection when changing aspect ratios
    
    If the existing crop area is too close to the boundaries of the image,
    then changing the aspect ratio can make it exceed the image. For
    example, if we had a square selection that touched one edge, or covered
    the entire width of a portrait, then changing the aspect ratio would
    make it exceed the horizontal limits of the image.
    
    In such cases, it is more important to ensure that the selection fits
    inside the image than to retain its centre and area.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=765136

 src/photos-tool-crop.c |   20 ++++++++++++++++++++
 1 files changed, 20 insertions(+), 0 deletions(-)
---
diff --git a/src/photos-tool-crop.c b/src/photos-tool-crop.c
index 46d7a27..28c1fe4 100644
--- a/src/photos-tool-crop.c
+++ b/src/photos-tool-crop.c
@@ -274,8 +274,28 @@ photos_tool_crop_change_constraint (PhotosToolCrop *self)
 
   self->crop_height = sqrt (old_area / self->crop_aspect_ratio);
   self->crop_width = sqrt (old_area * self->crop_aspect_ratio);
+
+  if (self->crop_height > self->bbox_zoomed.height)
+    {
+      self->crop_height = self->bbox_zoomed.height;
+      self->crop_width = self->crop_height * self->crop_aspect_ratio;
+    }
+
+  if (self->crop_width > self->bbox_zoomed.width)
+    {
+      self->crop_width = self->bbox_zoomed.width;
+      self->crop_height = self->crop_width / self->crop_aspect_ratio;
+    }
+
   self->crop_x = crop_center_x - self->crop_width / 2.0;
+  self->crop_x = CLAMP (self->crop_x,
+                        0.0,
+                        self->bbox_zoomed.width - self->crop_width);
+
   self->crop_y = crop_center_y - self->crop_height / 2.0;
+  self->crop_y = CLAMP (self->crop_y,
+                        0.0,
+                        self->bbox_zoomed.height - self->crop_height);
 
   photos_tool_crop_surface_draw (self);
   photos_tool_crop_redraw_damaged_area (self);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]