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:
parent
07bb35bbe3
commit
0eeb61f3a8
@ -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);
|
||||
|
@ -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];
|
||||
|
@ -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 >
|
||||
|
@ -1,4 +1,5 @@
|
||||
BOOLEAN:BOXED
|
||||
BOOLEAN:BOXED,INT,INT
|
||||
BOOLEAN:OBJECT,ENUM
|
||||
BOOLEAN:STRING,UINT,FLAGS
|
||||
BOOLEAN:OBJECT
|
||||
|
@ -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));
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user