[gtk+] tests: Use new drawing area APIs



commit 915e791586a3ba1e56db6748d2b746c1d1f1553a
Author: Benjamin Otte <otte redhat com>
Date:   Fri Nov 18 22:27:02 2016 +0100

    tests: Use new drawing area APIs

 tests/testpixbuf-save.c  |   20 ++++++++++++--------
 tests/testpixbuf-scale.c |   17 +++++++----------
 2 files changed, 19 insertions(+), 18 deletions(-)
---
diff --git a/tests/testpixbuf-save.c b/tests/testpixbuf-save.c
index be95c03..7657599 100644
--- a/tests/testpixbuf-save.c
+++ b/tests/testpixbuf-save.c
@@ -307,12 +307,16 @@ close_app (GtkWidget *widget, gpointer data)
         return TRUE;
 }
 
-static gboolean
-draw_cb (GtkWidget *drawing_area, cairo_t *cr, gpointer data)
+static void
+draw_func (GtkDrawingArea *darea,
+           cairo_t        *cr,
+           int             width,
+           int             height,
+           gpointer        data)
 {
         GdkPixbuf *pixbuf;
          
-        pixbuf = (GdkPixbuf *) g_object_get_data (G_OBJECT (drawing_area),
+        pixbuf = (GdkPixbuf *) g_object_get_data (G_OBJECT (darea),
                                                  "pixbuf");
 
         gdk_cairo_set_source_pixbuf (cr, pixbuf, 0, 0);
@@ -369,11 +373,11 @@ main (int argc, char **argv)
         gtk_container_add (GTK_CONTAINER (window), vbox);  
    
         drawing_area = gtk_drawing_area_new ();
-        gtk_widget_set_size_request (GTK_WIDGET (drawing_area),
-                                     gdk_pixbuf_get_width (pixbuf),
-                                     gdk_pixbuf_get_height (pixbuf));
-        g_signal_connect (drawing_area, "draw",
-                         G_CALLBACK (draw_cb), NULL);
+        gtk_drawing_area_set_content_width (GTK_DRAWING_AREA (drawing_area),
+                                            gdk_pixbuf_get_width (pixbuf));
+        gtk_drawing_area_set_content_height (GTK_DRAWING_AREA (drawing_area),
+                                             gdk_pixbuf_get_height (pixbuf));
+        gtk_drawing_area_set_draw_func (GTK_DRAWING_AREA (drawing_area), draw_func, NULL, NULL);
 
         g_signal_connect (drawing_area, "configure_event",
                          G_CALLBACK (configure_cb), NULL);
diff --git a/tests/testpixbuf-scale.c b/tests/testpixbuf-scale.c
index da58dcc..73bbf9a 100644
--- a/tests/testpixbuf-scale.c
+++ b/tests/testpixbuf-scale.c
@@ -31,14 +31,14 @@ overall_changed_cb (GtkAdjustment *adjustment, gpointer data)
     }
 }
 
-gboolean
-draw_cb (GtkWidget *widget, cairo_t *cr, gpointer data)
+static void
+draw_func (GtkDrawingArea *darea,
+           cairo_t        *cr,
+           int             width,
+           int             height,
+           gpointer        data)
 {
   GdkPixbuf *dest;
-  int width, height;
-
-  width = gtk_widget_get_allocated_width (widget);
-  height = gtk_widget_get_allocated_height (widget);
 
   dest = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, width, height);
 
@@ -54,8 +54,6 @@ draw_cb (GtkWidget *widget, cairo_t *cr, gpointer data)
   cairo_paint (cr);
 
   g_object_unref (dest);
-  
-  return TRUE;
 }
 
 int
@@ -135,8 +133,7 @@ main(int argc, char **argv)
        darea = gtk_drawing_area_new ();
        gtk_box_pack_start (GTK_BOX (vbox), darea, TRUE, TRUE);
 
-       g_signal_connect (darea, "draw",
-                         G_CALLBACK (draw_cb), NULL);
+        gtk_drawing_area_set_draw_func (GTK_DRAWING_AREA (darea), draw_func, NULL, NULL);
 
        gtk_window_set_default_size (GTK_WINDOW (window),
                                     gdk_pixbuf_get_width (pixbuf),


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