[gnome-photos/gnome-3-22] 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-22] tool-crop: Restrain the selection when changing aspect ratios
- Date: Thu, 6 Apr 2017 08:00:54 +0000 (UTC)
commit 60619e47a59fd9430cdc9fac417a51840ac779d7
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 81177a5..56c3525 100644
--- a/src/photos-tool-crop.c
+++ b/src/photos-tool-crop.c
@@ -287,8 +287,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]