4 * An OpenGL based 'interactive canvas' library.
6 * Authored By Matthew Allum <mallum@openedhand.com>
8 * Copyright (C) 2006, 2007, 2008 OpenedHand Ltd
9 * Copyright (C) 2009, 2010, 2011, 2012 Intel Corp
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2 of the License, or (at your option) any later version.
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
26 * SECTION:clutter-actor
27 * @short_description: The basic element of the scene graph
29 * The ClutterActor class is the basic element of the scene graph in Clutter,
30 * and it encapsulates the position, size, and transformations of a node in
33 * <refsect2 id="ClutterActor-transformations">
34 * <title>Actor transformations</title>
35 * <para>Each actor can be transformed using methods like
36 * clutter_actor_set_scale() or clutter_actor_set_rotation(). The order
37 * in which the transformations are applied is decided by Clutter and it is
38 * the following:</para>
40 * <listitem><para>translation by the origin of the #ClutterActor:allocation;</para></listitem>
41 * <listitem><para>translation by the actor's #ClutterActor:depth;</para></listitem>
42 * <listitem><para>scaling by the #ClutterActor:scale-x and #ClutterActor:scale-y factors;</para></listitem>
43 * <listitem><para>rotation around the #ClutterActor:rotation-z-angle and #ClutterActor:rotation-z-center;</para></listitem>
44 * <listitem><para>rotation around the #ClutterActor:rotation-y-angle and #ClutterActor:rotation-y-center;</para></listitem>
45 * <listitem><para>rotation around the #ClutterActor:rotation-x-angle and #ClutterActor:rotation-x-center;</para></listitem>
46 * <listitem><para>negative translation by the #ClutterActor:anchor-x and #ClutterActor:anchor-y point.</para></listitem>
50 * <refsect2 id="ClutterActor-geometry">
51 * <title>Modifying an actor's geometry</title>
52 * <para>Each actor has a bounding box, called #ClutterActor:allocation
53 * which is either set by its parent or explicitly through the
54 * clutter_actor_set_position() and clutter_actor_set_size() methods.
55 * Each actor also has an implicit preferred size.</para>
56 * <para>An actor’s preferred size can be defined by any subclass by
57 * overriding the #ClutterActorClass.get_preferred_width() and the
58 * #ClutterActorClass.get_preferred_height() virtual functions, or it can
59 * be explicitly set by using clutter_actor_set_width() and
60 * clutter_actor_set_height().</para>
61 * <para>An actor’s position can be set explicitly by using
62 * clutter_actor_set_x() and clutter_actor_set_y(); the coordinates are
63 * relative to the origin of the actor’s parent.</para>
66 * <refsect2 id="ClutterActor-children">
67 * <title>Managing actor children</title>
68 * <para>Each actor can have multiple children, by calling
69 * clutter_actor_add_child() to add a new child actor, and
70 * clutter_actor_remove_child() to remove an existing child. #ClutterActor
71 * will hold a reference on each child actor, which will be released when
72 * the child is removed from its parent, or destroyed using
73 * clutter_actor_destroy().</para>
74 * <informalexample><programlisting>
75 * ClutterActor *actor = clutter_actor_new ();
77 * /* set the bounding box of the actor */
78 * clutter_actor_set_position (actor, 0, 0);
79 * clutter_actor_set_size (actor, 480, 640);
81 * /* set the background color of the actor */
82 * clutter_actor_set_background_color (actor, CLUTTER_COLOR_Orange);
84 * /* set the bounding box of the child, relative to the parent */
85 * ClutterActor *child = clutter_actor_new ();
86 * clutter_actor_set_position (child, 20, 20);
87 * clutter_actor_set_size (child, 80, 240);
89 * /* set the background color of the child */
90 * clutter_actor_set_background_color (child, CLUTTER_COLOR_Blue);
92 * /* add the child to the actor */
93 * clutter_actor_add_child (actor, child);
94 * </programlisting></informalexample>
95 * <para>Children can be inserted at a given index, or above and below
96 * another child actor. The order of insertion determines the order of the
97 * children when iterating over them. Iterating over children is performed
98 * by using clutter_actor_get_first_child(), clutter_actor_get_previous_sibling(),
99 * clutter_actor_get_next_sibling(), and clutter_actor_get_last_child(). It is
100 * also possible to retrieve a list of children by using
101 * clutter_actor_get_children(), as well as retrieving a specific child at a
102 * given index by using clutter_actor_get_child_at_index().</para>
103 * <para>If you need to track additions of children to a #ClutterActor, use
104 * the #ClutterContainer::actor-added signal; similarly, to track removals
105 * of children from a ClutterActor, use the #ClutterContainer::actor-removed
107 * <informalexample><programlisting>
108 * <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" parse="text" href="../../../../tests/interactive/test-actor.c">
109 * <xi:fallback>FIXME: MISSING XINCLUDE CONTENT</xi:fallback>
111 * </programlisting></informalexample>
112 * <figure id="actor-example-image">
113 * <title>Actors</title>
114 * <graphic fileref="actor-example.png" format="PNG"/>
118 * <refsect2 id="ClutterActor-painting">
119 * <title>Painting an actor</title>
120 * <para>There are three ways to paint an actor:</para>
122 * <listitem><para>set a delegate #ClutterContent as the value for the
123 * #ClutterActor:content property of the actor;</para></listitem>
124 * <listitem><para>subclass #ClutterActor and override the
125 * #ClutterActorClass.paint_node() virtual function;</para></listitem>
126 * <listitem><para>subclass #ClutterActor and override the
127 * #ClutterActorClass.paint() virtual function.</para></listitem>
130 * <title>Setting the Content property</title>
131 * <para>A #ClutterContent is a delegate object that takes over the
132 * painting operation of one, or more actors. The #ClutterContent
133 * painting will be performed on top of the #ClutterActor:background-color
134 * of the actor, and before calling the #ClutterActorClass.paint_node()
135 * virtual function.</para>
136 * <informalexample><programlisting>
137 * ClutterActor *actor = clutter_actor_new ();
139 * /* set the bounding box */
140 * clutter_actor_set_position (actor, 50, 50);
141 * clutter_actor_set_size (actor, 100, 100);
143 * /* set the content; the image_content variable is set elsewhere */
144 * clutter_actor_set_content (actor, image_content);
145 * </programlisting></informalexample>
148 * <title>Overriding the paint_node virtual function</title>
149 * <para>The #ClutterActorClass.paint_node() virtual function is invoked
150 * whenever an actor needs to be painted. The implementation of the
151 * virtual function must only paint the contents of the actor itself,
152 * and not the contents of its children, if the actor has any.</para>
153 * <para>The #ClutterPaintNode passed to the virtual function is the
154 * local root of the render tree; any node added to it will be
155 * rendered at the correct position, as defined by the actor's
156 * #ClutterActor:allocation.</para>
157 * <informalexample><programlisting>
159 * my_actor_paint_node (ClutterActor *actor,
160 * ClutterPaintNode *root)
162 * ClutterPaintNode *node;
163 * ClutterActorBox box;
165 * /* where the content of the actor should be painted */
166 * clutter_actor_get_allocation_box (actor, &box);
168 * /* the cogl_texture variable is set elsewhere */
169 * node = clutter_texture_node_new (cogl_texture, CLUTTER_COLOR_White,
170 * CLUTTER_SCALING_FILTER_TRILINEAR,
171 * CLUTTER_SCALING_FILTER_LINEAR);
173 * /* paint the content of the node using the allocation */
174 * clutter_paint_node_add_rectangle (node, &box);
176 * /* add the node, and transfer ownership */
177 * clutter_paint_node_add_child (root, node);
178 * clutter_paint_node_unref (node);
180 * </programlisting></informalexample>
183 * <title>Overriding the paint virtual function</title>
184 * <para>The #ClutterActorClass.paint() virtual function is invoked
185 * when the #ClutterActor::paint signal is emitted, and after the other
186 * signal handlers have been invoked. Overriding the paint virtual
187 * function gives total control to the paint sequence of the actor
188 * itself, including the children of the actor, if any.</para>
189 * <warning><para>It is strongly discouraged to override the
190 * #ClutterActorClass.paint() virtual function, as well as connecting
191 * to the #ClutterActor::paint signal. These hooks into the paint
192 * sequence are considered legacy, and will be removed when the Clutter
193 * API changes.</para></warning>
197 * <refsect2 id="ClutterActor-events">
198 * <title>Handling events on an actor</title>
199 * <para>A #ClutterActor can receive and handle input device events, for
200 * instance pointer events and key events, as long as its
201 * #ClutterActor:reactive property is set to %TRUE.</para>
202 * <para>Once an actor has been determined to be the source of an event,
203 * Clutter will traverse the scene graph from the top-level actor towards the
204 * event source, emitting the #ClutterActor::captured-event signal on each
205 * ancestor until it reaches the source; this phase is also called
206 * <emphasis>the capture phase</emphasis>. If the event propagation was not
207 * stopped, the graph is walked backwards, from the source actor to the
208 * top-level, and the #ClutterActor::event signal, along with other event
209 * signals if needed, is emitted; this phase is also called <emphasis>the
210 * bubble phase</emphasis>. At any point of the signal emission, signal
211 * handlers can stop the propagation through the scene graph by returning
212 * %CLUTTER_EVENT_STOP; otherwise, they can continue the propagation by
213 * returning %CLUTTER_EVENT_PROPAGATE.</para>
216 * <refsect2 id="ClutterActor-animation">
217 * <title>Animation</title>
218 * <para>Animation is a core concept of modern user interfaces; Clutter
219 * provides a complete and powerful animation framework that automatically
220 * tweens the actor's state without requiring direct, frame by frame
221 * manipulation from your application code.</para>
223 * <title>Implicit animations</title>
224 * <para>The implicit animation model of Clutter assumes that all the
225 * changes in an actor state should be gradual and asynchronous; Clutter
226 * will automatically transition an actor's property change between the
227 * current state and the desired one without manual intervention.</para>
228 * <para>By default, in the 1.0 API series, the transition happens with
229 * a duration of zero milliseconds, and the implicit animation is an
230 * opt in feature to retain backwards compatibility. In order to enable
231 * implicit animations, it is necessary to change the easing state of
232 * an actor by using clutter_actor_save_easing_state():</para>
233 * <informalexample><programlisting>
234 * /* assume that the actor is currently positioned at (100, 100) */
235 * clutter_actor_save_easing_state (actor);
236 * clutter_actor_set_position (actor, 500, 500);
237 * clutter_actor_restore_easing_state (actor);
238 * </programlisting></informalexample>
239 * <para>The example above will trigger an implicit animation of the
240 * actor between its current position to a new position.</para>
241 * <para>It is possible to animate multiple properties of an actor
242 * at the same time, and you can animate multiple actors at the same
243 * time as well, for instance:</para>
244 * <informalexample><programlisting>
245 * /* animate the actor's opacity and depth */
246 * clutter_actor_save_easing_state (actor);
247 * clutter_actor_set_opacity (actor, 0);
248 * clutter_actor_set_depth (actor, -100);
249 * clutter_actor_restore_easing_state (actor);
251 * /* animate another actor's opacity */
252 * clutter_actor_save_easing_state (another_actor);
253 * clutter_actor_set_opacity (another_actor, 255);
254 * clutter_actor_set_depth (another_actor, 100);
255 * clutter_actor_restore_easing_state (another_actor);
256 * </programlisting></informalexample>
257 * <para>Implicit animations use a default duration of 250 milliseconds,
258 * and a default easing mode of %CLUTTER_EASE_OUT_CUBIC, unless you call
259 * clutter_actor_set_easing_mode() and clutter_actor_set_easing_duration()
260 * after changing the easing state of the actor.</para>
261 * <para>It is important to note that if you modify the state on an
262 * animatable property while a transition is in flight, the transition's
263 * final value will be updated, as well as its duration and progress
264 * mode by using the current easing state; for instance, in the following
266 * <informalexample><programlisting>
267 * clutter_actor_save_easing_state (actor);
268 * clutter_actor_set_x (actor, 200);
269 * clutter_actor_restore_easing_state (actor);
271 * clutter_actor_save_easing_state (actor);
272 * clutter_actor_set_x (actor, 100);
273 * clutter_actor_restore_easing_state (actor);
274 * </programlisting></informalexample>
275 * <para>the first call to clutter_actor_set_x() will begin a transition
276 * of the #ClutterActor:x property to the value of 200; the second call
277 * to clutter_actor_set_x() will change the transition's final value to
279 * <para>It is possible to retrieve the #ClutterTransition used by the
280 * animatable properties by using clutter_actor_get_transition() and using
281 * the property name as the transition name.</para>
284 * <title>Explicit animations</title>
285 * <para>The explicit animation model supported by Clutter requires that
286 * you create a #ClutterTransition object, and set the initial and
287 * final values. The transition will not start unless you add it to the
288 * #ClutterActor.</para>
289 * <informalexample><programlisting>
290 * ClutterTransition *transition;
292 * transition = clutter_property_transition_new ("opacity");
293 * clutter_timeline_set_duration (CLUTTER_TIMELINE (transition), 3000);
294 * clutter_timeline_set_repeat_count (CLUTTER_TIMELINE (transition), 2);
295 * clutter_timeline_set_auto_reverse (CLUTTER_TIMELINE (transition), TRUE);
296 * clutter_transition_set_interval (transition, clutter_interval_new (G_TYPE_UINT, 255, 0));
298 * clutter_actor_add_transition (actor, "animate-opacity", transition);
299 * </programlisting></informalexample>
300 * <para>The example above will animate the #ClutterActor:opacity property
301 * of an actor between fully opaque and fully transparent, and back, over
302 * a span of 3 seconds. The animation does not begin until it is added to
304 * <para>The explicit animation API should also be used when using custom
305 * animatable properties for #ClutterAction, #ClutterConstraint, and
306 * #ClutterEffect instances associated to an actor; see the section on
307 * <ulink linkend="ClutterActor-custom-animatable-properties">custom
308 * animatable properties below</ulink> for an example.</para>
309 * <para>Finally, explicit animations are useful for creating animations
310 * that run continuously, for instance:</para>
311 * <informalexample><programlisting>
312 * /* this animation will pulse the actor's opacity continuously */
313 * ClutterTransition *transition;
314 * ClutterInterval *interval;
316 * transition = clutter_property_transition_new ("opacity");
318 * /* we want to animate the opacity between 0 and 255 */
319 * internal = clutter_interval_new (G_TYPE_UINT, 0, 255);
320 * clutter_transition_set_interval (transition, interval);
322 * /* over a one second duration, running an infinite amount of times */
323 * clutter_timeline_set_duration (CLUTTER_TIMELINE (transition), 1000);
324 * clutter_timeline_set_repeat_count (CLUTTER_TIMELINE (transition), -1);
326 * /* we want to fade in and out, so we need to auto-reverse the transition */
327 * clutter_timeline_set_auto_reverse (CLUTTER_TIMELINE (transition), TRUE);
329 * /* and we want to use an easing function that eases both in and out */
330 * clutter_timeline_set_progress_mode (CLUTTER_TIMELINE (transition),
331 * CLUTTER_EASE_IN_OUT_CUBIC);
333 * /* add the transition to the desired actor; this will
334 * * start the animation.
336 * clutter_actor_add_transition (actor, "opacityAnimation", transition);
337 * </programlisting></informalexample>
341 * <refsect2 id="ClutterActor-subclassing">
342 * <title>Implementing an actor</title>
343 * <para>Careful consideration should be given when deciding to implement
344 * a #ClutterActor sub-class. It is generally recommended to implement a
345 * sub-class of #ClutterActor only for actors that should be used as leaf
346 * nodes of a scene graph.</para>
347 * <para>If your actor should be painted in a custom way, you should
348 * override the #ClutterActor::paint signal class handler. You can either
349 * opt to chain up to the parent class implementation or decide to fully
350 * override the default paint implementation; Clutter will set up the
351 * transformations and clip regions prior to emitting the #ClutterActor::paint
353 * <para>By overriding the #ClutterActorClass.get_preferred_width() and
354 * #ClutterActorClass.get_preferred_height() virtual functions it is
355 * possible to change or provide the preferred size of an actor; similarly,
356 * by overriding the #ClutterActorClass.allocate() virtual function it is
357 * possible to control the layout of the children of an actor. Make sure to
358 * always chain up to the parent implementation of the
359 * #ClutterActorClass.allocate() virtual function.</para>
360 * <para>In general, it is strongly encouraged to use delegation and
361 * composition instead of direct subclassing.</para>
364 * <refsect2 id="ClutterActor-script">
365 * <title>ClutterActor custom properties for #ClutterScript</title>
366 * <para>#ClutterActor defines a custom "rotation" property which
367 * allows a short-hand description of the rotations to be applied
368 * to an actor.</para>
369 * <para>The syntax of the "rotation" property is the following:</para>
373 * { "<axis>" : [ <angle>, [ <center> ] ] }
377 * <para>where the <emphasis>axis</emphasis> is the name of an enumeration
378 * value of type #ClutterRotateAxis and <emphasis>angle</emphasis> is a
379 * floating point value representing the rotation angle on the given axis,
381 * <para>The <emphasis>center</emphasis> array is optional, and if present
382 * it must contain the center of rotation as described by two coordinates:
383 * Y and Z for "x-axis"; X and Z for "y-axis"; and X and Y for
385 * <para>#ClutterActor will also parse every positional and dimensional
386 * property defined as a string through clutter_units_from_string(); you
387 * should read the documentation for the #ClutterUnits parser format for
388 * the valid units and syntax.</para>
391 * <refsect2 id="ClutterActor-custom-animatable-properties">
392 * <title>Custom animatable properties</title>
393 * <para>#ClutterActor allows accessing properties of #ClutterAction,
394 * #ClutterEffect, and #ClutterConstraint instances associated to an actor
395 * instance for animation purposes.</para>
396 * <para>In order to access a specific #ClutterAction or a #ClutterConstraint
397 * property it is necessary to set the #ClutterActorMeta:name property on the
398 * given action or constraint.</para>
399 * <para>The property can be accessed using the following syntax:</para>
402 * @<section>.<meta-name>.<property-name>
405 * <para>The initial <emphasis>@</emphasis> is mandatory.</para>
406 * <para>The <emphasis>section</emphasis> fragment can be one between
407 * "actions", "constraints" and "effects".</para>
408 * <para>The <emphasis>meta-name</emphasis> fragment is the name of the
409 * action or constraint, as specified by the #ClutterActorMeta:name
411 * <para>The <emphasis>property-name</emphasis> fragment is the name of the
412 * action or constraint property to be animated.</para>
413 * <para>The example below animates a #ClutterBindConstraint applied to an
414 * actor using clutter_actor_animate(). The <emphasis>rect</emphasis> has
415 * a binding constraint for the <emphasis>origin</emphasis> actor, and in
416 * its initial state is overlapping the actor to which is bound to.</para>
417 * <informalexample><programlisting>
418 * constraint = clutter_bind_constraint_new (origin, CLUTTER_BIND_X, 0.0);
419 * clutter_actor_meta_set_name (CLUTTER_ACTOR_META (constraint), "bind-x");
420 * clutter_actor_add_constraint (rect, constraint);
422 * constraint = clutter_bind_constraint_new (origin, CLUTTER_BIND_Y, 0.0);
423 * clutter_actor_meta_set_name (CLUTTER_ACTOR_META (constraint), "bind-y");
424 * clutter_actor_add_constraint (rect, constraint);
426 * clutter_actor_set_reactive (origin, TRUE);
428 * g_signal_connect (origin, "button-press-event",
429 * G_CALLBACK (on_button_press),
431 * </programlisting></informalexample>
432 * <para>On button press, the rectangle "slides" from behind the actor to
433 * which is bound to, using the #ClutterBindConstraint:offset property to
434 * achieve the effect:</para>
435 * <informalexample><programlisting>
437 * on_button_press (ClutterActor *origin,
438 * ClutterEvent *event,
439 * ClutterActor *rect)
441 * ClutterTransition *transition;
442 * ClutterInterval *interval;
444 * /* the offset that we want to apply; this will make the actor
445 * * slide in from behind the origin and rest at the right of
446 * * the origin, plus a padding value.
448 * float new_offset = clutter_actor_get_width (origin) + h_padding;
450 * /* the property we wish to animate; the "@constraints" section
451 * * tells Clutter to check inside the constraints associated
452 * * with the actor; the "bind-x" section is the name of the
453 * * constraint; and the "offset" is the name of the property
454 * * on the constraint.
456 * const char *prop = "@constraints.bind-x.offset";
458 * /* create a new transition for the given property */
459 * transition = clutter_property_transition_new (prop);
461 * /* set the easing mode and duration */
462 * clutter_timeline_set_progress_mode (CLUTTER_TIMELINE (transition),
463 * CLUTTER_EASE_OUT_CUBIC);
464 * clutter_timeline_set_duration (CLUTTER_TIMELINE (transition), 500);
466 * /* create the interval with the initial and final values */
467 * interval = clutter_interval_new (G_TYPE_FLOAT, 0, new_offset);
468 * clutter_transition_set_interval (transition, interval);
470 * /* add the transition to the actor; this causes the animation
471 * * to start. the name "offsetAnimation" can be used to retrieve
472 * * the transition later.
474 * clutter_actor_add_transition (rect, "offsetAnimation", transition);
476 * /* we handled the event */
477 * return CLUTTER_EVENT_STOP;
479 * </programlisting></informalexample>
484 * CLUTTER_ACTOR_IS_MAPPED:
485 * @a: a #ClutterActor
487 * Evaluates to %TRUE if the %CLUTTER_ACTOR_MAPPED flag is set.
489 * The mapped state is set when the actor is visible and all its parents up
490 * to a top-level (e.g. a #ClutterStage) are visible, realized, and mapped.
492 * This check can be used to see if an actor is going to be painted, as only
493 * actors with the %CLUTTER_ACTOR_MAPPED flag set are going to be painted.
495 * The %CLUTTER_ACTOR_MAPPED flag is managed by Clutter itself, and it should
496 * not be checked directly; instead, the recommended usage is to connect a
497 * handler on the #GObject::notify signal for the #ClutterActor:mapped
498 * property of #ClutterActor, and check the presence of
499 * the %CLUTTER_ACTOR_MAPPED flag on state changes.
501 * It is also important to note that Clutter may delay the changes of
502 * the %CLUTTER_ACTOR_MAPPED flag on top-levels due to backend-specific
503 * limitations, or during the reparenting of an actor, to optimize
504 * unnecessary (and potentially expensive) state changes.
510 * CLUTTER_ACTOR_IS_REALIZED:
511 * @a: a #ClutterActor
513 * Evaluates to %TRUE if the %CLUTTER_ACTOR_REALIZED flag is set.
515 * The realized state has an actor-dependant interpretation. If an
516 * actor wants to delay allocating resources until it is attached to a
517 * stage, it may use the realize state to do so. However it is
518 * perfectly acceptable for an actor to allocate Cogl resources before
519 * being realized because there is only one drawing context used by Clutter
520 * so any resources will work on any stage. If an actor is mapped it
521 * must also be realized, but an actor can be realized and unmapped
522 * (this is so hiding an actor temporarily doesn't do an expensive
523 * unrealize/realize).
525 * To be realized an actor must be inside a stage, and all its parents
532 * CLUTTER_ACTOR_IS_VISIBLE:
533 * @a: a #ClutterActor
535 * Evaluates to %TRUE if the actor has been shown, %FALSE if it's hidden.
536 * Equivalent to the ClutterActor::visible object property.
538 * Note that an actor is only painted onscreen if it's mapped, which
539 * means it's visible, and all its parents are visible, and one of the
540 * parents is a toplevel stage; see also %CLUTTER_ACTOR_IS_MAPPED.
546 * CLUTTER_ACTOR_IS_REACTIVE:
547 * @a: a #ClutterActor
549 * Evaluates to %TRUE if the %CLUTTER_ACTOR_REACTIVE flag is set.
551 * Only reactive actors will receive event-related signals.
562 #include <gobject/gvaluecollector.h>
564 #include <cogl/cogl.h>
566 #define CLUTTER_DISABLE_DEPRECATION_WARNINGS
567 #define CLUTTER_ENABLE_EXPERIMENTAL_API
569 #include "clutter-actor-private.h"
571 #include "clutter-action.h"
572 #include "clutter-actor-meta-private.h"
573 #include "clutter-animatable.h"
574 #include "clutter-color-static.h"
575 #include "clutter-color.h"
576 #include "clutter-constraint.h"
577 #include "clutter-container.h"
578 #include "clutter-content-private.h"
579 #include "clutter-debug.h"
580 #include "clutter-effect-private.h"
581 #include "clutter-enum-types.h"
582 #include "clutter-fixed-layout.h"
583 #include "clutter-flatten-effect.h"
584 #include "clutter-interval.h"
585 #include "clutter-main.h"
586 #include "clutter-marshal.h"
587 #include "clutter-paint-nodes.h"
588 #include "clutter-paint-node-private.h"
589 #include "clutter-paint-volume-private.h"
590 #include "clutter-private.h"
591 #include "clutter-profile.h"
592 #include "clutter-property-transition.h"
593 #include "clutter-scriptable.h"
594 #include "clutter-script-private.h"
595 #include "clutter-stage-private.h"
596 #include "clutter-timeline.h"
597 #include "clutter-transition.h"
598 #include "clutter-units.h"
600 #include "deprecated/clutter-actor.h"
601 #include "deprecated/clutter-behaviour.h"
602 #include "deprecated/clutter-container.h"
604 #define CLUTTER_ACTOR_GET_PRIVATE(obj) \
605 (G_TYPE_INSTANCE_GET_PRIVATE ((obj), CLUTTER_TYPE_ACTOR, ClutterActorPrivate))
607 /* Internal enum used to control mapped state update. This is a hint
608 * which indicates when to do something other than just enforce
612 MAP_STATE_CHECK, /* just enforce invariants. */
613 MAP_STATE_MAKE_UNREALIZED, /* force unrealize, ignoring invariants,
614 * used when about to unparent.
616 MAP_STATE_MAKE_MAPPED, /* set mapped, error if invariants not met;
617 * used to set mapped on toplevels.
619 MAP_STATE_MAKE_UNMAPPED /* set unmapped, even if parent is mapped,
620 * used just before unmapping parent.
624 /* 3 entries should be a good compromise, few layout managers
625 * will ask for 3 different preferred size in each allocation cycle */
626 #define N_CACHED_SIZE_REQUESTS 3
628 struct _ClutterActorPrivate
631 ClutterRequestMode request_mode;
633 /* our cached size requests for different width / height */
634 SizeRequest width_requests[N_CACHED_SIZE_REQUESTS];
635 SizeRequest height_requests[N_CACHED_SIZE_REQUESTS];
637 /* An age of 0 means the entry is not set */
638 guint cached_height_age;
639 guint cached_width_age;
641 /* the bounding box of the actor, relative to the parent's
644 ClutterActorBox allocation;
645 ClutterAllocationFlags allocation_flags;
647 /* clip, in actor coordinates */
648 cairo_rectangle_t clip;
650 /* the cached transformation matrix; see apply_transform() */
651 CoglMatrix transform;
654 gint opacity_override;
656 ClutterOffscreenRedirect offscreen_redirect;
658 /* This is an internal effect used to implement the
659 offscreen-redirect property */
660 ClutterEffect *flatten_effect;
663 ClutterActor *parent;
664 ClutterActor *prev_sibling;
665 ClutterActor *next_sibling;
666 ClutterActor *first_child;
667 ClutterActor *last_child;
671 /* tracks whenever the children of an actor are changed; the
672 * age is incremented by 1 whenever an actor is added or
673 * removed. the age is not incremented when the first or the
674 * last child pointers are changed, or when grandchildren of
675 * an actor are changed.
679 gchar *name; /* a non-unique name, used for debugging */
680 guint32 id; /* unique id, used for backward compatibility */
682 gint32 pick_id; /* per-stage unique id, used for picking */
684 /* a back-pointer to the Pango context that we can use
685 * to create pre-configured PangoLayout
687 PangoContext *pango_context;
689 /* the text direction configured for this child - either by
690 * application code, or by the actor's parent
692 ClutterTextDirection text_direction;
694 /* a counter used to toggle the CLUTTER_INTERNAL_CHILD flag */
698 ClutterMetaGroup *actions;
699 ClutterMetaGroup *constraints;
700 ClutterMetaGroup *effects;
702 /* delegate object used to allocate the children of this actor */
703 ClutterLayoutManager *layout_manager;
705 /* delegate object used to paint the contents of this actor */
706 ClutterContent *content;
708 ClutterContentGravity content_gravity;
709 ClutterScalingFilter min_filter;
710 ClutterScalingFilter mag_filter;
712 /* used when painting, to update the paint volume */
713 ClutterEffect *current_effect;
715 /* This is used to store an effect which needs to be redrawn. A
716 redraw can be queued to start from a particular effect. This is
717 used by parametrised effects that can cache an image of the
718 actor. If a parameter of the effect changes then it only needs to
719 redraw the cached image, not the actual actor. The pointer is
720 only valid if is_dirty == TRUE. If the pointer is NULL then the
721 whole actor is dirty. */
722 ClutterEffect *effect_to_redraw;
724 /* This is used when painting effects to implement the
725 clutter_actor_continue_paint() function. It points to the node in
726 the list of effects that is next in the chain */
727 const GList *next_effect_to_paint;
729 ClutterPaintVolume paint_volume;
731 /* NB: This volume isn't relative to this actor, it is in eye
732 * coordinates so that it can remain valid after the actor changes.
734 ClutterPaintVolume last_paint_volume;
736 ClutterStageQueueRedrawEntry *queue_redraw_entry;
738 ClutterColor bg_color;
742 /* fixed position and sizes */
743 guint position_set : 1;
744 guint min_width_set : 1;
745 guint min_height_set : 1;
746 guint natural_width_set : 1;
747 guint natural_height_set : 1;
748 /* cached request is invalid (implies allocation is too) */
749 guint needs_width_request : 1;
750 /* cached request is invalid (implies allocation is too) */
751 guint needs_height_request : 1;
752 /* cached allocation is invalid (request has changed, probably) */
753 guint needs_allocation : 1;
754 guint show_on_set_parent : 1;
756 guint clip_to_allocation : 1;
757 guint enable_model_view_transform : 1;
758 guint enable_paint_unmapped : 1;
759 guint has_pointer : 1;
760 guint propagated_one_redraw : 1;
761 guint paint_volume_valid : 1;
762 guint last_paint_volume_valid : 1;
763 guint in_clone_paint : 1;
764 guint transform_valid : 1;
765 /* This is TRUE if anything has queued a redraw since we were last
766 painted. In this case effect_to_redraw will point to an effect
767 the redraw was queued from or it will be NULL if the redraw was
768 queued without an effect. */
770 guint bg_color_set : 1;
779 /* X, Y, WIDTH, HEIGHT are "do what I mean" properties;
780 * when set they force a size request, when gotten they
781 * get the allocation if the allocation is valid, and the
789 /* Then the rest of these size-related properties are the "actual"
790 * underlying properties set or gotten by X, Y, WIDTH, HEIGHT
795 PROP_FIXED_POSITION_SET,
804 PROP_NATURAL_WIDTH_SET,
807 PROP_NATURAL_HEIGHT_SET,
811 /* Allocation properties are read-only */
818 PROP_CLIP_TO_ALLOCATION,
822 PROP_OFFSCREEN_REDIRECT,
835 PROP_ROTATION_ANGLE_X,
836 PROP_ROTATION_ANGLE_Y,
837 PROP_ROTATION_ANGLE_Z,
838 PROP_ROTATION_CENTER_X,
839 PROP_ROTATION_CENTER_Y,
840 PROP_ROTATION_CENTER_Z,
841 /* This property only makes sense for the z rotation because the
842 others would depend on the actor having a size along the
844 PROP_ROTATION_CENTER_Z_GRAVITY,
850 PROP_SHOW_ON_SET_PARENT,
868 PROP_BACKGROUND_COLOR,
869 PROP_BACKGROUND_COLOR_SET,
875 PROP_CONTENT_GRAVITY,
877 PROP_MINIFICATION_FILTER,
878 PROP_MAGNIFICATION_FILTER,
883 static GParamSpec *obj_props[PROP_LAST];
902 BUTTON_RELEASE_EVENT,
910 TRANSITIONS_COMPLETED,
915 static guint actor_signals[LAST_SIGNAL] = { 0, };
917 static void clutter_container_iface_init (ClutterContainerIface *iface);
918 static void clutter_scriptable_iface_init (ClutterScriptableIface *iface);
919 static void clutter_animatable_iface_init (ClutterAnimatableIface *iface);
920 static void atk_implementor_iface_init (AtkImplementorIface *iface);
922 /* These setters are all static for now, maybe they should be in the
923 * public API, but they are perhaps obscure enough to leave only as
926 static void clutter_actor_set_min_width (ClutterActor *self,
928 static void clutter_actor_set_min_height (ClutterActor *self,
930 static void clutter_actor_set_natural_width (ClutterActor *self,
931 gfloat natural_width);
932 static void clutter_actor_set_natural_height (ClutterActor *self,
933 gfloat natural_height);
934 static void clutter_actor_set_min_width_set (ClutterActor *self,
935 gboolean use_min_width);
936 static void clutter_actor_set_min_height_set (ClutterActor *self,
937 gboolean use_min_height);
938 static void clutter_actor_set_natural_width_set (ClutterActor *self,
939 gboolean use_natural_width);
940 static void clutter_actor_set_natural_height_set (ClutterActor *self,
941 gboolean use_natural_height);
942 static void clutter_actor_update_map_state (ClutterActor *self,
943 MapStateChange change);
944 static void clutter_actor_unrealize_not_hiding (ClutterActor *self);
946 /* Helper routines for managing anchor coords */
947 static void clutter_anchor_coord_get_units (ClutterActor *self,
948 const AnchorCoord *coord,
952 static void clutter_anchor_coord_set_units (AnchorCoord *coord,
957 static ClutterGravity clutter_anchor_coord_get_gravity (const AnchorCoord *coord);
958 static void clutter_anchor_coord_set_gravity (AnchorCoord *coord,
959 ClutterGravity gravity);
961 static gboolean clutter_anchor_coord_is_zero (const AnchorCoord *coord);
963 static void _clutter_actor_queue_only_relayout (ClutterActor *self);
965 static void _clutter_actor_get_relative_transformation_matrix (ClutterActor *self,
966 ClutterActor *ancestor,
969 static ClutterPaintVolume *_clutter_actor_get_paint_volume_mutable (ClutterActor *self);
971 static guint8 clutter_actor_get_paint_opacity_internal (ClutterActor *self);
973 static inline void clutter_actor_set_background_color_internal (ClutterActor *self,
974 const ClutterColor *color);
976 static void on_layout_manager_changed (ClutterLayoutManager *manager,
979 /* Helper macro which translates by the anchor coord, applies the
980 given transformation and then translates back */
981 #define TRANSFORM_ABOUT_ANCHOR_COORD(a,m,c,_transform) G_STMT_START { \
982 gfloat _tx, _ty, _tz; \
983 clutter_anchor_coord_get_units ((a), (c), &_tx, &_ty, &_tz); \
984 cogl_matrix_translate ((m), _tx, _ty, _tz); \
986 cogl_matrix_translate ((m), -_tx, -_ty, -_tz); } G_STMT_END
988 static GQuark quark_shader_data = 0;
989 static GQuark quark_actor_layout_info = 0;
990 static GQuark quark_actor_transform_info = 0;
991 static GQuark quark_actor_animation_info = 0;
993 G_DEFINE_TYPE_WITH_CODE (ClutterActor,
995 G_TYPE_INITIALLY_UNOWNED,
996 G_IMPLEMENT_INTERFACE (CLUTTER_TYPE_CONTAINER,
997 clutter_container_iface_init)
998 G_IMPLEMENT_INTERFACE (CLUTTER_TYPE_SCRIPTABLE,
999 clutter_scriptable_iface_init)
1000 G_IMPLEMENT_INTERFACE (CLUTTER_TYPE_ANIMATABLE,
1001 clutter_animatable_iface_init)
1002 G_IMPLEMENT_INTERFACE (ATK_TYPE_IMPLEMENTOR,
1003 atk_implementor_iface_init));
1006 * clutter_actor_get_debug_name:
1007 * @actor: a #ClutterActor
1009 * Retrieves a printable name of @actor for debugging messages
1011 * Return value: a string with a printable name
1014 _clutter_actor_get_debug_name (ClutterActor *actor)
1016 return actor->priv->name != NULL ? actor->priv->name
1017 : G_OBJECT_TYPE_NAME (actor);
1020 #ifdef CLUTTER_ENABLE_DEBUG
1021 /* XXX - this is for debugging only, remove once working (or leave
1022 * in only in some debug mode). Should leave it for a little while
1023 * until we're confident in the new map/realize/visible handling.
1026 clutter_actor_verify_map_state (ClutterActor *self)
1028 ClutterActorPrivate *priv = self->priv;
1030 if (CLUTTER_ACTOR_IS_REALIZED (self))
1032 /* all bets are off during reparent when we're potentially realized,
1033 * but should not be according to invariants
1035 if (!CLUTTER_ACTOR_IN_REPARENT (self))
1037 if (priv->parent == NULL)
1039 if (CLUTTER_ACTOR_IS_TOPLEVEL (self))
1043 g_warning ("Realized non-toplevel actor '%s' should "
1045 _clutter_actor_get_debug_name (self));
1047 else if (!CLUTTER_ACTOR_IS_REALIZED (priv->parent))
1049 g_warning ("Realized actor %s has an unrealized parent %s",
1050 _clutter_actor_get_debug_name (self),
1051 _clutter_actor_get_debug_name (priv->parent));
1056 if (CLUTTER_ACTOR_IS_MAPPED (self))
1058 if (!CLUTTER_ACTOR_IS_REALIZED (self))
1059 g_warning ("Actor '%s' is mapped but not realized",
1060 _clutter_actor_get_debug_name (self));
1062 /* remaining bets are off during reparent when we're potentially
1063 * mapped, but should not be according to invariants
1065 if (!CLUTTER_ACTOR_IN_REPARENT (self))
1067 if (priv->parent == NULL)
1069 if (CLUTTER_ACTOR_IS_TOPLEVEL (self))
1071 if (!CLUTTER_ACTOR_IS_VISIBLE (self) &&
1072 !CLUTTER_ACTOR_IN_DESTRUCTION (self))
1074 g_warning ("Toplevel actor '%s' is mapped "
1076 _clutter_actor_get_debug_name (self));
1081 g_warning ("Mapped actor '%s' should have a parent",
1082 _clutter_actor_get_debug_name (self));
1087 ClutterActor *iter = self;
1089 /* check for the enable_paint_unmapped flag on the actor
1090 * and parents; if the flag is enabled at any point of this
1091 * branch of the scene graph then all the later checks
1094 while (iter != NULL)
1096 if (iter->priv->enable_paint_unmapped)
1099 iter = iter->priv->parent;
1102 if (!CLUTTER_ACTOR_IS_VISIBLE (priv->parent))
1104 g_warning ("Actor '%s' should not be mapped if parent '%s'"
1106 _clutter_actor_get_debug_name (self),
1107 _clutter_actor_get_debug_name (priv->parent));
1110 if (!CLUTTER_ACTOR_IS_REALIZED (priv->parent))
1112 g_warning ("Actor '%s' should not be mapped if parent '%s'"
1114 _clutter_actor_get_debug_name (self),
1115 _clutter_actor_get_debug_name (priv->parent));
1118 if (!CLUTTER_ACTOR_IS_TOPLEVEL (priv->parent))
1120 if (!CLUTTER_ACTOR_IS_MAPPED (priv->parent))
1121 g_warning ("Actor '%s' is mapped but its non-toplevel "
1122 "parent '%s' is not mapped",
1123 _clutter_actor_get_debug_name (self),
1124 _clutter_actor_get_debug_name (priv->parent));
1131 #endif /* CLUTTER_ENABLE_DEBUG */
1134 clutter_actor_set_mapped (ClutterActor *self,
1137 if (CLUTTER_ACTOR_IS_MAPPED (self) == mapped)
1142 CLUTTER_ACTOR_GET_CLASS (self)->map (self);
1143 g_assert (CLUTTER_ACTOR_IS_MAPPED (self));
1147 CLUTTER_ACTOR_GET_CLASS (self)->unmap (self);
1148 g_assert (!CLUTTER_ACTOR_IS_MAPPED (self));
1152 /* this function updates the mapped and realized states according to
1153 * invariants, in the appropriate order.
1156 clutter_actor_update_map_state (ClutterActor *self,
1157 MapStateChange change)
1159 gboolean was_mapped;
1161 was_mapped = CLUTTER_ACTOR_IS_MAPPED (self);
1163 if (CLUTTER_ACTOR_IS_TOPLEVEL (self))
1165 /* the mapped flag on top-level actors must be set by the
1166 * per-backend implementation because it might be asynchronous.
1168 * That is, the MAPPED flag on toplevels currently tracks the X
1169 * server mapped-ness of the window, while the expected behavior
1170 * (if used to GTK) may be to track WM_STATE!=WithdrawnState.
1171 * This creates some weird complexity by breaking the invariant
1172 * that if we're visible and all ancestors shown then we are
1173 * also mapped - instead, we are mapped if all ancestors
1174 * _possibly excepting_ the stage are mapped. The stage
1175 * will map/unmap for example when it is minimized or
1176 * moved to another workspace.
1178 * So, the only invariant on the stage is that if visible it
1179 * should be realized, and that it has to be visible to be
1182 if (CLUTTER_ACTOR_IS_VISIBLE (self))
1183 clutter_actor_realize (self);
1187 case MAP_STATE_CHECK:
1190 case MAP_STATE_MAKE_MAPPED:
1191 g_assert (!was_mapped);
1192 clutter_actor_set_mapped (self, TRUE);
1195 case MAP_STATE_MAKE_UNMAPPED:
1196 g_assert (was_mapped);
1197 clutter_actor_set_mapped (self, FALSE);
1200 case MAP_STATE_MAKE_UNREALIZED:
1201 /* we only use MAKE_UNREALIZED in unparent,
1202 * and unparenting a stage isn't possible.
1203 * If someone wants to just unrealize a stage
1204 * then clutter_actor_unrealize() doesn't
1205 * go through this codepath.
1207 g_warning ("Trying to force unrealize stage is not allowed");
1211 if (CLUTTER_ACTOR_IS_MAPPED (self) &&
1212 !CLUTTER_ACTOR_IS_VISIBLE (self) &&
1213 !CLUTTER_ACTOR_IN_DESTRUCTION (self))
1215 g_warning ("Clutter toplevel of type '%s' is not visible, but "
1216 "it is somehow still mapped",
1217 _clutter_actor_get_debug_name (self));
1222 ClutterActorPrivate *priv = self->priv;
1223 ClutterActor *parent = priv->parent;
1224 gboolean should_be_mapped;
1225 gboolean may_be_realized;
1226 gboolean must_be_realized;
1228 should_be_mapped = FALSE;
1229 may_be_realized = TRUE;
1230 must_be_realized = FALSE;
1232 if (parent == NULL || change == MAP_STATE_MAKE_UNREALIZED)
1234 may_be_realized = FALSE;
1238 /* Maintain invariant that if parent is mapped, and we are
1239 * visible, then we are mapped ... unless parent is a
1240 * stage, in which case we map regardless of parent's map
1241 * state but do require stage to be visible and realized.
1243 * If parent is realized, that does not force us to be
1244 * realized; but if parent is unrealized, that does force
1245 * us to be unrealized.
1247 * The reason we don't force children to realize with
1248 * parents is _clutter_actor_rerealize(); if we require that
1249 * a realized parent means children are realized, then to
1250 * unrealize an actor we would have to unrealize its
1251 * parents, which would end up meaning unrealizing and
1252 * hiding the entire stage. So we allow unrealizing a
1253 * child (as long as that child is not mapped) while that
1254 * child still has a realized parent.
1256 * Also, if we unrealize from leaf nodes to root, and
1257 * realize from root to leaf, the invariants are never
1258 * violated if we allow children to be unrealized
1259 * while parents are realized.
1261 * When unmapping, MAP_STATE_MAKE_UNMAPPED is specified
1262 * to force us to unmap, even though parent is still
1263 * mapped. This is because we're unmapping from leaf nodes
1266 if (CLUTTER_ACTOR_IS_VISIBLE (self) &&
1267 change != MAP_STATE_MAKE_UNMAPPED)
1269 gboolean parent_is_visible_realized_toplevel;
1271 parent_is_visible_realized_toplevel =
1272 (CLUTTER_ACTOR_IS_TOPLEVEL (parent) &&
1273 CLUTTER_ACTOR_IS_VISIBLE (parent) &&
1274 CLUTTER_ACTOR_IS_REALIZED (parent));
1276 if (CLUTTER_ACTOR_IS_MAPPED (parent) ||
1277 parent_is_visible_realized_toplevel)
1279 must_be_realized = TRUE;
1280 should_be_mapped = TRUE;
1284 /* if the actor has been set to be painted even if unmapped
1285 * then we should map it and check for realization as well;
1286 * this is an override for the branch of the scene graph
1287 * which begins with this node
1289 if (priv->enable_paint_unmapped)
1291 if (priv->parent == NULL)
1292 g_warning ("Attempting to map an unparented actor '%s'",
1293 _clutter_actor_get_debug_name (self));
1295 should_be_mapped = TRUE;
1296 must_be_realized = TRUE;
1299 if (!CLUTTER_ACTOR_IS_REALIZED (parent))
1300 may_be_realized = FALSE;
1303 if (change == MAP_STATE_MAKE_MAPPED && !should_be_mapped)
1306 g_warning ("Attempting to map a child that does not "
1307 "meet the necessary invariants: the actor '%s' "
1309 _clutter_actor_get_debug_name (self));
1311 g_warning ("Attempting to map a child that does not "
1312 "meet the necessary invariants: the actor '%s' "
1313 "is parented to an unmapped actor '%s'",
1314 _clutter_actor_get_debug_name (self),
1315 _clutter_actor_get_debug_name (priv->parent));
1318 /* If in reparent, we temporarily suspend unmap and unrealize.
1320 * We want to go in the order "realize, map" and "unmap, unrealize"
1324 if (!should_be_mapped && !CLUTTER_ACTOR_IN_REPARENT (self))
1325 clutter_actor_set_mapped (self, FALSE);
1328 if (must_be_realized)
1329 clutter_actor_realize (self);
1331 /* if we must be realized then we may be, presumably */
1332 g_assert (!(must_be_realized && !may_be_realized));
1335 if (!may_be_realized && !CLUTTER_ACTOR_IN_REPARENT (self))
1336 clutter_actor_unrealize_not_hiding (self);
1339 if (should_be_mapped)
1341 if (!must_be_realized)
1342 g_warning ("Somehow we think actor '%s' should be mapped but "
1343 "not realized, which isn't allowed",
1344 _clutter_actor_get_debug_name (self));
1346 /* realization is allowed to fail (though I don't know what
1347 * an app is supposed to do about that - shouldn't it just
1348 * be a g_error? anyway, we have to avoid mapping if this
1351 if (CLUTTER_ACTOR_IS_REALIZED (self))
1352 clutter_actor_set_mapped (self, TRUE);
1356 #ifdef CLUTTER_ENABLE_DEBUG
1357 /* check all invariants were kept */
1358 clutter_actor_verify_map_state (self);
1363 clutter_actor_real_map (ClutterActor *self)
1365 ClutterActorPrivate *priv = self->priv;
1366 ClutterActor *stage, *iter;
1368 g_assert (!CLUTTER_ACTOR_IS_MAPPED (self));
1370 CLUTTER_NOTE (ACTOR, "Mapping actor '%s'",
1371 _clutter_actor_get_debug_name (self));
1373 CLUTTER_ACTOR_SET_FLAGS (self, CLUTTER_ACTOR_MAPPED);
1375 stage = _clutter_actor_get_stage_internal (self);
1376 priv->pick_id = _clutter_stage_acquire_pick_id (CLUTTER_STAGE (stage), self);
1378 CLUTTER_NOTE (ACTOR, "Pick id '%d' for actor '%s'",
1380 _clutter_actor_get_debug_name (self));
1382 /* notify on parent mapped before potentially mapping
1383 * children, so apps see a top-down notification.
1385 g_object_notify_by_pspec (G_OBJECT (self), obj_props[PROP_MAPPED]);
1387 for (iter = self->priv->first_child;
1389 iter = iter->priv->next_sibling)
1391 clutter_actor_map (iter);
1396 * clutter_actor_map:
1397 * @self: A #ClutterActor
1399 * Sets the %CLUTTER_ACTOR_MAPPED flag on the actor and possibly maps
1400 * and realizes its children if they are visible. Does nothing if the
1401 * actor is not visible.
1403 * Calling this function is strongly disencouraged: the default
1404 * implementation of #ClutterActorClass.map() will map all the children
1405 * of an actor when mapping its parent.
1407 * When overriding map, it is mandatory to chain up to the parent
1413 clutter_actor_map (ClutterActor *self)
1415 g_return_if_fail (CLUTTER_IS_ACTOR (self));
1417 if (CLUTTER_ACTOR_IS_MAPPED (self))
1420 if (!CLUTTER_ACTOR_IS_VISIBLE (self))
1423 clutter_actor_update_map_state (self, MAP_STATE_MAKE_MAPPED);
1427 clutter_actor_real_unmap (ClutterActor *self)
1429 ClutterActorPrivate *priv = self->priv;
1432 g_assert (CLUTTER_ACTOR_IS_MAPPED (self));
1434 CLUTTER_NOTE (ACTOR, "Unmapping actor '%s'",
1435 _clutter_actor_get_debug_name (self));
1437 for (iter = self->priv->first_child;
1439 iter = iter->priv->next_sibling)
1441 clutter_actor_unmap (iter);
1444 CLUTTER_ACTOR_UNSET_FLAGS (self, CLUTTER_ACTOR_MAPPED);
1446 /* clear the contents of the last paint volume, so that hiding + moving +
1447 * showing will not result in the wrong area being repainted
1449 _clutter_paint_volume_init_static (&priv->last_paint_volume, NULL);
1450 priv->last_paint_volume_valid = TRUE;
1452 /* notify on parent mapped after potentially unmapping
1453 * children, so apps see a bottom-up notification.
1455 g_object_notify_by_pspec (G_OBJECT (self), obj_props[PROP_MAPPED]);
1457 /* relinquish keyboard focus if we were unmapped while owning it */
1458 if (!CLUTTER_ACTOR_IS_TOPLEVEL (self))
1460 ClutterStage *stage;
1462 stage = CLUTTER_STAGE (_clutter_actor_get_stage_internal (self));
1465 _clutter_stage_release_pick_id (stage, priv->pick_id);
1469 if (stage != NULL &&
1470 clutter_stage_get_key_focus (stage) == self)
1472 clutter_stage_set_key_focus (stage, NULL);
1478 * clutter_actor_unmap:
1479 * @self: A #ClutterActor
1481 * Unsets the %CLUTTER_ACTOR_MAPPED flag on the actor and possibly
1482 * unmaps its children if they were mapped.
1484 * Calling this function is not encouraged: the default #ClutterActor
1485 * implementation of #ClutterActorClass.unmap() will also unmap any
1486 * eventual children by default when their parent is unmapped.
1488 * When overriding #ClutterActorClass.unmap(), it is mandatory to
1489 * chain up to the parent implementation.
1491 * <note>It is important to note that the implementation of the
1492 * #ClutterActorClass.unmap() virtual function may be called after
1493 * the #ClutterActorClass.destroy() or the #GObjectClass.dispose()
1494 * implementation, but it is guaranteed to be called before the
1495 * #GObjectClass.finalize() implementation.</note>
1500 clutter_actor_unmap (ClutterActor *self)
1502 g_return_if_fail (CLUTTER_IS_ACTOR (self));
1504 if (!CLUTTER_ACTOR_IS_MAPPED (self))
1507 clutter_actor_update_map_state (self, MAP_STATE_MAKE_UNMAPPED);
1511 clutter_actor_real_show (ClutterActor *self)
1513 if (!CLUTTER_ACTOR_IS_VISIBLE (self))
1515 ClutterActorPrivate *priv = self->priv;
1517 CLUTTER_ACTOR_SET_FLAGS (self, CLUTTER_ACTOR_VISIBLE);
1519 /* we notify on the "visible" flag in the clutter_actor_show()
1520 * wrapper so the entire show signal emission completes first
1523 clutter_actor_update_map_state (self, MAP_STATE_CHECK);
1525 /* we queue a relayout unless the actor is inside a
1526 * container that explicitly told us not to
1528 if (priv->parent != NULL &&
1529 (!(priv->parent->flags & CLUTTER_ACTOR_NO_LAYOUT)))
1531 /* While an actor is hidden the parent may not have
1532 * allocated/requested so we need to start from scratch
1533 * and avoid the short-circuiting in
1534 * clutter_actor_queue_relayout().
1536 priv->needs_width_request = FALSE;
1537 priv->needs_height_request = FALSE;
1538 priv->needs_allocation = FALSE;
1539 clutter_actor_queue_relayout (self);
1545 set_show_on_set_parent (ClutterActor *self,
1548 ClutterActorPrivate *priv = self->priv;
1550 set_show = !!set_show;
1552 if (priv->show_on_set_parent == set_show)
1555 if (priv->parent == NULL)
1557 priv->show_on_set_parent = set_show;
1558 g_object_notify_by_pspec (G_OBJECT (self),
1559 obj_props[PROP_SHOW_ON_SET_PARENT]);
1564 * clutter_actor_show:
1565 * @self: A #ClutterActor
1567 * Flags an actor to be displayed. An actor that isn't shown will not
1568 * be rendered on the stage.
1570 * Actors are visible by default.
1572 * If this function is called on an actor without a parent, the
1573 * #ClutterActor:show-on-set-parent will be set to %TRUE as a side
1577 clutter_actor_show (ClutterActor *self)
1579 ClutterActorPrivate *priv;
1581 g_return_if_fail (CLUTTER_IS_ACTOR (self));
1583 /* simple optimization */
1584 if (CLUTTER_ACTOR_IS_VISIBLE (self))
1586 /* we still need to set the :show-on-set-parent property, in
1587 * case show() is called on an unparented actor
1589 set_show_on_set_parent (self, TRUE);
1593 #ifdef CLUTTER_ENABLE_DEBUG
1594 clutter_actor_verify_map_state (self);
1599 g_object_freeze_notify (G_OBJECT (self));
1601 set_show_on_set_parent (self, TRUE);
1603 g_signal_emit (self, actor_signals[SHOW], 0);
1604 g_object_notify_by_pspec (G_OBJECT (self), obj_props[PROP_VISIBLE]);
1606 if (priv->parent != NULL)
1607 clutter_actor_queue_redraw (priv->parent);
1609 g_object_thaw_notify (G_OBJECT (self));
1613 * clutter_actor_show_all:
1614 * @self: a #ClutterActor
1616 * Calls clutter_actor_show() on all children of an actor (if any).
1620 * Deprecated: 1.10: Actors are visible by default
1623 clutter_actor_show_all (ClutterActor *self)
1625 ClutterActorClass *klass;
1627 g_return_if_fail (CLUTTER_IS_ACTOR (self));
1629 klass = CLUTTER_ACTOR_GET_CLASS (self);
1630 if (klass->show_all)
1631 klass->show_all (self);
1635 clutter_actor_real_hide (ClutterActor *self)
1637 if (CLUTTER_ACTOR_IS_VISIBLE (self))
1639 ClutterActorPrivate *priv = self->priv;
1641 CLUTTER_ACTOR_UNSET_FLAGS (self, CLUTTER_ACTOR_VISIBLE);
1643 /* we notify on the "visible" flag in the clutter_actor_hide()
1644 * wrapper so the entire hide signal emission completes first
1647 clutter_actor_update_map_state (self, MAP_STATE_CHECK);
1649 /* we queue a relayout unless the actor is inside a
1650 * container that explicitly told us not to
1652 if (priv->parent != NULL &&
1653 (!(priv->parent->flags & CLUTTER_ACTOR_NO_LAYOUT)))
1654 clutter_actor_queue_relayout (priv->parent);
1659 * clutter_actor_hide:
1660 * @self: A #ClutterActor
1662 * Flags an actor to be hidden. A hidden actor will not be
1663 * rendered on the stage.
1665 * Actors are visible by default.
1667 * If this function is called on an actor without a parent, the
1668 * #ClutterActor:show-on-set-parent property will be set to %FALSE
1672 clutter_actor_hide (ClutterActor *self)
1674 ClutterActorPrivate *priv;
1676 g_return_if_fail (CLUTTER_IS_ACTOR (self));
1678 /* simple optimization */
1679 if (!CLUTTER_ACTOR_IS_VISIBLE (self))
1681 /* we still need to set the :show-on-set-parent property, in
1682 * case hide() is called on an unparented actor
1684 set_show_on_set_parent (self, FALSE);
1688 #ifdef CLUTTER_ENABLE_DEBUG
1689 clutter_actor_verify_map_state (self);
1694 g_object_freeze_notify (G_OBJECT (self));
1696 set_show_on_set_parent (self, FALSE);
1698 g_signal_emit (self, actor_signals[HIDE], 0);
1699 g_object_notify_by_pspec (G_OBJECT (self), obj_props[PROP_VISIBLE]);
1701 if (priv->parent != NULL)
1702 clutter_actor_queue_redraw (priv->parent);
1704 g_object_thaw_notify (G_OBJECT (self));
1708 * clutter_actor_hide_all:
1709 * @self: a #ClutterActor
1711 * Calls clutter_actor_hide() on all child actors (if any).
1715 * Deprecated: 1.10: Using clutter_actor_hide() on the actor will
1716 * prevent its children from being painted as well.
1719 clutter_actor_hide_all (ClutterActor *self)
1721 ClutterActorClass *klass;
1723 g_return_if_fail (CLUTTER_IS_ACTOR (self));
1725 klass = CLUTTER_ACTOR_GET_CLASS (self);
1726 if (klass->hide_all)
1727 klass->hide_all (self);
1731 * clutter_actor_realize:
1732 * @self: A #ClutterActor
1734 * Realization informs the actor that it is attached to a stage. It
1735 * can use this to allocate resources if it wanted to delay allocation
1736 * until it would be rendered. However it is perfectly acceptable for
1737 * an actor to create resources before being realized because Clutter
1738 * only ever has a single rendering context so that actor is free to
1739 * be moved from one stage to another.
1741 * This function does nothing if the actor is already realized.
1743 * Because a realized actor must have realized parent actors, calling
1744 * clutter_actor_realize() will also realize all parents of the actor.
1746 * This function does not realize child actors, except in the special
1747 * case that realizing the stage, when the stage is visible, will
1748 * suddenly map (and thus realize) the children of the stage.
1751 clutter_actor_realize (ClutterActor *self)
1753 ClutterActorPrivate *priv;
1755 g_return_if_fail (CLUTTER_IS_ACTOR (self));
1759 #ifdef CLUTTER_ENABLE_DEBUG
1760 clutter_actor_verify_map_state (self);
1763 if (CLUTTER_ACTOR_IS_REALIZED (self))
1766 /* To be realized, our parent actors must be realized first.
1767 * This will only succeed if we're inside a toplevel.
1769 if (priv->parent != NULL)
1770 clutter_actor_realize (priv->parent);
1772 if (CLUTTER_ACTOR_IS_TOPLEVEL (self))
1774 /* toplevels can be realized at any time */
1778 /* "Fail" the realization if parent is missing or unrealized;
1779 * this should really be a g_warning() not some kind of runtime
1780 * failure; how can an app possibly recover? Instead it's a bug
1781 * in the app and the app should get an explanatory warning so
1782 * someone can fix it. But for now it's too hard to fix this
1783 * because e.g. ClutterTexture needs reworking.
1785 if (priv->parent == NULL ||
1786 !CLUTTER_ACTOR_IS_REALIZED (priv->parent))
1790 CLUTTER_NOTE (ACTOR, "Realizing actor '%s'", _clutter_actor_get_debug_name (self));
1792 CLUTTER_ACTOR_SET_FLAGS (self, CLUTTER_ACTOR_REALIZED);
1793 g_object_notify_by_pspec (G_OBJECT (self), obj_props[PROP_REALIZED]);
1795 g_signal_emit (self, actor_signals[REALIZE], 0);
1797 /* Stage actor is allowed to unset the realized flag again in its
1798 * default signal handler, though that is a pathological situation.
1801 /* If realization "failed" we'll have to update child state. */
1802 clutter_actor_update_map_state (self, MAP_STATE_CHECK);
1806 clutter_actor_real_unrealize (ClutterActor *self)
1808 /* we must be unmapped (implying our children are also unmapped) */
1809 g_assert (!CLUTTER_ACTOR_IS_MAPPED (self));
1813 * clutter_actor_unrealize:
1814 * @self: A #ClutterActor
1816 * Unrealization informs the actor that it may be being destroyed or
1817 * moved to another stage. The actor may want to destroy any
1818 * underlying graphics resources at this point. However it is
1819 * perfectly acceptable for it to retain the resources until the actor
1820 * is destroyed because Clutter only ever uses a single rendering
1821 * context and all of the graphics resources are valid on any stage.
1823 * Because mapped actors must be realized, actors may not be
1824 * unrealized if they are mapped. This function hides the actor to be
1825 * sure it isn't mapped, an application-visible side effect that you
1826 * may not be expecting.
1828 * This function should not be called by application code.
1831 clutter_actor_unrealize (ClutterActor *self)
1833 g_return_if_fail (CLUTTER_IS_ACTOR (self));
1834 g_return_if_fail (!CLUTTER_ACTOR_IS_MAPPED (self));
1836 /* This function should not really be in the public API, because
1837 * there isn't a good reason to call it. ClutterActor will already
1838 * unrealize things for you when it's important to do so.
1840 * If you were using clutter_actor_unrealize() in a dispose
1841 * implementation, then don't, just chain up to ClutterActor's
1844 * If you were using clutter_actor_unrealize() to implement
1845 * unrealizing children of your container, then don't, ClutterActor
1846 * will already take care of that.
1848 * If you were using clutter_actor_unrealize() to re-realize to
1849 * create your resources in a different way, then use
1850 * _clutter_actor_rerealize() (inside Clutter) or just call your
1851 * code that recreates your resources directly (outside Clutter).
1854 #ifdef CLUTTER_ENABLE_DEBUG
1855 clutter_actor_verify_map_state (self);
1858 clutter_actor_hide (self);
1860 clutter_actor_unrealize_not_hiding (self);
1863 static ClutterActorTraverseVisitFlags
1864 unrealize_actor_before_children_cb (ClutterActor *self,
1868 /* If an actor is already unrealized we know its children have also
1869 * already been unrealized... */
1870 if (!CLUTTER_ACTOR_IS_REALIZED (self))
1871 return CLUTTER_ACTOR_TRAVERSE_VISIT_SKIP_CHILDREN;
1873 g_signal_emit (self, actor_signals[UNREALIZE], 0);
1875 return CLUTTER_ACTOR_TRAVERSE_VISIT_CONTINUE;
1878 static ClutterActorTraverseVisitFlags
1879 unrealize_actor_after_children_cb (ClutterActor *self,
1883 /* We want to unset the realized flag only _after_
1884 * child actors are unrealized, to maintain invariants.
1886 CLUTTER_ACTOR_UNSET_FLAGS (self, CLUTTER_ACTOR_REALIZED);
1887 g_object_notify_by_pspec (G_OBJECT (self), obj_props[PROP_REALIZED]);
1888 return CLUTTER_ACTOR_TRAVERSE_VISIT_CONTINUE;
1892 * clutter_actor_unrealize_not_hiding:
1893 * @self: A #ClutterActor
1895 * Unrealization informs the actor that it may be being destroyed or
1896 * moved to another stage. The actor may want to destroy any
1897 * underlying graphics resources at this point. However it is
1898 * perfectly acceptable for it to retain the resources until the actor
1899 * is destroyed because Clutter only ever uses a single rendering
1900 * context and all of the graphics resources are valid on any stage.
1902 * Because mapped actors must be realized, actors may not be
1903 * unrealized if they are mapped. You must hide the actor or one of
1904 * its parents before attempting to unrealize.
1906 * This function is separate from clutter_actor_unrealize() because it
1907 * does not automatically hide the actor.
1908 * Actors need not be hidden to be unrealized, they just need to
1909 * be unmapped. In fact we don't want to mess up the application's
1910 * setting of the "visible" flag, so hiding is very undesirable.
1912 * clutter_actor_unrealize() does a clutter_actor_hide() just for
1913 * backward compatibility.
1916 clutter_actor_unrealize_not_hiding (ClutterActor *self)
1918 _clutter_actor_traverse (self,
1919 CLUTTER_ACTOR_TRAVERSE_DEPTH_FIRST,
1920 unrealize_actor_before_children_cb,
1921 unrealize_actor_after_children_cb,
1926 * _clutter_actor_rerealize:
1927 * @self: A #ClutterActor
1928 * @callback: Function to call while unrealized
1929 * @data: data for callback
1931 * If an actor is already unrealized, this just calls the callback.
1933 * If it is realized, it unrealizes temporarily, calls the callback,
1934 * and then re-realizes the actor.
1936 * As a side effect, leaves all children of the actor unrealized if
1937 * the actor was realized but not showing. This is because when we
1938 * unrealize the actor temporarily we must unrealize its children
1939 * (e.g. children of a stage can't be realized if stage window is
1940 * gone). And we aren't clever enough to save the realization state of
1941 * all children. In most cases this should not matter, because
1942 * the children will automatically realize when they next become mapped.
1945 _clutter_actor_rerealize (ClutterActor *self,
1946 ClutterCallback callback,
1949 gboolean was_mapped;
1950 gboolean was_showing;
1951 gboolean was_realized;
1953 g_return_if_fail (CLUTTER_IS_ACTOR (self));
1955 #ifdef CLUTTER_ENABLE_DEBUG
1956 clutter_actor_verify_map_state (self);
1959 was_realized = CLUTTER_ACTOR_IS_REALIZED (self);
1960 was_mapped = CLUTTER_ACTOR_IS_MAPPED (self);
1961 was_showing = CLUTTER_ACTOR_IS_VISIBLE (self);
1963 /* Must be unmapped to unrealize. Note we only have to hide this
1964 * actor if it was mapped (if all parents were showing). If actor
1965 * is merely visible (but not mapped), then that's fine, we can
1969 clutter_actor_hide (self);
1971 g_assert (!CLUTTER_ACTOR_IS_MAPPED (self));
1973 /* unrealize self and all children */
1974 clutter_actor_unrealize_not_hiding (self);
1976 if (callback != NULL)
1978 (* callback) (self, data);
1982 clutter_actor_show (self); /* will realize only if mapping implies it */
1983 else if (was_realized)
1984 clutter_actor_realize (self); /* realize self and all parents */
1988 clutter_actor_real_pick (ClutterActor *self,
1989 const ClutterColor *color)
1991 /* the default implementation is just to paint a rectangle
1992 * with the same size of the actor using the passed color
1994 if (clutter_actor_should_pick_paint (self))
1996 ClutterActorBox box = { 0, };
1997 float width, height;
1999 clutter_actor_get_allocation_box (self, &box);
2001 width = box.x2 - box.x1;
2002 height = box.y2 - box.y1;
2004 cogl_set_source_color4ub (color->red,
2009 cogl_rectangle (0, 0, width, height);
2012 /* XXX - this thoroughly sucks, but we need to maintain compatibility
2013 * with existing container classes that override the pick() virtual
2014 * and chain up to the default implementation - otherwise we'll end up
2015 * painting our children twice.
2017 * this has to go away for 2.0; hopefully along the pick() itself.
2019 if (CLUTTER_ACTOR_GET_CLASS (self)->pick == clutter_actor_real_pick)
2023 for (iter = self->priv->first_child;
2025 iter = iter->priv->next_sibling)
2026 clutter_actor_paint (iter);
2031 * clutter_actor_should_pick_paint:
2032 * @self: A #ClutterActor
2034 * Should be called inside the implementation of the
2035 * #ClutterActor::pick virtual function in order to check whether
2036 * the actor should paint itself in pick mode or not.
2038 * This function should never be called directly by applications.
2040 * Return value: %TRUE if the actor should paint its silhouette,
2044 clutter_actor_should_pick_paint (ClutterActor *self)
2046 g_return_val_if_fail (CLUTTER_IS_ACTOR (self), FALSE);
2048 if (CLUTTER_ACTOR_IS_MAPPED (self) &&
2049 (_clutter_context_get_pick_mode () == CLUTTER_PICK_ALL ||
2050 CLUTTER_ACTOR_IS_REACTIVE (self)))
2057 clutter_actor_real_get_preferred_width (ClutterActor *self,
2059 gfloat *min_width_p,
2060 gfloat *natural_width_p)
2062 ClutterActorPrivate *priv = self->priv;
2064 if (priv->n_children != 0 &&
2065 priv->layout_manager != NULL)
2067 ClutterContainer *container = CLUTTER_CONTAINER (self);
2069 CLUTTER_NOTE (LAYOUT, "Querying the layout manager '%s'[%p] "
2070 "for the preferred width",
2071 G_OBJECT_TYPE_NAME (priv->layout_manager),
2072 priv->layout_manager);
2074 clutter_layout_manager_get_preferred_width (priv->layout_manager,
2083 /* Default implementation is always 0x0, usually an actor
2084 * using this default is relying on someone to set the
2087 CLUTTER_NOTE (LAYOUT, "Default preferred width: 0, 0");
2092 if (natural_width_p)
2093 *natural_width_p = 0;
2097 clutter_actor_real_get_preferred_height (ClutterActor *self,
2099 gfloat *min_height_p,
2100 gfloat *natural_height_p)
2102 ClutterActorPrivate *priv = self->priv;
2104 if (priv->n_children != 0 &&
2105 priv->layout_manager != NULL)
2107 ClutterContainer *container = CLUTTER_CONTAINER (self);
2109 CLUTTER_NOTE (LAYOUT, "Querying the layout manager '%s'[%p] "
2110 "for the preferred height",
2111 G_OBJECT_TYPE_NAME (priv->layout_manager),
2112 priv->layout_manager);
2114 clutter_layout_manager_get_preferred_height (priv->layout_manager,
2122 /* Default implementation is always 0x0, usually an actor
2123 * using this default is relying on someone to set the
2126 CLUTTER_NOTE (LAYOUT, "Default preferred height: 0, 0");
2131 if (natural_height_p)
2132 *natural_height_p = 0;
2136 clutter_actor_store_old_geometry (ClutterActor *self,
2137 ClutterActorBox *box)
2139 *box = self->priv->allocation;
2143 clutter_actor_notify_if_geometry_changed (ClutterActor *self,
2144 const ClutterActorBox *old)
2146 ClutterActorPrivate *priv = self->priv;
2147 GObject *obj = G_OBJECT (self);
2149 g_object_freeze_notify (obj);
2151 /* to avoid excessive requisition or allocation cycles we
2152 * use the cached values.
2154 * - if we don't have an allocation we assume that we need
2156 * - if we don't have a width or a height request we notify
2158 * - if we have a valid allocation then we check the old
2159 * bounding box with the current allocation and we notify
2162 if (priv->needs_allocation)
2164 g_object_notify_by_pspec (obj, obj_props[PROP_X]);
2165 g_object_notify_by_pspec (obj, obj_props[PROP_Y]);
2166 g_object_notify_by_pspec (obj, obj_props[PROP_WIDTH]);
2167 g_object_notify_by_pspec (obj, obj_props[PROP_HEIGHT]);
2169 else if (priv->needs_width_request || priv->needs_height_request)
2171 g_object_notify_by_pspec (obj, obj_props[PROP_WIDTH]);
2172 g_object_notify_by_pspec (obj, obj_props[PROP_HEIGHT]);
2177 gfloat width, height;
2179 x = priv->allocation.x1;
2180 y = priv->allocation.y1;
2181 width = priv->allocation.x2 - priv->allocation.x1;
2182 height = priv->allocation.y2 - priv->allocation.y1;
2185 g_object_notify_by_pspec (obj, obj_props[PROP_X]);
2188 g_object_notify_by_pspec (obj, obj_props[PROP_Y]);
2190 if (width != (old->x2 - old->x1))
2191 g_object_notify_by_pspec (obj, obj_props[PROP_WIDTH]);
2193 if (height != (old->y2 - old->y1))
2194 g_object_notify_by_pspec (obj, obj_props[PROP_HEIGHT]);
2197 g_object_thaw_notify (obj);
2201 * clutter_actor_set_allocation_internal:
2202 * @self: a #ClutterActor
2203 * @box: a #ClutterActorBox
2204 * @flags: allocation flags
2206 * Stores the allocation of @self.
2208 * This function only performs basic storage and property notification.
2210 * This function should be called by clutter_actor_set_allocation()
2211 * and by the default implementation of #ClutterActorClass.allocate().
2213 * Return value: %TRUE if the allocation of the #ClutterActor has been
2214 * changed, and %FALSE otherwise
2216 static inline gboolean
2217 clutter_actor_set_allocation_internal (ClutterActor *self,
2218 const ClutterActorBox *box,
2219 ClutterAllocationFlags flags)
2221 ClutterActorPrivate *priv = self->priv;
2223 gboolean x1_changed, y1_changed, x2_changed, y2_changed;
2224 gboolean flags_changed;
2226 ClutterActorBox old_alloc = { 0, };
2228 obj = G_OBJECT (self);
2230 g_object_freeze_notify (obj);
2232 clutter_actor_store_old_geometry (self, &old_alloc);
2234 x1_changed = priv->allocation.x1 != box->x1;
2235 y1_changed = priv->allocation.y1 != box->y1;
2236 x2_changed = priv->allocation.x2 != box->x2;
2237 y2_changed = priv->allocation.y2 != box->y2;
2239 flags_changed = priv->allocation_flags != flags;
2241 priv->allocation = *box;
2242 priv->allocation_flags = flags;
2244 /* allocation is authoritative */
2245 priv->needs_width_request = FALSE;
2246 priv->needs_height_request = FALSE;
2247 priv->needs_allocation = FALSE;
2249 if (x1_changed || y1_changed ||
2250 x2_changed || y2_changed ||
2253 CLUTTER_NOTE (LAYOUT, "Allocation for '%s' changed",
2254 _clutter_actor_get_debug_name (self));
2256 priv->transform_valid = FALSE;
2258 g_object_notify_by_pspec (obj, obj_props[PROP_ALLOCATION]);
2260 /* if the allocation changes, so does the content box */
2261 if (priv->content != NULL)
2262 g_object_notify_by_pspec (obj, obj_props[PROP_CONTENT_BOX]);
2269 clutter_actor_notify_if_geometry_changed (self, &old_alloc);
2271 g_object_thaw_notify (obj);
2276 static void clutter_actor_real_allocate (ClutterActor *self,
2277 const ClutterActorBox *box,
2278 ClutterAllocationFlags flags);
2281 clutter_actor_maybe_layout_children (ClutterActor *self,
2282 const ClutterActorBox *allocation,
2283 ClutterAllocationFlags flags)
2285 ClutterActorPrivate *priv = self->priv;
2287 /* this is going to be a bit hard to follow, so let's put an explanation
2290 * we want ClutterActor to have a default layout manager if the actor was
2291 * created using "g_object_new (CLUTTER_TYPE_ACTOR, NULL)".
2293 * we also want any subclass of ClutterActor that does not override the
2294 * ::allocate() virtual function to delegate to a layout manager.
2296 * finally, we want to allow people subclassing ClutterActor and overriding
2297 * the ::allocate() vfunc to let Clutter delegate to the layout manager.
2299 * on the other hand, we want existing actor subclasses overriding the
2300 * ::allocate() virtual function and chaining up to the parent's
2301 * implementation to continue working without allocating their children
2302 * twice, or without entering an allocation loop.
2304 * for the first two points, we check if the class of the actor is
2305 * overridding the ::allocate() virtual function; if it isn't, then we
2306 * follow through with checking whether we have children and a layout
2307 * manager, and eventually calling clutter_layout_manager_allocate().
2309 * for the third point, we check the CLUTTER_DELEGATE_LAYOUT flag in the
2310 * allocation flags that we got passed, and if it is present, we continue
2311 * with the check above.
2313 * if neither of these two checks yields a positive result, we just
2314 * assume that the ::allocate() virtual function that resulted in this
2315 * function being called will also allocate the children of the actor.
2318 if (CLUTTER_ACTOR_GET_CLASS (self)->allocate == clutter_actor_real_allocate)
2321 if ((flags & CLUTTER_DELEGATE_LAYOUT) != 0)
2327 if (priv->n_children != 0 &&
2328 priv->layout_manager != NULL)
2330 ClutterContainer *container = CLUTTER_CONTAINER (self);
2331 ClutterAllocationFlags children_flags;
2332 ClutterActorBox children_box;
2334 /* normalize the box passed to the layout manager */
2335 children_box.x1 = children_box.y1 = 0.f;
2336 children_box.x2 = (allocation->x2 - allocation->x1);
2337 children_box.y2 = (allocation->y2 - allocation->y1);
2339 /* remove the DELEGATE_LAYOUT flag; this won't be passed to
2340 * the actor's children, since it refers only to the current
2341 * actor's allocation.
2343 children_flags = flags;
2344 children_flags &= ~CLUTTER_DELEGATE_LAYOUT;
2346 CLUTTER_NOTE (LAYOUT,
2347 "Allocating %d children of %s "
2348 "at { %.2f, %.2f - %.2f x %.2f } "
2351 _clutter_actor_get_debug_name (self),
2354 (allocation->x2 - allocation->x1),
2355 (allocation->y2 - allocation->y1),
2356 G_OBJECT_TYPE_NAME (priv->layout_manager));
2358 clutter_layout_manager_allocate (priv->layout_manager,
2366 clutter_actor_real_allocate (ClutterActor *self,
2367 const ClutterActorBox *box,
2368 ClutterAllocationFlags flags)
2370 ClutterActorPrivate *priv = self->priv;
2373 g_object_freeze_notify (G_OBJECT (self));
2375 changed = clutter_actor_set_allocation_internal (self, box, flags);
2377 /* we allocate our children before we notify changes in our geometry,
2378 * so that people connecting to properties will be able to get valid
2379 * data out of the sub-tree of the scene graph that has this actor at
2382 clutter_actor_maybe_layout_children (self, box, flags);
2386 ClutterActorBox signal_box = priv->allocation;
2387 ClutterAllocationFlags signal_flags = priv->allocation_flags;
2389 g_signal_emit (self, actor_signals[ALLOCATION_CHANGED], 0,
2394 g_object_thaw_notify (G_OBJECT (self));
2398 _clutter_actor_signal_queue_redraw (ClutterActor *self,
2399 ClutterActor *origin)
2401 /* no point in queuing a redraw on a destroyed actor */
2402 if (CLUTTER_ACTOR_IN_DESTRUCTION (self))
2405 /* NB: We can't bail out early here if the actor is hidden in case
2406 * the actor bas been cloned. In this case the clone will need to
2407 * receive the signal so it can queue its own redraw.
2410 /* calls klass->queue_redraw in default handler */
2411 g_signal_emit (self, actor_signals[QUEUE_REDRAW], 0, origin);
2415 clutter_actor_real_queue_redraw (ClutterActor *self,
2416 ClutterActor *origin)
2418 ClutterActor *parent;
2420 CLUTTER_NOTE (PAINT, "Redraw queued on '%s' (from: '%s')",
2421 _clutter_actor_get_debug_name (self),
2422 origin != NULL ? _clutter_actor_get_debug_name (origin)
2425 /* no point in queuing a redraw on a destroyed actor */
2426 if (CLUTTER_ACTOR_IN_DESTRUCTION (self))
2429 /* If the queue redraw is coming from a child then the actor has
2430 become dirty and any queued effect is no longer valid */
2433 self->priv->is_dirty = TRUE;
2434 self->priv->effect_to_redraw = NULL;
2437 /* If the actor isn't visible, we still had to emit the signal
2438 * to allow for a ClutterClone, but the appearance of the parent
2439 * won't change so we don't have to propagate up the hierarchy.
2441 if (!CLUTTER_ACTOR_IS_VISIBLE (self))
2444 /* Although we could determine here that a full stage redraw
2445 * has already been queued and immediately bail out, we actually
2446 * guarantee that we will propagate a queue-redraw signal to our
2447 * parent at least once so that it's possible to implement a
2448 * container that tracks which of its children have queued a
2451 if (self->priv->propagated_one_redraw)
2453 ClutterActor *stage = _clutter_actor_get_stage_internal (self);
2454 if (stage != NULL &&
2455 _clutter_stage_has_full_redraw_queued (CLUTTER_STAGE (stage)))
2459 self->priv->propagated_one_redraw = TRUE;
2461 /* notify parents, if they are all visible eventually we'll
2462 * queue redraw on the stage, which queues the redraw idle.
2464 parent = clutter_actor_get_parent (self);
2467 /* this will go up recursively */
2468 _clutter_actor_signal_queue_redraw (parent, origin);
2473 clutter_actor_real_queue_relayout (ClutterActor *self)
2475 ClutterActorPrivate *priv = self->priv;
2477 /* no point in queueing a redraw on a destroyed actor */
2478 if (CLUTTER_ACTOR_IN_DESTRUCTION (self))
2481 priv->needs_width_request = TRUE;
2482 priv->needs_height_request = TRUE;
2483 priv->needs_allocation = TRUE;
2485 /* reset the cached size requests */
2486 memset (priv->width_requests, 0,
2487 N_CACHED_SIZE_REQUESTS * sizeof (SizeRequest));
2488 memset (priv->height_requests, 0,
2489 N_CACHED_SIZE_REQUESTS * sizeof (SizeRequest));
2491 /* We need to go all the way up the hierarchy */
2492 if (priv->parent != NULL)
2493 _clutter_actor_queue_only_relayout (priv->parent);
2497 * clutter_actor_apply_relative_transform_to_point:
2498 * @self: A #ClutterActor
2499 * @ancestor: (allow-none): A #ClutterActor ancestor, or %NULL to use the
2500 * default #ClutterStage
2501 * @point: A point as #ClutterVertex
2502 * @vertex: (out caller-allocates): The translated #ClutterVertex
2504 * Transforms @point in coordinates relative to the actor into
2505 * ancestor-relative coordinates using the relevant transform
2506 * stack (i.e. scale, rotation, etc).
2508 * If @ancestor is %NULL the ancestor will be the #ClutterStage. In
2509 * this case, the coordinates returned will be the coordinates on
2510 * the stage before the projection is applied. This is different from
2511 * the behaviour of clutter_actor_apply_transform_to_point().
2516 clutter_actor_apply_relative_transform_to_point (ClutterActor *self,
2517 ClutterActor *ancestor,
2518 const ClutterVertex *point,
2519 ClutterVertex *vertex)
2524 g_return_if_fail (CLUTTER_IS_ACTOR (self));
2525 g_return_if_fail (ancestor == NULL || CLUTTER_IS_ACTOR (ancestor));
2526 g_return_if_fail (point != NULL);
2527 g_return_if_fail (vertex != NULL);
2532 if (ancestor == NULL)
2533 ancestor = _clutter_actor_get_stage_internal (self);
2535 if (ancestor == NULL)
2541 _clutter_actor_get_relative_transformation_matrix (self, ancestor, &matrix);
2542 cogl_matrix_transform_point (&matrix, &vertex->x, &vertex->y, &vertex->z, &w);
2546 _clutter_actor_fully_transform_vertices (ClutterActor *self,
2547 const ClutterVertex *vertices_in,
2548 ClutterVertex *vertices_out,
2551 ClutterActor *stage;
2552 CoglMatrix modelview;
2553 CoglMatrix projection;
2556 g_return_val_if_fail (CLUTTER_IS_ACTOR (self), FALSE);
2558 stage = _clutter_actor_get_stage_internal (self);
2560 /* We really can't do anything meaningful in this case so don't try
2561 * to do any transform */
2565 /* Note: we pass NULL as the ancestor because we don't just want the modelview
2566 * that gets us to stage coordinates, we want to go all the way to eye
2568 _clutter_actor_apply_relative_transformation_matrix (self, NULL, &modelview);
2570 /* Fetch the projection and viewport */
2571 _clutter_stage_get_projection_matrix (CLUTTER_STAGE (stage), &projection);
2572 _clutter_stage_get_viewport (CLUTTER_STAGE (stage),
2578 _clutter_util_fully_transform_vertices (&modelview,
2589 * clutter_actor_apply_transform_to_point:
2590 * @self: A #ClutterActor
2591 * @point: A point as #ClutterVertex
2592 * @vertex: (out caller-allocates): The translated #ClutterVertex
2594 * Transforms @point in coordinates relative to the actor
2595 * into screen-relative coordinates with the current actor
2596 * transformation (i.e. scale, rotation, etc)
2601 clutter_actor_apply_transform_to_point (ClutterActor *self,
2602 const ClutterVertex *point,
2603 ClutterVertex *vertex)
2605 g_return_if_fail (point != NULL);
2606 g_return_if_fail (vertex != NULL);
2607 _clutter_actor_fully_transform_vertices (self, point, vertex, 1);
2611 * _clutter_actor_get_relative_transformation_matrix:
2612 * @self: The actor whose coordinate space you want to transform from.
2613 * @ancestor: The ancestor actor whose coordinate space you want to transform too
2614 * or %NULL if you want to transform all the way to eye coordinates.
2615 * @matrix: A #CoglMatrix to store the transformation
2617 * This gets a transformation @matrix that will transform coordinates from the
2618 * coordinate space of @self into the coordinate space of @ancestor.
2620 * For example if you need a matrix that can transform the local actor
2621 * coordinates of @self into stage coordinates you would pass the actor's stage
2622 * pointer as the @ancestor.
2624 * If you pass %NULL then the transformation will take you all the way through
2625 * to eye coordinates. This can be useful if you want to extract the entire
2626 * modelview transform that Clutter applies before applying the projection
2627 * transformation. If you want to explicitly set a modelview on a CoglFramebuffer
2628 * using cogl_set_modelview_matrix() for example then you would want a matrix
2629 * that transforms into eye coordinates.
2631 * <note><para>This function explicitly initializes the given @matrix. If you just
2632 * want clutter to multiply a relative transformation with an existing matrix
2633 * you can use clutter_actor_apply_relative_transformation_matrix()
2634 * instead.</para></note>
2637 /* XXX: We should consider caching the stage relative modelview along with
2638 * the actor itself */
2640 _clutter_actor_get_relative_transformation_matrix (ClutterActor *self,
2641 ClutterActor *ancestor,
2644 cogl_matrix_init_identity (matrix);
2646 _clutter_actor_apply_relative_transformation_matrix (self, ancestor, matrix);
2649 /* Project the given @box into stage window coordinates, writing the
2650 * transformed vertices to @verts[]. */
2652 _clutter_actor_transform_and_project_box (ClutterActor *self,
2653 const ClutterActorBox *box,
2654 ClutterVertex verts[])
2656 ClutterVertex box_vertices[4];
2658 box_vertices[0].x = box->x1;
2659 box_vertices[0].y = box->y1;
2660 box_vertices[0].z = 0;
2661 box_vertices[1].x = box->x2;
2662 box_vertices[1].y = box->y1;
2663 box_vertices[1].z = 0;
2664 box_vertices[2].x = box->x1;
2665 box_vertices[2].y = box->y2;
2666 box_vertices[2].z = 0;
2667 box_vertices[3].x = box->x2;
2668 box_vertices[3].y = box->y2;
2669 box_vertices[3].z = 0;
2672 _clutter_actor_fully_transform_vertices (self, box_vertices, verts, 4);
2676 * clutter_actor_get_allocation_vertices:
2677 * @self: A #ClutterActor
2678 * @ancestor: (allow-none): A #ClutterActor to calculate the vertices
2679 * against, or %NULL to use the #ClutterStage
2680 * @verts: (out) (array fixed-size=4) (element-type Clutter.Vertex): return
2681 * location for an array of 4 #ClutterVertex in which to store the result
2683 * Calculates the transformed coordinates of the four corners of the
2684 * actor in the plane of @ancestor. The returned vertices relate to
2685 * the #ClutterActorBox coordinates as follows:
2687 * <listitem><para>@verts[0] contains (x1, y1)</para></listitem>
2688 * <listitem><para>@verts[1] contains (x2, y1)</para></listitem>
2689 * <listitem><para>@verts[2] contains (x1, y2)</para></listitem>
2690 * <listitem><para>@verts[3] contains (x2, y2)</para></listitem>
2693 * If @ancestor is %NULL the ancestor will be the #ClutterStage. In
2694 * this case, the coordinates returned will be the coordinates on
2695 * the stage before the projection is applied. This is different from
2696 * the behaviour of clutter_actor_get_abs_allocation_vertices().
2701 clutter_actor_get_allocation_vertices (ClutterActor *self,
2702 ClutterActor *ancestor,
2703 ClutterVertex verts[])
2705 ClutterActorPrivate *priv;
2706 ClutterActorBox box;
2707 ClutterVertex vertices[4];
2708 CoglMatrix modelview;
2710 g_return_if_fail (CLUTTER_IS_ACTOR (self));
2711 g_return_if_fail (ancestor == NULL || CLUTTER_IS_ACTOR (ancestor));
2713 if (ancestor == NULL)
2714 ancestor = _clutter_actor_get_stage_internal (self);
2716 /* Fallback to a NOP transform if the actor isn't parented under a
2718 if (ancestor == NULL)
2723 /* if the actor needs to be allocated we force a relayout, so that
2724 * we will have valid values to use in the transformations */
2725 if (priv->needs_allocation)
2727 ClutterActor *stage = _clutter_actor_get_stage_internal (self);
2729 _clutter_stage_maybe_relayout (stage);
2732 box.x1 = box.y1 = 0;
2733 /* The result isn't really meaningful in this case but at
2734 * least try to do something *vaguely* reasonable... */
2735 clutter_actor_get_size (self, &box.x2, &box.y2);
2739 clutter_actor_get_allocation_box (self, &box);
2741 vertices[0].x = box.x1;
2742 vertices[0].y = box.y1;
2744 vertices[1].x = box.x2;
2745 vertices[1].y = box.y1;
2747 vertices[2].x = box.x1;
2748 vertices[2].y = box.y2;
2750 vertices[3].x = box.x2;
2751 vertices[3].y = box.y2;
2754 _clutter_actor_get_relative_transformation_matrix (self, ancestor,
2757 cogl_matrix_transform_points (&modelview,
2759 sizeof (ClutterVertex),
2761 sizeof (ClutterVertex),
2767 * clutter_actor_get_abs_allocation_vertices:
2768 * @self: A #ClutterActor
2769 * @verts: (out) (array fixed-size=4): Pointer to a location of an array
2770 * of 4 #ClutterVertex where to store the result.
2772 * Calculates the transformed screen coordinates of the four corners of
2773 * the actor; the returned vertices relate to the #ClutterActorBox
2774 * coordinates as follows:
2776 * <listitem><para>v[0] contains (x1, y1)</para></listitem>
2777 * <listitem><para>v[1] contains (x2, y1)</para></listitem>
2778 * <listitem><para>v[2] contains (x1, y2)</para></listitem>
2779 * <listitem><para>v[3] contains (x2, y2)</para></listitem>
2785 clutter_actor_get_abs_allocation_vertices (ClutterActor *self,
2786 ClutterVertex verts[])
2788 ClutterActorPrivate *priv;
2789 ClutterActorBox actor_space_allocation;
2791 g_return_if_fail (CLUTTER_IS_ACTOR (self));
2795 /* if the actor needs to be allocated we force a relayout, so that
2796 * the actor allocation box will be valid for
2797 * _clutter_actor_transform_and_project_box()
2799 if (priv->needs_allocation)
2801 ClutterActor *stage = _clutter_actor_get_stage_internal (self);
2802 /* There's nothing meaningful we can do now */
2806 _clutter_stage_maybe_relayout (stage);
2809 /* NB: _clutter_actor_transform_and_project_box expects a box in the actor's
2810 * own coordinate space... */
2811 actor_space_allocation.x1 = 0;
2812 actor_space_allocation.y1 = 0;
2813 actor_space_allocation.x2 = priv->allocation.x2 - priv->allocation.x1;
2814 actor_space_allocation.y2 = priv->allocation.y2 - priv->allocation.y1;
2815 _clutter_actor_transform_and_project_box (self,
2816 &actor_space_allocation,
2821 clutter_actor_real_apply_transform (ClutterActor *self,
2824 ClutterActorPrivate *priv = self->priv;
2826 if (!priv->transform_valid)
2828 CoglMatrix *transform = &priv->transform;
2829 const ClutterTransformInfo *info;
2831 info = _clutter_actor_get_transform_info_or_defaults (self);
2833 cogl_matrix_init_identity (transform);
2835 cogl_matrix_translate (transform,
2836 priv->allocation.x1,
2837 priv->allocation.y1,
2841 cogl_matrix_translate (transform, 0, 0, info->depth);
2844 * because the rotation involves translations, we must scale
2845 * before applying the rotations (if we apply the scale after
2846 * the rotations, the translations included in the rotation are
2847 * not scaled and so the entire object will move on the screen
2848 * as a result of rotating it).
2850 if (info->scale_x != 1.0 || info->scale_y != 1.0)
2852 TRANSFORM_ABOUT_ANCHOR_COORD (self, transform,
2853 &info->scale_center,
2854 cogl_matrix_scale (transform,
2861 TRANSFORM_ABOUT_ANCHOR_COORD (self, transform,
2863 cogl_matrix_rotate (transform,
2868 TRANSFORM_ABOUT_ANCHOR_COORD (self, transform,
2870 cogl_matrix_rotate (transform,
2875 TRANSFORM_ABOUT_ANCHOR_COORD (self, transform,
2877 cogl_matrix_rotate (transform,
2881 if (!clutter_anchor_coord_is_zero (&info->anchor))
2885 clutter_anchor_coord_get_units (self, &info->anchor, &x, &y, &z);
2886 cogl_matrix_translate (transform, -x, -y, -z);
2889 priv->transform_valid = TRUE;
2892 cogl_matrix_multiply (matrix, matrix, &priv->transform);
2895 /* Applies the transforms associated with this actor to the given
2898 _clutter_actor_apply_modelview_transform (ClutterActor *self,
2901 CLUTTER_ACTOR_GET_CLASS (self)->apply_transform (self, matrix);
2905 * clutter_actor_apply_relative_transformation_matrix:
2906 * @self: The actor whose coordinate space you want to transform from.
2907 * @ancestor: The ancestor actor whose coordinate space you want to transform too
2908 * or %NULL if you want to transform all the way to eye coordinates.
2909 * @matrix: A #CoglMatrix to apply the transformation too.
2911 * This multiplies a transform with @matrix that will transform coordinates
2912 * from the coordinate space of @self into the coordinate space of @ancestor.
2914 * For example if you need a matrix that can transform the local actor
2915 * coordinates of @self into stage coordinates you would pass the actor's stage
2916 * pointer as the @ancestor.
2918 * If you pass %NULL then the transformation will take you all the way through
2919 * to eye coordinates. This can be useful if you want to extract the entire
2920 * modelview transform that Clutter applies before applying the projection
2921 * transformation. If you want to explicitly set a modelview on a CoglFramebuffer
2922 * using cogl_set_modelview_matrix() for example then you would want a matrix
2923 * that transforms into eye coordinates.
2925 * <note>This function doesn't initialize the given @matrix, it simply
2926 * multiplies the requested transformation matrix with the existing contents of
2927 * @matrix. You can use cogl_matrix_init_identity() to initialize the @matrix
2928 * before calling this function, or you can use
2929 * clutter_actor_get_relative_transformation_matrix() instead.</note>
2932 _clutter_actor_apply_relative_transformation_matrix (ClutterActor *self,
2933 ClutterActor *ancestor,
2936 ClutterActor *parent;
2938 /* Note we terminate before ever calling stage->apply_transform()
2939 * since that would conceptually be relative to the underlying
2940 * window OpenGL coordinates so we'd need a special @ancestor
2941 * value to represent the fake parent of the stage. */
2942 if (self == ancestor)
2945 parent = clutter_actor_get_parent (self);
2948 _clutter_actor_apply_relative_transformation_matrix (parent, ancestor,
2951 _clutter_actor_apply_modelview_transform (self, matrix);
2955 _clutter_actor_draw_paint_volume_full (ClutterActor *self,
2956 ClutterPaintVolume *pv,
2958 const CoglColor *color)
2960 static CoglPipeline *outline = NULL;
2961 CoglPrimitive *prim;
2962 ClutterVertex line_ends[12 * 2];
2965 clutter_backend_get_cogl_context (clutter_get_default_backend ());
2966 /* XXX: at some point we'll query this from the stage but we can't
2967 * do that until the osx backend uses Cogl natively. */
2968 CoglFramebuffer *fb = cogl_get_draw_framebuffer ();
2970 if (outline == NULL)
2971 outline = cogl_pipeline_new (ctx);
2973 _clutter_paint_volume_complete (pv);
2975 n_vertices = pv->is_2d ? 4 * 2 : 12 * 2;
2978 line_ends[0] = pv->vertices[0]; line_ends[1] = pv->vertices[1];
2979 line_ends[2] = pv->vertices[1]; line_ends[3] = pv->vertices[2];
2980 line_ends[4] = pv->vertices[2]; line_ends[5] = pv->vertices[3];
2981 line_ends[6] = pv->vertices[3]; line_ends[7] = pv->vertices[0];
2986 line_ends[8] = pv->vertices[4]; line_ends[9] = pv->vertices[5];
2987 line_ends[10] = pv->vertices[5]; line_ends[11] = pv->vertices[6];
2988 line_ends[12] = pv->vertices[6]; line_ends[13] = pv->vertices[7];
2989 line_ends[14] = pv->vertices[7]; line_ends[15] = pv->vertices[4];
2991 /* Lines connecting front face to back face */
2992 line_ends[16] = pv->vertices[0]; line_ends[17] = pv->vertices[4];
2993 line_ends[18] = pv->vertices[1]; line_ends[19] = pv->vertices[5];
2994 line_ends[20] = pv->vertices[2]; line_ends[21] = pv->vertices[6];
2995 line_ends[22] = pv->vertices[3]; line_ends[23] = pv->vertices[7];
2998 prim = cogl_primitive_new_p3 (ctx, COGL_VERTICES_MODE_LINES,
3000 (CoglVertexP3 *)line_ends);
3002 cogl_pipeline_set_color (outline, color);
3003 cogl_framebuffer_draw_primitive (fb, outline, prim);
3004 cogl_object_unref (prim);
3008 PangoLayout *layout;
3009 layout = pango_layout_new (clutter_actor_get_pango_context (self));
3010 pango_layout_set_text (layout, label, -1);
3011 cogl_pango_render_layout (layout,
3016 g_object_unref (layout);
3021 _clutter_actor_draw_paint_volume (ClutterActor *self)
3023 ClutterPaintVolume *pv;
3026 pv = _clutter_actor_get_paint_volume_mutable (self);
3029 gfloat width, height;
3030 ClutterPaintVolume fake_pv;
3032 ClutterActor *stage = _clutter_actor_get_stage_internal (self);
3033 _clutter_paint_volume_init_static (&fake_pv, stage);
3035 clutter_actor_get_size (self, &width, &height);
3036 clutter_paint_volume_set_width (&fake_pv, width);
3037 clutter_paint_volume_set_height (&fake_pv, height);
3039 cogl_color_init_from_4f (&color, 0, 0, 1, 1);
3040 _clutter_actor_draw_paint_volume_full (self, &fake_pv,
3041 _clutter_actor_get_debug_name (self),
3044 clutter_paint_volume_free (&fake_pv);
3048 cogl_color_init_from_4f (&color, 0, 1, 0, 1);
3049 _clutter_actor_draw_paint_volume_full (self, pv,
3050 _clutter_actor_get_debug_name (self),
3056 _clutter_actor_paint_cull_result (ClutterActor *self,
3058 ClutterCullResult result)
3060 ClutterPaintVolume *pv;
3065 if (result == CLUTTER_CULL_RESULT_IN)
3066 cogl_color_init_from_4f (&color, 0, 1, 0, 1);
3067 else if (result == CLUTTER_CULL_RESULT_OUT)
3068 cogl_color_init_from_4f (&color, 0, 0, 1, 1);
3070 cogl_color_init_from_4f (&color, 0, 1, 1, 1);
3073 cogl_color_init_from_4f (&color, 1, 1, 1, 1);
3075 if (success && (pv = _clutter_actor_get_paint_volume_mutable (self)))
3076 _clutter_actor_draw_paint_volume_full (self, pv,
3077 _clutter_actor_get_debug_name (self),
3081 PangoLayout *layout;
3083 g_strdup_printf ("CULL FAILURE: %s", _clutter_actor_get_debug_name (self));
3084 cogl_color_init_from_4f (&color, 1, 1, 1, 1);
3085 cogl_set_source_color (&color);
3087 layout = pango_layout_new (clutter_actor_get_pango_context (self));
3088 pango_layout_set_text (layout, label, -1);
3089 cogl_pango_render_layout (layout,
3095 g_object_unref (layout);
3099 static int clone_paint_level = 0;
3102 _clutter_actor_push_clone_paint (void)
3104 clone_paint_level++;
3108 _clutter_actor_pop_clone_paint (void)
3110 clone_paint_level--;
3114 in_clone_paint (void)
3116 return clone_paint_level > 0;
3119 /* Returns TRUE if the actor can be ignored */
3120 /* FIXME: we should return a ClutterCullResult, and
3121 * clutter_actor_paint should understand that a CLUTTER_CULL_RESULT_IN
3122 * means there's no point in trying to cull descendants of the current
3125 cull_actor (ClutterActor *self, ClutterCullResult *result_out)
3127 ClutterActorPrivate *priv = self->priv;
3128 ClutterActor *stage;
3129 const ClutterPlane *stage_clip;
3131 if (!priv->last_paint_volume_valid)
3133 CLUTTER_NOTE (CLIPPING, "Bail from cull_actor without culling (%s): "
3134 "->last_paint_volume_valid == FALSE",
3135 _clutter_actor_get_debug_name (self));
3139 if (G_UNLIKELY (clutter_paint_debug_flags & CLUTTER_DEBUG_DISABLE_CULLING))
3142 stage = _clutter_actor_get_stage_internal (self);
3143 stage_clip = _clutter_stage_get_clip (CLUTTER_STAGE (stage));
3144 if (G_UNLIKELY (!stage_clip))
3146 CLUTTER_NOTE (CLIPPING, "Bail from cull_actor without culling (%s): "
3147 "No stage clip set",
3148 _clutter_actor_get_debug_name (self));
3152 if (cogl_get_draw_framebuffer () !=
3153 _clutter_stage_get_active_framebuffer (CLUTTER_STAGE (stage)))
3155 CLUTTER_NOTE (CLIPPING, "Bail from cull_actor without culling (%s): "
3156 "Current framebuffer doesn't correspond to stage",
3157 _clutter_actor_get_debug_name (self));
3162 _clutter_paint_volume_cull (&priv->last_paint_volume, stage_clip);
3167 _clutter_actor_update_last_paint_volume (ClutterActor *self)
3169 ClutterActorPrivate *priv = self->priv;
3170 const ClutterPaintVolume *pv;
3172 if (priv->last_paint_volume_valid)
3174 clutter_paint_volume_free (&priv->last_paint_volume);
3175 priv->last_paint_volume_valid = FALSE;
3178 pv = clutter_actor_get_paint_volume (self);
3181 CLUTTER_NOTE (CLIPPING, "Bail from update_last_paint_volume (%s): "
3182 "Actor failed to report a paint volume",
3183 _clutter_actor_get_debug_name (self));
3187 _clutter_paint_volume_copy_static (pv, &priv->last_paint_volume);
3189 _clutter_paint_volume_transform_relative (&priv->last_paint_volume,
3190 NULL); /* eye coordinates */
3192 priv->last_paint_volume_valid = TRUE;
3195 static inline gboolean
3196 actor_has_shader_data (ClutterActor *self)
3198 return g_object_get_qdata (G_OBJECT (self), quark_shader_data) != NULL;
3202 _clutter_actor_get_pick_id (ClutterActor *self)
3204 if (self->priv->pick_id < 0)
3207 return self->priv->pick_id;
3210 /* This is the same as clutter_actor_add_effect except that it doesn't
3211 queue a redraw and it doesn't notify on the effect property */
3213 _clutter_actor_add_effect_internal (ClutterActor *self,
3214 ClutterEffect *effect)
3216 ClutterActorPrivate *priv = self->priv;
3218 if (priv->effects == NULL)
3220 priv->effects = g_object_new (CLUTTER_TYPE_META_GROUP, NULL);
3221 priv->effects->actor = self;
3224 _clutter_meta_group_add_meta (priv->effects, CLUTTER_ACTOR_META (effect));
3227 /* This is the same as clutter_actor_remove_effect except that it doesn't
3228 queue a redraw and it doesn't notify on the effect property */
3230 _clutter_actor_remove_effect_internal (ClutterActor *self,
3231 ClutterEffect *effect)
3233 ClutterActorPrivate *priv = self->priv;
3235 if (priv->effects == NULL)
3238 _clutter_meta_group_remove_meta (priv->effects, CLUTTER_ACTOR_META (effect));
3242 needs_flatten_effect (ClutterActor *self)
3244 ClutterActorPrivate *priv = self->priv;
3246 if (G_UNLIKELY (clutter_paint_debug_flags &
3247 CLUTTER_DEBUG_DISABLE_OFFSCREEN_REDIRECT))
3250 if (priv->offscreen_redirect & CLUTTER_OFFSCREEN_REDIRECT_ALWAYS)
3252 else if (priv->offscreen_redirect & CLUTTER_OFFSCREEN_REDIRECT_AUTOMATIC_FOR_OPACITY)
3254 if (clutter_actor_get_paint_opacity (self) < 255 &&
3255 clutter_actor_has_overlaps (self))
3263 add_or_remove_flatten_effect (ClutterActor *self)
3265 ClutterActorPrivate *priv = self->priv;
3267 /* Add or remove the flatten effect depending on the
3268 offscreen-redirect property. */
3269 if (needs_flatten_effect (self))
3271 if (priv->flatten_effect == NULL)
3273 ClutterActorMeta *actor_meta;
3276 priv->flatten_effect = _clutter_flatten_effect_new ();
3277 /* Keep a reference to the effect so that we can queue
3279 g_object_ref_sink (priv->flatten_effect);
3281 /* Set the priority of the effect to high so that it will
3282 always be applied to the actor first. It uses an internal
3283 priority so that it won't be visible to applications */
3284 actor_meta = CLUTTER_ACTOR_META (priv->flatten_effect);
3285 priority = CLUTTER_ACTOR_META_PRIORITY_INTERNAL_HIGH;
3286 _clutter_actor_meta_set_priority (actor_meta, priority);
3288 /* This will add the effect without queueing a redraw */
3289 _clutter_actor_add_effect_internal (self, priv->flatten_effect);
3294 if (priv->flatten_effect != NULL)
3296 /* Destroy the effect so that it will lose its fbo cache of
3298 _clutter_actor_remove_effect_internal (self, priv->flatten_effect);
3299 g_clear_object (&priv->flatten_effect);
3305 clutter_actor_real_paint (ClutterActor *actor)
3307 ClutterActorPrivate *priv = actor->priv;
3310 for (iter = priv->first_child;
3312 iter = iter->priv->next_sibling)
3314 CLUTTER_NOTE (PAINT, "Painting %s, child of %s, at { %.2f, %.2f - %.2f x %.2f }",
3315 _clutter_actor_get_debug_name (iter),
3316 _clutter_actor_get_debug_name (actor),
3317 iter->priv->allocation.x1,
3318 iter->priv->allocation.y1,
3319 iter->priv->allocation.x2 - iter->priv->allocation.x1,
3320 iter->priv->allocation.y2 - iter->priv->allocation.y1);
3322 clutter_actor_paint (iter);
3327 clutter_actor_paint_node (ClutterActor *actor,
3328 ClutterPaintNode *root)
3330 ClutterActorPrivate *priv = actor->priv;
3335 if (priv->bg_color_set &&
3336 !clutter_color_equal (&priv->bg_color, CLUTTER_COLOR_Transparent))
3338 ClutterPaintNode *node;
3339 ClutterColor bg_color;
3340 ClutterActorBox box;
3344 box.x2 = clutter_actor_box_get_width (&priv->allocation);
3345 box.y2 = clutter_actor_box_get_height (&priv->allocation);
3347 bg_color = priv->bg_color;
3348 bg_color.alpha = clutter_actor_get_paint_opacity_internal (actor)
3349 * priv->bg_color.alpha
3352 node = clutter_color_node_new (&bg_color);
3353 clutter_paint_node_set_name (node, "backgroundColor");
3354 clutter_paint_node_add_rectangle (node, &box);
3355 clutter_paint_node_add_child (root, node);
3356 clutter_paint_node_unref (node);
3359 if (priv->content != NULL)
3360 _clutter_content_paint_content (priv->content, actor, root);
3362 if (CLUTTER_ACTOR_GET_CLASS (actor)->paint_node != NULL)
3363 CLUTTER_ACTOR_GET_CLASS (actor)->paint_node (actor, root);
3365 if (clutter_paint_node_get_n_children (root) == 0)
3368 #ifdef CLUTTER_ENABLE_DEBUG
3369 if (CLUTTER_HAS_DEBUG (PAINT))
3371 /* dump the tree only if we have one */
3372 _clutter_paint_node_dump_tree (root);
3374 #endif /* CLUTTER_ENABLE_DEBUG */
3376 _clutter_paint_node_paint (root);
3379 /* XXX: Uncomment this when we disable emitting the paint signal */
3380 CLUTTER_ACTOR_GET_CLASS (actor)->paint (actor);
3387 * clutter_actor_paint:
3388 * @self: A #ClutterActor
3390 * Renders the actor to display.
3392 * This function should not be called directly by applications.
3393 * Call clutter_actor_queue_redraw() to queue paints, instead.
3395 * This function is context-aware, and will either cause a
3396 * regular paint or a pick paint.
3398 * This function will emit the #ClutterActor::paint signal or
3399 * the #ClutterActor::pick signal, depending on the context.
3401 * This function does not paint the actor if the actor is set to 0,
3402 * unless it is performing a pick paint.
3405 clutter_actor_paint (ClutterActor *self)
3407 ClutterActorPrivate *priv;
3408 ClutterPickMode pick_mode;
3409 gboolean clip_set = FALSE;
3410 gboolean shader_applied = FALSE;
3412 CLUTTER_STATIC_COUNTER (actor_paint_counter,
3413 "Actor real-paint counter",
3414 "Increments each time any actor is painted",
3415 0 /* no application private data */);
3416 CLUTTER_STATIC_COUNTER (actor_pick_counter,
3417 "Actor pick-paint counter",
3418 "Increments each time any actor is painted "
3420 0 /* no application private data */);
3422 g_return_if_fail (CLUTTER_IS_ACTOR (self));
3424 if (CLUTTER_ACTOR_IN_DESTRUCTION (self))
3429 pick_mode = _clutter_context_get_pick_mode ();
3431 if (pick_mode == CLUTTER_PICK_NONE)
3432 priv->propagated_one_redraw = FALSE;
3434 /* It's an important optimization that we consider painting of
3435 * actors with 0 opacity to be a NOP... */
3436 if (pick_mode == CLUTTER_PICK_NONE &&
3437 /* ignore top-levels, since they might be transparent */
3438 !CLUTTER_ACTOR_IS_TOPLEVEL (self) &&
3439 /* Use the override opacity if its been set */
3440 ((priv->opacity_override >= 0) ?
3441 priv->opacity_override : priv->opacity) == 0)
3444 /* if we aren't paintable (not in a toplevel with all
3445 * parents paintable) then do nothing.
3447 if (!CLUTTER_ACTOR_IS_MAPPED (self))
3450 /* mark that we are in the paint process */
3451 CLUTTER_SET_PRIVATE_FLAGS (self, CLUTTER_IN_PAINT);
3455 if (priv->enable_model_view_transform)
3459 /* XXX: It could be better to cache the modelview with the actor
3460 * instead of progressively building up the transformations on
3461 * the matrix stack every time we paint. */
3462 cogl_get_modelview_matrix (&matrix);
3463 _clutter_actor_apply_modelview_transform (self, &matrix);
3465 #ifdef CLUTTER_ENABLE_DEBUG
3466 /* Catch when out-of-band transforms have been made by actors not as part
3467 * of an apply_transform vfunc... */
3468 if (G_UNLIKELY (clutter_debug_flags & CLUTTER_DEBUG_OOB_TRANSFORMS))
3470 CoglMatrix expected_matrix;
3472 _clutter_actor_get_relative_transformation_matrix (self, NULL,
3475 if (!cogl_matrix_equal (&matrix, &expected_matrix))
3477 GString *buf = g_string_sized_new (1024);
3478 ClutterActor *parent;
3481 while (parent != NULL)
3483 g_string_append (buf, _clutter_actor_get_debug_name (parent));
3485 if (parent->priv->parent != NULL)
3486 g_string_append (buf, "->");
3488 parent = parent->priv->parent;
3491 g_warning ("Unexpected transform found when painting actor "
3492 "\"%s\". This will be caused by one of the actor's "
3493 "ancestors (%s) using the Cogl API directly to transform "
3494 "children instead of using ::apply_transform().",
3495 _clutter_actor_get_debug_name (self),
3498 g_string_free (buf, TRUE);
3501 #endif /* CLUTTER_ENABLE_DEBUG */
3503 cogl_set_modelview_matrix (&matrix);
3508 cogl_clip_push_rectangle (priv->clip.x,
3510 priv->clip.x + priv->clip.width,
3511 priv->clip.y + priv->clip.height);
3514 else if (priv->clip_to_allocation)
3516 gfloat width, height;
3518 width = priv->allocation.x2 - priv->allocation.x1;
3519 height = priv->allocation.y2 - priv->allocation.y1;
3521 cogl_clip_push_rectangle (0, 0, width, height);
3525 if (pick_mode == CLUTTER_PICK_NONE)
3527 CLUTTER_COUNTER_INC (_clutter_uprof_context, actor_paint_counter);
3529 /* We check whether we need to add the flatten effect before
3530 each paint so that we can avoid having a mechanism for
3531 applications to notify when the value of the
3532 has_overlaps virtual changes. */
3533 add_or_remove_flatten_effect (self);
3536 CLUTTER_COUNTER_INC (_clutter_uprof_context, actor_pick_counter);
3538 /* We save the current paint volume so that the next time the
3539 * actor queues a redraw we can constrain the redraw to just
3540 * cover the union of the new bounding box and the old.
3542 * We also fetch the current paint volume to perform culling so
3543 * we can avoid painting actors outside the current clip region.
3545 * If we are painting inside a clone, we should neither update
3546 * the paint volume or use it to cull painting, since the paint
3547 * box represents the location of the source actor on the
3550 * XXX: We are starting to do a lot of vertex transforms on
3551 * the CPU in a typical paint, so at some point we should
3552 * audit these and consider caching some things.
3554 * NB: We don't perform culling while picking at this point because
3555 * clutter-stage.c doesn't setup the clipping planes appropriately.
3557 * NB: We don't want to update the last-paint-volume during picking
3558 * because the last-paint-volume is used to determine the old screen
3559 * space location of an actor that has moved so we can know the
3560 * minimal region to redraw to clear an old view of the actor. If we
3561 * update this during picking then by the time we come around to
3562 * paint then the last-paint-volume would likely represent the new
3563 * actor position not the old.
3565 if (!in_clone_paint () && pick_mode == CLUTTER_PICK_NONE)
3568 /* annoyingly gcc warns if uninitialized even though
3569 * the initialization is redundant :-( */
3570 ClutterCullResult result = CLUTTER_CULL_RESULT_IN;
3572 if (G_LIKELY ((clutter_paint_debug_flags &
3573 (CLUTTER_DEBUG_DISABLE_CULLING |
3574 CLUTTER_DEBUG_DISABLE_CLIPPED_REDRAWS)) !=
3575 (CLUTTER_DEBUG_DISABLE_CULLING |
3576 CLUTTER_DEBUG_DISABLE_CLIPPED_REDRAWS)))
3577 _clutter_actor_update_last_paint_volume (self);
3579 success = cull_actor (self, &result);
3581 if (G_UNLIKELY (clutter_paint_debug_flags & CLUTTER_DEBUG_REDRAWS))
3582 _clutter_actor_paint_cull_result (self, success, result);
3583 else if (result == CLUTTER_CULL_RESULT_OUT && success)
3587 if (priv->effects == NULL)
3589 if (pick_mode == CLUTTER_PICK_NONE &&
3590 actor_has_shader_data (self))
3592 _clutter_actor_shader_pre_paint (self, FALSE);
3593 shader_applied = TRUE;
3596 priv->next_effect_to_paint = NULL;
3599 priv->next_effect_to_paint =
3600 _clutter_meta_group_peek_metas (priv->effects);
3602 clutter_actor_continue_paint (self);
3605 _clutter_actor_shader_post_paint (self);
3607 if (G_UNLIKELY (clutter_paint_debug_flags & CLUTTER_DEBUG_PAINT_VOLUMES &&
3608 pick_mode == CLUTTER_PICK_NONE))
3609 _clutter_actor_draw_paint_volume (self);
3612 /* If we make it here then the actor has run through a complete
3613 paint run including all the effects so it's no longer dirty */
3614 if (pick_mode == CLUTTER_PICK_NONE)
3615 priv->is_dirty = FALSE;
3622 /* paint sequence complete */
3623 CLUTTER_UNSET_PRIVATE_FLAGS (self, CLUTTER_IN_PAINT);
3627 * clutter_actor_continue_paint:
3628 * @self: A #ClutterActor
3630 * Run the next stage of the paint sequence. This function should only
3631 * be called within the implementation of the ‘run’ virtual of a
3632 * #ClutterEffect. It will cause the run method of the next effect to
3633 * be applied, or it will paint the actual actor if the current effect
3634 * is the last effect in the chain.
3639 clutter_actor_continue_paint (ClutterActor *self)
3641 ClutterActorPrivate *priv;
3643 g_return_if_fail (CLUTTER_IS_ACTOR (self));
3644 /* This should only be called from with in the ‘run’ implementation
3645 of a ClutterEffect */
3646 g_return_if_fail (CLUTTER_ACTOR_IN_PAINT (self));
3650 /* Skip any effects that are disabled */
3651 while (priv->next_effect_to_paint &&
3652 !clutter_actor_meta_get_enabled (priv->next_effect_to_paint->data))
3653 priv->next_effect_to_paint = priv->next_effect_to_paint->next;
3655 /* If this has come from the last effect then we'll just paint the
3657 if (priv->next_effect_to_paint == NULL)
3659 if (_clutter_context_get_pick_mode () == CLUTTER_PICK_NONE)
3661 ClutterPaintNode *dummy;
3663 /* XXX - this will go away in 2.0, when we can get rid of this
3664 * stuff and switch to a pure retained render tree of PaintNodes
3665 * for the entire frame, starting from the Stage; the paint()
3666 * virtual function can then be called directly.
3668 dummy = _clutter_dummy_node_new (self);
3669 clutter_paint_node_set_name (dummy, "Root");
3671 /* XXX - for 1.12, we use the return value of paint_node() to
3672 * decide whether we should emit the ::paint signal.
3674 clutter_actor_paint_node (self, dummy);
3675 clutter_paint_node_unref (dummy);
3677 g_signal_emit (self, actor_signals[PAINT], 0);
3681 ClutterColor col = { 0, };
3683 _clutter_id_to_color (_clutter_actor_get_pick_id (self), &col);
3685 /* Actor will then paint silhouette of itself in supplied
3686 * color. See clutter_stage_get_actor_at_pos() for where
3687 * picking is enabled.
3689 g_signal_emit (self, actor_signals[PICK], 0, &col);
3694 ClutterEffect *old_current_effect;
3695 ClutterEffectPaintFlags run_flags = 0;
3697 /* Cache the current effect so that we can put it back before
3699 old_current_effect = priv->current_effect;
3701 priv->current_effect = priv->next_effect_to_paint->data;
3702 priv->next_effect_to_paint = priv->next_effect_to_paint->next;
3704 if (_clutter_context_get_pick_mode () == CLUTTER_PICK_NONE)
3708 /* If there's an effect queued with this redraw then all
3709 effects up to that one will be considered dirty. It
3710 is expected the queued effect will paint the cached
3711 image and not call clutter_actor_continue_paint again
3712 (although it should work ok if it does) */
3713 if (priv->effect_to_redraw == NULL ||
3714 priv->current_effect != priv->effect_to_redraw)
3715 run_flags |= CLUTTER_EFFECT_PAINT_ACTOR_DIRTY;
3718 _clutter_effect_paint (priv->current_effect, run_flags);
3722 /* We can't determine when an actor has been modified since
3723 its last pick so lets just assume it has always been
3725 run_flags |= CLUTTER_EFFECT_PAINT_ACTOR_DIRTY;
3727 _clutter_effect_pick (priv->current_effect, run_flags);
3730 priv->current_effect = old_current_effect;
3734 static ClutterActorTraverseVisitFlags
3735 invalidate_queue_redraw_entry (ClutterActor *self,
3739 ClutterActorPrivate *priv = self->priv;
3741 if (priv->queue_redraw_entry != NULL)
3743 _clutter_stage_queue_redraw_entry_invalidate (priv->queue_redraw_entry);
3744 priv->queue_redraw_entry = NULL;
3747 return CLUTTER_ACTOR_TRAVERSE_VISIT_CONTINUE;
3751 remove_child (ClutterActor *self,
3752 ClutterActor *child)
3754 ClutterActor *prev_sibling, *next_sibling;
3756 prev_sibling = child->priv->prev_sibling;
3757 next_sibling = child->priv->next_sibling;
3759 if (prev_sibling != NULL)
3760 prev_sibling->priv->next_sibling = next_sibling;
3762 if (next_sibling != NULL)
3763 next_sibling->priv->prev_sibling = prev_sibling;
3765 if (self->priv->first_child == child)
3766 self->priv->first_child = next_sibling;
3768 if (self->priv->last_child == child)
3769 self->priv->last_child = prev_sibling;
3771 child->priv->parent = NULL;
3772 child->priv->prev_sibling = NULL;
3773 child->priv->next_sibling = NULL;
3777 REMOVE_CHILD_DESTROY_META = 1 << 0,
3778 REMOVE_CHILD_EMIT_PARENT_SET = 1 << 1,
3779 REMOVE_CHILD_EMIT_ACTOR_REMOVED = 1 << 2,
3780 REMOVE_CHILD_CHECK_STATE = 1 << 3,
3781 REMOVE_CHILD_FLUSH_QUEUE = 1 << 4,
3782 REMOVE_CHILD_NOTIFY_FIRST_LAST = 1 << 5,
3784 /* default flags for public API */
3785 REMOVE_CHILD_DEFAULT_FLAGS = REMOVE_CHILD_DESTROY_META |
3786 REMOVE_CHILD_EMIT_PARENT_SET |
3787 REMOVE_CHILD_EMIT_ACTOR_REMOVED |
3788 REMOVE_CHILD_CHECK_STATE |
3789 REMOVE_CHILD_FLUSH_QUEUE |
3790 REMOVE_CHILD_NOTIFY_FIRST_LAST,
3792 /* flags for legacy/deprecated API */
3793 REMOVE_CHILD_LEGACY_FLAGS = REMOVE_CHILD_CHECK_STATE |
3794 REMOVE_CHILD_FLUSH_QUEUE |
3795 REMOVE_CHILD_EMIT_PARENT_SET |
3796 REMOVE_CHILD_NOTIFY_FIRST_LAST
3797 } ClutterActorRemoveChildFlags;
3800 * clutter_actor_remove_child_internal:
3801 * @self: a #ClutterActor
3802 * @child: the child of @self that has to be removed
3803 * @flags: control the removal operations
3805 * Removes @child from the list of children of @self.
3808 clutter_actor_remove_child_internal (ClutterActor *self,
3809 ClutterActor *child,
3810 ClutterActorRemoveChildFlags flags)
3812 ClutterActor *old_first, *old_last;
3813 gboolean destroy_meta, emit_parent_set, emit_actor_removed, check_state;
3814 gboolean flush_queue;
3815 gboolean notify_first_last;
3816 gboolean was_mapped;
3818 destroy_meta = (flags & REMOVE_CHILD_DESTROY_META) != 0;
3819 emit_parent_set = (flags & REMOVE_CHILD_EMIT_PARENT_SET) != 0;
3820 emit_actor_removed = (flags & REMOVE_CHILD_EMIT_ACTOR_REMOVED) != 0;
3821 check_state = (flags & REMOVE_CHILD_CHECK_STATE) != 0;
3822 flush_queue = (flags & REMOVE_CHILD_FLUSH_QUEUE) != 0;
3823 notify_first_last = (flags & REMOVE_CHILD_NOTIFY_FIRST_LAST) != 0;
3825 g_object_freeze_notify (G_OBJECT (self));
3828 clutter_container_destroy_child_meta (CLUTTER_CONTAINER (self), child);
3832 was_mapped = CLUTTER_ACTOR_IS_MAPPED (child);
3834 /* we need to unrealize *before* we set parent_actor to NULL,
3835 * because in an unrealize method actors are dissociating from the
3836 * stage, which means they need to be able to
3837 * clutter_actor_get_stage().
3839 * yhis should unmap and unrealize, unless we're reparenting.
3841 clutter_actor_update_map_state (child, MAP_STATE_MAKE_UNREALIZED);
3848 /* We take this opportunity to invalidate any queue redraw entry
3849 * associated with the actor and descendants since we won't be able to
3850 * determine the appropriate stage after this.
3852 * we do this after we updated the mapped state because actors might
3853 * end up queueing redraws inside their mapped/unmapped virtual
3854 * functions, and if we invalidate the redraw entry we could end up
3855 * with an inconsistent state and weird memory corruption. see
3858 * http://bugzilla.clutter-project.org/show_bug.cgi?id=2621
3859 * https://bugzilla.gnome.org/show_bug.cgi?id=652036
3861 _clutter_actor_traverse (child,
3863 invalidate_queue_redraw_entry,
3868 old_first = self->priv->first_child;
3869 old_last = self->priv->last_child;
3871 remove_child (self, child);
3873 self->priv->n_children -= 1;
3875 self->priv->age += 1;
3877 /* clutter_actor_reparent() will emit ::parent-set for us */
3878 if (emit_parent_set && !CLUTTER_ACTOR_IN_REPARENT (child))
3879 g_signal_emit (child, actor_signals[PARENT_SET], 0, self);
3881 /* if the child was mapped then we need to relayout ourselves to account
3882 * for the removed child
3885 clutter_actor_queue_relayout (self);
3887 /* we need to emit the signal before dropping the reference */
3888 if (emit_actor_removed)
3889 g_signal_emit_by_name (self, "actor-removed", child);
3891 if (notify_first_last)
3893 if (old_first != self->priv->first_child)
3894 g_object_notify_by_pspec (G_OBJECT (self), obj_props[PROP_FIRST_CHILD]);
3896 if (old_last != self->priv->last_child)
3897 g_object_notify_by_pspec (G_OBJECT (self), obj_props[PROP_LAST_CHILD]);
3900 g_object_thaw_notify (G_OBJECT (self));
3902 /* remove the reference we acquired in clutter_actor_add_child() */
3903 g_object_unref (child);
3906 static const ClutterTransformInfo default_transform_info = {
3907 0.0, { 0, }, /* rotation-x */
3908 0.0, { 0, }, /* rotation-y */
3909 0.0, { 0, }, /* rotation-z */
3911 1.0, 1.0, { 0, }, /* scale */
3913 { 0, }, /* anchor */
3919 * _clutter_actor_get_transform_info_or_defaults:
3920 * @self: a #ClutterActor
3922 * Retrieves the ClutterTransformInfo structure associated to an actor.
3924 * If the actor does not have a ClutterTransformInfo structure associated
3925 * to it, then the default structure will be returned.
3927 * This function should only be used for getters.
3929 * Return value: a const pointer to the ClutterTransformInfo structure
3931 const ClutterTransformInfo *
3932 _clutter_actor_get_transform_info_or_defaults (ClutterActor *self)
3934 ClutterTransformInfo *info;
3936 info = g_object_get_qdata (G_OBJECT (self), quark_actor_transform_info);
3940 return &default_transform_info;
3944 clutter_transform_info_free (gpointer data)
3947 g_slice_free (ClutterTransformInfo, data);
3951 * _clutter_actor_get_transform_info:
3952 * @self: a #ClutterActor
3954 * Retrieves a pointer to the ClutterTransformInfo structure.
3956 * If the actor does not have a ClutterTransformInfo associated to it, one
3957 * will be created and initialized to the default values.
3959 * This function should be used for setters.
3961 * For getters, you should use _clutter_actor_get_transform_info_or_defaults()
3964 * Return value: (transfer none): a pointer to the ClutterTransformInfo
3967 ClutterTransformInfo *
3968 _clutter_actor_get_transform_info (ClutterActor *self)
3970 ClutterTransformInfo *info;
3972 info = g_object_get_qdata (G_OBJECT (self), quark_actor_transform_info);
3975 info = g_slice_new (ClutterTransformInfo);
3977 *info = default_transform_info;
3979 g_object_set_qdata_full (G_OBJECT (self), quark_actor_transform_info,
3981 clutter_transform_info_free);
3988 * clutter_actor_set_rotation_angle_internal:
3989 * @self: a #ClutterActor
3990 * @axis: the axis of the angle to change
3991 * @angle: the angle of rotation
3993 * Sets the rotation angle on the given axis without affecting the
3994 * rotation center point.
3997 clutter_actor_set_rotation_angle_internal (ClutterActor *self,
3998 ClutterRotateAxis axis,
4001 GObject *obj = G_OBJECT (self);
4002 ClutterTransformInfo *info;
4004 info = _clutter_actor_get_transform_info (self);
4006 g_object_freeze_notify (obj);
4010 case CLUTTER_X_AXIS:
4011 info->rx_angle = angle;
4012 g_object_notify_by_pspec (obj, obj_props[PROP_ROTATION_ANGLE_X]);
4015 case CLUTTER_Y_AXIS:
4016 info->ry_angle = angle;
4017 g_object_notify_by_pspec (obj, obj_props[PROP_ROTATION_ANGLE_Y]);
4020 case CLUTTER_Z_AXIS:
4021 info->rz_angle = angle;
4022 g_object_notify_by_pspec (obj, obj_props[PROP_ROTATION_ANGLE_Z]);
4026 self->priv->transform_valid = FALSE;
4028 g_object_thaw_notify (obj);
4030 clutter_actor_queue_redraw (self);
4034 clutter_actor_set_rotation_angle (ClutterActor *self,
4035 ClutterRotateAxis axis,
4038 const ClutterTransformInfo *info;
4039 const double *cur_angle_p = NULL;
4040 GParamSpec *pspec = NULL;
4042 info = _clutter_actor_get_transform_info_or_defaults (self);
4046 case CLUTTER_X_AXIS:
4047 cur_angle_p = &info->rx_angle;
4048 pspec = obj_props[PROP_ROTATION_ANGLE_X];
4051 case CLUTTER_Y_AXIS:
4052 cur_angle_p = &info->ry_angle;
4053 pspec = obj_props[PROP_ROTATION_ANGLE_Y];
4056 case CLUTTER_Z_AXIS:
4057 cur_angle_p = &info->rz_angle;
4058 pspec = obj_props[PROP_ROTATION_ANGLE_Z];
4062 g_assert (pspec != NULL);
4063 g_assert (cur_angle_p != NULL);
4065 if (_clutter_actor_get_transition (self, pspec) == NULL)
4066 _clutter_actor_create_transition (self, pspec, *cur_angle_p, angle);
4068 _clutter_actor_update_transition (self, pspec, angle);
4070 clutter_actor_queue_redraw (self);
4074 * clutter_actor_set_rotation_center_internal:
4075 * @self: a #ClutterActor
4076 * @axis: the axis of the center to change
4077 * @center: the coordinates of the rotation center
4079 * Sets the rotation center on the given axis without affecting the
4083 clutter_actor_set_rotation_center_internal (ClutterActor *self,
4084 ClutterRotateAxis axis,
4085 const ClutterVertex *center)
4087 GObject *obj = G_OBJECT (self);
4088 ClutterTransformInfo *info;
4089 ClutterVertex v = { 0, 0, 0 };
4091 info = _clutter_actor_get_transform_info (self);
4096 g_object_freeze_notify (obj);
4100 case CLUTTER_X_AXIS:
4101 clutter_anchor_coord_set_units (&info->rx_center, v.x, v.y, v.z);
4102 g_object_notify_by_pspec (obj, obj_props[PROP_ROTATION_CENTER_X]);
4105 case CLUTTER_Y_AXIS:
4106 clutter_anchor_coord_set_units (&info->ry_center, v.x, v.y, v.z);
4107 g_object_notify_by_pspec (obj, obj_props[PROP_ROTATION_CENTER_Y]);
4110 case CLUTTER_Z_AXIS:
4111 /* if the previously set rotation center was fractional, then
4112 * setting explicit coordinates will have to notify the
4113 * :rotation-center-z-gravity property as well
4115 if (info->rz_center.is_fractional)
4116 g_object_notify_by_pspec (obj, obj_props[PROP_ROTATION_CENTER_Z_GRAVITY]);
4118 clutter_anchor_coord_set_units (&info->rz_center, v.x, v.y, v.z);
4119 g_object_notify_by_pspec (obj, obj_props[PROP_ROTATION_CENTER_Z]);
4123 self->priv->transform_valid = FALSE;
4125 g_object_thaw_notify (obj);
4127 clutter_actor_queue_redraw (self);
4131 clutter_actor_set_scale_factor_internal (ClutterActor *self,
4135 GObject *obj = G_OBJECT (self);
4136 ClutterTransformInfo *info;
4138 info = _clutter_actor_get_transform_info (self);
4140 if (pspec == obj_props[PROP_SCALE_X])
4141 info->scale_x = factor;
4143 info->scale_y = factor;
4145 self->priv->transform_valid = FALSE;
4146 clutter_actor_queue_redraw (self);
4147 g_object_notify_by_pspec (obj, pspec);
4151 clutter_actor_set_scale_factor (ClutterActor *self,
4152 ClutterRotateAxis axis,
4155 const ClutterTransformInfo *info;
4156 const double *scale_p = NULL;
4157 GParamSpec *pspec = NULL;
4159 info = _clutter_actor_get_transform_info_or_defaults (self);
4163 case CLUTTER_X_AXIS:
4164 pspec = obj_props[PROP_SCALE_X];
4165 scale_p = &info->scale_x;
4168 case CLUTTER_Y_AXIS:
4169 pspec = obj_props[PROP_SCALE_Y];
4170 scale_p = &info->scale_y;
4173 case CLUTTER_Z_AXIS:
4177 g_assert (pspec != NULL);
4178 g_assert (scale_p != NULL);
4180 if (_clutter_actor_get_transition (self, pspec) == NULL)
4181 _clutter_actor_create_transition (self, pspec, *scale_p, factor);
4183 _clutter_actor_update_transition (self, pspec, factor);
4185 clutter_actor_queue_redraw (self);
4189 clutter_actor_set_scale_center (ClutterActor *self,
4190 ClutterRotateAxis axis,
4193 GObject *obj = G_OBJECT (self);
4194 ClutterTransformInfo *info;
4195 gfloat center_x, center_y;
4197 info = _clutter_actor_get_transform_info (self);
4199 g_object_freeze_notify (obj);
4201 /* get the current scale center coordinates */
4202 clutter_anchor_coord_get_units (self, &info->scale_center,
4207 /* we need to notify this too, because setting explicit coordinates will
4208 * change the gravity as a side effect
4210 if (info->scale_center.is_fractional)
4211 g_object_notify_by_pspec (obj, obj_props[PROP_SCALE_GRAVITY]);
4215 case CLUTTER_X_AXIS:
4216 clutter_anchor_coord_set_units (&info->scale_center, coord, center_y, 0);
4217 g_object_notify_by_pspec (obj, obj_props[PROP_SCALE_CENTER_X]);
4220 case CLUTTER_Y_AXIS:
4221 clutter_anchor_coord_set_units (&info->scale_center, center_x, coord, 0);
4222 g_object_notify_by_pspec (obj, obj_props[PROP_SCALE_CENTER_Y]);
4226 g_assert_not_reached ();
4229 self->priv->transform_valid = FALSE;
4231 clutter_actor_queue_redraw (self);
4233 g_object_thaw_notify (obj);
4237 clutter_actor_set_scale_gravity (ClutterActor *self,
4238 ClutterGravity gravity)
4240 ClutterTransformInfo *info;
4243 info = _clutter_actor_get_transform_info (self);
4244 obj = G_OBJECT (self);
4246 if (gravity == CLUTTER_GRAVITY_NONE)
4247 clutter_anchor_coord_set_units (&info->scale_center, 0, 0, 0);
4249 clutter_anchor_coord_set_gravity (&info->scale_center, gravity);
4251 self->priv->transform_valid = FALSE;
4253 g_object_notify_by_pspec (obj, obj_props[PROP_SCALE_CENTER_X]);
4254 g_object_notify_by_pspec (obj, obj_props[PROP_SCALE_CENTER_Y]);
4255 g_object_notify_by_pspec (obj, obj_props[PROP_SCALE_GRAVITY]);
4257 clutter_actor_queue_redraw (self);
4261 clutter_actor_set_anchor_coord (ClutterActor *self,
4262 ClutterRotateAxis axis,
4265 GObject *obj = G_OBJECT (self);
4266 ClutterTransformInfo *info;
4267 gfloat anchor_x, anchor_y;
4269 info = _clutter_actor_get_transform_info (self);
4271 g_object_freeze_notify (obj);
4273 clutter_anchor_coord_get_units (self, &info->anchor,
4278 if (info->anchor.is_fractional)
4279 g_object_notify_by_pspec (obj, obj_props[PROP_ANCHOR_GRAVITY]);
4283 case CLUTTER_X_AXIS:
4284 clutter_anchor_coord_set_units (&info->anchor,
4288 g_object_notify_by_pspec (obj, obj_props[PROP_ANCHOR_X]);
4291 case CLUTTER_Y_AXIS:
4292 clutter_anchor_coord_set_units (&info->anchor,
4296 g_object_notify_by_pspec (obj, obj_props[PROP_ANCHOR_Y]);
4300 g_assert_not_reached ();
4303 self->priv->transform_valid = FALSE;
4305 clutter_actor_queue_redraw (self);
4307 g_object_thaw_notify (obj);
4311 clutter_actor_set_property (GObject *object,
4313 const GValue *value,
4316 ClutterActor *actor = CLUTTER_ACTOR (object);
4317 ClutterActorPrivate *priv = actor->priv;
4322 clutter_actor_set_x (actor, g_value_get_float (value));
4326 clutter_actor_set_y (actor, g_value_get_float (value));
4330 clutter_actor_set_width (actor, g_value_get_float (value));
4334 clutter_actor_set_height (actor, g_value_get_float (value));
4338 clutter_actor_set_x (actor, g_value_get_float (value));
4342 clutter_actor_set_y (actor, g_value_get_float (value));
4345 case PROP_FIXED_POSITION_SET:
4346 clutter_actor_set_fixed_position_set (actor, g_value_get_boolean (value));
4349 case PROP_MIN_WIDTH:
4350 clutter_actor_set_min_width (actor, g_value_get_float (value));
4353 case PROP_MIN_HEIGHT:
4354 clutter_actor_set_min_height (actor, g_value_get_float (value));
4357 case PROP_NATURAL_WIDTH:
4358 clutter_actor_set_natural_width (actor, g_value_get_float (value));
4361 case PROP_NATURAL_HEIGHT:
4362 clutter_actor_set_natural_height (actor, g_value_get_float (value));
4365 case PROP_MIN_WIDTH_SET:
4366 clutter_actor_set_min_width_set (actor, g_value_get_boolean (value));
4369 case PROP_MIN_HEIGHT_SET:
4370 clutter_actor_set_min_height_set (actor, g_value_get_boolean (value));
4373 case PROP_NATURAL_WIDTH_SET:
4374 clutter_actor_set_natural_width_set (actor, g_value_get_boolean (value));
4377 case PROP_NATURAL_HEIGHT_SET:
4378 clutter_actor_set_natural_height_set (actor, g_value_get_boolean (value));
4381 case PROP_REQUEST_MODE:
4382 clutter_actor_set_request_mode (actor, g_value_get_enum (value));
4386 clutter_actor_set_depth (actor, g_value_get_float (value));
4390 clutter_actor_set_opacity (actor, g_value_get_uint (value));
4393 case PROP_OFFSCREEN_REDIRECT:
4394 clutter_actor_set_offscreen_redirect (actor, g_value_get_enum (value));
4398 clutter_actor_set_name (actor, g_value_get_string (value));
4402 if (g_value_get_boolean (value) == TRUE)
4403 clutter_actor_show (actor);
4405 clutter_actor_hide (actor);
4409 clutter_actor_set_scale_factor (actor, CLUTTER_X_AXIS,
4410 g_value_get_double (value));
4414 clutter_actor_set_scale_factor (actor, CLUTTER_Y_AXIS,
4415 g_value_get_double (value));
4418 case PROP_SCALE_CENTER_X:
4419 clutter_actor_set_scale_center (actor, CLUTTER_X_AXIS,
4420 g_value_get_float (value));
4423 case PROP_SCALE_CENTER_Y:
4424 clutter_actor_set_scale_center (actor, CLUTTER_Y_AXIS,
4425 g_value_get_float (value));
4428 case PROP_SCALE_GRAVITY:
4429 clutter_actor_set_scale_gravity (actor, g_value_get_enum (value));
4434 const ClutterGeometry *geom = g_value_get_boxed (value);
4436 clutter_actor_set_clip (actor,
4438 geom->width, geom->height);
4442 case PROP_CLIP_TO_ALLOCATION:
4443 clutter_actor_set_clip_to_allocation (actor, g_value_get_boolean (value));
4447 clutter_actor_set_reactive (actor, g_value_get_boolean (value));
4450 case PROP_ROTATION_ANGLE_X:
4451 clutter_actor_set_rotation_angle (actor,
4453 g_value_get_double (value));
4456 case PROP_ROTATION_ANGLE_Y:
4457 clutter_actor_set_rotation_angle (actor,
4459 g_value_get_double (value));
4462 case PROP_ROTATION_ANGLE_Z:
4463 clutter_actor_set_rotation_angle (actor,
4465 g_value_get_double (value));
4468 case PROP_ROTATION_CENTER_X:
4469 clutter_actor_set_rotation_center_internal (actor,
4471 g_value_get_boxed (value));
4474 case PROP_ROTATION_CENTER_Y:
4475 clutter_actor_set_rotation_center_internal (actor,
4477 g_value_get_boxed (value));
4480 case PROP_ROTATION_CENTER_Z:
4481 clutter_actor_set_rotation_center_internal (actor,
4483 g_value_get_boxed (value));
4486 case PROP_ROTATION_CENTER_Z_GRAVITY:
4488 const ClutterTransformInfo *info;
4490 info = _clutter_actor_get_transform_info_or_defaults (actor);
4491 clutter_actor_set_z_rotation_from_gravity (actor, info->rz_angle,
4492 g_value_get_enum (value));
4497 clutter_actor_set_anchor_coord (actor, CLUTTER_X_AXIS,
4498 g_value_get_float (value));
4502 clutter_actor_set_anchor_coord (actor, CLUTTER_Y_AXIS,
4503 g_value_get_float (value));
4506 case PROP_ANCHOR_GRAVITY:
4507 clutter_actor_set_anchor_point_from_gravity (actor,
4508 g_value_get_enum (value));
4511 case PROP_SHOW_ON_SET_PARENT:
4512 priv->show_on_set_parent = g_value_get_boolean (value);
4515 case PROP_TEXT_DIRECTION:
4516 clutter_actor_set_text_direction (actor, g_value_get_enum (value));
4520 clutter_actor_add_action (actor, g_value_get_object (value));
4523 case PROP_CONSTRAINTS:
4524 clutter_actor_add_constraint (actor, g_value_get_object (value));
4528 clutter_actor_add_effect (actor, g_value_get_object (value));
4531 case PROP_LAYOUT_MANAGER:
4532 clutter_actor_set_layout_manager (actor, g_value_get_object (value));
4536 clutter_actor_set_x_align (actor, g_value_get_enum (value));
4540 clutter_actor_set_y_align (actor, g_value_get_enum (value));
4543 case PROP_MARGIN_TOP:
4544 clutter_actor_set_margin_top (actor, g_value_get_float (value));
4547 case PROP_MARGIN_BOTTOM:
4548 clutter_actor_set_margin_bottom (actor, g_value_get_float (value));
4551 case PROP_MARGIN_LEFT:
4552 clutter_actor_set_margin_left (actor, g_value_get_float (value));
4555 case PROP_MARGIN_RIGHT:
4556 clutter_actor_set_margin_right (actor, g_value_get_float (value));
4559 case PROP_BACKGROUND_COLOR:
4560 clutter_actor_set_background_color (actor, g_value_get_boxed (value));
4564 clutter_actor_set_content (actor, g_value_get_object (value));
4567 case PROP_CONTENT_GRAVITY:
4568 clutter_actor_set_content_gravity (actor, g_value_get_enum (value));
4571 case PROP_MINIFICATION_FILTER:
4572 clutter_actor_set_content_scaling_filters (actor,
4573 g_value_get_enum (value),
4574 actor->priv->mag_filter);
4577 case PROP_MAGNIFICATION_FILTER:
4578 clutter_actor_set_content_scaling_filters (actor,
4579 actor->priv->min_filter,
4580 g_value_get_enum (value));
4584 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
4590 clutter_actor_get_property (GObject *object,
4595 ClutterActor *actor = CLUTTER_ACTOR (object);
4596 ClutterActorPrivate *priv = actor->priv;
4601 g_value_set_float (value, clutter_actor_get_x (actor));
4605 g_value_set_float (value, clutter_actor_get_y (actor));
4609 g_value_set_float (value, clutter_actor_get_width (actor));
4613 g_value_set_float (value, clutter_actor_get_height (actor));
4618 const ClutterLayoutInfo *info;
4620 info = _clutter_actor_get_layout_info_or_defaults (actor);
4621 g_value_set_float (value, info->fixed_x);
4627 const ClutterLayoutInfo *info;
4629 info = _clutter_actor_get_layout_info_or_defaults (actor);
4630 g_value_set_float (value, info->fixed_y);
4634 case PROP_FIXED_POSITION_SET:
4635 g_value_set_boolean (value, priv->position_set);
4638 case PROP_MIN_WIDTH:
4640 const ClutterLayoutInfo *info;
4642 info = _clutter_actor_get_layout_info_or_defaults (actor);
4643 g_value_set_float (value, info->min_width);
4647 case PROP_MIN_HEIGHT:
4649 const ClutterLayoutInfo *info;
4651 info = _clutter_actor_get_layout_info_or_defaults (actor);
4652 g_value_set_float (value, info->min_height);
4656 case PROP_NATURAL_WIDTH:
4658 const ClutterLayoutInfo *info;
4660 info = _clutter_actor_get_layout_info_or_defaults (actor);
4661 g_value_set_float (value, info->natural_width);
4665 case PROP_NATURAL_HEIGHT:
4667 const ClutterLayoutInfo *info;
4669 info = _clutter_actor_get_layout_info_or_defaults (actor);
4670 g_value_set_float (value, info->natural_height);
4674 case PROP_MIN_WIDTH_SET:
4675 g_value_set_boolean (value, priv->min_width_set);
4678 case PROP_MIN_HEIGHT_SET:
4679 g_value_set_boolean (value, priv->min_height_set);
4682 case PROP_NATURAL_WIDTH_SET:
4683 g_value_set_boolean (value, priv->natural_width_set);
4686 case PROP_NATURAL_HEIGHT_SET:
4687 g_value_set_boolean (value, priv->natural_height_set);
4690 case PROP_REQUEST_MODE:
4691 g_value_set_enum (value, priv->request_mode);
4694 case PROP_ALLOCATION:
4695 g_value_set_boxed (value, &priv->allocation);
4699 g_value_set_float (value, clutter_actor_get_depth (actor));
4703 g_value_set_uint (value, priv->opacity);
4706 case PROP_OFFSCREEN_REDIRECT:
4707 g_value_set_enum (value, priv->offscreen_redirect);
4711 g_value_set_string (value, priv->name);
4715 g_value_set_boolean (value, CLUTTER_ACTOR_IS_VISIBLE (actor));
4719 g_value_set_boolean (value, CLUTTER_ACTOR_IS_MAPPED (actor));
4723 g_value_set_boolean (value, CLUTTER_ACTOR_IS_REALIZED (actor));
4727 g_value_set_boolean (value, priv->has_clip);
4732 ClutterGeometry clip;
4734 clip.x = CLUTTER_NEARBYINT (priv->clip.x);
4735 clip.y = CLUTTER_NEARBYINT (priv->clip.y);
4736 clip.width = CLUTTER_NEARBYINT (priv->clip.width);
4737 clip.height = CLUTTER_NEARBYINT (priv->clip.height);
4739 g_value_set_boxed (value, &clip);
4743 case PROP_CLIP_TO_ALLOCATION:
4744 g_value_set_boolean (value, priv->clip_to_allocation);
4749 const ClutterTransformInfo *info;
4751 info = _clutter_actor_get_transform_info_or_defaults (actor);
4752 g_value_set_double (value, info->scale_x);
4758 const ClutterTransformInfo *info;
4760 info = _clutter_actor_get_transform_info_or_defaults (actor);
4761 g_value_set_double (value, info->scale_y);
4765 case PROP_SCALE_CENTER_X:
4769 clutter_actor_get_scale_center (actor, ¢er, NULL);
4771 g_value_set_float (value, center);
4775 case PROP_SCALE_CENTER_Y:
4779 clutter_actor_get_scale_center (actor, NULL, ¢er);
4781 g_value_set_float (value, center);
4785 case PROP_SCALE_GRAVITY:
4786 g_value_set_enum (value, clutter_actor_get_scale_gravity (actor));
4790 g_value_set_boolean (value, clutter_actor_get_reactive (actor));
4793 case PROP_ROTATION_ANGLE_X:
4795 const ClutterTransformInfo *info;
4797 info = _clutter_actor_get_transform_info_or_defaults (actor);
4798 g_value_set_double (value, info->rx_angle);
4802 case PROP_ROTATION_ANGLE_Y:
4804 const ClutterTransformInfo *info;
4806 info = _clutter_actor_get_transform_info_or_defaults (actor);
4807 g_value_set_double (value, info->ry_angle);
4811 case PROP_ROTATION_ANGLE_Z:
4813 const ClutterTransformInfo *info;
4815 info = _clutter_actor_get_transform_info_or_defaults (actor);
4816 g_value_set_double (value, info->rz_angle);
4820 case PROP_ROTATION_CENTER_X:
4822 ClutterVertex center;
4824 clutter_actor_get_rotation (actor, CLUTTER_X_AXIS,
4829 g_value_set_boxed (value, ¢er);
4833 case PROP_ROTATION_CENTER_Y:
4835 ClutterVertex center;
4837 clutter_actor_get_rotation (actor, CLUTTER_Y_AXIS,
4842 g_value_set_boxed (value, ¢er);
4846 case PROP_ROTATION_CENTER_Z:
4848 ClutterVertex center;
4850 clutter_actor_get_rotation (actor, CLUTTER_Z_AXIS,
4855 g_value_set_boxed (value, ¢er);
4859 case PROP_ROTATION_CENTER_Z_GRAVITY:
4860 g_value_set_enum (value, clutter_actor_get_z_rotation_gravity (actor));
4865 const ClutterTransformInfo *info;
4868 info = _clutter_actor_get_transform_info_or_defaults (actor);
4869 clutter_anchor_coord_get_units (actor, &info->anchor,
4873 g_value_set_float (value, anchor_x);
4879 const ClutterTransformInfo *info;
4882 info = _clutter_actor_get_transform_info_or_defaults (actor);
4883 clutter_anchor_coord_get_units (actor, &info->anchor,
4887 g_value_set_float (value, anchor_y);
4891 case PROP_ANCHOR_GRAVITY:
4892 g_value_set_enum (value, clutter_actor_get_anchor_point_gravity (actor));
4895 case PROP_SHOW_ON_SET_PARENT:
4896 g_value_set_boolean (value, priv->show_on_set_parent);
4899 case PROP_TEXT_DIRECTION:
4900 g_value_set_enum (value, priv->text_direction);
4903 case PROP_HAS_POINTER:
4904 g_value_set_boolean (value, priv->has_pointer);
4907 case PROP_LAYOUT_MANAGER:
4908 g_value_set_object (value, priv->layout_manager);
4913 const ClutterLayoutInfo *info;
4915 info = _clutter_actor_get_layout_info_or_defaults (actor);
4916 g_value_set_enum (value, info->x_align);
4922 const ClutterLayoutInfo *info;
4924 info = _clutter_actor_get_layout_info_or_defaults (actor);
4925 g_value_set_enum (value, info->y_align);
4929 case PROP_MARGIN_TOP:
4931 const ClutterLayoutInfo *info;
4933 info = _clutter_actor_get_layout_info_or_defaults (actor);
4934 g_value_set_float (value, info->margin.top);
4938 case PROP_MARGIN_BOTTOM:
4940 const ClutterLayoutInfo *info;
4942 info = _clutter_actor_get_layout_info_or_defaults (actor);
4943 g_value_set_float (value, info->margin.bottom);
4947 case PROP_MARGIN_LEFT:
4949 const ClutterLayoutInfo *info;
4951 info = _clutter_actor_get_layout_info_or_defaults (actor);
4952 g_value_set_float (value, info->margin.left);
4956 case PROP_MARGIN_RIGHT:
4958 const ClutterLayoutInfo *info;
4960 info = _clutter_actor_get_layout_info_or_defaults (actor);
4961 g_value_set_float (value, info->margin.right);
4965 case PROP_BACKGROUND_COLOR_SET:
4966 g_value_set_boolean (value, priv->bg_color_set);
4969 case PROP_BACKGROUND_COLOR:
4970 g_value_set_boxed (value, &priv->bg_color);
4973 case PROP_FIRST_CHILD:
4974 g_value_set_object (value, priv->first_child);
4977 case PROP_LAST_CHILD:
4978 g_value_set_object (value, priv->last_child);
4982 g_value_set_object (value, priv->content);
4985 case PROP_CONTENT_GRAVITY:
4986 g_value_set_enum (value, priv->content_gravity);
4989 case PROP_CONTENT_BOX:
4991 ClutterActorBox box = { 0, };
4993 clutter_actor_get_content_box (actor, &box);
4994 g_value_set_boxed (value, &box);
4998 case PROP_MINIFICATION_FILTER:
4999 g_value_set_enum (value, priv->min_filter);
5002 case PROP_MAGNIFICATION_FILTER:
5003 g_value_set_enum (value, priv->mag_filter);
5007 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
5013 clutter_actor_dispose (GObject *object)
5015 ClutterActor *self = CLUTTER_ACTOR (object);
5016 ClutterActorPrivate *priv = self->priv;
5018 CLUTTER_NOTE (MISC, "Disposing of object (id=%d) of type '%s' (ref_count:%d)",
5020 g_type_name (G_OBJECT_TYPE (self)),
5023 g_signal_emit (self, actor_signals[DESTROY], 0);
5025 /* avoid recursing when called from clutter_actor_destroy() */
5026 if (priv->parent != NULL)
5028 ClutterActor *parent = priv->parent;
5030 /* go through the Container implementation unless this
5031 * is an internal child and has been marked as such.
5033 * removing the actor from its parent will reset the
5034 * realized and mapped states.
5036 if (!CLUTTER_ACTOR_IS_INTERNAL_CHILD (self))
5037 clutter_container_remove_actor (CLUTTER_CONTAINER (parent), self);
5039 clutter_actor_remove_child_internal (parent, self,
5040 REMOVE_CHILD_LEGACY_FLAGS);
5043 /* parent must be gone at this point */
5044 g_assert (priv->parent == NULL);
5046 if (!CLUTTER_ACTOR_IS_TOPLEVEL (self))
5048 /* can't be mapped or realized with no parent */
5049 g_assert (!CLUTTER_ACTOR_IS_MAPPED (self));
5050 g_assert (!CLUTTER_ACTOR_IS_REALIZED (self));
5053 g_clear_object (&priv->pango_context);
5054 g_clear_object (&priv->actions);
5055 g_clear_object (&priv->constraints);
5056 g_clear_object (&priv->effects);
5057 g_clear_object (&priv->flatten_effect);
5059 if (priv->layout_manager != NULL)
5061 clutter_layout_manager_set_container (priv->layout_manager, NULL);
5062 g_clear_object (&priv->layout_manager);
5065 if (priv->content != NULL)
5067 _clutter_content_detached (priv->content, self);
5068 g_clear_object (&priv->content);
5071 G_OBJECT_CLASS (clutter_actor_parent_class)->dispose (object);
5075 clutter_actor_finalize (GObject *object)
5077 ClutterActorPrivate *priv = CLUTTER_ACTOR (object)->priv;
5079 CLUTTER_NOTE (MISC, "Finalize actor (name='%s', id=%d) of type '%s'",
5080 priv->name != NULL ? priv->name : "<none>",
5082 g_type_name (G_OBJECT_TYPE (object)));
5084 _clutter_context_release_id (priv->id);
5086 g_free (priv->name);
5088 G_OBJECT_CLASS (clutter_actor_parent_class)->finalize (object);
5093 * clutter_actor_get_accessible:
5094 * @self: a #ClutterActor
5096 * Returns the accessible object that describes the actor to an
5097 * assistive technology.
5099 * If no class-specific #AtkObject implementation is available for the
5100 * actor instance in question, it will inherit an #AtkObject
5101 * implementation from the first ancestor class for which such an
5102 * implementation is defined.
5104 * The documentation of the <ulink
5105 * url="http://developer.gnome.org/doc/API/2.0/atk/index.html">ATK</ulink>
5106 * library contains more information about accessible objects and
5109 * Returns: (transfer none): the #AtkObject associated with @actor
5112 clutter_actor_get_accessible (ClutterActor *self)
5114 g_return_val_if_fail (CLUTTER_IS_ACTOR (self), NULL);
5116 return CLUTTER_ACTOR_GET_CLASS (self)->get_accessible (self);
5120 clutter_actor_real_get_accessible (ClutterActor *actor)
5122 return atk_gobject_accessible_for_object (G_OBJECT (actor));
5126 _clutter_actor_ref_accessible (AtkImplementor *implementor)
5128 AtkObject *accessible;
5130 accessible = clutter_actor_get_accessible (CLUTTER_ACTOR (implementor));
5131 if (accessible != NULL)
5132 g_object_ref (accessible);
5138 atk_implementor_iface_init (AtkImplementorIface *iface)
5140 iface->ref_accessible = _clutter_actor_ref_accessible;
5144 clutter_actor_update_default_paint_volume (ClutterActor *self,
5145 ClutterPaintVolume *volume)
5147 ClutterActorPrivate *priv = self->priv;
5148 gboolean res = FALSE;
5150 /* we start from the allocation */
5151 clutter_paint_volume_set_width (volume,
5152 priv->allocation.x2 - priv->allocation.x1);
5153 clutter_paint_volume_set_height (volume,
5154 priv->allocation.y2 - priv->allocation.y1);
5156 /* if the actor has a clip set then we have a pretty definite
5157 * size for the paint volume: the actor cannot possibly paint
5158 * outside the clip region.
5160 if (priv->clip_to_allocation)
5162 /* the allocation has already been set, so we just flip the
5169 ClutterActor *child;
5171 if (priv->has_clip &&
5172 priv->clip.width >= 0 &&
5173 priv->clip.height >= 0)
5175 ClutterVertex origin;
5177 origin.x = priv->clip.x;
5178 origin.y = priv->clip.y;
5181 clutter_paint_volume_set_origin (volume, &origin);
5182 clutter_paint_volume_set_width (volume, priv->clip.width);
5183 clutter_paint_volume_set_height (volume, priv->clip.height);
5188 /* if we don't have children we just bail out here... */
5189 if (priv->n_children == 0)
5192 /* ...but if we have children then we ask for their paint volume in
5193 * our coordinates. if any of our children replies that it doesn't
5194 * have a paint volume, we bail out
5196 for (child = priv->first_child;
5198 child = child->priv->next_sibling)
5200 const ClutterPaintVolume *child_volume;
5202 child_volume = clutter_actor_get_transformed_paint_volume (child, self);
5203 if (child_volume == NULL)
5209 clutter_paint_volume_union (volume, child_volume);
5219 clutter_actor_real_get_paint_volume (ClutterActor *self,
5220 ClutterPaintVolume *volume)
5222 ClutterActorClass *klass;
5225 klass = CLUTTER_ACTOR_GET_CLASS (self);
5227 /* XXX - this thoroughly sucks, but we don't want to penalize users
5228 * who use ClutterActor as a "new ClutterGroup" by forcing a full-stage
5229 * redraw. This should go away in 2.0.
5231 if (klass->paint == clutter_actor_real_paint &&
5232 klass->get_paint_volume == clutter_actor_real_get_paint_volume)
5238 /* this is the default return value: we cannot know if a class
5239 * is going to paint outside its allocation, so we take the
5240 * conservative approach.
5245 if (clutter_actor_update_default_paint_volume (self, volume))
5252 * clutter_actor_get_default_paint_volume:
5253 * @self: a #ClutterActor
5255 * Retrieves the default paint volume for @self.
5257 * This function provides the same #ClutterPaintVolume that would be
5258 * computed by the default implementation inside #ClutterActor of the
5259 * #ClutterActorClass.get_paint_volume() virtual function.
5261 * This function should only be used by #ClutterActor subclasses that
5262 * cannot chain up to the parent implementation when computing their
5265 * Return value: (transfer none): a pointer to the default
5266 * #ClutterPaintVolume, relative to the #ClutterActor, or %NULL if
5267 * the actor could not compute a valid paint volume. The returned value
5268 * is not guaranteed to be stable across multiple frames, so if you
5269 * want to retain it, you will need to copy it using
5270 * clutter_paint_volume_copy().
5274 const ClutterPaintVolume *
5275 clutter_actor_get_default_paint_volume (ClutterActor *self)
5277 ClutterPaintVolume volume;
5278 ClutterPaintVolume *res;
5280 g_return_val_if_fail (CLUTTER_IS_ACTOR (self), NULL);
5283 _clutter_paint_volume_init_static (&volume, self);
5284 if (clutter_actor_update_default_paint_volume (self, &volume))
5286 ClutterActor *stage = _clutter_actor_get_stage_internal (self);
5290 res = _clutter_stage_paint_volume_stack_allocate (CLUTTER_STAGE (stage));
5291 _clutter_paint_volume_copy_static (&volume, res);
5295 clutter_paint_volume_free (&volume);
5301 clutter_actor_real_has_overlaps (ClutterActor *self)
5303 /* By default we'll assume that all actors need an offscreen redirect to get
5304 * the correct opacity. Actors such as ClutterTexture that would never need
5305 * an offscreen redirect can override this to return FALSE. */
5310 clutter_actor_real_destroy (ClutterActor *actor)
5312 ClutterActorIter iter;
5314 g_object_freeze_notify (G_OBJECT (actor));
5316 clutter_actor_iter_init (&iter, actor);
5317 while (clutter_actor_iter_next (&iter, NULL))
5318 clutter_actor_iter_destroy (&iter);
5320 g_object_thaw_notify (G_OBJECT (actor));
5324 clutter_actor_constructor (GType gtype,
5326 GObjectConstructParam *props)
5328 GObjectClass *gobject_class;
5332 gobject_class = G_OBJECT_CLASS (clutter_actor_parent_class);
5333 retval = gobject_class->constructor (gtype, n_props, props);
5334 self = CLUTTER_ACTOR (retval);
5336 if (self->priv->layout_manager == NULL)
5338 ClutterLayoutManager *default_layout;
5340 CLUTTER_NOTE (LAYOUT, "Creating default layout manager");
5342 default_layout = clutter_fixed_layout_new ();
5343 clutter_actor_set_layout_manager (self, default_layout);
5350 clutter_actor_class_init (ClutterActorClass *klass)
5352 GObjectClass *object_class = G_OBJECT_CLASS (klass);
5354 quark_shader_data = g_quark_from_static_string ("-clutter-actor-shader-data");
5355 quark_actor_layout_info = g_quark_from_static_string ("-clutter-actor-layout-info");
5356 quark_actor_transform_info = g_quark_from_static_string ("-clutter-actor-transform-info");
5357 quark_actor_animation_info = g_quark_from_static_string ("-clutter-actor-animation-info");
5359 object_class->constructor = clutter_actor_constructor;
5360 object_class->set_property = clutter_actor_set_property;
5361 object_class->get_property = clutter_actor_get_property;
5362 object_class->dispose = clutter_actor_dispose;
5363 object_class->finalize = clutter_actor_finalize;
5365 klass->show = clutter_actor_real_show;
5366 klass->show_all = clutter_actor_show;
5367 klass->hide = clutter_actor_real_hide;
5368 klass->hide_all = clutter_actor_hide;
5369 klass->map = clutter_actor_real_map;
5370 klass->unmap = clutter_actor_real_unmap;
5371 klass->unrealize = clutter_actor_real_unrealize;
5372 klass->pick = clutter_actor_real_pick;
5373 klass->get_preferred_width = clutter_actor_real_get_preferred_width;
5374 klass->get_preferred_height = clutter_actor_real_get_preferred_height;
5375 klass->allocate = clutter_actor_real_allocate;
5376 klass->queue_redraw = clutter_actor_real_queue_redraw;
5377 klass->queue_relayout = clutter_actor_real_queue_relayout;
5378 klass->apply_transform = clutter_actor_real_apply_transform;
5379 klass->get_accessible = clutter_actor_real_get_accessible;
5380 klass->get_paint_volume = clutter_actor_real_get_paint_volume;
5381 klass->has_overlaps = clutter_actor_real_has_overlaps;
5382 klass->paint = clutter_actor_real_paint;
5383 klass->destroy = clutter_actor_real_destroy;
5385 g_type_class_add_private (klass, sizeof (ClutterActorPrivate));
5390 * X coordinate of the actor in pixels. If written, forces a fixed
5391 * position for the actor. If read, returns the fixed position if any,
5392 * otherwise the allocation if available, otherwise 0.
5394 * The #ClutterActor:x property is animatable.
5397 g_param_spec_float ("x",
5399 P_("X coordinate of the actor"),
5400 -G_MAXFLOAT, G_MAXFLOAT,
5403 G_PARAM_STATIC_STRINGS |
5404 CLUTTER_PARAM_ANIMATABLE);
5409 * Y coordinate of the actor in pixels. If written, forces a fixed
5410 * position for the actor. If read, returns the fixed position if
5411 * any, otherwise the allocation if available, otherwise 0.
5413 * The #ClutterActor:y property is animatable.
5416 g_param_spec_float ("y",
5418 P_("Y coordinate of the actor"),
5419 -G_MAXFLOAT, G_MAXFLOAT,
5422 G_PARAM_STATIC_STRINGS |
5423 CLUTTER_PARAM_ANIMATABLE);
5426 * ClutterActor:width:
5428 * Width of the actor (in pixels). If written, forces the minimum and
5429 * natural size request of the actor to the given width. If read, returns
5430 * the allocated width if available, otherwise the width request.
5432 * The #ClutterActor:width property is animatable.
5434 obj_props[PROP_WIDTH] =
5435 g_param_spec_float ("width",
5437 P_("Width of the actor"),
5441 G_PARAM_STATIC_STRINGS |
5442 CLUTTER_PARAM_ANIMATABLE);
5445 * ClutterActor:height:
5447 * Height of the actor (in pixels). If written, forces the minimum and
5448 * natural size request of the actor to the given height. If read, returns
5449 * the allocated height if available, otherwise the height request.
5451 * The #ClutterActor:height property is animatable.
5453 obj_props[PROP_HEIGHT] =
5454 g_param_spec_float ("height",
5456 P_("Height of the actor"),
5460 G_PARAM_STATIC_STRINGS |
5461 CLUTTER_PARAM_ANIMATABLE);
5464 * ClutterActor:fixed-x:
5466 * The fixed X position of the actor in pixels.
5468 * Writing this property sets #ClutterActor:fixed-position-set
5469 * property as well, as a side effect
5473 obj_props[PROP_FIXED_X] =
5474 g_param_spec_float ("fixed-x",
5476 P_("Forced X position of the actor"),
5477 -G_MAXFLOAT, G_MAXFLOAT,
5479 CLUTTER_PARAM_READWRITE);
5482 * ClutterActor:fixed-y:
5484 * The fixed Y position of the actor in pixels.
5486 * Writing this property sets the #ClutterActor:fixed-position-set
5487 * property as well, as a side effect
5491 obj_props[PROP_FIXED_Y] =
5492 g_param_spec_float ("fixed-y",
5494 P_("Forced Y position of the actor"),
5495 -G_MAXFLOAT, G_MAXFLOAT,
5497 CLUTTER_PARAM_READWRITE);
5500 * ClutterActor:fixed-position-set:
5502 * This flag controls whether the #ClutterActor:fixed-x and
5503 * #ClutterActor:fixed-y properties are used
5507 obj_props[PROP_FIXED_POSITION_SET] =
5508 g_param_spec_boolean ("fixed-position-set",
5509 P_("Fixed position set"),
5510 P_("Whether to use fixed positioning for the actor"),
5512 CLUTTER_PARAM_READWRITE);
5515 * ClutterActor:min-width:
5517 * A forced minimum width request for the actor, in pixels
5519 * Writing this property sets the #ClutterActor:min-width-set property
5520 * as well, as a side effect.
5522 *This property overrides the usual width request of the actor.
5526 obj_props[PROP_MIN_WIDTH] =
5527 g_param_spec_float ("min-width",
5529 P_("Forced minimum width request for the actor"),
5532 CLUTTER_PARAM_READWRITE);
5535 * ClutterActor:min-height:
5537 * A forced minimum height request for the actor, in pixels
5539 * Writing this property sets the #ClutterActor:min-height-set property
5540 * as well, as a side effect. This property overrides the usual height
5541 * request of the actor.
5545 obj_props[PROP_MIN_HEIGHT] =
5546 g_param_spec_float ("min-height",
5548 P_("Forced minimum height request for the actor"),
5551 CLUTTER_PARAM_READWRITE);
5554 * ClutterActor:natural-width:
5556 * A forced natural width request for the actor, in pixels
5558 * Writing this property sets the #ClutterActor:natural-width-set
5559 * property as well, as a side effect. This property overrides the
5560 * usual width request of the actor
5564 obj_props[PROP_NATURAL_WIDTH] =
5565 g_param_spec_float ("natural-width",
5566 P_("Natural Width"),
5567 P_("Forced natural width request for the actor"),
5570 CLUTTER_PARAM_READWRITE);
5573 * ClutterActor:natural-height:
5575 * A forced natural height request for the actor, in pixels
5577 * Writing this property sets the #ClutterActor:natural-height-set
5578 * property as well, as a side effect. This property overrides the
5579 * usual height request of the actor
5583 obj_props[PROP_NATURAL_HEIGHT] =
5584 g_param_spec_float ("natural-height",
5585 P_("Natural Height"),
5586 P_("Forced natural height request for the actor"),
5589 CLUTTER_PARAM_READWRITE);
5592 * ClutterActor:min-width-set:
5594 * This flag controls whether the #ClutterActor:min-width property
5599 obj_props[PROP_MIN_WIDTH_SET] =
5600 g_param_spec_boolean ("min-width-set",
5601 P_("Minimum width set"),
5602 P_("Whether to use the min-width property"),
5604 CLUTTER_PARAM_READWRITE);
5607 * ClutterActor:min-height-set:
5609 * This flag controls whether the #ClutterActor:min-height property
5614 obj_props[PROP_MIN_HEIGHT_SET] =
5615 g_param_spec_boolean ("min-height-set",
5616 P_("Minimum height set"),
5617 P_("Whether to use the min-height property"),
5619 CLUTTER_PARAM_READWRITE);
5622 * ClutterActor:natural-width-set:
5624 * This flag controls whether the #ClutterActor:natural-width property
5629 obj_props[PROP_NATURAL_WIDTH_SET] =
5630 g_param_spec_boolean ("natural-width-set",
5631 P_("Natural width set"),
5632 P_("Whether to use the natural-width property"),
5634 CLUTTER_PARAM_READWRITE);
5637 * ClutterActor:natural-height-set:
5639 * This flag controls whether the #ClutterActor:natural-height property
5644 obj_props[PROP_NATURAL_HEIGHT_SET] =
5645 g_param_spec_boolean ("natural-height-set",
5646 P_("Natural height set"),
5647 P_("Whether to use the natural-height property"),
5649 CLUTTER_PARAM_READWRITE);
5652 * ClutterActor:allocation:
5654 * The allocation for the actor, in pixels
5656 * This is property is read-only, but you might monitor it to know when an
5657 * actor moves or resizes
5661 obj_props[PROP_ALLOCATION] =
5662 g_param_spec_boxed ("allocation",
5664 P_("The actor's allocation"),
5665 CLUTTER_TYPE_ACTOR_BOX,
5666 CLUTTER_PARAM_READABLE);
5669 * ClutterActor:request-mode:
5671 * Request mode for the #ClutterActor. The request mode determines the
5672 * type of geometry management used by the actor, either height for width
5673 * (the default) or width for height.
5675 * For actors implementing height for width, the parent container should get
5676 * the preferred width first, and then the preferred height for that width.
5678 * For actors implementing width for height, the parent container should get
5679 * the preferred height first, and then the preferred width for that height.
5684 * ClutterRequestMode mode;
5685 * gfloat natural_width, min_width;
5686 * gfloat natural_height, min_height;
5688 * mode = clutter_actor_get_request_mode (child);
5689 * if (mode == CLUTTER_REQUEST_HEIGHT_FOR_WIDTH)
5691 * clutter_actor_get_preferred_width (child, -1,
5693 * &natural_width);
5694 * clutter_actor_get_preferred_height (child, natural_width,
5696 * &natural_height);
5700 * clutter_actor_get_preferred_height (child, -1,
5702 * &natural_height);
5703 * clutter_actor_get_preferred_width (child, natural_height,
5705 * &natural_width);
5709 * will retrieve the minimum and natural width and height depending on the
5710 * preferred request mode of the #ClutterActor "child".
5712 * The clutter_actor_get_preferred_size() function will implement this
5717 obj_props[PROP_REQUEST_MODE] =
5718 g_param_spec_enum ("request-mode",
5720 P_("The actor's request mode"),
5721 CLUTTER_TYPE_REQUEST_MODE,
5722 CLUTTER_REQUEST_HEIGHT_FOR_WIDTH,
5723 CLUTTER_PARAM_READWRITE);
5726 * ClutterActor:depth:
5728 * The position of the actor on the Z axis.
5730 * The #ClutterActor:depth property is relative to the parent's
5733 * The #ClutterActor:depth property is animatable.
5737 obj_props[PROP_DEPTH] =
5738 g_param_spec_float ("depth",
5740 P_("Position on the Z axis"),
5741 -G_MAXFLOAT, G_MAXFLOAT,
5744 G_PARAM_STATIC_STRINGS |
5745 CLUTTER_PARAM_ANIMATABLE);
5748 * ClutterActor:opacity:
5750 * Opacity of an actor, between 0 (fully transparent) and
5751 * 255 (fully opaque)
5753 * The #ClutterActor:opacity property is animatable.
5755 obj_props[PROP_OPACITY] =
5756 g_param_spec_uint ("opacity",
5758 P_("Opacity of an actor"),
5762 G_PARAM_STATIC_STRINGS |
5763 CLUTTER_PARAM_ANIMATABLE);
5766 * ClutterActor:offscreen-redirect:
5768 * Determines the conditions in which the actor will be redirected
5769 * to an offscreen framebuffer while being painted. For example this
5770 * can be used to cache an actor in a framebuffer or for improved
5771 * handling of transparent actors. See
5772 * clutter_actor_set_offscreen_redirect() for details.
5776 obj_props[PROP_OFFSCREEN_REDIRECT] =
5777 g_param_spec_flags ("offscreen-redirect",
5778 P_("Offscreen redirect"),
5779 P_("Flags controlling when to flatten the actor into a single image"),
5780 CLUTTER_TYPE_OFFSCREEN_REDIRECT,
5782 CLUTTER_PARAM_READWRITE);
5785 * ClutterActor:visible:
5787 * Whether the actor is set to be visible or not
5789 * See also #ClutterActor:mapped
5791 obj_props[PROP_VISIBLE] =
5792 g_param_spec_boolean ("visible",
5794 P_("Whether the actor is visible or not"),
5796 CLUTTER_PARAM_READWRITE);
5799 * ClutterActor:mapped:
5801 * Whether the actor is mapped (will be painted when the stage
5802 * to which it belongs is mapped)
5806 obj_props[PROP_MAPPED] =
5807 g_param_spec_boolean ("mapped",
5809 P_("Whether the actor will be painted"),
5811 CLUTTER_PARAM_READABLE);
5814 * ClutterActor:realized:
5816 * Whether the actor has been realized
5820 obj_props[PROP_REALIZED] =
5821 g_param_spec_boolean ("realized",
5823 P_("Whether the actor has been realized"),
5825 CLUTTER_PARAM_READABLE);
5828 * ClutterActor:reactive:
5830 * Whether the actor is reactive to events or not
5832 * Only reactive actors will emit event-related signals
5836 obj_props[PROP_REACTIVE] =
5837 g_param_spec_boolean ("reactive",
5839 P_("Whether the actor is reactive to events"),
5841 CLUTTER_PARAM_READWRITE);
5844 * ClutterActor:has-clip:
5846 * Whether the actor has the #ClutterActor:clip property set or not
5848 obj_props[PROP_HAS_CLIP] =
5849 g_param_spec_boolean ("has-clip",
5851 P_("Whether the actor has a clip set"),
5853 CLUTTER_PARAM_READABLE);
5856 * ClutterActor:clip:
5858 * The clip region for the actor, in actor-relative coordinates
5860 * Every part of the actor outside the clip region will not be
5863 obj_props[PROP_CLIP] =
5864 g_param_spec_boxed ("clip",
5866 P_("The clip region for the actor"),
5867 CLUTTER_TYPE_GEOMETRY,
5868 CLUTTER_PARAM_READWRITE);
5871 * ClutterActor:name:
5873 * The name of the actor
5877 obj_props[PROP_NAME] =
5878 g_param_spec_string ("name",
5880 P_("Name of the actor"),
5882 CLUTTER_PARAM_READWRITE);
5885 * ClutterActor:scale-x:
5887 * The horizontal scale of the actor.
5889 * The #ClutterActor:scale-x property is animatable.
5893 obj_props[PROP_SCALE_X] =
5894 g_param_spec_double ("scale-x",
5896 P_("Scale factor on the X axis"),
5900 G_PARAM_STATIC_STRINGS |
5901 CLUTTER_PARAM_ANIMATABLE);
5904 * ClutterActor:scale-y:
5906 * The vertical scale of the actor.
5908 * The #ClutterActor:scale-y property is animatable.
5912 obj_props[PROP_SCALE_Y] =
5913 g_param_spec_double ("scale-y",
5915 P_("Scale factor on the Y axis"),
5919 G_PARAM_STATIC_STRINGS |
5920 CLUTTER_PARAM_ANIMATABLE);
5923 * ClutterActor:scale-center-x:
5925 * The horizontal center point for scaling
5929 obj_props[PROP_SCALE_CENTER_X] =
5930 g_param_spec_float ("scale-center-x",
5931 P_("Scale Center X"),
5932 P_("Horizontal scale center"),
5933 -G_MAXFLOAT, G_MAXFLOAT,
5935 CLUTTER_PARAM_READWRITE);
5938 * ClutterActor:scale-center-y:
5940 * The vertical center point for scaling
5944 obj_props[PROP_SCALE_CENTER_Y] =
5945 g_param_spec_float ("scale-center-y",
5946 P_("Scale Center Y"),
5947 P_("Vertical scale center"),
5948 -G_MAXFLOAT, G_MAXFLOAT,
5950 CLUTTER_PARAM_READWRITE);
5953 * ClutterActor:scale-gravity:
5955 * The center point for scaling expressed as a #ClutterGravity
5959 obj_props[PROP_SCALE_GRAVITY] =
5960 g_param_spec_enum ("scale-gravity",
5961 P_("Scale Gravity"),
5962 P_("The center of scaling"),
5963 CLUTTER_TYPE_GRAVITY,
5964 CLUTTER_GRAVITY_NONE,
5965 CLUTTER_PARAM_READWRITE);
5968 * ClutterActor:rotation-angle-x:
5970 * The rotation angle on the X axis.
5972 * The #ClutterActor:rotation-angle-x property is animatable.
5976 obj_props[PROP_ROTATION_ANGLE_X] =
5977 g_param_spec_double ("rotation-angle-x",
5978 P_("Rotation Angle X"),
5979 P_("The rotation angle on the X axis"),
5980 -G_MAXDOUBLE, G_MAXDOUBLE,
5983 G_PARAM_STATIC_STRINGS |
5984 CLUTTER_PARAM_ANIMATABLE);
5987 * ClutterActor:rotation-angle-y:
5989 * The rotation angle on the Y axis
5991 * The #ClutterActor:rotation-angle-y property is animatable.
5995 obj_props[PROP_ROTATION_ANGLE_Y] =
5996 g_param_spec_double ("rotation-angle-y",
5997 P_("Rotation Angle Y"),
5998 P_("The rotation angle on the Y axis"),
5999 -G_MAXDOUBLE, G_MAXDOUBLE,
6002 G_PARAM_STATIC_STRINGS |
6003 CLUTTER_PARAM_ANIMATABLE);
6006 * ClutterActor:rotation-angle-z:
6008 * The rotation angle on the Z axis
6010 * The #ClutterActor:rotation-angle-z property is animatable.
6014 obj_props[PROP_ROTATION_ANGLE_Z] =
6015 g_param_spec_double ("rotation-angle-z",
6016 P_("Rotation Angle Z"),
6017 P_("The rotation angle on the Z axis"),
6018 -G_MAXDOUBLE, G_MAXDOUBLE,
6021 G_PARAM_STATIC_STRINGS |
6022 CLUTTER_PARAM_ANIMATABLE);
6025 * ClutterActor:rotation-center-x:
6027 * The rotation center on the X axis.
6031 obj_props[PROP_ROTATION_CENTER_X] =
6032 g_param_spec_boxed ("rotation-center-x",
6033 P_("Rotation Center X"),
6034 P_("The rotation center on the X axis"),
6035 CLUTTER_TYPE_VERTEX,
6036 CLUTTER_PARAM_READWRITE);
6039 * ClutterActor:rotation-center-y:
6041 * The rotation center on the Y axis.
6045 obj_props[PROP_ROTATION_CENTER_Y] =
6046 g_param_spec_boxed ("rotation-center-y",
6047 P_("Rotation Center Y"),
6048 P_("The rotation center on the Y axis"),
6049 CLUTTER_TYPE_VERTEX,
6050 CLUTTER_PARAM_READWRITE);
6053 * ClutterActor:rotation-center-z:
6055 * The rotation center on the Z axis.
6059 obj_props[PROP_ROTATION_CENTER_Z] =
6060 g_param_spec_boxed ("rotation-center-z",
6061 P_("Rotation Center Z"),
6062 P_("The rotation center on the Z axis"),
6063 CLUTTER_TYPE_VERTEX,
6064 CLUTTER_PARAM_READWRITE);
6067 * ClutterActor:rotation-center-z-gravity:
6069 * The rotation center on the Z axis expressed as a #ClutterGravity.
6073 obj_props[PROP_ROTATION_CENTER_Z_GRAVITY] =
6074 g_param_spec_enum ("rotation-center-z-gravity",
6075 P_("Rotation Center Z Gravity"),
6076 P_("Center point for rotation around the Z axis"),
6077 CLUTTER_TYPE_GRAVITY,
6078 CLUTTER_GRAVITY_NONE,
6079 CLUTTER_PARAM_READWRITE);
6082 * ClutterActor:anchor-x:
6084 * The X coordinate of an actor's anchor point, relative to
6085 * the actor coordinate space, in pixels
6089 obj_props[PROP_ANCHOR_X] =
6090 g_param_spec_float ("anchor-x",
6092 P_("X coordinate of the anchor point"),
6093 -G_MAXFLOAT, G_MAXFLOAT,
6095 CLUTTER_PARAM_READWRITE);
6098 * ClutterActor:anchor-y:
6100 * The Y coordinate of an actor's anchor point, relative to
6101 * the actor coordinate space, in pixels
6105 obj_props[PROP_ANCHOR_Y] =
6106 g_param_spec_float ("anchor-y",
6108 P_("Y coordinate of the anchor point"),
6109 -G_MAXFLOAT, G_MAXFLOAT,
6111 CLUTTER_PARAM_READWRITE);
6114 * ClutterActor:anchor-gravity:
6116 * The anchor point expressed as a #ClutterGravity
6120 obj_props[PROP_ANCHOR_GRAVITY] =
6121 g_param_spec_enum ("anchor-gravity",
6122 P_("Anchor Gravity"),
6123 P_("The anchor point as a ClutterGravity"),
6124 CLUTTER_TYPE_GRAVITY,
6125 CLUTTER_GRAVITY_NONE,
6126 CLUTTER_PARAM_READWRITE);
6129 * ClutterActor:show-on-set-parent:
6131 * If %TRUE, the actor is automatically shown when parented.
6133 * Calling clutter_actor_hide() on an actor which has not been
6134 * parented will set this property to %FALSE as a side effect.
6138 obj_props[PROP_SHOW_ON_SET_PARENT] =
6139 g_param_spec_boolean ("show-on-set-parent",
6140 P_("Show on set parent"),
6141 P_("Whether the actor is shown when parented"),
6143 CLUTTER_PARAM_READWRITE);
6146 * ClutterActor:clip-to-allocation:
6148 * Whether the clip region should track the allocated area
6151 * This property is ignored if a clip area has been explicitly
6152 * set using clutter_actor_set_clip().
6156 obj_props[PROP_CLIP_TO_ALLOCATION] =
6157 g_param_spec_boolean ("clip-to-allocation",
6158 P_("Clip to Allocation"),
6159 P_("Sets the clip region to track the actor's allocation"),
6161 CLUTTER_PARAM_READWRITE);
6164 * ClutterActor:text-direction:
6166 * The direction of the text inside a #ClutterActor.
6170 obj_props[PROP_TEXT_DIRECTION] =
6171 g_param_spec_enum ("text-direction",
6172 P_("Text Direction"),
6173 P_("Direction of the text"),
6174 CLUTTER_TYPE_TEXT_DIRECTION,
6175 CLUTTER_TEXT_DIRECTION_LTR,
6176 CLUTTER_PARAM_READWRITE);
6179 * ClutterActor:has-pointer:
6181 * Whether the actor contains the pointer of a #ClutterInputDevice
6186 obj_props[PROP_HAS_POINTER] =
6187 g_param_spec_boolean ("has-pointer",
6189 P_("Whether the actor contains the pointer of an input device"),
6191 CLUTTER_PARAM_READABLE);
6194 * ClutterActor:actions:
6196 * Adds a #ClutterAction to the actor
6200 obj_props[PROP_ACTIONS] =
6201 g_param_spec_object ("actions",
6203 P_("Adds an action to the actor"),
6204 CLUTTER_TYPE_ACTION,
6205 CLUTTER_PARAM_WRITABLE);
6208 * ClutterActor:constraints:
6210 * Adds a #ClutterConstraint to the actor
6214 obj_props[PROP_CONSTRAINTS] =
6215 g_param_spec_object ("constraints",
6217 P_("Adds a constraint to the actor"),
6218 CLUTTER_TYPE_CONSTRAINT,
6219 CLUTTER_PARAM_WRITABLE);
6222 * ClutterActor:effect:
6224 * Adds #ClutterEffect to the list of effects be applied on a #ClutterActor
6228 obj_props[PROP_EFFECT] =
6229 g_param_spec_object ("effect",
6231 P_("Add an effect to be applied on the actor"),
6232 CLUTTER_TYPE_EFFECT,
6233 CLUTTER_PARAM_WRITABLE);
6236 * ClutterActor:layout-manager:
6238 * A delegate object for controlling the layout of the children of
6243 obj_props[PROP_LAYOUT_MANAGER] =
6244 g_param_spec_object ("layout-manager",
6245 P_("Layout Manager"),
6246 P_("The object controlling the layout of an actor's children"),
6247 CLUTTER_TYPE_LAYOUT_MANAGER,
6248 CLUTTER_PARAM_READWRITE);
6252 * ClutterActor:x-align:
6254 * The alignment of an actor on the X axis, if the actor has been given
6255 * extra space for its allocation.
6259 obj_props[PROP_X_ALIGN] =
6260 g_param_spec_enum ("x-align",
6262 P_("The alignment of the actor on the X axis within its allocation"),
6263 CLUTTER_TYPE_ACTOR_ALIGN,
6264 CLUTTER_ACTOR_ALIGN_FILL,
6265 CLUTTER_PARAM_READWRITE);
6268 * ClutterActor:y-align:
6270 * The alignment of an actor on the Y axis, if the actor has been given
6271 * extra space for its allocation.
6275 obj_props[PROP_Y_ALIGN] =
6276 g_param_spec_enum ("y-align",
6278 P_("The alignment of the actor on the Y axis within its allocation"),
6279 CLUTTER_TYPE_ACTOR_ALIGN,
6280 CLUTTER_ACTOR_ALIGN_FILL,
6281 CLUTTER_PARAM_READWRITE);
6284 * ClutterActor:margin-top:
6286 * The margin (in pixels) from the top of the actor.
6288 * This property adds a margin to the actor's preferred size; the margin
6289 * will be automatically taken into account when allocating the actor.
6293 obj_props[PROP_MARGIN_TOP] =
6294 g_param_spec_float ("margin-top",
6296 P_("Extra space at the top"),
6299 CLUTTER_PARAM_READWRITE);
6302 * ClutterActor:margin-bottom:
6304 * The margin (in pixels) from the bottom of the actor.
6306 * This property adds a margin to the actor's preferred size; the margin
6307 * will be automatically taken into account when allocating the actor.
6311 obj_props[PROP_MARGIN_BOTTOM] =
6312 g_param_spec_float ("margin-bottom",
6313 P_("Margin Bottom"),
6314 P_("Extra space at the bottom"),
6317 CLUTTER_PARAM_READWRITE);
6320 * ClutterActor:margin-left:
6322 * The margin (in pixels) from the left of the actor.
6324 * This property adds a margin to the actor's preferred size; the margin
6325 * will be automatically taken into account when allocating the actor.
6329 obj_props[PROP_MARGIN_LEFT] =
6330 g_param_spec_float ("margin-left",
6332 P_("Extra space at the left"),
6335 CLUTTER_PARAM_READWRITE);
6338 * ClutterActor:margin-right:
6340 * The margin (in pixels) from the right of the actor.
6342 * This property adds a margin to the actor's preferred size; the margin
6343 * will be automatically taken into account when allocating the actor.
6347 obj_props[PROP_MARGIN_RIGHT] =
6348 g_param_spec_float ("margin-right",
6350 P_("Extra space at the right"),
6353 CLUTTER_PARAM_READWRITE);
6356 * ClutterActor:background-color-set:
6358 * Whether the #ClutterActor:background-color property has been set.
6362 obj_props[PROP_BACKGROUND_COLOR_SET] =
6363 g_param_spec_boolean ("background-color-set",
6364 P_("Background Color Set"),
6365 P_("Whether the background color is set"),
6367 CLUTTER_PARAM_READABLE);
6370 * ClutterActor:background-color:
6372 * Paints a solid fill of the actor's allocation using the specified
6375 * The #ClutterActor:background-color property is animatable.
6379 obj_props[PROP_BACKGROUND_COLOR] =
6380 clutter_param_spec_color ("background-color",
6381 P_("Background color"),
6382 P_("The actor's background color"),
6383 CLUTTER_COLOR_Transparent,
6385 G_PARAM_STATIC_STRINGS |
6386 CLUTTER_PARAM_ANIMATABLE);
6389 * ClutterActor:first-child:
6391 * The actor's first child.
6395 obj_props[PROP_FIRST_CHILD] =
6396 g_param_spec_object ("first-child",
6398 P_("The actor's first child"),
6400 CLUTTER_PARAM_READABLE);
6403 * ClutterActor:last-child:
6405 * The actor's last child.
6409 obj_props[PROP_LAST_CHILD] =
6410 g_param_spec_object ("last-child",
6412 P_("The actor's last child"),
6414 CLUTTER_PARAM_READABLE);
6417 * ClutterActor:content:
6419 * The #ClutterContent implementation that controls the content
6424 obj_props[PROP_CONTENT] =
6425 g_param_spec_object ("content",
6427 P_("Delegate object for painting the actor's content"),
6428 CLUTTER_TYPE_CONTENT,
6429 CLUTTER_PARAM_READWRITE);
6432 * ClutterActor:content-gravity:
6434 * The alignment that should be honoured by the #ClutterContent
6435 * set with the #ClutterActor:content property.
6437 * Changing the value of this property will change the bounding box of
6438 * the content; you can use the #ClutterActor:content-box property to
6439 * get the position and size of the content within the actor's
6442 * This property is meaningful only for #ClutterContent implementations
6443 * that have a preferred size, and if the preferred size is smaller than
6444 * the actor's allocation.
6448 obj_props[PROP_CONTENT_GRAVITY] =
6449 g_param_spec_enum ("content-gravity",
6450 P_("Content Gravity"),
6451 P_("Alignment of the actor's content"),
6452 CLUTTER_TYPE_CONTENT_GRAVITY,
6453 CLUTTER_CONTENT_GRAVITY_RESIZE_FILL,
6454 CLUTTER_PARAM_READWRITE);
6457 * ClutterActor:content-box:
6459 * The bounding box for the #ClutterContent used by the actor.
6461 * The value of this property is controlled by the #ClutterActor:allocation
6462 * and #ClutterActor:content-gravity properties of #ClutterActor.
6464 * The bounding box for the content is guaranteed to never exceed the
6465 * allocation's of the actor.
6469 obj_props[PROP_CONTENT_BOX] =
6470 g_param_spec_boxed ("content-box",
6472 P_("The bounding box of the actor's content"),
6473 CLUTTER_TYPE_ACTOR_BOX,
6474 CLUTTER_PARAM_READABLE);
6476 obj_props[PROP_MINIFICATION_FILTER] =
6477 g_param_spec_enum ("minification-filter",
6478 P_("Minification Filter"),
6479 P_("The filter used when reducing the size of the content"),
6480 CLUTTER_TYPE_SCALING_FILTER,
6481 CLUTTER_SCALING_FILTER_LINEAR,
6482 CLUTTER_PARAM_READWRITE);
6484 obj_props[PROP_MAGNIFICATION_FILTER] =
6485 g_param_spec_enum ("magnification-filter",
6486 P_("Magnification Filter"),
6487 P_("The filter used when increasing the size of the content"),
6488 CLUTTER_TYPE_SCALING_FILTER,
6489 CLUTTER_SCALING_FILTER_LINEAR,
6490 CLUTTER_PARAM_READWRITE);
6492 g_object_class_install_properties (object_class, PROP_LAST, obj_props);
6495 * ClutterActor::destroy:
6496 * @actor: the #ClutterActor which emitted the signal
6498 * The ::destroy signal notifies that all references held on the
6499 * actor which emitted it should be released.
6501 * The ::destroy signal should be used by all holders of a reference
6504 * This signal might result in the finalization of the #ClutterActor
6505 * if all references are released.
6507 * Composite actors and actors implementing the #ClutterContainer
6508 * interface should override the default implementation of the
6509 * class handler of this signal and call clutter_actor_destroy() on
6510 * their children. When overriding the default class handler, it is
6511 * required to chain up to the parent's implementation.
6515 actor_signals[DESTROY] =
6516 g_signal_new (I_("destroy"),
6517 G_TYPE_FROM_CLASS (object_class),
6518 G_SIGNAL_RUN_CLEANUP | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
6519 G_STRUCT_OFFSET (ClutterActorClass, destroy),
6521 _clutter_marshal_VOID__VOID,
6524 * ClutterActor::show:
6525 * @actor: the object which received the signal
6527 * The ::show signal is emitted when an actor is visible and
6528 * rendered on the stage.
6532 actor_signals[SHOW] =
6533 g_signal_new (I_("show"),
6534 G_TYPE_FROM_CLASS (object_class),
6536 G_STRUCT_OFFSET (ClutterActorClass, show),
6538 _clutter_marshal_VOID__VOID,
6541 * ClutterActor::hide:
6542 * @actor: the object which received the signal
6544 * The ::hide signal is emitted when an actor is no longer rendered
6549 actor_signals[HIDE] =
6550 g_signal_new (I_("hide"),
6551 G_TYPE_FROM_CLASS (object_class),
6553 G_STRUCT_OFFSET (ClutterActorClass, hide),
6555 _clutter_marshal_VOID__VOID,
6558 * ClutterActor::parent-set:
6559 * @actor: the object which received the signal
6560 * @old_parent: (allow-none): the previous parent of the actor, or %NULL
6562 * This signal is emitted when the parent of the actor changes.
6566 actor_signals[PARENT_SET] =
6567 g_signal_new (I_("parent-set"),
6568 G_TYPE_FROM_CLASS (object_class),
6570 G_STRUCT_OFFSET (ClutterActorClass, parent_set),
6572 _clutter_marshal_VOID__OBJECT,
6574 CLUTTER_TYPE_ACTOR);
6577 * ClutterActor::queue-redraw:
6578 * @actor: the actor we're bubbling the redraw request through
6579 * @origin: the actor which initiated the redraw request
6581 * The ::queue_redraw signal is emitted when clutter_actor_queue_redraw()
6582 * is called on @origin.
6584 * The default implementation for #ClutterActor chains up to the
6585 * parent actor and queues a redraw on the parent, thus "bubbling"
6586 * the redraw queue up through the actor graph. The default
6587 * implementation for #ClutterStage queues a clutter_stage_ensure_redraw()
6588 * in a main loop idle handler.
6590 * Note that the @origin actor may be the stage, or a container; it
6591 * does not have to be a leaf node in the actor graph.
6593 * Toolkits embedding a #ClutterStage which require a redraw and
6594 * relayout cycle can stop the emission of this signal using the
6595 * GSignal API, redraw the UI and then call clutter_stage_ensure_redraw()
6600 * on_redraw_complete (gpointer data)
6602 * ClutterStage *stage = data;
6604 * /* execute the Clutter drawing pipeline */
6605 * clutter_stage_ensure_redraw (stage);
6609 * on_stage_queue_redraw (ClutterStage *stage)
6611 * /* this prevents the default handler to run */
6612 * g_signal_stop_emission_by_name (stage, "queue-redraw");
6614 * /* queue a redraw with the host toolkit and call
6615 * * a function when the redraw has been completed
6617 * queue_a_redraw (G_CALLBACK (on_redraw_complete), stage);
6621 * <note><para>This signal is emitted before the Clutter paint
6622 * pipeline is executed. If you want to know when the pipeline has
6623 * been completed you should connect to the ::paint signal on the
6624 * Stage with g_signal_connect_after().</para></note>
6628 actor_signals[QUEUE_REDRAW] =
6629 g_signal_new (I_("queue-redraw"),
6630 G_TYPE_FROM_CLASS (object_class),
6633 G_STRUCT_OFFSET (ClutterActorClass, queue_redraw),
6635 _clutter_marshal_VOID__OBJECT,
6637 CLUTTER_TYPE_ACTOR);
6640 * ClutterActor::queue-relayout
6641 * @actor: the actor being queued for relayout
6643 * The ::queue_layout signal is emitted when clutter_actor_queue_relayout()
6644 * is called on an actor.
6646 * The default implementation for #ClutterActor chains up to the
6647 * parent actor and queues a relayout on the parent, thus "bubbling"
6648 * the relayout queue up through the actor graph.
6650 * The main purpose of this signal is to allow relayout to be propagated
6651 * properly in the procense of #ClutterClone actors. Applications will
6652 * not normally need to connect to this signal.
6656 actor_signals[QUEUE_RELAYOUT] =
6657 g_signal_new (I_("queue-relayout"),
6658 G_TYPE_FROM_CLASS (object_class),
6661 G_STRUCT_OFFSET (ClutterActorClass, queue_relayout),
6663 _clutter_marshal_VOID__VOID,
6667 * ClutterActor::event:
6668 * @actor: the actor which received the event
6669 * @event: a #ClutterEvent
6671 * The ::event signal is emitted each time an event is received
6672 * by the @actor. This signal will be emitted on every actor,
6673 * following the hierarchy chain, until it reaches the top-level
6674 * container (the #ClutterStage).
6676 * Return value: %TRUE if the event has been handled by the actor,
6677 * or %FALSE to continue the emission.
6681 actor_signals[EVENT] =
6682 g_signal_new (I_("event"),
6683 G_TYPE_FROM_CLASS (object_class),
6685 G_STRUCT_OFFSET (ClutterActorClass, event),
6686 _clutter_boolean_handled_accumulator, NULL,
6687 _clutter_marshal_BOOLEAN__BOXED,
6689 CLUTTER_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
6691 * ClutterActor::button-press-event:
6692 * @actor: the actor which received the event
6693 * @event: (type ClutterButtonEvent): a #ClutterButtonEvent
6695 * The ::button-press-event signal is emitted each time a mouse button
6696 * is pressed on @actor.
6698 * Return value: %TRUE if the event has been handled by the actor,
6699 * or %FALSE to continue the emission.
6703 actor_signals[BUTTON_PRESS_EVENT] =
6704 g_signal_new (I_("button-press-event"),
6705 G_TYPE_FROM_CLASS (object_class),
6707 G_STRUCT_OFFSET (ClutterActorClass, button_press_event),
6708 _clutter_boolean_handled_accumulator, NULL,
6709 _clutter_marshal_BOOLEAN__BOXED,
6711 CLUTTER_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
6713 * ClutterActor::button-release-event:
6714 * @actor: the actor which received the event
6715 * @event: (type ClutterButtonEvent): a #ClutterButtonEvent
6717 * The ::button-release-event signal is emitted each time a mouse button
6718 * is released on @actor.
6720 * Return value: %TRUE if the event has been handled by the actor,
6721 * or %FALSE to continue the emission.
6725 actor_signals[BUTTON_RELEASE_EVENT] =
6726 g_signal_new (I_("button-release-event"),
6727 G_TYPE_FROM_CLASS (object_class),
6729 G_STRUCT_OFFSET (ClutterActorClass, button_release_event),
6730 _clutter_boolean_handled_accumulator, NULL,
6731 _clutter_marshal_BOOLEAN__BOXED,
6733 CLUTTER_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
6735 * ClutterActor::scroll-event:
6736 * @actor: the actor which received the event
6737 * @event: (type ClutterScrollEvent): a #ClutterScrollEvent
6739 * The ::scroll-event signal is emitted each time the mouse is
6740 * scrolled on @actor
6742 * Return value: %TRUE if the event has been handled by the actor,
6743 * or %FALSE to continue the emission.
6747 actor_signals[SCROLL_EVENT] =
6748 g_signal_new (I_("scroll-event"),
6749 G_TYPE_FROM_CLASS (object_class),
6751 G_STRUCT_OFFSET (ClutterActorClass, scroll_event),
6752 _clutter_boolean_handled_accumulator, NULL,
6753 _clutter_marshal_BOOLEAN__BOXED,
6755 CLUTTER_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
6757 * ClutterActor::key-press-event:
6758 * @actor: the actor which received the event
6759 * @event: (type ClutterKeyEvent): a #ClutterKeyEvent
6761 * The ::key-press-event signal is emitted each time a keyboard button
6762 * is pressed while @actor has key focus (see clutter_stage_set_key_focus()).
6764 * Return value: %TRUE if the event has been handled by the actor,
6765 * or %FALSE to continue the emission.
6769 actor_signals[KEY_PRESS_EVENT] =
6770 g_signal_new (I_("key-press-event"),
6771 G_TYPE_FROM_CLASS (object_class),
6773 G_STRUCT_OFFSET (ClutterActorClass, key_press_event),
6774 _clutter_boolean_handled_accumulator, NULL,
6775 _clutter_marshal_BOOLEAN__BOXED,
6777 CLUTTER_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
6779 * ClutterActor::key-release-event:
6780 * @actor: the actor which received the event
6781 * @event: (type ClutterKeyEvent): a #ClutterKeyEvent
6783 * The ::key-release-event signal is emitted each time a keyboard button
6784 * is released while @actor has key focus (see
6785 * clutter_stage_set_key_focus()).
6787 * Return value: %TRUE if the event has been handled by the actor,
6788 * or %FALSE to continue the emission.
6792 actor_signals[KEY_RELEASE_EVENT] =
6793 g_signal_new (I_("key-release-event"),
6794 G_TYPE_FROM_CLASS (object_class),
6796 G_STRUCT_OFFSET (ClutterActorClass, key_release_event),
6797 _clutter_boolean_handled_accumulator, NULL,
6798 _clutter_marshal_BOOLEAN__BOXED,
6800 CLUTTER_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
6802 * ClutterActor::motion-event:
6803 * @actor: the actor which received the event
6804 * @event: (type ClutterMotionEvent): a #ClutterMotionEvent
6806 * The ::motion-event signal is emitted each time the mouse pointer is
6807 * moved over @actor.
6809 * Return value: %TRUE if the event has been handled by the actor,
6810 * or %FALSE to continue the emission.
6814 actor_signals[MOTION_EVENT] =
6815 g_signal_new (I_("motion-event"),
6816 G_TYPE_FROM_CLASS (object_class),
6818 G_STRUCT_OFFSET (ClutterActorClass, motion_event),
6819 _clutter_boolean_handled_accumulator, NULL,
6820 _clutter_marshal_BOOLEAN__BOXED,
6822 CLUTTER_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
6825 * ClutterActor::key-focus-in:
6826 * @actor: the actor which now has key focus
6828 * The ::key-focus-in signal is emitted when @actor receives key focus.
6832 actor_signals[KEY_FOCUS_IN] =
6833 g_signal_new (I_("key-focus-in"),
6834 G_TYPE_FROM_CLASS (object_class),
6836 G_STRUCT_OFFSET (ClutterActorClass, key_focus_in),
6838 _clutter_marshal_VOID__VOID,
6842 * ClutterActor::key-focus-out:
6843 * @actor: the actor which now has key focus
6845 * The ::key-focus-out signal is emitted when @actor loses key focus.
6849 actor_signals[KEY_FOCUS_OUT] =
6850 g_signal_new (I_("key-focus-out"),
6851 G_TYPE_FROM_CLASS (object_class),
6853 G_STRUCT_OFFSET (ClutterActorClass, key_focus_out),
6855 _clutter_marshal_VOID__VOID,
6859 * ClutterActor::enter-event:
6860 * @actor: the actor which the pointer has entered.
6861 * @event: (type ClutterCrossingEvent): a #ClutterCrossingEvent
6863 * The ::enter-event signal is emitted when the pointer enters the @actor
6865 * Return value: %TRUE if the event has been handled by the actor,
6866 * or %FALSE to continue the emission.
6870 actor_signals[ENTER_EVENT] =
6871 g_signal_new (I_("enter-event"),
6872 G_TYPE_FROM_CLASS (object_class),
6874 G_STRUCT_OFFSET (ClutterActorClass, enter_event),
6875 _clutter_boolean_handled_accumulator, NULL,
6876 _clutter_marshal_BOOLEAN__BOXED,
6878 CLUTTER_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
6881 * ClutterActor::leave-event:
6882 * @actor: the actor which the pointer has left
6883 * @event: (type ClutterCrossingEvent): a #ClutterCrossingEvent
6885 * The ::leave-event signal is emitted when the pointer leaves the @actor.
6887 * Return value: %TRUE if the event has been handled by the actor,
6888 * or %FALSE to continue the emission.
6892 actor_signals[LEAVE_EVENT] =
6893 g_signal_new (I_("leave-event"),
6894 G_TYPE_FROM_CLASS (object_class),
6896 G_STRUCT_OFFSET (ClutterActorClass, leave_event),
6897 _clutter_boolean_handled_accumulator, NULL,
6898 _clutter_marshal_BOOLEAN__BOXED,
6900 CLUTTER_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
6903 * ClutterActor::captured-event:
6904 * @actor: the actor which received the signal
6905 * @event: a #ClutterEvent
6907 * The ::captured-event signal is emitted when an event is captured
6908 * by Clutter. This signal will be emitted starting from the top-level
6909 * container (the #ClutterStage) to the actor which received the event
6910 * going down the hierarchy. This signal can be used to intercept every
6911 * event before the specialized events (like
6912 * ClutterActor::button-press-event or ::key-released-event) are
6915 * Return value: %TRUE if the event has been handled by the actor,
6916 * or %FALSE to continue the emission.
6920 actor_signals[CAPTURED_EVENT] =
6921 g_signal_new (I_("captured-event"),
6922 G_TYPE_FROM_CLASS (object_class),
6924 G_STRUCT_OFFSET (ClutterActorClass, captured_event),
6925 _clutter_boolean_handled_accumulator, NULL,
6926 _clutter_marshal_BOOLEAN__BOXED,
6928 CLUTTER_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
6931 * ClutterActor::paint:
6932 * @actor: the #ClutterActor that received the signal
6934 * The ::paint signal is emitted each time an actor is being painted.
6936 * Subclasses of #ClutterActor should override the class signal handler
6937 * and paint themselves in that function.
6939 * It is possible to connect a handler to the ::paint signal in order
6940 * to set up some custom aspect of a paint.
6944 actor_signals[PAINT] =
6945 g_signal_new (I_("paint"),
6946 G_TYPE_FROM_CLASS (object_class),
6949 G_STRUCT_OFFSET (ClutterActorClass, paint),
6951 _clutter_marshal_VOID__VOID,
6954 * ClutterActor::realize:
6955 * @actor: the #ClutterActor that received the signal
6957 * The ::realize signal is emitted each time an actor is being
6962 actor_signals[REALIZE] =
6963 g_signal_new (I_("realize"),
6964 G_TYPE_FROM_CLASS (object_class),
6966 G_STRUCT_OFFSET (ClutterActorClass, realize),
6968 _clutter_marshal_VOID__VOID,
6971 * ClutterActor::unrealize:
6972 * @actor: the #ClutterActor that received the signal
6974 * The ::unrealize signal is emitted each time an actor is being
6979 actor_signals[UNREALIZE] =
6980 g_signal_new (I_("unrealize"),
6981 G_TYPE_FROM_CLASS (object_class),
6983 G_STRUCT_OFFSET (ClutterActorClass, unrealize),
6985 _clutter_marshal_VOID__VOID,
6989 * ClutterActor::pick:
6990 * @actor: the #ClutterActor that received the signal
6991 * @color: the #ClutterColor to be used when picking
6993 * The ::pick signal is emitted each time an actor is being painted
6994 * in "pick mode". The pick mode is used to identify the actor during
6995 * the event handling phase, or by clutter_stage_get_actor_at_pos().
6996 * The actor should paint its shape using the passed @pick_color.
6998 * Subclasses of #ClutterActor should override the class signal handler
6999 * and paint themselves in that function.
7001 * It is possible to connect a handler to the ::pick signal in order
7002 * to set up some custom aspect of a paint in pick mode.
7006 actor_signals[PICK] =
7007 g_signal_new (I_("pick"),
7008 G_TYPE_FROM_CLASS (object_class),
7010 G_STRUCT_OFFSET (ClutterActorClass, pick),
7012 _clutter_marshal_VOID__BOXED,
7014 CLUTTER_TYPE_COLOR | G_SIGNAL_TYPE_STATIC_SCOPE);
7017 * ClutterActor::allocation-changed:
7018 * @actor: the #ClutterActor that emitted the signal
7019 * @box: a #ClutterActorBox with the new allocation
7020 * @flags: #ClutterAllocationFlags for the allocation
7022 * The ::allocation-changed signal is emitted when the
7023 * #ClutterActor:allocation property changes. Usually, application
7024 * code should just use the notifications for the :allocation property
7025 * but if you want to track the allocation flags as well, for instance
7026 * to know whether the absolute origin of @actor changed, then you might
7027 * want use this signal instead.
7031 actor_signals[ALLOCATION_CHANGED] =
7032 g_signal_new (I_("allocation-changed"),
7033 G_TYPE_FROM_CLASS (object_class),
7037 _clutter_marshal_VOID__BOXED_FLAGS,
7039 CLUTTER_TYPE_ACTOR_BOX | G_SIGNAL_TYPE_STATIC_SCOPE,
7040 CLUTTER_TYPE_ALLOCATION_FLAGS);
7043 * ClutterActor::transitions-completed:
7044 * @actor: a #ClutterActor
7046 * The ::transitions-completed signal is emitted once all transitions
7047 * involving @actor are complete.
7051 actor_signals[TRANSITIONS_COMPLETED] =
7052 g_signal_new (I_("transitions-completed"),
7053 G_TYPE_FROM_CLASS (object_class),
7057 _clutter_marshal_VOID__VOID,
7062 clutter_actor_init (ClutterActor *self)
7064 ClutterActorPrivate *priv;
7066 self->priv = priv = CLUTTER_ACTOR_GET_PRIVATE (self);
7068 priv->id = _clutter_context_acquire_id (self);
7071 priv->opacity = 0xff;
7072 priv->show_on_set_parent = TRUE;
7074 priv->needs_width_request = TRUE;
7075 priv->needs_height_request = TRUE;
7076 priv->needs_allocation = TRUE;
7078 priv->cached_width_age = 1;
7079 priv->cached_height_age = 1;
7081 priv->opacity_override = -1;
7082 priv->enable_model_view_transform = TRUE;
7084 /* Initialize an empty paint volume to start with */
7085 _clutter_paint_volume_init_static (&priv->last_paint_volume, NULL);
7086 priv->last_paint_volume_valid = TRUE;
7088 priv->transform_valid = FALSE;
7090 /* the default is to stretch the content, to match the
7091 * current behaviour of basically all actors. also, it's
7092 * the easiest thing to compute.
7094 priv->content_gravity = CLUTTER_CONTENT_GRAVITY_RESIZE_FILL;
7095 priv->min_filter = CLUTTER_SCALING_FILTER_LINEAR;
7096 priv->mag_filter = CLUTTER_SCALING_FILTER_LINEAR;
7100 * clutter_actor_new:
7102 * Creates a new #ClutterActor.
7104 * A newly created actor has a floating reference, which will be sunk
7105 * when it is added to another actor.
7107 * Return value: (transfer full): the newly created #ClutterActor
7112 clutter_actor_new (void)
7114 return g_object_new (CLUTTER_TYPE_ACTOR, NULL);
7118 * clutter_actor_destroy:
7119 * @self: a #ClutterActor
7121 * Destroys an actor. When an actor is destroyed, it will break any
7122 * references it holds to other objects. If the actor is inside a
7123 * container, the actor will be removed.
7125 * When you destroy a container, its children will be destroyed as well.
7127 * Note: you cannot destroy the #ClutterStage returned by
7128 * clutter_stage_get_default().
7131 clutter_actor_destroy (ClutterActor *self)
7133 g_return_if_fail (CLUTTER_IS_ACTOR (self));
7135 g_object_ref (self);
7137 /* avoid recursion while destroying */
7138 if (!CLUTTER_ACTOR_IN_DESTRUCTION (self))
7140 CLUTTER_SET_PRIVATE_FLAGS (self, CLUTTER_IN_DESTRUCTION);
7142 g_object_run_dispose (G_OBJECT (self));
7144 CLUTTER_UNSET_PRIVATE_FLAGS (self, CLUTTER_IN_DESTRUCTION);
7147 g_object_unref (self);
7151 _clutter_actor_finish_queue_redraw (ClutterActor *self,
7152 ClutterPaintVolume *clip)
7154 ClutterActorPrivate *priv = self->priv;
7155 ClutterPaintVolume *pv;
7158 /* Remove queue entry early in the process, otherwise a new
7159 queue_redraw() during signal handling could put back this
7160 object in the stage redraw list (but the entry is freed as
7161 soon as we return from this function, causing a segfault
7164 priv->queue_redraw_entry = NULL;
7166 /* If we've been explicitly passed a clip volume then there's
7167 * nothing more to calculate, but otherwise the only thing we know
7168 * is that the change is constrained to the given actor.
7170 * The idea is that if we know the paint volume for where the actor
7171 * was last drawn (in eye coordinates) and we also have the paint
7172 * volume for where it will be drawn next (in actor coordinates)
7173 * then if we queue a redraw for both these volumes that will cover
7174 * everything that needs to be redrawn to clear the old view and
7175 * show the latest view of the actor.
7177 * Don't clip this redraw if we don't know what position we had for
7178 * the previous redraw since we don't know where to set the clip so
7179 * it will clear the actor as it is currently.
7183 _clutter_actor_set_queue_redraw_clip (self, clip);
7186 else if (G_LIKELY (priv->last_paint_volume_valid))
7188 pv = _clutter_actor_get_paint_volume_mutable (self);
7191 ClutterActor *stage = _clutter_actor_get_stage_internal (self);
7193 /* make sure we redraw the actors old position... */
7194 _clutter_actor_set_queue_redraw_clip (stage,
7195 &priv->last_paint_volume);
7196 _clutter_actor_signal_queue_redraw (stage, stage);
7197 _clutter_actor_set_queue_redraw_clip (stage, NULL);
7199 /* XXX: Ideally the redraw signal would take a clip volume
7200 * argument, but that would be an ABI break. Until we can
7201 * break the ABI we pass the argument out-of-band
7204 /* setup the clip for the actors new position... */
7205 _clutter_actor_set_queue_redraw_clip (self, pv);
7214 _clutter_actor_signal_queue_redraw (self, self);
7216 /* Just in case anyone is manually firing redraw signals without
7217 * using the public queue_redraw() API we are careful to ensure that
7218 * our out-of-band clip member is cleared before returning...
7220 * Note: A NULL clip denotes a full-stage, un-clipped redraw
7222 if (G_LIKELY (clipped))
7223 _clutter_actor_set_queue_redraw_clip (self, NULL);
7227 _clutter_actor_get_allocation_clip (ClutterActor *self,
7228 ClutterActorBox *clip)
7230 ClutterActorBox allocation;
7232 /* XXX: we don't care if we get an out of date allocation here
7233 * because clutter_actor_queue_redraw_with_clip knows to ignore
7234 * the clip if the actor's allocation is invalid.
7236 * This is noted because clutter_actor_get_allocation_box does some
7237 * unnecessary work to support buggy code with a comment suggesting
7238 * that it could be changed later which would be good for this use
7241 clutter_actor_get_allocation_box (self, &allocation);
7243 /* NB: clutter_actor_queue_redraw_with_clip expects a box in the
7244 * actor's own coordinate space but the allocation is in parent
7248 clip->x2 = allocation.x2 - allocation.x1;
7249 clip->y2 = allocation.y2 - allocation.y1;
7253 _clutter_actor_queue_redraw_full (ClutterActor *self,
7254 ClutterRedrawFlags flags,
7255 ClutterPaintVolume *volume,
7256 ClutterEffect *effect)
7258 ClutterActorPrivate *priv = self->priv;
7259 ClutterPaintVolume allocation_pv;
7260 ClutterPaintVolume *pv;
7261 gboolean should_free_pv;
7262 ClutterActor *stage;
7264 /* Here's an outline of the actor queue redraw mechanism:
7266 * The process starts in one of the following two functions which
7267 * are wrappers for this function:
7268 * clutter_actor_queue_redraw
7269 * _clutter_actor_queue_redraw_with_clip
7271 * additionally, an effect can queue a redraw by wrapping this
7272 * function in clutter_effect_queue_rerun
7274 * This functions queues an entry in a list associated with the
7275 * stage which is a list of actors that queued a redraw while
7276 * updating the timelines, performing layouting and processing other
7277 * mainloop sources before the next paint starts.
7279 * We aim to minimize the processing done at this point because
7280 * there is a good chance other events will happen while updating
7281 * the scenegraph that would invalidate any expensive work we might
7282 * otherwise try to do here. For example we don't try and resolve
7283 * the screen space bounding box of an actor at this stage so as to
7284 * minimize how much of the screen redraw because it's possible
7285 * something else will happen which will force a full redraw anyway.
7287 * When all updates are complete and we come to paint the stage then
7288 * we iterate this list and actually emit the "queue-redraw" signals
7289 * for each of the listed actors which will bubble up to the stage
7290 * for each actor and at that point we will transform the actors
7291 * paint volume into screen coordinates to determine the clip region
7292 * for what needs to be redrawn in the next paint.
7294 * Besides minimizing redundant work another reason for this
7295 * deferred design is that it's more likely we will be able to
7296 * determine the paint volume of an actor once we've finished
7297 * updating the scenegraph because its allocation should be up to
7298 * date. NB: If we can't determine an actors paint volume then we
7299 * can't automatically queue a clipped redraw which can make a big
7300 * difference to performance.
7302 * So the control flow goes like this:
7303 * One of clutter_actor_queue_redraw,
7304 * _clutter_actor_queue_redraw_with_clip
7305 * or clutter_effect_queue_rerun
7307 * then control moves to:
7308 * _clutter_stage_queue_actor_redraw
7310 * later during _clutter_stage_do_update, once relayouting is done
7311 * and the scenegraph has been updated we will call:
7312 * _clutter_stage_finish_queue_redraws
7314 * _clutter_stage_finish_queue_redraws will call
7315 * _clutter_actor_finish_queue_redraw for each listed actor.
7316 * Note: actors *are* allowed to queue further redraws during this
7317 * process (considering clone actors or texture_new_from_actor which
7318 * respond to their source queueing a redraw by queuing a redraw
7319 * themselves). We repeat the process until the list is empty.
7321 * This will result in the "queue-redraw" signal being fired for
7322 * each actor which will pass control to the default signal handler:
7323 * clutter_actor_real_queue_redraw
7325 * This will bubble up to the stages handler:
7326 * clutter_stage_real_queue_redraw
7328 * clutter_stage_real_queue_redraw will transform the actors paint
7329 * volume into screen space and add it as a clip region for the next
7333 /* ignore queueing a redraw for actors being destroyed */
7334 if (CLUTTER_ACTOR_IN_DESTRUCTION (self))
7337 stage = _clutter_actor_get_stage_internal (self);
7339 /* Ignore queueing a redraw for actors not descended from a stage */
7343 /* ignore queueing a redraw on stages that are being destroyed */
7344 if (CLUTTER_ACTOR_IN_DESTRUCTION (stage))
7347 if (flags & CLUTTER_REDRAW_CLIPPED_TO_ALLOCATION)
7349 ClutterActorBox allocation_clip;
7350 ClutterVertex origin;
7352 /* If the actor doesn't have a valid allocation then we will
7353 * queue a full stage redraw. */
7354 if (priv->needs_allocation)
7356 /* NB: NULL denotes an undefined clip which will result in a
7358 _clutter_actor_set_queue_redraw_clip (self, NULL);
7359 _clutter_actor_signal_queue_redraw (self, self);
7363 _clutter_paint_volume_init_static (&allocation_pv, self);
7364 pv = &allocation_pv;
7366 _clutter_actor_get_allocation_clip (self, &allocation_clip);
7368 origin.x = allocation_clip.x1;
7369 origin.y = allocation_clip.y1;
7371 clutter_paint_volume_set_origin (pv, &origin);
7372 clutter_paint_volume_set_width (pv,
7373 allocation_clip.x2 - allocation_clip.x1);
7374 clutter_paint_volume_set_height (pv,
7375 allocation_clip.y2 -
7376 allocation_clip.y1);
7377 should_free_pv = TRUE;
7382 should_free_pv = FALSE;
7385 self->priv->queue_redraw_entry =
7386 _clutter_stage_queue_actor_redraw (CLUTTER_STAGE (stage),
7387 priv->queue_redraw_entry,
7392 clutter_paint_volume_free (pv);
7394 /* If this is the first redraw queued then we can directly use the
7396 if (!priv->is_dirty)
7397 priv->effect_to_redraw = effect;
7398 /* Otherwise we need to merge it with the existing effect parameter */
7399 else if (effect != NULL)
7401 /* If there's already an effect then we need to use whichever is
7402 later in the chain of actors. Otherwise a full redraw has
7403 already been queued on the actor so we need to ignore the
7405 if (priv->effect_to_redraw != NULL)
7407 if (priv->effects == NULL)
7408 g_warning ("Redraw queued with an effect that is "
7409 "not applied to the actor");
7414 for (l = _clutter_meta_group_peek_metas (priv->effects);
7418 if (l->data == priv->effect_to_redraw ||
7420 priv->effect_to_redraw = l->data;
7427 /* If no effect is specified then we need to redraw the whole
7429 priv->effect_to_redraw = NULL;
7432 priv->is_dirty = TRUE;
7436 * clutter_actor_queue_redraw:
7437 * @self: A #ClutterActor
7439 * Queues up a redraw of an actor and any children. The redraw occurs
7440 * once the main loop becomes idle (after the current batch of events
7441 * has been processed, roughly).
7443 * Applications rarely need to call this, as redraws are handled
7444 * automatically by modification functions.
7446 * This function will not do anything if @self is not visible, or
7447 * if the actor is inside an invisible part of the scenegraph.
7449 * Also be aware that painting is a NOP for actors with an opacity of
7452 * When you are implementing a custom actor you must queue a redraw
7453 * whenever some private state changes that will affect painting or
7454 * picking of your actor.
7457 clutter_actor_queue_redraw (ClutterActor *self)
7459 g_return_if_fail (CLUTTER_IS_ACTOR (self));
7461 _clutter_actor_queue_redraw_full (self,
7463 NULL, /* clip volume */
7468 * _clutter_actor_queue_redraw_with_clip:
7469 * @self: A #ClutterActor
7470 * @flags: A mask of #ClutterRedrawFlags controlling the behaviour of
7471 * this queue redraw.
7472 * @volume: A #ClutterPaintVolume describing the bounds of what needs to be
7473 * redrawn or %NULL if you are just using a @flag to state your
7476 * Queues up a clipped redraw of an actor and any children. The redraw
7477 * occurs once the main loop becomes idle (after the current batch of
7478 * events has been processed, roughly).
7480 * If no flags are given the clip volume is defined by @volume
7481 * specified in actor coordinates and tells Clutter that only content
7482 * within this volume has been changed so Clutter can optionally
7483 * optimize the redraw.
7485 * If the %CLUTTER_REDRAW_CLIPPED_TO_ALLOCATION @flag is used, @volume
7486 * should be %NULL and this tells Clutter to use the actor's current
7487 * allocation as a clip box. This flag can only be used for 2D actors,
7488 * because any actor with depth may be projected outside its
7491 * Applications rarely need to call this, as redraws are handled
7492 * automatically by modification functions.
7494 * This function will not do anything if @self is not visible, or if
7495 * the actor is inside an invisible part of the scenegraph.
7497 * Also be aware that painting is a NOP for actors with an opacity of
7500 * When you are implementing a custom actor you must queue a redraw
7501 * whenever some private state changes that will affect painting or
7502 * picking of your actor.
7505 _clutter_actor_queue_redraw_with_clip (ClutterActor *self,
7506 ClutterRedrawFlags flags,
7507 ClutterPaintVolume *volume)
7509 _clutter_actor_queue_redraw_full (self,
7511 volume, /* clip volume */
7516 _clutter_actor_queue_only_relayout (ClutterActor *self)
7518 ClutterActorPrivate *priv = self->priv;
7520 if (CLUTTER_ACTOR_IN_DESTRUCTION (self))
7523 if (priv->needs_width_request &&
7524 priv->needs_height_request &&
7525 priv->needs_allocation)
7526 return; /* save some cpu cycles */
7528 #if CLUTTER_ENABLE_DEBUG
7529 if (!CLUTTER_ACTOR_IS_TOPLEVEL (self) && CLUTTER_ACTOR_IN_RELAYOUT (self))
7531 g_warning ("The actor '%s' is currently inside an allocation "
7532 "cycle; calling clutter_actor_queue_relayout() is "
7534 _clutter_actor_get_debug_name (self));
7536 #endif /* CLUTTER_ENABLE_DEBUG */
7538 g_signal_emit (self, actor_signals[QUEUE_RELAYOUT], 0);
7542 * clutter_actor_queue_redraw_with_clip:
7543 * @self: a #ClutterActor
7544 * @clip: (allow-none): a rectangular clip region, or %NULL
7546 * Queues a redraw on @self limited to a specific, actor-relative
7549 * If @clip is %NULL this function is equivalent to
7550 * clutter_actor_queue_redraw().
7555 clutter_actor_queue_redraw_with_clip (ClutterActor *self,
7556 const cairo_rectangle_int_t *clip)
7558 ClutterPaintVolume volume;
7559 ClutterVertex origin;
7561 g_return_if_fail (CLUTTER_IS_ACTOR (self));
7565 clutter_actor_queue_redraw (self);
7569 _clutter_paint_volume_init_static (&volume, self);
7575 clutter_paint_volume_set_origin (&volume, &origin);
7576 clutter_paint_volume_set_width (&volume, clip->width);
7577 clutter_paint_volume_set_height (&volume, clip->height);
7579 _clutter_actor_queue_redraw_full (self, 0, &volume, NULL);
7581 clutter_paint_volume_free (&volume);
7585 * clutter_actor_queue_relayout:
7586 * @self: A #ClutterActor
7588 * Indicates that the actor's size request or other layout-affecting
7589 * properties may have changed. This function is used inside #ClutterActor
7590 * subclass implementations, not by applications directly.
7592 * Queueing a new layout automatically queues a redraw as well.
7597 clutter_actor_queue_relayout (ClutterActor *self)
7599 g_return_if_fail (CLUTTER_IS_ACTOR (self));
7601 _clutter_actor_queue_only_relayout (self);
7602 clutter_actor_queue_redraw (self);
7606 * clutter_actor_get_preferred_size:
7607 * @self: a #ClutterActor
7608 * @min_width_p: (out) (allow-none): return location for the minimum
7610 * @min_height_p: (out) (allow-none): return location for the minimum
7612 * @natural_width_p: (out) (allow-none): return location for the natural
7614 * @natural_height_p: (out) (allow-none): return location for the natural
7617 * Computes the preferred minimum and natural size of an actor, taking into
7618 * account the actor's geometry management (either height-for-width
7619 * or width-for-height).
7621 * The width and height used to compute the preferred height and preferred
7622 * width are the actor's natural ones.
7624 * If you need to control the height for the preferred width, or the width for
7625 * the preferred height, you should use clutter_actor_get_preferred_width()
7626 * and clutter_actor_get_preferred_height(), and check the actor's preferred
7627 * geometry management using the #ClutterActor:request-mode property.
7632 clutter_actor_get_preferred_size (ClutterActor *self,
7633 gfloat *min_width_p,
7634 gfloat *min_height_p,
7635 gfloat *natural_width_p,
7636 gfloat *natural_height_p)
7638 ClutterActorPrivate *priv;
7639 gfloat min_width, min_height;
7640 gfloat natural_width, natural_height;
7642 g_return_if_fail (CLUTTER_IS_ACTOR (self));
7646 min_width = min_height = 0;
7647 natural_width = natural_height = 0;
7649 if (priv->request_mode == CLUTTER_REQUEST_HEIGHT_FOR_WIDTH)
7651 CLUTTER_NOTE (LAYOUT, "Preferred size (height-for-width)");
7652 clutter_actor_get_preferred_width (self, -1,
7655 clutter_actor_get_preferred_height (self, natural_width,
7661 CLUTTER_NOTE (LAYOUT, "Preferred size (width-for-height)");
7662 clutter_actor_get_preferred_height (self, -1,
7665 clutter_actor_get_preferred_width (self, natural_height,
7671 *min_width_p = min_width;
7674 *min_height_p = min_height;
7676 if (natural_width_p)
7677 *natural_width_p = natural_width;
7679 if (natural_height_p)
7680 *natural_height_p = natural_height;
7685 * @align: a #ClutterActorAlign
7686 * @direction: a #ClutterTextDirection
7688 * Retrieves the correct alignment depending on the text direction
7690 * Return value: the effective alignment
7692 static ClutterActorAlign
7693 effective_align (ClutterActorAlign align,
7694 ClutterTextDirection direction)
7696 ClutterActorAlign res;
7700 case CLUTTER_ACTOR_ALIGN_START:
7701 res = (direction == CLUTTER_TEXT_DIRECTION_RTL)
7702 ? CLUTTER_ACTOR_ALIGN_END
7703 : CLUTTER_ACTOR_ALIGN_START;
7706 case CLUTTER_ACTOR_ALIGN_END:
7707 res = (direction == CLUTTER_TEXT_DIRECTION_RTL)
7708 ? CLUTTER_ACTOR_ALIGN_START
7709 : CLUTTER_ACTOR_ALIGN_END;
7721 adjust_for_margin (float margin_start,
7723 float *minimum_size,
7724 float *natural_size,
7725 float *allocated_start,
7726 float *allocated_end)
7728 *minimum_size -= (margin_start + margin_end);
7729 *natural_size -= (margin_start + margin_end);
7730 *allocated_start += margin_start;
7731 *allocated_end -= margin_end;
7735 adjust_for_alignment (ClutterActorAlign alignment,
7737 float *allocated_start,
7738 float *allocated_end)
7740 float allocated_size = *allocated_end - *allocated_start;
7744 case CLUTTER_ACTOR_ALIGN_FILL:
7748 case CLUTTER_ACTOR_ALIGN_START:
7750 *allocated_end = *allocated_start + MIN (natural_size, allocated_size);
7753 case CLUTTER_ACTOR_ALIGN_END:
7754 if (allocated_size > natural_size)
7756 *allocated_start += (allocated_size - natural_size);
7757 *allocated_end = *allocated_start + natural_size;
7761 case CLUTTER_ACTOR_ALIGN_CENTER:
7762 if (allocated_size > natural_size)
7764 *allocated_start += ceilf ((allocated_size - natural_size) / 2);
7765 *allocated_end = *allocated_start + MIN (allocated_size, natural_size);
7772 * clutter_actor_adjust_width:
7773 * @self: a #ClutterActor
7774 * @minimum_width: (inout): the actor's preferred minimum width, which
7775 * will be adjusted depending on the margin
7776 * @natural_width: (inout): the actor's preferred natural width, which
7777 * will be adjusted depending on the margin
7778 * @adjusted_x1: (out): the adjusted x1 for the actor's bounding box
7779 * @adjusted_x2: (out): the adjusted x2 for the actor's bounding box
7781 * Adjusts the preferred and allocated position and size of an actor,
7782 * depending on the margin and alignment properties.
7785 clutter_actor_adjust_width (ClutterActor *self,
7786 gfloat *minimum_width,
7787 gfloat *natural_width,
7788 gfloat *adjusted_x1,
7789 gfloat *adjusted_x2)
7791 ClutterTextDirection text_dir;
7792 const ClutterLayoutInfo *info;
7794 info = _clutter_actor_get_layout_info_or_defaults (self);
7795 text_dir = clutter_actor_get_text_direction (self);
7797 CLUTTER_NOTE (LAYOUT, "Adjusting allocated X and width");
7799 /* this will tweak natural_width to remove the margin, so that
7800 * adjust_for_alignment() will use the correct size
7802 adjust_for_margin (info->margin.left, info->margin.right,
7803 minimum_width, natural_width,
7804 adjusted_x1, adjusted_x2);
7806 adjust_for_alignment (effective_align (info->x_align, text_dir),
7808 adjusted_x1, adjusted_x2);
7812 * clutter_actor_adjust_height:
7813 * @self: a #ClutterActor
7814 * @minimum_height: (inout): the actor's preferred minimum height, which
7815 * will be adjusted depending on the margin
7816 * @natural_height: (inout): the actor's preferred natural height, which
7817 * will be adjusted depending on the margin
7818 * @adjusted_y1: (out): the adjusted y1 for the actor's bounding box
7819 * @adjusted_y2: (out): the adjusted y2 for the actor's bounding box
7821 * Adjusts the preferred and allocated position and size of an actor,
7822 * depending on the margin and alignment properties.
7825 clutter_actor_adjust_height (ClutterActor *self,
7826 gfloat *minimum_height,
7827 gfloat *natural_height,
7828 gfloat *adjusted_y1,
7829 gfloat *adjusted_y2)
7831 const ClutterLayoutInfo *info;
7833 info = _clutter_actor_get_layout_info_or_defaults (self);
7835 CLUTTER_NOTE (LAYOUT, "Adjusting allocated Y and height");
7837 /* this will tweak natural_height to remove the margin, so that
7838 * adjust_for_alignment() will use the correct size
7840 adjust_for_margin (info->margin.top, info->margin.bottom,
7841 minimum_height, natural_height,
7845 /* we don't use effective_align() here, because text direction
7846 * only affects the horizontal axis
7848 adjust_for_alignment (info->y_align,
7855 /* looks for a cached size request for this for_size. If not
7856 * found, returns the oldest entry so it can be overwritten */
7858 _clutter_actor_get_cached_size_request (gfloat for_size,
7859 SizeRequest *cached_size_requests,
7860 SizeRequest **result)
7864 *result = &cached_size_requests[0];
7866 for (i = 0; i < N_CACHED_SIZE_REQUESTS; i++)
7870 sr = &cached_size_requests[i];
7873 sr->for_size == for_size)
7875 CLUTTER_NOTE (LAYOUT, "Size cache hit for size: %.2f", for_size);
7879 else if (sr->age < (*result)->age)
7885 CLUTTER_NOTE (LAYOUT, "Size cache miss for size: %.2f", for_size);
7891 * clutter_actor_get_preferred_width:
7892 * @self: A #ClutterActor
7893 * @for_height: available height when computing the preferred width,
7894 * or a negative value to indicate that no height is defined
7895 * @min_width_p: (out) (allow-none): return location for minimum width,
7897 * @natural_width_p: (out) (allow-none): return location for the natural
7900 * Computes the requested minimum and natural widths for an actor,
7901 * optionally depending on the specified height, or if they are
7902 * already computed, returns the cached values.
7904 * An actor may not get its request - depending on the layout
7905 * manager that's in effect.
7907 * A request should not incorporate the actor's scale or anchor point;
7908 * those transformations do not affect layout, only rendering.
7913 clutter_actor_get_preferred_width (ClutterActor *self,
7915 gfloat *min_width_p,
7916 gfloat *natural_width_p)
7918 float request_min_width, request_natural_width;
7919 SizeRequest *cached_size_request;
7920 const ClutterLayoutInfo *info;
7921 ClutterActorPrivate *priv;
7922 gboolean found_in_cache;
7924 g_return_if_fail (CLUTTER_IS_ACTOR (self));
7928 info = _clutter_actor_get_layout_info_or_defaults (self);
7930 /* we shortcircuit the case of a fixed size set using set_width() */
7931 if (priv->min_width_set && priv->natural_width_set)
7933 if (min_width_p != NULL)
7934 *min_width_p = info->min_width + (info->margin.left + info->margin.right);
7936 if (natural_width_p != NULL)
7937 *natural_width_p = info->natural_width + (info->margin.left + info->margin.right);
7942 /* the remaining cases are:
7944 * - either min_width or natural_width have been set
7945 * - neither min_width or natural_width have been set
7947 * in both cases, we go through the cache (and through the actor in case
7948 * of cache misses) and determine the authoritative value depending on
7952 if (!priv->needs_width_request)
7955 _clutter_actor_get_cached_size_request (for_height,
7956 priv->width_requests,
7957 &cached_size_request);
7961 /* if the actor needs a width request we use the first slot */
7962 found_in_cache = FALSE;
7963 cached_size_request = &priv->width_requests[0];
7966 if (!found_in_cache)
7968 gfloat minimum_width, natural_width;
7969 ClutterActorClass *klass;
7971 minimum_width = natural_width = 0;
7973 /* adjust for the margin */
7974 if (for_height >= 0)
7976 for_height -= (info->margin.top + info->margin.bottom);
7981 CLUTTER_NOTE (LAYOUT, "Width request for %.2f px", for_height);
7983 klass = CLUTTER_ACTOR_GET_CLASS (self);
7984 klass->get_preferred_width (self, for_height,
7988 /* adjust for the margin */
7989 minimum_width += (info->margin.left + info->margin.right);
7990 natural_width += (info->margin.left + info->margin.right);
7992 /* Due to accumulated float errors, it's better not to warn
7993 * on this, but just fix it.
7995 if (natural_width < minimum_width)
7996 natural_width = minimum_width;
7998 cached_size_request->min_size = minimum_width;
7999 cached_size_request->natural_size = natural_width;
8000 cached_size_request->for_size = for_height;
8001 cached_size_request->age = priv->cached_width_age;
8003 priv->cached_width_age += 1;
8004 priv->needs_width_request = FALSE;
8007 if (!priv->min_width_set)
8008 request_min_width = cached_size_request->min_size;
8010 request_min_width = info->min_width;
8012 if (!priv->natural_width_set)
8013 request_natural_width = cached_size_request->natural_size;
8015 request_natural_width = info->natural_width;
8018 *min_width_p = request_min_width;
8020 if (natural_width_p)
8021 *natural_width_p = request_natural_width;
8025 * clutter_actor_get_preferred_height:
8026 * @self: A #ClutterActor
8027 * @for_width: available width to assume in computing desired height,
8028 * or a negative value to indicate that no width is defined
8029 * @min_height_p: (out) (allow-none): return location for minimum height,
8031 * @natural_height_p: (out) (allow-none): return location for natural
8034 * Computes the requested minimum and natural heights for an actor,
8035 * or if they are already computed, returns the cached values.
8037 * An actor may not get its request - depending on the layout
8038 * manager that's in effect.
8040 * A request should not incorporate the actor's scale or anchor point;
8041 * those transformations do not affect layout, only rendering.
8046 clutter_actor_get_preferred_height (ClutterActor *self,
8048 gfloat *min_height_p,
8049 gfloat *natural_height_p)
8051 float request_min_height, request_natural_height;
8052 SizeRequest *cached_size_request;
8053 const ClutterLayoutInfo *info;
8054 ClutterActorPrivate *priv;
8055 gboolean found_in_cache;
8057 g_return_if_fail (CLUTTER_IS_ACTOR (self));
8061 info = _clutter_actor_get_layout_info_or_defaults (self);
8063 /* we shortcircuit the case of a fixed size set using set_height() */
8064 if (priv->min_height_set && priv->natural_height_set)
8066 if (min_height_p != NULL)
8067 *min_height_p = info->min_height + (info->margin.top + info->margin.bottom);
8069 if (natural_height_p != NULL)
8070 *natural_height_p = info->natural_height + (info->margin.top + info->margin.bottom);
8075 /* the remaining cases are:
8077 * - either min_height or natural_height have been set
8078 * - neither min_height or natural_height have been set
8080 * in both cases, we go through the cache (and through the actor in case
8081 * of cache misses) and determine the authoritative value depending on
8085 if (!priv->needs_height_request)
8088 _clutter_actor_get_cached_size_request (for_width,
8089 priv->height_requests,
8090 &cached_size_request);
8094 found_in_cache = FALSE;
8095 cached_size_request = &priv->height_requests[0];
8098 if (!found_in_cache)
8100 gfloat minimum_height, natural_height;
8101 ClutterActorClass *klass;
8103 minimum_height = natural_height = 0;
8105 CLUTTER_NOTE (LAYOUT, "Height request for %.2f px", for_width);
8107 /* adjust for margin */
8110 for_width -= (info->margin.left + info->margin.right);
8115 klass = CLUTTER_ACTOR_GET_CLASS (self);
8116 klass->get_preferred_height (self, for_width,
8120 /* adjust for margin */
8121 minimum_height += (info->margin.top + info->margin.bottom);
8122 natural_height += (info->margin.top + info->margin.bottom);
8124 /* Due to accumulated float errors, it's better not to warn
8125 * on this, but just fix it.
8127 if (natural_height < minimum_height)
8128 natural_height = minimum_height;
8130 cached_size_request->min_size = minimum_height;
8131 cached_size_request->natural_size = natural_height;
8132 cached_size_request->for_size = for_width;
8133 cached_size_request->age = priv->cached_height_age;
8135 priv->cached_height_age += 1;
8136 priv->needs_height_request = FALSE;
8139 if (!priv->min_height_set)
8140 request_min_height = cached_size_request->min_size;
8142 request_min_height = info->min_height;
8144 if (!priv->natural_height_set)
8145 request_natural_height = cached_size_request->natural_size;
8147 request_natural_height = info->natural_height;
8150 *min_height_p = request_min_height;
8152 if (natural_height_p)
8153 *natural_height_p = request_natural_height;
8157 * clutter_actor_get_allocation_box:
8158 * @self: A #ClutterActor
8159 * @box: (out): the function fills this in with the actor's allocation
8161 * Gets the layout box an actor has been assigned. The allocation can
8162 * only be assumed valid inside a paint() method; anywhere else, it
8163 * may be out-of-date.
8165 * An allocation does not incorporate the actor's scale or anchor point;
8166 * those transformations do not affect layout, only rendering.
8168 * <note>Do not call any of the clutter_actor_get_allocation_*() family
8169 * of functions inside the implementation of the get_preferred_width()
8170 * or get_preferred_height() virtual functions.</note>
8175 clutter_actor_get_allocation_box (ClutterActor *self,
8176 ClutterActorBox *box)
8178 g_return_if_fail (CLUTTER_IS_ACTOR (self));
8180 /* XXX - if needs_allocation=TRUE, we can either 1) g_return_if_fail,
8181 * which limits calling get_allocation to inside paint() basically; or
8182 * we can 2) force a layout, which could be expensive if someone calls
8183 * get_allocation somewhere silly; or we can 3) just return the latest
8184 * value, allowing it to be out-of-date, and assume people know what
8187 * The least-surprises approach that keeps existing code working is
8188 * likely to be 2). People can end up doing some inefficient things,
8189 * though, and in general code that requires 2) is probably broken.
8192 /* this implements 2) */
8193 if (G_UNLIKELY (self->priv->needs_allocation))
8195 ClutterActor *stage = _clutter_actor_get_stage_internal (self);
8197 /* do not queue a relayout on an unparented actor */
8199 _clutter_stage_maybe_relayout (stage);
8202 /* commenting out the code above and just keeping this assigment
8205 *box = self->priv->allocation;
8209 * clutter_actor_get_allocation_geometry:
8210 * @self: A #ClutterActor
8211 * @geom: (out): allocation geometry in pixels
8213 * Gets the layout box an actor has been assigned. The allocation can
8214 * only be assumed valid inside a paint() method; anywhere else, it
8215 * may be out-of-date.
8217 * An allocation does not incorporate the actor's scale or anchor point;
8218 * those transformations do not affect layout, only rendering.
8220 * The returned rectangle is in pixels.
8225 clutter_actor_get_allocation_geometry (ClutterActor *self,
8226 ClutterGeometry *geom)
8228 ClutterActorBox box;
8230 g_return_if_fail (CLUTTER_IS_ACTOR (self));
8231 g_return_if_fail (geom != NULL);
8233 clutter_actor_get_allocation_box (self, &box);
8235 geom->x = CLUTTER_NEARBYINT (clutter_actor_box_get_x (&box));
8236 geom->y = CLUTTER_NEARBYINT (clutter_actor_box_get_y (&box));
8237 geom->width = CLUTTER_NEARBYINT (clutter_actor_box_get_width (&box));
8238 geom->height = CLUTTER_NEARBYINT (clutter_actor_box_get_height (&box));
8242 clutter_actor_update_constraints (ClutterActor *self,
8243 ClutterActorBox *allocation)
8245 ClutterActorPrivate *priv = self->priv;
8246 const GList *constraints, *l;
8248 if (priv->constraints == NULL)
8251 constraints = _clutter_meta_group_peek_metas (priv->constraints);
8252 for (l = constraints; l != NULL; l = l->next)
8254 ClutterConstraint *constraint = l->data;
8255 ClutterActorMeta *meta = l->data;
8257 if (clutter_actor_meta_get_enabled (meta))
8259 _clutter_constraint_update_allocation (constraint,
8263 CLUTTER_NOTE (LAYOUT,
8264 "Allocation of '%s' after constraint '%s': "
8265 "{ %.2f, %.2f, %.2f, %.2f }",
8266 _clutter_actor_get_debug_name (self),
8267 _clutter_actor_meta_get_debug_name (meta),
8277 * clutter_actor_adjust_allocation:
8278 * @self: a #ClutterActor
8279 * @allocation: (inout): the allocation to adjust
8281 * Adjusts the passed allocation box taking into account the actor's
8282 * layout information, like alignment, expansion, and margin.
8285 clutter_actor_adjust_allocation (ClutterActor *self,
8286 ClutterActorBox *allocation)
8288 ClutterActorBox adj_allocation;
8289 float alloc_width, alloc_height;
8290 float min_width, min_height;
8291 float nat_width, nat_height;
8292 ClutterRequestMode req_mode;
8294 adj_allocation = *allocation;
8296 clutter_actor_box_get_size (allocation, &alloc_width, &alloc_height);
8298 /* we want to hit the cache, so we use the public API */
8299 req_mode = clutter_actor_get_request_mode (self);
8301 if (req_mode == CLUTTER_REQUEST_HEIGHT_FOR_WIDTH)
8303 clutter_actor_get_preferred_width (self, -1,
8306 clutter_actor_get_preferred_height (self, alloc_width,
8310 else if (req_mode == CLUTTER_REQUEST_WIDTH_FOR_HEIGHT)
8312 clutter_actor_get_preferred_height (self, -1,
8315 clutter_actor_get_preferred_height (self, alloc_height,
8320 #ifdef CLUTTER_ENABLE_DEBUG
8321 /* warn about underallocations */
8322 if (_clutter_diagnostic_enabled () &&
8323 (floorf (min_width - alloc_width) > 0 ||
8324 floorf (min_height - alloc_height) > 0))
8326 ClutterActor *parent = clutter_actor_get_parent (self);
8328 /* the only actors that are allowed to be underallocated are the Stage,
8329 * as it doesn't have an implicit size, and Actors that specifically
8330 * told us that they want to opt-out from layout control mechanisms
8331 * through the NO_LAYOUT escape hatch.
8333 if (parent != NULL &&
8334 !(self->flags & CLUTTER_ACTOR_NO_LAYOUT) != 0)
8336 g_warning (G_STRLOC ": The actor '%s' is getting an allocation "
8337 "of %.2f x %.2f from its parent actor '%s', but its "
8338 "requested minimum size is of %.2f x %.2f",
8339 _clutter_actor_get_debug_name (self),
8340 alloc_width, alloc_height,
8341 _clutter_actor_get_debug_name (parent),
8342 min_width, min_height);
8347 clutter_actor_adjust_width (self,
8351 &adj_allocation.x2);
8353 clutter_actor_adjust_height (self,
8357 &adj_allocation.y2);
8359 /* we maintain the invariant that an allocation cannot be adjusted
8360 * to be outside the parent-given box
8362 if (adj_allocation.x1 < allocation->x1 ||
8363 adj_allocation.y1 < allocation->y1 ||
8364 adj_allocation.x2 > allocation->x2 ||
8365 adj_allocation.y2 > allocation->y2)
8367 g_warning (G_STRLOC ": The actor '%s' tried to adjust its allocation "
8368 "to { %.2f, %.2f, %.2f, %.2f }, which is outside of its "
8369 "original allocation of { %.2f, %.2f, %.2f, %.2f }",
8370 _clutter_actor_get_debug_name (self),
8371 adj_allocation.x1, adj_allocation.y1,
8372 adj_allocation.x2 - adj_allocation.x1,
8373 adj_allocation.y2 - adj_allocation.y1,
8374 allocation->x1, allocation->y1,
8375 allocation->x2 - allocation->x1,
8376 allocation->y2 - allocation->y1);
8380 *allocation = adj_allocation;
8384 * clutter_actor_allocate:
8385 * @self: A #ClutterActor
8386 * @box: new allocation of the actor, in parent-relative coordinates
8387 * @flags: flags that control the allocation
8389 * Called by the parent of an actor to assign the actor its size.
8390 * Should never be called by applications (except when implementing
8391 * a container or layout manager).
8393 * Actors can know from their allocation box whether they have moved
8394 * with respect to their parent actor. The @flags parameter describes
8395 * additional information about the allocation, for instance whether
8396 * the parent has moved with respect to the stage, for example because
8397 * a grandparent's origin has moved.
8402 clutter_actor_allocate (ClutterActor *self,
8403 const ClutterActorBox *box,
8404 ClutterAllocationFlags flags)
8406 ClutterActorPrivate *priv;
8407 ClutterActorClass *klass;
8408 ClutterActorBox old_allocation, real_allocation;
8409 gboolean origin_changed, child_moved, size_changed;
8410 gboolean stage_allocation_changed;
8412 g_return_if_fail (CLUTTER_IS_ACTOR (self));
8413 if (G_UNLIKELY (_clutter_actor_get_stage_internal (self) == NULL))
8415 g_warning ("Spurious clutter_actor_allocate called for actor %p/%s "
8416 "which isn't a descendent of the stage!\n",
8417 self, _clutter_actor_get_debug_name (self));
8423 old_allocation = priv->allocation;
8424 real_allocation = *box;
8426 /* constraints are allowed to modify the allocation only here; we do
8427 * this prior to all the other checks so that we can bail out if the
8428 * allocation did not change
8430 clutter_actor_update_constraints (self, &real_allocation);
8432 /* adjust the allocation depending on the align/margin properties */
8433 clutter_actor_adjust_allocation (self, &real_allocation);
8435 if (real_allocation.x2 < real_allocation.x1 ||
8436 real_allocation.y2 < real_allocation.y1)
8438 g_warning (G_STRLOC ": Actor '%s' tried to allocate a size of %.2f x %.2f",
8439 _clutter_actor_get_debug_name (self),
8440 real_allocation.x2 - real_allocation.x1,
8441 real_allocation.y2 - real_allocation.y1);
8444 /* we allow 0-sized actors, but not negative-sized ones */
8445 real_allocation.x2 = MAX (real_allocation.x2, real_allocation.x1);
8446 real_allocation.y2 = MAX (real_allocation.y2, real_allocation.y1);
8448 origin_changed = (flags & CLUTTER_ABSOLUTE_ORIGIN_CHANGED);
8450 child_moved = (real_allocation.x1 != old_allocation.x1 ||
8451 real_allocation.y1 != old_allocation.y1);
8453 size_changed = (real_allocation.x2 != old_allocation.x2 ||
8454 real_allocation.y2 != old_allocation.y2);
8456 if (origin_changed || child_moved || size_changed)
8457 stage_allocation_changed = TRUE;
8459 stage_allocation_changed = FALSE;
8461 /* If we get an allocation "out of the blue"
8462 * (we did not queue relayout), then we want to
8463 * ignore it. But if we have needs_allocation set,
8464 * we want to guarantee that allocate() virtual
8465 * method is always called, i.e. that queue_relayout()
8466 * always results in an allocate() invocation on
8469 * The optimization here is to avoid re-allocating
8470 * actors that did not queue relayout and were
8473 if (!priv->needs_allocation && !stage_allocation_changed)
8475 CLUTTER_NOTE (LAYOUT, "No allocation needed");
8479 /* When ABSOLUTE_ORIGIN_CHANGED is passed in to
8480 * clutter_actor_allocate(), it indicates whether the parent has its
8481 * absolute origin moved; when passed in to ClutterActor::allocate()
8482 * virtual method though, it indicates whether the child has its
8483 * absolute origin moved. So we set it when child_moved is TRUE
8486 flags |= CLUTTER_ABSOLUTE_ORIGIN_CHANGED;
8488 CLUTTER_SET_PRIVATE_FLAGS (self, CLUTTER_IN_RELAYOUT);
8490 CLUTTER_NOTE (LAYOUT, "Calling %s::allocate()",
8491 _clutter_actor_get_debug_name (self));
8493 klass = CLUTTER_ACTOR_GET_CLASS (self);
8494 klass->allocate (self, &real_allocation, flags);
8496 CLUTTER_UNSET_PRIVATE_FLAGS (self, CLUTTER_IN_RELAYOUT);
8498 if (stage_allocation_changed)
8499 clutter_actor_queue_redraw (self);
8503 * clutter_actor_set_allocation:
8504 * @self: a #ClutterActor
8505 * @box: a #ClutterActorBox
8506 * @flags: allocation flags
8508 * Stores the allocation of @self as defined by @box.
8510 * This function can only be called from within the implementation of
8511 * the #ClutterActorClass.allocate() virtual function.
8513 * The allocation should have been adjusted to take into account constraints,
8514 * alignment, and margin properties. If you are implementing a #ClutterActor
8515 * subclass that provides its own layout management policy for its children
8516 * instead of using a #ClutterLayoutManager delegate, you should not call
8517 * this function on the children of @self; instead, you should call
8518 * clutter_actor_allocate(), which will adjust the allocation box for
8521 * This function should only be used by subclasses of #ClutterActor
8522 * that wish to store their allocation but cannot chain up to the
8523 * parent's implementation; the default implementation of the
8524 * #ClutterActorClass.allocate() virtual function will call this
8527 * It is important to note that, while chaining up was the recommended
8528 * behaviour for #ClutterActor subclasses prior to the introduction of
8529 * this function, it is recommended to call clutter_actor_set_allocation()
8532 * If the #ClutterActor is using a #ClutterLayoutManager delegate object
8533 * to handle the allocation of its children, this function will call
8534 * the clutter_layout_manager_allocate() function only if the
8535 * %CLUTTER_DELEGATE_LAYOUT flag is set on @flags, otherwise it is
8536 * expected that the subclass will call clutter_layout_manager_allocate()
8537 * by itself. For instance, the following code:
8541 * my_actor_allocate (ClutterActor *actor,
8542 * const ClutterActorBox *allocation,
8543 * ClutterAllocationFlags flags)
8545 * ClutterActorBox new_alloc;
8546 * ClutterAllocationFlags new_flags;
8548 * adjust_allocation (allocation, &new_alloc);
8550 * new_flags = flags | CLUTTER_DELEGATE_LAYOUT;
8552 * /* this will use the layout manager set on the actor */
8553 * clutter_actor_set_allocation (actor, &new_alloc, new_flags);
8557 * is equivalent to this:
8561 * my_actor_allocate (ClutterActor *actor,
8562 * const ClutterActorBox *allocation,
8563 * ClutterAllocationFlags flags)
8565 * ClutterLayoutManager *layout;
8566 * ClutterActorBox new_alloc;
8568 * adjust_allocation (allocation, &new_alloc);
8570 * clutter_actor_set_allocation (actor, &new_alloc, flags);
8572 * layout = clutter_actor_get_layout_manager (actor);
8573 * clutter_layout_manager_allocate (layout,
8574 * CLUTTER_CONTAINER (actor),
8583 clutter_actor_set_allocation (ClutterActor *self,
8584 const ClutterActorBox *box,
8585 ClutterAllocationFlags flags)
8587 ClutterActorPrivate *priv;
8590 g_return_if_fail (CLUTTER_IS_ACTOR (self));
8591 g_return_if_fail (box != NULL);
8593 if (G_UNLIKELY (!CLUTTER_ACTOR_IN_RELAYOUT (self)))
8595 g_critical (G_STRLOC ": The clutter_actor_set_allocation() function "
8596 "can only be called from within the implementation of "
8597 "the ClutterActor::allocate() virtual function.");
8603 g_object_freeze_notify (G_OBJECT (self));
8605 changed = clutter_actor_set_allocation_internal (self, box, flags);
8607 /* we allocate our children before we notify changes in our geometry,
8608 * so that people connecting to properties will be able to get valid
8609 * data out of the sub-tree of the scene graph that has this actor at
8612 clutter_actor_maybe_layout_children (self, box, flags);
8616 ClutterActorBox signal_box = priv->allocation;
8617 ClutterAllocationFlags signal_flags = priv->allocation_flags;
8619 g_signal_emit (self, actor_signals[ALLOCATION_CHANGED], 0,
8624 g_object_thaw_notify (G_OBJECT (self));
8628 * clutter_actor_set_geometry:
8629 * @self: A #ClutterActor
8630 * @geometry: A #ClutterGeometry
8632 * Sets the actor's fixed position and forces its minimum and natural
8633 * size, in pixels. This means the untransformed actor will have the
8634 * given geometry. This is the same as calling clutter_actor_set_position()
8635 * and clutter_actor_set_size().
8637 * Deprecated: 1.10: Use clutter_actor_set_position() and
8638 * clutter_actor_set_size() instead.
8641 clutter_actor_set_geometry (ClutterActor *self,
8642 const ClutterGeometry *geometry)
8644 g_object_freeze_notify (G_OBJECT (self));
8646 clutter_actor_set_position (self, geometry->x, geometry->y);
8647 clutter_actor_set_size (self, geometry->width, geometry->height);
8649 g_object_thaw_notify (G_OBJECT (self));
8653 * clutter_actor_get_geometry:
8654 * @self: A #ClutterActor
8655 * @geometry: (out caller-allocates): A location to store actors #ClutterGeometry
8657 * Gets the size and position of an actor relative to its parent
8658 * actor. This is the same as calling clutter_actor_get_position() and
8659 * clutter_actor_get_size(). It tries to "do what you mean" and get the
8660 * requested size and position if the actor's allocation is invalid.
8662 * Deprecated: 1.10: Use clutter_actor_get_position() and
8663 * clutter_actor_get_size(), or clutter_actor_get_allocation_geometry()
8667 clutter_actor_get_geometry (ClutterActor *self,
8668 ClutterGeometry *geometry)
8670 gfloat x, y, width, height;
8672 g_return_if_fail (CLUTTER_IS_ACTOR (self));
8673 g_return_if_fail (geometry != NULL);
8675 clutter_actor_get_position (self, &x, &y);
8676 clutter_actor_get_size (self, &width, &height);
8678 geometry->x = (int) x;
8679 geometry->y = (int) y;
8680 geometry->width = (int) width;
8681 geometry->height = (int) height;
8685 * clutter_actor_set_position:
8686 * @self: A #ClutterActor
8687 * @x: New left position of actor in pixels.
8688 * @y: New top position of actor in pixels.
8690 * Sets the actor's fixed position in pixels relative to any parent
8693 * If a layout manager is in use, this position will override the
8694 * layout manager and force a fixed position.
8697 clutter_actor_set_position (ClutterActor *self,
8701 g_return_if_fail (CLUTTER_IS_ACTOR (self));
8703 g_object_freeze_notify (G_OBJECT (self));
8705 clutter_actor_set_x (self, x);
8706 clutter_actor_set_y (self, y);
8708 g_object_thaw_notify (G_OBJECT (self));
8712 * clutter_actor_get_fixed_position_set:
8713 * @self: A #ClutterActor
8715 * Checks whether an actor has a fixed position set (and will thus be
8716 * unaffected by any layout manager).
8718 * Return value: %TRUE if the fixed position is set on the actor
8723 clutter_actor_get_fixed_position_set (ClutterActor *self)
8725 g_return_val_if_fail (CLUTTER_IS_ACTOR (self), FALSE);
8727 return self->priv->position_set;
8731 * clutter_actor_set_fixed_position_set:
8732 * @self: A #ClutterActor
8733 * @is_set: whether to use fixed position
8735 * Sets whether an actor has a fixed position set (and will thus be
8736 * unaffected by any layout manager).
8741 clutter_actor_set_fixed_position_set (ClutterActor *self,
8744 g_return_if_fail (CLUTTER_IS_ACTOR (self));
8746 if (self->priv->position_set == (is_set != FALSE))
8749 self->priv->position_set = is_set != FALSE;
8750 g_object_notify_by_pspec (G_OBJECT (self), obj_props[PROP_FIXED_POSITION_SET]);
8752 clutter_actor_queue_relayout (self);
8756 * clutter_actor_move_by:
8757 * @self: A #ClutterActor
8758 * @dx: Distance to move Actor on X axis.
8759 * @dy: Distance to move Actor on Y axis.
8761 * Moves an actor by the specified distance relative to its current
8762 * position in pixels.
8764 * This function modifies the fixed position of an actor and thus removes
8765 * it from any layout management. Another way to move an actor is with an
8766 * anchor point, see clutter_actor_set_anchor_point().
8771 clutter_actor_move_by (ClutterActor *self,
8775 const ClutterLayoutInfo *info;
8778 g_return_if_fail (CLUTTER_IS_ACTOR (self));
8780 info = _clutter_actor_get_layout_info_or_defaults (self);
8784 clutter_actor_set_position (self, x + dx, y + dy);
8788 clutter_actor_set_min_width (ClutterActor *self,
8791 ClutterActorPrivate *priv = self->priv;
8792 ClutterActorBox old = { 0, };
8793 ClutterLayoutInfo *info;
8795 /* if we are setting the size on a top-level actor and the
8796 * backend only supports static top-levels (e.g. framebuffers)
8797 * then we ignore the passed value and we override it with
8798 * the stage implementation's preferred size.
8800 if (CLUTTER_ACTOR_IS_TOPLEVEL (self) &&
8801 clutter_feature_available (CLUTTER_FEATURE_STAGE_STATIC))
8804 info = _clutter_actor_get_layout_info (self);
8806 if (priv->min_width_set && min_width == info->min_width)
8809 g_object_freeze_notify (G_OBJECT (self));
8811 clutter_actor_store_old_geometry (self, &old);
8813 info->min_width = min_width;
8814 g_object_notify_by_pspec (G_OBJECT (self), obj_props[PROP_MIN_WIDTH]);
8815 clutter_actor_set_min_width_set (self, TRUE);
8817 clutter_actor_notify_if_geometry_changed (self, &old);
8819 g_object_thaw_notify (G_OBJECT (self));
8821 clutter_actor_queue_relayout (self);
8825 clutter_actor_set_min_height (ClutterActor *self,
8829 ClutterActorPrivate *priv = self->priv;
8830 ClutterActorBox old = { 0, };
8831 ClutterLayoutInfo *info;
8833 /* if we are setting the size on a top-level actor and the
8834 * backend only supports static top-levels (e.g. framebuffers)
8835 * then we ignore the passed value and we override it with
8836 * the stage implementation's preferred size.
8838 if (CLUTTER_ACTOR_IS_TOPLEVEL (self) &&
8839 clutter_feature_available (CLUTTER_FEATURE_STAGE_STATIC))
8842 info = _clutter_actor_get_layout_info (self);
8844 if (priv->min_height_set && min_height == info->min_height)
8847 g_object_freeze_notify (G_OBJECT (self));
8849 clutter_actor_store_old_geometry (self, &old);
8851 info->min_height = min_height;
8852 g_object_notify_by_pspec (G_OBJECT (self), obj_props[PROP_MIN_HEIGHT]);
8853 clutter_actor_set_min_height_set (self, TRUE);
8855 clutter_actor_notify_if_geometry_changed (self, &old);
8857 g_object_thaw_notify (G_OBJECT (self));
8859 clutter_actor_queue_relayout (self);
8863 clutter_actor_set_natural_width (ClutterActor *self,
8864 gfloat natural_width)
8866 ClutterActorPrivate *priv = self->priv;
8867 ClutterActorBox old = { 0, };
8868 ClutterLayoutInfo *info;
8870 /* if we are setting the size on a top-level actor and the
8871 * backend only supports static top-levels (e.g. framebuffers)
8872 * then we ignore the passed value and we override it with
8873 * the stage implementation's preferred size.
8875 if (CLUTTER_ACTOR_IS_TOPLEVEL (self) &&
8876 clutter_feature_available (CLUTTER_FEATURE_STAGE_STATIC))
8879 info = _clutter_actor_get_layout_info (self);
8881 if (priv->natural_width_set && natural_width == info->natural_width)
8884 g_object_freeze_notify (G_OBJECT (self));
8886 clutter_actor_store_old_geometry (self, &old);
8888 info->natural_width = natural_width;
8889 g_object_notify_by_pspec (G_OBJECT (self), obj_props[PROP_NATURAL_WIDTH]);
8890 clutter_actor_set_natural_width_set (self, TRUE);
8892 clutter_actor_notify_if_geometry_changed (self, &old);
8894 g_object_thaw_notify (G_OBJECT (self));
8896 clutter_actor_queue_relayout (self);
8900 clutter_actor_set_natural_height (ClutterActor *self,
8901 gfloat natural_height)
8903 ClutterActorPrivate *priv = self->priv;
8904 ClutterActorBox old = { 0, };
8905 ClutterLayoutInfo *info;
8907 /* if we are setting the size on a top-level actor and the
8908 * backend only supports static top-levels (e.g. framebuffers)
8909 * then we ignore the passed value and we override it with
8910 * the stage implementation's preferred size.
8912 if (CLUTTER_ACTOR_IS_TOPLEVEL (self) &&
8913 clutter_feature_available (CLUTTER_FEATURE_STAGE_STATIC))
8916 info = _clutter_actor_get_layout_info (self);
8918 if (priv->natural_height_set && natural_height == info->natural_height)
8921 g_object_freeze_notify (G_OBJECT (self));
8923 clutter_actor_store_old_geometry (self, &old);
8925 info->natural_height = natural_height;
8926 g_object_notify_by_pspec (G_OBJECT (self), obj_props[PROP_NATURAL_HEIGHT]);
8927 clutter_actor_set_natural_height_set (self, TRUE);
8929 clutter_actor_notify_if_geometry_changed (self, &old);
8931 g_object_thaw_notify (G_OBJECT (self));
8933 clutter_actor_queue_relayout (self);
8937 clutter_actor_set_min_width_set (ClutterActor *self,
8938 gboolean use_min_width)
8940 ClutterActorPrivate *priv = self->priv;
8941 ClutterActorBox old = { 0, };
8943 if (priv->min_width_set == (use_min_width != FALSE))
8946 clutter_actor_store_old_geometry (self, &old);
8948 priv->min_width_set = use_min_width != FALSE;
8949 g_object_notify_by_pspec (G_OBJECT (self), obj_props[PROP_MIN_WIDTH_SET]);
8951 clutter_actor_notify_if_geometry_changed (self, &old);
8953 clutter_actor_queue_relayout (self);
8957 clutter_actor_set_min_height_set (ClutterActor *self,
8958 gboolean use_min_height)
8960 ClutterActorPrivate *priv = self->priv;
8961 ClutterActorBox old = { 0, };
8963 if (priv->min_height_set == (use_min_height != FALSE))
8966 clutter_actor_store_old_geometry (self, &old);
8968 priv->min_height_set = use_min_height != FALSE;
8969 g_object_notify_by_pspec (G_OBJECT (self), obj_props[PROP_MIN_HEIGHT_SET]);
8971 clutter_actor_notify_if_geometry_changed (self, &old);
8973 clutter_actor_queue_relayout (self);
8977 clutter_actor_set_natural_width_set (ClutterActor *self,
8978 gboolean use_natural_width)
8980 ClutterActorPrivate *priv = self->priv;
8981 ClutterActorBox old = { 0, };
8983 if (priv->natural_width_set == (use_natural_width != FALSE))
8986 clutter_actor_store_old_geometry (self, &old);
8988 priv->natural_width_set = use_natural_width != FALSE;
8989 g_object_notify_by_pspec (G_OBJECT (self), obj_props[PROP_NATURAL_WIDTH_SET]);
8991 clutter_actor_notify_if_geometry_changed (self, &old);
8993 clutter_actor_queue_relayout (self);
8997 clutter_actor_set_natural_height_set (ClutterActor *self,
8998 gboolean use_natural_height)
9000 ClutterActorPrivate *priv = self->priv;
9001 ClutterActorBox old = { 0, };
9003 if (priv->natural_height_set == (use_natural_height != FALSE))
9006 clutter_actor_store_old_geometry (self, &old);
9008 priv->natural_height_set = use_natural_height != FALSE;
9009 g_object_notify_by_pspec (G_OBJECT (self), obj_props[PROP_NATURAL_HEIGHT_SET]);
9011 clutter_actor_notify_if_geometry_changed (self, &old);
9013 clutter_actor_queue_relayout (self);
9017 * clutter_actor_set_request_mode:
9018 * @self: a #ClutterActor
9019 * @mode: the request mode
9021 * Sets the geometry request mode of @self.
9023 * The @mode determines the order for invoking
9024 * clutter_actor_get_preferred_width() and
9025 * clutter_actor_get_preferred_height()
9030 clutter_actor_set_request_mode (ClutterActor *self,
9031 ClutterRequestMode mode)
9033 ClutterActorPrivate *priv;
9035 g_return_if_fail (CLUTTER_IS_ACTOR (self));
9039 if (priv->request_mode == mode)
9042 priv->request_mode = mode;
9044 priv->needs_width_request = TRUE;
9045 priv->needs_height_request = TRUE;
9047 g_object_notify_by_pspec (G_OBJECT (self), obj_props[PROP_REQUEST_MODE]);
9049 clutter_actor_queue_relayout (self);
9053 * clutter_actor_get_request_mode:
9054 * @self: a #ClutterActor
9056 * Retrieves the geometry request mode of @self
9058 * Return value: the request mode for the actor
9063 clutter_actor_get_request_mode (ClutterActor *self)
9065 g_return_val_if_fail (CLUTTER_IS_ACTOR (self),
9066 CLUTTER_REQUEST_HEIGHT_FOR_WIDTH);
9068 return self->priv->request_mode;
9071 /* variant of set_width() without checks and without notification
9072 * freeze+thaw, for internal usage only
9075 clutter_actor_set_width_internal (ClutterActor *self,
9080 /* the Stage will use the :min-width to control the minimum
9081 * width to be resized to, so we should not be setting it
9082 * along with the :natural-width
9084 if (!CLUTTER_ACTOR_IS_TOPLEVEL (self))
9085 clutter_actor_set_min_width (self, width);
9087 clutter_actor_set_natural_width (self, width);
9091 /* we only unset the :natural-width for the Stage */
9092 if (!CLUTTER_ACTOR_IS_TOPLEVEL (self))
9093 clutter_actor_set_min_width_set (self, FALSE);
9095 clutter_actor_set_natural_width_set (self, FALSE);
9099 /* variant of set_height() without checks and without notification
9100 * freeze+thaw, for internal usage only
9103 clutter_actor_set_height_internal (ClutterActor *self,
9108 /* see the comment above in set_width_internal() */
9109 if (!CLUTTER_ACTOR_IS_TOPLEVEL (self))
9110 clutter_actor_set_min_height (self, height);
9112 clutter_actor_set_natural_height (self, height);
9116 /* see the comment above in set_width_internal() */
9117 if (!CLUTTER_ACTOR_IS_TOPLEVEL (self))
9118 clutter_actor_set_min_height_set (self, FALSE);
9120 clutter_actor_set_natural_height_set (self, FALSE);
9125 * clutter_actor_set_size:
9126 * @self: A #ClutterActor
9127 * @width: New width of actor in pixels, or -1
9128 * @height: New height of actor in pixels, or -1
9130 * Sets the actor's size request in pixels. This overrides any
9131 * "normal" size request the actor would have. For example
9132 * a text actor might normally request the size of the text;
9133 * this function would force a specific size instead.
9135 * If @width and/or @height are -1 the actor will use its
9136 * "normal" size request instead of overriding it, i.e.
9137 * you can "unset" the size with -1.
9139 * This function sets or unsets both the minimum and natural size.
9142 clutter_actor_set_size (ClutterActor *self,
9146 g_return_if_fail (CLUTTER_IS_ACTOR (self));
9148 g_object_freeze_notify (G_OBJECT (self));
9150 clutter_actor_set_width (self, width);
9151 clutter_actor_set_height (self, height);
9153 g_object_thaw_notify (G_OBJECT (self));
9157 * clutter_actor_get_size:
9158 * @self: A #ClutterActor
9159 * @width: (out) (allow-none): return location for the width, or %NULL.
9160 * @height: (out) (allow-none): return location for the height, or %NULL.
9162 * This function tries to "do what you mean" and return
9163 * the size an actor will have. If the actor has a valid
9164 * allocation, the allocation will be returned; otherwise,
9165 * the actors natural size request will be returned.
9167 * If you care whether you get the request vs. the allocation, you
9168 * should probably call a different function like
9169 * clutter_actor_get_allocation_box() or
9170 * clutter_actor_get_preferred_width().
9175 clutter_actor_get_size (ClutterActor *self,
9179 g_return_if_fail (CLUTTER_IS_ACTOR (self));
9182 *width = clutter_actor_get_width (self);
9185 *height = clutter_actor_get_height (self);
9189 * clutter_actor_get_position:
9190 * @self: a #ClutterActor
9191 * @x: (out) (allow-none): return location for the X coordinate, or %NULL
9192 * @y: (out) (allow-none): return location for the Y coordinate, or %NULL
9194 * This function tries to "do what you mean" and tell you where the
9195 * actor is, prior to any transformations. Retrieves the fixed
9196 * position of an actor in pixels, if one has been set; otherwise, if
9197 * the allocation is valid, returns the actor's allocated position;
9198 * otherwise, returns 0,0.
9200 * The returned position is in pixels.
9205 clutter_actor_get_position (ClutterActor *self,
9209 g_return_if_fail (CLUTTER_IS_ACTOR (self));
9212 *x = clutter_actor_get_x (self);
9215 *y = clutter_actor_get_y (self);
9219 * clutter_actor_get_transformed_position:
9220 * @self: A #ClutterActor
9221 * @x: (out) (allow-none): return location for the X coordinate, or %NULL
9222 * @y: (out) (allow-none): return location for the Y coordinate, or %NULL
9224 * Gets the absolute position of an actor, in pixels relative to the stage.
9229 clutter_actor_get_transformed_position (ClutterActor *self,
9236 v1.x = v1.y = v1.z = 0;
9237 clutter_actor_apply_transform_to_point (self, &v1, &v2);
9247 * clutter_actor_get_transformed_size:
9248 * @self: A #ClutterActor
9249 * @width: (out) (allow-none): return location for the width, or %NULL
9250 * @height: (out) (allow-none): return location for the height, or %NULL
9252 * Gets the absolute size of an actor in pixels, taking into account the
9255 * If the actor has a valid allocation, the allocated size will be used.
9256 * If the actor has not a valid allocation then the preferred size will
9257 * be transformed and returned.
9259 * If you want the transformed allocation, see
9260 * clutter_actor_get_abs_allocation_vertices() instead.
9262 * <note>When the actor (or one of its ancestors) is rotated around the
9263 * X or Y axis, it no longer appears as on the stage as a rectangle, but
9264 * as a generic quadrangle; in that case this function returns the size
9265 * of the smallest rectangle that encapsulates the entire quad. Please
9266 * note that in this case no assumptions can be made about the relative
9267 * position of this envelope to the absolute position of the actor, as
9268 * returned by clutter_actor_get_transformed_position(); if you need this
9269 * information, you need to use clutter_actor_get_abs_allocation_vertices()
9270 * to get the coords of the actual quadrangle.</note>
9275 clutter_actor_get_transformed_size (ClutterActor *self,
9279 ClutterActorPrivate *priv;
9281 gfloat x_min, x_max, y_min, y_max;
9284 g_return_if_fail (CLUTTER_IS_ACTOR (self));
9288 /* if the actor hasn't been allocated yet, get the preferred
9289 * size and transform that
9291 if (priv->needs_allocation)
9293 gfloat natural_width, natural_height;
9294 ClutterActorBox box;
9296 /* Make a fake allocation to transform.
9298 * NB: _clutter_actor_transform_and_project_box expects a box in
9299 * the actor's coordinate space... */
9304 natural_width = natural_height = 0;
9305 clutter_actor_get_preferred_size (self, NULL, NULL,
9309 box.x2 = natural_width;
9310 box.y2 = natural_height;
9312 _clutter_actor_transform_and_project_box (self, &box, v);
9315 clutter_actor_get_abs_allocation_vertices (self, v);
9317 x_min = x_max = v[0].x;
9318 y_min = y_max = v[0].y;
9320 for (i = 1; i < G_N_ELEMENTS (v); ++i)
9336 *width = x_max - x_min;
9339 *height = y_max - y_min;
9343 * clutter_actor_get_width:
9344 * @self: A #ClutterActor
9346 * Retrieves the width of a #ClutterActor.
9348 * If the actor has a valid allocation, this function will return the
9349 * width of the allocated area given to the actor.
9351 * If the actor does not have a valid allocation, this function will
9352 * return the actor's natural width, that is the preferred width of
9355 * If you care whether you get the preferred width or the width that
9356 * has been assigned to the actor, you should probably call a different
9357 * function like clutter_actor_get_allocation_box() to retrieve the
9358 * allocated size or clutter_actor_get_preferred_width() to retrieve the
9361 * If an actor has a fixed width, for instance a width that has been
9362 * assigned using clutter_actor_set_width(), the width returned will
9363 * be the same value.
9365 * Return value: the width of the actor, in pixels
9368 clutter_actor_get_width (ClutterActor *self)
9370 ClutterActorPrivate *priv;
9372 g_return_val_if_fail (CLUTTER_IS_ACTOR (self), 0);
9376 if (priv->needs_allocation)
9378 gfloat natural_width = 0;
9380 if (self->priv->request_mode == CLUTTER_REQUEST_HEIGHT_FOR_WIDTH)
9381 clutter_actor_get_preferred_width (self, -1, NULL, &natural_width);
9384 gfloat natural_height = 0;
9386 clutter_actor_get_preferred_height (self, -1, NULL, &natural_height);
9387 clutter_actor_get_preferred_width (self, natural_height,
9392 return natural_width;
9395 return priv->allocation.x2 - priv->allocation.x1;
9399 * clutter_actor_get_height:
9400 * @self: A #ClutterActor
9402 * Retrieves the height of a #ClutterActor.
9404 * If the actor has a valid allocation, this function will return the
9405 * height of the allocated area given to the actor.
9407 * If the actor does not have a valid allocation, this function will
9408 * return the actor's natural height, that is the preferred height of
9411 * If you care whether you get the preferred height or the height that
9412 * has been assigned to the actor, you should probably call a different
9413 * function like clutter_actor_get_allocation_box() to retrieve the
9414 * allocated size or clutter_actor_get_preferred_height() to retrieve the
9417 * If an actor has a fixed height, for instance a height that has been
9418 * assigned using clutter_actor_set_height(), the height returned will
9419 * be the same value.
9421 * Return value: the height of the actor, in pixels
9424 clutter_actor_get_height (ClutterActor *self)
9426 ClutterActorPrivate *priv;
9428 g_return_val_if_fail (CLUTTER_IS_ACTOR (self), 0);
9432 if (priv->needs_allocation)
9434 gfloat natural_height = 0;
9436 if (priv->request_mode == CLUTTER_REQUEST_HEIGHT_FOR_WIDTH)
9438 gfloat natural_width = 0;
9440 clutter_actor_get_preferred_width (self, -1, NULL, &natural_width);
9441 clutter_actor_get_preferred_height (self, natural_width,
9442 NULL, &natural_height);
9445 clutter_actor_get_preferred_height (self, -1, NULL, &natural_height);
9447 return natural_height;
9450 return priv->allocation.y2 - priv->allocation.y1;
9454 * clutter_actor_set_width:
9455 * @self: A #ClutterActor
9456 * @width: Requested new width for the actor, in pixels, or -1
9458 * Forces a width on an actor, causing the actor's preferred width
9459 * and height (if any) to be ignored.
9461 * If @width is -1 the actor will use its preferred width request
9462 * instead of overriding it, i.e. you can "unset" the width with -1.
9464 * This function sets both the minimum and natural size of the actor.
9469 clutter_actor_set_width (ClutterActor *self,
9472 g_return_if_fail (CLUTTER_IS_ACTOR (self));
9474 if (_clutter_actor_get_transition (self, obj_props[PROP_WIDTH]) == NULL)
9476 float cur_size = clutter_actor_get_width (self);
9478 _clutter_actor_create_transition (self,
9479 obj_props[PROP_WIDTH],
9484 _clutter_actor_update_transition (self, obj_props[PROP_WIDTH], width);
9486 clutter_actor_queue_relayout (self);
9490 * clutter_actor_set_height:
9491 * @self: A #ClutterActor
9492 * @height: Requested new height for the actor, in pixels, or -1
9494 * Forces a height on an actor, causing the actor's preferred width
9495 * and height (if any) to be ignored.
9497 * If @height is -1 the actor will use its preferred height instead of
9498 * overriding it, i.e. you can "unset" the height with -1.
9500 * This function sets both the minimum and natural size of the actor.
9505 clutter_actor_set_height (ClutterActor *self,
9508 g_return_if_fail (CLUTTER_IS_ACTOR (self));
9510 if (_clutter_actor_get_transition (self, obj_props[PROP_HEIGHT]) == NULL)
9512 float cur_size = clutter_actor_get_height (self);
9514 _clutter_actor_create_transition (self,
9515 obj_props[PROP_HEIGHT],
9520 _clutter_actor_update_transition (self, obj_props[PROP_HEIGHT], height);
9522 clutter_actor_queue_relayout (self);
9526 clutter_actor_set_x_internal (ClutterActor *self,
9529 ClutterActorPrivate *priv = self->priv;
9530 ClutterLayoutInfo *linfo;
9531 ClutterActorBox old = { 0, };
9533 linfo = _clutter_actor_get_layout_info (self);
9535 if (priv->position_set && linfo->fixed_x == x)
9538 clutter_actor_store_old_geometry (self, &old);
9541 clutter_actor_set_fixed_position_set (self, TRUE);
9543 clutter_actor_notify_if_geometry_changed (self, &old);
9545 clutter_actor_queue_relayout (self);
9549 clutter_actor_set_y_internal (ClutterActor *self,
9552 ClutterActorPrivate *priv = self->priv;
9553 ClutterLayoutInfo *linfo;
9554 ClutterActorBox old = { 0, };
9556 linfo = _clutter_actor_get_layout_info (self);
9558 if (priv->position_set && linfo->fixed_y == y)
9561 clutter_actor_store_old_geometry (self, &old);
9564 clutter_actor_set_fixed_position_set (self, TRUE);
9566 clutter_actor_notify_if_geometry_changed (self, &old);
9568 clutter_actor_queue_relayout (self);
9572 * clutter_actor_set_x:
9573 * @self: a #ClutterActor
9574 * @x: the actor's position on the X axis
9576 * Sets the actor's X coordinate, relative to its parent, in pixels.
9578 * Overrides any layout manager and forces a fixed position for
9581 * The #ClutterActor:x property is animatable.
9586 clutter_actor_set_x (ClutterActor *self,
9589 g_return_if_fail (CLUTTER_IS_ACTOR (self));
9591 if (_clutter_actor_get_transition (self, obj_props[PROP_X]) == NULL)
9593 float cur_position = clutter_actor_get_x (self);
9595 _clutter_actor_create_transition (self, obj_props[PROP_X],
9600 _clutter_actor_update_transition (self, obj_props[PROP_X], x);
9602 clutter_actor_queue_relayout (self);
9606 * clutter_actor_set_y:
9607 * @self: a #ClutterActor
9608 * @y: the actor's position on the Y axis
9610 * Sets the actor's Y coordinate, relative to its parent, in pixels.#
9612 * Overrides any layout manager and forces a fixed position for
9615 * The #ClutterActor:y property is animatable.
9620 clutter_actor_set_y (ClutterActor *self,
9623 g_return_if_fail (CLUTTER_IS_ACTOR (self));
9625 if (_clutter_actor_get_transition (self, obj_props[PROP_Y]) == NULL)
9627 float cur_position = clutter_actor_get_y (self);
9629 _clutter_actor_create_transition (self, obj_props[PROP_Y],
9634 _clutter_actor_update_transition (self, obj_props[PROP_Y], y);
9636 clutter_actor_queue_relayout (self);
9640 * clutter_actor_get_x:
9641 * @self: A #ClutterActor
9643 * Retrieves the X coordinate of a #ClutterActor.
9645 * This function tries to "do what you mean", by returning the
9646 * correct value depending on the actor's state.
9648 * If the actor has a valid allocation, this function will return
9649 * the X coordinate of the origin of the allocation box.
9651 * If the actor has any fixed coordinate set using clutter_actor_set_x(),
9652 * clutter_actor_set_position() or clutter_actor_set_geometry(), this
9653 * function will return that coordinate.
9655 * If both the allocation and a fixed position are missing, this function
9658 * Return value: the X coordinate, in pixels, ignoring any
9659 * transformation (i.e. scaling, rotation)
9662 clutter_actor_get_x (ClutterActor *self)
9664 ClutterActorPrivate *priv;
9666 g_return_val_if_fail (CLUTTER_IS_ACTOR (self), 0);
9670 if (priv->needs_allocation)
9672 if (priv->position_set)
9674 const ClutterLayoutInfo *info;
9676 info = _clutter_actor_get_layout_info_or_defaults (self);
9678 return info->fixed_x;
9684 return priv->allocation.x1;
9688 * clutter_actor_get_y:
9689 * @self: A #ClutterActor
9691 * Retrieves the Y coordinate of a #ClutterActor.
9693 * This function tries to "do what you mean", by returning the
9694 * correct value depending on the actor's state.
9696 * If the actor has a valid allocation, this function will return
9697 * the Y coordinate of the origin of the allocation box.
9699 * If the actor has any fixed coordinate set using clutter_actor_set_y(),
9700 * clutter_actor_set_position() or clutter_actor_set_geometry(), this
9701 * function will return that coordinate.
9703 * If both the allocation and a fixed position are missing, this function
9706 * Return value: the Y coordinate, in pixels, ignoring any
9707 * transformation (i.e. scaling, rotation)
9710 clutter_actor_get_y (ClutterActor *self)
9712 ClutterActorPrivate *priv;
9714 g_return_val_if_fail (CLUTTER_IS_ACTOR (self), 0);
9718 if (priv->needs_allocation)
9720 if (priv->position_set)
9722 const ClutterLayoutInfo *info;
9724 info = _clutter_actor_get_layout_info_or_defaults (self);
9726 return info->fixed_y;
9732 return priv->allocation.y1;
9736 * clutter_actor_set_scale:
9737 * @self: A #ClutterActor
9738 * @scale_x: double factor to scale actor by horizontally.
9739 * @scale_y: double factor to scale actor by vertically.
9741 * Scales an actor with the given factors. The scaling is relative to
9742 * the scale center and the anchor point. The scale center is
9743 * unchanged by this function and defaults to 0,0.
9745 * The #ClutterActor:scale-x and #ClutterActor:scale-y properties are
9751 clutter_actor_set_scale (ClutterActor *self,
9755 g_return_if_fail (CLUTTER_IS_ACTOR (self));
9757 g_object_freeze_notify (G_OBJECT (self));
9759 clutter_actor_set_scale_factor (self, CLUTTER_X_AXIS, scale_x);
9760 clutter_actor_set_scale_factor (self, CLUTTER_Y_AXIS, scale_y);
9762 g_object_thaw_notify (G_OBJECT (self));
9766 * clutter_actor_set_scale_full:
9767 * @self: A #ClutterActor
9768 * @scale_x: double factor to scale actor by horizontally.
9769 * @scale_y: double factor to scale actor by vertically.
9770 * @center_x: X coordinate of the center of the scale.
9771 * @center_y: Y coordinate of the center of the scale
9773 * Scales an actor with the given factors around the given center
9774 * point. The center point is specified in pixels relative to the
9775 * anchor point (usually the top left corner of the actor).
9777 * The #ClutterActor:scale-x and #ClutterActor:scale-y properties
9783 clutter_actor_set_scale_full (ClutterActor *self,
9789 g_return_if_fail (CLUTTER_IS_ACTOR (self));
9791 g_object_freeze_notify (G_OBJECT (self));
9793 clutter_actor_set_scale_factor (self, CLUTTER_X_AXIS, scale_x);
9794 clutter_actor_set_scale_factor (self, CLUTTER_Y_AXIS, scale_y);
9795 clutter_actor_set_scale_center (self, CLUTTER_X_AXIS, center_x);
9796 clutter_actor_set_scale_center (self, CLUTTER_Y_AXIS, center_y);
9798 g_object_thaw_notify (G_OBJECT (self));
9802 * clutter_actor_set_scale_with_gravity:
9803 * @self: A #ClutterActor
9804 * @scale_x: double factor to scale actor by horizontally.
9805 * @scale_y: double factor to scale actor by vertically.
9806 * @gravity: the location of the scale center expressed as a compass
9809 * Scales an actor with the given factors around the given
9810 * center point. The center point is specified as one of the compass
9811 * directions in #ClutterGravity. For example, setting it to north
9812 * will cause the top of the actor to remain unchanged and the rest of
9813 * the actor to expand left, right and downwards.
9815 * The #ClutterActor:scale-x and #ClutterActor:scale-y properties are
9821 clutter_actor_set_scale_with_gravity (ClutterActor *self,
9824 ClutterGravity gravity)
9826 g_return_if_fail (CLUTTER_IS_ACTOR (self));
9828 g_object_freeze_notify (G_OBJECT (self));
9830 clutter_actor_set_scale_factor (self, CLUTTER_X_AXIS, scale_x);
9831 clutter_actor_set_scale_factor (self, CLUTTER_Y_AXIS, scale_y);
9832 clutter_actor_set_scale_gravity (self, gravity);
9834 g_object_thaw_notify (G_OBJECT (self));
9838 * clutter_actor_get_scale:
9839 * @self: A #ClutterActor
9840 * @scale_x: (out) (allow-none): Location to store horizonal
9841 * scale factor, or %NULL.
9842 * @scale_y: (out) (allow-none): Location to store vertical
9843 * scale factor, or %NULL.
9845 * Retrieves an actors scale factors.
9850 clutter_actor_get_scale (ClutterActor *self,
9854 const ClutterTransformInfo *info;
9856 g_return_if_fail (CLUTTER_IS_ACTOR (self));
9858 info = _clutter_actor_get_transform_info_or_defaults (self);
9861 *scale_x = info->scale_x;
9864 *scale_y = info->scale_y;
9868 * clutter_actor_get_scale_center:
9869 * @self: A #ClutterActor
9870 * @center_x: (out) (allow-none): Location to store the X position
9871 * of the scale center, or %NULL.
9872 * @center_y: (out) (allow-none): Location to store the Y position
9873 * of the scale center, or %NULL.
9875 * Retrieves the scale center coordinate in pixels relative to the top
9876 * left corner of the actor. If the scale center was specified using a
9877 * #ClutterGravity this will calculate the pixel offset using the
9878 * current size of the actor.
9883 clutter_actor_get_scale_center (ClutterActor *self,
9887 const ClutterTransformInfo *info;
9889 g_return_if_fail (CLUTTER_IS_ACTOR (self));
9891 info = _clutter_actor_get_transform_info_or_defaults (self);
9893 clutter_anchor_coord_get_units (self, &info->scale_center,
9900 * clutter_actor_get_scale_gravity:
9901 * @self: A #ClutterActor
9903 * Retrieves the scale center as a compass direction. If the scale
9904 * center was specified in pixels or units this will return
9905 * %CLUTTER_GRAVITY_NONE.
9907 * Return value: the scale gravity
9912 clutter_actor_get_scale_gravity (ClutterActor *self)
9914 const ClutterTransformInfo *info;
9916 g_return_val_if_fail (CLUTTER_IS_ACTOR (self), CLUTTER_GRAVITY_NONE);
9918 info = _clutter_actor_get_transform_info_or_defaults (self);
9920 return clutter_anchor_coord_get_gravity (&info->scale_center);
9924 clutter_actor_set_opacity_internal (ClutterActor *self,
9927 ClutterActorPrivate *priv = self->priv;
9929 if (priv->opacity != opacity)
9931 priv->opacity = opacity;
9933 /* Queue a redraw from the flatten effect so that it can use
9934 its cached image if available instead of having to redraw the
9935 actual actor. If it doesn't end up using the FBO then the
9936 effect is still able to continue the paint anyway. If there
9937 is no flatten effect yet then this is equivalent to queueing
9939 _clutter_actor_queue_redraw_full (self,
9942 priv->flatten_effect);
9944 g_object_notify_by_pspec (G_OBJECT (self), obj_props[PROP_OPACITY]);
9949 * clutter_actor_set_opacity:
9950 * @self: A #ClutterActor
9951 * @opacity: New opacity value for the actor.
9953 * Sets the actor's opacity, with zero being completely transparent and
9954 * 255 (0xff) being fully opaque.
9956 * The #ClutterActor:opacity property is animatable.
9959 clutter_actor_set_opacity (ClutterActor *self,
9962 g_return_if_fail (CLUTTER_IS_ACTOR (self));
9964 if (_clutter_actor_get_transition (self, obj_props[PROP_OPACITY]) == NULL)
9966 _clutter_actor_create_transition (self, obj_props[PROP_OPACITY],
9967 self->priv->opacity,
9971 _clutter_actor_update_transition (self, obj_props[PROP_OPACITY], opacity);
9973 clutter_actor_queue_redraw (self);
9977 * clutter_actor_get_paint_opacity_internal:
9978 * @self: a #ClutterActor
9980 * Retrieves the absolute opacity of the actor, as it appears on the stage
9982 * This function does not do type checks
9984 * Return value: the absolute opacity of the actor
9987 clutter_actor_get_paint_opacity_internal (ClutterActor *self)
9989 ClutterActorPrivate *priv = self->priv;
9990 ClutterActor *parent;
9992 /* override the top-level opacity to always be 255; even in
9993 * case of ClutterStage:use-alpha being TRUE we want the rest
9994 * of the scene to be painted
9996 if (CLUTTER_ACTOR_IS_TOPLEVEL (self))
9999 if (priv->opacity_override >= 0)
10000 return priv->opacity_override;
10002 parent = priv->parent;
10004 /* Factor in the actual actors opacity with parents */
10005 if (parent != NULL)
10007 guint8 opacity = clutter_actor_get_paint_opacity_internal (parent);
10009 if (opacity != 0xff)
10010 return (opacity * priv->opacity) / 0xff;
10013 return priv->opacity;
10018 * clutter_actor_get_paint_opacity:
10019 * @self: A #ClutterActor
10021 * Retrieves the absolute opacity of the actor, as it appears on the stage.
10023 * This function traverses the hierarchy chain and composites the opacity of
10024 * the actor with that of its parents.
10026 * This function is intended for subclasses to use in the paint virtual
10027 * function, to paint themselves with the correct opacity.
10029 * Return value: The actor opacity value.
10034 clutter_actor_get_paint_opacity (ClutterActor *self)
10036 g_return_val_if_fail (CLUTTER_IS_ACTOR (self), 0);
10038 return clutter_actor_get_paint_opacity_internal (self);
10042 * clutter_actor_get_opacity:
10043 * @self: a #ClutterActor
10045 * Retrieves the opacity value of an actor, as set by
10046 * clutter_actor_set_opacity().
10048 * For retrieving the absolute opacity of the actor inside a paint
10049 * virtual function, see clutter_actor_get_paint_opacity().
10051 * Return value: the opacity of the actor
10054 clutter_actor_get_opacity (ClutterActor *self)
10056 g_return_val_if_fail (CLUTTER_IS_ACTOR (self), 0);
10058 return self->priv->opacity;
10062 * clutter_actor_set_offscreen_redirect:
10063 * @self: A #ClutterActor
10064 * @redirect: New offscreen redirect flags for the actor.
10066 * Defines the circumstances where the actor should be redirected into
10067 * an offscreen image. The offscreen image is used to flatten the
10068 * actor into a single image while painting for two main reasons.
10069 * Firstly, when the actor is painted a second time without any of its
10070 * contents changing it can simply repaint the cached image without
10071 * descending further down the actor hierarchy. Secondly, it will make
10072 * the opacity look correct even if there are overlapping primitives
10075 * Caching the actor could in some cases be a performance win and in
10076 * some cases be a performance lose so it is important to determine
10077 * which value is right for an actor before modifying this value. For
10078 * example, there is never any reason to flatten an actor that is just
10079 * a single texture (such as a #ClutterTexture) because it is
10080 * effectively already cached in an image so the offscreen would be
10081 * redundant. Also if the actor contains primitives that are far apart
10082 * with a large transparent area in the middle (such as a large
10083 * CluterGroup with a small actor in the top left and a small actor in
10084 * the bottom right) then the cached image will contain the entire
10085 * image of the large area and the paint will waste time blending all
10086 * of the transparent pixels in the middle.
10088 * The default method of implementing opacity on a container simply
10089 * forwards on the opacity to all of the children. If the children are
10090 * overlapping then it will appear as if they are two separate glassy
10091 * objects and there will be a break in the color where they
10092 * overlap. By redirecting to an offscreen buffer it will be as if the
10093 * two opaque objects are combined into one and then made transparent
10094 * which is usually what is expected.
10096 * The image below demonstrates the difference between redirecting and
10097 * not. The image shows two Clutter groups, each containing a red and
10098 * a green rectangle which overlap. The opacity on the group is set to
10099 * 128 (which is 50%). When the offscreen redirect is not used, the
10100 * red rectangle can be seen through the blue rectangle as if the two
10101 * rectangles were separately transparent. When the redirect is used
10102 * the group as a whole is transparent instead so the red rectangle is
10103 * not visible where they overlap.
10105 * <figure id="offscreen-redirect">
10106 * <title>Sample of using an offscreen redirect for transparency</title>
10107 * <graphic fileref="offscreen-redirect.png" format="PNG"/>
10110 * The default value for this property is 0, so we effectively will
10111 * never redirect an actor offscreen by default. This means that there
10112 * are times that transparent actors may look glassy as described
10113 * above. The reason this is the default is because there is a
10114 * performance trade off between quality and performance here. In many
10115 * cases the default form of glassy opacity looks good enough, but if
10116 * it's not you will need to set the
10117 * %CLUTTER_OFFSCREEN_REDIRECT_AUTOMATIC_FOR_OPACITY flag to enable
10118 * redirection for opacity.
10120 * Custom actors that don't contain any overlapping primitives are
10121 * recommended to override the has_overlaps() virtual to return %FALSE
10122 * for maximum efficiency.
10127 clutter_actor_set_offscreen_redirect (ClutterActor *self,
10128 ClutterOffscreenRedirect redirect)
10130 ClutterActorPrivate *priv;
10132 g_return_if_fail (CLUTTER_IS_ACTOR (self));
10136 if (priv->offscreen_redirect != redirect)
10138 priv->offscreen_redirect = redirect;
10140 /* Queue a redraw from the effect so that it can use its cached
10141 image if available instead of having to redraw the actual
10142 actor. If it doesn't end up using the FBO then the effect is
10143 still able to continue the paint anyway. If there is no
10144 effect then this is equivalent to queuing a full redraw */
10145 _clutter_actor_queue_redraw_full (self,
10148 priv->flatten_effect);
10150 g_object_notify_by_pspec (G_OBJECT (self),
10151 obj_props[PROP_OFFSCREEN_REDIRECT]);
10156 * clutter_actor_get_offscreen_redirect:
10157 * @self: a #ClutterActor
10159 * Retrieves whether to redirect the actor to an offscreen buffer, as
10160 * set by clutter_actor_set_offscreen_redirect().
10162 * Return value: the value of the offscreen-redirect property of the actor
10166 ClutterOffscreenRedirect
10167 clutter_actor_get_offscreen_redirect (ClutterActor *self)
10169 g_return_val_if_fail (CLUTTER_IS_ACTOR (self), 0);
10171 return self->priv->offscreen_redirect;
10175 * clutter_actor_set_name:
10176 * @self: A #ClutterActor
10177 * @name: Textual tag to apply to actor
10179 * Sets the given name to @self. The name can be used to identify
10183 clutter_actor_set_name (ClutterActor *self,
10186 g_return_if_fail (CLUTTER_IS_ACTOR (self));
10188 g_free (self->priv->name);
10189 self->priv->name = g_strdup (name);
10191 g_object_notify_by_pspec (G_OBJECT (self), obj_props[PROP_NAME]);
10195 * clutter_actor_get_name:
10196 * @self: A #ClutterActor
10198 * Retrieves the name of @self.
10200 * Return value: the name of the actor, or %NULL. The returned string is
10201 * owned by the actor and should not be modified or freed.
10204 clutter_actor_get_name (ClutterActor *self)
10206 g_return_val_if_fail (CLUTTER_IS_ACTOR (self), NULL);
10208 return self->priv->name;
10212 * clutter_actor_get_gid:
10213 * @self: A #ClutterActor
10215 * Retrieves the unique id for @self.
10217 * Return value: Globally unique value for this object instance.
10221 * Deprecated: 1.8: The id is not used any longer.
10224 clutter_actor_get_gid (ClutterActor *self)
10226 g_return_val_if_fail (CLUTTER_IS_ACTOR (self), 0);
10228 return self->priv->id;
10232 clutter_actor_set_depth_internal (ClutterActor *self,
10235 ClutterTransformInfo *info;
10237 info = _clutter_actor_get_transform_info (self);
10239 if (info->depth != depth)
10241 /* Sets Z value - XXX 2.0: should we invert? */
10242 info->depth = depth;
10244 self->priv->transform_valid = FALSE;
10246 /* FIXME - remove this crap; sadly, there are still containers
10247 * in Clutter that depend on this utter brain damage
10249 clutter_container_sort_depth_order (CLUTTER_CONTAINER (self));
10251 clutter_actor_queue_redraw (self);
10253 g_object_notify_by_pspec (G_OBJECT (self), obj_props[PROP_DEPTH]);
10258 * clutter_actor_set_depth:
10259 * @self: a #ClutterActor
10262 * Sets the Z coordinate of @self to @depth.
10264 * The unit used by @depth is dependant on the perspective setup. See
10265 * also clutter_stage_set_perspective().
10268 clutter_actor_set_depth (ClutterActor *self,
10271 g_return_if_fail (CLUTTER_IS_ACTOR (self));
10273 if (_clutter_actor_get_transition (self, obj_props[PROP_DEPTH]) == NULL)
10275 const ClutterTransformInfo *info;
10277 info = _clutter_actor_get_transform_info_or_defaults (self);
10279 _clutter_actor_create_transition (self, obj_props[PROP_DEPTH],
10284 _clutter_actor_update_transition (self, obj_props[PROP_DEPTH], depth);
10286 clutter_actor_queue_redraw (self);
10290 * clutter_actor_get_depth:
10291 * @self: a #ClutterActor
10293 * Retrieves the depth of @self.
10295 * Return value: the depth of the actor
10298 clutter_actor_get_depth (ClutterActor *self)
10300 g_return_val_if_fail (CLUTTER_IS_ACTOR (self), 0.0);
10302 return _clutter_actor_get_transform_info_or_defaults (self)->depth;
10306 * clutter_actor_set_rotation:
10307 * @self: a #ClutterActor
10308 * @axis: the axis of rotation
10309 * @angle: the angle of rotation
10310 * @x: X coordinate of the rotation center
10311 * @y: Y coordinate of the rotation center
10312 * @z: Z coordinate of the rotation center
10314 * Sets the rotation angle of @self around the given axis.
10316 * The rotation center coordinates used depend on the value of @axis:
10318 * <listitem><para>%CLUTTER_X_AXIS requires @y and @z</para></listitem>
10319 * <listitem><para>%CLUTTER_Y_AXIS requires @x and @z</para></listitem>
10320 * <listitem><para>%CLUTTER_Z_AXIS requires @x and @y</para></listitem>
10323 * The rotation coordinates are relative to the anchor point of the
10324 * actor, set using clutter_actor_set_anchor_point(). If no anchor
10325 * point is set, the upper left corner is assumed as the origin.
10330 clutter_actor_set_rotation (ClutterActor *self,
10331 ClutterRotateAxis axis,
10339 g_return_if_fail (CLUTTER_IS_ACTOR (self));
10345 g_object_freeze_notify (G_OBJECT (self));
10347 clutter_actor_set_rotation_angle (self, axis, angle);
10348 clutter_actor_set_rotation_center_internal (self, axis, &v);
10350 g_object_thaw_notify (G_OBJECT (self));
10354 * clutter_actor_set_z_rotation_from_gravity:
10355 * @self: a #ClutterActor
10356 * @angle: the angle of rotation
10357 * @gravity: the center point of the rotation
10359 * Sets the rotation angle of @self around the Z axis using the center
10360 * point specified as a compass point. For example to rotate such that
10361 * the center of the actor remains static you can use
10362 * %CLUTTER_GRAVITY_CENTER. If the actor changes size the center point
10363 * will move accordingly.
10368 clutter_actor_set_z_rotation_from_gravity (ClutterActor *self,
10370 ClutterGravity gravity)
10372 g_return_if_fail (CLUTTER_IS_ACTOR (self));
10374 if (gravity == CLUTTER_GRAVITY_NONE)
10375 clutter_actor_set_rotation (self, CLUTTER_Z_AXIS, angle, 0, 0, 0);
10378 GObject *obj = G_OBJECT (self);
10379 ClutterTransformInfo *info;
10381 info = _clutter_actor_get_transform_info (self);
10383 g_object_freeze_notify (obj);
10385 clutter_actor_set_rotation_angle_internal (self, CLUTTER_Z_AXIS, angle);
10387 clutter_anchor_coord_set_gravity (&info->rz_center, gravity);
10388 g_object_notify_by_pspec (obj, obj_props[PROP_ROTATION_CENTER_Z_GRAVITY]);
10389 g_object_notify_by_pspec (obj, obj_props[PROP_ROTATION_CENTER_Z]);
10391 g_object_thaw_notify (obj);
10396 * clutter_actor_get_rotation:
10397 * @self: a #ClutterActor
10398 * @axis: the axis of rotation
10399 * @x: (out): return value for the X coordinate of the center of rotation
10400 * @y: (out): return value for the Y coordinate of the center of rotation
10401 * @z: (out): return value for the Z coordinate of the center of rotation
10403 * Retrieves the angle and center of rotation on the given axis,
10404 * set using clutter_actor_set_rotation().
10406 * Return value: the angle of rotation
10411 clutter_actor_get_rotation (ClutterActor *self,
10412 ClutterRotateAxis axis,
10417 const ClutterTransformInfo *info;
10418 const AnchorCoord *anchor_coord;
10419 gdouble retval = 0;
10421 g_return_val_if_fail (CLUTTER_IS_ACTOR (self), 0);
10423 info = _clutter_actor_get_transform_info_or_defaults (self);
10427 case CLUTTER_X_AXIS:
10428 anchor_coord = &info->rx_center;
10429 retval = info->rx_angle;
10432 case CLUTTER_Y_AXIS:
10433 anchor_coord = &info->ry_center;
10434 retval = info->ry_angle;
10437 case CLUTTER_Z_AXIS:
10438 anchor_coord = &info->rz_center;
10439 retval = info->rz_angle;
10443 anchor_coord = NULL;
10448 clutter_anchor_coord_get_units (self, anchor_coord, x, y, z);
10454 * clutter_actor_get_z_rotation_gravity:
10455 * @self: A #ClutterActor
10457 * Retrieves the center for the rotation around the Z axis as a
10458 * compass direction. If the center was specified in pixels or units
10459 * this will return %CLUTTER_GRAVITY_NONE.
10461 * Return value: the Z rotation center
10466 clutter_actor_get_z_rotation_gravity (ClutterActor *self)
10468 const ClutterTransformInfo *info;
10470 g_return_val_if_fail (CLUTTER_IS_ACTOR (self), 0.0);
10472 info = _clutter_actor_get_transform_info_or_defaults (self);
10474 return clutter_anchor_coord_get_gravity (&info->rz_center);
10478 * clutter_actor_set_clip:
10479 * @self: A #ClutterActor
10480 * @xoff: X offset of the clip rectangle
10481 * @yoff: Y offset of the clip rectangle
10482 * @width: Width of the clip rectangle
10483 * @height: Height of the clip rectangle
10485 * Sets clip area for @self. The clip area is always computed from the
10486 * upper left corner of the actor, even if the anchor point is set
10492 clutter_actor_set_clip (ClutterActor *self,
10498 ClutterActorPrivate *priv;
10500 g_return_if_fail (CLUTTER_IS_ACTOR (self));
10504 if (priv->has_clip &&
10505 priv->clip.x == xoff &&
10506 priv->clip.y == yoff &&
10507 priv->clip.width == width &&
10508 priv->clip.height == height)
10511 priv->clip.x = xoff;
10512 priv->clip.y = yoff;
10513 priv->clip.width = width;
10514 priv->clip.height = height;
10516 priv->has_clip = TRUE;
10518 clutter_actor_queue_redraw (self);
10520 g_object_notify_by_pspec (G_OBJECT (self), obj_props[PROP_HAS_CLIP]);
10521 g_object_notify_by_pspec (G_OBJECT (self), obj_props[PROP_CLIP]);
10525 * clutter_actor_remove_clip:
10526 * @self: A #ClutterActor
10528 * Removes clip area from @self.
10531 clutter_actor_remove_clip (ClutterActor *self)
10533 g_return_if_fail (CLUTTER_IS_ACTOR (self));
10535 if (!self->priv->has_clip)
10538 self->priv->has_clip = FALSE;
10540 clutter_actor_queue_redraw (self);
10542 g_object_notify_by_pspec (G_OBJECT (self), obj_props[PROP_HAS_CLIP]);
10546 * clutter_actor_has_clip:
10547 * @self: a #ClutterActor
10549 * Determines whether the actor has a clip area set or not.
10551 * Return value: %TRUE if the actor has a clip area set.
10556 clutter_actor_has_clip (ClutterActor *self)
10558 g_return_val_if_fail (CLUTTER_IS_ACTOR (self), FALSE);
10560 return self->priv->has_clip;
10564 * clutter_actor_get_clip:
10565 * @self: a #ClutterActor
10566 * @xoff: (out) (allow-none): return location for the X offset of
10567 * the clip rectangle, or %NULL
10568 * @yoff: (out) (allow-none): return location for the Y offset of
10569 * the clip rectangle, or %NULL
10570 * @width: (out) (allow-none): return location for the width of
10571 * the clip rectangle, or %NULL
10572 * @height: (out) (allow-none): return location for the height of
10573 * the clip rectangle, or %NULL
10575 * Gets the clip area for @self, if any is set
10580 clutter_actor_get_clip (ClutterActor *self,
10586 ClutterActorPrivate *priv;
10588 g_return_if_fail (CLUTTER_IS_ACTOR (self));
10592 if (!priv->has_clip)
10596 *xoff = priv->clip.x;
10599 *yoff = priv->clip.y;
10602 *width = priv->clip.width;
10604 if (height != NULL)
10605 *height = priv->clip.height;
10609 * clutter_actor_get_children:
10610 * @self: a #ClutterActor
10612 * Retrieves the list of children of @self.
10614 * Return value: (transfer container) (element-type ClutterActor): A newly
10615 * allocated #GList of #ClutterActor<!-- -->s. Use g_list_free() when
10621 clutter_actor_get_children (ClutterActor *self)
10623 ClutterActor *iter;
10626 g_return_val_if_fail (CLUTTER_IS_ACTOR (self), NULL);
10628 /* we walk the list backward so that we can use prepend(),
10631 for (iter = self->priv->last_child, res = NULL;
10633 iter = iter->priv->prev_sibling)
10635 res = g_list_prepend (res, iter);
10642 * insert_child_at_depth:
10643 * @self: a #ClutterActor
10644 * @child: a #ClutterActor
10646 * Inserts @child inside the list of children held by @self, using
10647 * the depth as the insertion criteria.
10649 * This sadly makes the insertion not O(1), but we can keep the
10650 * list sorted so that the painters algorithm we use for painting
10651 * the children will work correctly.
10654 insert_child_at_depth (ClutterActor *self,
10655 ClutterActor *child,
10656 gpointer dummy G_GNUC_UNUSED)
10658 ClutterActor *iter;
10661 child->priv->parent = self;
10664 _clutter_actor_get_transform_info_or_defaults (child)->depth;
10666 /* special-case the first child */
10667 if (self->priv->n_children == 0)
10669 self->priv->first_child = child;
10670 self->priv->last_child = child;
10672 child->priv->next_sibling = NULL;
10673 child->priv->prev_sibling = NULL;
10678 /* Find the right place to insert the child so that it will still be
10679 sorted and the child will be after all of the actors at the same
10681 for (iter = self->priv->first_child;
10683 iter = iter->priv->next_sibling)
10688 _clutter_actor_get_transform_info_or_defaults (iter)->depth;
10690 if (iter_depth > child_depth)
10696 ClutterActor *tmp = iter->priv->prev_sibling;
10699 tmp->priv->next_sibling = child;
10701 /* Insert the node before the found one */
10702 child->priv->prev_sibling = iter->priv->prev_sibling;
10703 child->priv->next_sibling = iter;
10704 iter->priv->prev_sibling = child;
10708 ClutterActor *tmp = self->priv->last_child;
10711 tmp->priv->next_sibling = child;
10713 /* insert the node at the end of the list */
10714 child->priv->prev_sibling = self->priv->last_child;
10715 child->priv->next_sibling = NULL;
10718 if (child->priv->prev_sibling == NULL)
10719 self->priv->first_child = child;
10721 if (child->priv->next_sibling == NULL)
10722 self->priv->last_child = child;
10726 insert_child_at_index (ClutterActor *self,
10727 ClutterActor *child,
10730 gint index_ = GPOINTER_TO_INT (data_);
10732 child->priv->parent = self;
10736 ClutterActor *tmp = self->priv->first_child;
10739 tmp->priv->prev_sibling = child;
10741 child->priv->prev_sibling = NULL;
10742 child->priv->next_sibling = tmp;
10744 else if (index_ < 0 || index_ >= self->priv->n_children)
10746 ClutterActor *tmp = self->priv->last_child;
10749 tmp->priv->next_sibling = child;
10751 child->priv->prev_sibling = tmp;
10752 child->priv->next_sibling = NULL;
10756 ClutterActor *iter;
10759 for (iter = self->priv->first_child, i = 0;
10761 iter = iter->priv->next_sibling, i += 1)
10765 ClutterActor *tmp = iter->priv->prev_sibling;
10767 child->priv->prev_sibling = tmp;
10768 child->priv->next_sibling = iter;
10770 iter->priv->prev_sibling = child;
10773 tmp->priv->next_sibling = child;
10780 if (child->priv->prev_sibling == NULL)
10781 self->priv->first_child = child;
10783 if (child->priv->next_sibling == NULL)
10784 self->priv->last_child = child;
10788 insert_child_above (ClutterActor *self,
10789 ClutterActor *child,
10792 ClutterActor *sibling = data;
10794 child->priv->parent = self;
10796 if (sibling == NULL)
10797 sibling = self->priv->last_child;
10799 child->priv->prev_sibling = sibling;
10801 if (sibling != NULL)
10803 ClutterActor *tmp = sibling->priv->next_sibling;
10805 child->priv->next_sibling = tmp;
10808 tmp->priv->prev_sibling = child;
10810 sibling->priv->next_sibling = child;
10813 child->priv->next_sibling = NULL;
10815 if (child->priv->prev_sibling == NULL)
10816 self->priv->first_child = child;
10818 if (child->priv->next_sibling == NULL)
10819 self->priv->last_child = child;
10823 insert_child_below (ClutterActor *self,
10824 ClutterActor *child,
10827 ClutterActor *sibling = data;
10829 child->priv->parent = self;
10831 if (sibling == NULL)
10832 sibling = self->priv->first_child;
10834 child->priv->next_sibling = sibling;
10836 if (sibling != NULL)
10838 ClutterActor *tmp = sibling->priv->prev_sibling;
10840 child->priv->prev_sibling = tmp;
10843 tmp->priv->next_sibling = child;
10845 sibling->priv->prev_sibling = child;
10848 child->priv->prev_sibling = NULL;
10850 if (child->priv->prev_sibling == NULL)
10851 self->priv->first_child = child;
10853 if (child->priv->next_sibling == NULL)
10854 self->priv->last_child = child;
10857 typedef void (* ClutterActorAddChildFunc) (ClutterActor *parent,
10858 ClutterActor *child,
10862 ADD_CHILD_CREATE_META = 1 << 0,
10863 ADD_CHILD_EMIT_PARENT_SET = 1 << 1,
10864 ADD_CHILD_EMIT_ACTOR_ADDED = 1 << 2,
10865 ADD_CHILD_CHECK_STATE = 1 << 3,
10866 ADD_CHILD_NOTIFY_FIRST_LAST = 1 << 4,
10868 /* default flags for public API */
10869 ADD_CHILD_DEFAULT_FLAGS = ADD_CHILD_CREATE_META |
10870 ADD_CHILD_EMIT_PARENT_SET |
10871 ADD_CHILD_EMIT_ACTOR_ADDED |
10872 ADD_CHILD_CHECK_STATE |
10873 ADD_CHILD_NOTIFY_FIRST_LAST,
10875 /* flags for legacy/deprecated API */
10876 ADD_CHILD_LEGACY_FLAGS = ADD_CHILD_EMIT_PARENT_SET |
10877 ADD_CHILD_CHECK_STATE |
10878 ADD_CHILD_NOTIFY_FIRST_LAST
10879 } ClutterActorAddChildFlags;
10882 * clutter_actor_add_child_internal:
10883 * @self: a #ClutterActor
10884 * @child: a #ClutterActor
10885 * @flags: control flags for actions
10886 * @add_func: delegate function
10887 * @data: (closure): data to pass to @add_func
10889 * Adds @child to the list of children of @self.
10891 * The actual insertion inside the list is delegated to @add_func: this
10892 * function will just set up the state, perform basic checks, and emit
10895 * The @flags argument is used to perform additional operations.
10898 clutter_actor_add_child_internal (ClutterActor *self,
10899 ClutterActor *child,
10900 ClutterActorAddChildFlags flags,
10901 ClutterActorAddChildFunc add_func,
10904 ClutterTextDirection text_dir;
10905 gboolean create_meta;
10906 gboolean emit_parent_set, emit_actor_added;
10907 gboolean check_state;
10908 gboolean notify_first_last;
10909 ClutterActor *old_first_child, *old_last_child;
10911 if (child->priv->parent != NULL)
10913 g_warning ("The actor '%s' already has a parent, '%s'. You must "
10914 "use clutter_actor_remove_child() first.",
10915 _clutter_actor_get_debug_name (child),
10916 _clutter_actor_get_debug_name (child->priv->parent));
10920 if (CLUTTER_ACTOR_IS_TOPLEVEL (child))
10922 g_warning ("The actor '%s' is a top-level actor, and cannot be "
10923 "a child of another actor.",
10924 _clutter_actor_get_debug_name (child));
10929 /* XXX - this check disallows calling methods that change the stacking
10930 * order within the destruction sequence, by triggering a critical
10931 * warning first, and leaving the actor in an undefined state, which
10932 * then ends up being caught by an assertion.
10934 * the reproducible sequence is:
10936 * - actor gets destroyed;
10937 * - another actor, linked to the first, will try to change the
10938 * stacking order of the first actor;
10939 * - changing the stacking order is a composite operation composed
10940 * by the following steps:
10941 * 1. ref() the child;
10942 * 2. remove_child_internal(), which removes the reference;
10943 * 3. add_child_internal(), which adds a reference;
10944 * - the state of the actor is not changed between (2) and (3), as
10945 * it could be an expensive recomputation;
10946 * - if (3) bails out, then the actor is in an undefined state, but
10948 * - the destruction sequence terminates, but the actor is unparented
10949 * while its state indicates being parented instead.
10950 * - assertion failure.
10952 * the obvious fix would be to decompose each set_child_*_sibling()
10953 * method into proper remove_child()/add_child(), with state validation;
10954 * this may cause excessive work, though, and trigger a cascade of other
10955 * bugs in code that assumes that a change in the stacking order is an
10956 * atomic operation.
10958 * another potential fix is to just remove this check here, and let
10959 * code doing stacking order changes inside the destruction sequence
10960 * of an actor continue doing the work.
10962 * the third fix is to silently bail out early from every
10963 * set_child_*_sibling() and set_child_at_index() method, and avoid
10966 * I have a preference for the second solution, since it involves the
10967 * least amount of work, and the least amount of code duplication.
10969 * see bug: https://bugzilla.gnome.org/show_bug.cgi?id=670647
10971 if (CLUTTER_ACTOR_IN_DESTRUCTION (child))
10973 g_warning ("The actor '%s' is currently being destroyed, and "
10974 "cannot be added as a child of another actor.",
10975 _clutter_actor_get_debug_name (child));
10980 create_meta = (flags & ADD_CHILD_CREATE_META) != 0;
10981 emit_parent_set = (flags & ADD_CHILD_EMIT_PARENT_SET) != 0;
10982 emit_actor_added = (flags & ADD_CHILD_EMIT_ACTOR_ADDED) != 0;
10983 check_state = (flags & ADD_CHILD_CHECK_STATE) != 0;
10984 notify_first_last = (flags & ADD_CHILD_NOTIFY_FIRST_LAST) != 0;
10986 old_first_child = self->priv->first_child;
10987 old_last_child = self->priv->last_child;
10989 g_object_freeze_notify (G_OBJECT (self));
10992 clutter_container_create_child_meta (CLUTTER_CONTAINER (self), child);
10994 g_object_ref_sink (child);
10995 child->priv->parent = NULL;
10996 child->priv->next_sibling = NULL;
10997 child->priv->prev_sibling = NULL;
10999 /* delegate the actual insertion */
11000 add_func (self, child, data);
11002 g_assert (child->priv->parent == self);
11004 self->priv->n_children += 1;
11006 self->priv->age += 1;
11008 /* if push_internal() has been called then we automatically set
11009 * the flag on the actor
11011 if (self->priv->internal_child)
11012 CLUTTER_SET_PRIVATE_FLAGS (child, CLUTTER_INTERNAL_CHILD);
11014 /* clutter_actor_reparent() will emit ::parent-set for us */
11015 if (emit_parent_set && !CLUTTER_ACTOR_IN_REPARENT (child))
11016 g_signal_emit (child, actor_signals[PARENT_SET], 0, NULL);
11020 /* If parent is mapped or realized, we need to also be mapped or
11021 * realized once we're inside the parent.
11023 clutter_actor_update_map_state (child, MAP_STATE_CHECK);
11025 /* propagate the parent's text direction to the child */
11026 text_dir = clutter_actor_get_text_direction (self);
11027 clutter_actor_set_text_direction (child, text_dir);
11030 if (child->priv->show_on_set_parent)
11031 clutter_actor_show (child);
11033 if (CLUTTER_ACTOR_IS_MAPPED (child))
11034 clutter_actor_queue_redraw (child);
11036 /* maintain the invariant that if an actor needs layout,
11037 * its parents do as well
11039 if (child->priv->needs_width_request ||
11040 child->priv->needs_height_request ||
11041 child->priv->needs_allocation)
11043 /* we work around the short-circuiting we do
11044 * in clutter_actor_queue_relayout() since we
11045 * want to force a relayout
11047 child->priv->needs_width_request = TRUE;
11048 child->priv->needs_height_request = TRUE;
11049 child->priv->needs_allocation = TRUE;
11051 clutter_actor_queue_relayout (child->priv->parent);
11054 if (emit_actor_added)
11055 g_signal_emit_by_name (self, "actor-added", child);
11057 if (notify_first_last)
11059 if (old_first_child != self->priv->first_child)
11060 g_object_notify_by_pspec (G_OBJECT (self), obj_props[PROP_FIRST_CHILD]);
11062 if (old_last_child != self->priv->last_child)
11063 g_object_notify_by_pspec (G_OBJECT (self), obj_props[PROP_LAST_CHILD]);
11066 g_object_thaw_notify (G_OBJECT (self));
11070 * clutter_actor_add_child:
11071 * @self: a #ClutterActor
11072 * @child: a #ClutterActor
11074 * Adds @child to the children of @self.
11076 * This function will acquire a reference on @child that will only
11077 * be released when calling clutter_actor_remove_child().
11079 * This function will take into consideration the #ClutterActor:depth
11080 * of @child, and will keep the list of children sorted.
11082 * This function will emit the #ClutterContainer::actor-added signal
11088 clutter_actor_add_child (ClutterActor *self,
11089 ClutterActor *child)
11091 g_return_if_fail (CLUTTER_IS_ACTOR (self));
11092 g_return_if_fail (CLUTTER_IS_ACTOR (child));
11093 g_return_if_fail (self != child);
11094 g_return_if_fail (child->priv->parent == NULL);
11096 clutter_actor_add_child_internal (self, child,
11097 ADD_CHILD_DEFAULT_FLAGS,
11098 insert_child_at_depth,
11103 * clutter_actor_insert_child_at_index:
11104 * @self: a #ClutterActor
11105 * @child: a #ClutterActor
11106 * @index_: the index
11108 * Inserts @child into the list of children of @self, using the
11109 * given @index_. If @index_ is greater than the number of children
11110 * in @self, or is less than 0, then the new child is added at the end.
11112 * This function will acquire a reference on @child that will only
11113 * be released when calling clutter_actor_remove_child().
11115 * This function will not take into consideration the #ClutterActor:depth
11118 * This function will emit the #ClutterContainer::actor-added signal
11124 clutter_actor_insert_child_at_index (ClutterActor *self,
11125 ClutterActor *child,
11128 g_return_if_fail (CLUTTER_IS_ACTOR (self));
11129 g_return_if_fail (CLUTTER_IS_ACTOR (child));
11130 g_return_if_fail (self != child);
11131 g_return_if_fail (child->priv->parent == NULL);
11133 clutter_actor_add_child_internal (self, child,
11134 ADD_CHILD_DEFAULT_FLAGS,
11135 insert_child_at_index,
11136 GINT_TO_POINTER (index_));
11140 * clutter_actor_insert_child_above:
11141 * @self: a #ClutterActor
11142 * @child: a #ClutterActor
11143 * @sibling: (allow-none): a child of @self, or %NULL
11145 * Inserts @child into the list of children of @self, above another
11146 * child of @self or, if @sibling is %NULL, above all the children
11149 * This function will acquire a reference on @child that will only
11150 * be released when calling clutter_actor_remove_child().
11152 * This function will not take into consideration the #ClutterActor:depth
11155 * This function will emit the #ClutterContainer::actor-added signal
11161 clutter_actor_insert_child_above (ClutterActor *self,
11162 ClutterActor *child,
11163 ClutterActor *sibling)
11165 g_return_if_fail (CLUTTER_IS_ACTOR (self));
11166 g_return_if_fail (CLUTTER_IS_ACTOR (child));
11167 g_return_if_fail (self != child);
11168 g_return_if_fail (child != sibling);
11169 g_return_if_fail (child->priv->parent == NULL);
11170 g_return_if_fail (sibling == NULL ||
11171 (CLUTTER_IS_ACTOR (sibling) &&
11172 sibling->priv->parent == self));
11174 clutter_actor_add_child_internal (self, child,
11175 ADD_CHILD_DEFAULT_FLAGS,
11176 insert_child_above,
11181 * clutter_actor_insert_child_below:
11182 * @self: a #ClutterActor
11183 * @child: a #ClutterActor
11184 * @sibling: (allow-none): a child of @self, or %NULL
11186 * Inserts @child into the list of children of @self, below another
11187 * child of @self or, if @sibling is %NULL, below all the children
11190 * This function will acquire a reference on @child that will only
11191 * be released when calling clutter_actor_remove_child().
11193 * This function will not take into consideration the #ClutterActor:depth
11196 * This function will emit the #ClutterContainer::actor-added signal
11202 clutter_actor_insert_child_below (ClutterActor *self,
11203 ClutterActor *child,
11204 ClutterActor *sibling)
11206 g_return_if_fail (CLUTTER_IS_ACTOR (self));
11207 g_return_if_fail (CLUTTER_IS_ACTOR (child));
11208 g_return_if_fail (self != child);
11209 g_return_if_fail (child != sibling);
11210 g_return_if_fail (child->priv->parent == NULL);
11211 g_return_if_fail (sibling == NULL ||
11212 (CLUTTER_IS_ACTOR (sibling) &&
11213 sibling->priv->parent == self));
11215 clutter_actor_add_child_internal (self, child,
11216 ADD_CHILD_DEFAULT_FLAGS,
11217 insert_child_below,
11222 * clutter_actor_set_parent:
11223 * @self: A #ClutterActor
11224 * @parent: A new #ClutterActor parent
11226 * Sets the parent of @self to @parent.
11228 * This function will result in @parent acquiring a reference on @self,
11229 * eventually by sinking its floating reference first. The reference
11230 * will be released by clutter_actor_unparent().
11232 * This function should only be called by legacy #ClutterActor<!-- -->s
11233 * implementing the #ClutterContainer interface.
11235 * Deprecated: 1.10: Use clutter_actor_add_child() instead.
11238 clutter_actor_set_parent (ClutterActor *self,
11239 ClutterActor *parent)
11241 g_return_if_fail (CLUTTER_IS_ACTOR (self));
11242 g_return_if_fail (CLUTTER_IS_ACTOR (parent));
11243 g_return_if_fail (self != parent);
11244 g_return_if_fail (self->priv->parent == NULL);
11246 /* as this function will be called inside ClutterContainer::add
11247 * implementations or when building up a composite actor, we have
11248 * to preserve the old behaviour, and not create child meta or
11249 * emit the ::actor-added signal, to avoid recursion or double
11252 clutter_actor_add_child_internal (parent, self,
11253 ADD_CHILD_LEGACY_FLAGS,
11254 insert_child_at_depth,
11259 * clutter_actor_get_parent:
11260 * @self: A #ClutterActor
11262 * Retrieves the parent of @self.
11264 * Return Value: (transfer none): The #ClutterActor parent, or %NULL
11265 * if no parent is set
11268 clutter_actor_get_parent (ClutterActor *self)
11270 g_return_val_if_fail (CLUTTER_IS_ACTOR (self), NULL);
11272 return self->priv->parent;
11276 * clutter_actor_get_paint_visibility:
11277 * @self: A #ClutterActor
11279 * Retrieves the 'paint' visibility of an actor recursively checking for non
11282 * This is by definition the same as %CLUTTER_ACTOR_IS_MAPPED.
11284 * Return Value: %TRUE if the actor is visibile and will be painted.
11289 clutter_actor_get_paint_visibility (ClutterActor *actor)
11291 g_return_val_if_fail (CLUTTER_IS_ACTOR (actor), FALSE);
11293 return CLUTTER_ACTOR_IS_MAPPED (actor);
11297 * clutter_actor_remove_child:
11298 * @self: a #ClutterActor
11299 * @child: a #ClutterActor
11301 * Removes @child from the children of @self.
11303 * This function will release the reference added by
11304 * clutter_actor_add_child(), so if you want to keep using @child
11305 * you will have to acquire a referenced on it before calling this
11308 * This function will emit the #ClutterContainer::actor-removed
11314 clutter_actor_remove_child (ClutterActor *self,
11315 ClutterActor *child)
11317 g_return_if_fail (CLUTTER_IS_ACTOR (self));
11318 g_return_if_fail (CLUTTER_IS_ACTOR (child));
11319 g_return_if_fail (self != child);
11320 g_return_if_fail (child->priv->parent != NULL);
11321 g_return_if_fail (child->priv->parent == self);
11323 clutter_actor_remove_child_internal (self, child,
11324 REMOVE_CHILD_DEFAULT_FLAGS);
11328 * clutter_actor_remove_all_children:
11329 * @self: a #ClutterActor
11331 * Removes all children of @self.
11333 * This function releases the reference added by inserting a child actor
11334 * in the list of children of @self.
11336 * If the reference count of a child drops to zero, the child will be
11337 * destroyed. If you want to ensure the destruction of all the children
11338 * of @self, use clutter_actor_destroy_all_children().
11343 clutter_actor_remove_all_children (ClutterActor *self)
11345 ClutterActorIter iter;
11347 g_return_if_fail (CLUTTER_IS_ACTOR (self));
11349 if (self->priv->n_children == 0)
11352 g_object_freeze_notify (G_OBJECT (self));
11354 clutter_actor_iter_init (&iter, self);
11355 while (clutter_actor_iter_next (&iter, NULL))
11356 clutter_actor_iter_remove (&iter);
11358 g_object_thaw_notify (G_OBJECT (self));
11361 g_assert (self->priv->first_child == NULL);
11362 g_assert (self->priv->last_child == NULL);
11363 g_assert (self->priv->n_children == 0);
11367 * clutter_actor_destroy_all_children:
11368 * @self: a #ClutterActor
11370 * Destroys all children of @self.
11372 * This function releases the reference added by inserting a child
11373 * actor in the list of children of @self, and ensures that the
11374 * #ClutterActor::destroy signal is emitted on each child of the
11377 * By default, #ClutterActor will emit the #ClutterActor::destroy signal
11378 * when its reference count drops to 0; the default handler of the
11379 * #ClutterActor::destroy signal will destroy all the children of an
11380 * actor. This function ensures that all children are destroyed, instead
11381 * of just removed from @self, unlike clutter_actor_remove_all_children()
11382 * which will merely release the reference and remove each child.
11384 * Unless you acquired an additional reference on each child of @self
11385 * prior to calling clutter_actor_remove_all_children() and want to reuse
11386 * the actors, you should use clutter_actor_destroy_all_children() in
11387 * order to make sure that children are destroyed and signal handlers
11388 * are disconnected even in cases where circular references prevent this
11389 * from automatically happening through reference counting alone.
11394 clutter_actor_destroy_all_children (ClutterActor *self)
11396 ClutterActorIter iter;
11398 g_return_if_fail (CLUTTER_IS_ACTOR (self));
11400 if (self->priv->n_children == 0)
11403 g_object_freeze_notify (G_OBJECT (self));
11405 clutter_actor_iter_init (&iter, self);
11406 while (clutter_actor_iter_next (&iter, NULL))
11407 clutter_actor_iter_destroy (&iter);
11409 g_object_thaw_notify (G_OBJECT (self));
11412 g_assert (self->priv->first_child == NULL);
11413 g_assert (self->priv->last_child == NULL);
11414 g_assert (self->priv->n_children == 0);
11417 typedef struct _InsertBetweenData {
11418 ClutterActor *prev_sibling;
11419 ClutterActor *next_sibling;
11420 } InsertBetweenData;
11423 insert_child_between (ClutterActor *self,
11424 ClutterActor *child,
11427 InsertBetweenData *data = data_;
11428 ClutterActor *prev_sibling = data->prev_sibling;
11429 ClutterActor *next_sibling = data->next_sibling;
11431 child->priv->parent = self;
11432 child->priv->prev_sibling = prev_sibling;
11433 child->priv->next_sibling = next_sibling;
11435 if (prev_sibling != NULL)
11436 prev_sibling->priv->next_sibling = child;
11438 if (next_sibling != NULL)
11439 next_sibling->priv->prev_sibling = child;
11441 if (child->priv->prev_sibling == NULL)
11442 self->priv->first_child = child;
11444 if (child->priv->next_sibling == NULL)
11445 self->priv->last_child = child;
11449 * clutter_actor_replace_child:
11450 * @self: a #ClutterActor
11451 * @old_child: the child of @self to replace
11452 * @new_child: the #ClutterActor to replace @old_child
11454 * Replaces @old_child with @new_child in the list of children of @self.
11459 clutter_actor_replace_child (ClutterActor *self,
11460 ClutterActor *old_child,
11461 ClutterActor *new_child)
11463 ClutterActor *prev_sibling, *next_sibling;
11464 InsertBetweenData clos;
11466 g_return_if_fail (CLUTTER_IS_ACTOR (self));
11467 g_return_if_fail (CLUTTER_IS_ACTOR (old_child));
11468 g_return_if_fail (old_child->priv->parent == self);
11469 g_return_if_fail (CLUTTER_IS_ACTOR (new_child));
11470 g_return_if_fail (old_child != new_child);
11471 g_return_if_fail (new_child != self);
11472 g_return_if_fail (new_child->priv->parent == NULL);
11474 prev_sibling = old_child->priv->prev_sibling;
11475 next_sibling = old_child->priv->next_sibling;
11476 clutter_actor_remove_child_internal (self, old_child,
11477 REMOVE_CHILD_DEFAULT_FLAGS);
11479 clos.prev_sibling = prev_sibling;
11480 clos.next_sibling = next_sibling;
11481 clutter_actor_add_child_internal (self, new_child,
11482 ADD_CHILD_DEFAULT_FLAGS,
11483 insert_child_between,
11488 * clutter_actor_unparent:
11489 * @self: a #ClutterActor
11491 * Removes the parent of @self.
11493 * This will cause the parent of @self to release the reference
11494 * acquired when calling clutter_actor_set_parent(), so if you
11495 * want to keep @self you will have to acquire a reference of
11496 * your own, through g_object_ref().
11498 * This function should only be called by legacy #ClutterActor<!-- -->s
11499 * implementing the #ClutterContainer interface.
11503 * Deprecated: 1.10: Use clutter_actor_remove_child() instead.
11506 clutter_actor_unparent (ClutterActor *self)
11508 g_return_if_fail (CLUTTER_IS_ACTOR (self));
11510 if (self->priv->parent == NULL)
11513 clutter_actor_remove_child_internal (self->priv->parent, self,
11514 REMOVE_CHILD_LEGACY_FLAGS);
11518 * clutter_actor_reparent:
11519 * @self: a #ClutterActor
11520 * @new_parent: the new #ClutterActor parent
11522 * Resets the parent actor of @self.
11524 * This function is logically equivalent to calling clutter_actor_unparent()
11525 * and clutter_actor_set_parent(), but more efficiently implemented, as it
11526 * ensures the child is not finalized when unparented, and emits the
11527 * #ClutterActor::parent-set signal only once.
11529 * In reality, calling this function is less useful than it sounds, as some
11530 * application code may rely on changes in the intermediate state between
11531 * removal and addition of the actor from its old parent to the @new_parent.
11532 * Thus, it is strongly encouraged to avoid using this function in application
11537 * Deprecated: 1.10: Use clutter_actor_remove_child() and
11538 * clutter_actor_add_child() instead; remember to take a reference on
11539 * the actor being removed before calling clutter_actor_remove_child()
11540 * to avoid the reference count dropping to zero and the actor being
11544 clutter_actor_reparent (ClutterActor *self,
11545 ClutterActor *new_parent)
11547 ClutterActorPrivate *priv;
11549 g_return_if_fail (CLUTTER_IS_ACTOR (self));
11550 g_return_if_fail (CLUTTER_IS_ACTOR (new_parent));
11551 g_return_if_fail (self != new_parent);
11553 if (CLUTTER_ACTOR_IS_TOPLEVEL (self))
11555 g_warning ("Cannot set a parent on a toplevel actor");
11559 if (CLUTTER_ACTOR_IN_DESTRUCTION (self))
11561 g_warning ("Cannot set a parent currently being destroyed");
11567 if (priv->parent != new_parent)
11569 ClutterActor *old_parent;
11571 CLUTTER_SET_PRIVATE_FLAGS (self, CLUTTER_IN_REPARENT);
11573 old_parent = priv->parent;
11575 g_object_ref (self);
11577 if (old_parent != NULL)
11579 /* go through the Container implementation if this is a regular
11580 * child and not an internal one
11582 if (!CLUTTER_ACTOR_IS_INTERNAL_CHILD (self))
11584 ClutterContainer *parent = CLUTTER_CONTAINER (old_parent);
11586 /* this will have to call unparent() */
11587 clutter_container_remove_actor (parent, self);
11590 clutter_actor_remove_child_internal (old_parent, self,
11591 REMOVE_CHILD_LEGACY_FLAGS);
11594 /* Note, will call set_parent() */
11595 if (!CLUTTER_ACTOR_IS_INTERNAL_CHILD (self))
11596 clutter_container_add_actor (CLUTTER_CONTAINER (new_parent), self);
11598 clutter_actor_add_child_internal (new_parent, self,
11599 ADD_CHILD_LEGACY_FLAGS,
11600 insert_child_at_depth,
11603 /* we emit the ::parent-set signal once */
11604 g_signal_emit (self, actor_signals[PARENT_SET], 0, old_parent);
11606 CLUTTER_UNSET_PRIVATE_FLAGS (self, CLUTTER_IN_REPARENT);
11608 /* the IN_REPARENT flag suspends state updates */
11609 clutter_actor_update_map_state (self, MAP_STATE_CHECK);
11611 g_object_unref (self);
11616 * clutter_actor_contains:
11617 * @self: A #ClutterActor
11618 * @descendant: A #ClutterActor, possibly contained in @self
11620 * Determines if @descendant is contained inside @self (either as an
11621 * immediate child, or as a deeper descendant). If @self and
11622 * @descendant point to the same actor then it will also return %TRUE.
11624 * Return value: whether @descendent is contained within @self
11629 clutter_actor_contains (ClutterActor *self,
11630 ClutterActor *descendant)
11632 ClutterActor *actor;
11634 g_return_val_if_fail (CLUTTER_IS_ACTOR (self), FALSE);
11635 g_return_val_if_fail (CLUTTER_IS_ACTOR (descendant), FALSE);
11637 for (actor = descendant; actor; actor = actor->priv->parent)
11645 * clutter_actor_set_child_above_sibling:
11646 * @self: a #ClutterActor
11647 * @child: a #ClutterActor child of @self
11648 * @sibling: (allow-none): a #ClutterActor child of @self, or %NULL
11650 * Sets @child to be above @sibling in the list of children of @self.
11652 * If @sibling is %NULL, @child will be the new last child of @self.
11654 * This function is logically equivalent to removing @child and using
11655 * clutter_actor_insert_child_above(), but it will not emit signals
11656 * or change state on @child.
11661 clutter_actor_set_child_above_sibling (ClutterActor *self,
11662 ClutterActor *child,
11663 ClutterActor *sibling)
11665 g_return_if_fail (CLUTTER_IS_ACTOR (self));
11666 g_return_if_fail (CLUTTER_IS_ACTOR (child));
11667 g_return_if_fail (child->priv->parent == self);
11668 g_return_if_fail (child != sibling);
11669 g_return_if_fail (sibling == NULL || CLUTTER_IS_ACTOR (sibling));
11671 if (sibling != NULL)
11672 g_return_if_fail (sibling->priv->parent == self);
11674 if (CLUTTER_ACTOR_IN_DESTRUCTION (self) ||
11675 CLUTTER_ACTOR_IN_DESTRUCTION (child) ||
11676 (sibling != NULL && CLUTTER_ACTOR_IN_DESTRUCTION (sibling)))
11679 /* we don't want to change the state of child, or emit signals, or
11680 * regenerate ChildMeta instances here, but we still want to follow
11681 * the correct sequence of steps encoded in remove_child() and
11682 * add_child(), so that correctness is ensured, and we only go
11683 * through one known code path.
11685 g_object_ref (child);
11686 clutter_actor_remove_child_internal (self, child, 0);
11687 clutter_actor_add_child_internal (self, child,
11688 ADD_CHILD_NOTIFY_FIRST_LAST,
11689 insert_child_above,
11692 clutter_actor_queue_relayout (self);
11696 * clutter_actor_set_child_below_sibling:
11697 * @self: a #ClutterActor
11698 * @child: a #ClutterActor child of @self
11699 * @sibling: (allow-none): a #ClutterActor child of @self, or %NULL
11701 * Sets @child to be below @sibling in the list of children of @self.
11703 * If @sibling is %NULL, @child will be the new first child of @self.
11705 * This function is logically equivalent to removing @self and using
11706 * clutter_actor_insert_child_below(), but it will not emit signals
11707 * or change state on @child.
11712 clutter_actor_set_child_below_sibling (ClutterActor *self,
11713 ClutterActor *child,
11714 ClutterActor *sibling)
11716 g_return_if_fail (CLUTTER_IS_ACTOR (self));
11717 g_return_if_fail (CLUTTER_IS_ACTOR (child));
11718 g_return_if_fail (child->priv->parent == self);
11719 g_return_if_fail (child != sibling);
11720 g_return_if_fail (sibling == NULL || CLUTTER_IS_ACTOR (sibling));
11722 if (sibling != NULL)
11723 g_return_if_fail (sibling->priv->parent == self);
11725 if (CLUTTER_ACTOR_IN_DESTRUCTION (self) ||
11726 CLUTTER_ACTOR_IN_DESTRUCTION (child) ||
11727 (sibling != NULL && CLUTTER_ACTOR_IN_DESTRUCTION (sibling)))
11730 /* see the comment in set_child_above_sibling() */
11731 g_object_ref (child);
11732 clutter_actor_remove_child_internal (self, child, 0);
11733 clutter_actor_add_child_internal (self, child,
11734 ADD_CHILD_NOTIFY_FIRST_LAST,
11735 insert_child_below,
11738 clutter_actor_queue_relayout (self);
11742 * clutter_actor_set_child_at_index:
11743 * @self: a #ClutterActor
11744 * @child: a #ClutterActor child of @self
11745 * @index_: the new index for @child
11747 * Changes the index of @child in the list of children of @self.
11749 * This function is logically equivalent to removing @child and
11750 * calling clutter_actor_insert_child_at_index(), but it will not
11751 * emit signals or change state on @child.
11756 clutter_actor_set_child_at_index (ClutterActor *self,
11757 ClutterActor *child,
11760 g_return_if_fail (CLUTTER_IS_ACTOR (self));
11761 g_return_if_fail (CLUTTER_IS_ACTOR (child));
11762 g_return_if_fail (child->priv->parent == self);
11763 g_return_if_fail (index_ <= self->priv->n_children);
11765 if (CLUTTER_ACTOR_IN_DESTRUCTION (self) ||
11766 CLUTTER_ACTOR_IN_DESTRUCTION (child))
11769 g_object_ref (child);
11770 clutter_actor_remove_child_internal (self, child, 0);
11771 clutter_actor_add_child_internal (self, child,
11772 ADD_CHILD_NOTIFY_FIRST_LAST,
11773 insert_child_at_index,
11774 GINT_TO_POINTER (index_));
11776 clutter_actor_queue_relayout (self);
11780 * clutter_actor_raise:
11781 * @self: A #ClutterActor
11782 * @below: (allow-none): A #ClutterActor to raise above.
11784 * Puts @self above @below.
11786 * Both actors must have the same parent, and the parent must implement
11787 * the #ClutterContainer interface
11789 * This function calls clutter_container_raise_child() internally.
11791 * Deprecated: 1.10: Use clutter_actor_set_child_above_sibling() instead.
11794 clutter_actor_raise (ClutterActor *self,
11795 ClutterActor *below)
11797 ClutterActor *parent;
11799 g_return_if_fail (CLUTTER_IS_ACTOR (self));
11801 parent = clutter_actor_get_parent (self);
11802 if (parent == NULL)
11804 g_warning ("%s: Actor '%s' is not inside a container",
11806 _clutter_actor_get_debug_name (self));
11812 if (parent != clutter_actor_get_parent (below))
11814 g_warning ("%s Actor '%s' is not in the same container as "
11817 _clutter_actor_get_debug_name (self),
11818 _clutter_actor_get_debug_name (below));
11823 clutter_container_raise_child (CLUTTER_CONTAINER (parent), self, below);
11827 * clutter_actor_lower:
11828 * @self: A #ClutterActor
11829 * @above: (allow-none): A #ClutterActor to lower below
11831 * Puts @self below @above.
11833 * Both actors must have the same parent, and the parent must implement
11834 * the #ClutterContainer interface.
11836 * This function calls clutter_container_lower_child() internally.
11838 * Deprecated: 1.10: Use clutter_actor_set_child_below_sibling() instead.
11841 clutter_actor_lower (ClutterActor *self,
11842 ClutterActor *above)
11844 ClutterActor *parent;
11846 g_return_if_fail (CLUTTER_IS_ACTOR (self));
11848 parent = clutter_actor_get_parent (self);
11849 if (parent == NULL)
11851 g_warning ("%s: Actor of type %s is not inside a container",
11853 _clutter_actor_get_debug_name (self));
11859 if (parent != clutter_actor_get_parent (above))
11861 g_warning ("%s: Actor '%s' is not in the same container as "
11864 _clutter_actor_get_debug_name (self),
11865 _clutter_actor_get_debug_name (above));
11870 clutter_container_lower_child (CLUTTER_CONTAINER (parent), self, above);
11874 * clutter_actor_raise_top:
11875 * @self: A #ClutterActor
11877 * Raises @self to the top.
11879 * This function calls clutter_actor_raise() internally.
11881 * Deprecated: 1.10: Use clutter_actor_set_child_above_sibling() with
11882 * a %NULL sibling, instead.
11885 clutter_actor_raise_top (ClutterActor *self)
11887 clutter_actor_raise (self, NULL);
11891 * clutter_actor_lower_bottom:
11892 * @self: A #ClutterActor
11894 * Lowers @self to the bottom.
11896 * This function calls clutter_actor_lower() internally.
11898 * Deprecated: 1.10: Use clutter_actor_set_child_below_sibling() with
11899 * a %NULL sibling, instead.
11902 clutter_actor_lower_bottom (ClutterActor *self)
11904 clutter_actor_lower (self, NULL);
11912 * clutter_actor_event:
11913 * @actor: a #ClutterActor
11914 * @event: a #ClutterEvent
11915 * @capture: TRUE if event in in capture phase, FALSE otherwise.
11917 * This function is used to emit an event on the main stage.
11918 * You should rarely need to use this function, except for
11919 * synthetising events.
11921 * Return value: the return value from the signal emission: %TRUE
11922 * if the actor handled the event, or %FALSE if the event was
11928 clutter_actor_event (ClutterActor *actor,
11929 ClutterEvent *event,
11932 gboolean retval = FALSE;
11933 gint signal_num = -1;
11935 g_return_val_if_fail (CLUTTER_IS_ACTOR (actor), FALSE);
11936 g_return_val_if_fail (event != NULL, FALSE);
11938 g_object_ref (actor);
11942 g_signal_emit (actor, actor_signals[CAPTURED_EVENT], 0,
11948 g_signal_emit (actor, actor_signals[EVENT], 0, event, &retval);
11952 switch (event->type)
11954 case CLUTTER_NOTHING:
11956 case CLUTTER_BUTTON_PRESS:
11957 signal_num = BUTTON_PRESS_EVENT;
11959 case CLUTTER_BUTTON_RELEASE:
11960 signal_num = BUTTON_RELEASE_EVENT;
11962 case CLUTTER_SCROLL:
11963 signal_num = SCROLL_EVENT;
11965 case CLUTTER_KEY_PRESS:
11966 signal_num = KEY_PRESS_EVENT;
11968 case CLUTTER_KEY_RELEASE:
11969 signal_num = KEY_RELEASE_EVENT;
11971 case CLUTTER_MOTION:
11972 signal_num = MOTION_EVENT;
11974 case CLUTTER_ENTER:
11975 signal_num = ENTER_EVENT;
11977 case CLUTTER_LEAVE:
11978 signal_num = LEAVE_EVENT;
11980 case CLUTTER_DELETE:
11981 case CLUTTER_DESTROY_NOTIFY:
11982 case CLUTTER_CLIENT_MESSAGE:
11988 if (signal_num != -1)
11989 g_signal_emit (actor, actor_signals[signal_num], 0,
11994 g_object_unref (actor);
12000 * clutter_actor_set_reactive:
12001 * @actor: a #ClutterActor
12002 * @reactive: whether the actor should be reactive to events
12004 * Sets @actor as reactive. Reactive actors will receive events.
12009 clutter_actor_set_reactive (ClutterActor *actor,
12012 g_return_if_fail (CLUTTER_IS_ACTOR (actor));
12014 if (reactive == CLUTTER_ACTOR_IS_REACTIVE (actor))
12018 CLUTTER_ACTOR_SET_FLAGS (actor, CLUTTER_ACTOR_REACTIVE);
12020 CLUTTER_ACTOR_UNSET_FLAGS (actor, CLUTTER_ACTOR_REACTIVE);
12022 g_object_notify_by_pspec (G_OBJECT (actor), obj_props[PROP_REACTIVE]);
12026 * clutter_actor_get_reactive:
12027 * @actor: a #ClutterActor
12029 * Checks whether @actor is marked as reactive.
12031 * Return value: %TRUE if the actor is reactive
12036 clutter_actor_get_reactive (ClutterActor *actor)
12038 g_return_val_if_fail (CLUTTER_IS_ACTOR (actor), FALSE);
12040 return CLUTTER_ACTOR_IS_REACTIVE (actor) ? TRUE : FALSE;
12044 * clutter_actor_get_anchor_point:
12045 * @self: a #ClutterActor
12046 * @anchor_x: (out): return location for the X coordinate of the anchor point
12047 * @anchor_y: (out): return location for the Y coordinate of the anchor point
12049 * Gets the current anchor point of the @actor in pixels.
12054 clutter_actor_get_anchor_point (ClutterActor *self,
12058 const ClutterTransformInfo *info;
12060 g_return_if_fail (CLUTTER_IS_ACTOR (self));
12062 info = _clutter_actor_get_transform_info_or_defaults (self);
12063 clutter_anchor_coord_get_units (self, &info->anchor,
12070 * clutter_actor_set_anchor_point:
12071 * @self: a #ClutterActor
12072 * @anchor_x: X coordinate of the anchor point
12073 * @anchor_y: Y coordinate of the anchor point
12075 * Sets an anchor point for @self. The anchor point is a point in the
12076 * coordinate space of an actor to which the actor position within its
12077 * parent is relative; the default is (0, 0), i.e. the top-left corner
12083 clutter_actor_set_anchor_point (ClutterActor *self,
12087 ClutterTransformInfo *info;
12088 ClutterActorPrivate *priv;
12089 gboolean changed = FALSE;
12090 gfloat old_anchor_x, old_anchor_y;
12093 g_return_if_fail (CLUTTER_IS_ACTOR (self));
12095 obj = G_OBJECT (self);
12097 info = _clutter_actor_get_transform_info (self);
12099 g_object_freeze_notify (obj);
12101 clutter_anchor_coord_get_units (self, &info->anchor,
12106 if (info->anchor.is_fractional)
12107 g_object_notify_by_pspec (obj, obj_props[PROP_ANCHOR_GRAVITY]);
12109 if (old_anchor_x != anchor_x)
12111 g_object_notify_by_pspec (obj, obj_props[PROP_ANCHOR_X]);
12115 if (old_anchor_y != anchor_y)
12117 g_object_notify_by_pspec (obj, obj_props[PROP_ANCHOR_Y]);
12121 clutter_anchor_coord_set_units (&info->anchor, anchor_x, anchor_y, 0);
12125 priv->transform_valid = FALSE;
12126 clutter_actor_queue_redraw (self);
12129 g_object_thaw_notify (obj);
12133 * clutter_actor_get_anchor_point_gravity:
12134 * @self: a #ClutterActor
12136 * Retrieves the anchor position expressed as a #ClutterGravity. If
12137 * the anchor point was specified using pixels or units this will
12138 * return %CLUTTER_GRAVITY_NONE.
12140 * Return value: the #ClutterGravity used by the anchor point
12145 clutter_actor_get_anchor_point_gravity (ClutterActor *self)
12147 const ClutterTransformInfo *info;
12149 g_return_val_if_fail (CLUTTER_IS_ACTOR (self), CLUTTER_GRAVITY_NONE);
12151 info = _clutter_actor_get_transform_info_or_defaults (self);
12153 return clutter_anchor_coord_get_gravity (&info->anchor);
12157 * clutter_actor_move_anchor_point:
12158 * @self: a #ClutterActor
12159 * @anchor_x: X coordinate of the anchor point
12160 * @anchor_y: Y coordinate of the anchor point
12162 * Sets an anchor point for the actor, and adjusts the actor postion so that
12163 * the relative position of the actor toward its parent remains the same.
12168 clutter_actor_move_anchor_point (ClutterActor *self,
12172 gfloat old_anchor_x, old_anchor_y;
12173 const ClutterTransformInfo *info;
12175 g_return_if_fail (CLUTTER_IS_ACTOR (self));
12177 info = _clutter_actor_get_transform_info (self);
12178 clutter_anchor_coord_get_units (self, &info->anchor,
12183 g_object_freeze_notify (G_OBJECT (self));
12185 clutter_actor_set_anchor_point (self, anchor_x, anchor_y);
12187 if (self->priv->position_set)
12188 clutter_actor_move_by (self,
12189 anchor_x - old_anchor_x,
12190 anchor_y - old_anchor_y);
12192 g_object_thaw_notify (G_OBJECT (self));
12196 * clutter_actor_move_anchor_point_from_gravity:
12197 * @self: a #ClutterActor
12198 * @gravity: #ClutterGravity.
12200 * Sets an anchor point on the actor based on the given gravity, adjusting the
12201 * actor postion so that its relative position within its parent remains
12204 * Since version 1.0 the anchor point will be stored as a gravity so
12205 * that if the actor changes size then the anchor point will move. For
12206 * example, if you set the anchor point to %CLUTTER_GRAVITY_SOUTH_EAST
12207 * and later double the size of the actor, the anchor point will move
12208 * to the bottom right.
12213 clutter_actor_move_anchor_point_from_gravity (ClutterActor *self,
12214 ClutterGravity gravity)
12216 gfloat old_anchor_x, old_anchor_y, new_anchor_x, new_anchor_y;
12217 const ClutterTransformInfo *info;
12218 ClutterActorPrivate *priv;
12220 g_return_if_fail (CLUTTER_IS_ACTOR (self));
12223 info = _clutter_actor_get_transform_info (self);
12225 g_object_freeze_notify (G_OBJECT (self));
12227 clutter_anchor_coord_get_units (self, &info->anchor,
12231 clutter_actor_set_anchor_point_from_gravity (self, gravity);
12232 clutter_anchor_coord_get_units (self, &info->anchor,
12237 if (priv->position_set)
12238 clutter_actor_move_by (self,
12239 new_anchor_x - old_anchor_x,
12240 new_anchor_y - old_anchor_y);
12242 g_object_thaw_notify (G_OBJECT (self));
12246 * clutter_actor_set_anchor_point_from_gravity:
12247 * @self: a #ClutterActor
12248 * @gravity: #ClutterGravity.
12250 * Sets an anchor point on the actor, based on the given gravity (this is a
12251 * convenience function wrapping clutter_actor_set_anchor_point()).
12253 * Since version 1.0 the anchor point will be stored as a gravity so
12254 * that if the actor changes size then the anchor point will move. For
12255 * example, if you set the anchor point to %CLUTTER_GRAVITY_SOUTH_EAST
12256 * and later double the size of the actor, the anchor point will move
12257 * to the bottom right.
12262 clutter_actor_set_anchor_point_from_gravity (ClutterActor *self,
12263 ClutterGravity gravity)
12265 g_return_if_fail (CLUTTER_IS_ACTOR (self));
12267 if (gravity == CLUTTER_GRAVITY_NONE)
12268 clutter_actor_set_anchor_point (self, 0, 0);
12271 GObject *obj = G_OBJECT (self);
12272 ClutterTransformInfo *info;
12274 g_object_freeze_notify (obj);
12276 info = _clutter_actor_get_transform_info (self);
12277 clutter_anchor_coord_set_gravity (&info->anchor, gravity);
12279 g_object_notify_by_pspec (obj, obj_props[PROP_ANCHOR_GRAVITY]);
12280 g_object_notify_by_pspec (obj, obj_props[PROP_ANCHOR_X]);
12281 g_object_notify_by_pspec (obj, obj_props[PROP_ANCHOR_Y]);
12283 self->priv->transform_valid = FALSE;
12285 clutter_actor_queue_redraw (self);
12287 g_object_thaw_notify (obj);
12292 clutter_container_iface_init (ClutterContainerIface *iface)
12294 /* we don't override anything, as ClutterContainer already has a default
12295 * implementation that we can use, and which calls into our own API.
12310 parse_units (ClutterActor *self,
12311 ParseDimension dimension,
12314 GValue value = G_VALUE_INIT;
12317 if (JSON_NODE_TYPE (node) != JSON_NODE_VALUE)
12320 json_node_get_value (node, &value);
12322 if (G_VALUE_HOLDS (&value, G_TYPE_INT64))
12324 retval = (gfloat) g_value_get_int64 (&value);
12326 else if (G_VALUE_HOLDS (&value, G_TYPE_DOUBLE))
12328 retval = g_value_get_double (&value);
12330 else if (G_VALUE_HOLDS (&value, G_TYPE_STRING))
12332 ClutterUnits units;
12335 res = clutter_units_from_string (&units, g_value_get_string (&value));
12337 retval = clutter_units_to_pixels (&units);
12340 g_warning ("Invalid value '%s': integers, strings or floating point "
12341 "values can be used for the x, y, width and height "
12342 "properties. Valid modifiers for strings are 'px', 'mm', "
12344 g_value_get_string (&value));
12350 g_warning ("Invalid value of type '%s': integers, strings of floating "
12351 "point values can be used for the x, y, width, height "
12352 "anchor-x and anchor-y properties.",
12353 g_type_name (G_VALUE_TYPE (&value)));
12356 g_value_unset (&value);
12362 ClutterRotateAxis axis;
12371 static inline gboolean
12372 parse_rotation_array (ClutterActor *actor,
12374 RotationInfo *info)
12378 if (json_array_get_length (array) != 2)
12382 element = json_array_get_element (array, 0);
12383 if (JSON_NODE_TYPE (element) == JSON_NODE_VALUE)
12384 info->angle = json_node_get_double (element);
12389 element = json_array_get_element (array, 1);
12390 if (JSON_NODE_TYPE (element) == JSON_NODE_ARRAY)
12392 JsonArray *center = json_node_get_array (element);
12394 if (json_array_get_length (center) != 2)
12397 switch (info->axis)
12399 case CLUTTER_X_AXIS:
12400 info->center_y = parse_units (actor, PARSE_Y,
12401 json_array_get_element (center, 0));
12402 info->center_z = parse_units (actor, PARSE_Y,
12403 json_array_get_element (center, 1));
12406 case CLUTTER_Y_AXIS:
12407 info->center_x = parse_units (actor, PARSE_X,
12408 json_array_get_element (center, 0));
12409 info->center_z = parse_units (actor, PARSE_X,
12410 json_array_get_element (center, 1));
12413 case CLUTTER_Z_AXIS:
12414 info->center_x = parse_units (actor, PARSE_X,
12415 json_array_get_element (center, 0));
12416 info->center_y = parse_units (actor, PARSE_Y,
12417 json_array_get_element (center, 1));
12426 parse_rotation (ClutterActor *actor,
12428 RotationInfo *info)
12432 gboolean retval = FALSE;
12434 if (JSON_NODE_TYPE (node) != JSON_NODE_ARRAY)
12436 g_warning ("Invalid node of type '%s' found, expecting an array",
12437 json_node_type_name (node));
12441 array = json_node_get_array (node);
12442 len = json_array_get_length (array);
12444 for (i = 0; i < len; i++)
12446 JsonNode *element = json_array_get_element (array, i);
12447 JsonObject *object;
12450 if (JSON_NODE_TYPE (element) != JSON_NODE_OBJECT)
12452 g_warning ("Invalid node of type '%s' found, expecting an object",
12453 json_node_type_name (element));
12457 object = json_node_get_object (element);
12459 if (json_object_has_member (object, "x-axis"))
12461 member = json_object_get_member (object, "x-axis");
12463 info->axis = CLUTTER_X_AXIS;
12465 if (JSON_NODE_TYPE (member) == JSON_NODE_VALUE)
12467 info->angle = json_node_get_double (member);
12470 else if (JSON_NODE_TYPE (member) == JSON_NODE_ARRAY)
12471 retval = parse_rotation_array (actor,
12472 json_node_get_array (member),
12477 else if (json_object_has_member (object, "y-axis"))
12479 member = json_object_get_member (object, "y-axis");
12481 info->axis = CLUTTER_Y_AXIS;
12483 if (JSON_NODE_TYPE (member) == JSON_NODE_VALUE)
12485 info->angle = json_node_get_double (member);
12488 else if (JSON_NODE_TYPE (member) == JSON_NODE_ARRAY)
12489 retval = parse_rotation_array (actor,
12490 json_node_get_array (member),
12495 else if (json_object_has_member (object, "z-axis"))
12497 member = json_object_get_member (object, "z-axis");
12499 info->axis = CLUTTER_Z_AXIS;
12501 if (JSON_NODE_TYPE (member) == JSON_NODE_VALUE)
12503 info->angle = json_node_get_double (member);
12506 else if (JSON_NODE_TYPE (member) == JSON_NODE_ARRAY)
12507 retval = parse_rotation_array (actor,
12508 json_node_get_array (member),
12519 parse_actor_metas (ClutterScript *script,
12520 ClutterActor *actor,
12523 GList *elements, *l;
12524 GSList *retval = NULL;
12526 if (!JSON_NODE_HOLDS_ARRAY (node))
12529 elements = json_array_get_elements (json_node_get_array (node));
12531 for (l = elements; l != NULL; l = l->next)
12533 JsonNode *element = l->data;
12534 const gchar *id_ = _clutter_script_get_id_from_node (element);
12537 if (id_ == NULL || *id_ == '\0')
12540 meta = clutter_script_get_object (script, id_);
12544 retval = g_slist_prepend (retval, meta);
12547 g_list_free (elements);
12549 return g_slist_reverse (retval);
12553 parse_behaviours (ClutterScript *script,
12554 ClutterActor *actor,
12557 GList *elements, *l;
12558 GSList *retval = NULL;
12560 if (!JSON_NODE_HOLDS_ARRAY (node))
12563 elements = json_array_get_elements (json_node_get_array (node));
12565 for (l = elements; l != NULL; l = l->next)
12567 JsonNode *element = l->data;
12568 const gchar *id_ = _clutter_script_get_id_from_node (element);
12569 GObject *behaviour;
12571 if (id_ == NULL || *id_ == '\0')
12574 behaviour = clutter_script_get_object (script, id_);
12575 if (behaviour == NULL)
12578 retval = g_slist_prepend (retval, behaviour);
12581 g_list_free (elements);
12583 return g_slist_reverse (retval);
12587 clutter_actor_parse_custom_node (ClutterScriptable *scriptable,
12588 ClutterScript *script,
12593 ClutterActor *actor = CLUTTER_ACTOR (scriptable);
12594 gboolean retval = FALSE;
12596 if ((name[0] == 'x' && name[1] == '\0') ||
12597 (name[0] == 'y' && name[1] == '\0') ||
12598 (strcmp (name, "width") == 0) ||
12599 (strcmp (name, "height") == 0) ||
12600 (strcmp (name, "anchor_x") == 0) ||
12601 (strcmp (name, "anchor_y") == 0))
12603 ParseDimension dimension;
12606 if (name[0] == 'x')
12607 dimension = PARSE_X;
12608 else if (name[0] == 'y')
12609 dimension = PARSE_Y;
12610 else if (name[0] == 'w')
12611 dimension = PARSE_WIDTH;
12612 else if (name[0] == 'h')
12613 dimension = PARSE_HEIGHT;
12614 else if (name[0] == 'a' && name[7] == 'x')
12615 dimension = PARSE_ANCHOR_X;
12616 else if (name[0] == 'a' && name[7] == 'y')
12617 dimension = PARSE_ANCHOR_Y;
12621 units = parse_units (actor, dimension, node);
12623 /* convert back to pixels: all properties are pixel-based */
12624 g_value_init (value, G_TYPE_FLOAT);
12625 g_value_set_float (value, units);
12629 else if (strcmp (name, "rotation") == 0)
12631 RotationInfo *info;
12633 info = g_slice_new0 (RotationInfo);
12634 retval = parse_rotation (actor, node, info);
12638 g_value_init (value, G_TYPE_POINTER);
12639 g_value_set_pointer (value, info);
12642 g_slice_free (RotationInfo, info);
12644 else if (strcmp (name, "behaviours") == 0)
12648 #ifdef CLUTTER_ENABLE_DEBUG
12649 if (G_UNLIKELY (_clutter_diagnostic_enabled ()))
12650 _clutter_diagnostic_message ("The 'behaviours' key is deprecated "
12651 "and it should not be used in newly "
12652 "written ClutterScript definitions.");
12655 l = parse_behaviours (script, actor, node);
12657 g_value_init (value, G_TYPE_POINTER);
12658 g_value_set_pointer (value, l);
12662 else if (strcmp (name, "actions") == 0 ||
12663 strcmp (name, "constraints") == 0 ||
12664 strcmp (name, "effects") == 0)
12668 l = parse_actor_metas (script, actor, node);
12670 g_value_init (value, G_TYPE_POINTER);
12671 g_value_set_pointer (value, l);
12680 clutter_actor_set_custom_property (ClutterScriptable *scriptable,
12681 ClutterScript *script,
12683 const GValue *value)
12685 ClutterActor *actor = CLUTTER_ACTOR (scriptable);
12687 #ifdef CLUTTER_ENABLE_DEBUG
12688 if (G_UNLIKELY (CLUTTER_HAS_DEBUG (SCRIPT)))
12690 gchar *tmp = g_strdup_value_contents (value);
12692 CLUTTER_NOTE (SCRIPT,
12693 "in ClutterActor::set_custom_property('%s') = %s",
12699 #endif /* CLUTTER_ENABLE_DEBUG */
12701 if (strcmp (name, "rotation") == 0)
12703 RotationInfo *info;
12705 if (!G_VALUE_HOLDS (value, G_TYPE_POINTER))
12708 info = g_value_get_pointer (value);
12710 clutter_actor_set_rotation (actor,
12711 info->axis, info->angle,
12716 g_slice_free (RotationInfo, info);
12721 if (strcmp (name, "behaviours") == 0)
12723 GSList *behaviours, *l;
12725 if (!G_VALUE_HOLDS (value, G_TYPE_POINTER))
12728 behaviours = g_value_get_pointer (value);
12729 for (l = behaviours; l != NULL; l = l->next)
12731 ClutterBehaviour *behaviour = l->data;
12733 clutter_behaviour_apply (behaviour, actor);
12736 g_slist_free (behaviours);
12741 if (strcmp (name, "actions") == 0 ||
12742 strcmp (name, "constraints") == 0 ||
12743 strcmp (name, "effects") == 0)
12747 if (!G_VALUE_HOLDS (value, G_TYPE_POINTER))
12750 metas = g_value_get_pointer (value);
12751 for (l = metas; l != NULL; l = l->next)
12753 if (name[0] == 'a')
12754 clutter_actor_add_action (actor, l->data);
12756 if (name[0] == 'c')
12757 clutter_actor_add_constraint (actor, l->data);
12759 if (name[0] == 'e')
12760 clutter_actor_add_effect (actor, l->data);
12763 g_slist_free (metas);
12768 g_object_set_property (G_OBJECT (scriptable), name, value);
12772 clutter_scriptable_iface_init (ClutterScriptableIface *iface)
12774 iface->parse_custom_node = clutter_actor_parse_custom_node;
12775 iface->set_custom_property = clutter_actor_set_custom_property;
12778 static ClutterActorMeta *
12779 get_meta_from_animation_property (ClutterActor *actor,
12783 ClutterActorPrivate *priv = actor->priv;
12784 ClutterActorMeta *meta = NULL;
12787 /* if this is not a special property, fall through */
12788 if (name[0] != '@')
12791 /* detect the properties named using the following spec:
12793 * @<section>.<meta-name>.<property-name>
12795 * where <section> can be one of the following:
12801 * and <meta-name> is the name set on a specific ActorMeta
12804 tokens = g_strsplit (name + 1, ".", -1);
12805 if (tokens == NULL || g_strv_length (tokens) != 3)
12807 CLUTTER_NOTE (ANIMATION, "Invalid property name '%s'",
12809 g_strfreev (tokens);
12813 if (strcmp (tokens[0], "actions") == 0)
12814 meta = _clutter_meta_group_get_meta (priv->actions, tokens[1]);
12816 if (strcmp (tokens[0], "constraints") == 0)
12817 meta = _clutter_meta_group_get_meta (priv->constraints, tokens[1]);
12819 if (strcmp (tokens[0], "effects") == 0)
12820 meta = _clutter_meta_group_get_meta (priv->effects, tokens[1]);
12822 if (name_p != NULL)
12823 *name_p = g_strdup (tokens[2]);
12825 CLUTTER_NOTE (ANIMATION,
12826 "Looking for property '%s' of object '%s' in section '%s'",
12831 g_strfreev (tokens);
12836 static GParamSpec *
12837 clutter_actor_find_property (ClutterAnimatable *animatable,
12838 const gchar *property_name)
12840 ClutterActorMeta *meta = NULL;
12841 GObjectClass *klass = NULL;
12842 GParamSpec *pspec = NULL;
12843 gchar *p_name = NULL;
12845 meta = get_meta_from_animation_property (CLUTTER_ACTOR (animatable),
12851 klass = G_OBJECT_GET_CLASS (meta);
12853 pspec = g_object_class_find_property (klass, p_name);
12857 klass = G_OBJECT_GET_CLASS (animatable);
12859 pspec = g_object_class_find_property (klass, property_name);
12868 clutter_actor_get_initial_state (ClutterAnimatable *animatable,
12869 const gchar *property_name,
12872 ClutterActorMeta *meta = NULL;
12873 gchar *p_name = NULL;
12875 meta = get_meta_from_animation_property (CLUTTER_ACTOR (animatable),
12880 g_object_get_property (G_OBJECT (meta), p_name, initial);
12882 g_object_get_property (G_OBJECT (animatable), property_name, initial);
12888 * clutter_actor_set_animatable_property:
12889 * @actor: a #ClutterActor
12890 * @prop_id: the paramspec id
12891 * @value: the value to set
12892 * @pspec: the paramspec
12894 * Sets values of animatable properties.
12896 * This is a variant of clutter_actor_set_property() that gets called
12897 * by the #ClutterAnimatable implementation of #ClutterActor for the
12898 * properties with the %CLUTTER_PARAM_ANIMATABLE flag set on their
12901 * Unlike the implementation of #GObjectClass.set_property(), this
12902 * function will not update the interval if a transition involving an
12903 * animatable property is in progress - this avoids cycles with the
12904 * transition API calling the public API.
12907 clutter_actor_set_animatable_property (ClutterActor *actor,
12909 const GValue *value,
12912 GObject *obj = G_OBJECT (actor);
12914 g_object_freeze_notify (obj);
12919 clutter_actor_set_x_internal (actor, g_value_get_float (value));
12923 clutter_actor_set_y_internal (actor, g_value_get_float (value));
12927 clutter_actor_set_width_internal (actor, g_value_get_float (value));
12931 clutter_actor_set_height_internal (actor, g_value_get_float (value));
12935 clutter_actor_set_depth_internal (actor, g_value_get_float (value));
12939 clutter_actor_set_opacity_internal (actor, g_value_get_uint (value));
12942 case PROP_BACKGROUND_COLOR:
12943 clutter_actor_set_background_color_internal (actor, clutter_value_get_color (value));
12947 clutter_actor_set_scale_factor_internal (actor,
12948 g_value_get_double (value),
12953 clutter_actor_set_scale_factor_internal (actor,
12954 g_value_get_double (value),
12958 case PROP_ROTATION_ANGLE_X:
12959 clutter_actor_set_rotation_angle_internal (actor,
12961 g_value_get_double (value));
12964 case PROP_ROTATION_ANGLE_Y:
12965 clutter_actor_set_rotation_angle_internal (actor,
12967 g_value_get_double (value));
12970 case PROP_ROTATION_ANGLE_Z:
12971 clutter_actor_set_rotation_angle_internal (actor,
12973 g_value_get_double (value));
12977 g_object_set_property (obj, pspec->name, value);
12981 g_object_thaw_notify (obj);
12985 clutter_actor_set_final_state (ClutterAnimatable *animatable,
12986 const gchar *property_name,
12987 const GValue *final)
12989 ClutterActor *actor = CLUTTER_ACTOR (animatable);
12990 ClutterActorMeta *meta = NULL;
12991 gchar *p_name = NULL;
12993 meta = get_meta_from_animation_property (actor,
12997 g_object_set_property (G_OBJECT (meta), p_name, final);
13000 GObjectClass *obj_class = G_OBJECT_GET_CLASS (animatable);
13003 pspec = g_object_class_find_property (obj_class, property_name);
13005 if ((pspec->flags & CLUTTER_PARAM_ANIMATABLE) != 0)
13007 /* XXX - I'm going to the special hell for this */
13008 clutter_actor_set_animatable_property (actor, pspec->param_id, final, pspec);
13011 g_object_set_property (G_OBJECT (animatable), pspec->name, final);
13018 clutter_animatable_iface_init (ClutterAnimatableIface *iface)
13020 iface->find_property = clutter_actor_find_property;
13021 iface->get_initial_state = clutter_actor_get_initial_state;
13022 iface->set_final_state = clutter_actor_set_final_state;
13026 * clutter_actor_transform_stage_point:
13027 * @self: A #ClutterActor
13028 * @x: (in): x screen coordinate of the point to unproject
13029 * @y: (in): y screen coordinate of the point to unproject
13030 * @x_out: (out): return location for the unprojected x coordinance
13031 * @y_out: (out): return location for the unprojected y coordinance
13033 * This function translates screen coordinates (@x, @y) to
13034 * coordinates relative to the actor. For example, it can be used to translate
13035 * screen events from global screen coordinates into actor-local coordinates.
13037 * The conversion can fail, notably if the transform stack results in the
13038 * actor being projected on the screen as a mere line.
13040 * The conversion should not be expected to be pixel-perfect due to the
13041 * nature of the operation. In general the error grows when the skewing
13042 * of the actor rectangle on screen increases.
13044 * <note><para>This function can be computationally intensive.</para></note>
13046 * <note><para>This function only works when the allocation is up-to-date,
13047 * i.e. inside of paint().</para></note>
13049 * Return value: %TRUE if conversion was successful.
13054 clutter_actor_transform_stage_point (ClutterActor *self,
13060 ClutterVertex v[4];
13063 int du, dv, xi, yi;
13065 float xf, yf, wf, det;
13066 ClutterActorPrivate *priv;
13068 g_return_val_if_fail (CLUTTER_IS_ACTOR (self), FALSE);
13072 /* This implementation is based on the quad -> quad projection algorithm
13073 * described by Paul Heckbert in:
13075 * http://www.cs.cmu.edu/~ph/texfund/texfund.pdf
13077 * and the sample implementation at:
13079 * http://www.cs.cmu.edu/~ph/src/texfund/
13081 * Our texture is a rectangle with origin [0, 0], so we are mapping from
13082 * quad to rectangle only, which significantly simplifies things; the
13083 * function calls have been unrolled, and most of the math is done in fixed
13087 clutter_actor_get_abs_allocation_vertices (self, v);
13089 /* Keeping these as ints simplifies the multiplication (no significant
13090 * loss of precision here).
13092 du = (int) (priv->allocation.x2 - priv->allocation.x1);
13093 dv = (int) (priv->allocation.y2 - priv->allocation.y1);
13098 #define UX2FP(x) (x)
13099 #define DET2FP(a,b,c,d) (((a) * (d)) - ((b) * (c)))
13101 /* First, find mapping from unit uv square to xy quadrilateral; this
13102 * equivalent to the pmap_square_quad() functions in the sample
13103 * implementation, which we can simplify, since our target is always
13106 px = v[0].x - v[1].x + v[3].x - v[2].x;
13107 py = v[0].y - v[1].y + v[3].y - v[2].y;
13111 /* affine transform */
13112 RQ[0][0] = UX2FP (v[1].x - v[0].x);
13113 RQ[1][0] = UX2FP (v[3].x - v[1].x);
13114 RQ[2][0] = UX2FP (v[0].x);
13115 RQ[0][1] = UX2FP (v[1].y - v[0].y);
13116 RQ[1][1] = UX2FP (v[3].y - v[1].y);
13117 RQ[2][1] = UX2FP (v[0].y);
13124 /* projective transform */
13125 double dx1, dx2, dy1, dy2, del;
13127 dx1 = UX2FP (v[1].x - v[3].x);
13128 dx2 = UX2FP (v[2].x - v[3].x);
13129 dy1 = UX2FP (v[1].y - v[3].y);
13130 dy2 = UX2FP (v[2].y - v[3].y);
13132 del = DET2FP (dx1, dx2, dy1, dy2);
13137 * The division here needs to be done in floating point for
13138 * precisions reasons.
13140 RQ[0][2] = (DET2FP (UX2FP (px), dx2, UX2FP (py), dy2) / del);
13141 RQ[1][2] = (DET2FP (dx1, UX2FP (px), dy1, UX2FP (py)) / del);
13142 RQ[1][2] = (DET2FP (dx1, UX2FP (px), dy1, UX2FP (py)) / del);
13144 RQ[0][0] = UX2FP (v[1].x - v[0].x) + (RQ[0][2] * UX2FP (v[1].x));
13145 RQ[1][0] = UX2FP (v[2].x - v[0].x) + (RQ[1][2] * UX2FP (v[2].x));
13146 RQ[2][0] = UX2FP (v[0].x);
13147 RQ[0][1] = UX2FP (v[1].y - v[0].y) + (RQ[0][2] * UX2FP (v[1].y));
13148 RQ[1][1] = UX2FP (v[2].y - v[0].y) + (RQ[1][2] * UX2FP (v[2].y));
13149 RQ[2][1] = UX2FP (v[0].y);
13153 * Now combine with transform from our rectangle (u0,v0,u1,v1) to unit
13154 * square. Since our rectangle is based at 0,0 we only need to scale.
13164 * Now RQ is transform from uv rectangle to xy quadrilateral; we need an
13167 ST[0][0] = DET2FP (RQ[1][1], RQ[1][2], RQ[2][1], RQ[2][2]);
13168 ST[1][0] = DET2FP (RQ[1][2], RQ[1][0], RQ[2][2], RQ[2][0]);
13169 ST[2][0] = DET2FP (RQ[1][0], RQ[1][1], RQ[2][0], RQ[2][1]);
13170 ST[0][1] = DET2FP (RQ[2][1], RQ[2][2], RQ[0][1], RQ[0][2]);
13171 ST[1][1] = DET2FP (RQ[2][2], RQ[2][0], RQ[0][2], RQ[0][0]);
13172 ST[2][1] = DET2FP (RQ[2][0], RQ[2][1], RQ[0][0], RQ[0][1]);
13173 ST[0][2] = DET2FP (RQ[0][1], RQ[0][2], RQ[1][1], RQ[1][2]);
13174 ST[1][2] = DET2FP (RQ[0][2], RQ[0][0], RQ[1][2], RQ[1][0]);
13175 ST[2][2] = DET2FP (RQ[0][0], RQ[0][1], RQ[1][0], RQ[1][1]);
13178 * Check the resulting matrix is OK.
13180 det = (RQ[0][0] * ST[0][0])
13181 + (RQ[0][1] * ST[0][1])
13182 + (RQ[0][2] * ST[0][2]);
13187 * Now transform our point with the ST matrix; the notional w
13188 * coordinate is 1, hence the last part is simply added.
13193 xf = xi * ST[0][0] + yi * ST[1][0] + ST[2][0];
13194 yf = xi * ST[0][1] + yi * ST[1][1] + ST[2][1];
13195 wf = xi * ST[0][2] + yi * ST[1][2] + ST[2][2];
13213 static ClutterGeometry*
13214 clutter_geometry_copy (const ClutterGeometry *geometry)
13216 return g_slice_dup (ClutterGeometry, geometry);
13220 clutter_geometry_free (ClutterGeometry *geometry)
13222 if (G_LIKELY (geometry != NULL))
13223 g_slice_free (ClutterGeometry, geometry);
13227 * clutter_geometry_union:
13228 * @geometry_a: a #ClutterGeometry
13229 * @geometry_b: another #ClutterGeometry
13230 * @result: (out): location to store the result
13232 * Find the union of two rectangles represented as #ClutterGeometry.
13237 clutter_geometry_union (const ClutterGeometry *geometry_a,
13238 const ClutterGeometry *geometry_b,
13239 ClutterGeometry *result)
13241 /* We don't try to handle rectangles that can't be represented
13242 * as a signed integer box */
13243 gint x_1 = MIN (geometry_a->x, geometry_b->x);
13244 gint y_1 = MIN (geometry_a->y, geometry_b->y);
13245 gint x_2 = MAX (geometry_a->x + (gint)geometry_a->width,
13246 geometry_b->x + (gint)geometry_b->width);
13247 gint y_2 = MAX (geometry_a->y + (gint)geometry_a->height,
13248 geometry_b->y + (gint)geometry_b->height);
13251 result->width = x_2 - x_1;
13252 result->height = y_2 - y_1;
13256 * clutter_geometry_intersects:
13257 * @geometry0: The first geometry to test
13258 * @geometry1: The second geometry to test
13260 * Determines if @geometry0 and geometry1 intersect returning %TRUE if
13261 * they do else %FALSE.
13263 * Return value: %TRUE of @geometry0 and geometry1 intersect else
13269 clutter_geometry_intersects (const ClutterGeometry *geometry0,
13270 const ClutterGeometry *geometry1)
13272 if (geometry1->x >= (geometry0->x + (gint)geometry0->width) ||
13273 geometry1->y >= (geometry0->y + (gint)geometry0->height) ||
13274 (geometry1->x + (gint)geometry1->width) <= geometry0->x ||
13275 (geometry1->y + (gint)geometry1->height) <= geometry0->y)
13282 clutter_geometry_progress (const GValue *a,
13287 const ClutterGeometry *a_geom = g_value_get_boxed (a);
13288 const ClutterGeometry *b_geom = g_value_get_boxed (b);
13289 ClutterGeometry res = { 0, };
13290 gint a_width = a_geom->width;
13291 gint b_width = b_geom->width;
13292 gint a_height = a_geom->height;
13293 gint b_height = b_geom->height;
13295 res.x = a_geom->x + (b_geom->x - a_geom->x) * progress;
13296 res.y = a_geom->y + (b_geom->y - a_geom->y) * progress;
13298 res.width = a_width + (b_width - a_width) * progress;
13299 res.height = a_height + (b_height - a_height) * progress;
13301 g_value_set_boxed (retval, &res);
13306 G_DEFINE_BOXED_TYPE_WITH_CODE (ClutterGeometry, clutter_geometry,
13307 clutter_geometry_copy,
13308 clutter_geometry_free,
13309 CLUTTER_REGISTER_INTERVAL_PROGRESS (clutter_geometry_progress));
13316 * clutter_vertex_new:
13321 * Creates a new #ClutterVertex for the point in 3D space
13322 * identified by the 3 coordinates @x, @y, @z
13324 * Return value: the newly allocate #ClutterVertex. Use
13325 * clutter_vertex_free() to free the resources
13330 clutter_vertex_new (gfloat x,
13334 ClutterVertex *vertex;
13336 vertex = g_slice_new (ClutterVertex);
13337 clutter_vertex_init (vertex, x, y, z);
13343 * clutter_vertex_init:
13344 * @vertex: a #ClutterVertex
13349 * Initializes @vertex with the given coordinates.
13354 clutter_vertex_init (ClutterVertex *vertex,
13359 g_return_if_fail (vertex != NULL);
13367 * clutter_vertex_copy:
13368 * @vertex: a #ClutterVertex
13372 * Return value: a newly allocated copy of #ClutterVertex. Use
13373 * clutter_vertex_free() to free the allocated resources
13378 clutter_vertex_copy (const ClutterVertex *vertex)
13380 if (G_LIKELY (vertex != NULL))
13381 return g_slice_dup (ClutterVertex, vertex);
13387 * clutter_vertex_free:
13388 * @vertex: a #ClutterVertex
13390 * Frees a #ClutterVertex allocated using clutter_vertex_copy()
13395 clutter_vertex_free (ClutterVertex *vertex)
13397 if (G_UNLIKELY (vertex != NULL))
13398 g_slice_free (ClutterVertex, vertex);
13402 * clutter_vertex_equal:
13403 * @vertex_a: a #ClutterVertex
13404 * @vertex_b: a #ClutterVertex
13406 * Compares @vertex_a and @vertex_b for equality
13408 * Return value: %TRUE if the passed #ClutterVertex are equal
13413 clutter_vertex_equal (const ClutterVertex *vertex_a,
13414 const ClutterVertex *vertex_b)
13416 g_return_val_if_fail (vertex_a != NULL && vertex_b != NULL, FALSE);
13418 if (vertex_a == vertex_b)
13421 return vertex_a->x == vertex_b->x &&
13422 vertex_a->y == vertex_b->y &&
13423 vertex_a->z == vertex_b->z;
13427 clutter_vertex_progress (const GValue *a,
13432 const ClutterVertex *av = g_value_get_boxed (a);
13433 const ClutterVertex *bv = g_value_get_boxed (b);
13434 ClutterVertex res = { 0, };
13436 res.x = av->x + (bv->x - av->x) * progress;
13437 res.y = av->y + (bv->y - av->y) * progress;
13438 res.z = av->z + (bv->z - av->z) * progress;
13440 g_value_set_boxed (retval, &res);
13445 G_DEFINE_BOXED_TYPE_WITH_CODE (ClutterVertex, clutter_vertex,
13446 clutter_vertex_copy,
13447 clutter_vertex_free,
13448 CLUTTER_REGISTER_INTERVAL_PROGRESS (clutter_vertex_progress));
13451 * clutter_actor_is_rotated:
13452 * @self: a #ClutterActor
13454 * Checks whether any rotation is applied to the actor.
13456 * Return value: %TRUE if the actor is rotated.
13461 clutter_actor_is_rotated (ClutterActor *self)
13463 const ClutterTransformInfo *info;
13465 g_return_val_if_fail (CLUTTER_IS_ACTOR (self), FALSE);
13467 info = _clutter_actor_get_transform_info_or_defaults (self);
13469 if (info->rx_angle || info->ry_angle || info->rz_angle)
13476 * clutter_actor_is_scaled:
13477 * @self: a #ClutterActor
13479 * Checks whether the actor is scaled in either dimension.
13481 * Return value: %TRUE if the actor is scaled.
13486 clutter_actor_is_scaled (ClutterActor *self)
13488 const ClutterTransformInfo *info;
13490 g_return_val_if_fail (CLUTTER_IS_ACTOR (self), FALSE);
13492 info = _clutter_actor_get_transform_info_or_defaults (self);
13494 if (info->scale_x != 1.0 || info->scale_y != 1.0)
13501 _clutter_actor_get_stage_internal (ClutterActor *actor)
13503 while (actor && !CLUTTER_ACTOR_IS_TOPLEVEL (actor))
13504 actor = actor->priv->parent;
13510 * clutter_actor_get_stage:
13511 * @actor: a #ClutterActor
13513 * Retrieves the #ClutterStage where @actor is contained.
13515 * Return value: (transfer none) (type Clutter.Stage): the stage
13516 * containing the actor, or %NULL
13521 clutter_actor_get_stage (ClutterActor *actor)
13523 g_return_val_if_fail (CLUTTER_IS_ACTOR (actor), NULL);
13525 return _clutter_actor_get_stage_internal (actor);
13529 * clutter_actor_allocate_available_size:
13530 * @self: a #ClutterActor
13531 * @x: the actor's X coordinate
13532 * @y: the actor's Y coordinate
13533 * @available_width: the maximum available width, or -1 to use the
13534 * actor's natural width
13535 * @available_height: the maximum available height, or -1 to use the
13536 * actor's natural height
13537 * @flags: flags controlling the allocation
13539 * Allocates @self taking into account the #ClutterActor<!-- -->'s
13540 * preferred size, but limiting it to the maximum available width
13541 * and height provided.
13543 * This function will do the right thing when dealing with the
13544 * actor's request mode.
13546 * The implementation of this function is equivalent to:
13549 * if (request_mode == CLUTTER_REQUEST_HEIGHT_FOR_WIDTH)
13551 * clutter_actor_get_preferred_width (self, available_height,
13553 * &natural_width);
13554 * width = CLAMP (natural_width, min_width, available_width);
13556 * clutter_actor_get_preferred_height (self, width,
13558 * &natural_height);
13559 * height = CLAMP (natural_height, min_height, available_height);
13563 * clutter_actor_get_preferred_height (self, available_width,
13565 * &natural_height);
13566 * height = CLAMP (natural_height, min_height, available_height);
13568 * clutter_actor_get_preferred_width (self, height,
13570 * &natural_width);
13571 * width = CLAMP (natural_width, min_width, available_width);
13574 * box.x1 = x; box.y1 = y;
13575 * box.x2 = box.x1 + available_width;
13576 * box.y2 = box.y1 + available_height;
13577 * clutter_actor_allocate (self, &box, flags);
13580 * This function can be used by fluid layout managers to allocate
13581 * an actor's preferred size without making it bigger than the area
13582 * available for the container.
13587 clutter_actor_allocate_available_size (ClutterActor *self,
13590 gfloat available_width,
13591 gfloat available_height,
13592 ClutterAllocationFlags flags)
13594 ClutterActorPrivate *priv;
13595 gfloat width, height;
13596 gfloat min_width, min_height;
13597 gfloat natural_width, natural_height;
13598 ClutterActorBox box;
13600 g_return_if_fail (CLUTTER_IS_ACTOR (self));
13604 width = height = 0.0;
13606 switch (priv->request_mode)
13608 case CLUTTER_REQUEST_HEIGHT_FOR_WIDTH:
13609 clutter_actor_get_preferred_width (self, available_height,
13612 width = CLAMP (natural_width, min_width, available_width);
13614 clutter_actor_get_preferred_height (self, width,
13617 height = CLAMP (natural_height, min_height, available_height);
13620 case CLUTTER_REQUEST_WIDTH_FOR_HEIGHT:
13621 clutter_actor_get_preferred_height (self, available_width,
13624 height = CLAMP (natural_height, min_height, available_height);
13626 clutter_actor_get_preferred_width (self, height,
13629 width = CLAMP (natural_width, min_width, available_width);
13636 box.x2 = box.x1 + width;
13637 box.y2 = box.y1 + height;
13638 clutter_actor_allocate (self, &box, flags);
13642 * clutter_actor_allocate_preferred_size:
13643 * @self: a #ClutterActor
13644 * @flags: flags controlling the allocation
13646 * Allocates the natural size of @self.
13648 * This function is a utility call for #ClutterActor implementations
13649 * that allocates the actor's preferred natural size. It can be used
13650 * by fixed layout managers (like #ClutterGroup or so called
13651 * 'composite actors') inside the ClutterActor::allocate
13652 * implementation to give each child exactly how much space it
13655 * This function is not meant to be used by applications. It is also
13656 * not meant to be used outside the implementation of the
13657 * ClutterActor::allocate virtual function.
13662 clutter_actor_allocate_preferred_size (ClutterActor *self,
13663 ClutterAllocationFlags flags)
13665 gfloat actor_x, actor_y;
13666 gfloat natural_width, natural_height;
13667 ClutterActorBox actor_box;
13669 g_return_if_fail (CLUTTER_IS_ACTOR (self));
13671 actor_x = clutter_actor_get_x (self);
13672 actor_y = clutter_actor_get_y (self);
13674 clutter_actor_get_preferred_size (self,
13679 actor_box.x1 = actor_x;
13680 actor_box.y1 = actor_y;
13681 actor_box.x2 = actor_box.x1 + natural_width;
13682 actor_box.y2 = actor_box.y1 + natural_height;
13684 clutter_actor_allocate (self, &actor_box, flags);
13688 * clutter_actor_allocate_align_fill:
13689 * @self: a #ClutterActor
13690 * @box: a #ClutterActorBox, containing the available width and height
13691 * @x_align: the horizontal alignment, between 0 and 1
13692 * @y_align: the vertical alignment, between 0 and 1
13693 * @x_fill: whether the actor should fill horizontally
13694 * @y_fill: whether the actor should fill vertically
13695 * @flags: allocation flags to be passed to clutter_actor_allocate()
13697 * Allocates @self by taking into consideration the available allocation
13698 * area; an alignment factor on either axis; and whether the actor should
13699 * fill the allocation on either axis.
13701 * The @box should contain the available allocation width and height;
13702 * if the x1 and y1 members of #ClutterActorBox are not set to 0, the
13703 * allocation will be offset by their value.
13705 * This function takes into consideration the geometry request specified by
13706 * the #ClutterActor:request-mode property, and the text direction.
13708 * This function is useful for fluid layout managers, like #ClutterBinLayout
13709 * or #ClutterTableLayout
13714 clutter_actor_allocate_align_fill (ClutterActor *self,
13715 const ClutterActorBox *box,
13720 ClutterAllocationFlags flags)
13722 ClutterActorPrivate *priv;
13723 ClutterActorBox allocation = { 0, };
13724 gfloat x_offset, y_offset;
13725 gfloat available_width, available_height;
13726 gfloat child_width, child_height;
13728 g_return_if_fail (CLUTTER_IS_ACTOR (self));
13729 g_return_if_fail (box != NULL);
13730 g_return_if_fail (x_align >= 0.0 && x_align <= 1.0);
13731 g_return_if_fail (y_align >= 0.0 && y_align <= 1.0);
13735 clutter_actor_box_get_origin (box, &x_offset, &y_offset);
13736 clutter_actor_box_get_size (box, &available_width, &available_height);
13738 if (available_width < 0)
13739 available_width = 0;
13741 if (available_height < 0)
13742 available_height = 0;
13746 allocation.x1 = x_offset;
13747 allocation.x2 = allocation.x1 + available_width;
13752 allocation.y1 = y_offset;
13753 allocation.y2 = allocation.y1 + available_height;
13756 /* if we are filling horizontally and vertically then we're done */
13757 if (x_fill && y_fill)
13760 child_width = child_height = 0.0f;
13762 if (priv->request_mode == CLUTTER_REQUEST_HEIGHT_FOR_WIDTH)
13764 gfloat min_width, natural_width;
13765 gfloat min_height, natural_height;
13767 clutter_actor_get_preferred_width (self, available_height,
13771 child_width = CLAMP (natural_width, min_width, available_width);
13775 clutter_actor_get_preferred_height (self, child_width,
13779 child_height = CLAMP (natural_height, min_height, available_height);
13784 gfloat min_width, natural_width;
13785 gfloat min_height, natural_height;
13787 clutter_actor_get_preferred_height (self, available_width,
13791 child_height = CLAMP (natural_height, min_height, available_height);
13795 clutter_actor_get_preferred_width (self, child_height,
13799 child_width = CLAMP (natural_width, min_width, available_width);
13803 /* invert the horizontal alignment for RTL languages */
13804 if (priv->text_direction == CLUTTER_TEXT_DIRECTION_RTL)
13805 x_align = 1.0 - x_align;
13809 allocation.x1 = x_offset
13810 + ((available_width - child_width) * x_align);
13811 allocation.x2 = allocation.x1 + child_width;
13816 allocation.y1 = y_offset
13817 + ((available_height - child_height) * y_align);
13818 allocation.y2 = allocation.y1 + child_height;
13822 clutter_actor_box_clamp_to_pixel (&allocation);
13823 clutter_actor_allocate (self, &allocation, flags);
13827 * clutter_actor_grab_key_focus:
13828 * @self: a #ClutterActor
13830 * Sets the key focus of the #ClutterStage including @self
13831 * to this #ClutterActor.
13836 clutter_actor_grab_key_focus (ClutterActor *self)
13838 ClutterActor *stage;
13840 g_return_if_fail (CLUTTER_IS_ACTOR (self));
13842 stage = _clutter_actor_get_stage_internal (self);
13844 clutter_stage_set_key_focus (CLUTTER_STAGE (stage), self);
13848 * clutter_actor_get_pango_context:
13849 * @self: a #ClutterActor
13851 * Retrieves the #PangoContext for @self. The actor's #PangoContext
13852 * is already configured using the appropriate font map, resolution
13853 * and font options.
13855 * Unlike clutter_actor_create_pango_context(), this context is owend
13856 * by the #ClutterActor and it will be updated each time the options
13857 * stored by the #ClutterBackend change.
13859 * You can use the returned #PangoContext to create a #PangoLayout
13860 * and render text using cogl_pango_render_layout() to reuse the
13861 * glyphs cache also used by Clutter.
13863 * Return value: (transfer none): the #PangoContext for a #ClutterActor.
13864 * The returned #PangoContext is owned by the actor and should not be
13865 * unreferenced by the application code
13870 clutter_actor_get_pango_context (ClutterActor *self)
13872 ClutterActorPrivate *priv;
13874 g_return_val_if_fail (CLUTTER_IS_ACTOR (self), NULL);
13878 if (priv->pango_context != NULL)
13879 return priv->pango_context;
13881 priv->pango_context = _clutter_context_get_pango_context ();
13882 g_object_ref (priv->pango_context);
13884 return priv->pango_context;
13888 * clutter_actor_create_pango_context:
13889 * @self: a #ClutterActor
13891 * Creates a #PangoContext for the given actor. The #PangoContext
13892 * is already configured using the appropriate font map, resolution
13893 * and font options.
13895 * See also clutter_actor_get_pango_context().
13897 * Return value: (transfer full): the newly created #PangoContext.
13898 * Use g_object_unref() on the returned value to deallocate its
13904 clutter_actor_create_pango_context (ClutterActor *self)
13906 g_return_val_if_fail (CLUTTER_IS_ACTOR (self), NULL);
13908 return _clutter_context_create_pango_context ();
13912 * clutter_actor_create_pango_layout:
13913 * @self: a #ClutterActor
13914 * @text: (allow-none) the text to set on the #PangoLayout, or %NULL
13916 * Creates a new #PangoLayout from the same #PangoContext used
13917 * by the #ClutterActor. The #PangoLayout is already configured
13918 * with the font map, resolution and font options, and the
13921 * If you want to keep around a #PangoLayout created by this
13922 * function you will have to connect to the #ClutterBackend::font-changed
13923 * and #ClutterBackend::resolution-changed signals, and call
13924 * pango_layout_context_changed() in response to them.
13926 * Return value: (transfer full): the newly created #PangoLayout.
13927 * Use g_object_unref() when done
13932 clutter_actor_create_pango_layout (ClutterActor *self,
13935 PangoContext *context;
13936 PangoLayout *layout;
13938 g_return_val_if_fail (CLUTTER_IS_ACTOR (self), NULL);
13940 context = clutter_actor_get_pango_context (self);
13941 layout = pango_layout_new (context);
13944 pango_layout_set_text (layout, text, -1);
13949 /* Allows overriding the calculated paint opacity. Used by ClutterClone and
13950 * ClutterOffscreenEffect.
13953 _clutter_actor_set_opacity_override (ClutterActor *self,
13956 g_return_if_fail (CLUTTER_IS_ACTOR (self));
13958 self->priv->opacity_override = opacity;
13962 _clutter_actor_get_opacity_override (ClutterActor *self)
13964 g_return_val_if_fail (CLUTTER_IS_ACTOR (self), -1);
13966 return self->priv->opacity_override;
13969 /* Allows you to disable applying the actors model view transform during
13970 * a paint. Used by ClutterClone. */
13972 _clutter_actor_set_enable_model_view_transform (ClutterActor *self,
13975 g_return_if_fail (CLUTTER_IS_ACTOR (self));
13977 self->priv->enable_model_view_transform = enable;
13981 _clutter_actor_set_enable_paint_unmapped (ClutterActor *self,
13984 ClutterActorPrivate *priv;
13986 g_return_if_fail (CLUTTER_IS_ACTOR (self));
13990 priv->enable_paint_unmapped = enable;
13992 if (priv->enable_paint_unmapped)
13994 /* Make sure that the parents of the widget are realized first;
13995 * otherwise checks in clutter_actor_update_map_state() will
13998 clutter_actor_realize (self);
14000 clutter_actor_update_map_state (self, MAP_STATE_MAKE_MAPPED);
14004 clutter_actor_update_map_state (self, MAP_STATE_MAKE_UNMAPPED);
14009 clutter_anchor_coord_get_units (ClutterActor *self,
14010 const AnchorCoord *coord,
14015 if (coord->is_fractional)
14017 gfloat actor_width, actor_height;
14019 clutter_actor_get_size (self, &actor_width, &actor_height);
14022 *x = actor_width * coord->v.fraction.x;
14025 *y = actor_height * coord->v.fraction.y;
14033 *x = coord->v.units.x;
14036 *y = coord->v.units.y;
14039 *z = coord->v.units.z;
14044 clutter_anchor_coord_set_units (AnchorCoord *coord,
14049 coord->is_fractional = FALSE;
14050 coord->v.units.x = x;
14051 coord->v.units.y = y;
14052 coord->v.units.z = z;
14055 static ClutterGravity
14056 clutter_anchor_coord_get_gravity (const AnchorCoord *coord)
14058 if (coord->is_fractional)
14060 if (coord->v.fraction.x == 0.0)
14062 if (coord->v.fraction.y == 0.0)
14063 return CLUTTER_GRAVITY_NORTH_WEST;
14064 else if (coord->v.fraction.y == 0.5)
14065 return CLUTTER_GRAVITY_WEST;
14066 else if (coord->v.fraction.y == 1.0)
14067 return CLUTTER_GRAVITY_SOUTH_WEST;
14069 return CLUTTER_GRAVITY_NONE;
14071 else if (coord->v.fraction.x == 0.5)
14073 if (coord->v.fraction.y == 0.0)
14074 return CLUTTER_GRAVITY_NORTH;
14075 else if (coord->v.fraction.y == 0.5)
14076 return CLUTTER_GRAVITY_CENTER;
14077 else if (coord->v.fraction.y == 1.0)
14078 return CLUTTER_GRAVITY_SOUTH;
14080 return CLUTTER_GRAVITY_NONE;
14082 else if (coord->v.fraction.x == 1.0)
14084 if (coord->v.fraction.y == 0.0)
14085 return CLUTTER_GRAVITY_NORTH_EAST;
14086 else if (coord->v.fraction.y == 0.5)
14087 return CLUTTER_GRAVITY_EAST;
14088 else if (coord->v.fraction.y == 1.0)
14089 return CLUTTER_GRAVITY_SOUTH_EAST;
14091 return CLUTTER_GRAVITY_NONE;
14094 return CLUTTER_GRAVITY_NONE;
14097 return CLUTTER_GRAVITY_NONE;
14101 clutter_anchor_coord_set_gravity (AnchorCoord *coord,
14102 ClutterGravity gravity)
14106 case CLUTTER_GRAVITY_NORTH:
14107 coord->v.fraction.x = 0.5;
14108 coord->v.fraction.y = 0.0;
14111 case CLUTTER_GRAVITY_NORTH_EAST:
14112 coord->v.fraction.x = 1.0;
14113 coord->v.fraction.y = 0.0;
14116 case CLUTTER_GRAVITY_EAST:
14117 coord->v.fraction.x = 1.0;
14118 coord->v.fraction.y = 0.5;
14121 case CLUTTER_GRAVITY_SOUTH_EAST:
14122 coord->v.fraction.x = 1.0;
14123 coord->v.fraction.y = 1.0;
14126 case CLUTTER_GRAVITY_SOUTH:
14127 coord->v.fraction.x = 0.5;
14128 coord->v.fraction.y = 1.0;
14131 case CLUTTER_GRAVITY_SOUTH_WEST:
14132 coord->v.fraction.x = 0.0;
14133 coord->v.fraction.y = 1.0;
14136 case CLUTTER_GRAVITY_WEST:
14137 coord->v.fraction.x = 0.0;
14138 coord->v.fraction.y = 0.5;
14141 case CLUTTER_GRAVITY_NORTH_WEST:
14142 coord->v.fraction.x = 0.0;
14143 coord->v.fraction.y = 0.0;
14146 case CLUTTER_GRAVITY_CENTER:
14147 coord->v.fraction.x = 0.5;
14148 coord->v.fraction.y = 0.5;
14152 coord->v.fraction.x = 0.0;
14153 coord->v.fraction.y = 0.0;
14157 coord->is_fractional = TRUE;
14161 clutter_anchor_coord_is_zero (const AnchorCoord *coord)
14163 if (coord->is_fractional)
14164 return coord->v.fraction.x == 0.0 && coord->v.fraction.y == 0.0;
14166 return (coord->v.units.x == 0.0
14167 && coord->v.units.y == 0.0
14168 && coord->v.units.z == 0.0);
14172 * clutter_actor_get_flags:
14173 * @self: a #ClutterActor
14175 * Retrieves the flags set on @self
14177 * Return value: a bitwise or of #ClutterActorFlags or 0
14182 clutter_actor_get_flags (ClutterActor *self)
14184 g_return_val_if_fail (CLUTTER_IS_ACTOR (self), 0);
14186 return self->flags;
14190 * clutter_actor_set_flags:
14191 * @self: a #ClutterActor
14192 * @flags: the flags to set
14194 * Sets @flags on @self
14196 * This function will emit notifications for the changed properties
14201 clutter_actor_set_flags (ClutterActor *self,
14202 ClutterActorFlags flags)
14204 ClutterActorFlags old_flags;
14206 gboolean was_reactive_set, reactive_set;
14207 gboolean was_realized_set, realized_set;
14208 gboolean was_mapped_set, mapped_set;
14209 gboolean was_visible_set, visible_set;
14211 g_return_if_fail (CLUTTER_IS_ACTOR (self));
14213 if (self->flags == flags)
14216 obj = G_OBJECT (self);
14217 g_object_ref (obj);
14218 g_object_freeze_notify (obj);
14220 old_flags = self->flags;
14222 was_reactive_set = ((old_flags & CLUTTER_ACTOR_REACTIVE) != 0);
14223 was_realized_set = ((old_flags & CLUTTER_ACTOR_REALIZED) != 0);
14224 was_mapped_set = ((old_flags & CLUTTER_ACTOR_MAPPED) != 0);
14225 was_visible_set = ((old_flags & CLUTTER_ACTOR_VISIBLE) != 0);
14227 self->flags |= flags;
14229 reactive_set = ((self->flags & CLUTTER_ACTOR_REACTIVE) != 0);
14230 realized_set = ((self->flags & CLUTTER_ACTOR_REALIZED) != 0);
14231 mapped_set = ((self->flags & CLUTTER_ACTOR_MAPPED) != 0);
14232 visible_set = ((self->flags & CLUTTER_ACTOR_VISIBLE) != 0);
14234 if (reactive_set != was_reactive_set)
14235 g_object_notify_by_pspec (obj, obj_props[PROP_REACTIVE]);
14237 if (realized_set != was_realized_set)
14238 g_object_notify_by_pspec (obj, obj_props[PROP_REALIZED]);
14240 if (mapped_set != was_mapped_set)
14241 g_object_notify_by_pspec (obj, obj_props[PROP_MAPPED]);
14243 if (visible_set != was_visible_set)
14244 g_object_notify_by_pspec (obj, obj_props[PROP_VISIBLE]);
14246 g_object_thaw_notify (obj);
14247 g_object_unref (obj);
14251 * clutter_actor_unset_flags:
14252 * @self: a #ClutterActor
14253 * @flags: the flags to unset
14255 * Unsets @flags on @self
14257 * This function will emit notifications for the changed properties
14262 clutter_actor_unset_flags (ClutterActor *self,
14263 ClutterActorFlags flags)
14265 ClutterActorFlags old_flags;
14267 gboolean was_reactive_set, reactive_set;
14268 gboolean was_realized_set, realized_set;
14269 gboolean was_mapped_set, mapped_set;
14270 gboolean was_visible_set, visible_set;
14272 g_return_if_fail (CLUTTER_IS_ACTOR (self));
14274 obj = G_OBJECT (self);
14275 g_object_freeze_notify (obj);
14277 old_flags = self->flags;
14279 was_reactive_set = ((old_flags & CLUTTER_ACTOR_REACTIVE) != 0);
14280 was_realized_set = ((old_flags & CLUTTER_ACTOR_REALIZED) != 0);
14281 was_mapped_set = ((old_flags & CLUTTER_ACTOR_MAPPED) != 0);
14282 was_visible_set = ((old_flags & CLUTTER_ACTOR_VISIBLE) != 0);
14284 self->flags &= ~flags;
14286 if (self->flags == old_flags)
14289 reactive_set = ((self->flags & CLUTTER_ACTOR_REACTIVE) != 0);
14290 realized_set = ((self->flags & CLUTTER_ACTOR_REALIZED) != 0);
14291 mapped_set = ((self->flags & CLUTTER_ACTOR_MAPPED) != 0);
14292 visible_set = ((self->flags & CLUTTER_ACTOR_VISIBLE) != 0);
14294 if (reactive_set != was_reactive_set)
14295 g_object_notify_by_pspec (obj, obj_props[PROP_REACTIVE]);
14297 if (realized_set != was_realized_set)
14298 g_object_notify_by_pspec (obj, obj_props[PROP_REALIZED]);
14300 if (mapped_set != was_mapped_set)
14301 g_object_notify_by_pspec (obj, obj_props[PROP_MAPPED]);
14303 if (visible_set != was_visible_set)
14304 g_object_notify_by_pspec (obj, obj_props[PROP_VISIBLE]);
14306 g_object_thaw_notify (obj);
14310 * clutter_actor_get_transformation_matrix:
14311 * @self: a #ClutterActor
14312 * @matrix: (out caller-allocates): the return location for a #CoglMatrix
14314 * Retrieves the transformations applied to @self relative to its
14320 clutter_actor_get_transformation_matrix (ClutterActor *self,
14321 CoglMatrix *matrix)
14323 g_return_if_fail (CLUTTER_IS_ACTOR (self));
14325 cogl_matrix_init_identity (matrix);
14327 _clutter_actor_apply_modelview_transform (self, matrix);
14331 _clutter_actor_set_in_clone_paint (ClutterActor *self,
14332 gboolean is_in_clone_paint)
14334 g_return_if_fail (CLUTTER_IS_ACTOR (self));
14335 self->priv->in_clone_paint = is_in_clone_paint;
14339 * clutter_actor_is_in_clone_paint:
14340 * @self: a #ClutterActor
14342 * Checks whether @self is being currently painted by a #ClutterClone
14344 * This function is useful only inside the ::paint virtual function
14345 * implementations or within handlers for the #ClutterActor::paint
14348 * This function should not be used by applications
14350 * Return value: %TRUE if the #ClutterActor is currently being painted
14351 * by a #ClutterClone, and %FALSE otherwise
14356 clutter_actor_is_in_clone_paint (ClutterActor *self)
14358 g_return_val_if_fail (CLUTTER_IS_ACTOR (self), FALSE);
14360 return self->priv->in_clone_paint;
14364 set_direction_recursive (ClutterActor *actor,
14365 gpointer user_data)
14367 ClutterTextDirection text_dir = GPOINTER_TO_INT (user_data);
14369 clutter_actor_set_text_direction (actor, text_dir);
14375 * clutter_actor_set_text_direction:
14376 * @self: a #ClutterActor
14377 * @text_dir: the text direction for @self
14379 * Sets the #ClutterTextDirection for an actor
14381 * The passed text direction must not be %CLUTTER_TEXT_DIRECTION_DEFAULT
14383 * If @self implements #ClutterContainer then this function will recurse
14384 * inside all the children of @self (including the internal ones).
14386 * Composite actors not implementing #ClutterContainer, or actors requiring
14387 * special handling when the text direction changes, should connect to
14388 * the #GObject::notify signal for the #ClutterActor:text-direction property
14393 clutter_actor_set_text_direction (ClutterActor *self,
14394 ClutterTextDirection text_dir)
14396 ClutterActorPrivate *priv;
14398 g_return_if_fail (CLUTTER_IS_ACTOR (self));
14399 g_return_if_fail (text_dir != CLUTTER_TEXT_DIRECTION_DEFAULT);
14403 if (priv->text_direction != text_dir)
14405 priv->text_direction = text_dir;
14407 /* we need to emit the notify::text-direction first, so that
14408 * the sub-classes can catch that and do specific handling of
14409 * the text direction; see clutter_text_direction_changed_cb()
14410 * inside clutter-text.c
14412 g_object_notify_by_pspec (G_OBJECT (self), obj_props[PROP_TEXT_DIRECTION]);
14414 _clutter_actor_foreach_child (self, set_direction_recursive,
14415 GINT_TO_POINTER (text_dir));
14417 clutter_actor_queue_relayout (self);
14422 _clutter_actor_set_has_pointer (ClutterActor *self,
14423 gboolean has_pointer)
14425 ClutterActorPrivate *priv = self->priv;
14427 if (priv->has_pointer != has_pointer)
14429 priv->has_pointer = has_pointer;
14431 g_object_notify_by_pspec (G_OBJECT (self), obj_props[PROP_HAS_POINTER]);
14436 * clutter_actor_get_text_direction:
14437 * @self: a #ClutterActor
14439 * Retrieves the value set using clutter_actor_set_text_direction()
14441 * If no text direction has been previously set, the default text
14442 * direction, as returned by clutter_get_default_text_direction(), will
14443 * be returned instead
14445 * Return value: the #ClutterTextDirection for the actor
14449 ClutterTextDirection
14450 clutter_actor_get_text_direction (ClutterActor *self)
14452 ClutterActorPrivate *priv;
14454 g_return_val_if_fail (CLUTTER_IS_ACTOR (self),
14455 CLUTTER_TEXT_DIRECTION_LTR);
14459 /* if no direction has been set yet use the default */
14460 if (priv->text_direction == CLUTTER_TEXT_DIRECTION_DEFAULT)
14461 priv->text_direction = clutter_get_default_text_direction ();
14463 return priv->text_direction;
14467 * clutter_actor_push_internal:
14468 * @self: a #ClutterActor
14470 * Should be used by actors implementing the #ClutterContainer and with
14471 * internal children added through clutter_actor_set_parent(), for instance:
14475 * my_actor_init (MyActor *self)
14477 * self->priv = SELF_ACTOR_GET_PRIVATE (self);
14479 * clutter_actor_push_internal (CLUTTER_ACTOR (self));
14481 * /* calling clutter_actor_set_parent() now will result in
14482 * * the internal flag being set on a child of MyActor
14485 * /* internal child - a background texture */
14486 * self->priv->background_tex = clutter_texture_new ();
14487 * clutter_actor_set_parent (self->priv->background_tex,
14488 * CLUTTER_ACTOR (self));
14490 * /* internal child - a label */
14491 * self->priv->label = clutter_text_new ();
14492 * clutter_actor_set_parent (self->priv->label,
14493 * CLUTTER_ACTOR (self));
14495 * clutter_actor_pop_internal (CLUTTER_ACTOR (self));
14497 * /* calling clutter_actor_set_parent() now will not result in
14498 * * the internal flag being set on a child of MyActor
14503 * This function will be used by Clutter to toggle an "internal child"
14504 * flag whenever clutter_actor_set_parent() is called; internal children
14505 * are handled differently by Clutter, specifically when destroying their
14508 * Call clutter_actor_pop_internal() when you finished adding internal
14511 * Nested calls to clutter_actor_push_internal() are allowed, but each
14512 * one must by followed by a clutter_actor_pop_internal() call.
14516 * Deprecated: 1.10: All children of an actor are accessible through
14517 * the #ClutterActor API, and #ClutterActor implements the
14518 * #ClutterContainer interface, so this function is only useful
14519 * for legacy containers overriding the default implementation.
14522 clutter_actor_push_internal (ClutterActor *self)
14524 g_return_if_fail (CLUTTER_IS_ACTOR (self));
14526 self->priv->internal_child += 1;
14530 * clutter_actor_pop_internal:
14531 * @self: a #ClutterActor
14533 * Disables the effects of clutter_actor_push_internal().
14537 * Deprecated: 1.10: All children of an actor are accessible through
14538 * the #ClutterActor API. This function is only useful for legacy
14539 * containers overriding the default implementation of the
14540 * #ClutterContainer interface.
14543 clutter_actor_pop_internal (ClutterActor *self)
14545 ClutterActorPrivate *priv;
14547 g_return_if_fail (CLUTTER_IS_ACTOR (self));
14551 if (priv->internal_child == 0)
14553 g_warning ("Mismatched %s: you need to call "
14554 "clutter_actor_push_composite() at least once before "
14555 "calling this function", G_STRFUNC);
14559 priv->internal_child -= 1;
14563 * clutter_actor_has_pointer:
14564 * @self: a #ClutterActor
14566 * Checks whether an actor contains the pointer of a
14567 * #ClutterInputDevice
14569 * Return value: %TRUE if the actor contains the pointer, and
14575 clutter_actor_has_pointer (ClutterActor *self)
14577 g_return_val_if_fail (CLUTTER_IS_ACTOR (self), FALSE);
14579 return self->priv->has_pointer;
14582 /* XXX: This is a workaround for not being able to break the ABI of
14583 * the QUEUE_REDRAW signal. It is an out-of-band argument. See
14584 * clutter_actor_queue_clipped_redraw() for details.
14586 ClutterPaintVolume *
14587 _clutter_actor_get_queue_redraw_clip (ClutterActor *self)
14589 return g_object_get_data (G_OBJECT (self),
14590 "-clutter-actor-queue-redraw-clip");
14594 _clutter_actor_set_queue_redraw_clip (ClutterActor *self,
14595 ClutterPaintVolume *clip)
14597 g_object_set_data (G_OBJECT (self),
14598 "-clutter-actor-queue-redraw-clip",
14603 * clutter_actor_has_allocation:
14604 * @self: a #ClutterActor
14606 * Checks if the actor has an up-to-date allocation assigned to
14607 * it. This means that the actor should have an allocation: it's
14608 * visible and has a parent. It also means that there is no
14609 * outstanding relayout request in progress for the actor or its
14610 * children (There might be other outstanding layout requests in
14611 * progress that will cause the actor to get a new allocation
14612 * when the stage is laid out, however).
14614 * If this function returns %FALSE, then the actor will normally
14615 * be allocated before it is next drawn on the screen.
14617 * Return value: %TRUE if the actor has an up-to-date allocation
14622 clutter_actor_has_allocation (ClutterActor *self)
14624 ClutterActorPrivate *priv;
14626 g_return_val_if_fail (CLUTTER_IS_ACTOR (self), FALSE);
14630 return priv->parent != NULL &&
14631 CLUTTER_ACTOR_IS_VISIBLE (self) &&
14632 !priv->needs_allocation;
14636 * clutter_actor_add_action:
14637 * @self: a #ClutterActor
14638 * @action: a #ClutterAction
14640 * Adds @action to the list of actions applied to @self
14642 * A #ClutterAction can only belong to one actor at a time
14644 * The #ClutterActor will hold a reference on @action until either
14645 * clutter_actor_remove_action() or clutter_actor_clear_actions()
14651 clutter_actor_add_action (ClutterActor *self,
14652 ClutterAction *action)
14654 ClutterActorPrivate *priv;
14656 g_return_if_fail (CLUTTER_IS_ACTOR (self));
14657 g_return_if_fail (CLUTTER_IS_ACTION (action));
14661 if (priv->actions == NULL)
14663 priv->actions = g_object_new (CLUTTER_TYPE_META_GROUP, NULL);
14664 priv->actions->actor = self;
14667 _clutter_meta_group_add_meta (priv->actions, CLUTTER_ACTOR_META (action));
14669 g_object_notify_by_pspec (G_OBJECT (self), obj_props[PROP_ACTIONS]);
14673 * clutter_actor_add_action_with_name:
14674 * @self: a #ClutterActor
14675 * @name: the name to set on the action
14676 * @action: a #ClutterAction
14678 * A convenience function for setting the name of a #ClutterAction
14679 * while adding it to the list of actions applied to @self
14681 * This function is the logical equivalent of:
14684 * clutter_actor_meta_set_name (CLUTTER_ACTOR_META (action), name);
14685 * clutter_actor_add_action (self, action);
14691 clutter_actor_add_action_with_name (ClutterActor *self,
14693 ClutterAction *action)
14695 g_return_if_fail (CLUTTER_IS_ACTOR (self));
14696 g_return_if_fail (name != NULL);
14697 g_return_if_fail (CLUTTER_IS_ACTION (action));
14699 clutter_actor_meta_set_name (CLUTTER_ACTOR_META (action), name);
14700 clutter_actor_add_action (self, action);
14704 * clutter_actor_remove_action:
14705 * @self: a #ClutterActor
14706 * @action: a #ClutterAction
14708 * Removes @action from the list of actions applied to @self
14710 * The reference held by @self on the #ClutterAction will be released
14715 clutter_actor_remove_action (ClutterActor *self,
14716 ClutterAction *action)
14718 ClutterActorPrivate *priv;
14720 g_return_if_fail (CLUTTER_IS_ACTOR (self));
14721 g_return_if_fail (CLUTTER_IS_ACTION (action));
14725 if (priv->actions == NULL)
14728 _clutter_meta_group_remove_meta (priv->actions, CLUTTER_ACTOR_META (action));
14730 g_object_notify_by_pspec (G_OBJECT (self), obj_props[PROP_ACTIONS]);
14734 * clutter_actor_remove_action_by_name:
14735 * @self: a #ClutterActor
14736 * @name: the name of the action to remove
14738 * Removes the #ClutterAction with the given name from the list
14739 * of actions applied to @self
14744 clutter_actor_remove_action_by_name (ClutterActor *self,
14747 ClutterActorPrivate *priv;
14748 ClutterActorMeta *meta;
14750 g_return_if_fail (CLUTTER_IS_ACTOR (self));
14751 g_return_if_fail (name != NULL);
14755 if (priv->actions == NULL)
14758 meta = _clutter_meta_group_get_meta (priv->actions, name);
14762 _clutter_meta_group_remove_meta (priv->actions, meta);
14764 g_object_notify_by_pspec (G_OBJECT (self), obj_props[PROP_ACTIONS]);
14768 * clutter_actor_get_actions:
14769 * @self: a #ClutterActor
14771 * Retrieves the list of actions applied to @self
14773 * Return value: (transfer container) (element-type Clutter.Action): a copy
14774 * of the list of #ClutterAction<!-- -->s. The contents of the list are
14775 * owned by the #ClutterActor. Use g_list_free() to free the resources
14776 * allocated by the returned #GList
14781 clutter_actor_get_actions (ClutterActor *self)
14783 g_return_val_if_fail (CLUTTER_IS_ACTOR (self), NULL);
14785 if (self->priv->actions == NULL)
14788 return _clutter_meta_group_get_metas_no_internal (self->priv->actions);
14792 * clutter_actor_get_action:
14793 * @self: a #ClutterActor
14794 * @name: the name of the action to retrieve
14796 * Retrieves the #ClutterAction with the given name in the list
14797 * of actions applied to @self
14799 * Return value: (transfer none): a #ClutterAction for the given
14800 * name, or %NULL. The returned #ClutterAction is owned by the
14801 * actor and it should not be unreferenced directly
14806 clutter_actor_get_action (ClutterActor *self,
14809 g_return_val_if_fail (CLUTTER_IS_ACTOR (self), NULL);
14810 g_return_val_if_fail (name != NULL, NULL);
14812 if (self->priv->actions == NULL)
14815 return CLUTTER_ACTION (_clutter_meta_group_get_meta (self->priv->actions, name));
14819 * clutter_actor_clear_actions:
14820 * @self: a #ClutterActor
14822 * Clears the list of actions applied to @self
14827 clutter_actor_clear_actions (ClutterActor *self)
14829 g_return_if_fail (CLUTTER_IS_ACTOR (self));
14831 if (self->priv->actions == NULL)
14834 _clutter_meta_group_clear_metas_no_internal (self->priv->actions);
14838 * clutter_actor_add_constraint:
14839 * @self: a #ClutterActor
14840 * @constraint: a #ClutterConstraint
14842 * Adds @constraint to the list of #ClutterConstraint<!-- -->s applied
14845 * The #ClutterActor will hold a reference on the @constraint until
14846 * either clutter_actor_remove_constraint() or
14847 * clutter_actor_clear_constraints() is called.
14852 clutter_actor_add_constraint (ClutterActor *self,
14853 ClutterConstraint *constraint)
14855 ClutterActorPrivate *priv;
14857 g_return_if_fail (CLUTTER_IS_ACTOR (self));
14858 g_return_if_fail (CLUTTER_IS_CONSTRAINT (constraint));
14862 if (priv->constraints == NULL)
14864 priv->constraints = g_object_new (CLUTTER_TYPE_META_GROUP, NULL);
14865 priv->constraints->actor = self;
14868 _clutter_meta_group_add_meta (priv->constraints,
14869 CLUTTER_ACTOR_META (constraint));
14870 clutter_actor_queue_relayout (self);
14872 g_object_notify_by_pspec (G_OBJECT (self), obj_props[PROP_CONSTRAINTS]);
14876 * clutter_actor_add_constraint_with_name:
14877 * @self: a #ClutterActor
14878 * @name: the name to set on the constraint
14879 * @constraint: a #ClutterConstraint
14881 * A convenience function for setting the name of a #ClutterConstraint
14882 * while adding it to the list of constraints applied to @self
14884 * This function is the logical equivalent of:
14887 * clutter_actor_meta_set_name (CLUTTER_ACTOR_META (constraint), name);
14888 * clutter_actor_add_constraint (self, constraint);
14894 clutter_actor_add_constraint_with_name (ClutterActor *self,
14896 ClutterConstraint *constraint)
14898 g_return_if_fail (CLUTTER_IS_ACTOR (self));
14899 g_return_if_fail (name != NULL);
14900 g_return_if_fail (CLUTTER_IS_CONSTRAINT (constraint));
14902 clutter_actor_meta_set_name (CLUTTER_ACTOR_META (constraint), name);
14903 clutter_actor_add_constraint (self, constraint);
14907 * clutter_actor_remove_constraint:
14908 * @self: a #ClutterActor
14909 * @constraint: a #ClutterConstraint
14911 * Removes @constraint from the list of constraints applied to @self
14913 * The reference held by @self on the #ClutterConstraint will be released
14918 clutter_actor_remove_constraint (ClutterActor *self,
14919 ClutterConstraint *constraint)
14921 ClutterActorPrivate *priv;
14923 g_return_if_fail (CLUTTER_IS_ACTOR (self));
14924 g_return_if_fail (CLUTTER_IS_CONSTRAINT (constraint));
14928 if (priv->constraints == NULL)
14931 _clutter_meta_group_remove_meta (priv->constraints,
14932 CLUTTER_ACTOR_META (constraint));
14933 clutter_actor_queue_relayout (self);
14935 g_object_notify_by_pspec (G_OBJECT (self), obj_props[PROP_CONSTRAINTS]);
14939 * clutter_actor_remove_constraint_by_name:
14940 * @self: a #ClutterActor
14941 * @name: the name of the constraint to remove
14943 * Removes the #ClutterConstraint with the given name from the list
14944 * of constraints applied to @self
14949 clutter_actor_remove_constraint_by_name (ClutterActor *self,
14952 ClutterActorPrivate *priv;
14953 ClutterActorMeta *meta;
14955 g_return_if_fail (CLUTTER_IS_ACTOR (self));
14956 g_return_if_fail (name != NULL);
14960 if (priv->constraints == NULL)
14963 meta = _clutter_meta_group_get_meta (priv->constraints, name);
14967 _clutter_meta_group_remove_meta (priv->constraints, meta);
14968 clutter_actor_queue_relayout (self);
14972 * clutter_actor_get_constraints:
14973 * @self: a #ClutterActor
14975 * Retrieves the list of constraints applied to @self
14977 * Return value: (transfer container) (element-type Clutter.Constraint): a copy
14978 * of the list of #ClutterConstraint<!-- -->s. The contents of the list are
14979 * owned by the #ClutterActor. Use g_list_free() to free the resources
14980 * allocated by the returned #GList
14985 clutter_actor_get_constraints (ClutterActor *self)
14987 g_return_val_if_fail (CLUTTER_IS_ACTOR (self), NULL);
14989 if (self->priv->constraints == NULL)
14992 return _clutter_meta_group_get_metas_no_internal (self->priv->constraints);
14996 * clutter_actor_get_constraint:
14997 * @self: a #ClutterActor
14998 * @name: the name of the constraint to retrieve
15000 * Retrieves the #ClutterConstraint with the given name in the list
15001 * of constraints applied to @self
15003 * Return value: (transfer none): a #ClutterConstraint for the given
15004 * name, or %NULL. The returned #ClutterConstraint is owned by the
15005 * actor and it should not be unreferenced directly
15009 ClutterConstraint *
15010 clutter_actor_get_constraint (ClutterActor *self,
15013 g_return_val_if_fail (CLUTTER_IS_ACTOR (self), NULL);
15014 g_return_val_if_fail (name != NULL, NULL);
15016 if (self->priv->constraints == NULL)
15019 return CLUTTER_CONSTRAINT (_clutter_meta_group_get_meta (self->priv->constraints, name));
15023 * clutter_actor_clear_constraints:
15024 * @self: a #ClutterActor
15026 * Clears the list of constraints applied to @self
15031 clutter_actor_clear_constraints (ClutterActor *self)
15033 g_return_if_fail (CLUTTER_IS_ACTOR (self));
15035 if (self->priv->constraints == NULL)
15038 _clutter_meta_group_clear_metas_no_internal (self->priv->constraints);
15040 clutter_actor_queue_relayout (self);
15044 * clutter_actor_set_clip_to_allocation:
15045 * @self: a #ClutterActor
15046 * @clip_set: %TRUE to apply a clip tracking the allocation
15048 * Sets whether @self should be clipped to the same size as its
15054 clutter_actor_set_clip_to_allocation (ClutterActor *self,
15057 ClutterActorPrivate *priv;
15059 g_return_if_fail (CLUTTER_IS_ACTOR (self));
15061 clip_set = !!clip_set;
15065 if (priv->clip_to_allocation != clip_set)
15067 priv->clip_to_allocation = clip_set;
15069 clutter_actor_queue_redraw (self);
15071 g_object_notify_by_pspec (G_OBJECT (self), obj_props[PROP_CLIP_TO_ALLOCATION]);
15076 * clutter_actor_get_clip_to_allocation:
15077 * @self: a #ClutterActor
15079 * Retrieves the value set using clutter_actor_set_clip_to_allocation()
15081 * Return value: %TRUE if the #ClutterActor is clipped to its allocation
15086 clutter_actor_get_clip_to_allocation (ClutterActor *self)
15088 g_return_val_if_fail (CLUTTER_IS_ACTOR (self), FALSE);
15090 return self->priv->clip_to_allocation;
15094 * clutter_actor_add_effect:
15095 * @self: a #ClutterActor
15096 * @effect: a #ClutterEffect
15098 * Adds @effect to the list of #ClutterEffect<!-- -->s applied to @self
15100 * The #ClutterActor will hold a reference on the @effect until either
15101 * clutter_actor_remove_effect() or clutter_actor_clear_effects() is
15107 clutter_actor_add_effect (ClutterActor *self,
15108 ClutterEffect *effect)
15110 g_return_if_fail (CLUTTER_IS_ACTOR (self));
15111 g_return_if_fail (CLUTTER_IS_EFFECT (effect));
15113 _clutter_actor_add_effect_internal (self, effect);
15115 clutter_actor_queue_redraw (self);
15117 g_object_notify_by_pspec (G_OBJECT (self), obj_props[PROP_EFFECT]);
15121 * clutter_actor_add_effect_with_name:
15122 * @self: a #ClutterActor
15123 * @name: the name to set on the effect
15124 * @effect: a #ClutterEffect
15126 * A convenience function for setting the name of a #ClutterEffect
15127 * while adding it to the list of effectss applied to @self
15129 * This function is the logical equivalent of:
15132 * clutter_actor_meta_set_name (CLUTTER_ACTOR_META (effect), name);
15133 * clutter_actor_add_effect (self, effect);
15139 clutter_actor_add_effect_with_name (ClutterActor *self,
15141 ClutterEffect *effect)
15143 g_return_if_fail (CLUTTER_IS_ACTOR (self));
15144 g_return_if_fail (name != NULL);
15145 g_return_if_fail (CLUTTER_IS_EFFECT (effect));
15147 clutter_actor_meta_set_name (CLUTTER_ACTOR_META (effect), name);
15148 clutter_actor_add_effect (self, effect);
15152 * clutter_actor_remove_effect:
15153 * @self: a #ClutterActor
15154 * @effect: a #ClutterEffect
15156 * Removes @effect from the list of effects applied to @self
15158 * The reference held by @self on the #ClutterEffect will be released
15163 clutter_actor_remove_effect (ClutterActor *self,
15164 ClutterEffect *effect)
15166 g_return_if_fail (CLUTTER_IS_ACTOR (self));
15167 g_return_if_fail (CLUTTER_IS_EFFECT (effect));
15169 _clutter_actor_remove_effect_internal (self, effect);
15171 clutter_actor_queue_redraw (self);
15173 g_object_notify_by_pspec (G_OBJECT (self), obj_props[PROP_EFFECT]);
15177 * clutter_actor_remove_effect_by_name:
15178 * @self: a #ClutterActor
15179 * @name: the name of the effect to remove
15181 * Removes the #ClutterEffect with the given name from the list
15182 * of effects applied to @self
15187 clutter_actor_remove_effect_by_name (ClutterActor *self,
15190 ClutterActorPrivate *priv;
15191 ClutterActorMeta *meta;
15193 g_return_if_fail (CLUTTER_IS_ACTOR (self));
15194 g_return_if_fail (name != NULL);
15198 if (priv->effects == NULL)
15201 meta = _clutter_meta_group_get_meta (priv->effects, name);
15205 clutter_actor_remove_effect (self, CLUTTER_EFFECT (meta));
15209 * clutter_actor_get_effects:
15210 * @self: a #ClutterActor
15212 * Retrieves the #ClutterEffect<!-- -->s applied on @self, if any
15214 * Return value: (transfer container) (element-type Clutter.Effect): a list
15215 * of #ClutterEffect<!-- -->s, or %NULL. The elements of the returned
15216 * list are owned by Clutter and they should not be freed. You should
15217 * free the returned list using g_list_free() when done
15222 clutter_actor_get_effects (ClutterActor *self)
15224 ClutterActorPrivate *priv;
15226 g_return_val_if_fail (CLUTTER_IS_ACTOR (self), NULL);
15230 if (priv->effects == NULL)
15233 return _clutter_meta_group_get_metas_no_internal (priv->effects);
15237 * clutter_actor_get_effect:
15238 * @self: a #ClutterActor
15239 * @name: the name of the effect to retrieve
15241 * Retrieves the #ClutterEffect with the given name in the list
15242 * of effects applied to @self
15244 * Return value: (transfer none): a #ClutterEffect for the given
15245 * name, or %NULL. The returned #ClutterEffect is owned by the
15246 * actor and it should not be unreferenced directly
15251 clutter_actor_get_effect (ClutterActor *self,
15254 g_return_val_if_fail (CLUTTER_IS_ACTOR (self), NULL);
15255 g_return_val_if_fail (name != NULL, NULL);
15257 if (self->priv->effects == NULL)
15260 return CLUTTER_EFFECT (_clutter_meta_group_get_meta (self->priv->effects, name));
15264 * clutter_actor_clear_effects:
15265 * @self: a #ClutterActor
15267 * Clears the list of effects applied to @self
15272 clutter_actor_clear_effects (ClutterActor *self)
15274 g_return_if_fail (CLUTTER_IS_ACTOR (self));
15276 if (self->priv->effects == NULL)
15279 _clutter_meta_group_clear_metas_no_internal (self->priv->effects);
15281 clutter_actor_queue_redraw (self);
15285 * clutter_actor_has_key_focus:
15286 * @self: a #ClutterActor
15288 * Checks whether @self is the #ClutterActor that has key focus
15290 * Return value: %TRUE if the actor has key focus, and %FALSE otherwise
15295 clutter_actor_has_key_focus (ClutterActor *self)
15297 ClutterActor *stage;
15299 g_return_val_if_fail (CLUTTER_IS_ACTOR (self), FALSE);
15301 stage = _clutter_actor_get_stage_internal (self);
15305 return clutter_stage_get_key_focus (CLUTTER_STAGE (stage)) == self;
15309 _clutter_actor_get_paint_volume_real (ClutterActor *self,
15310 ClutterPaintVolume *pv)
15312 ClutterActorPrivate *priv = self->priv;
15314 /* Actors are only expected to report a valid paint volume
15315 * while they have a valid allocation. */
15316 if (G_UNLIKELY (priv->needs_allocation))
15318 CLUTTER_NOTE (CLIPPING, "Bail from get_paint_volume (%s): "
15319 "Actor needs allocation",
15320 _clutter_actor_get_debug_name (self));
15324 /* Check if there are any handlers connected to the paint
15325 * signal. If there are then all bets are off for what the paint
15326 * volume for this actor might possibly be!
15328 * XXX: It's expected that this is going to end up being quite a
15329 * costly check to have to do here, but we haven't come up with
15330 * another solution that can reliably catch paint signal handlers at
15331 * the right time to either avoid artefacts due to invalid stage
15332 * clipping or due to incorrect culling.
15334 * Previously we checked in clutter_actor_paint(), but at that time
15335 * we may already be using a stage clip that could be derived from
15336 * an invalid paint-volume. We used to try and handle that by
15337 * queuing a follow up, unclipped, redraw but still the previous
15338 * checking wasn't enough to catch invalid volumes involved in
15339 * culling (considering that containers may derive their volume from
15340 * children that haven't yet been painted)
15342 * Longer term, improved solutions could be:
15343 * - Disallow painting in the paint signal, only allow using it
15344 * for tracking when paints happen. We can add another API that
15345 * allows monkey patching the paint of arbitrary actors but in a
15346 * more controlled way and that also supports modifying the
15348 * - If we could be notified somehow when signal handlers are
15349 * connected we wouldn't have to poll for handlers like this.
15351 if (g_signal_has_handler_pending (self,
15352 actor_signals[PAINT],
15356 CLUTTER_NOTE (CLIPPING, "Bail from get_paint_volume (%s): "
15357 "Actor has \"paint\" signal handlers",
15358 _clutter_actor_get_debug_name (self));
15362 _clutter_paint_volume_init_static (pv, self);
15364 if (!CLUTTER_ACTOR_GET_CLASS (self)->get_paint_volume (self, pv))
15366 clutter_paint_volume_free (pv);
15367 CLUTTER_NOTE (CLIPPING, "Bail from get_paint_volume (%s): "
15368 "Actor failed to report a volume",
15369 _clutter_actor_get_debug_name (self));
15373 /* since effects can modify the paint volume, we allow them to actually
15374 * do this by making get_paint_volume() "context sensitive"
15376 if (priv->effects != NULL)
15378 if (priv->current_effect != NULL)
15380 const GList *effects, *l;
15382 /* if we are being called from within the paint sequence of
15383 * an actor, get the paint volume up to the current effect
15385 effects = _clutter_meta_group_peek_metas (priv->effects);
15387 l != NULL || (l != NULL && l->data != priv->current_effect);
15390 if (!_clutter_effect_get_paint_volume (l->data, pv))
15392 clutter_paint_volume_free (pv);
15393 CLUTTER_NOTE (CLIPPING, "Bail from get_paint_volume (%s): "
15394 "Effect (%s) failed to report a volume",
15395 _clutter_actor_get_debug_name (self),
15396 _clutter_actor_meta_get_debug_name (l->data));
15403 const GList *effects, *l;
15405 /* otherwise, get the cumulative volume */
15406 effects = _clutter_meta_group_peek_metas (priv->effects);
15407 for (l = effects; l != NULL; l = l->next)
15408 if (!_clutter_effect_get_paint_volume (l->data, pv))
15410 clutter_paint_volume_free (pv);
15411 CLUTTER_NOTE (CLIPPING, "Bail from get_paint_volume (%s): "
15412 "Effect (%s) failed to report a volume",
15413 _clutter_actor_get_debug_name (self),
15414 _clutter_actor_meta_get_debug_name (l->data));
15423 /* The public clutter_actor_get_paint_volume API returns a const
15424 * pointer since we return a pointer directly to the cached
15425 * PaintVolume associated with the actor and don't want the user to
15426 * inadvertently modify it, but for internal uses we sometimes need
15427 * access to the same PaintVolume but need to apply some book-keeping
15428 * modifications to it so we don't want a const pointer.
15430 static ClutterPaintVolume *
15431 _clutter_actor_get_paint_volume_mutable (ClutterActor *self)
15433 ClutterActorPrivate *priv;
15437 if (priv->paint_volume_valid)
15438 clutter_paint_volume_free (&priv->paint_volume);
15440 if (_clutter_actor_get_paint_volume_real (self, &priv->paint_volume))
15442 priv->paint_volume_valid = TRUE;
15443 return &priv->paint_volume;
15447 priv->paint_volume_valid = FALSE;
15453 * clutter_actor_get_paint_volume:
15454 * @self: a #ClutterActor
15456 * Retrieves the paint volume of the passed #ClutterActor, or %NULL
15457 * when a paint volume can't be determined.
15459 * The paint volume is defined as the 3D space occupied by an actor
15460 * when being painted.
15462 * This function will call the <function>get_paint_volume()</function>
15463 * virtual function of the #ClutterActor class. Sub-classes of #ClutterActor
15464 * should not usually care about overriding the default implementation,
15465 * unless they are, for instance: painting outside their allocation, or
15466 * actors with a depth factor (not in terms of #ClutterActor:depth but real
15469 * <note>2D actors overriding <function>get_paint_volume()</function>
15470 * ensure their volume has a depth of 0. (This will be true so long as
15471 * you don't call clutter_paint_volume_set_depth().)</note>
15473 * Return value: (transfer none): a pointer to a #ClutterPaintVolume,
15474 * or %NULL if no volume could be determined. The returned pointer
15475 * is not guaranteed to be valid across multiple frames; if you want
15476 * to keep it, you will need to copy it using clutter_paint_volume_copy().
15480 const ClutterPaintVolume *
15481 clutter_actor_get_paint_volume (ClutterActor *self)
15483 g_return_val_if_fail (CLUTTER_IS_ACTOR (self), NULL);
15485 return _clutter_actor_get_paint_volume_mutable (self);
15489 * clutter_actor_get_transformed_paint_volume:
15490 * @self: a #ClutterActor
15491 * @relative_to_ancestor: A #ClutterActor that is an ancestor of @self
15492 * (or %NULL for the stage)
15494 * Retrieves the 3D paint volume of an actor like
15495 * clutter_actor_get_paint_volume() does (Please refer to the
15496 * documentation of clutter_actor_get_paint_volume() for more
15497 * details.) and it additionally transforms the paint volume into the
15498 * coordinate space of @relative_to_ancestor. (Or the stage if %NULL
15499 * is passed for @relative_to_ancestor)
15501 * This can be used by containers that base their paint volume on
15502 * the volume of their children. Such containers can query the
15503 * transformed paint volume of all of its children and union them
15504 * together using clutter_paint_volume_union().
15506 * Return value: (transfer none): a pointer to a #ClutterPaintVolume,
15507 * or %NULL if no volume could be determined. The returned pointer is
15508 * not guaranteed to be valid across multiple frames; if you wish to
15509 * keep it, you will have to copy it using clutter_paint_volume_copy().
15513 const ClutterPaintVolume *
15514 clutter_actor_get_transformed_paint_volume (ClutterActor *self,
15515 ClutterActor *relative_to_ancestor)
15517 const ClutterPaintVolume *volume;
15518 ClutterActor *stage;
15519 ClutterPaintVolume *transformed_volume;
15521 stage = _clutter_actor_get_stage_internal (self);
15522 if (G_UNLIKELY (stage == NULL))
15525 if (relative_to_ancestor == NULL)
15526 relative_to_ancestor = stage;
15528 volume = clutter_actor_get_paint_volume (self);
15529 if (volume == NULL)
15532 transformed_volume =
15533 _clutter_stage_paint_volume_stack_allocate (CLUTTER_STAGE (stage));
15535 _clutter_paint_volume_copy_static (volume, transformed_volume);
15537 _clutter_paint_volume_transform_relative (transformed_volume,
15538 relative_to_ancestor);
15540 return transformed_volume;
15544 * clutter_actor_get_paint_box:
15545 * @self: a #ClutterActor
15546 * @box: (out): return location for a #ClutterActorBox
15548 * Retrieves the paint volume of the passed #ClutterActor, and
15549 * transforms it into a 2D bounding box in stage coordinates.
15551 * This function is useful to determine the on screen area occupied by
15552 * the actor. The box is only an approximation and may often be
15553 * considerably larger due to the optimizations used to calculate the
15554 * box. The box is never smaller though, so it can reliably be used
15557 * There are times when a 2D paint box can't be determined, e.g.
15558 * because the actor isn't yet parented under a stage or because
15559 * the actor is unable to determine a paint volume.
15561 * Return value: %TRUE if a 2D paint box could be determined, else
15567 clutter_actor_get_paint_box (ClutterActor *self,
15568 ClutterActorBox *box)
15570 ClutterActor *stage;
15571 ClutterPaintVolume *pv;
15573 g_return_val_if_fail (CLUTTER_IS_ACTOR (self), FALSE);
15574 g_return_val_if_fail (box != NULL, FALSE);
15576 stage = _clutter_actor_get_stage_internal (self);
15577 if (G_UNLIKELY (!stage))
15580 pv = _clutter_actor_get_paint_volume_mutable (self);
15581 if (G_UNLIKELY (!pv))
15584 _clutter_paint_volume_get_stage_paint_box (pv, CLUTTER_STAGE (stage), box);
15590 * clutter_actor_has_overlaps:
15591 * @self: A #ClutterActor
15593 * Asks the actor's implementation whether it may contain overlapping
15596 * For example; Clutter may use this to determine whether the painting
15597 * should be redirected to an offscreen buffer to correctly implement
15598 * the opacity property.
15600 * Custom actors can override the default response by implementing the
15601 * #ClutterActor <function>has_overlaps</function> virtual function. See
15602 * clutter_actor_set_offscreen_redirect() for more information.
15604 * Return value: %TRUE if the actor may have overlapping primitives, and
15610 clutter_actor_has_overlaps (ClutterActor *self)
15612 g_return_val_if_fail (CLUTTER_IS_ACTOR (self), TRUE);
15614 return CLUTTER_ACTOR_GET_CLASS (self)->has_overlaps (self);
15618 * clutter_actor_has_effects:
15619 * @self: A #ClutterActor
15621 * Returns whether the actor has any effects applied.
15623 * Return value: %TRUE if the actor has any effects,
15629 clutter_actor_has_effects (ClutterActor *self)
15631 g_return_val_if_fail (CLUTTER_IS_ACTOR (self), TRUE);
15633 if (self->priv->effects == NULL)
15636 return _clutter_meta_group_has_metas_no_internal (self->priv->effects);
15640 * clutter_actor_has_constraints:
15641 * @self: A #ClutterActor
15643 * Returns whether the actor has any constraints applied.
15645 * Return value: %TRUE if the actor has any constraints,
15651 clutter_actor_has_constraints (ClutterActor *self)
15653 g_return_val_if_fail (CLUTTER_IS_ACTOR (self), TRUE);
15655 return self->priv->constraints != NULL;
15659 * clutter_actor_has_actions:
15660 * @self: A #ClutterActor
15662 * Returns whether the actor has any actions applied.
15664 * Return value: %TRUE if the actor has any actions,
15670 clutter_actor_has_actions (ClutterActor *self)
15672 g_return_val_if_fail (CLUTTER_IS_ACTOR (self), TRUE);
15674 return self->priv->actions != NULL;
15678 * clutter_actor_get_n_children:
15679 * @self: a #ClutterActor
15681 * Retrieves the number of children of @self.
15683 * Return value: the number of children of an actor
15688 clutter_actor_get_n_children (ClutterActor *self)
15690 g_return_val_if_fail (CLUTTER_IS_ACTOR (self), 0);
15692 return self->priv->n_children;
15696 * clutter_actor_get_child_at_index:
15697 * @self: a #ClutterActor
15698 * @index_: the position in the list of children
15700 * Retrieves the actor at the given @index_ inside the list of
15701 * children of @self.
15703 * Return value: (transfer none): a pointer to a #ClutterActor, or %NULL
15708 clutter_actor_get_child_at_index (ClutterActor *self,
15711 ClutterActor *iter;
15714 g_return_val_if_fail (CLUTTER_IS_ACTOR (self), NULL);
15715 g_return_val_if_fail (index_ <= self->priv->n_children, NULL);
15717 for (iter = self->priv->first_child, i = 0;
15718 iter != NULL && i < index_;
15719 iter = iter->priv->next_sibling, i += 1)
15726 * _clutter_actor_foreach_child:
15727 * @actor: The actor whos children you want to iterate
15728 * @callback: The function to call for each child
15729 * @user_data: Private data to pass to @callback
15731 * Calls a given @callback once for each child of the specified @actor and
15732 * passing the @user_data pointer each time.
15734 * Return value: returns %TRUE if all children were iterated, else
15735 * %FALSE if a callback broke out of iteration early.
15738 _clutter_actor_foreach_child (ClutterActor *self,
15739 ClutterForeachCallback callback,
15740 gpointer user_data)
15742 ClutterActorPrivate *priv = self->priv;
15743 ClutterActor *iter;
15746 for (cont = TRUE, iter = priv->first_child;
15747 cont && iter != NULL;
15748 iter = iter->priv->next_sibling)
15750 cont = callback (iter, user_data);
15757 /* For debugging purposes this gives us a simple way to print out
15758 * the scenegraph e.g in gdb using:
15760 * _clutter_actor_traverse (stage,
15762 * clutter_debug_print_actor_cb,
15767 static ClutterActorTraverseVisitFlags
15768 clutter_debug_print_actor_cb (ClutterActor *actor,
15772 g_print ("%*s%s:%p\n",
15774 _clutter_actor_get_debug_name (actor),
15777 return CLUTTER_ACTOR_TRAVERSE_VISIT_CONTINUE;
15782 _clutter_actor_traverse_breadth (ClutterActor *actor,
15783 ClutterTraverseCallback callback,
15784 gpointer user_data)
15786 GQueue *queue = g_queue_new ();
15787 ClutterActor dummy;
15788 int current_depth = 0;
15790 g_queue_push_tail (queue, actor);
15791 g_queue_push_tail (queue, &dummy); /* use to delimit depth changes */
15793 while ((actor = g_queue_pop_head (queue)))
15795 ClutterActorTraverseVisitFlags flags;
15797 if (actor == &dummy)
15800 g_queue_push_tail (queue, &dummy);
15804 flags = callback (actor, current_depth, user_data);
15805 if (flags & CLUTTER_ACTOR_TRAVERSE_VISIT_BREAK)
15807 else if (!(flags & CLUTTER_ACTOR_TRAVERSE_VISIT_SKIP_CHILDREN))
15809 ClutterActor *iter;
15811 for (iter = actor->priv->first_child;
15813 iter = iter->priv->next_sibling)
15815 g_queue_push_tail (queue, iter);
15820 g_queue_free (queue);
15823 static ClutterActorTraverseVisitFlags
15824 _clutter_actor_traverse_depth (ClutterActor *actor,
15825 ClutterTraverseCallback before_children_callback,
15826 ClutterTraverseCallback after_children_callback,
15828 gpointer user_data)
15830 ClutterActorTraverseVisitFlags flags;
15832 flags = before_children_callback (actor, current_depth, user_data);
15833 if (flags & CLUTTER_ACTOR_TRAVERSE_VISIT_BREAK)
15834 return CLUTTER_ACTOR_TRAVERSE_VISIT_BREAK;
15836 if (!(flags & CLUTTER_ACTOR_TRAVERSE_VISIT_SKIP_CHILDREN))
15838 ClutterActor *iter;
15840 for (iter = actor->priv->first_child;
15842 iter = iter->priv->next_sibling)
15844 flags = _clutter_actor_traverse_depth (iter,
15845 before_children_callback,
15846 after_children_callback,
15850 if (flags & CLUTTER_ACTOR_TRAVERSE_VISIT_BREAK)
15851 return CLUTTER_ACTOR_TRAVERSE_VISIT_BREAK;
15855 if (after_children_callback)
15856 return after_children_callback (actor, current_depth, user_data);
15858 return CLUTTER_ACTOR_TRAVERSE_VISIT_CONTINUE;
15861 /* _clutter_actor_traverse:
15862 * @actor: The actor to start traversing the graph from
15863 * @flags: These flags may affect how the traversal is done
15864 * @before_children_callback: A function to call before visiting the
15865 * children of the current actor.
15866 * @after_children_callback: A function to call after visiting the
15867 * children of the current actor. (Ignored if
15868 * %CLUTTER_ACTOR_TRAVERSE_BREADTH_FIRST is passed to @flags.)
15869 * @user_data: The private data to pass to the callbacks
15871 * Traverses the scenegraph starting at the specified @actor and
15872 * descending through all its children and its children's children.
15873 * For each actor traversed @before_children_callback and
15874 * @after_children_callback are called with the specified
15875 * @user_data, before and after visiting that actor's children.
15877 * The callbacks can return flags that affect the ongoing traversal
15878 * such as by skipping over an actors children or bailing out of
15879 * any further traversing.
15882 _clutter_actor_traverse (ClutterActor *actor,
15883 ClutterActorTraverseFlags flags,
15884 ClutterTraverseCallback before_children_callback,
15885 ClutterTraverseCallback after_children_callback,
15886 gpointer user_data)
15888 if (flags & CLUTTER_ACTOR_TRAVERSE_BREADTH_FIRST)
15889 _clutter_actor_traverse_breadth (actor,
15890 before_children_callback,
15892 else /* DEPTH_FIRST */
15893 _clutter_actor_traverse_depth (actor,
15894 before_children_callback,
15895 after_children_callback,
15896 0, /* start depth */
15901 on_layout_manager_changed (ClutterLayoutManager *manager,
15902 ClutterActor *self)
15904 clutter_actor_queue_relayout (self);
15908 * clutter_actor_set_layout_manager:
15909 * @self: a #ClutterActor
15910 * @manager: (allow-none): a #ClutterLayoutManager, or %NULL to unset it
15912 * Sets the #ClutterLayoutManager delegate object that will be used to
15913 * lay out the children of @self.
15915 * The #ClutterActor will take a reference on the passed @manager which
15916 * will be released either when the layout manager is removed, or when
15917 * the actor is destroyed.
15922 clutter_actor_set_layout_manager (ClutterActor *self,
15923 ClutterLayoutManager *manager)
15925 ClutterActorPrivate *priv;
15927 g_return_if_fail (CLUTTER_IS_ACTOR (self));
15928 g_return_if_fail (manager == NULL || CLUTTER_IS_LAYOUT_MANAGER (manager));
15932 if (priv->layout_manager != NULL)
15934 g_signal_handlers_disconnect_by_func (priv->layout_manager,
15935 G_CALLBACK (on_layout_manager_changed),
15937 clutter_layout_manager_set_container (priv->layout_manager, NULL);
15938 g_clear_object (&priv->layout_manager);
15941 priv->layout_manager = manager;
15943 if (priv->layout_manager != NULL)
15945 g_object_ref_sink (priv->layout_manager);
15946 clutter_layout_manager_set_container (priv->layout_manager,
15947 CLUTTER_CONTAINER (self));
15948 g_signal_connect (priv->layout_manager, "layout-changed",
15949 G_CALLBACK (on_layout_manager_changed),
15953 clutter_actor_queue_relayout (self);
15955 g_object_notify_by_pspec (G_OBJECT (self), obj_props[PROP_LAYOUT_MANAGER]);
15959 * clutter_actor_get_layout_manager:
15960 * @self: a #ClutterActor
15962 * Retrieves the #ClutterLayoutManager used by @self.
15964 * Return value: (transfer none): a pointer to the #ClutterLayoutManager,
15969 ClutterLayoutManager *
15970 clutter_actor_get_layout_manager (ClutterActor *self)
15972 g_return_val_if_fail (CLUTTER_IS_ACTOR (self), NULL);
15974 return self->priv->layout_manager;
15977 static const ClutterLayoutInfo default_layout_info = {
15980 { 0, 0, 0, 0 }, /* margin */
15981 CLUTTER_ACTOR_ALIGN_FILL, /* x-align */
15982 CLUTTER_ACTOR_ALIGN_FILL, /* y-align */
15983 0.f, 0.f, /* min_width, natural_width */
15984 0.f, 0.f, /* natual_width, natural_height */
15988 layout_info_free (gpointer data)
15990 if (G_LIKELY (data != NULL))
15991 g_slice_free (ClutterLayoutInfo, data);
15995 * _clutter_actor_get_layout_info:
15996 * @self: a #ClutterActor
15998 * Retrieves a pointer to the ClutterLayoutInfo structure.
16000 * If the actor does not have a ClutterLayoutInfo associated to it, one
16001 * will be created and initialized to the default values.
16003 * This function should be used for setters.
16005 * For getters, you should use _clutter_actor_get_layout_info_or_defaults()
16008 * Return value: (transfer none): a pointer to the ClutterLayoutInfo structure
16010 ClutterLayoutInfo *
16011 _clutter_actor_get_layout_info (ClutterActor *self)
16013 ClutterLayoutInfo *retval;
16015 retval = g_object_get_qdata (G_OBJECT (self), quark_actor_layout_info);
16016 if (retval == NULL)
16018 retval = g_slice_new (ClutterLayoutInfo);
16020 *retval = default_layout_info;
16022 g_object_set_qdata_full (G_OBJECT (self), quark_actor_layout_info,
16031 * _clutter_actor_get_layout_info_or_defaults:
16032 * @self: a #ClutterActor
16034 * Retrieves the ClutterLayoutInfo structure associated to an actor.
16036 * If the actor does not have a ClutterLayoutInfo structure associated to it,
16037 * then the default structure will be returned.
16039 * This function should only be used for getters.
16041 * Return value: a const pointer to the ClutterLayoutInfo structure
16043 const ClutterLayoutInfo *
16044 _clutter_actor_get_layout_info_or_defaults (ClutterActor *self)
16046 const ClutterLayoutInfo *info;
16048 info = g_object_get_qdata (G_OBJECT (self), quark_actor_layout_info);
16050 return &default_layout_info;
16056 * clutter_actor_set_x_align:
16057 * @self: a #ClutterActor
16058 * @x_align: the horizontal alignment policy
16060 * Sets the horizontal alignment policy of a #ClutterActor, in case the
16061 * actor received extra horizontal space.
16063 * See also the #ClutterActor:x-align property.
16068 clutter_actor_set_x_align (ClutterActor *self,
16069 ClutterActorAlign x_align)
16071 ClutterLayoutInfo *info;
16073 g_return_if_fail (CLUTTER_IS_ACTOR (self));
16075 info = _clutter_actor_get_layout_info (self);
16077 if (info->x_align != x_align)
16079 info->x_align = x_align;
16081 clutter_actor_queue_relayout (self);
16083 g_object_notify_by_pspec (G_OBJECT (self), obj_props[PROP_X_ALIGN]);
16088 * clutter_actor_get_x_align:
16089 * @self: a #ClutterActor
16091 * Retrieves the horizontal alignment policy set using
16092 * clutter_actor_set_x_align().
16094 * Return value: the horizontal alignment policy.
16099 clutter_actor_get_x_align (ClutterActor *self)
16101 g_return_val_if_fail (CLUTTER_IS_ACTOR (self), CLUTTER_ACTOR_ALIGN_FILL);
16103 return _clutter_actor_get_layout_info_or_defaults (self)->x_align;
16107 * clutter_actor_set_y_align:
16108 * @self: a #ClutterActor
16109 * @y_align: the vertical alignment policy
16111 * Sets the vertical alignment policy of a #ClutterActor, in case the
16112 * actor received extra vertical space.
16114 * See also the #ClutterActor:y-align property.
16119 clutter_actor_set_y_align (ClutterActor *self,
16120 ClutterActorAlign y_align)
16122 ClutterLayoutInfo *info;
16124 g_return_if_fail (CLUTTER_IS_ACTOR (self));
16126 info = _clutter_actor_get_layout_info (self);
16128 if (info->y_align != y_align)
16130 info->y_align = y_align;
16132 clutter_actor_queue_relayout (self);
16134 g_object_notify_by_pspec (G_OBJECT (self), obj_props[PROP_Y_ALIGN]);
16139 * clutter_actor_get_y_align:
16140 * @self: a #ClutterActor
16142 * Retrieves the vertical alignment policy set using
16143 * clutter_actor_set_y_align().
16145 * Return value: the vertical alignment policy.
16150 clutter_actor_get_y_align (ClutterActor *self)
16152 g_return_val_if_fail (CLUTTER_IS_ACTOR (self), CLUTTER_ACTOR_ALIGN_FILL);
16154 return _clutter_actor_get_layout_info_or_defaults (self)->y_align;
16159 * clutter_margin_new:
16161 * Creates a new #ClutterMargin.
16163 * Return value: (transfer full): a newly allocated #ClutterMargin. Use
16164 * clutter_margin_free() to free the resources associated with it when
16170 clutter_margin_new (void)
16172 return g_slice_new0 (ClutterMargin);
16176 * clutter_margin_copy:
16177 * @margin_: a #ClutterMargin
16179 * Creates a new #ClutterMargin and copies the contents of @margin_ into
16180 * the newly created structure.
16182 * Return value: (transfer full): a copy of the #ClutterMargin.
16187 clutter_margin_copy (const ClutterMargin *margin_)
16189 if (G_LIKELY (margin_ != NULL))
16190 return g_slice_dup (ClutterMargin, margin_);
16196 * clutter_margin_free:
16197 * @margin_: a #ClutterMargin
16199 * Frees the resources allocated by clutter_margin_new() and
16200 * clutter_margin_copy().
16205 clutter_margin_free (ClutterMargin *margin_)
16207 if (G_LIKELY (margin_ != NULL))
16208 g_slice_free (ClutterMargin, margin_);
16211 G_DEFINE_BOXED_TYPE (ClutterMargin, clutter_margin,
16212 clutter_margin_copy,
16213 clutter_margin_free)
16216 * clutter_actor_set_margin:
16217 * @self: a #ClutterActor
16218 * @margin: a #ClutterMargin
16220 * Sets all the components of the margin of a #ClutterActor.
16225 clutter_actor_set_margin (ClutterActor *self,
16226 const ClutterMargin *margin)
16228 ClutterLayoutInfo *info;
16232 g_return_if_fail (CLUTTER_IS_ACTOR (self));
16233 g_return_if_fail (margin != NULL);
16235 obj = G_OBJECT (self);
16238 g_object_freeze_notify (obj);
16240 info = _clutter_actor_get_layout_info (self);
16242 if (info->margin.top != margin->top)
16244 info->margin.top = margin->top;
16245 g_object_notify_by_pspec (obj, obj_props[PROP_MARGIN_TOP]);
16249 if (info->margin.right != margin->right)
16251 info->margin.right = margin->right;
16252 g_object_notify_by_pspec (obj, obj_props[PROP_MARGIN_RIGHT]);
16256 if (info->margin.bottom != margin->bottom)
16258 info->margin.bottom = margin->bottom;
16259 g_object_notify_by_pspec (obj, obj_props[PROP_MARGIN_BOTTOM]);
16263 if (info->margin.left != margin->left)
16265 info->margin.left = margin->left;
16266 g_object_notify_by_pspec (obj, obj_props[PROP_MARGIN_LEFT]);
16271 clutter_actor_queue_relayout (self);
16273 g_object_thaw_notify (obj);
16277 * clutter_actor_get_margin:
16278 * @self: a #ClutterActor
16279 * @margin: (out caller-allocates): return location for a #ClutterMargin
16281 * Retrieves all the components of the margin of a #ClutterActor.
16286 clutter_actor_get_margin (ClutterActor *self,
16287 ClutterMargin *margin)
16289 const ClutterLayoutInfo *info;
16291 g_return_if_fail (CLUTTER_IS_ACTOR (self));
16292 g_return_if_fail (margin != NULL);
16294 info = _clutter_actor_get_layout_info_or_defaults (self);
16296 *margin = info->margin;
16300 * clutter_actor_set_margin_top:
16301 * @self: a #ClutterActor
16302 * @margin: the top margin
16304 * Sets the margin from the top of a #ClutterActor.
16309 clutter_actor_set_margin_top (ClutterActor *self,
16312 ClutterLayoutInfo *info;
16314 g_return_if_fail (CLUTTER_IS_ACTOR (self));
16315 g_return_if_fail (margin >= 0.f);
16317 info = _clutter_actor_get_layout_info (self);
16319 if (info->margin.top == margin)
16322 info->margin.top = margin;
16324 clutter_actor_queue_relayout (self);
16326 g_object_notify_by_pspec (G_OBJECT (self), obj_props[PROP_MARGIN_TOP]);
16330 * clutter_actor_get_margin_top:
16331 * @self: a #ClutterActor
16333 * Retrieves the top margin of a #ClutterActor.
16335 * Return value: the top margin
16340 clutter_actor_get_margin_top (ClutterActor *self)
16342 g_return_val_if_fail (CLUTTER_IS_ACTOR (self), 0.f);
16344 return _clutter_actor_get_layout_info_or_defaults (self)->margin.top;
16348 * clutter_actor_set_margin_bottom:
16349 * @self: a #ClutterActor
16350 * @margin: the bottom margin
16352 * Sets the margin from the bottom of a #ClutterActor.
16357 clutter_actor_set_margin_bottom (ClutterActor *self,
16360 ClutterLayoutInfo *info;
16362 g_return_if_fail (CLUTTER_IS_ACTOR (self));
16363 g_return_if_fail (margin >= 0.f);
16365 info = _clutter_actor_get_layout_info (self);
16367 if (info->margin.bottom == margin)
16370 info->margin.bottom = margin;
16372 clutter_actor_queue_relayout (self);
16374 g_object_notify_by_pspec (G_OBJECT (self), obj_props[PROP_MARGIN_BOTTOM]);
16378 * clutter_actor_get_margin_bottom:
16379 * @self: a #ClutterActor
16381 * Retrieves the bottom margin of a #ClutterActor.
16383 * Return value: the bottom margin
16388 clutter_actor_get_margin_bottom (ClutterActor *self)
16390 g_return_val_if_fail (CLUTTER_IS_ACTOR (self), 0.f);
16392 return _clutter_actor_get_layout_info_or_defaults (self)->margin.bottom;
16396 * clutter_actor_set_margin_left:
16397 * @self: a #ClutterActor
16398 * @margin: the left margin
16400 * Sets the margin from the left of a #ClutterActor.
16405 clutter_actor_set_margin_left (ClutterActor *self,
16408 ClutterLayoutInfo *info;
16410 g_return_if_fail (CLUTTER_IS_ACTOR (self));
16411 g_return_if_fail (margin >= 0.f);
16413 info = _clutter_actor_get_layout_info (self);
16415 if (info->margin.left == margin)
16418 info->margin.left = margin;
16420 clutter_actor_queue_relayout (self);
16422 g_object_notify_by_pspec (G_OBJECT (self), obj_props[PROP_MARGIN_LEFT]);
16426 * clutter_actor_get_margin_left:
16427 * @self: a #ClutterActor
16429 * Retrieves the left margin of a #ClutterActor.
16431 * Return value: the left margin
16436 clutter_actor_get_margin_left (ClutterActor *self)
16438 g_return_val_if_fail (CLUTTER_IS_ACTOR (self), 0.f);
16440 return _clutter_actor_get_layout_info_or_defaults (self)->margin.left;
16444 * clutter_actor_set_margin_right:
16445 * @self: a #ClutterActor
16446 * @margin: the right margin
16448 * Sets the margin from the right of a #ClutterActor.
16453 clutter_actor_set_margin_right (ClutterActor *self,
16456 ClutterLayoutInfo *info;
16458 g_return_if_fail (CLUTTER_IS_ACTOR (self));
16459 g_return_if_fail (margin >= 0.f);
16461 info = _clutter_actor_get_layout_info (self);
16463 if (info->margin.right == margin)
16466 info->margin.right = margin;
16468 clutter_actor_queue_relayout (self);
16470 g_object_notify_by_pspec (G_OBJECT (self), obj_props[PROP_MARGIN_RIGHT]);
16474 * clutter_actor_get_margin_right:
16475 * @self: a #ClutterActor
16477 * Retrieves the right margin of a #ClutterActor.
16479 * Return value: the right margin
16484 clutter_actor_get_margin_right (ClutterActor *self)
16486 g_return_val_if_fail (CLUTTER_IS_ACTOR (self), 0.f);
16488 return _clutter_actor_get_layout_info_or_defaults (self)->margin.right;
16492 clutter_actor_set_background_color_internal (ClutterActor *self,
16493 const ClutterColor *color)
16495 ClutterActorPrivate *priv = self->priv;
16498 if (priv->bg_color_set && clutter_color_equal (color, &priv->bg_color))
16501 obj = G_OBJECT (self);
16503 priv->bg_color = *color;
16504 priv->bg_color_set = TRUE;
16506 clutter_actor_queue_redraw (self);
16508 g_object_notify_by_pspec (obj, obj_props[PROP_BACKGROUND_COLOR_SET]);
16509 g_object_notify_by_pspec (obj, obj_props[PROP_BACKGROUND_COLOR]);
16513 * clutter_actor_set_background_color:
16514 * @self: a #ClutterActor
16515 * @color: (allow-none): a #ClutterColor, or %NULL to unset a previously
16518 * Sets the background color of a #ClutterActor.
16520 * The background color will be used to cover the whole allocation of the
16521 * actor. The default background color of an actor is transparent.
16523 * To check whether an actor has a background color, you can use the
16524 * #ClutterActor:background-color-set actor property.
16526 * The #ClutterActor:background-color property is animatable.
16531 clutter_actor_set_background_color (ClutterActor *self,
16532 const ClutterColor *color)
16534 ClutterActorPrivate *priv;
16536 GParamSpec *bg_color_pspec;
16538 g_return_if_fail (CLUTTER_IS_ACTOR (self));
16540 obj = G_OBJECT (self);
16546 priv->bg_color_set = FALSE;
16547 g_object_notify_by_pspec (obj, obj_props[PROP_BACKGROUND_COLOR_SET]);
16548 clutter_actor_queue_redraw (self);
16552 bg_color_pspec = obj_props[PROP_BACKGROUND_COLOR];
16553 if (_clutter_actor_get_transition (self, bg_color_pspec) == NULL)
16555 _clutter_actor_create_transition (self, bg_color_pspec,
16560 _clutter_actor_update_transition (self, bg_color_pspec, color);
16562 clutter_actor_queue_redraw (self);
16566 * clutter_actor_get_background_color:
16567 * @self: a #ClutterActor
16568 * @color: (out caller-allocates): return location for a #ClutterColor
16570 * Retrieves the color set using clutter_actor_set_background_color().
16575 clutter_actor_get_background_color (ClutterActor *self,
16576 ClutterColor *color)
16578 g_return_if_fail (CLUTTER_IS_ACTOR (self));
16579 g_return_if_fail (color != NULL);
16581 *color = self->priv->bg_color;
16585 * clutter_actor_get_previous_sibling:
16586 * @self: a #ClutterActor
16588 * Retrieves the sibling of @self that comes before it in the list
16589 * of children of @self's parent.
16591 * The returned pointer is only valid until the scene graph changes; it
16592 * is not safe to modify the list of children of @self while iterating
16595 * Return value: (transfer none): a pointer to a #ClutterActor, or %NULL
16600 clutter_actor_get_previous_sibling (ClutterActor *self)
16602 g_return_val_if_fail (CLUTTER_IS_ACTOR (self), NULL);
16604 return self->priv->prev_sibling;
16608 * clutter_actor_get_next_sibling:
16609 * @self: a #ClutterActor
16611 * Retrieves the sibling of @self that comes after it in the list
16612 * of children of @self's parent.
16614 * The returned pointer is only valid until the scene graph changes; it
16615 * is not safe to modify the list of children of @self while iterating
16618 * Return value: (transfer none): a pointer to a #ClutterActor, or %NULL
16623 clutter_actor_get_next_sibling (ClutterActor *self)
16625 g_return_val_if_fail (CLUTTER_IS_ACTOR (self), NULL);
16627 return self->priv->next_sibling;
16631 * clutter_actor_get_first_child:
16632 * @self: a #ClutterActor
16634 * Retrieves the first child of @self.
16636 * The returned pointer is only valid until the scene graph changes; it
16637 * is not safe to modify the list of children of @self while iterating
16640 * Return value: (transfer none): a pointer to a #ClutterActor, or %NULL
16645 clutter_actor_get_first_child (ClutterActor *self)
16647 g_return_val_if_fail (CLUTTER_IS_ACTOR (self), NULL);
16649 return self->priv->first_child;
16653 * clutter_actor_get_last_child:
16654 * @self: a #ClutterActor
16656 * Retrieves the last child of @self.
16658 * The returned pointer is only valid until the scene graph changes; it
16659 * is not safe to modify the list of children of @self while iterating
16662 * Return value: (transfer none): a pointer to a #ClutterActor, or %NULL
16667 clutter_actor_get_last_child (ClutterActor *self)
16669 g_return_val_if_fail (CLUTTER_IS_ACTOR (self), NULL);
16671 return self->priv->last_child;
16674 /* easy way to have properly named fields instead of the dummy ones
16675 * we use in the public structure
16677 typedef struct _RealActorIter
16679 ClutterActor *root; /* dummy1 */
16680 ClutterActor *current; /* dummy2 */
16681 gpointer padding_1; /* dummy3 */
16682 gint age; /* dummy4 */
16683 gpointer padding_2; /* dummy5 */
16687 * clutter_actor_iter_init:
16688 * @iter: a #ClutterActorIter
16689 * @root: a #ClutterActor
16691 * Initializes a #ClutterActorIter, which can then be used to iterate
16692 * efficiently over a section of the scene graph, and associates it
16695 * Modifying the scene graph section that contains @root will invalidate
16699 * ClutterActorIter iter;
16700 * ClutterActor *child;
16702 * clutter_actor_iter_init (&iter, container);
16703 * while (clutter_actor_iter_next (&iter, &child))
16705 * /* do something with child */
16712 clutter_actor_iter_init (ClutterActorIter *iter,
16713 ClutterActor *root)
16715 RealActorIter *ri = (RealActorIter *) iter;
16717 g_return_if_fail (iter != NULL);
16718 g_return_if_fail (CLUTTER_IS_ACTOR (root));
16721 ri->current = NULL;
16722 ri->age = root->priv->age;
16726 * clutter_actor_iter_next:
16727 * @iter: a #ClutterActorIter
16728 * @child: (out): return location for a #ClutterActor
16730 * Advances the @iter and retrieves the next child of the root #ClutterActor
16731 * that was used to initialize the #ClutterActorIterator.
16733 * If the iterator can advance, this function returns %TRUE and sets the
16736 * If the iterator cannot advance, this function returns %FALSE, and
16737 * the contents of @child are undefined.
16739 * Return value: %TRUE if the iterator could advance, and %FALSE otherwise.
16744 clutter_actor_iter_next (ClutterActorIter *iter,
16745 ClutterActor **child)
16747 RealActorIter *ri = (RealActorIter *) iter;
16749 g_return_val_if_fail (iter != NULL, FALSE);
16750 g_return_val_if_fail (ri->root != NULL, FALSE);
16751 #ifndef G_DISABLE_ASSERT
16752 g_return_val_if_fail (ri->age == ri->root->priv->age, FALSE);
16755 if (ri->current == NULL)
16756 ri->current = ri->root->priv->first_child;
16758 ri->current = ri->current->priv->next_sibling;
16761 *child = ri->current;
16763 return ri->current != NULL;
16767 * clutter_actor_iter_prev:
16768 * @iter: a #ClutterActorIter
16769 * @child: (out): return location for a #ClutterActor
16771 * Advances the @iter and retrieves the previous child of the root
16772 * #ClutterActor that was used to initialize the #ClutterActorIterator.
16774 * If the iterator can advance, this function returns %TRUE and sets the
16777 * If the iterator cannot advance, this function returns %FALSE, and
16778 * the contents of @child are undefined.
16780 * Return value: %TRUE if the iterator could advance, and %FALSE otherwise.
16785 clutter_actor_iter_prev (ClutterActorIter *iter,
16786 ClutterActor **child)
16788 RealActorIter *ri = (RealActorIter *) iter;
16790 g_return_val_if_fail (iter != NULL, FALSE);
16791 g_return_val_if_fail (ri->root != NULL, FALSE);
16792 #ifndef G_DISABLE_ASSERT
16793 g_return_val_if_fail (ri->age == ri->root->priv->age, FALSE);
16796 if (ri->current == NULL)
16797 ri->current = ri->root->priv->last_child;
16799 ri->current = ri->current->priv->prev_sibling;
16802 *child = ri->current;
16804 return ri->current != NULL;
16808 * clutter_actor_iter_remove:
16809 * @iter: a #ClutterActorIter
16811 * Safely removes the #ClutterActor currently pointer to by the iterator
16814 * This function can only be called after clutter_actor_iter_next() or
16815 * clutter_actor_iter_prev() returned %TRUE, and cannot be called more
16816 * than once for the same actor.
16818 * This function will call clutter_actor_remove_child() internally.
16823 clutter_actor_iter_remove (ClutterActorIter *iter)
16825 RealActorIter *ri = (RealActorIter *) iter;
16828 g_return_if_fail (iter != NULL);
16829 g_return_if_fail (ri->root != NULL);
16830 #ifndef G_DISABLE_ASSERT
16831 g_return_if_fail (ri->age == ri->root->priv->age);
16833 g_return_if_fail (ri->current != NULL);
16839 ri->current = cur->priv->prev_sibling;
16841 clutter_actor_remove_child_internal (ri->root, cur,
16842 REMOVE_CHILD_DEFAULT_FLAGS);
16849 * clutter_actor_iter_destroy:
16850 * @iter: a #ClutterActorIter
16852 * Safely destroys the #ClutterActor currently pointer to by the iterator
16855 * This function can only be called after clutter_actor_iter_next() or
16856 * clutter_actor_iter_prev() returned %TRUE, and cannot be called more
16857 * than once for the same actor.
16859 * This function will call clutter_actor_destroy() internally.
16864 clutter_actor_iter_destroy (ClutterActorIter *iter)
16866 RealActorIter *ri = (RealActorIter *) iter;
16869 g_return_if_fail (iter != NULL);
16870 g_return_if_fail (ri->root != NULL);
16871 #ifndef G_DISABLE_ASSERT
16872 g_return_if_fail (ri->age == ri->root->priv->age);
16874 g_return_if_fail (ri->current != NULL);
16880 ri->current = cur->priv->prev_sibling;
16882 clutter_actor_destroy (cur);
16888 static const ClutterAnimationInfo default_animation_info = {
16889 NULL, /* transitions */
16891 NULL, /* cur_state */
16895 clutter_animation_info_free (gpointer data)
16899 ClutterAnimationInfo *info = data;
16901 if (info->transitions != NULL)
16902 g_hash_table_unref (info->transitions);
16904 if (info->states != NULL)
16905 g_array_unref (info->states);
16907 g_slice_free (ClutterAnimationInfo, info);
16911 const ClutterAnimationInfo *
16912 _clutter_actor_get_animation_info_or_defaults (ClutterActor *self)
16914 const ClutterAnimationInfo *res;
16915 GObject *obj = G_OBJECT (self);
16917 res = g_object_get_qdata (obj, quark_actor_animation_info);
16921 return &default_animation_info;
16924 ClutterAnimationInfo *
16925 _clutter_actor_get_animation_info (ClutterActor *self)
16927 GObject *obj = G_OBJECT (self);
16928 ClutterAnimationInfo *res;
16930 res = g_object_get_qdata (obj, quark_actor_animation_info);
16933 res = g_slice_new (ClutterAnimationInfo);
16935 *res = default_animation_info;
16937 g_object_set_qdata_full (obj, quark_actor_animation_info,
16939 clutter_animation_info_free);
16945 ClutterTransition *
16946 _clutter_actor_get_transition (ClutterActor *actor,
16949 const ClutterAnimationInfo *info;
16951 info = _clutter_actor_get_animation_info_or_defaults (actor);
16953 if (info->transitions == NULL)
16956 return g_hash_table_lookup (info->transitions, pspec->name);
16959 typedef struct _TransitionClosure
16961 ClutterActor *actor;
16962 ClutterTransition *transition;
16964 gulong completed_id;
16965 } TransitionClosure;
16968 transition_closure_free (gpointer data)
16970 if (G_LIKELY (data != NULL))
16972 TransitionClosure *clos = data;
16974 if (clutter_timeline_is_playing (CLUTTER_TIMELINE (clos->transition)))
16975 clutter_timeline_stop (CLUTTER_TIMELINE (clos->transition));
16977 g_signal_handler_disconnect (clos->transition, clos->completed_id);
16979 g_object_unref (clos->transition);
16980 g_free (clos->name);
16982 g_slice_free (TransitionClosure, clos);
16987 on_transition_completed (ClutterTransition *transition,
16988 TransitionClosure *clos)
16990 ClutterActor *actor = clos->actor;
16991 ClutterAnimationInfo *info;
16993 info = _clutter_actor_get_animation_info (actor);
16995 /* this will take care of cleaning clos for us */
16996 if (clutter_transition_get_remove_on_complete (transition))
16998 /* we take a reference here because removing the closure
16999 * will release the reference on the transition, and we
17000 * want the transition to survive the signal emission;
17001 * the master clock will release the laste reference at
17002 * the end of the frame processing.
17004 g_object_ref (transition);
17005 g_hash_table_remove (info->transitions, clos->name);
17008 /* if it's the last transition then we clean up */
17009 if (g_hash_table_size (info->transitions) == 0)
17011 g_hash_table_unref (info->transitions);
17012 info->transitions = NULL;
17014 CLUTTER_NOTE (ANIMATION, "Transitions for '%s' completed",
17015 _clutter_actor_get_debug_name (actor));
17017 g_signal_emit (actor, actor_signals[TRANSITIONS_COMPLETED], 0);
17022 _clutter_actor_update_transition (ClutterActor *actor,
17026 TransitionClosure *clos;
17027 ClutterTimeline *timeline;
17028 ClutterInterval *interval;
17029 const ClutterAnimationInfo *info;
17032 GValue initial = G_VALUE_INIT;
17033 GValue final = G_VALUE_INIT;
17034 char *error = NULL;
17036 info = _clutter_actor_get_animation_info_or_defaults (actor);
17038 if (info->transitions == NULL)
17041 clos = g_hash_table_lookup (info->transitions, pspec->name);
17045 timeline = CLUTTER_TIMELINE (clos->transition);
17047 va_start (var_args, pspec);
17049 ptype = G_PARAM_SPEC_VALUE_TYPE (pspec);
17051 g_value_init (&initial, ptype);
17052 clutter_animatable_get_initial_state (CLUTTER_ANIMATABLE (actor),
17056 G_VALUE_COLLECT_INIT (&final, ptype, var_args, 0, &error);
17059 g_critical ("%s: %s", G_STRLOC, error);
17064 interval = clutter_transition_get_interval (clos->transition);
17065 clutter_interval_set_initial_value (interval, &initial);
17066 clutter_interval_set_final_value (interval, &final);
17068 /* if we're updating with an easing duration of zero milliseconds,
17069 * we just jump the timeline to the end and let it run its course
17071 if (info->cur_state != NULL &&
17072 info->cur_state->easing_duration != 0)
17074 guint cur_duration = clutter_timeline_get_duration (timeline);
17075 ClutterAnimationMode cur_mode =
17076 clutter_timeline_get_progress_mode (timeline);
17078 if (cur_duration != info->cur_state->easing_duration)
17079 clutter_timeline_set_duration (timeline, info->cur_state->easing_duration);
17081 if (cur_mode != info->cur_state->easing_mode)
17082 clutter_timeline_set_progress_mode (timeline, info->cur_state->easing_mode);
17084 clutter_timeline_rewind (timeline);
17088 guint duration = clutter_timeline_get_duration (timeline);
17090 clutter_timeline_advance (timeline, duration);
17094 g_value_unset (&initial);
17095 g_value_unset (&final);
17101 * _clutter_actor_create_transition:
17102 * @actor: a #ClutterActor
17103 * @pspec: the property used for the transition
17104 * @...: initial and final state
17106 * Creates a #ClutterTransition for the property represented by @pspec.
17108 * Return value: a #ClutterTransition
17110 ClutterTransition *
17111 _clutter_actor_create_transition (ClutterActor *actor,
17115 ClutterAnimationInfo *info;
17116 ClutterTransition *res = NULL;
17117 gboolean call_restore = FALSE;
17118 TransitionClosure *clos;
17121 info = _clutter_actor_get_animation_info (actor);
17123 /* XXX - this will go away in 2.0
17125 * if no state has been pushed, we assume that the easing state is
17126 * in "compatibility mode": all transitions have a duration of 0
17127 * msecs, which means that they happen immediately. in Clutter 2.0
17128 * this will turn into a g_assert(info->states != NULL), as every
17129 * actor will start with a predefined easing state
17131 if (info->states == NULL)
17133 clutter_actor_save_easing_state (actor);
17134 clutter_actor_set_easing_duration (actor, 0);
17135 call_restore = TRUE;
17138 if (info->transitions == NULL)
17139 info->transitions = g_hash_table_new_full (g_str_hash, g_str_equal,
17141 transition_closure_free);
17143 va_start (var_args, pspec);
17145 clos = g_hash_table_lookup (info->transitions, pspec->name);
17148 ClutterInterval *interval;
17149 GValue initial = G_VALUE_INIT;
17150 GValue final = G_VALUE_INIT;
17154 ptype = G_PARAM_SPEC_VALUE_TYPE (pspec);
17156 G_VALUE_COLLECT_INIT (&initial, ptype,
17161 g_critical ("%s: %s", G_STRLOC, error);
17166 G_VALUE_COLLECT_INIT (&final, ptype,
17172 g_critical ("%s: %s", G_STRLOC, error);
17173 g_value_unset (&initial);
17178 /* if the current easing state has a duration of 0, then we don't
17179 * bother to create the transition, and we just set the final value
17180 * directly on the actor; we don't go through the Animatable
17181 * interface because we know we got here through an animatable
17184 if (info->cur_state->easing_duration == 0)
17186 clutter_actor_set_animatable_property (actor,
17190 g_value_unset (&initial);
17191 g_value_unset (&final);
17196 interval = clutter_interval_new_with_values (ptype, &initial, &final);
17198 g_value_unset (&initial);
17199 g_value_unset (&final);
17201 res = clutter_property_transition_new (pspec->name);
17203 clutter_transition_set_interval (res, interval);
17204 clutter_transition_set_remove_on_complete (res, TRUE);
17206 /* this will start the transition as well */
17207 clutter_actor_add_transition (actor, pspec->name, res);
17209 /* the actor now owns the transition */
17210 g_object_unref (res);
17213 res = clos->transition;
17217 clutter_actor_restore_easing_state (actor);
17225 * clutter_actor_add_transition:
17226 * @self: a #ClutterActor
17227 * @name: the name of the transition to add
17228 * @transition: the #ClutterTransition to add
17230 * Adds a @transition to the #ClutterActor's list of animations.
17232 * The @name string is a per-actor unique identifier of the @transition: only
17233 * one #ClutterTransition can be associated to the specified @name.
17235 * The @transition will be given the easing duration, mode, and delay
17236 * associated to the actor's current easing state; it is possible to modify
17237 * these values after calling clutter_actor_add_transition().
17239 * The @transition will be started once added.
17241 * This function will take a reference on the @transition.
17243 * This function is usually called implicitly when modifying an animatable
17249 clutter_actor_add_transition (ClutterActor *self,
17251 ClutterTransition *transition)
17253 ClutterTimeline *timeline;
17254 TransitionClosure *clos;
17255 ClutterAnimationInfo *info;
17257 g_return_if_fail (CLUTTER_IS_ACTOR (self));
17258 g_return_if_fail (name != NULL);
17259 g_return_if_fail (CLUTTER_IS_TRANSITION (transition));
17261 info = _clutter_actor_get_animation_info (self);
17263 if (info->cur_state == NULL)
17265 g_warning ("No easing state is defined for the actor '%s'; you "
17266 "must call clutter_actor_save_easing_state() before "
17267 "calling clutter_actor_add_transition().",
17268 _clutter_actor_get_debug_name (self));
17272 if (info->transitions == NULL)
17273 info->transitions = g_hash_table_new_full (g_str_hash, g_str_equal,
17275 transition_closure_free);
17277 if (g_hash_table_lookup (info->transitions, name) != NULL)
17279 g_warning ("A transition with name '%s' already exists for "
17282 _clutter_actor_get_debug_name (self));
17286 clutter_transition_set_animatable (transition, CLUTTER_ANIMATABLE (self));
17288 timeline = CLUTTER_TIMELINE (transition);
17290 clutter_timeline_set_delay (timeline, info->cur_state->easing_delay);
17291 clutter_timeline_set_duration (timeline, info->cur_state->easing_duration);
17292 clutter_timeline_set_progress_mode (timeline, info->cur_state->easing_mode);
17294 clos = g_slice_new (TransitionClosure);
17295 clos->actor = self;
17296 clos->transition = g_object_ref (transition);
17297 clos->name = g_strdup (name);
17298 clos->completed_id = g_signal_connect (timeline, "completed",
17299 G_CALLBACK (on_transition_completed),
17302 CLUTTER_NOTE (ANIMATION,
17303 "Adding transition '%s' [%p] to actor '%s'",
17306 _clutter_actor_get_debug_name (self));
17308 g_hash_table_insert (info->transitions, clos->name, clos);
17309 clutter_timeline_start (timeline);
17313 * clutter_actor_remove_transition:
17314 * @self: a #ClutterActor
17315 * @name: the name of the transition to remove
17317 * Removes the transition stored inside a #ClutterActor using @name
17320 * If the transition is currently in progress, it will be stopped.
17322 * This function releases the reference acquired when the transition
17323 * was added to the #ClutterActor.
17328 clutter_actor_remove_transition (ClutterActor *self,
17331 const ClutterAnimationInfo *info;
17333 g_return_if_fail (CLUTTER_IS_ACTOR (self));
17334 g_return_if_fail (name != NULL);
17336 info = _clutter_actor_get_animation_info_or_defaults (self);
17338 if (info->transitions == NULL)
17341 g_hash_table_remove (info->transitions, name);
17345 * clutter_actor_remove_all_transitions:
17346 * @self: a #ClutterActor
17348 * Removes all transitions associated to @self.
17353 clutter_actor_remove_all_transitions (ClutterActor *self)
17355 const ClutterAnimationInfo *info;
17357 g_return_if_fail (CLUTTER_IS_ACTOR (self));
17359 info = _clutter_actor_get_animation_info_or_defaults (self);
17360 if (info->transitions == NULL)
17363 g_hash_table_remove_all (info->transitions);
17367 * clutter_actor_set_easing_duration:
17368 * @self: a #ClutterActor
17369 * @msecs: the duration of the easing, or %NULL
17371 * Sets the duration of the tweening for animatable properties
17372 * of @self for the current easing state.
17377 clutter_actor_set_easing_duration (ClutterActor *self,
17380 ClutterAnimationInfo *info;
17382 g_return_if_fail (CLUTTER_IS_ACTOR (self));
17384 info = _clutter_actor_get_animation_info (self);
17386 if (info->cur_state == NULL)
17388 g_warning ("You must call clutter_actor_save_easing_state() prior "
17389 "to calling clutter_actor_set_easing_duration().");
17393 if (info->cur_state->easing_duration != msecs)
17394 info->cur_state->easing_duration = msecs;
17398 * clutter_actor_get_easing_duration:
17399 * @self: a #ClutterActor
17401 * Retrieves the duration of the tweening for animatable
17402 * properties of @self for the current easing state.
17404 * Return value: the duration of the tweening, in milliseconds
17409 clutter_actor_get_easing_duration (ClutterActor *self)
17411 const ClutterAnimationInfo *info;
17413 g_return_val_if_fail (CLUTTER_IS_ACTOR (self), 0);
17415 info = _clutter_actor_get_animation_info_or_defaults (self);
17417 if (info->cur_state != NULL)
17418 return info->cur_state->easing_duration;
17424 * clutter_actor_set_easing_mode:
17425 * @self: a #ClutterActor
17426 * @mode: an easing mode, excluding %CLUTTER_CUSTOM_MODE
17428 * Sets the easing mode for the tweening of animatable properties
17434 clutter_actor_set_easing_mode (ClutterActor *self,
17435 ClutterAnimationMode mode)
17437 ClutterAnimationInfo *info;
17439 g_return_if_fail (CLUTTER_IS_ACTOR (self));
17440 g_return_if_fail (mode != CLUTTER_CUSTOM_MODE);
17441 g_return_if_fail (mode < CLUTTER_ANIMATION_LAST);
17443 info = _clutter_actor_get_animation_info (self);
17445 if (info->cur_state == NULL)
17447 g_warning ("You must call clutter_actor_save_easing_state() prior "
17448 "to calling clutter_actor_set_easing_mode().");
17452 if (info->cur_state->easing_mode != mode)
17453 info->cur_state->easing_mode = mode;
17457 * clutter_actor_get_easing_mode:
17458 * @self: a #ClutterActor
17460 * Retrieves the easing mode for the tweening of animatable properties
17461 * of @self for the current easing state.
17463 * Return value: an easing mode
17467 ClutterAnimationMode
17468 clutter_actor_get_easing_mode (ClutterActor *self)
17470 const ClutterAnimationInfo *info;
17472 g_return_val_if_fail (CLUTTER_IS_ACTOR (self), CLUTTER_EASE_OUT_CUBIC);
17474 info = _clutter_actor_get_animation_info_or_defaults (self);
17476 if (info->cur_state != NULL)
17477 return info->cur_state->easing_mode;
17479 return CLUTTER_EASE_OUT_CUBIC;
17483 * clutter_actor_set_easing_delay:
17484 * @self: a #ClutterActor
17485 * @msecs: the delay before the start of the tweening, in milliseconds
17487 * Sets the delay that should be applied before tweening animatable
17493 clutter_actor_set_easing_delay (ClutterActor *self,
17496 ClutterAnimationInfo *info;
17498 g_return_if_fail (CLUTTER_IS_ACTOR (self));
17500 info = _clutter_actor_get_animation_info (self);
17502 if (info->cur_state == NULL)
17504 g_warning ("You must call clutter_actor_save_easing_state() prior "
17505 "to calling clutter_actor_set_easing_delay().");
17509 if (info->cur_state->easing_delay != msecs)
17510 info->cur_state->easing_delay = msecs;
17514 * clutter_actor_get_easing_delay:
17515 * @self: a #ClutterActor
17517 * Retrieves the delay that should be applied when tweening animatable
17520 * Return value: a delay, in milliseconds
17525 clutter_actor_get_easing_delay (ClutterActor *self)
17527 const ClutterAnimationInfo *info;
17529 g_return_val_if_fail (CLUTTER_IS_ACTOR (self), 0);
17531 info = _clutter_actor_get_animation_info_or_defaults (self);
17533 if (info->cur_state != NULL)
17534 return info->cur_state->easing_delay;
17540 * clutter_actor_get_transition:
17541 * @self: a #ClutterActor
17542 * @name: the name of the transition
17544 * Retrieves the #ClutterTransition of a #ClutterActor by using the
17545 * transition @name.
17547 * Transitions created for animatable properties use the name of the
17548 * property itself, for instance the code below:
17551 * clutter_actor_set_easing_duration (actor, 1000);
17552 * clutter_actor_set_rotation (actor, CLUTTER_Y_AXIS, 360.0, x, y, z);
17554 * transition = clutter_actor_get_transition (actor, "rotation-angle-y");
17555 * g_signal_connect (transition, "completed",
17556 * G_CALLBACK (on_transition_complete),
17560 * will call the <function>on_transition_complete</function> callback when
17561 * the transition is complete.
17563 * Return value: (transfer none): a #ClutterTransition, or %NULL is none
17564 * was found to match the passed name; the returned instance is owned
17565 * by Clutter and it should not be freed
17569 ClutterTransition *
17570 clutter_actor_get_transition (ClutterActor *self,
17573 TransitionClosure *clos;
17574 const ClutterAnimationInfo *info;
17576 g_return_val_if_fail (CLUTTER_IS_ACTOR (self), NULL);
17577 g_return_val_if_fail (name != NULL, NULL);
17579 info = _clutter_actor_get_animation_info_or_defaults (self);
17580 if (info->transitions == NULL)
17583 clos = g_hash_table_lookup (info->transitions, name);
17587 return clos->transition;
17591 * clutter_actor_save_easing_state:
17592 * @self: a #ClutterActor
17594 * Saves the current easing state for animatable properties, and creates
17595 * a new state with the default values for easing mode and duration.
17600 clutter_actor_save_easing_state (ClutterActor *self)
17602 ClutterAnimationInfo *info;
17605 g_return_if_fail (CLUTTER_IS_ACTOR (self));
17607 info = _clutter_actor_get_animation_info (self);
17609 if (info->states == NULL)
17610 info->states = g_array_new (FALSE, FALSE, sizeof (AState));
17612 new_state.easing_mode = CLUTTER_EASE_OUT_CUBIC;
17613 new_state.easing_duration = 250;
17614 new_state.easing_delay = 0;
17616 g_array_append_val (info->states, new_state);
17618 info->cur_state = &g_array_index (info->states, AState, info->states->len - 1);
17622 * clutter_actor_restore_easing_state:
17623 * @self: a #ClutterActor
17625 * Restores the easing state as it was prior to a call to
17626 * clutter_actor_save_easing_state().
17631 clutter_actor_restore_easing_state (ClutterActor *self)
17633 ClutterAnimationInfo *info;
17635 g_return_if_fail (CLUTTER_IS_ACTOR (self));
17637 info = _clutter_actor_get_animation_info (self);
17639 if (info->states == NULL)
17641 g_critical ("The function clutter_actor_restore_easing_state() has "
17642 "called without a previous call to "
17643 "clutter_actor_save_easing_state().");
17647 g_array_remove_index (info->states, info->states->len - 1);
17649 if (info->states->len > 0)
17650 info->cur_state = &g_array_index (info->states, AState, info->states->len - 1);
17653 g_array_unref (info->states);
17654 info->states = NULL;
17655 info->cur_state = NULL;
17660 * clutter_actor_set_content:
17661 * @self: a #ClutterActor
17662 * @content: (allow-none): a #ClutterContent, or %NULL
17664 * Sets the contents of a #ClutterActor.
17669 clutter_actor_set_content (ClutterActor *self,
17670 ClutterContent *content)
17672 ClutterActorPrivate *priv;
17674 g_return_if_fail (CLUTTER_IS_ACTOR (self));
17675 g_return_if_fail (content == NULL || CLUTTER_IS_CONTENT (content));
17679 if (priv->content != NULL)
17681 _clutter_content_detached (priv->content, self);
17682 g_clear_object (&priv->content);
17685 priv->content = content;
17687 if (priv->content != NULL)
17689 g_object_ref (priv->content);
17690 _clutter_content_attached (priv->content, self);
17693 /* given that the content is always painted within the allocation,
17694 * we only need to queue a redraw here
17696 clutter_actor_queue_redraw (self);
17698 g_object_notify_by_pspec (G_OBJECT (self), obj_props[PROP_CONTENT]);
17700 /* if the content gravity is not resize-fill, and the new content has a
17701 * different preferred size than the previous one, then the content box
17702 * may have been changed. since we compute that lazily, we just notify
17703 * here, and let whomever watches :content-box do whatever they need to
17706 if (priv->content_gravity != CLUTTER_CONTENT_GRAVITY_RESIZE_FILL)
17707 g_object_notify_by_pspec (G_OBJECT (self), obj_props[PROP_CONTENT_BOX]);
17711 * clutter_actor_get_content:
17712 * @self: a #ClutterActor
17714 * Retrieves the contents of @self.
17716 * Return value: (transfer none): a pointer to the #ClutterContent instance,
17717 * or %NULL if none was set
17722 clutter_actor_get_content (ClutterActor *self)
17724 g_return_val_if_fail (CLUTTER_IS_ACTOR (self), NULL);
17726 return self->priv->content;
17730 * clutter_actor_set_content_gravity:
17731 * @self: a #ClutterActor
17732 * @gravity: the #ClutterContentGravity
17734 * Sets the gravity of the #ClutterContent used by @self.
17736 * See the description of the #ClutterActor:content-gravity property for
17737 * more information.
17742 clutter_actor_set_content_gravity (ClutterActor *self,
17743 ClutterContentGravity gravity)
17745 ClutterActorPrivate *priv;
17747 g_return_if_fail (CLUTTER_IS_ACTOR (self));
17751 if (priv->content_gravity == gravity)
17754 priv->content_gravity = gravity;
17756 clutter_actor_queue_redraw (self);
17758 g_object_notify_by_pspec (G_OBJECT (self), obj_props[PROP_CONTENT_GRAVITY]);
17759 g_object_notify_by_pspec (G_OBJECT (self), obj_props[PROP_CONTENT_BOX]);
17763 * clutter_actor_get_content_gravity:
17764 * @self: a #ClutterActor
17766 * Retrieves the content gravity as set using
17767 * clutter_actor_get_content_gravity().
17769 * Return value: the content gravity
17773 ClutterContentGravity
17774 clutter_actor_get_content_gravity (ClutterActor *self)
17776 g_return_val_if_fail (CLUTTER_IS_ACTOR (self),
17777 CLUTTER_CONTENT_GRAVITY_RESIZE_FILL);
17779 return self->priv->content_gravity;
17783 * clutter_actor_get_content_box:
17784 * @self: a #ClutterActor
17785 * @box: (out caller-allocates): the return location for the bounding
17786 * box for the #ClutterContent
17788 * Retrieves the bounding box for the #ClutterContent of @self.
17790 * The bounding box is relative to the actor's allocation.
17792 * If no #ClutterContent is set for @self, or if @self has not been
17793 * allocated yet, then the result is undefined.
17795 * The content box is guaranteed to be, at most, as big as the allocation
17796 * of the #ClutterActor.
17798 * If the #ClutterContent used by the actor has a preferred size, then
17799 * it is possible to modify the content box by using the
17800 * #ClutterActor:content-gravity property.
17805 clutter_actor_get_content_box (ClutterActor *self,
17806 ClutterActorBox *box)
17808 ClutterActorPrivate *priv;
17809 gfloat content_w, content_h;
17810 gfloat alloc_w, alloc_h;
17812 g_return_if_fail (CLUTTER_IS_ACTOR (self));
17813 g_return_if_fail (box != NULL);
17819 box->x2 = priv->allocation.x2 - priv->allocation.x1;
17820 box->y2 = priv->allocation.y2 - priv->allocation.y1;
17822 if (priv->content == NULL)
17825 /* no need to do any more work */
17826 if (priv->content_gravity == CLUTTER_CONTENT_GRAVITY_RESIZE_FILL)
17829 /* if the content does not have a preferred size then there is
17830 * no point in computing the content box
17832 if (!clutter_content_get_preferred_size (priv->content,
17840 switch (priv->content_gravity)
17842 case CLUTTER_CONTENT_GRAVITY_TOP_LEFT:
17843 box->x2 = box->x1 + MIN (content_w, alloc_w);
17844 box->y2 = box->y1 + MIN (content_h, alloc_h);
17847 case CLUTTER_CONTENT_GRAVITY_TOP:
17848 if (alloc_w > content_w)
17850 box->x1 += ceilf ((alloc_w - content_w) / 2.0);
17851 box->x2 = box->x1 + content_w;
17853 box->y2 = box->y1 + MIN (content_h, alloc_h);
17856 case CLUTTER_CONTENT_GRAVITY_TOP_RIGHT:
17857 if (alloc_w > content_w)
17859 box->x1 += (alloc_w - content_w);
17860 box->x2 = box->x1 + content_w;
17862 box->y2 = box->y1 + MIN (content_h, alloc_h);
17865 case CLUTTER_CONTENT_GRAVITY_LEFT:
17866 box->x2 = box->x1 + MIN (content_w, alloc_w);
17867 if (alloc_h > content_h)
17869 box->y1 += ceilf ((alloc_h - content_h) / 2.0);
17870 box->y2 = box->y1 + content_h;
17874 case CLUTTER_CONTENT_GRAVITY_CENTER:
17875 if (alloc_w > content_w)
17877 box->x1 += ceilf ((alloc_w - content_w) / 2.0);
17878 box->x2 = box->x1 + content_w;
17880 if (alloc_h > content_h)
17882 box->y1 += ceilf ((alloc_h - content_h) / 2.0);
17883 box->y2 = box->y1 + content_h;
17887 case CLUTTER_CONTENT_GRAVITY_RIGHT:
17888 if (alloc_w > content_w)
17890 box->x1 += (alloc_w - content_w);
17891 box->x2 = box->x1 + content_w;
17893 if (alloc_h > content_h)
17895 box->y1 += ceilf ((alloc_h - content_h) / 2.0);
17896 box->y2 = box->y1 + content_h;
17900 case CLUTTER_CONTENT_GRAVITY_BOTTOM_LEFT:
17901 box->x2 = box->x1 + MIN (content_w, alloc_w);
17902 if (alloc_h > content_h)
17904 box->y1 += (alloc_h - content_h);
17905 box->y2 = box->y1 + content_h;
17909 case CLUTTER_CONTENT_GRAVITY_BOTTOM:
17910 if (alloc_w > content_w)
17912 box->x1 += ceilf ((alloc_w - content_w) / 2.0);
17913 box->x2 = box->x1 + content_w;
17915 if (alloc_h > content_h)
17917 box->y1 += (alloc_h - content_h);
17918 box->y2 = box->y1 + content_h;
17922 case CLUTTER_CONTENT_GRAVITY_BOTTOM_RIGHT:
17923 if (alloc_w > content_w)
17925 box->x1 += (alloc_w - content_w);
17926 box->x2 = box->x1 + content_w;
17928 if (alloc_h > content_h)
17930 box->y1 += (alloc_h - content_h);
17931 box->y2 = box->y1 + content_h;
17935 case CLUTTER_CONTENT_GRAVITY_RESIZE_FILL:
17936 g_assert_not_reached ();
17939 case CLUTTER_CONTENT_GRAVITY_RESIZE_ASPECT:
17941 double r_c = content_w / content_h;
17942 double r_a = alloc_w / alloc_h;
17951 box->y1 = (alloc_h - (alloc_w * r_c)) / 2.0f;
17952 box->y2 = box->y1 + (alloc_w * r_c);
17959 box->x1 = (alloc_w - (alloc_h * r_c)) / 2.0f;
17960 box->x2 = box->x1 + (alloc_h * r_c);
17970 box->x1 = (alloc_w - (alloc_h * r_c)) / 2.0f;
17971 box->x2 = box->x1 + (alloc_h * r_c);
17978 box->y1 = (alloc_h - (alloc_w * r_c)) / 2.0f;
17979 box->y2 = box->y1 + (alloc_w * r_c);
17988 * clutter_actor_set_content_scaling_filters:
17989 * @self: a #ClutterActor
17990 * @min_filter: the minification filter for the content
17991 * @mag_filter: the magnification filter for the content
17993 * Sets the minification and magnification filter to be applied when
17994 * scaling the #ClutterActor:content of a #ClutterActor.
17996 * The #ClutterActor:minification-filter will be used when reducing
17997 * the size of the content; the #ClutterActor:magnification-filter
17998 * will be used when increasing the size of the content.
18003 clutter_actor_set_content_scaling_filters (ClutterActor *self,
18004 ClutterScalingFilter min_filter,
18005 ClutterScalingFilter mag_filter)
18007 ClutterActorPrivate *priv;
18011 g_return_if_fail (CLUTTER_IS_ACTOR (self));
18014 obj = G_OBJECT (self);
18016 g_object_freeze_notify (obj);
18020 if (priv->min_filter != min_filter)
18022 priv->min_filter = min_filter;
18025 g_object_notify_by_pspec (obj, obj_props[PROP_MINIFICATION_FILTER]);
18028 if (priv->mag_filter != mag_filter)
18030 priv->mag_filter = mag_filter;
18033 g_object_notify_by_pspec (obj, obj_props[PROP_MAGNIFICATION_FILTER]);
18037 clutter_actor_queue_redraw (self);
18039 g_object_thaw_notify (obj);
18043 * clutter_actor_get_content_scaling_filters:
18044 * @self: a #ClutterActor
18045 * @min_filter: (out) (allow-none): return location for the minification
18047 * @mag_filter: (out) (allow-none): return location for the magnification
18050 * Retrieves the values set using clutter_actor_set_content_scaling_filters().
18055 clutter_actor_get_content_scaling_filters (ClutterActor *self,
18056 ClutterScalingFilter *min_filter,
18057 ClutterScalingFilter *mag_filter)
18059 g_return_if_fail (CLUTTER_IS_ACTOR (self));
18061 if (min_filter != NULL)
18062 *min_filter = self->priv->min_filter;
18064 if (mag_filter != NULL)
18065 *mag_filter = self->priv->mag_filter;