[gtk+/wip/baedert/gtkimageview: 215/232] Remove GtkPixbufImage



commit 4503637436d6ff28375114dde968ed08995cb3e3
Author: Timm Bäder <mail baedert org>
Date:   Fri Feb 26 18:02:50 2016 +0100

    Remove GtkPixbufImage

 demos/gtk-demo/image_view.c |    4 +-
 gtk/gtkabstractimage.c      |   67 ++++++------------------------------------
 gtk/gtkabstractimage.h      |   34 ++--------------------
 gtk/gtkimageview.c          |   25 ++++++---------
 4 files changed, 25 insertions(+), 105 deletions(-)
---
diff --git a/demos/gtk-demo/image_view.c b/demos/gtk-demo/image_view.c
index 3483037..dbd6722 100644
--- a/demos/gtk-demo/image_view.c
+++ b/demos/gtk-demo/image_view.c
@@ -155,10 +155,10 @@ void
 load_pixbuf_button_clicked_cb ()
 {
   GdkPixbuf *pixbuf;
-  GtkPixbufImage *image;
+  GtkSurfaceImage *image;
 
   pixbuf = gdk_pixbuf_new_from_file ("/usr/share/backgrounds/gnome/Fabric.jpg", NULL);
-  image = gtk_pixbuf_image_new (pixbuf, 1);
+  image = gtk_surface_image_new_from_pixbuf (pixbuf, 1);
 
   g_object_unref (pixbuf);
 
diff --git a/gtk/gtkabstractimage.c b/gtk/gtkabstractimage.c
index 4ba1bb6..1cf43e9 100644
--- a/gtk/gtkabstractimage.c
+++ b/gtk/gtkabstractimage.c
@@ -83,62 +83,6 @@ gtk_abstract_image_get_scale_factor (GtkAbstractImage *image)
 
 /* }}} */
 
-/* GtkPixbufImage {{{ */
-G_DEFINE_TYPE (GtkPixbufImage, gtk_pixbuf_image, GTK_TYPE_ABSTRACT_IMAGE)
-
-
-GtkPixbufImage *
-gtk_pixbuf_image_new (const GdkPixbuf *pixbuf, int scale_factor)
-{
-  GtkPixbufImage *image = g_object_new (GTK_TYPE_PIXBUF_IMAGE, NULL);
-  image->scale_factor = scale_factor;
-  image->surface = gdk_cairo_surface_create_from_pixbuf (pixbuf, 1, NULL);
-
-  return image;
-}
-
-static int
-gtk_pixbuf_image_get_width (GtkAbstractImage *image)
-{
-  return cairo_image_surface_get_width (GTK_PIXBUF_IMAGE (image)->surface);
-}
-
-static int
-gtk_pixbuf_image_get_height (GtkAbstractImage *image)
-{
-  return cairo_image_surface_get_height (GTK_PIXBUF_IMAGE (image)->surface);
-}
-
-static int
-gtk_pixbuf_image_get_scale_factor (GtkAbstractImage *image)
-{
-  return GTK_PIXBUF_IMAGE (image)->scale_factor;
-}
-
-static void
-gtk_pixbuf_image_draw (GtkAbstractImage *image, cairo_t *ct)
-{
-  cairo_set_source_surface (ct, GTK_PIXBUF_IMAGE (image)->surface, 0, 0);
-}
-
-
-static void
-gtk_pixbuf_image_init (GtkPixbufImage *image)
-{
-}
-
-static void
-gtk_pixbuf_image_class_init (GtkPixbufImageClass *klass)
-{
-  GtkAbstractImageClass *image_class = GTK_ABSTRACT_IMAGE_CLASS (klass);
-
-  image_class->get_width = gtk_pixbuf_image_get_width;
-  image_class->get_height = gtk_pixbuf_image_get_height;
-  image_class->get_scale_factor = gtk_pixbuf_image_get_scale_factor;
-  image_class->draw = gtk_pixbuf_image_draw;
-}
-/* }}} */
-
 /* GtkPixbufAnimationImage {{{ */
 G_DEFINE_TYPE (GtkPixbufAnimationImage, gtk_pixbuf_animation_image, GTK_TYPE_ABSTRACT_IMAGE)
 
@@ -197,7 +141,7 @@ gtk_pixbuf_animation_image_draw (GtkAbstractImage *_image, cairo_t *ct)
   GtkPixbufAnimationImage *image = GTK_PIXBUF_ANIMATION_IMAGE (_image);
 
   /* We start the animation at the first draw() call... */
-  if (image->timeout_id == 0)
+  if (G_UNLIKELY (image->timeout_id == 0))
     {
       image->timeout_id = g_timeout_add (image->delay_ms, gtk_pixbuf_animation_image_advance, image);
     }
@@ -265,6 +209,15 @@ gtk_surface_image_new (cairo_surface_t *surface)
   return image;
 }
 
