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