Add another simple clutter example, showing actors and Container i/f.
[girtod.git] / example_clutter2.d
blobcd351c33ec6d98a9e0b7892a37cbddb08cde2cb5
1 // D version of example from
2 // http://www.openismus.com/documents/clutter_tutorial/1.0/docs/tutorial/html/sec-actors.html
3 //
4 // Link with: "gtk2/glib2.o gtk2/gobject2.o gtk2/clutter.o `pkg-config --libs clutter-1.0`"
6 import std.stdio;
7 import clut = gtk2.clutter;
9 int on_stage_button_press(clut.Actor* stage, clut.Event* event, void* data)
11 float x = 0, y = 0;
12 event.get_coords(&x, &y);
13 writef("Stage clicked at (%f, %f)\n", x, y);
14 return true; /* Stop further handling of this event. */
17 int main(string argv[]) {
18 clut.Color stage_color = { 0x00, 0x00, 0x00, 0xff }; /* Black */
19 clut.Color actor_color = { 0xff, 0xff, 0xff, 0x99 };
21 argv = clut.init(argv);
23 /* Get the stage and set its size and color: */
24 auto stage = clut.Stage.get_default();
25 stage.set_size(200, 200);
26 stage.set_color(&stage_color);
28 /* Add a rectangle to the stage: */
29 auto rect = clut.Rectangle.new_with_color(&actor_color);
30 rect.set_size(100, 100);
31 rect.set_position(20, 20);
32 stage.add_actor(&rect.actor);
33 rect.show();
35 /* Add a label to the stage: */
36 auto label = clut.Text.new_full(cast(char*)"Sans 12", cast(char*)"Some Text", &actor_color);
37 label.set_size(500, 500);
38 label.set_position(20, 150);
39 stage.add_actor(&label.actor);
40 label.show();
42 /* Show the stage: */
43 stage.show();
45 /* Connect a signal handler to handle mouse clicks and key presses on the stage: */
46 stage.signal_connect!"button-press-event"(&on_stage_button_press);
48 /* Start the main loop, so we can respond to events: */
49 clut.main_();
51 return 0;