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