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