Clutter (computing)

From Wikipedia, the free encyclopedia

Clutter
Developed by OpenedHand Ltd
Initial release 22 June 2006
Latest release 0.6.0 / February 18, 2008 (2008-02-18); 112 days ago
Written in C
OS Cross-platform
Available in English
Genre Graphics library
License LGPL
Website Clutter Project

Clutter is an open source graphics library for creating hardware-accelerated user interfaces. It relies upon OpenGL (1.2 or 2.0) or OpenGL ES (1.1) for rendering, can be compiled on different platforms (X11, Darwin and Win32) and has multiple bindings to other languages (including Mono, Perl, Python, Ruby and Vala). It also supports media playback using GStreamer and 2D graphics rendering using Cairo.

Clutter was created by OpenedHand Ltd. Licensed under the LGPL, Clutter is free software (and open source).

Contents

[edit] Programming languages

Clutter uses the C programming language, although its design uses the GObject object system. Bindings are available for these languages:

[edit] Platforms

Clutter is developed on the X Window System, using the GLX extension. It is also targeted to embedded environments, either using X or the native frame buffer. As of release 0.6, native support for Mac OS X has been added. Microsoft Windows is supported through the Simple DirectMedia Layer backend.

[edit] Design

Clutter is a scene graph based canvas working in retained mode. Every object on the scene is (usually) a 2D surface inside a 3D space.

Clutter abstracts the native windowing environment behind a backend, which is also responsible of creating the main container for the scene graph; this top level container is called stage. Items on the stage are called actors.

Instead of working on matrices, like OpenGL, the developer changes properties on each actor. Clutter will then take care of rendering the scene accordingly.

[edit] Example

This example will add a label on the stage.

ClutterActor *stage = clutter_stage_get_default ();
This statement will retrieve the default stage, which will contain all the actors on the scene.
ClutterActor *label = clutter_label_new_with_text ("Sans 32px", "Hello, world");
clutter_container_add_actor (CLUTTER_CONTAINER (stage), label);
These statement will create a new label, using the Sans font 32 pixels high, and with the "Hello, world" text, and will place it into the stage.
gint x, y;
 
x = (clutter_actor_get_width (stage) + clutter_label_get_width (label)) / 2;
y = (clutter_actor_get_height (stage) + clutter_label_get_height (label)) / 2;
clutter_actor_set_position (label, x, y);
These statements will position the label at the center of the stage, taking into account the stage and the label size.
clutter_actor_show (label);
clutter_actor_show (stage);
These statements will show the label and the stage.

[edit] Animation

Clutter allows implicit animations of every item on the canvas using special objects called behaviours: each behaviour can be applied to multiple actors, and multiple behaviours can be composed on the same actor. Behaviours handle animations implicitly: the developer specifies the initial and final states, the time (or number of frames) needed to complete the animation, the function of time to be used (linear, sine wave, exponential, etc.), and the behaviour will take care of the tweening. Clutter provides a generic base class for developers to implement custom behaviours, and various simple classes handling simple properties, like opacity, position on the Z axis (depth), position along a path, rotation, etc.

[edit] Example

This example will scale the label from its size to a factor of 2 in 2 seconds, using a linear function of time:

ClutterTimeline *timeline = clutter_timeline_new_for_duration (2000); /* milliseconds */
ClutterAlpha *alpha = clutter_alpha_new_full (timeline, clutter_ramp_func, NULL, NULL);
These statements will create a timeline, a clock function which will be used to time the animation; and an alpha, an object binding the timeline to a function.
ClutterBehaviour *behaviour;
 
behaviour = clutter_behaviour_scale_new (alpha,
                                         1.0, 1.0, /* scale factor on the X axis */
                                         2.0, 2.0  /* scale factor on the Y axis */);
clutter_behaviour_apply (behaviour, label);
These statements will create a new behaviour and will apply it to the label.
clutter_timeline_start (timeline);
This statement will start the animation.

[edit] Interface builder

Clutter can build user interfaces using a specialized JSON dialect. The entire scene graph is defined using JSON types and built at run time through the ClutterScript class.

[edit] Example

This definition will create the main window and place a label with the text Hello, world! inside it.

{
  "id" : "main-stage",
  "type" : "ClutterStage",
  "color" : "white"
  "width" : 800,
  "height" : 600,
  "children" : [
    {
      "id" : "hello-label",
      "type" : "ClutterLabel",
      "x" : 400,
      "y" : 300,
      "text" : "Hello, world!",
      "color" : "black"
    }
  ]
}

[edit] Integration libraries

Clutter can be integrated with other libraries and toolkits, for instance:

  • GTK+ applications can embed the Clutter stage using a special widget
  • Clutter applications can use GStreamer to play videos directly into a Clutter texture actor
  • Clutter applications can use Cairo to draw onto a texture

Experimental support is present for using WebKit to render a web page onto a Clutter texture.[1]

[edit] See also

[edit] References

[edit] External links