[gnome-photos] gegl-gtk-view, gegl-gtk-view-helper, tool-crop: Rename scale to zoom



commit 08e6554e7ac567d9a6d6742aa4a845ce3e42a819
Author: Debarshi Ray <debarshir gnome org>
Date:   Wed Dec 2 11:18:44 2015 +0100

    gegl-gtk-view, gegl-gtk-view-helper, tool-crop: Rename scale to zoom
    
    Terms like "device_scale", "scale" or "scale_factor" are widely used
    in Cairo and GTK+ to refer to the HiDpi scale factor that maps from
    logical window co-ordinates to the actual device pixels. It's
    confusing to use the same term to refer to the item's zoom
    factor. Especially when both concepts are used in the same class.
    
    I don't know if we should rename "autoscale", and, if we do, what the
    new name should be. We can revisit it later.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=758352

 src/gegl-gtk-view-helper.c |   42 +++++++++++-----------
 src/gegl-gtk-view-helper.h |    7 ++--
 src/gegl-gtk-view.c        |   36 +++++++++---------
 src/gegl-gtk-view.h        |    4 +-
 src/photos-tool-crop.c     |   84 ++++++++++++++++++++++----------------------
 5 files changed, 87 insertions(+), 86 deletions(-)
---
diff --git a/src/gegl-gtk-view-helper.c b/src/gegl-gtk-view-helper.c
index 0adbe2b..0e9e252 100644
--- a/src/gegl-gtk-view-helper.c
+++ b/src/gegl-gtk-view-helper.c
@@ -82,7 +82,7 @@ view_helper_init(ViewHelper *self)
     self->node        = NULL;
     self->x           = 0;
     self->y           = 0;
-    self->scale       = 1.0;
+    self->zoom        = 1.0;
     self->scale_factor = 1;
     self->autoscale_policy = GEGL_GTK_VIEW_AUTOSCALE_CONTENT;
     self->block = FALSE;
@@ -105,10 +105,10 @@ model_rect_to_view_rect(ViewHelper *self, GeglRectangle *rect)
 {
     GeglRectangle temp;
 
-    temp.x = self->scale * (rect->x) - self->x;
-    temp.y = self->scale * (rect->y) - self->y;
-    temp.width = ceil(self->scale * rect->width);
-    temp.height = ceil(self->scale * rect->height);
+    temp.x = self->zoom * (rect->x) - self->x;
+    temp.y = self->zoom * (rect->y) - self->y;
+    temp.width = ceil(self->zoom * rect->width);
+    temp.height = ceil(self->zoom * rect->height);
 
     *rect = temp;
 }
@@ -128,14 +128,14 @@ update_autoscale(ViewHelper *self)
 
     if (self->autoscale_policy == GEGL_GTK_VIEW_AUTOSCALE_WIDGET) {
         /* Request widget size change */
-        /* XXX: Should we reset scale/x/y here? */
+        /* XXX: Should we reset zoom/x/y here? */
         model_rect_to_view_rect(self, &bbox);
         g_signal_emit(self, view_helper_signals[SIGNAL_SIZE_CHANGED],
                       0, &bbox, NULL);
 
     } else if (self->autoscale_policy == GEGL_GTK_VIEW_AUTOSCALE_CONTENT) {
         /* Calculate and set scaling factor to make the content fit inside */
-        float scale = 1.0;
+        float zoom = 1.0;
         const gint real_viewport_height = viewport.height * self->scale_factor;
         const gint real_viewport_width = viewport.width * self->scale_factor;
 
@@ -144,15 +144,15 @@ update_autoscale(ViewHelper *self)
             float height_ratio = bbox.height / (float)real_viewport_height;
             float max_ratio = width_ratio >= height_ratio ? width_ratio : height_ratio;
 
-            scale = 1.0 / max_ratio;
+            zoom = 1.0 / max_ratio;
 
-            bbox.width = (gint) (scale * bbox.width + 0.5);
-            bbox.height = (gint) (scale * bbox.height + 0.5);
-            bbox.x = (gint) (scale * bbox.x + 0.5);
-            bbox.y = (gint) (scale * bbox.y + 0.5);
+            bbox.width = (gint) (zoom * bbox.width + 0.5);
+            bbox.height = (gint) (zoom * bbox.height + 0.5);
+            bbox.x = (gint) (zoom * bbox.x + 0.5);
+            bbox.y = (gint) (zoom * bbox.y + 0.5);
         }
 
-        self->scale = scale;
+        self->zoom = zoom;
 
         /* At this point, viewport is definitely bigger than bbox. */
         self->x = (bbox.width - real_viewport_width) / 2.0 + bbox.x;
