Clutter (computing)
Encyclopedia
Clutter is an open source
Open source
The term open source describes practices in production and development that promote access to the end product's source materials. Some consider open source a philosophy, others consider it a pragmatic methodology...

 graphics library for creating hardware-accelerated user interfaces. It relies upon OpenGL
OpenGL
OpenGL is a standard specification defining a cross-language, cross-platform API for writing applications that produce 2D and 3D computer graphics. The interface consists of over 250 different function calls which can be used to draw complex three-dimensional scenes from simple primitives. OpenGL...

 (1.4+) or OpenGL ES
OpenGL ES
OpenGL for Embedded Systems is a subset of the OpenGL 3D graphics application programming interface designed for embedded systems such as mobile phones, PDAs, and video game consoles. OpenGL ES is managed by the not-for-profit technology consortium, the Khronos Group, Inc.- Versions :Several...

 (1.1 or 2.0) for rendering, can be compiled on different platforms (X11, Darwin and Win32) and has multiple bindings to other languages (including Mono
Mono (software)
Mono, pronounced , is a free and open source project led by Xamarin to create an Ecma standard compliant .NET-compatible set of tools including, among others, a C# compiler and a Common Language Runtime....

, Perl
Perl
Perl is a high-level, general-purpose, interpreted, dynamic programming language. Perl was originally developed by Larry Wall in 1987 as a general-purpose Unix scripting language to make report processing easier. Since then, it has undergone many changes and revisions and become widely popular...

, Python, Ruby
Ruby (programming language)
Ruby is a dynamic, reflective, general-purpose object-oriented programming language that combines syntax inspired by Perl with Smalltalk-like features. Ruby originated in Japan during the mid-1990s and was first developed and designed by Yukihiro "Matz" Matsumoto...

 and Vala
Vala (programming language)
Vala is a programming language created with the goal of bringing modern language features to C, with no added runtime needs and with little overhead, by targeting the GObject object system. It is being developed by Jürg Billeter and Raffaele Sandrini. The syntax borrows heavily from C#...

). It also supports media playback using GStreamer
GStreamer
GStreamer is a pipeline-based multimedia framework written in the C programming language with the type system based on GObject.GStreamer allows a programmer to create a variety of media-handling components, including simple audio playback, audio and video playback, recording, streaming and editing...

 and 2D graphics rendering using Cairo
Cairo (graphics)
cairo is a software library used to provide a vector graphics-based, device-independent API for software developers. It is designed to provide primitives for 2-dimensional drawing across a number of different backends...

.

Clutter was created by OpenedHand Ltd
OpenedHand
OpenedHand was an embedded Linux start-up that was acquired by Intel in Q3, 2008. The firm developed a OpenEmbedded distribution called Poky Linux and the Clutter library. The latter is heavily used in the customized UIs of Maemo and Moblin, embedded Linux distributions from Nokia and Intel,...

, now part of Intel
Intel Corporation
Intel Corporation is an American multinational semiconductor chip maker corporation headquartered in Santa Clara, California, United States and the world's largest semiconductor chip maker, based on revenue. It is the inventor of the x86 series of microprocessors, the processors found in most...

. Licensed under the LGPL
GNU Lesser General Public License
The GNU Lesser General Public License or LGPL is a free software license published by the Free Software Foundation . It was designed as a compromise between the strong-copyleft GNU General Public License or GPL and permissive licenses such as the BSD licenses and the MIT License...

 v2.1, Clutter is free
Free software
Free software, software libre or libre software is software that can be used, studied, and modified without restriction, and which can be copied and redistributed in modified or unmodified form either without restriction, or with restrictions that only ensure that further recipients can also do...

 and open source
Open source
The term open source describes practices in production and development that promote access to the end product's source materials. Some consider open source a philosophy, others consider it a pragmatic methodology...

 software.

Programming languages

Clutter is implemented using the C programming language
C (programming language)
C is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating system....

 with a design based on the GObject
