ClutterTest
[app.Builder.js] / ClutterTest / Window.js
1 Gtk = imports.gi.Gtk;
2 Gdk = imports.gi.Gdk;
3 Pango = imports.gi.Pango;
4 GLib = imports.gi.GLib;
5 Gio = imports.gi.Gio;
6 GObject = imports.gi.GObject;
7 GtkSource = imports.gi.GtkSource;
8 WebKit = imports.gi.WebKit;
9 Vte = imports.gi.Vte;
10 GtkClutter = imports.gi.GtkClutter;
11 console = imports.console;
12 XObject = imports.XObject.XObject;
13 Window=new XObject({
14     xtype: Gtk.Window,
15     default_height : 600,
16     default_width : 600,
17     init : function() {
18         XObject.prototype.init.call(this);
19         this.el.show_all();
20     },
21     items : [
22         {
23             xtype: GtkClutter.Embed,
24             listeners : {
25                 show : function() { 
26                    var stage = this.el.get_stage(); 
27                    print(this.items.length);
28                    this.items.forEach( 
29                       function(e) { 
30                           print(e.xtype);
31                           stage.add_actor(e.el);
32                         }
33                      );
34                 }
35             },
36             pack : "add",
37             items : [
38                 {
39                     xtype: GtkClutter.Actor,
40                     pack : false,
41                     x : 100,
42                     y : 100,
43                     init : function() {
44                     
45                         var child = new XObject(this.items[0]);
46                         child.init();
47                         child.parent = this;
48                         //var contents = new Gtk.Button({ label: 'test' }); 
49                         var contents = child.el;
50                        
51                         print(JSON.stringify(this.items));
52                         
53                         
54                         this.el = new GtkClutter.Actor.with_contents (  contents) ;
55                         XObject.prototype.init.call(this);
56                     },
57                     items : [
58                         {
59                             xtype: Gtk.Button,
60                             listeners : {
61                                 clicked : function (self) {
62                                    Clutter = imports.gi.Clutter;
63                                         var animate = this.parent.el.animate(
64                                                 Clutter.AnimationMode.EASE_OUT_ELASTIC, 2000,
65                                                 {
66                                                            scale_x : 5,
67                                                           scale_y: 5,
68                                 
69                                                 }
70                                                 );
71                                                 animate.timeline.start();
72                                 
73                                 }
74                             },
75                             height_request : 100,
76                             label : "test",
77                             pack : false,
78                             width_request : 100
79                         }
80                     ]
81                 },
82                 {
83                     xtype: GtkClutter.Actor,
84                     pack : false,
85                     x : 300,
86                     y : 100,
87                     init : function() {
88                     
89                         var child = new XObject(this.items[0]);
90                         child.init();
91                         child.parent = this;
92                         //var contents = new Gtk.Button({ label: 'test' }); 
93                         var contents = child.el;
94                         print ("actor.items");
95                         print(JSON.stringify(this.items));
96                         
97                         
98                         this.el = new GtkClutter.Actor.with_contents (  contents) ;
99                         XObject.prototype.init.call(this);
100                     },
101                     items : [
102                         {
103                             xtype: Gtk.Button,
104                             listeners : {
105                                 clicked : function (self) {
106                                    Clutter = imports.gi.Clutter;
107                                         var animate = this.parent.el.animate(
108                                                 Clutter.AnimationMode.EASE_OUT_ELASTIC, 2000,
109                                                 {
110                                                            scale_x : 5,
111                                                           scale_y: 5,
112                                 
113                                                 }
114                                                 );
115                                                 animate.timeline.start();
116                                 
117                                 }
118                             },
119                             height_request : 100,
120                             label : "test",
121                             pack : false,
122                             width_request : 100
123                         }
124                     ]
125                 }
126             ]
127         }
128     ]
129 });
130 Window.init();
131 XObject.cache['/Window'] = Window;