Clutter concepts
Translation of the original in Catalan. Read it in: CatalàCastellano
A few months ago I started working in depth with
, it is an
plus an
programmed in C to create user interfaces. Although it is essentially an API to create 3D spaces with 2D objects, it has the ability to move objects along the Z coordinate. So you can take advantage of OpenGL's power in a transparent and simple way, without having to worry about how to render 2D objects in 3D spaces, which is no easy thing for a newcomer to the world of graphics like me.
Clutter uses its own event reactor, but in certain cases it can also use Gobject, Glib and Gtk. It integrates easily with DBUS and with GStreamer. Essentially it offers me everything I need for a project I have in hand. For those of you who still haven't got it clear, the graphical interface that
uses is programmed with Clutter as its graphics library. In fact, it is this project that has given Clutter a lot of momentum: it has 29 full-time programmers, of whom 14 are not from
(intel is the one pushing 'moblin' hardest).
Well then, this push that moblin has received has taken it to version 0.9.8, which is really powerful and already almost the same as the 1.0 version that should be out soon. Although so far Clutter has been characterised by delays in the release of new versions, let's hope this time it is not like that.
Before going on to define which elements this library has, let me say that it also has a python
binding
, which for 'non-programmers', like me, is a real joy. It should also be said that as of today there are no official
bindings
for the 0.9 branch of Clutter, which is the experimental one, or the future 1.0. So I have only tried Clutter up to version 0.8, although I follow version 0.9.x closely; waiting to be able to start doing things with it once the python
bindings
are available.
Let's get to the main point of the article, going over the concepts Clutter uses up to version 0.8:
- Stages: a Clutter application contains at least one 'stage', these contain actors which are: images, rectangles, texts, etc. A 'stage' behaves in a way similar to a 'canvas' (a tapestry).
- Stage Widget: we can have a 'stage' inside a GTK+ window object. In these cases GTK can be used as the event reactor.
- Actors: they are 2D shapes shown in a 3D space. These shapes can be, for example, geometric shapes, images, texts, etc. If what you need is to have three-dimensional actors in this space, then you will have to instantiate the OpenGL API directly. To show an actor on a 'stage' you have to do it through a 'container'.
- Transformations: it refers to the transformations we can apply to an 'actor' when showing it:
- Scaling: increasing or decreasing its apparent size, not its real one.
- Rotation: it can be rotated on its X, Y and Z axes.
- Clipping: fixing the object on the 'canvas'; this allows us, for example, to create a scrolling area inside it.
- Movement: shifting the object's position coordinates.
- Containers: in itself it is a special kind of actor, made up of other child actors that are positioned in space relative to the position of their container. In fact, if we look closely, the 'stage' itself is an 'actor' of type 'container'. Essentially there are two kinds of 'containers': ClutterContainer and ClutterGroup.
- Events: the 'actor' class emits a series of signals that we can capture to link to functions; the signals are:
- button-press-event: emitted when the user presses the mouse button on the actor.
- button-release-event: emitted when the user releases the mouse button on the actor.
- motion-event: when the mouse moves over the object.
- enter-event: emitted when entering the actor's surface.
- leave-event: emitted when leaving the actor's surface.
- Timelines: they can be used to change an actor's position or appearance over time. Timelines can be used on their own or in combination with 'effects' and 'behaviours'. For each 'frame' that has to be drawn in time a signal called 'new-frame' is emitted, which of course we can connect to some function. When creating a timeline we have to specify two parameters: the total number of 'frames' it will have and the 'frames per second' at which it will play.
- Score: we can group several 'timelines' into a 'score', this allows us to start or stop several 'timelines' at the same time.
- Effects: they are a series of functions we can apply to actors using a 'timeline' in order to change their properties over time, using a simple numerical calculation. Often this is the simplest way to create an animation. It is important to remember that effects can only affect one actor in a 'timeline' and we cannot change the effects over time; to do that you have to use a 'behaviour'.
- Behaviours: they have the ability to change a specific property of an actor over time by applying a simple numerical calculation. Unlike 'effects', with 'behaviours' we can control more than one actor at a time and change the parameters of the calculations that are made along the 'timeline'. A very simple example of applying this would be that we can make the function that is called over time detect that the applied effect has finished and make it start again automatically, simply by changing the parameter of the effect that is being applied. The 'behaviours' that Clutter has by default are:
- ClutterBehaviourBspline: moves the actor along a 'bezier' line.
- ClutterBehaviourDepth: moves an actor on the Z axis.
- ClutterBehaviourEllipse: moves an actor along an ellipse.
- ClutterBehaviourOpacity: changes the opacity of an actor.
- ** ClutterBehaviourPath**: moves an actor along a path defined by a series of points.
- ClutterBehaviourRotate: rotates an actor.
- ClutterBehaviourScale: changes the apparent size of an actor.
To write this reference I have based myself on the information in the guide '
' written by Murray Cumming.