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