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