+GtkSurfaceImage *
+gtk_surface_image_new_from_pixbuf (const GdkPixbuf *pixbuf, int scale_factor)
+{
+  GtkSurfaceImage *image = g_object_new (GTK_TYPE_SURFACE_IMAGE, NULL);
+  image->surface = gdk_cairo_surface_create_from_pixbuf (pixbuf, scale_factor, NULL);
+
+  return image;
+}
+
 static void
 gtk_surface_image_init (GtkSurfaceImage *image)
 {
diff --git a/gtk/gtkabstractimage.h b/gtk/gtkabstractimage.h
index 7936d54..89bc5cf 100644
--- a/gtk/gtkabstractimage.h
+++ b/gtk/gtkabstractimage.h
@@ -67,37 +67,6 @@ int gtk_abstract_image_get_scale_factor (GtkAbstractImage *image);
 
 /* ------------------------------------------------------------------------------------ */
 
-typedef struct _GtkPixbufImage GtkPixbufImage;
-typedef struct _GtkPixbufImageClass GtkPixbufImageClass;
-
-#define GTK_TYPE_PIXBUF_IMAGE           (gtk_pixbuf_image_get_type ())
-#define GTK_PIXBUF_IMAGE(obj)           (G_TYPE_CHECK_INSTANCE_CAST (obj, GTK_TYPE_PIXBUF_IMAGE, 
GtkPixbufImage))
-#define GTK_PIXBUF_IMAGE_CLASS(cls)     (G_TYPE_CHECK_CLASS_CAST (cls, GTK_TYPE_PIXBUF_IMAGE, 
GtkPixbufImageClass))
-#define GTK_IS_PIXBUF_IMAGE(obj)        (G_TYPE_CHECK_INSTANCE_TYPE (obj, GTK_TYPE_PIXBUF_IMAGE))
-#define GTK_IS_PIXBUF_IMAGE_CLASS(obj)  (G_TYPE_CHECK_CLASS_TYPE (obj, GTK_TYPE_PIXBUF_IMAGE))
-#define GTK_PIXBUF_IMAGE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_PIXBUF_IMAGE, 
GtkPixbufImageClass))
-
-struct _GtkPixbufImage
-{
-  GtkAbstractImage parent;
-  cairo_surface_t *surface;
-  int scale_factor;
-};
-
-struct _GtkPixbufImageClass
-{
-  GtkAbstractImageClass parent_class;
-};
-
-GDK_AVAILABLE_IN_3_20
-GType gtk_pixbuf_image_get_type (void) G_GNUC_CONST;
-
-GDK_AVAILABLE_IN_3_20
-GtkPixbufImage *gtk_pixbuf_image_new (const GdkPixbuf *pixbuf, int scale_factor);
-
-
-/* ------------------------------------------------------------------------------------ */
-
 
 typedef struct _GtkPixbufAnimationImage GtkPixbufAnimationImage;
 typedef struct _GtkPixbufAnimationImageClass GtkPixbufAnimationImageClass;
@@ -160,7 +129,10 @@ struct _GtkSurfaceImageClass
 GDK_AVAILABLE_IN_3_20
 GType gtk_surface_image_get_type (void) G_GNUC_CONST;
 
+GDK_AVAILABLE_IN_3_20
 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);
 
 G_END_DECLS
 
