Mercurial > MadButterfly
annotate nodejs/testcase.js @ 643:a65720721c60
Fix issue of exception of internal field.
img_ldr is a function to return a new img_ldr, not a constructor as in
previous implementation. This changeset fix semantic error on
xnjsmb_img_ldr_new().
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Wed, 28 Jul 2010 08:31:15 +0800 |
parents | d45c928f6523 |
children | c9f8c7e6f57e |
rev | line source |
---|---|
549
6ec4d7e90480
Nodejs testcase in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
1 var mbfly = require("mbfly"); |
6ec4d7e90480
Nodejs testcase in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
2 var r = mbfly.Hello(" test"); |
6ec4d7e90480
Nodejs testcase in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
3 var sys = require("sys"); |
6ec4d7e90480
Nodejs testcase in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
4 sys.puts(r); |
6ec4d7e90480
Nodejs testcase in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
5 |
558
d61133da2845
New MadButterfly runtime object install of calling function
Thinker K.F. Li <thinker@branda.to>
parents:
556
diff
changeset
|
6 var mb_rt = new mbfly.mb_rt(":0.0", 300, 200); |
563
bc207070e3d5
Fix issue of im-properly using persistent handler for coord object template.
Thinker K.F. Li <thinker@branda.to>
parents:
562
diff
changeset
|
7 var root = mb_rt.root; |
bc207070e3d5
Fix issue of im-properly using persistent handler for coord object template.
Thinker K.F. Li <thinker@branda.to>
parents:
562
diff
changeset
|
8 sys.puts("root matrix: " + |
bc207070e3d5
Fix issue of im-properly using persistent handler for coord object template.
Thinker K.F. Li <thinker@branda.to>
parents:
562
diff
changeset
|
9 [root[0], root[1], root[2], root[3], root[4], root[5]]); |
bc207070e3d5
Fix issue of im-properly using persistent handler for coord object template.
Thinker K.F. Li <thinker@branda.to>
parents:
562
diff
changeset
|
10 var coord = mb_rt.coord_new(root); |
bc207070e3d5
Fix issue of im-properly using persistent handler for coord object template.
Thinker K.F. Li <thinker@branda.to>
parents:
562
diff
changeset
|
11 sys.puts("coord matrix: " + |
bc207070e3d5
Fix issue of im-properly using persistent handler for coord object template.
Thinker K.F. Li <thinker@branda.to>
parents:
562
diff
changeset
|
12 [coord[0], coord[1], coord[2], coord[3], coord[4], coord[5]]); |
549
6ec4d7e90480
Nodejs testcase in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
13 |
643
a65720721c60
Fix issue of exception of internal field.
Thinker K.F. Li <thinker@branda.to>
parents:
624
diff
changeset
|
14 /* Testcase for image shapes */ |
a65720721c60
Fix issue of exception of internal field.
Thinker K.F. Li <thinker@branda.to>
parents:
624
diff
changeset
|
15 var img = mb_rt.image_new(10, 10, 50, 50); |
a65720721c60
Fix issue of exception of internal field.
Thinker K.F. Li <thinker@branda.to>
parents:
624
diff
changeset
|
16 var ldr = mbfly.img_ldr_new("."); |
a65720721c60
Fix issue of exception of internal field.
Thinker K.F. Li <thinker@branda.to>
parents:
624
diff
changeset
|
17 var img_data = ldr.load("sample.png"); |
a65720721c60
Fix issue of exception of internal field.
Thinker K.F. Li <thinker@branda.to>
parents:
624
diff
changeset
|
18 var paint = mb_rt.paint_image_new(img_data); |
a65720721c60
Fix issue of exception of internal field.
Thinker K.F. Li <thinker@branda.to>
parents:
624
diff
changeset
|
19 paint.fill(img); |
a65720721c60
Fix issue of exception of internal field.
Thinker K.F. Li <thinker@branda.to>
parents:
624
diff
changeset
|
20 root.add_shape(img); |
a65720721c60
Fix issue of exception of internal field.
Thinker K.F. Li <thinker@branda.to>
parents:
624
diff
changeset
|
21 |
565
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
563
diff
changeset
|
22 sys.puts(mb_rt.path_new); |
571
13b15b7a463b
Redraw all and changed in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
570
diff
changeset
|
23 var path = mb_rt.path_new("m 100,50 L 120,50 L 200,150 L 180,150 z"); |
565
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
563
diff
changeset
|
24 sys.puts(path); |
566
6639d386db78
Function of add a shape to a coord in Javascript.
Thinker K.F. Li <thinker@branda.to>
parents:
565
diff
changeset
|
25 sys.puts(coord.add_shape); |
6639d386db78
Function of add a shape to a coord in Javascript.
Thinker K.F. Li <thinker@branda.to>
parents:
565
diff
changeset
|
26 coord.add_shape(path); |
565
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
563
diff
changeset
|
27 |
567
a12c3448afb6
Add dummy paint_color templates
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
28 sys.puts(mb_rt.paint_color_new); |
574
a2faee809514
Implement stext type for Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
571
diff
changeset
|
29 var paint = mb_rt.paint_color_new(1, 1, 1, 1); |
568
d796e6b8b97e
Real initialize a paint_color_t object for paint_color JS obj
Thinker K.F. Li <thinker@branda.to>
parents:
567
diff
changeset
|
30 sys.puts(paint); |
569
f87a368e847a
Functions of stroke and fill a shape
Thinker K.F. Li <thinker@branda.to>
parents:
568
diff
changeset
|
31 paint.stroke(path); |
567
a12c3448afb6
Add dummy paint_color templates
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
32 |
570
49e79253b6d3
Functions of setting/getting stroke width of a shape
Thinker K.F. Li <thinker@branda.to>
parents:
569
diff
changeset
|
33 sys.puts(path.stroke_width); |
49e79253b6d3
Functions of setting/getting stroke width of a shape
Thinker K.F. Li <thinker@branda.to>
parents:
569
diff
changeset
|
34 path.stroke_width = 2; |
49e79253b6d3
Functions of setting/getting stroke width of a shape
Thinker K.F. Li <thinker@branda.to>
parents:
569
diff
changeset
|
35 sys.puts(path.stroke_width); |
49e79253b6d3
Functions of setting/getting stroke width of a shape
Thinker K.F. Li <thinker@branda.to>
parents:
569
diff
changeset
|
36 |
576
5a68e2bcea17
Set font styles for stext in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
574
diff
changeset
|
37 var face = mb_rt.font_face_query("courier", 2, 100); |
5a68e2bcea17
Set font styles for stext in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
574
diff
changeset
|
38 var blks = [[5, face, 20]]; |
5a68e2bcea17
Set font styles for stext in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
574
diff
changeset
|
39 var stext = mb_rt.stext_new("Hello", 100, 50); |
5a68e2bcea17
Set font styles for stext in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
574
diff
changeset
|
40 stext.set_style(blks); |
5a68e2bcea17
Set font styles for stext in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
574
diff
changeset
|
41 paint.fill(stext); |
5a68e2bcea17
Set font styles for stext in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
574
diff
changeset
|
42 coord.add_shape(stext); |
5a68e2bcea17
Set font styles for stext in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
574
diff
changeset
|
43 |
571
13b15b7a463b
Redraw all and changed in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
570
diff
changeset
|
44 mb_rt.redraw_all(); |
13b15b7a463b
Redraw all and changed in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
570
diff
changeset
|
45 |
13b15b7a463b
Redraw all and changed in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
570
diff
changeset
|
46 var i = 0; |
13b15b7a463b
Redraw all and changed in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
570
diff
changeset
|
47 setInterval(function() { |
13b15b7a463b
Redraw all and changed in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
570
diff
changeset
|
48 var deg = (i++) * 0.1; |
13b15b7a463b
Redraw all and changed in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
570
diff
changeset
|
49 coord[2] = (i % 20) * 10; |
13b15b7a463b
Redraw all and changed in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
570
diff
changeset
|
50 mb_rt.redraw_changed(); |
624 | 51 }, 20); |
549
6ec4d7e90480
Nodejs testcase in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
52 setTimeout(function() { sys.puts("timeout"); }, 1000); |