Next: , Previous: ClutterBackend, Up: Top


12 ClutterBindConstraint

A constraint binding the position or size of an actor

12.1 Overview

<clutter-bind-constraint> is a <clutter-constraint> that binds the position or the size of the <clutter-actor> to which it is applied to the the position or the size of another <clutter-actor>, or "source".

An offset can be applied to the constraint, to avoid overlapping. The offset can also be animated. For instance, the following code will set up three actors to be bound to the same origin:

     
     /&#x002A; source &#x002A;/
     rect[0] = clutter_rectangle_new_with_color (&red_color);
     clutter_actor_set_position (rect[0], x_pos, y_pos);
     clutter_actor_set_size (rect[0], 100, 100);
     
     /&#x002A; second rectangle &#x002A;/
     rect[1] = clutter_rectangle_new_with_color (&green_color);
     clutter_actor_set_size (rect[1], 100, 100);
     clutter_actor_set_opacity (rect[1], 0);
     
     constraint = clutter_bind_constraint_new (rect[0], CLUTTER_BIND_X, 0.0);
     clutter_actor_add_constraint_with_name (rect[1], "green-x", constraint);
     constraint = clutter_bind_constraint_new (rect[0], CLUTTER_BIND_Y, 0.0);
     clutter_actor_add_constraint_with_name (rect[1], "green-y", constraint);
     
     /&#x002A; third rectangle &#x002A;/
     rect[2] = clutter_rectangle_new_with_color (&blue_color);
     clutter_actor_set_size (rect[2], 100, 100);
     clutter_actor_set_opacity (rect[2], 0);
     
     constraint = clutter_bind_constraint_new (rect[0], CLUTTER_BIND_X, 0.0);
     clutter_actor_add_constraint_with_name (rect[2], "blue-x", constraint);
     constraint = clutter_bind_constraint_new (rect[0], CLUTTER_BIND_Y, 0.0);
     clutter_actor_add_constraint_with_name (rect[2], "blue-y", constraint);

The following code animates the second and third rectangles to "expand" them horizontally from underneath the first rectangle:

     
     clutter_actor_animate (rect[1], CLUTTER_EASE_OUT_CUBIC, 250,
                            "@constraints.green-x.offset", 100.0,
                            "opacity", 255,
                            NULL);
     clutter_actor_animate (rect[2], CLUTTER_EASE_OUT_CUBIC, 250,
                            "@constraints.blue-x.offset", 200.0,
                            "opacity", 255,
                            NULL);
     

The example above creates eight rectangles and binds them to a rectangle positioned in the center of the stage; when the user presses the center rectangle, the <"offset"> property is animated through the clutter-actor-animate function to lay out the eight rectangles around the center one. Pressing one of the outer rectangles will animate the offset back to 0.

<clutter-bind-constraint> is available since Clutter 1.4

12.2 Usage

— Function: clutter-bind-constraint-new (source <clutter-actor>) (coordinate <clutter-bind-coordinate>) (offset float) ⇒  (ret <clutter-constraint>)

Creates a new constraint, binding a <clutter-actor>'s position to the given coordinate of the position of source

source
the <clutter-actor> to use as the source of the binding, or ‘#f’.
coordinate
the coordinate to bind
offset
the offset to apply to the binding, in pixels
ret
the newly created <clutter-bind-constraint>

Since 1.4

— Function: clutter-bind-constraint-set-source (self <clutter-bind-constraint>) (source <clutter-actor>)
— Method: set-source

Sets the source <clutter-actor> for the constraint

constraint
a <clutter-bind-constraint>
source
a <clutter-actor>, or ‘#f’ to unset the source.

Since 1.4

— Function: clutter-bind-constraint-get-source (self <clutter-bind-constraint>) ⇒  (ret <clutter-actor>)
— Method: get-source

Retrieves the <clutter-actor> set using clutter-bind-constraint-set-source

constraint
a <clutter-bind-constraint>
ret
a pointer to the source actor.

Since 1.4

— Function: clutter-bind-constraint-set-offset (self <clutter-bind-constraint>) (offset float)
— Method: set-offset

Sets the offset to be applied to the constraint

constraint
a <clutter-bind-constraint>
offset
the offset to apply, in pixels

Since 1.4

— Function: clutter-bind-constraint-get-offset (self <clutter-bind-constraint>) ⇒  (ret float)
— Method: get-offset

Retrieves the offset set using clutter-bind-constraint-set-offset

constraint
a <clutter-bind-constraint>
ret
the offset, in pixels

Since 1.4