1 first recognized clutter
According to the clutter official website, clutter is a GUI library that supports 3D animation of 2D surfaces and is a set of C APIs. The current version is clutter1.8.0-stable release, http://download.gnome.org/sources/clutter/1.8.
2 programming in gjs
Const clutter = imports. gi. clutter;
It is through this statement that the clutter module is imported into gjs programming, so that gjs can access the clutter lib Based on the C language at the underlying layer.
2.1 Basic Class
Clutter's core concepts are: stage (canvas, stage) and actor (actor ). Shakespeare said, "The world is a stage, and all men and women are actors. The canvas is equivalent to a stage where a window is an actor. Clutter is an encapsulation that contains a iner. Therefore, all clutter programs need to create a stage, which is the top-level object and a container for other actors to perform on it. Actors are 2D objects and flat objects, but clutter allows us to perform operations on these actors in 3D space, such as rotating around X, Y, and Z axes.
2.2 simple programming example (C to gjs)
The program embeds a small rectangle in a rectangle, displays the text, and accepts the mouse event.
Int main (INT argc, char ** argv) |
{ |
Cluttercolor stage_color = {0x00,0x00,0x00, 0xff }; |
Clutter_init (& argc, & argv ); |
Clutteractor * stage = clutter_stage_get_default (); |
Clutter_actor_set_size (stage, 200,200 ); |
Clutter_stage_set_color (clutter_stage (stage), & stage_color ); |
Clutteractor * Actor = clutter_rectangle_new (); |
Clutter_actor_set_size (actor, 100,100 ); |
Clutter_container_add_actor (clutter_container (stage), actor ); |
Clutter_actor_set_position (actor, 50, 50 ); |
Cluttercolor color_color = {0xff, 0xff, 0xff, 0xff }; |
Clutteractor * label = clutter_text_new_full ("sans 12", "alex_test", & color_color ); |
Clutter_actor_set_size (Label, 50, 20 ); |
Clutter_actor_set_position (Label, 20,160 ); |
Clutter_container_add_actor (clutter_container (stage), label ); |
Clutter_actor_set_scale (actor, 0.5, 0.5 ); |
Clutter_actor_set_scale (actor, 0.5, 0.5 ); |
Clutter_actor_show (stage ); |
G_signal_connect (stage, "button-press-Event ", |
G_callback (on_stage_button_press), null ); |
Clutter_main (); |
Return exit_success; |
} |
To use gjs programming, you need to change mothod and use clutter programming in the gjs environment. Method class call, you can refer to the Clutter-1.0.gir (see below ).
<Class name = "timeline" |
C: Symbol-Prefix = "timeline" |
C: TYPE = "cluttertimeline" |
Version = "0.2" |
Parent = "gobject. Object" |
Glib: Type-name = "cluttertimeline" |
Glib: Get-type = "clutter_timeline_get_type" |
Glib: Type-struct = "timelineclass"> |
2.3 cluttertimeline
Clutter not only allows us to operate 2D actor in 3D space, but also allows us to use time series.
The following is the code used to hide the bar in the dockbar JS file:
_ Hidedock: function (){ |
This. _ timeline = new clutter. Timeline ({duration: 200 }); |
This. _ timeline. Start (); |
This. _ timeline. Connect ('new-framework', Lang. BIND (this, |
Function (timeline, frame ){ |
This. _ onhidenewframe (FRAME ); |
})); |
Hidedock = true; |
}, |
_ Onhidenewframe: function (FRAME ){ |
Let monitor = Global. get_primary_monitor (); |
This. _ time = This. _ timeline. get_elapsed_time (); |
This. bin. set_position (-This. Actor. width) * (this. _ time/200) + 1, monitor. Height * 0.122 ); |
}, |
3 appendix
For details about how to import clutter and how to query the clutter method from C to JS, see.
3.1 lib import to gjs (clutter-1.0 version)
Two paths:
. Typelib path:/usr/lib/girepository-1.0/
. Gir path:/usr/share/gir-1.0/
GI (gobject introspection) can describe the API information into XML, and then parse to the typelib format, that is, binary format, which is convenient for use during runtime. Through this process, GI enables gobject-based native lib to easily porting to script language.
3.2 gnome database is Gi-based
Most of the GNOME Desktop libraries are now Gi-based and can usually be seen in the/usr/lib/girepository-1.0 directory as long as the typelib file appears in that directory, the corresponding library can be used in gjs through imports. GI object. To query the methods used by APIs in JS, use command:
[Alex @ Alex girepository-1.0] $ G-ir-generate Clutter-1.0.typelib | grep timeline
You can also query the C function prototype information from the/usr/share/gir-1.0/Corresponding. gir file.