[clutter/wip/apocalypses/apocalypse-3: 18/35] canvas: Add canvas size to the ::draw signal



commit d2feede16265c50f92fdb7d5ce3c6611a7ef3724
Author: Emmanuele Bassi <ebassi linux intel com>
Date:   Thu Mar 8 15:47:16 2012 +0000

    canvas: Add canvas size to the ::draw signal
    
    Instead of requiring a call to clutter_content_get_preferred_size(), we
    can simply pass the canvas size to the Canvas::draw signal.

 clutter/clutter-canvas.c        |   24 +++++++++++++++---------
 clutter/clutter-canvas.h        |    4 +++-
 clutter/clutter-content.c       |    4 ++--
 clutter/clutter-marshal.list    |    1 +
 tests/interactive/test-canvas.c |   11 ++++++-----
 5 files changed, 27 insertions(+), 17 deletions(-)
---
diff --git a/clutter/clutter-canvas.c b/clutter/clutter-canvas.c
index 64c135d..c0122ac 100644
--- a/clutter/clutter-canvas.c
+++ b/clutter/clutter-canvas.c
@@ -115,12 +115,12 @@ clutter_cairo_context_draw_marshaller (GClosure     *closure,
 
   cairo_save (cr);
 
-  _clutter_marshal_BOOLEAN__BOXED (closure,
-                                   return_value,
-                                   n_param_values,
-                                   param_values,
-                                   invocation_hint,
-                                   marshal_data);
+  _clutter_marshal_BOOLEAN__BOXED_INT_INT (closure,
+                                           return_value,
+                                           n_param_values,
+                                           param_values,
+                                           invocation_hint,
+                                           marshal_data);
 
   cairo_restore (cr);
 }
@@ -238,6 +238,8 @@ clutter_canvas_class_init (ClutterCanvasClass *klass)
    * ClutterCanvas::draw:
    * @canvas: the #ClutterCanvas that emitted the signal
    * @cr: the Cairo context used to draw
+   * @width: the width of the @canvas
+   * @height: the height of the @canvas
    *
    * The #ClutterCanvas::draw signal is emitted each time a canvas is
    * invalidated.
@@ -258,8 +260,10 @@ clutter_canvas_class_init (ClutterCanvasClass *klass)
                   G_STRUCT_OFFSET (ClutterCanvasClass, draw),
                   _clutter_boolean_handled_accumulator, NULL,
                   clutter_cairo_context_draw_marshaller,
-                  G_TYPE_BOOLEAN, 1,
-                  CAIRO_GOBJECT_TYPE_CONTEXT);
+                  G_TYPE_BOOLEAN, 3,
+                  CAIRO_GOBJECT_TYPE_CONTEXT,
+                  G_TYPE_INT,
+                  G_TYPE_INT);
 
   gobject_class->set_property = clutter_canvas_set_property;
   gobject_class->get_property = clutter_canvas_get_property;
@@ -372,7 +376,9 @@ clutter_canvas_emit_draw (ClutterCanvas *self)
 
   self->priv->cr = cr = cairo_create (surface);
 
-  g_signal_emit (self, canvas_signals[DRAW], 0, cr, &res);
+  g_signal_emit (self, canvas_signals[DRAW], 0,
+                 cr, priv->width, priv->height,
+                 &res);
 
   self->priv->cr = NULL;
   cairo_destroy (cr);
diff --git a/clutter/clutter-canvas.h b/clutter/clutter-canvas.h
index 02ed0d6..26cc8d3 100644
--- a/clutter/clutter-canvas.h
+++ b/clutter/clutter-canvas.h
@@ -73,7 +73,9 @@ struct _ClutterCanvasClass
 
   /*< public >*/
   gboolean (* draw) (ClutterCanvas *canvas,
-                     cairo_t       *cr);
+                     cairo_t       *cr,
+                     int            width,
+                     int            height);
 
   /*< private >*/
   gpointer _padding[16];
diff --git a/clutter/clutter-content.c b/clutter/clutter-content.c
index c404620..26d8f26 100644
--- a/clutter/clutter-content.c
+++ b/clutter/clutter-content.c
@@ -173,6 +173,8 @@ clutter_content_invalidate (ClutterContent *content)
 
   g_return_if_fail (CLUTTER_IS_CONTENT (content));
 
+  CLUTTER_CONTENT_GET_IFACE (content)->invalidate (content);
+
   actors = g_object_get_qdata (G_OBJECT (content), quark_content_actors);
   if (actors == NULL)
     return;
@@ -186,8 +188,6 @@ clutter_content_invalidate (ClutterContent *content)
 
       clutter_actor_queue_redraw (actor);
     }
-
-  CLUTTER_CONTENT_GET_IFACE (content)->invalidate (content);
 }
 
 /*< private >
diff --git a/clutter/clutter-marshal.list b/clutter/clutter-marshal.list
index 8f9e0f8..509aa0b 100644
--- a/clutter/clutter-marshal.list
+++ b/clutter/clutter-marshal.list
@@ -1,4 +1,5 @@
 BOOLEAN:BOXED
+BOOLEAN:BOXED,INT,INT
 BOOLEAN:OBJECT,ENUM
 BOOLEAN:STRING,UINT,FLAGS
 BOOLEAN:OBJECT
diff --git a/tests/interactive/test-canvas.c b/tests/interactive/test-canvas.c
index 61038ef..18d7f16 100644
--- a/tests/interactive/test-canvas.c
+++ b/tests/interactive/test-canvas.c
@@ -5,9 +5,10 @@
 
 static gboolean
 draw_clock (ClutterCanvas *canvas,
-            cairo_t       *cr)
+            cairo_t       *cr,
+            int            width,
+            int            height)
 {
-  float width, height;
   GDateTime *now;
   float hours, minutes, seconds;
   ClutterColor color;
@@ -31,9 +32,6 @@ draw_clock (ClutterCanvas *canvas,
   cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
 
   /* scale the modelview to the size of the surface */
-  clutter_content_get_preferred_size (CLUTTER_CONTENT (canvas),
-                                      &width,
-                                      &height);
   cairo_scale (cr, width, height);
 
   cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
@@ -108,6 +106,9 @@ test_canvas_main (int argc, char *argv[])
   clutter_actor_set_content (actor, canvas);
   clutter_actor_add_child (stage, actor);
 
+  /* the actor now owns the canvas */
+  g_object_unref (canvas);
+
   /* bind the size of the actor to that of the stage */
   clutter_actor_add_constraint (actor, clutter_bind_constraint_new (stage, CLUTTER_BIND_SIZE, 0));
 



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