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