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