[gnome-photos] image-view: Split out the code to check valid allocation and extent



commit b69f53e29e97f17bf75c908a87bf14dab413d105
Author: Debarshi Ray <debarshir gnome org>
Date:   Sun Oct 15 23:47:52 2017 +0200

    image-view: Split out the code to check valid allocation and extent
    
    This will make the subsequent commits easier to read.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=783922

 src/photos-image-view.c |   36 ++++++++++++++++++++++++++++--------
 1 files changed, 28 insertions(+), 8 deletions(-)
---
diff --git a/src/photos-image-view.c b/src/photos-image-view.c
index 740dab9..4333c65 100644
--- a/src/photos-image-view.c
+++ b/src/photos-image-view.c
@@ -96,6 +96,31 @@ static const guint ZOOM_ANIMATION_DURATION = 250; /* ms */
 static void photos_image_view_computed (PhotosImageView *self, GeglRectangle *rect);
 
 
+static gboolean
+photos_image_view_has_allocation_and_extent (PhotosImageView *self)
+{
+  GeglRectangle bbox;
+  GtkAllocation allocation;
+  gboolean ret_val = FALSE;
+
+  if (self->buffer == NULL)
+    goto out;
+
+  gtk_widget_get_allocation (GTK_WIDGET (self), &allocation);
+  if (allocation.width <= 0 || allocation.height <= 0)
+    goto out;
+
+  bbox = *gegl_buffer_get_extent (self->buffer);
+  if (bbox.width < 0 || bbox.height < 0)
+    goto out;
+
+  ret_val = TRUE;
+
+ out:
+  return ret_val;
+}
+
+
 static void
 photos_image_view_notify_zoom (GObject *object, GParamSpec *pspec, gpointer user_data)
 {
@@ -299,18 +324,13 @@ photos_image_view_update (PhotosImageView *self)
   if (self->node == NULL)
     goto out;
 
-  g_assert_true (GEGL_IS_BUFFER (self->buffer));
-
-  gtk_widget_get_allocation (GTK_WIDGET (self), &allocation);
-
-  if (allocation.width <= 0 || allocation.height <= 0)
+  if (!photos_image_view_has_allocation_and_extent (self))
     goto out;
 
+  gtk_widget_get_allocation (GTK_WIDGET (self), &allocation);
   bbox = *gegl_buffer_get_extent (self->buffer);
-  if (bbox.width < 0 || bbox.height < 0)
-    goto out;
-
   scale_factor = gtk_widget_get_scale_factor (GTK_WIDGET (self));
+
   viewport_height_real = allocation.height * scale_factor;
   viewport_width_real = allocation.width * scale_factor;
 


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