[gnome-photos] tool-crop: Decouple crop rectangle updates from drawing



commit 200aaba21b6afeccd9ec93c6893dd2bebfdf8b77
Author: Debarshi Ray <debarshir gnome org>
Date:   Wed Jan 10 18:11:01 2018 +0100

    tool-crop: Decouple crop rectangle updates from drawing
    
    A subsequent commit will animate changes to the crop rectangle caused
    by changing the active constraint or its orientation. The size and
    position of the crop rectangle used to crop the image will still jump
    to its final intended values, but the visual on-screen representation
    of it will slowly transition to the final state through a series of
    intermediate temporary states.
    
    This requires the ability to calculate the final size and position of
    the crop rectangle without any drawing. The drawing will be driven
    separately with EggAnimation.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=791274

 src/photos-tool-crop.c | 121 ++++++++++++++++++++++++++-----------------------
 1 file changed, 65 insertions(+), 56 deletions(-)
---
diff --git a/src/photos-tool-crop.c b/src/photos-tool-crop.c
index e0cf394b..9e8a4d96 100644
--- a/src/photos-tool-crop.c
+++ b/src/photos-tool-crop.c
@@ -302,49 +302,6 @@ photos_tool_crop_surface_draw (PhotosToolCrop *self)
 }
 
 
-static void
-photos_tool_crop_change_constraint (PhotosToolCrop *self)
-{
-  gdouble crop_center_x;
-  gdouble crop_center_y;
-  gdouble old_area;
-
-  photos_tool_crop_redraw_damaged_area (self);
-
-  crop_center_x = self->crop_x + self->crop_width / 2.0;
-  crop_center_y = self->crop_y + self->crop_height / 2.0;
-  old_area = self->crop_height * self->crop_width;
-
-  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);
-}
-
-
 static gint
 photos_tool_crop_get_active (PhotosToolCrop *self)
 {
@@ -831,6 +788,44 @@ photos_tool_crop_set_location (PhotosToolCrop *self, gdouble event_x, gdouble ev
 }
 
 
+static void
+photos_tool_crop_update_crop_after_constraint_changed (PhotosToolCrop *self)
+{
+  gdouble crop_center_x;
+  gdouble crop_center_y;
+  gdouble old_area;
+
+  crop_center_x = self->crop_x + self->crop_width / 2.0;
+  crop_center_y = self->crop_y + self->crop_height / 2.0;
+  old_area = self->crop_height * self->crop_width;
+
+  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);
+}
+
+
 static void
 photos_tool_crop_active_changed (PhotosToolCrop *self)
 {
@@ -847,7 +842,12 @@ photos_tool_crop_active_changed (PhotosToolCrop *self)
   if (self->crop_aspect_ratio < 0.0)
     return;
 
-  photos_tool_crop_change_constraint (self);
+  photos_tool_crop_redraw_damaged_area (self);
+
+  photos_tool_crop_update_crop_after_constraint_changed (self);
+
+  photos_tool_crop_surface_draw (self);
+  photos_tool_crop_redraw_damaged_area (self);
 }
 
 
@@ -951,30 +951,39 @@ photos_tool_crop_set_active (PhotosToolCrop *self, gint active, GtkToggleButton
 
 
 static void
-photos_tool_crop_size_allocate (PhotosToolCrop *self, GdkRectangle *allocation)
+photos_tool_crop_update_crop_after_size_allocate (PhotosToolCrop *self,
+                                                  GeglRectangle *bbox_zoomed_new,
+                                                  GeglRectangle *bbox_zoomed_old)
 {
   gdouble crop_height_ratio;
   gdouble crop_width_ratio;
   gdouble crop_x_ratio;
   gdouble crop_y_ratio;
-  gdouble zoom;
 
-  crop_height_ratio = self->crop_height / (gdouble) self->bbox_zoomed.height;
-  crop_width_ratio = self->crop_width / (gdouble) self->bbox_zoomed.width;
-  crop_x_ratio = self->crop_x / (gdouble) self->bbox_zoomed.width;
-  crop_y_ratio = self->crop_y / (gdouble) self->bbox_zoomed.height;
+  crop_height_ratio = self->crop_height / (gdouble) bbox_zoomed_old->height;
+  crop_width_ratio = self->crop_width / (gdouble) bbox_zoomed_old->width;
+  crop_x_ratio = self->crop_x / (gdouble) bbox_zoomed_old->width;
+  crop_y_ratio = self->crop_y / (gdouble) bbox_zoomed_old->height;
+
+  self->crop_height = crop_height_ratio * (gdouble) bbox_zoomed_new->height;
+  self->crop_width = crop_width_ratio * (gdouble) bbox_zoomed_new->width;
+  self->crop_x = crop_x_ratio * (gdouble) bbox_zoomed_new->width;
+  self->crop_y = crop_y_ratio * (gdouble) bbox_zoomed_new->height;
+}
+
+
+static void
+photos_tool_crop_size_allocate (PhotosToolCrop *self, GdkRectangle *allocation)
+{
+  GeglRectangle bbox_zoomed_old = self->bbox_zoomed;
+  gdouble zoom;
 
   zoom = photos_image_view_get_zoom (PHOTOS_IMAGE_VIEW (self->view));
   self->bbox_zoomed.height = (gint) (zoom * self->bbox_source.height + 0.5);
   self->bbox_zoomed.width = (gint) (zoom * self->bbox_source.width + 0.5);
 
   photos_tool_crop_surface_create (self);
-
-  self->crop_height = crop_height_ratio * (gdouble) self->bbox_zoomed.height;
-  self->crop_width = crop_width_ratio * (gdouble) self->bbox_zoomed.width;
-  self->crop_x = crop_x_ratio * (gdouble) self->bbox_zoomed.width;
-  self->crop_y = crop_y_ratio * (gdouble) self->bbox_zoomed.height;
-
+  photos_tool_crop_update_crop_after_size_allocate (self, &self->bbox_zoomed, &bbox_zoomed_old);
   photos_tool_crop_surface_draw (self);
 }
 


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