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