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.
This commit is contained in:
Emmanuele Bassi 2012-03-08 15:47:16 +00:00
parent 07bb35bbe3
commit 0eeb61f3a8
5 changed files with 27 additions and 17 deletions

View File

@ -115,7 +115,7 @@ clutter_cairo_context_draw_marshaller (GClosure *closure,
cairo_save (cr); cairo_save (cr);
_clutter_marshal_BOOLEAN__BOXED (closure, _clutter_marshal_BOOLEAN__BOXED_INT_INT (closure,
return_value, return_value,
n_param_values, n_param_values,
param_values, param_values,
@ -238,6 +238,8 @@ clutter_canvas_class_init (ClutterCanvasClass *klass)
* ClutterCanvas::draw: * ClutterCanvas::draw:
* @canvas: the #ClutterCanvas that emitted the signal * @canvas: the #ClutterCanvas that emitted the signal
* @cr: the Cairo context used to draw * @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 * The #ClutterCanvas::draw signal is emitted each time a canvas is
* invalidated. * invalidated.
@ -258,8 +260,10 @@ clutter_canvas_class_init (ClutterCanvasClass *klass)
G_STRUCT_OFFSET (ClutterCanvasClass, draw), G_STRUCT_OFFSET (ClutterCanvasClass, draw),
_clutter_boolean_handled_accumulator, NULL, _clutter_boolean_handled_accumulator, NULL,
clutter_cairo_context_draw_marshaller, clutter_cairo_context_draw_marshaller,
G_TYPE_BOOLEAN, 1, G_TYPE_BOOLEAN, 3,
CAIRO_GOBJECT_TYPE_CONTEXT); CAIRO_GOBJECT_TYPE_CONTEXT,
G_TYPE_INT,
G_TYPE_INT);
gobject_class->set_property = clutter_canvas_set_property; gobject_class->set_property = clutter_canvas_set_property;
gobject_class->get_property = clutter_canvas_get_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); 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; self->priv->cr = NULL;
cairo_destroy (cr); cairo_destroy (cr);

View File

@ -73,7 +73,9 @@ struct _ClutterCanvasClass
/*< public >*/ /*< public >*/
gboolean (* draw) (ClutterCanvas *canvas, gboolean (* draw) (ClutterCanvas *canvas,
cairo_t *cr); cairo_t *cr,
int width,
int height);
/*< private >*/ /*< private >*/
gpointer _padding[16]; gpointer _padding[16];

View File

@ -173,6 +173,8 @@ clutter_content_invalidate (ClutterContent *content)
g_return_if_fail (CLUTTER_IS_CONTENT (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); actors = g_object_get_qdata (G_OBJECT (content), quark_content_actors);
if (actors == NULL) if (actors == NULL)
return; return;
@ -186,8 +188,6 @@ clutter_content_invalidate (ClutterContent *content)
clutter_actor_queue_redraw (actor); clutter_actor_queue_redraw (actor);
} }
CLUTTER_CONTENT_GET_IFACE (content)->invalidate (content);
} }
/*< private > /*< private >

View File

@ -1,4 +1,5 @@
BOOLEAN:BOXED BOOLEAN:BOXED
BOOLEAN:BOXED,INT,INT
BOOLEAN:OBJECT,ENUM BOOLEAN:OBJECT,ENUM
BOOLEAN:STRING,UINT,FLAGS BOOLEAN:STRING,UINT,FLAGS
BOOLEAN:OBJECT BOOLEAN:OBJECT

View File

@ -5,9 +5,10 @@
static gboolean static gboolean
draw_clock (ClutterCanvas *canvas, draw_clock (ClutterCanvas *canvas,
cairo_t *cr) cairo_t *cr,
int width,
int height)
{ {
float width, height;
GDateTime *now; GDateTime *now;
float hours, minutes, seconds; float hours, minutes, seconds;
ClutterColor color; ClutterColor color;
@ -31,9 +32,6 @@ draw_clock (ClutterCanvas *canvas,
cairo_set_operator (cr, CAIRO_OPERATOR_OVER); cairo_set_operator (cr, CAIRO_OPERATOR_OVER);
/* scale the modelview to the size of the surface */ /* 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_scale (cr, width, height);
cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); 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_set_content (actor, canvas);
clutter_actor_add_child (stage, actor); 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 */ /* 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)); clutter_actor_add_constraint (actor, clutter_bind_constraint_new (stage, CLUTTER_BIND_SIZE, 0));