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