Builder4/ClutterFiles.bjs
[app.Builder.js] / Builder4 / ClutterFiles.vala
1 /* -- to compile
2 valac  --pkg gio-2.0  --pkg posix  --pkg gtk+-3.0 --pkg libnotify --pkg gtksourceview-3.0  --pkg  libwnck-3.0 \
3     /tmp/ClutterFiles.vala  -o /tmp/ClutterFiles
4 */
5
6
7 /* -- to test class
8 static int main (string[] args) {
9     Gtk.init (ref args);
10     new Xcls_ClutterFiles();
11     ClutterFiles.show_all();
12      Gtk.main ();
13     return 0;
14 }
15 */
16
17
18 public static Xcls_ClutterFiles  ClutterFiles;
19
20 public class Xcls_ClutterFiles : Object 
21 {
22     public Clutter.ScrollActor el;
23     private Xcls_ClutterFiles  _this;
24
25     public static Xcls_ClutterFiles singleton()
26     {
27         if (ClutterFiles == null) {
28             ClutterFiles= new Xcls_ClutterFiles();
29         }
30         return ClutterFiles;
31     }
32     public Xcls_filelayout filelayout;
33     public Xcls_filelayout_manager filelayout_manager;
34
35         // my vars
36     public Gee.ArrayList<Xcls_fileitem> fileitems;
37     public signal void open(JsRender.JsRender file);
38
39         // ctor 
40     public Xcls_ClutterFiles()
41     {
42         _this = this;
43         this.el = new Clutter.ScrollActor();
44
45         // my vars
46
47         // set gobject values
48         this.el.reactive = true;
49         var child_0 = new Xcls_filelayout( _this );
50         child_0.ref();
51         this.el.add_child (  child_0.el  );
52
53         // init method 
54         this.fileitems = new Gee.ArrayList<Xcls_fileitem>();
55
56         // listeners 
57         this.el.scroll_event.connect( ( event) => {
58            //Sprint("scroll event");
59                     var y = this.filelayout.el.y;
60                     var dir = event.direction;
61                     switch (dir) {
62                         case Clutter.ScrollDirection.UP:
63                             y += event.y /2;
64                             break;
65                         case Clutter.ScrollDirection.DOWN:
66                             y -= event.y /2 ;
67                             break;
68                         default:
69                             return false;
70                     }
71                     // range of scroll -- can go up -- eg.. -ve value.
72                     
73                     y = float.min(0, y);
74                     
75                     // to work out the max -ve number
76                     // height of filelayout
77                     // height of scrollactor..
78                     
79                     var last_child_bottom = this.filelayout.el.last_child.y +  this.filelayout.el.last_child.height;
80                      if ( (-1 * (y+200)) > (  last_child_bottom - this.el.height)) {
81                         return  false;
82                     }
83                 
84                 
85                     
86                     
87                 //    print("\nlast child - this height = %f  ==== new y %f\n ".printf( 
88                   //          last_child_bottom - this.el.height,
89                    //         y));    
90                    // y = float.min(0, y);    //??
91                    // print("scroll event of %f  - new y = %f ".printf(event.y, y));
92                     this.filelayout.el.y = y;
93                     return true;
94         } );
95     }
96
97     // userdefined functions 
98     public void clearFiles() {
99             
100             this.filelayout.el.remove_all_children();
101             // we need to unref all the chidren that we loaded though...
102             
103         }
104     public void loadProject(Project.Project pr) {
105             // list all the files, and create new Xcls_fileitem for each one.
106             
107             // LEAK --- we should unref all the chilren...
108             this.clearFiles();
109             
110             print("clutter files - load project: " + pr.name +"\n");
111             // should unref.. them hopefully.
112             this.fileitems = new Gee.ArrayList<Xcls_fileitem>();
113         
114             var fiter = pr.files.map_iterator();
115             while (fiter.next()) {
116                 var a = new Xcls_fileitem(this,fiter.get_value());
117                 this.fileitems.add(a);
118         
119         //        a.ref();
120                 print("add to clutter file view: " + fiter.get_value().name + "\n");
121                 this.filelayout.el.add_child(a.el);
122             }
123             this.el.show_all();
124         }
125     public void set_size(float w, float h) 
126         {
127              if (this.el == null) {
128                 print("object not ready yet?");
129                 return;
130             }
131            _this.filelayout_manager.el.max_column_width = w - 150;
132            this.el.set_size(this.el.get_stage().width-150,
133                                 this.el.get_stage().height);
134                     this.el.set_position(100,50);
135         }
136
137     // skip |xns - no return type
138     public class Xcls_filelayout : Object 
139     {
140         public Clutter.Actor el;
141         private Xcls_ClutterFiles  _this;
142
143
144             // my vars
145
146             // ctor 
147         public Xcls_filelayout(Xcls_ClutterFiles _owner )
148         {
149             _this = _owner;
150             _this.filelayout = this;
151             this.el = new Clutter.Actor();
152
153             // my vars
154
155             // set gobject values
156             this.el.reactive = true;
157             var child_0 = new Xcls_filelayout_manager( _this );
158             child_0.ref();
159             this.el.layout_manager = child_0.el;
160
161             // init method 
162             this.el.add_constraint(
163                 new Clutter.BindConstraint(_this.el,Clutter.BindCoordinate.SIZE, 0.0f)
164             );
165         }
166
167         // userdefined functions 
168
169         // skip |xns - no return type
170     }
171     public class Xcls_filelayout_manager : Object 
172     {
173         public Clutter.FlowLayout el;
174         private Xcls_ClutterFiles  _this;
175
176
177             // my vars
178
179             // ctor 
180         public Xcls_filelayout_manager(Xcls_ClutterFiles _owner )
181         {
182             _this = _owner;
183             _this.filelayout_manager = this;
184             this.el = new Clutter.FlowLayout( Clutter.FlowOrientation.HORIZONTAL );
185
186             // my vars
187
188             // set gobject values
189             this.el.column_spacing = 20;
190             this.el.homogeneous = true;
191             this.el.row_spacing = 20;
192         }
193
194         // userdefined functions 
195
196         // skip |xns - no return type
197     }
198     public class Xcls_fileitem : Object 
199     {
200         public Clutter.Actor el;
201         private Xcls_ClutterFiles  _this;
202
203
204             // my vars
205         public JsRender.JsRender file;
206         public Xcls_image image;
207         public Xcls_typetitle typetitle;
208         public Xcls_title title;
209
210             // ctor 
211         public Xcls_fileitem(Xcls_ClutterFiles _owner , JsRender.JsRender file)
212         {
213             _this = _owner;
214             this.el = new Clutter.Actor();
215
216             // my vars
217
218             // set gobject values
219             this.el.reactive = true;
220             var child_0 = new Xcls_BoxLayout5( _this );
221             child_0.ref();
222             this.el.layout_manager = child_0.el;
223             var child_1 = new Xcls_image( _this ,file);
224             child_1.ref();
225             this.el.add_child (  child_1.el  );
226             this.image =  child_1;
227             var child_2 = new Xcls_typetitle( _this ,file);
228             child_2.ref();
229             this.el.add_child (  child_2.el  );
230             this.typetitle =  child_2;
231             var child_3 = new Xcls_title( _this ,file);
232             child_3.ref();
233             this.el.add_child (  child_3.el  );
234             this.title =  child_3;
235
236             // init method 
237             this.file = file;
238             this.el.set_size(100,100);
239
240             // listeners 
241             this.el.enter_event.connect( (  event)  => {
242                 this.el.background_color = new Clutter.Color.from_string("#333");
243                     return false;
244             } );
245             this.el.leave_event.connect( (  event)  => {
246                 this.el.background_color = new Clutter.Color.from_string("#000");
247                 return false;
248             } );
249             this.el.button_press_event.connect(   (  event) => {
250                 _this.open(this.file);
251                 return false;
252             } );
253         }
254
255         // userdefined functions 
256
257         // skip |xns - no return type
258     }
259     public class Xcls_BoxLayout5 : Object 
260     {
261         public Clutter.BoxLayout el;
262         private Xcls_ClutterFiles  _this;
263
264
265             // my vars
266
267             // ctor 
268         public Xcls_BoxLayout5(Xcls_ClutterFiles _owner )
269         {
270             _this = _owner;
271             this.el = new Clutter.BoxLayout();
272
273             // my vars
274
275             // set gobject values
276             this.el.orientation = Clutter.Orientation.VERTICAL;
277             this.el.spacing = 4;
278         }
279
280         // userdefined functions 
281
282         // skip |xns - no return type
283     }
284     public class Xcls_image : Object 
285     {
286         public Clutter.Texture el;
287         private Xcls_ClutterFiles  _this;
288
289
290             // my vars
291
292             // ctor 
293         public Xcls_image(Xcls_ClutterFiles _owner , JsRender.JsRender file)
294         {
295             _this = _owner;
296             this.el = new Clutter.Texture.from_file(file.getIconFileName(true));
297
298             // my vars
299
300             // set gobject values
301             this.el.margin_left = 5;
302             this.el.margin_right = 5;
303             this.el.margin_top = 5;
304             this.el.x_align = Clutter.ActorAlign.START;
305             this.el.x_expand = true;
306             this.el.y_align = Clutter.ActorAlign.START;
307             this.el.y_expand = false;
308         }
309
310         // userdefined functions 
311
312         // skip |xns - no return type
313     }
314     public class Xcls_typetitle : Object 
315     {
316         public Clutter.Text el;
317         private Xcls_ClutterFiles  _this;
318
319
320             // my vars
321
322             // ctor 
323         public Xcls_typetitle(Xcls_ClutterFiles _owner , JsRender.JsRender file)
324         {
325             _this = _owner;
326             this.el = new Clutter.Text.full("Sans 10px", file.nickType(),new Clutter.Color.from_string("#fff"));
327
328             // my vars
329
330             // set gobject values
331             this.el.x_align = Clutter.ActorAlign.START;
332             this.el.x_expand = true;
333             this.el.y_align = Clutter.ActorAlign.START;
334             this.el.y_expand = false;
335         }
336
337         // userdefined functions 
338
339         // skip |xns - no return type
340     }
341     public class Xcls_title : Object 
342     {
343         public Clutter.Text el;
344         private Xcls_ClutterFiles  _this;
345
346
347             // my vars
348
349             // ctor 
350         public Xcls_title(Xcls_ClutterFiles _owner , JsRender.JsRender file)
351         {
352             _this = _owner;
353             this.el = new Clutter.Text.full("Sans 10px", file.nickName(),new Clutter.Color.from_string("#fff"));
354
355             // my vars
356
357             // set gobject values
358             this.el.x_align = Clutter.ActorAlign.START;
359             this.el.x_expand = true;
360             this.el.y_align = Clutter.ActorAlign.START;
361             this.el.y_expand = false;
362         }
363
364         // userdefined functions 
365
366         // skip |xns - no return type
367     }
368 }