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