Effect


Object Hierarchy:

Object hierarchy for Effect

Description:

[ CCode ( type_id = "clutter_effect_get_type ()" ) ]
[ Version ( since = "1.4" ) ]
public abstract class Effect : ActorMeta

The Effect class provides a default type and API for creating effects for generic actors.

Effects are a ActorMeta sub-class that modify the way an actor is painted in a way that is not part of the actor's implementation.

Effects should be the preferred way to affect the paint sequence of an actor without sub-classing the actor itself and overriding the paint_ virtual function.

typeof (unichar2) typeof (unichar2) Implementing a ClutterEffect

Creating a sub-class of Effect requires overriding the paint method. The implementation of the function should look something like this:

void effect_paint (ClutterEffect *effect, ClutterEffectPaintFlags flags)
{
// Set up initialisation of the paint such as binding a
// CoglOffscreen or other operations

// Chain to the next item in the paint sequence. This will either call
// ‘paint’ on the next effect or just paint the actor if this is
// the last effect.
ClutterActor *actor =
clutter_actor_meta_get_actor (CLUTTER_ACTOR_META (effect));

clutter_actor_continue_paint (actor);

// perform any cleanup of state, such as popping the CoglOffscreen
}

The effect can optionally avoid calling continue_paint to skip any further stages of the paint sequence. This is useful for example if the effect contains a cached image of the actor. In that case it can optimise painting by avoiding the actor paint and instead painting the cached image.

The ACTOR_DIRTY flag is useful in this case. Clutter will set this flag when a redraw has been queued on the actor since it was last painted. The effect can use this information to decide if the cached image is still valid.

typeof (unichar2) typeof (unichar2) A simple ClutterEffect implementation

The example below creates two rectangles: one will be painted "behind" the actor, while another will be painted "on top" of the actor.

The set_actor implementation will create the two materials used for the two different rectangles; the paint implementation will paint the first material using rectangle, before continuing and then it will paint paint the second material after.

 typedef struct {
ClutterEffect parent_instance;

CoglHandle rect_1;
CoglHandle rect_2;
} MyEffect;

typedef struct _ClutterEffectClass MyEffectClass;

G_DEFINE_TYPE (MyEffect, my_effect, CLUTTER_TYPE_EFFECT);

static void
my_effect_set_actor (ClutterActorMeta *meta,
ClutterActor *actor)
{
MyEffect *self = MY_EFFECT (meta);

// Clear the previous state //
if (self->rect_1)
{
cogl_handle_unref (self->rect_1);
self->rect_1 = NULL;
}

if (self->rect_2)
{
cogl_handle_unref (self->rect_2);
self->rect_2 = NULL;
}

// Maintain a pointer to the actor
self->actor = actor;

// If we've been detached by the actor then we should just bail out here
if (self->actor == NULL)
return;

// Create a red material
self->rect_1 = cogl_material_new ();
cogl_material_set_color4f (self->rect_1, 1.0, 0.0, 0.0, 1.0);

// Create a green material
self->rect_2 = cogl_material_new ();
cogl_material_set_color4f (self->rect_2, 0.0, 1.0, 0.0, 1.0);
}

static gboolean
my_effect_paint (ClutterEffect *effect)
{
MyEffect *self = MY_EFFECT (effect);
gfloat width, height;

clutter_actor_get_size (self->actor, &width, &height);

// Paint the first rectangle in the upper left quadrant
cogl_set_source (self->rect_1);
cogl_rectangle (0, 0, width / 2, height / 2);

// Continue to the rest of the paint sequence
clutter_actor_continue_paint (self->actor);

// Paint the second rectangle in the lower right quadrant
cogl_set_source (self->rect_2);
cogl_rectangle (width / 2, height / 2, width, height);
}

static void
my_effect_class_init (MyEffectClass *klass)
{
ClutterActorMetaClas *meta_class = CLUTTER_ACTOR_META_CLASS (klass);

meta_class->set_actor = my_effect_set_actor;

klass->paint = my_effect_paint;
}

Effect is available since Clutter 1.4


Namespace: Clutter
Package: clutter-1.0

Content:

Creation methods:

Methods:

Inherited Members:

All known members inherited from class Clutter.ActorMeta