GObject
The GLib Object System, or GObject, is a free software library providing a portable object system and transparent cross-language interoperability...

 object system. Bindings are available for these languages:
  • C++
    C++
    C++ is a statically typed, free-form, multi-paradigm, compiled, general-purpose programming language. It is regarded as an intermediate-level language, as it comprises a combination of both high-level and low-level language features. It was developed by Bjarne Stroustrup starting in 1979 at Bell...

     (cluttermm)
  • Perl
    Perl
    Perl is a high-level, general-purpose, interpreted, dynamic programming language. Perl was originally developed by Larry Wall in 1987 as a general-purpose Unix scripting language to make report processing easier. Since then, it has undergone many changes and revisions and become widely popular...

     (clutter-perl)
  • Ruby (rbclutter)
  • Python
    Python (programming language)
    Python is a general-purpose, high-level programming language whose design philosophy emphasizes code readability. Python claims to "[combine] remarkable power with very clear syntax", and its standard library is large and comprehensive...

     (PyClutter)
  • Vala
    Vala (programming language)
    Vala is a programming language created with the goal of bringing modern language features to C, with no added runtime needs and with little overhead, by targeting the GObject object system. It is being developed by Jürg Billeter and Raffaele Sandrini. The syntax borrows heavily from C#...

     (clutter-vala)
  • C# (clutter-sharp (aka Clutter#))
  • JavaScript
    JavaScript
    JavaScript is a prototype-based scripting language that is dynamic, weakly typed and has first-class functions. It is a multi-paradigm language, supporting object-oriented, imperative, and functional programming styles....

     (Seed and GJS)
  • Haskell
    Haskell (programming language)
    Haskell is a standardized, general-purpose purely functional programming language, with non-strict semantics and strong static typing. It is named after logician Haskell Curry. In Haskell, "a function is a first-class citizen" of the programming language. As a functional programming language, the...

     (clutterhs)

Platforms

Clutter is developed on the X Window System
X Window System
The X window system is a computer software system and network protocol that provides a basis for graphical user interfaces and rich input device capability for networked computers...

, 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
Mac OS X
Mac OS X is a series of Unix-based operating systems and graphical user interfaces developed, marketed, and sold by Apple Inc. Since 2002, has been included with all new Macintosh computer systems...

 has been added. A native Microsoft Windows
Microsoft Windows
Microsoft Windows is a series of operating systems produced by Microsoft.Microsoft introduced an operating environment named Windows on November 20, 1985 as an add-on to MS-DOS in response to the growing interest in graphical user interfaces . Microsoft Windows came to dominate the world's personal...

 backend is supported since the 0.8 release. Windows pre-compiled dll's can be found on or , however, you can build the latest dll for Windows with MinGW and Bash shell for Windows.

Design

Clutter is a scene graph
Scene graph
A scene graph is a general data structure commonly used by vector-based graphics editing applications and modern computer games. Examples of such programs include Acrobat 3D, Adobe Illustrator, AutoCAD, CorelDRAW, OpenSceneGraph, OpenSG, VRML97, and X3D....

 based canvas working in retained mode
Retained mode
In computing, retained mode rendering is a style for application programming interfaces of graphics libraries, in which the libraries retain a complete model of the objects to be rendered.-Overview:...

. 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 for creating the main container for the scene graph; this top level container is called the stage. Items on the stage are called actors.

Instead of operating on matrices, as does OpenGL
OpenGL
OpenGL is a standard specification defining a cross-language, cross-platform API for writing applications that produce 2D and 3D computer graphics. The interface consists of over 250 different function calls which can be used to draw complex three-dimensional scenes from simple primitives. OpenGL...

, the Clutter developer changes properties of each actor. Clutter will then notice the changes, and render the scene accordingly.

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_text_new_with_text ("Sans 32px", "Hello, world");
clutter_container_add_actor (CLUTTER_CONTAINER (stage), label);
These statements 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.



float x, y;