@@ -206,7 +206,7 @@ view_helper_draw(ViewHelper *self, cairo_t *cr, GdkRectangle *rect)
     start = g_get_monotonic_time ();
 
     gegl_node_blit(self->node,
-                   self->scale,
+                   self->zoom,
                    &roi,
                    babl_format("cairo-ARGB32"),
                    (gpointer)buf,
@@ -284,20 +284,20 @@ view_helper_get_node(ViewHelper *self)
 }
 
 void
-view_helper_set_scale(ViewHelper *self, float scale)
+view_helper_set_zoom(ViewHelper *self, float zoom)
 {
-    if (self->scale == scale)
+    if (self->zoom == zoom)
         return;
 
-    self->scale = scale;
+    self->zoom = zoom;
     update_autoscale(self);
     trigger_redraw(self, NULL);
 }
 
 float
-view_helper_get_scale(ViewHelper *self)
+view_helper_get_zoom(ViewHelper *self)
 {
-    return self->scale;
+    return self->zoom;
 }
 
 float
@@ -317,12 +317,12 @@ void view_helper_get_transformation(ViewHelper *self, GeglMatrix3 *matrix)
     /* XXX: Below gives the right result, but is it really the
      * way we want transformations to work? */
 
-    matrix->coeff [0][0] = self->scale; /* xx */
+    matrix->coeff [0][0] = self->zoom; /* xx */
     matrix->coeff [0][1] = 0.0; /* xy */
     matrix->coeff [0][2] = -self->x; /* x0 */
 
     matrix->coeff [1][0] = 0.0; /* yx */
-    matrix->coeff [1][1] = self->scale; /* yy */
+    matrix->coeff [1][1] = self->zoom; /* yy */
     matrix->coeff [1][2] = -self->y; /* y0 */
 
     matrix->coeff [2][0] = 0.0;
diff --git a/src/gegl-gtk-view-helper.h b/src/gegl-gtk-view-helper.h
index 19af9ae..5689d19 100644
--- a/src/gegl-gtk-view-helper.h
+++ b/src/gegl-gtk-view-helper.h
@@ -15,6 +15,7 @@
  *
  * Copyright (C) 2003, 2004, 2006 Øyvind Kolås <pippin gimp org>
  * Copyright (C) 2011 Jon Nordby <jononor gmail com>
+ * Copyright (C) 2015 Red Hat, Inc.
  */
 
 #ifndef __VIEW_HELPER_H__
@@ -44,7 +45,7 @@ struct _ViewHelper {
     GeglNode      *node;
     gfloat         x;
     gfloat         y;
-    gdouble        scale;
+    gdouble        zoom;
     gint           scale_factor;
     gboolean       block;    /* blocking render */
     GeglGtkViewAutoscale autoscale_policy;
@@ -69,8 +70,8 @@ void view_helper_set_allocation(ViewHelper *self, GdkRectangle *allocation, gint
 void view_helper_set_node(ViewHelper *self, GeglNode *node);
 GeglNode *view_helper_get_node(ViewHelper *self);
 
-void view_helper_set_scale(ViewHelper *self, float scale);
-float view_helper_get_scale(ViewHelper *self);
+void view_helper_set_zoom(ViewHelper *self, float zoom);
+float view_helper_get_zoom(ViewHelper *self);
 
 float view_helper_get_x(ViewHelper *self);
 
diff --git a/src/gegl-gtk-view.c b/src/gegl-gtk-view.c
index 41c08ff..21ec610 100644
--- a/src/gegl-gtk-view.c
+++ b/src/gegl-gtk-view.c
@@ -49,7 +49,7 @@
  * The widget can show a transformed view of the GeglNode. Scaling and
  * transformations are supported, as well as autoscaling.
  * For manual control over the transformation see
- * methods gegl_gtk_view_set_scale(), gegl_gtk_view_set_x() and
+ * methods gegl_gtk_view_set_zoom(), gegl_gtk_view_set_x() and
  * gegl_gtk_view_set_y(), or use the corresponding properties.
  * For changing the autoscaling behavior, see
  * gegl_gtk_view_set_autoscale_policy()
@@ -85,7 +85,7 @@ enum {
     PROP_NODE,
     PROP_X,
     PROP_Y,
-    PROP_SCALE,
+    PROP_ZOOM,
     PROP_BLOCK,
     PROP_AUTOSCALE_POLICY
 };
@@ -167,9 +167,9 @@ gegl_gtk_view_class_init(GeglGtkViewClass *klass)
                                             "Y origin",
                                             -G_MAXFLOAT, G_MAXFLOAT, 0.0,
                                             G_PARAM_READABLE));
