[gnome-photos/gnome-3-24] tool-crop: Restrain the selection when changing aspect ratios
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-photos/gnome-3-24] tool-crop: Restrain the selection when changing aspect ratios
- Date: Thu, 6 Apr 2017 07:56:33 +0000 (UTC)
commit d92c71e1da7a2ccd860ba48a426eca3e4b327be1
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]