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