comparison nodejs/canvas.js @ 736:cdd578c1f866

Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
author wycc
date Sat, 21 Aug 2010 19:12:43 +0800
parents
children 9f4a1134ec82
comparison
equal deleted inserted replaced
732:6879aa403306 736:cdd578c1f866
1 var mbfly = require("mbfly");
2 var sys=require("sys");
3
4
5 function canvas(app,root) {
6 this.mb_rt = app.mb_rt;
7 this.root = this.mb_rt.coord_new(root);
8 this.bg_r = 0;
9 this.bg_g = 0;
10 this.bg_b = 0;
11 this.bg_a = 0;
12 this.stroke_r = 0;
13 this.stroke_g = 0;
14 this.stroke_b = 0;
15 this.stroke_a = 0;
16 this.stroke_w = 1;
17 }
18
19 canvas.prototype.background=function(r,g,b,a) {
20 this.bg_r = r;
21 this.bg_g = g;
22 this.bg_b = b;
23 this.bg_a = a;
24 }
25
26 canvas.prototype.rect=function(x,y,w,h) {
27 var rect = this.mb_rt.rect_new(x,y,w,h,0,0);
28 var paint = this.mb_rt.paint_color_new(this.bg_r,this.bg_g,this.bg_b,this.bg_a);
29 paint.fill(rect);
30 this.root.add_shape(rect);
31 }
32
33 canvas.prototype.stroke=function(r,g,b,a) {
34 this.stroke_r = r;
35 this.stroke_g = g;
36 this.stroke_b = b;
37 this.stroke_a = a;
38 }
39
40
41 canvas.prototype.line=function(x1,y1,x2,y2) {
42 var s = "M "+x1+","+y1+" L "+x2+","+y2;
43 sys.puts(s);
44
45 var p = this.mb_rt.path_new(s);
46 this.root.add_shape(p);
47 var paint = this.mb_rt.paint_color_new(this.stroke_r,this.stroke_g,this.stroke_b,this.stroke_a);
48 paint.stroke(p);
49 p.stroke_width = this.stroke_w;
50 }
51
52 canvas.prototype.strokeWeight=function(w) {
53 this.stroke_w = w;
54 }
55
56
57 exports.canvas = canvas;