4. Overriding the paint sequence
Prev | Chapter 2. Actors | Next

## 4. Overriding the paint sequence

### 4.1. Problem

You want to override the way an actor paints itself without creating a subclass.

### 4.2. Solution

You can use the paint signal to invoke a callback that will be executed before the actor's paint implementation:

    g_signal_connect (actor, "paint", G_CALLBACK (on_paint), NULL);

You can paint something after the actor's paint implementation by using the `g_signal_connect_after()` function instead of `g_signal_connect()`:

    g_signal_connect_after (actor, "paint", G_CALLBACK (on_paint_after), NULL);

The signature for the handler of the "paint" signal is:

    void on_paint (ClutterActor *actor, gpointer user_data);

### 4.3. Discussion

The paint cycle in Clutter works its way recursively from the stage through every child.

Whenever an Actor is going to be painted it will be positioned in a new frame of reference according to the list of transformations (scaling, rotation and additional translations). After that, the "paint" signal will be emitted.

The "paint" signal is defined as run-last, that is the signal handlers connected to it using `g_signal_connetc()` will be called first; then the default handler defined by the Actor's sub-class will be called; finally, all the signal handlers connected to the signal using `g_signal_connect_after()` will be called.

This allows pre- and post-default paint handlers, and it also allows completely overriding the way an Actor draws itself by default; for instance:

    void
    on_paint (ClutterActor *actor)
    {
      do_my_paint (actor);

      g_signal_stop_emission_by_name (actor, "paint");
    }

The code above will prevent the default paint implementation of the actor from running.

Prev | Up | Next
3. Knowing when an actor's position or size changes | Home | 5. Making an actor transparent by changing its opacity