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 set_size(float w, float h) 
91         {
92              if (this.el == null) {
93                 print("object not ready yet?");
94                 return;
95             }
96            _this.filelayout_manager.el.max_column_width = w - 150;
97            this.el.set_size(this.el.get_stage().width-150,
98                                 this.el.get_stage().height);
99                     this.el.set_position(100,50);
100         }
101     public void show(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.filelayout.el.remove_all_children();
106             
107             
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
118     // skip |xns - no return type
119     public class Xcls_filelayout : Object 
120     {
121         public Clutter.Actor el;
122         private Xcls_ClutterFiles  _this;
123
124
125             // my vars
126
127             // ctor 
128         public Xcls_filelayout(Xcls_ClutterFiles _owner )
129         {
130             _this = _owner;
131             _this.filelayout = this;
132             this.el = new Clutter.Actor();
133
134             // my vars
135
136             // set gobject values
137             this.el.reactive = true;
138             var child_0 = new Xcls_filelayout_manager( _this );
139             child_0.ref();
140             this.el.layout_manager = child_0.el;
141
142             // init method 
143             this.el.add_constraint(
144                 new Clutter.BindConstraint(_this.el,Clutter.BindCoordinate.SIZE, 0.0f)
145             );
146         }
147
148         // userdefined functions 
149
150         // skip |xns - no return type
151     }
152     public class Xcls_filelayout_manager : Object 
153     {
154         public Clutter.FlowLayout el;
155         private Xcls_ClutterFiles  _this;
156
157
158             // my vars
159
160             // ctor 
161         public Xcls_filelayout_manager(Xcls_ClutterFiles _owner )
162         {
163             _this = _owner;
164             _this.filelayout_manager = this;
165             this.el = new Clutter.FlowLayout( Clutter.FlowOrientation.HORIZONTAL );
166
167             // my vars
168
169             // set gobject values
170             this.el.column_spacing = 20;
171             this.el.homogeneous = true;
172             this.el.row_spacing = 20;
173         }
174
175         // userdefined functions 
176
177         // skip |xns - no return type
178     }
179     public class Xcls_fileitem : Object 
180     {
181         public Clutter.Actor el;
182         private Xcls_ClutterFiles  _this;
183
184
185             // my vars
186         public JsRender.JsRender file;
187         public Xcls_image image;
188         public Xcls_title title;
189
190             // ctor 
191         public Xcls_fileitem(Xcls_ClutterFiles _owner , JsRender.JsRender file)
192         {
193             _this = _owner;
194             this.el = new Clutter.Actor();
195
196             // my vars
197
198             // set gobject values
199             this.el.reactive = true;
200             var child_0 = new Xcls_BoxLayout5( _this );
201             child_0.ref();
202             this.el.layout_manager = child_0.el;
203             var child_1 = new Xcls_image( _this ,file);
204             child_1.ref();
205             this.el.add_child (  child_1.el  );
206             this.image =  child_1;
207             var child_2 = new Xcls_title( _this ,file);
208             child_2.ref();
209             this.el.add_child (  child_2.el  );
210             this.title =  child_2;
211
212             // init method 
213             this.file = file;
214             this.el.set_size(100,100);
215
216             // listeners 
217             this.el.enter_event.connect( (  event)  => {
218                 this.el.background_color = new Clutter.Color.from_string("#333");
219                     return false;
220             } );
221             this.el.leave_event.connect( (  event)  => {
222                 this.el.background_color = new Clutter.Color.from_string("#000");
223                 return false;
224             } );
225             this.el.button_press_event.connect(   (  event) => {
226                 _this.open(this.file);
227                 return false;
228             } );
229         }
230
231         // userdefined functions 
232
233         // skip |xns - no return type
234     }
235     public class Xcls_BoxLayout5 : Object 
236     {
237         public Clutter.BoxLayout el;
238         private Xcls_ClutterFiles  _this;
239
240
241             // my vars
242
243             // ctor 
244         public Xcls_BoxLayout5(Xcls_ClutterFiles _owner )
245         {
246             _this = _owner;
247             this.el = new Clutter.BoxLayout();
248
249             // my vars
250
251             // set gobject values
252             this.el.orientation = Clutter.Orientation.VERTICAL;
253             this.el.spacing = 4;
254         }
255
256         // userdefined functions 
257
258         // skip |xns - no return type
259     }
260     public class Xcls_image : Object 
261     {
262         public Clutter.Texture el;
263         private Xcls_ClutterFiles  _this;
264
265
266             // my vars
267
268             // ctor 
269         public Xcls_image(Xcls_ClutterFiles _owner , JsRender.JsRender file)
270         {
271             _this = _owner;
272             this.el = new Clutter.Texture.from_file(file.getIconFile());
273
274             // my vars
275
276             // set gobject values
277             this.el.margin_left = 5;
278             this.el.margin_right = 5;
279             this.el.margin_top = 5;
280             this.el.x_align = Clutter.ActorAlign.START;
281             this.el.x_expand = true;
282             this.el.y_align = Clutter.ActorAlign.START;
283             this.el.y_expand = false;
284         }
285
286         // userdefined functions 
287
288         // skip |xns - no return type
289     }
290     public class Xcls_title : Object 
291     {
292         public Clutter.Text el;
293         private Xcls_ClutterFiles  _this;
294
295
296             // my vars
297
298             // ctor 
299         public Xcls_title(Xcls_ClutterFiles _owner , JsRender.JsRender file)
300         {
301             _this = _owner;
302             this.el = new Clutter.Text.full("Sans 10px", file.nickName(),new Clutter.Color.from_string("#fff"));
303
304             // my vars
305
306             // set gobject values
307             this.el.x_align = Clutter.ActorAlign.START;
308             this.el.x_expand = true;
309             this.el.y_align = Clutter.ActorAlign.START;
310             this.el.y_expand = false;
311         }
312
313         // userdefined functions 
314
315         // skip |xns - no return type
316     }
317 }