src/Builder4/ClutterFiles.bjs
[app.Builder.js] / src / Builder4 / ClutterFiles.vala
1 static Xcls_ClutterFiles  _ClutterFiles;
2
3 public class Xcls_ClutterFiles : Object
4 {
5     public Clutter.Actor 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_project_title project_title;
16     public Xcls_project_title_manager project_title_manager;
17     public Xcls_project_title_name project_title_name;
18     public Xcls_project_title_path project_title_path;
19     public Xcls_scoller scoller;
20     public Xcls_filelayout filelayout;
21     public Xcls_filelayout_manager filelayout_manager;
22
23         // my vars (def)
24     public Gee.ArrayList<Xcls_fileitem> fileitems;
25     public Clutter.ScrollMode scroll_mode;
26     public Gdk.Pixbuf missing_thumb_pixbuf;
27     public signal void open (JsRender.JsRender file);
28
29     // ctor
30     public Xcls_ClutterFiles()
31     {
32         _this = this;
33         this.el = new Clutter.Actor();
34
35         // my vars (dec)
36         this.fileitems = new Gee.ArrayList<Xcls_fileitem>();
37         this.scroll_mode = Clutter.ScrollMode.VERTICALLY;
38         this.missing_thumb_pixbuf = null;
39
40         // set gobject values
41         this.el.reactive = true;
42         var child_0 = new Xcls_project_title( _this );
43         child_0.ref();
44         this.el.add_child (  child_0.el  );
45         var child_1 = new Xcls_scoller( _this );
46         child_1.ref();
47         this.el.add_child (  child_1.el  );
48     }
49
50     // user defined functions
51     public  void clearFiles () {
52         
53         this.filelayout.el.remove_all_children();
54         // we need to unref all the chidren that we loaded though...
55         
56     }
57     public  void loadProject (Project.Project pr) {
58         // list all the files, and create new Xcls_fileitem for each one.
59         
60         // LEAK --- we should unref all the chilren...
61         this.filelayout.el.y = 0;
62         this.clearFiles();
63         
64         print("clutter files - load project: " + pr.name +"\n");
65         // should unref.. them hopefully.
66         
67         this.project_title_name.el.text = pr.name;
68         this.project_title_path.el.text = pr.firstPath();
69         
70         this.fileitems = new Gee.ArrayList<Xcls_fileitem>();
71     
72         
73     
74         var fiter = pr.sortedFiles().list_iterator();
75         while (fiter.next()) {
76             var a = new Xcls_fileitem(this,fiter.get());
77             this.fileitems.add(a);
78     
79     //        a.ref();
80             print("add to clutter file view: " + fiter.get().name + "\n");
81             this.filelayout.el.add_child(a.el);
82         }
83         
84         // folders...
85         
86         
87        
88         
89         this.el.show();
90     }
91     public  void set_size (float w, float h) 
92     {
93         
94          // called by window resize... with is alreaddy -50 (for the buttons?)
95          
96     
97          if (this.el == null) {
98             print("object not ready yet?");
99             return;
100         }
101        _this.filelayout_manager.el.max_column_width = w - 75;
102        
103         this.el.set_size(
104                // this.el.get_stage().width-150,
105                w,
106                h  // this.el.get_stage().height
107         );
108         
109         // 100 right for buttons ..
110         this.el.set_position(0,0);
111        
112        
113        this.scoller.el.set_size(
114                // this.el.get_stage().width-150,
115                w-150,
116                h  // this.el.get_stage().height
117         );
118         
119         // 100 right for buttons ..
120         this.scoller.el.set_position(75,50);
121     }
122     public class Xcls_project_title : Object
123     {
124         public Clutter.Actor el;
125         private Xcls_ClutterFiles  _this;
126
127
128             // my vars (def)
129
130         // ctor
131         public Xcls_project_title(Xcls_ClutterFiles _owner )
132         {
133             _this = _owner;
134             _this.project_title = this;
135             this.el = new Clutter.Actor();
136
137             // my vars (dec)
138
139             // set gobject values
140             this.el.reactive = true;
141             var child_0 = new Xcls_project_title_manager( _this );
142             child_0.ref();
143             this.el.layout_manager = child_0.el;
144             var child_1 = new Xcls_FixedLayout4( _this );
145             child_1.ref();
146             this.el.layout_manager = child_1.el;
147             var child_2 = new Xcls_project_title_name( _this );
148             child_2.ref();
149             this.el.add_child (  child_2.el  );
150             var child_3 = new Xcls_project_title_path( _this );
151             child_3.ref();
152             this.el.add_child (  child_3.el  );
153
154             // init method
155
156             this.el.add_constraint(
157                 new Clutter.BindConstraint(_this.el,Clutter.BindCoordinate.SIZE, 0.0f)
158             );
159             this.el.set_position(75,0);
160         }
161
162         // user defined functions
163     }
164     public class Xcls_project_title_manager : Object
165     {
166         public Clutter.FlowLayout el;
167         private Xcls_ClutterFiles  _this;
168
169
170             // my vars (def)
171
172         // ctor
173         public Xcls_project_title_manager(Xcls_ClutterFiles _owner )
174         {
175             _this = _owner;
176             _this.project_title_manager = this;
177             this.el = new Clutter.FlowLayout( Clutter.FlowOrientation.HORIZONTAL );
178
179             // my vars (dec)
180
181             // set gobject values
182             this.el.homogeneous = false;
183             this.el.row_spacing = 5f;
184             this.el.column_spacing = 20f;
185         }
186
187         // user defined functions
188     }
189
190     public class Xcls_FixedLayout4 : Object
191     {
192         public Clutter.FixedLayout el;
193         private Xcls_ClutterFiles  _this;
194
195
196             // my vars (def)
197
198         // ctor
199         public Xcls_FixedLayout4(Xcls_ClutterFiles _owner )
200         {
201             _this = _owner;
202             this.el = new Clutter.FixedLayout();
203
204             // my vars (dec)
205
206             // set gobject values
207         }
208
209         // user defined functions
210     }
211
212     public class Xcls_project_title_name : Object
213     {
214         public Clutter.Text el;
215         private Xcls_ClutterFiles  _this;
216
217
218             // my vars (def)
219
220         // ctor
221         public Xcls_project_title_name(Xcls_ClutterFiles _owner )
222         {
223             _this = _owner;
224             _this.project_title_name = this;
225             this.el = new Clutter.Text.full("Sans 20px", "",  Clutter.Color.from_string("#eee"));
226
227             // my vars (dec)
228
229             // set gobject values
230             this.el.x = 0.0f;
231             this.el.y = 10.0f;
232             this.el.x_expand = false;
233         }
234
235         // user defined functions
236     }
237
238     public class Xcls_project_title_path : Object
239     {
240         public Clutter.Text el;
241         private Xcls_ClutterFiles  _this;
242
243
244             // my vars (def)
245
246         // ctor
247         public Xcls_project_title_path(Xcls_ClutterFiles _owner )
248         {
249             _this = _owner;
250             _this.project_title_path = this;
251             this.el = new Clutter.Text.full("Sans 10px", "",  Clutter.Color.from_string("#ccc"));
252
253             // my vars (dec)
254
255             // set gobject values
256             this.el.x = 0.0f;
257             this.el.y = 35.0f;
258         }
259
260         // user defined functions
261     }
262
263
264     public class Xcls_scoller : Object
265     {
266         public Clutter.ScrollActor el;
267         private Xcls_ClutterFiles  _this;
268
269
270             // my vars (def)
271         public Gee.ArrayList<Xcls_fileitem> fileitems;
272         public Gdk.Pixbuf missing_thumb_pixbuf;
273
274         // ctor
275         public Xcls_scoller(Xcls_ClutterFiles _owner )
276         {
277             _this = _owner;
278             _this.scoller = this;
279             this.el = new Clutter.ScrollActor();
280
281             // my vars (dec)
282             this.fileitems = new Gee.ArrayList<Xcls_fileitem>();
283             this.missing_thumb_pixbuf = null;
284
285             // set gobject values
286             this.el.scroll_mode = Clutter.ScrollMode.VERTICALLY;
287             this.el.reactive = true;
288             var child_0 = new Xcls_filelayout( _this );
289             child_0.ref();
290             this.el.add_child (  child_0.el  );
291
292             //listeners
293             this.el.scroll_event.connect( ( event) => {
294                //Sprint("scroll event");
295                         var y = _this.filelayout.el.y;
296                         var dir = event.direction;
297                         switch (dir) {
298                             case Clutter.ScrollDirection.UP:
299                                 y += event.y /2;
300                                 break;
301                             case Clutter.ScrollDirection.DOWN:
302                                 y -= event.y /2 ;
303                                 break;
304                             default:
305                                 return false;
306                         }
307                         // range of scroll -- can go up -- eg.. -ve value.
308                         
309                         y = float.min(0, y);
310                         
311                         // to work out the max -ve number
312                         // height of filelayout
313                         // height of scrollactor..
314                         
315                         var last_child_bottom = _this.filelayout.el.last_child.y +  _this.filelayout.el.last_child.height;
316                          if ( (-1 * (y+200)) > (  last_child_bottom - this.el.height)) {
317                             return  false;
318                         }
319                     
320                     
321                         
322                         
323                     //    print("\nlast child - this height = %f  ==== new y %f\n ".printf( 
324                       //          last_child_bottom - this.el.height,
325                        //         y));    
326                        // y = float.min(0, y);    //??
327                        // print("scroll event of %f  - new y = %f ".printf(event.y, y));
328                         _this.filelayout.el.y = y;
329                         return true;
330                       
331             });
332         }
333
334         // user defined functions
335     }
336     public class Xcls_filelayout : Object
337     {
338         public Clutter.Actor el;
339         private Xcls_ClutterFiles  _this;
340
341
342             // my vars (def)
343
344         // ctor
345         public Xcls_filelayout(Xcls_ClutterFiles _owner )
346         {
347             _this = _owner;
348             _this.filelayout = this;
349             this.el = new Clutter.Actor();
350
351             // my vars (dec)
352
353             // set gobject values
354             this.el.reactive = true;
355             var child_0 = new Xcls_filelayout_manager( _this );
356             child_0.ref();
357             this.el.layout_manager = child_0.el;
358
359             // init method
360
361             this.el.add_constraint(
362                 new Clutter.BindConstraint(_this.el,Clutter.BindCoordinate.SIZE, 0.0f)
363             );
364         }
365
366         // user defined functions
367     }
368     public class Xcls_filelayout_manager : Object
369     {
370         public Clutter.FlowLayout el;
371         private Xcls_ClutterFiles  _this;
372
373
374             // my vars (def)
375
376         // ctor
377         public Xcls_filelayout_manager(Xcls_ClutterFiles _owner )
378         {
379             _this = _owner;
380             _this.filelayout_manager = this;
381             this.el = new Clutter.FlowLayout( Clutter.FlowOrientation.HORIZONTAL );
382
383             // my vars (dec)
384
385             // set gobject values
386             this.el.homogeneous = true;
387             this.el.row_spacing = 20f;
388             this.el.column_spacing = 20f;
389         }
390
391         // user defined functions
392     }
393
394     public class Xcls_fileitem : Object
395     {
396         public Clutter.Actor el;
397         private Xcls_ClutterFiles  _this;
398
399
400             // my vars (def)
401         public JsRender.JsRender file;
402         public Xcls_image image;
403         public Xcls_typetitle typetitle;
404         public Xcls_title title;
405
406         // ctor
407         public Xcls_fileitem(Xcls_ClutterFiles _owner , JsRender.JsRender file)
408         {
409             _this = _owner;
410             this.el = new Clutter.Actor();
411
412             // my vars (dec)
413
414             // set gobject values
415             this.el.reactive = true;
416             var child_0 = new Xcls_BoxLayout11( _this );
417             child_0.ref();
418             this.el.layout_manager = child_0.el;
419             var child_1 = new Xcls_image( _this ,file);
420             child_1.ref();
421             this.el.add_child (  child_1.el  );
422             this.image =  child_1;
423             var child_2 = new Xcls_typetitle( _this ,file);
424             child_2.ref();
425             this.el.add_child (  child_2.el  );
426             this.typetitle =  child_2;
427             var child_3 = new Xcls_title( _this ,file);
428             child_3.ref();
429             this.el.add_child (  child_3.el  );
430             this.title =  child_3;
431
432             // init method
433
434             this.file = file;
435             this.el.set_size(100,100);
436
437             //listeners
438             this.el.button_press_event.connect( (  event) => {
439                 _this.open(this.file);
440                 return false;
441             });
442             this.el.enter_event.connect( (  event)  => {
443                 this.el.background_color =   Clutter.Color.from_string("#333");
444                     return false;
445             });
446             this.el.leave_event.connect( (  event)  => {
447                 this.el.background_color =   Clutter.Color.from_string("#000");
448                 return false;
449             });
450         }
451
452         // user defined functions
453     }
454     public class Xcls_BoxLayout11 : Object
455     {
456         public Clutter.BoxLayout el;
457         private Xcls_ClutterFiles  _this;
458
459
460             // my vars (def)
461
462         // ctor
463         public Xcls_BoxLayout11(Xcls_ClutterFiles _owner )
464         {
465             _this = _owner;
466             this.el = new Clutter.BoxLayout();
467
468             // my vars (dec)
469
470             // set gobject values
471             this.el.spacing = 4;
472             this.el.orientation = Clutter.Orientation.VERTICAL;
473         }
474
475         // user defined functions
476     }
477
478     public class Xcls_image : Object
479     {
480         public Clutter.Actor el;
481         private Xcls_ClutterFiles  _this;
482
483
484             // my vars (def)
485
486         // ctor
487         public Xcls_image(Xcls_ClutterFiles _owner , JsRender.JsRender file)
488         {
489             _this = _owner;
490             this.el = new Clutter.Actor();
491
492             // my vars (dec)
493
494             // set gobject values
495             this.el.margin_right = 5f;
496             this.el.margin_left = 5f;
497             this.el.x_align = Clutter.ActorAlign.START;
498             this.el.x_expand = true;
499             this.el.y_align = Clutter.ActorAlign.START;
500             this.el.margin_top = 5f;
501             this.el.y_expand = true;
502
503             // init method
504
505             {
506                 Gdk.Pixbuf pixbuf= null;
507                 
508                 var fname = file.getIconFileName(false);
509             
510                 try {
511                     if (FileUtils.test(fname, FileTest.EXISTS)) {
512                         pixbuf = new Gdk.Pixbuf.from_file(fname);
513                     } 
514                 } catch (Error e) {
515                     // noop
516                 
517                 }
518                 if (pixbuf == null) {
519                     
520                     try {
521                         if (_this.missing_thumb_pixbuf == null) {
522                                 var icon_theme = Gtk.IconTheme.get_default ();
523                                 _this.missing_thumb_pixbuf = icon_theme.load_icon ("package-x-generic", 92, 0);
524                                 _this.missing_thumb_pixbuf.ref();
525                             }
526                             pixbuf = _this.missing_thumb_pixbuf;
527             
528                     } catch (Error e) {
529                         // noop?
530                     }
531                 }
532                 try {
533                     var img = new Clutter.Image();
534                     img.set_data(pixbuf.get_pixels(),   
535                                         pixbuf.has_alpha 
536                                           ? Cogl.PixelFormat.RGBA_8888
537                                           : Cogl.PixelFormat.RGB_888,
538                                         pixbuf.get_width (),
539                             pixbuf.get_height (),
540                                         pixbuf.get_rowstride ()
541                     );
542                     this.el.set_content(img);
543                 } catch (Error e) {
544                     // noop?
545                 }
546                  // should probably do smarter scaling...
547                 
548                 
549                 this.el.set_size(90, 70);
550             }
551         }
552
553         // user defined functions
554     }
555
556     public class Xcls_typetitle : Object
557     {
558         public Clutter.Text el;
559         private Xcls_ClutterFiles  _this;
560
561
562             // my vars (def)
563
564         // ctor
565         public Xcls_typetitle(Xcls_ClutterFiles _owner , JsRender.JsRender file)
566         {
567             _this = _owner;
568             this.el = new Clutter.Text.full("Sans 10px", file.nickType(),  Clutter.Color.from_string("#fff"));
569
570             // my vars (dec)
571
572             // set gobject values
573             this.el.x_align = Clutter.ActorAlign.START;
574             this.el.x_expand = true;
575             this.el.y_align = Clutter.ActorAlign.START;
576             this.el.y_expand = true;
577         }
578
579         // user defined functions
580     }
581
582     public class Xcls_title : Object
583     {
584         public Clutter.Text el;
585         private Xcls_ClutterFiles  _this;
586
587
588             // my vars (def)
589
590         // ctor
591         public Xcls_title(Xcls_ClutterFiles _owner , JsRender.JsRender file)
592         {
593             _this = _owner;
594             this.el = new Clutter.Text.full("Sans 10px", file.nickName(),  Clutter.Color.from_string("#fff"));
595
596             // my vars (dec)
597
598             // set gobject values
599             this.el.x_align = Clutter.ActorAlign.START;
600             this.el.x_expand = true;
601             this.el.y_align = Clutter.ActorAlign.START;
602             this.el.y_expand = true;
603         }
604
605         // user defined functions
606     }
607
608
609     public class Xcls_folderitem : Object
610     {
611         public Clutter.Actor el;
612         private Xcls_ClutterFiles  _this;
613
614
615             // my vars (def)
616         public Xcls_foldertitle foldertitle;
617
618         // ctor
619         public Xcls_folderitem(Xcls_ClutterFiles _owner , string folderpath)
620         {
621             _this = _owner;
622             this.el = new Clutter.Actor();
623
624             // my vars (dec)
625
626             // set gobject values
627             this.el.reactive = true;
628             var child_0 = new Xcls_BoxLayout16( _this );
629             child_0.ref();
630             this.el.layout_manager = child_0.el;
631             var child_1 = new Xcls_foldertitle( _this ,folderpath);
632             child_1.ref();
633             this.el.add_child (  child_1.el  );
634             this.foldertitle =  child_1;
635
636             // init method
637
638             //this.el.set_size(100,100);
639         }
640
641         // user defined functions
642     }
643     public class Xcls_BoxLayout16 : Object
644     {
645         public Clutter.BoxLayout el;
646         private Xcls_ClutterFiles  _this;
647
648
649             // my vars (def)
650
651         // ctor
652         public Xcls_BoxLayout16(Xcls_ClutterFiles _owner )
653         {
654             _this = _owner;
655             this.el = new Clutter.BoxLayout();
656
657             // my vars (dec)
658
659             // set gobject values
660             this.el.spacing = 2;
661             this.el.orientation = Clutter.Orientation.VERTICAL;
662         }
663
664         // user defined functions
665     }
666
667     public class Xcls_foldertitle : Object
668     {
669         public Clutter.Text el;
670         private Xcls_ClutterFiles  _this;
671
672
673             // my vars (def)
674
675         // ctor
676         public Xcls_foldertitle(Xcls_ClutterFiles _owner , string folderpath)
677         {
678             _this = _owner;
679             this.el = new Clutter.Text.full("Sans 14px", GLib.Path.get_basename(folderpath),  Clutter.Color.from_string("#fff"));
680
681             // my vars (dec)
682
683             // set gobject values
684             this.el.x_align = Clutter.ActorAlign.START;
685             this.el.x_expand = true;
686             this.el.y_align = Clutter.ActorAlign.START;
687             this.el.y_expand = true;
688         }
689
690         // user defined functions
691     }
692
693     public class Xcls_folderfile : Object
694     {
695         public Clutter.Text el;
696         private Xcls_ClutterFiles  _this;
697
698
699             // my vars (def)
700         public string filepath;
701
702         // ctor
703         public Xcls_folderfile(Xcls_ClutterFiles _owner , string filepath)
704         {
705             _this = _owner;
706             this.el = new Clutter.Text.full("Sans 10px", GLib.Path.get_basename(filepath),  Clutter.Color.from_string("#fff"));
707
708             // my vars (dec)
709
710             // set gobject values
711             this.el.x_align = Clutter.ActorAlign.START;
712             this.el.x_expand = true;
713             this.el.y_align = Clutter.ActorAlign.START;
714             this.el.y_expand = true;
715
716             // init method
717
718             {
719                 this.filepath = filepath;
720             }
721
722             //listeners
723             this.el.button_press_event.connect( (  event) => {
724                // _this.open(this.filepath);
725                 return false;
726             });
727             this.el.enter_event.connect( (  event)  => {
728                 this.el.background_color =   Clutter.Color.from_string("#333");
729                     return false;
730             });
731             this.el.leave_event.connect( (  event)  => {
732                 this.el.background_color =   Clutter.Color.from_string("#000");
733                 return false;
734             });
735         }
736
737         // user defined functions
738     }
739
740
741
742
743 }