Mercurial > MadButterfly
annotate nodejs/canvas.js @ 948:518c61784355
Add frameruler to show ruler for framelines
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Wed, 17 Nov 2010 01:46:10 +0800 |
parents | 586e50f82c1f |
children |
rev | line source |
---|---|
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
774
diff
changeset
|
1 // -*- indent-tabs-mode: t; tab-width: 8; c-basic-offset: 4; -*- |
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
774
diff
changeset
|
2 // vim: sw=4:ts=8:sts=4 |
736
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
3 var mbfly = require("mbfly"); |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
4 var sys=require("sys"); |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
5 |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
6 |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
7 function canvas(app,root) { |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
8 this.mb_rt = app.mb_rt; |
751
9f4a1134ec82
Use the coord.remove() to implement the processing canvas
wycc
parents:
736
diff
changeset
|
9 this.parent = root; |
736
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
10 this.root = this.mb_rt.coord_new(root); |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
11 this.bg_r = 0; |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
12 this.bg_g = 0; |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
13 this.bg_b = 0; |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
14 this.bg_a = 0; |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
15 this.stroke_r = 0; |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
16 this.stroke_g = 0; |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
17 this.stroke_b = 0; |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
18 this.stroke_a = 0; |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
19 this.stroke_w = 1; |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
20 } |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
21 |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
22 canvas.prototype.background=function(r,g,b,a) { |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
23 this.bg_r = r; |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
24 this.bg_g = g; |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
25 this.bg_b = b; |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
26 this.bg_a = a; |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
27 } |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
28 |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
29 canvas.prototype.rect=function(x,y,w,h) { |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
30 var rect = this.mb_rt.rect_new(x,y,w,h,0,0); |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
31 var paint = this.mb_rt.paint_color_new(this.bg_r,this.bg_g,this.bg_b,this.bg_a); |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
32 paint.fill(rect); |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
33 this.root.add_shape(rect); |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
34 } |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
35 |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
36 canvas.prototype.stroke=function(r,g,b,a) { |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
37 this.stroke_r = r; |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
38 this.stroke_g = g; |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
39 this.stroke_b = b; |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
40 this.stroke_a = a; |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
41 } |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
42 |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
43 |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
44 canvas.prototype.line=function(x1,y1,x2,y2) { |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
45 var s = "M "+x1+","+y1+" L "+x2+","+y2; |
773
1b522a22e16a
Remove sys.puts, it is why leaking
Thinker K.F. Li <thinker@codemud.net>
parents:
751
diff
changeset
|
46 //sys.puts(s); |
736
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
47 |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
48 var p = this.mb_rt.path_new(s); |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
49 this.root.add_shape(p); |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
50 var paint = this.mb_rt.paint_color_new(this.stroke_r,this.stroke_g,this.stroke_b,this.stroke_a); |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
51 paint.stroke(p); |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
52 p.stroke_width = this.stroke_w; |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
53 } |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
54 |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
55 canvas.prototype.strokeWeight=function(w) { |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
56 this.stroke_w = w; |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
57 } |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
58 |
751
9f4a1134ec82
Use the coord.remove() to implement the processing canvas
wycc
parents:
736
diff
changeset
|
59 canvas.prototype.alpha=function(c) { |
9f4a1134ec82
Use the coord.remove() to implement the processing canvas
wycc
parents:
736
diff
changeset
|
60 } |
9f4a1134ec82
Use the coord.remove() to implement the processing canvas
wycc
parents:
736
diff
changeset
|
61 |
9f4a1134ec82
Use the coord.remove() to implement the processing canvas
wycc
parents:
736
diff
changeset
|
62 canvas.prototype.red=function(c) { |
9f4a1134ec82
Use the coord.remove() to implement the processing canvas
wycc
parents:
736
diff
changeset
|
63 } |
9f4a1134ec82
Use the coord.remove() to implement the processing canvas
wycc
parents:
736
diff
changeset
|
64 canvas.prototype.green=function(c) { |
9f4a1134ec82
Use the coord.remove() to implement the processing canvas
wycc
parents:
736
diff
changeset
|
65 } |
9f4a1134ec82
Use the coord.remove() to implement the processing canvas
wycc
parents:
736
diff
changeset
|
66 canvas.prototype.blue=function(c) { |
9f4a1134ec82
Use the coord.remove() to implement the processing canvas
wycc
parents:
736
diff
changeset
|
67 } |
9f4a1134ec82
Use the coord.remove() to implement the processing canvas
wycc
parents:
736
diff
changeset
|
68 |
9f4a1134ec82
Use the coord.remove() to implement the processing canvas
wycc
parents:
736
diff
changeset
|
69 |
9f4a1134ec82
Use the coord.remove() to implement the processing canvas
wycc
parents:
736
diff
changeset
|
70 canvas.prototype.clear=function() { |
9f4a1134ec82
Use the coord.remove() to implement the processing canvas
wycc
parents:
736
diff
changeset
|
71 this.root.remove(); |
9f4a1134ec82
Use the coord.remove() to implement the processing canvas
wycc
parents:
736
diff
changeset
|
72 this.root = this.mb_rt.coord_new(this.parent); |
9f4a1134ec82
Use the coord.remove() to implement the processing canvas
wycc
parents:
736
diff
changeset
|
73 } |
9f4a1134ec82
Use the coord.remove() to implement the processing canvas
wycc
parents:
736
diff
changeset
|
74 |
9f4a1134ec82
Use the coord.remove() to implement the processing canvas
wycc
parents:
736
diff
changeset
|
75 canvas.prototype.arc=function(x,y,w,h,start,end) { |
9f4a1134ec82
Use the coord.remove() to implement the processing canvas
wycc
parents:
736
diff
changeset
|
76 } |
9f4a1134ec82
Use the coord.remove() to implement the processing canvas
wycc
parents:
736
diff
changeset
|
77 |
9f4a1134ec82
Use the coord.remove() to implement the processing canvas
wycc
parents:
736
diff
changeset
|
78 canvas.prototype.ellipse=function(x, y, width, height) { |
9f4a1134ec82
Use the coord.remove() to implement the processing canvas
wycc
parents:
736
diff
changeset
|
79 } |
9f4a1134ec82
Use the coord.remove() to implement the processing canvas
wycc
parents:
736
diff
changeset
|
80 |
9f4a1134ec82
Use the coord.remove() to implement the processing canvas
wycc
parents:
736
diff
changeset
|
81 canvas.prototype.point=function(x,y) { |
9f4a1134ec82
Use the coord.remove() to implement the processing canvas
wycc
parents:
736
diff
changeset
|
82 } |
9f4a1134ec82
Use the coord.remove() to implement the processing canvas
wycc
parents:
736
diff
changeset
|
83 |
9f4a1134ec82
Use the coord.remove() to implement the processing canvas
wycc
parents:
736
diff
changeset
|
84 canvas.prototype.quad=function(x1,y1,x2,y2,x3,y3,x4,y4) { |
9f4a1134ec82
Use the coord.remove() to implement the processing canvas
wycc
parents:
736
diff
changeset
|
85 } |
9f4a1134ec82
Use the coord.remove() to implement the processing canvas
wycc
parents:
736
diff
changeset
|
86 |
9f4a1134ec82
Use the coord.remove() to implement the processing canvas
wycc
parents:
736
diff
changeset
|
87 canvas.prototype.triangle=function(x1,y1,x2,y2,x3,y3) { |
9f4a1134ec82
Use the coord.remove() to implement the processing canvas
wycc
parents:
736
diff
changeset
|
88 } |
9f4a1134ec82
Use the coord.remove() to implement the processing canvas
wycc
parents:
736
diff
changeset
|
89 |
9f4a1134ec82
Use the coord.remove() to implement the processing canvas
wycc
parents:
736
diff
changeset
|
90 canvas.prototype.bezier=function(x1, y1, cx1, cy1, cx2, cy2, x2, y2) { |
9f4a1134ec82
Use the coord.remove() to implement the processing canvas
wycc
parents:
736
diff
changeset
|
91 } |
9f4a1134ec82
Use the coord.remove() to implement the processing canvas
wycc
parents:
736
diff
changeset
|
92 |
9f4a1134ec82
Use the coord.remove() to implement the processing canvas
wycc
parents:
736
diff
changeset
|
93 canvas.prototype.curveTightness=function(squishy) { |
9f4a1134ec82
Use the coord.remove() to implement the processing canvas
wycc
parents:
736
diff
changeset
|
94 } |
9f4a1134ec82
Use the coord.remove() to implement the processing canvas
wycc
parents:
736
diff
changeset
|
95 |
9f4a1134ec82
Use the coord.remove() to implement the processing canvas
wycc
parents:
736
diff
changeset
|
96 canvas.prototype.colorMode=function() { |
9f4a1134ec82
Use the coord.remove() to implement the processing canvas
wycc
parents:
736
diff
changeset
|
97 } |
9f4a1134ec82
Use the coord.remove() to implement the processing canvas
wycc
parents:
736
diff
changeset
|
98 |
9f4a1134ec82
Use the coord.remove() to implement the processing canvas
wycc
parents:
736
diff
changeset
|
99 canvas.prototype.fill=function(color) { |
9f4a1134ec82
Use the coord.remove() to implement the processing canvas
wycc
parents:
736
diff
changeset
|
100 } |
9f4a1134ec82
Use the coord.remove() to implement the processing canvas
wycc
parents:
736
diff
changeset
|
101 |
9f4a1134ec82
Use the coord.remove() to implement the processing canvas
wycc
parents:
736
diff
changeset
|
102 canvas.prototype.noFill=function() { |
9f4a1134ec82
Use the coord.remove() to implement the processing canvas
wycc
parents:
736
diff
changeset
|
103 } |
9f4a1134ec82
Use the coord.remove() to implement the processing canvas
wycc
parents:
736
diff
changeset
|
104 |
9f4a1134ec82
Use the coord.remove() to implement the processing canvas
wycc
parents:
736
diff
changeset
|
105 canvas.prototype.noStroke=function() { |
9f4a1134ec82
Use the coord.remove() to implement the processing canvas
wycc
parents:
736
diff
changeset
|
106 } |
9f4a1134ec82
Use the coord.remove() to implement the processing canvas
wycc
parents:
736
diff
changeset
|
107 |
736
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
108 |
cdd578c1f866
Add Canvas class for the dynamic content generation. The testcanvas.js is used to demostrate the capability of it.
wycc
parents:
diff
changeset
|
109 exports.canvas = canvas; |