-    g_object_class_install_property(gobject_class, PROP_SCALE,
-                                    g_param_spec_double("scale",
-                                            "Scale",
+    g_object_class_install_property(gobject_class, PROP_ZOOM,
+                                    g_param_spec_double("zoom",
+                                            "Zoom",
                                             "Zoom factor",
                                             0.0, 100.0, 1.00,
                                             G_PARAM_CONSTRUCT |
@@ -288,8 +288,8 @@ set_property(GObject      *gobject,
     case PROP_BLOCK:
         priv->block = g_value_get_boolean(value);
         break;
-    case PROP_SCALE:
-        gegl_gtk_view_set_scale(self, g_value_get_double(value));
+    case PROP_ZOOM:
+        gegl_gtk_view_set_zoom(self, g_value_get_double(value));
         break;
     case PROP_AUTOSCALE_POLICY:
         gegl_gtk_view_set_autoscale_policy(self, g_value_get_enum(value));
@@ -323,8 +323,8 @@ get_property(GObject      *gobject,
     case PROP_Y:
         g_value_set_float(value, gegl_gtk_view_get_y(self));
         break;
-    case PROP_SCALE:
-        g_value_set_double(value, gegl_gtk_view_get_scale(self));
+    case PROP_ZOOM:
+        g_value_set_double(value, gegl_gtk_view_get_zoom(self));
         break;
     case PROP_AUTOSCALE_POLICY:
         g_value_set_enum(value, gegl_gtk_view_get_autoscale_policy(self));
@@ -498,30 +498,30 @@ gegl_gtk_view_get_node(GeglGtkView *self)
 }
 
 /**
- * gegl_gtk_view_set_scale:
+ * gegl_gtk_view_set_zoom:
  * @self: A #GeglGtkView
- * @scale:
+ * @zoom:
  *
- * Setter for the :scale property
+ * Setter for the :zoom property
  **/
 void
-gegl_gtk_view_set_scale(GeglGtkView *self, float scale)
+gegl_gtk_view_set_zoom(GeglGtkView *self, float zoom)
 {
-    view_helper_set_scale(GET_PRIVATE(self), scale);
+    view_helper_set_zoom(GET_PRIVATE(self), zoom);
 }
 
 /**
- * gegl_gtk_view_get_scale:
+ * gegl_gtk_view_get_zoom:
  * @self: A #GeglGtkView
  *
- * Getter for the :scale property
+ * Getter for the :zoom property
  *
  * Returns:
  **/
 float
-gegl_gtk_view_get_scale(GeglGtkView *self)
+gegl_gtk_view_get_zoom(GeglGtkView *self)
 {
-    return view_helper_get_scale(GET_PRIVATE(self));
+    return view_helper_get_zoom(GET_PRIVATE(self));
 }
 
 /**
diff --git a/src/gegl-gtk-view.h b/src/gegl-gtk-view.h
index 957f10f..4b16bd8 100644
--- a/src/gegl-gtk-view.h
+++ b/src/gegl-gtk-view.h
@@ -59,8 +59,8 @@ GeglGtkView *gegl_gtk_view_new_for_node(GeglNode *node);
 void gegl_gtk_view_set_node(GeglGtkView *self, GeglNode *node);
 GeglNode *gegl_gtk_view_get_node(GeglGtkView *self);
 
-void gegl_gtk_view_set_scale(GeglGtkView *self, float scale);
-float gegl_gtk_view_get_scale(GeglGtkView *self);
+void gegl_gtk_view_set_zoom(GeglGtkView *self, float zoom);
+float gegl_gtk_view_get_zoom(GeglGtkView *self);
 
 float gegl_gtk_view_get_x(GeglGtkView *self);
 
diff --git a/src/photos-tool-crop.c b/src/photos-tool-crop.c
index a0468cc..539e216 100644
--- a/src/photos-tool-crop.c
+++ b/src/photos-tool-crop.c
@@ -60,7 +60,7 @@ struct _PhotosToolCrop
 {
   PhotosTool parent_instance;
   GAction *crop;
-  GeglRectangle bbox_scaled;
+  GeglRectangle bbox_zoomed;
   GeglRectangle bbox_source;
   GtkListStore *model;
   GtkWidget *box;
@@ -235,18 +235,18 @@ static void
 photos_tool_crop_surface_create (PhotosToolCrop *self)
 {
   GdkWindow *window;
-  gfloat scale;
+  gfloat zoom;
 
   g_clear_pointer (&self->surface, (GDestroyNotify) cairo_surface_destroy);
 
   window = gtk_widget_get_window (self->view);
-  scale = gegl_gtk_view_get_scale (GEGL_GTK_VIEW (self->view));
-  self->bbox_scaled.height = (gint) (scale * self->bbox_source.height + 0.5);
-  self->bbox_scaled.width = (gint) (scale * self->bbox_source.width + 0.5);
+  zoom = gegl_gtk_view_get_zoom (GEGL_GTK_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);
   self->surface = gdk_window_create_similar_surface (window,
                                                      CAIRO_CONTENT_COLOR_ALPHA,
-                                                     self->bbox_scaled.width,
-                                                     self->bbox_scaled.height);
+                                                     self->bbox_zoomed.width,
+                                                     self->bbox_zoomed.height);
 }
 
 
@@ -340,17 +340,17 @@ photos_tool_crop_init_crop (PhotosToolCrop *self)
 
   if (self->crop_aspect_ratio < aspect_ratio)
     {
-      self->crop_height = 0.7 * self->bbox_scaled.height;
+      self->crop_height = 0.7 * self->bbox_zoomed.height;
       self->crop_width = self->crop_height * self->crop_aspect_ratio;
     }
   else
     {
-      self->crop_width = 0.7 * self->bbox_scaled.width;
+      self->crop_width = 0.7 * self->bbox_zoomed.width;
       self->crop_height = self->crop_width / self->crop_aspect_ratio;
     }
 
-  self->crop_x = ((gdouble) self->bbox_scaled.width - self->crop_width) / 2.0;
-  self->crop_y = ((gdouble) self->bbox_scaled.height - self->crop_height) / 2.0;
+  self->crop_x = ((gdouble) self->bbox_zoomed.width - self->crop_width) / 2.0;
+  self->crop_y = ((gdouble) self->bbox_zoomed.height - self->crop_height) / 2.0;
 
  out:
   photos_tool_crop_surface_draw (self);
@@ -578,8 +578,8 @@ photos_tool_crop_set_crop (PhotosToolCrop *self, gdouble event_x, gdouble event_
       {
         gboolean x_adj = FALSE;
         gboolean y_adj = FALSE;
-        gdouble bbox_scaled_height = (gdouble) self->bbox_scaled.height;
-        gdouble bbox_scaled_width = (gdouble) self->bbox_scaled.width;
+        gdouble bbox_zoomed_height = (gdouble) self->bbox_zoomed.height;
+        gdouble bbox_zoomed_width = (gdouble) self->bbox_zoomed.width;
 
         self->crop_x += delta_x;
         self->crop_y += delta_y;
@@ -598,15 +598,15 @@ photos_tool_crop_set_crop (PhotosToolCrop *self, gdouble event_x, gdouble event_
             y_adj = TRUE;
           }
 
-        if (self->crop_x + self->crop_width > bbox_scaled_width)
+        if (self->crop_x + self->crop_width > bbox_zoomed_width)
           {
-            self->crop_width = bbox_scaled_width - self->crop_x;
+            self->crop_width = bbox_zoomed_width - self->crop_x;
             x_adj = TRUE;
           }
 
-        if (self->crop_y + self->crop_height > bbox_scaled_height)
+        if (self->crop_y + self->crop_height > bbox_zoomed_height)
           {
-            self->crop_height = bbox_scaled_height - self->crop_y;
+            self->crop_height = bbox_zoomed_height - self->crop_y;
             y_adj = TRUE;
           }
 
@@ -616,7 +616,7 @@ photos_tool_crop_set_crop (PhotosToolCrop *self, gdouble event_x, gdouble event_
               self->crop_width = crop_width_old;
             else
               {
-                self->crop_x = bbox_scaled_width - crop_width_old;
+                self->crop_x = bbox_zoomed_width - crop_width_old;
                 self->crop_width = crop_width_old;
               }
           }
@@ -627,7 +627,7 @@ photos_tool_crop_set_crop (PhotosToolCrop *self, gdouble event_x, gdouble event_
               self->crop_height = crop_height_old;
             else
               {
-                self->crop_y = bbox_scaled_height - crop_height_old;
+                self->crop_y = bbox_zoomed_height - crop_height_old;
                 self->crop_height = crop_height_old;
               }
           }
@@ -672,9 +672,9 @@ photos_tool_crop_set_crop (PhotosToolCrop *self, gdouble event_x, gdouble event_
   if (self->crop_height < CROP_MIN_SIZE
       || self->crop_width < CROP_MIN_SIZE
       || self->crop_x < 0.0
-      || self->crop_x + self->crop_width > self->bbox_scaled.width
+      || self->crop_x + self->crop_width > self->bbox_zoomed.width
       || self->crop_y < 0.0
-      || self->crop_y + self->crop_height > self->bbox_scaled.height)
+      || self->crop_y + self->crop_height > self->bbox_zoomed.height)
     {
       self->crop_height = crop_height_old;
       self->crop_width = crop_width_old;
@@ -846,7 +846,7 @@ photos_tool_crop_process (GObject *source_object, GAsyncResult *res, gpointer us
   PhotosToolCrop *self = PHOTOS_TOOL_CROP (user_data);
   GError *error = NULL;
   PhotosBaseItem *item = PHOTOS_BASE_ITEM (source_object);
-  gfloat scale;
+  gfloat zoom;
   guint active;
 
   photos_base_item_process_finish (item, res, &error);
@@ -857,11 +857,11 @@ photos_tool_crop_process (GObject *source_object, GAsyncResult *res, gpointer us
       goto out;
     }
 
-  scale = gegl_gtk_view_get_scale (GEGL_GTK_VIEW (self->view));
-  self->crop_height *= scale;
-  self->crop_width *= scale;
-  self->crop_x *= scale;
-  self->crop_y *= scale;
+  zoom = gegl_gtk_view_get_zoom (GEGL_GTK_VIEW (self->view));
+  self->crop_height *= zoom;
+  self->crop_width *= zoom;
+  self->crop_x *= zoom;
+  self->crop_y *= zoom;
 
   self->crop_aspect_ratio = self->crop_width / self->crop_height;
   active = photos_tool_crop_find_constraint (self, self->crop_aspect_ratio);
@@ -892,17 +892,17 @@ photos_tool_crop_size_allocate (PhotosToolCrop *self, GdkRectangle *allocation)
   gdouble crop_x_ratio;
   gdouble crop_y_ratio;
 
-  crop_height_ratio = self->crop_height / (gdouble) self->bbox_scaled.height;
-  crop_width_ratio = self->crop_width / (gdouble) self->bbox_scaled.width;
-  crop_x_ratio = self->crop_x / (gdouble) self->bbox_scaled.width;
-  crop_y_ratio = self->crop_y / (gdouble) self->bbox_scaled.height;
+  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;
 
   photos_tool_crop_surface_create (self);
 
-  self->crop_height = crop_height_ratio * (gdouble) self->bbox_scaled.height;
-  self->crop_width = crop_width_ratio * (gdouble) self->bbox_scaled.width;
-  self->crop_x = crop_x_ratio * (gdouble) self->bbox_scaled.width;
-  self->crop_y = crop_y_ratio * (gdouble) self->bbox_scaled.height;
+  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_surface_draw (self);
 }
@@ -938,7 +938,7 @@ photos_tool_crop_activate (PhotosTool *tool, PhotosBaseItem *item, GeglGtkView *
       g_return_if_fail (y >= 0.0);
 
       /* These values are invalid until they are multiplied by the
-       * view's scale, which we won't know until we have finished
+       * view's zoom, which we won't know until we have finished
        * processing with the reset gegl:crop values.
        */
       self->crop_height = height;
@@ -982,16 +982,16 @@ photos_tool_crop_deactivate (PhotosTool *tool)
     {
       GVariantBuilder parameter;
       GVariantType *parameter_type;
-      gfloat scale;
+      gfloat zoom;
 
-      scale = gegl_gtk_view_get_scale (GEGL_GTK_VIEW (self->view));
+      zoom = gegl_gtk_view_get_zoom (GEGL_GTK_VIEW (self->view));
 
       parameter_type = g_variant_type_new ("a{sd}");
       g_variant_builder_init (&parameter, parameter_type);
-      g_variant_builder_add (&parameter, "{sd}", "height", self->crop_height / scale);
-      g_variant_builder_add (&parameter, "{sd}", "width", self->crop_width / scale);
-      g_variant_builder_add (&parameter, "{sd}", "x", self->crop_x / scale);
-      g_variant_builder_add (&parameter, "{sd}", "y", self->crop_y / scale);
+      g_variant_builder_add (&parameter, "{sd}", "height", self->crop_height / zoom);
+      g_variant_builder_add (&parameter, "{sd}", "width", self->crop_width / zoom);
+      g_variant_builder_add (&parameter, "{sd}", "x", self->crop_x / zoom);
+      g_variant_builder_add (&parameter, "{sd}", "y", self->crop_y / zoom);
       g_action_activate (self->crop, g_variant_builder_end (&parameter));
 
       g_variant_type_free (parameter_type);


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