[gtk+/wip/baedert/gtkimageview: 262/275] Add GtkScalingImage



commit e37222c02ecbb5f735de9f0bfe29eb0bc1d420c0
Author: Timm Bäder <mail baedert org>
Date:   Sat Mar 19 08:55:23 2016 +0100

    Add GtkScalingImage

 gtk/gtkabstractimage.c |   24 ++++++++++++++++++++++++
 gtk/gtkabstractimage.h |   33 +++++++++++++++++++++++++++++++++
 gtk/gtkimageview.c     |   20 ++++++++++++++++----
 3 files changed, 73 insertions(+), 4 deletions(-)
---
diff --git a/gtk/gtkabstractimage.c b/gtk/gtkabstractimage.c
index 1256df5..ce2729d 100644
--- a/gtk/gtkabstractimage.c
+++ b/gtk/gtkabstractimage.c
@@ -283,3 +283,27 @@ gtk_surface_image_class_init (GtkSurfaceImageClass *klass)
 }
 
 /* }}} */
+
+/* GtkScalingImage {{{ */
+
+G_DEFINE_TYPE (GtkScalingImage, gtk_scaling_image, GTK_TYPE_ABSTRACT_IMAGE)
+
+static void
+gtk_scaling_image_init (GtkScalingImage *image)
+{
+
+}
+
+static void
+gtk_scaling_image_class_init (GtkScalingImageClass *image)
+{
+
+}
+
+void
+gtk_scaling_image_set_scale (GtkScalingImage *image, double scale)
+{
+  GTK_SCALING_IMAGE_GET_CLASS (image)->set_scale (image, scale);
+}
+
+/* }}} */
diff --git a/gtk/gtkabstractimage.h b/gtk/gtkabstractimage.h
index f0b7510..6711671 100644
--- a/gtk/gtkabstractimage.h
+++ b/gtk/gtkabstractimage.h
@@ -174,6 +174,39 @@ GtkSurfaceImage *gtk_surface_image_new (cairo_surface_t *surface);
 GDK_AVAILABLE_IN_3_20
 GtkSurfaceImage *gtk_surface_image_new_from_pixbuf (const GdkPixbuf *pixbuf, int scale_factor);
 
+/* ------------------------------------------------------------------------------------ */
+
+typedef struct _GtkScalingImage GtkScalingImage;
+typedef struct _GtkScalingImageClass GtkScalingImageClass;
+
+
+#define GTK_TYPE_SCALING_IMAGE           (gtk_scaling_image_get_type ())
+#define GTK_SCALING_IMAGE(obj)           (G_TYPE_CHECK_INSTANCE_CAST (obj, GTK_TYPE_SCALING_IMAGE, 
GtkScalingImage))
+#define GTK_SCALING_IMAGE_CLASS(cls)     (G_TYPE_CHECK_CLASS_CAST (cls, GTK_TYPE_SCALING_IMAGE, 
GtkScalingImageClass))
+#define GTK_IS_SCALING_IMAGE(obj)        (G_TYPE_CHECK_INSTANCE_TYPE (obj, GTK_TYPE_SCALING_IMAGE))
+#define GTK_IS_SCALING_IMAGE_CLASS(obj)  (G_TYPE_CHECK_CLASS_TYPE (obj, GTK_TYPE_SCALING_IMAGE))
+#define GTK_SCALING_IMAGE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_SCALING_IMAGE, 
GtkScalingImageClass))
+
+struct _GtkScalingImage
+{
+  GtkAbstractImage parent;
+};
+
+struct _GtkScalingImageClass
+{
+  GtkAbstractImageClass parent_class;
+
+  void   (*set_scale) (GtkScalingImage *image, double scale);
+};
+
+GDK_AVAILABLE_IN_3_20
+GType gtk_scaling_image_get_type (void) G_GNUC_CONST;
+
+GDK_AVAILABLE_IN_3_20
+void gtk_scaling_image_set_scale (GtkScalingImage *image, double scale);
+
+
+
 G_END_DECLS
 
 #endif
diff --git a/gtk/gtkimageview.c b/gtk/gtkimageview.c
index 4209fae..2e47f9b 100644
--- a/gtk/gtkimageview.c
+++ b/gtk/gtkimageview.c
@@ -554,6 +554,14 @@ gtk_image_view_fix_anchor (GtkImageView *image_view,
   gtk_widget_queue_draw (GTK_WIDGET (image_view));
 }
 
+static inline void
+set_scale (GtkImageView *image_view, double scale)
+{
+  GtkImageViewPrivate *priv = gtk_image_view_get_instance_private (image_view);
+
+  priv->scale = scale;
+}
+
 static void
 gtk_image_view_compute_bounding_box (GtkImageView *image_view,
                                      double       *width,
@@ -633,7 +641,8 @@ gtk_image_view_compute_bounding_box (GtkImageView *image_view,
   if (priv->fit_allocation)
     {
       g_assert (!priv->scale_set);
-      priv->scale = scale;
+      set_scale (image_view, scale);
+      /*priv->scale = scale;*/
       g_object_notify_by_pspec (G_OBJECT (image_view),
                                 widget_props[PROP_SCALE]);
     }
@@ -711,7 +720,8 @@ gtk_image_view_set_scale_internal (GtkImageView *image_view,
   GtkImageViewPrivate *priv = gtk_image_view_get_instance_private (image_view);
   scale = MAX (0, scale);
 
-  priv->scale = scale;
+  /*priv->scale = scale;*/
+  set_scale (image_view, scale);
   priv->size_valid = FALSE;
   g_object_notify_by_pspec (G_OBJECT (image_view),
                             widget_props[PROP_SCALE]);
@@ -1222,7 +1232,8 @@ gtk_image_view_set_scale (GtkImageView *image_view,
   if (gtk_image_view_transitions_enabled (image_view))
     gtk_image_view_animate_to_scale (image_view);
 
-  priv->scale = scale;
+  /*priv->scale = scale;*/
+  set_scale (image_view, scale);
   g_object_notify_by_pspec (G_OBJECT (image_view),
                             widget_props[PROP_SCALE]);
 
@@ -1458,7 +1469,8 @@ gtk_image_view_set_fit_allocation (GtkImageView *image_view,
 
   if (!priv->fit_allocation)
     {
-      priv->scale = 1.0;
+      /*priv->scale = 1.0;*/
+      set_scale (image_view, 1.0);
       g_object_notify_by_pspec (G_OBJECT (image_view),
                                 widget_props[PROP_SCALE]);
     }


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