Next: , Previous: ClutterBehaviourScale, Up: Top


12 ClutterBehaviour

Class for providing behaviours to actors

12.1 Overview

<clutter-behaviour> is the base class for implementing behaviours. A behaviour is a controller object for <clutter-actor>s; you can use a behaviour to control one or more properties of an actor (such as its opacity, or its position). A <clutter-behaviour> is driven by an "alpha function" stored inside a <clutter-alpha> object; an alpha function is a function depending solely on time. The alpha function computes a value which is then applied to the properties of the actors driven by a behaviour.

Clutter provides some pre-defined behaviours, like <clutter-behaviour-path>, which controls the position of a set of actors making them "walk" along a set of nodes; <clutter-behaviour-opacity>, which controls the opacity of a set of actors; <clutter-behaviour-scale>, which controls the width and height of a set of actors.

To visualize the effects of different alpha functions on a <clutter-behaviour> implementation it is possible to take the <clutter-behaviour-path> as an example:

(The missing figure, behaviour-path-alpha

The actors position between the path's end points directly correlates to the <clutter-alpha>'s current alpha value driving the behaviour. With the <clutter-alpha>'s function set to ‘CLUTTER_ALPHA_RAMP_INC’ the actor will follow the path at a constant velocity, but when changing to ‘CLUTTER_ALPHA_SINE_INC’ the actor initially accelerates before quickly decelerating.

In order to implement a new behaviour you should subclass <clutter-behaviour> and override the "alpha_notify" virtual function; inside the overridden function you should obtain the alpha value from the <clutter-alpha> instance bound to the behaviour and apply it to the desiderd property (or properties) of every actor controlled by the behaviour.

<clutter-behaviour> is available since Clutter 0.2

12.2 Usage

— Class: <clutter-behaviour>

Derives from <gobject>.

This class defines the following slots:

alpha
Alpha Object to drive the behaviour
— Signal on <clutter-behaviour>: applied (arg0 <clutter-actor>)

The ::apply signal is emitted each time the behaviour is applied to an actor.

Since 0.4

— Signal on <clutter-behaviour>: removed (arg0 <clutter-actor>)

The ::removed signal is emitted each time a behaviour is not applied to an actor anymore.

— Function: clutter-behaviour-apply (self <clutter-behaviour>) (actor <clutter-actor>)
— Method: apply

Applies behave to actor. This function adds a reference on the actor.

behave
a <clutter-behaviour>
actor
a <clutter-actor>

Since 0.2

— Function: clutter-behaviour-remove (self <clutter-behaviour>) (actor <clutter-actor>)
— Method: remove

Removes actor from the list of <clutter-actor>s to which behave applies. This function removes a reference on the actor.

behave
a <clutter-behaviour>
actor
a <clutter-actor>

Since 0.2

— Function: clutter-behaviour-remove-all (self <clutter-behaviour>)
— Method: remove-all

Removes every actor from the list that behave holds.

behave
a <clutter-behaviour>

Since 0.4

— Function: clutter-behaviour-is-applied (self <clutter-behaviour>) (actor <clutter-actor>)   (ret bool)
— Method: is-applied

Check if behave applied to actor.

behave
a <clutter-behaviour>
actor
a <clutter-actor>
ret
TRUE if actor has behaviour. FALSE otherwise.

Since 0.4

— Function: clutter-behaviour-get-actors (self <clutter-behaviour>)   (ret gslist-of)
— Method: get-actors

Retrieves all the actors to which behave applies. It is not recommended for derived classes to use this in there alpha notify method but use <clutter-behaviour-actors-foreach> as it avoids alot of needless allocations.

behave
a <clutter-behaviour>
ret
a list of actors. You should free the returned list with g-slist-free when finished using it.

Since 0.2

— Function: clutter-behaviour-get-n-actors (self <clutter-behaviour>)   (ret int)
— Method: get-n-actors

Gets the number of actors this behaviour is applied too.

behave
a <clutter-behaviour>
ret
The number of applied actors

Since 0.2

— Function: clutter-behaviour-get-nth-actor (self <clutter-behaviour>) (index_ int)   (ret <clutter-actor>)
— Method: get-nth-actor

Gets an actor the behaviour was applied to referenced by index num.

behave
a <clutter-behaviour>
index
the index of an actor this behaviour is applied too.
ret
A Clutter actor or NULL if index is invalid.

Since 0.2

— Function: clutter-behaviour-get-alpha (self <clutter-behaviour>)   (ret <clutter-alpha>)
— Method: get-alpha

Retrieves the <clutter-alpha> object bound to behave.

behave
a <clutter-behaviour>
ret
a <clutter-alpha> object, or ‘#f’ if no alpha object has been bound to this behaviour.

Since 0.2

— Function: clutter-behaviour-set-alpha (self <clutter-behaviour>) (alpha <clutter-alpha>)
— Method: set-alpha

Binds alpha to a <clutter-behaviour>. The <clutter-alpha> object is what makes a behaviour work: for each tick of the timeline used by <clutter-alpha> a new value of the alpha parameter is computed by the alpha function; the value should be used by the <clutter-behaviour> to update one or more properties of the actors to which the behaviour applies.

behave
a <clutter-behaviour>
alpha
a <clutter-alpha> or ‘#f’ to unset a previously set alpha

Since 0.2