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