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