diff --git a/gtk/gtkimageview.c b/gtk/gtkimageview.c
index 8c6b945..88e9314 100644
--- a/gtk/gtkimageview.c
+++ b/gtk/gtkimageview.c
@@ -59,7 +59,6 @@
 #define RAD_TO_DEG(x) (((x) / (2.0 * M_PI) * 360.0))
 
 #define TRANSITION_DURATION (150.0 * 1000.0)
-/*#define TRANSITION_DURATION (4500.0 * 1000.0)*/
 #define ANGLE_TRANSITION_MIN_DELTA (1.0)
 #define SCALE_TRANSITION_MIN_DELTA (0.01)
 
@@ -83,6 +82,9 @@ typedef struct
 
 struct _GtkImageViewPrivate
 {
+  GtkAbstractImage *image;
+  GdkWindow *event_window;
+
   double   scale;
   double   angle;
 
@@ -111,18 +113,12 @@ struct _GtkImageViewPrivate
   double      anchor_x;
   double      anchor_y;
 
-
-  GdkWindow *event_window;
-
   /* GtkScrollable stuff */
   GtkAdjustment       *hadjustment;
   GtkAdjustment       *vadjustment;
   GtkScrollablePolicy  hscroll_policy : 1;
   GtkScrollablePolicy  vscroll_policy : 1;
 
-  GtkAbstractImage *image;
-
-
   /* Transitions */
   double transition_start_angle;
   gint64 angle_transition_start;
@@ -568,8 +564,8 @@ gtk_image_view_compute_bounding_box (GtkImageView *image_view,
   GtkAllocation alloc;
   double image_width;
   double image_height;
-  double bb_width  = 0;
-  double bb_height = 0;
+  double bb_width;
+  double bb_height;
   double upper_right_degrees;
   double upper_left_degrees;
   double r;
@@ -971,7 +967,6 @@ gtk_image_view_init (GtkImageView *image_view)
   GtkImageViewPrivate *priv = gtk_image_view_get_instance_private (image_view);
   GtkWidget *widget = GTK_WIDGET (image_view);
 
-  gtk_widget_set_can_focus (widget, TRUE);
   gtk_widget_set_has_window (widget, FALSE);
 
   priv->scale = 1.0;
@@ -1150,9 +1145,9 @@ gtk_image_view_set_vadjustment (GtkImageView  *image_view,
   gtk_image_view_update_adjustments (image_view);
 
   if (priv->fit_allocation)
-    gtk_widget_queue_draw ((GtkWidget *)image_view);
+    gtk_widget_queue_draw (GTK_WIDGET (image_view));
   else
-    gtk_widget_queue_resize ((GtkWidget *)image_view);
+    gtk_widget_queue_resize (GTK_WIDGET (image_view));
 }
 
 static void
@@ -2157,7 +2152,7 @@ gtk_image_view_load_image_from_stream (GtkImageView *image_view,
         {
           GdkPixbuf *frame = gdk_pixbuf_animation_get_static_image (result);
 
-          image = GTK_ABSTRACT_IMAGE (gtk_pixbuf_image_new (frame, scale_factor));
+          image = GTK_ABSTRACT_IMAGE (gtk_surface_image_new_from_pixbuf (frame, scale_factor));
           g_object_unref (result);
         }
       else
@@ -2368,13 +2363,13 @@ gtk_image_view_set_pixbuf (GtkImageView    *image_view,
                            const GdkPixbuf *pixbuf,
                            int              scale_factor)
 {
-  GtkPixbufImage *image;
+  GtkSurfaceImage *image;
 
   g_return_if_fail (GTK_IS_IMAGE_VIEW (image_view));
   g_return_if_fail (GDK_IS_PIXBUF (pixbuf));
   g_return_if_fail (scale_factor >= 0);
 
-  image = gtk_pixbuf_image_new (pixbuf, scale_factor);
+  image = gtk_surface_image_new_from_pixbuf (pixbuf, scale_factor);
 
   gtk_image_view_set_abstract_image (image_view, GTK_ABSTRACT_IMAGE (image));
 }


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