x = (clutter_actor_get_width (stage) - clutter_actor_get_width (label)) / 2;
y = (clutter_actor_get_height (stage) - clutter_actor_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 (stage);
These statements will show the stage. All actors in Clutter are visible unless explicitly hidden, except for the stage; thus showing the stage will automatically display all of its visible children.

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
Tweening
Inbetweening or tweening is the process of generating intermediate frames between two images to give the appearance that the first image evolves smoothly into the second image. Inbetweens are the drawings between the key frames which help to create the illusion of motion...

. Clutter provides a generic base class
Class (computer science)
In object-oriented programming, a class is a construct that is used as a blueprint to create instances of itself – referred to as class instances, class objects, instance objects or simply objects. A class defines constituent members which enable these class instances to have state and behavior...

 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.

Since Clutter 1.0, it is also possible to create simple, one-off animations using the ClutterAnimation class and the clutter_actor_animate convenience function. The clutter_actor_animate function animates an actor properties between their current state and the specified final state.

Example

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


ClutterTimeline *timeline = clutter_timeline_new (2000);
ClutterAlpha *alpha = clutter_alpha_new_full (timeline, CLUTTER_LINEAR);
ClutterBehaviour *behaviour = clutter_behaviour_scale_new (alpha,
1.0, 1.0, /* initial scaling factors */
2.0, 2.0 /* final scaling factors */ );
clutter_behaviour_apply (behaviour, label);
These statements will create a Timeline with a duration of 2000 milliseconds; an Alpha, binding the Timeline to a linear easing mode; a Behaviour, which will scale any actor to which it is applied between factor 1.0 and factor 2.0 (both horizontally and vertically). Finally, it applies the behaviour to an actor.


The equivalent code using the implicit animations API is:


clutter_actor_animate (label, /* the actor to animate */
CLUTTER_LINEAR, /* the easing mode */
2000, /* the duration of the animation */
"scale-x", 2.0, /* final horizontal scaling factor */
"scale-y", 2.0, /* final vertical scaling factor */
NULL);
This statement will create an implicit ClutterAnimation object, which will animate the provided GObject properties between their current value and the specified final value.

Interface builder

Clutter can build user interfaces using a specialized JSON
JSON
JSON , or JavaScript Object Notation, is a lightweight text-based open standard designed for human-readable data interchange. It is derived from the JavaScript scripting language for representing simple data structures and associative arrays, called objects...

 dialect. The entire scene graph is defined using JSON types and built at run time through the ClutterScript class.

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,
"title" : "Script demo",
"children" : [
{
"id" : "hello-label",
"type" : "ClutterText",
"x" : 400,
"y" : 300,
"text" : "Hello, world!",
"color" : "black",
"font-name" : "Sans 48px"
}
],
"signals" : [
{ "name" : "destroy", "handler" : "clutter_main_quit" }
]
}


The definition can be saved into a file or as a string, and loaded using:


ClutterScript *script = clutter_script_new ;
GError *error = NULL;
clutter_script_load_from_data (script, description, -1, &error);
if (error)
{
g_warning ("Unable to load UI description: %s", error->message);
g_error_free (error);
}
else
{
GObject *stage;

clutter_script_connect_signals (script, NULL); /* connect the signal handlers */
stage = clutter_script_get_object (script, "main-stage"); /* get the "main-stage" object */
clutter_actor_show (CLUTTER_ACTOR (stage));
}

Integration libraries

Clutter can be integrated with other libraries and toolkits, for instance:
  • GTK+
    GTK+
    GTK+ is a cross-platform widget toolkit for creating graphical user interfaces. It is licensed under the terms of the GNU LGPL, allowing both free and proprietary software to use it. It is one of the most popular toolkits for the X Window System, along with Qt.The name GTK+ originates from GTK;...

     applications can embed Clutter stages using a special widget.
  • Clutter applications can embed GTK+ widgets using the 'client-side windows' feature since GTK+ 2.18.
  • Clutter applications can use GStreamer
    GStreamer
    GStreamer is a pipeline-based multimedia framework written in the C programming language with the type system based on GObject.GStreamer allows a programmer to create a variety of media-handling components, including simple audio playback, audio and video playback, recording, streaming and editing...

     to play videos directly into a Clutter texture actor.
  • Clutter applications can use Cairo
    Cairo (graphics)
    cairo is a software library used to provide a vector graphics-based, device-independent API for software developers. It is designed to provide primitives for 2-dimensional drawing across a number of different backends...

     to draw onto a texture.

See also

  • List of widget toolkits
  • Core Animation
    Core Animation
    Core Animation is a data visualization API used by Mac OS X 10.5 and later as well as iOS to produce animated user interfaces.-Overview:Core Animation provides a way for developers to produce animated user interfaces via an implicit animation model as well as an "explicit" model...

  • Windows Presentation Foundation
    Windows Presentation Foundation
    Developed by Microsoft, the Windows Presentation Foundation is a computer-software graphical subsystem for rendering user interfaces in Windows-based applications. WPF, previously known as "Avalon", was initially released as part of .NET Framework 3.0. Rather than relying on the older GDI...

  • Qt (framework)

External links

The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK