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