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             print("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             
70             print("\nnew y %f  sroll actor height %f = last child bottom %f\n ".printf( 
71                     y, 
72                     this.el.height, 
73                     this.filelayout.el.last_child.y +  this.filelayout.el.last_child.height));    
74            // y = float.min(0, y);    //??
75             print("scroll event of %f  - new y = %f ".printf(event.y, y));
76             this.filelayout.el.y = y;
77             return true;
78                 
79         } );
80     }
81
82     // userdefined functions 
83     public void set_size(float w, float h) {
84             _this.filelayout_manager.el.max_column_width = w - 150;
85            this.el.set_size(this.el.get_stage().width-150,
86                                 this.el.get_stage().height);
87                     this.el.set_position(100,50);
88         }
89     public void show(Project.Project pr) {
90             // list all the files, and create new Xcls_fileitem for each one.
91             
92             var fiter = pr.files.map_iterator();
93             while (fiter.next()) {
94                 var a = new Xcls_fileitem(this,fiter.get_value());
95                 a.ref();
96                 print("add " + fiter.get_value().name + "\n");
97                 this.filelayout.el.add_child(a.el);
98             }
99             this.el.show_all();
100         }
101
102     // skip |xns - no return type
103     public class Xcls_filelayout : Object 
104     {
105         public Clutter.Actor el;
106         private Xcls_ClutterFiles  _this;
107
108
109             // my vars
110
111             // ctor 
112         public Xcls_filelayout(Xcls_ClutterFiles _owner )
113         {
114             _this = _owner;
115             _this.filelayout = this;
116             this.el = new Clutter.Actor();
117
118             // my vars
119
120             // set gobject values
121             this.el.reactive = true;
122             var child_0 = new Xcls_filelayout_manager( _this );
123             child_0.ref();
124             this.el.layout_manager = child_0.el;
125
126             // init method 
127             this.el.add_constraint(
128                 new Clutter.BindConstraint(_this.el,Clutter.BindCoordinate.SIZE, 0.0f)
129             );
130         }
131
132         // userdefined functions 
133
134         // skip |xns - no return type
135     }
136     public class Xcls_filelayout_manager : Object 
137     {
138         public Clutter.FlowLayout el;
139         private Xcls_ClutterFiles  _this;
140
141
142             // my vars
143
144             // ctor 
145         public Xcls_filelayout_manager(Xcls_ClutterFiles _owner )
146         {
147             _this = _owner;
148             _this.filelayout_manager = this;
149             this.el = new Clutter.FlowLayout( Clutter.FlowOrientation.HORIZONTAL );
150
151             // my vars
152
153             // set gobject values
154             this.el.column_spacing = 20;
155             this.el.homogeneous = true;
156             this.el.row_spacing = 20;
157         }
158
159         // userdefined functions 
160
161         // skip |xns - no return type
162     }
163     public class Xcls_fileitem : Object 
164     {
165         public Clutter.Actor el;
166         private Xcls_ClutterFiles  _this;
167
168
169             // my vars
170         public Xcls_image image;
171         public Xcls_title title;
172
173             // ctor 
174         public Xcls_fileitem(Xcls_ClutterFiles _owner , JsRender.JsRender file)
175         {
176             _this = _owner;
177             this.el = new Clutter.Actor();
178
179             // my vars
180
181             // set gobject values
182             var child_0 = new Xcls_BoxLayout5( _this );
183             child_0.ref();
184             this.el.layout_manager = child_0.el;
185             var child_1 = new Xcls_image( _this ,file);
186             child_1.ref();
187             this.el.add_child (  child_1.el  );
188             this.image =  child_1;
189             var child_2 = new Xcls_title( _this ,file);
190             child_2.ref();
191             this.el.add_child (  child_2.el  );
192             this.title =  child_2;
193
194             // init method 
195             this.el.set_size(100,100);
196         }
197
198         // userdefined functions 
199
200         // skip |xns - no return type
201     }
202     public class Xcls_BoxLayout5 : Object 
203     {
204         public Clutter.BoxLayout el;
205         private Xcls_ClutterFiles  _this;
206
207
208             // my vars
209
210             // ctor 
211         public Xcls_BoxLayout5(Xcls_ClutterFiles _owner )
212         {
213             _this = _owner;
214             this.el = new Clutter.BoxLayout();
215
216             // my vars
217
218             // set gobject values
219             this.el.orientation = Clutter.Orientation.VERTICAL;
220             this.el.spacing = 4;
221         }
222
223         // userdefined functions 
224
225         // skip |xns - no return type
226     }
227     public class Xcls_image : Object 
228     {
229         public Clutter.Texture el;
230         private Xcls_ClutterFiles  _this;
231
232
233             // my vars
234
235             // ctor 
236         public Xcls_image(Xcls_ClutterFiles _owner , JsRender.JsRender file)
237         {
238             _this = _owner;
239             this.el = new Clutter.Texture.from_file(file.getIconFile());
240
241             // my vars
242
243             // set gobject values
244             this.el.x_align = Clutter.ActorAlign.START;
245             this.el.x_expand = true;
246             this.el.y_align = Clutter.ActorAlign.START;
247             this.el.y_expand = false;
248         }
249
250         // userdefined functions 
251
252         // skip |xns - no return type
253     }
254     public class Xcls_title : Object 
255     {
256         public Clutter.Text el;
257         private Xcls_ClutterFiles  _this;
258
259
260             // my vars
261
262             // ctor 
263         public Xcls_title(Xcls_ClutterFiles _owner , JsRender.JsRender file)
264         {
265             _this = _owner;
266             this.el = new Clutter.Text.full("Sans 10px", file.nickName(),new Clutter.Color.from_string("#fff"));
267
268             // my vars
269
270             // set gobject values
271             this.el.x_align = Clutter.ActorAlign.START;
272             this.el.x_expand = true;
273             this.el.y_align = Clutter.ActorAlign.START;
274             this.el.y_expand = false;
275         }
276
277         // userdefined functions 
278
279         // skip |xns - no return type
280     }
281 }