Mercurial > MadButterfly
annotate nodejs/testcase.js @ 742:24038e7a365b
Reorder instructions to invalidate coords correctly
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Wed, 25 Aug 2010 11:58:30 +0800 |
parents | 5ac257be7bc0 |
children | dd1f3382d6a4 |
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 |
734
5ac257be7bc0
Testcase for linear and radial paint for JS
Thinker K.F. Li <thinker@branda.to>
parents:
733
diff
changeset
|
22 /* test linear paint and rectangle */ |
5ac257be7bc0
Testcase for linear and radial paint for JS
Thinker K.F. Li <thinker@branda.to>
parents:
733
diff
changeset
|
23 var rect = mb_rt.rect_new(100, 100, 50, 50, 10, 10); |
5ac257be7bc0
Testcase for linear and radial paint for JS
Thinker K.F. Li <thinker@branda.to>
parents:
733
diff
changeset
|
24 sys.puts(mb_rt.paint_linear_new); |
5ac257be7bc0
Testcase for linear and radial paint for JS
Thinker K.F. Li <thinker@branda.to>
parents:
733
diff
changeset
|
25 var paint = mb_rt.paint_linear_new(100, 100, 150, 150); |
5ac257be7bc0
Testcase for linear and radial paint for JS
Thinker K.F. Li <thinker@branda.to>
parents:
733
diff
changeset
|
26 paint.set_stops([[0, 0, 1, 0, 1], [1, 0, 0, 1, 1]]); |
5ac257be7bc0
Testcase for linear and radial paint for JS
Thinker K.F. Li <thinker@branda.to>
parents:
733
diff
changeset
|
27 paint.fill(rect); |
5ac257be7bc0
Testcase for linear and radial paint for JS
Thinker K.F. Li <thinker@branda.to>
parents:
733
diff
changeset
|
28 root.add_shape(rect); |
5ac257be7bc0
Testcase for linear and radial paint for JS
Thinker K.F. Li <thinker@branda.to>
parents:
733
diff
changeset
|
29 |
5ac257be7bc0
Testcase for linear and radial paint for JS
Thinker K.F. Li <thinker@branda.to>
parents:
733
diff
changeset
|
30 /* test radial paint and rectangle */ |
5ac257be7bc0
Testcase for linear and radial paint for JS
Thinker K.F. Li <thinker@branda.to>
parents:
733
diff
changeset
|
31 var rect = mb_rt.rect_new(150, 100, 50, 50, 10, 10); |
5ac257be7bc0
Testcase for linear and radial paint for JS
Thinker K.F. Li <thinker@branda.to>
parents:
733
diff
changeset
|
32 sys.puts(mb_rt.paint_radial_new); |
5ac257be7bc0
Testcase for linear and radial paint for JS
Thinker K.F. Li <thinker@branda.to>
parents:
733
diff
changeset
|
33 var paint = mb_rt.paint_radial_new(175, 125, 25); |
5ac257be7bc0
Testcase for linear and radial paint for JS
Thinker K.F. Li <thinker@branda.to>
parents:
733
diff
changeset
|
34 paint.set_stops([[0, 0, 1, 0, 1], [1, 0, 0, 1, 1]]); |
5ac257be7bc0
Testcase for linear and radial paint for JS
Thinker K.F. Li <thinker@branda.to>
parents:
733
diff
changeset
|
35 paint.fill(rect); |
5ac257be7bc0
Testcase for linear and radial paint for JS
Thinker K.F. Li <thinker@branda.to>
parents:
733
diff
changeset
|
36 root.add_shape(rect); |
5ac257be7bc0
Testcase for linear and radial paint for JS
Thinker K.F. Li <thinker@branda.to>
parents:
733
diff
changeset
|
37 |
690
86c6ebf1de25
Add JS binding for sh_rect_t
Thinker K.F. Li <thinker@branda.to>
parents:
681
diff
changeset
|
38 /* test alpha blending and rectangle */ |
86c6ebf1de25
Add JS binding for sh_rect_t
Thinker K.F. Li <thinker@branda.to>
parents:
681
diff
changeset
|
39 var rect = mb_rt.rect_new(40, 40, 100, 100, 10, 10); |
86c6ebf1de25
Add JS binding for sh_rect_t
Thinker K.F. Li <thinker@branda.to>
parents:
681
diff
changeset
|
40 sys.puts(mb_rt.paint_color_new); |
86c6ebf1de25
Add JS binding for sh_rect_t
Thinker K.F. Li <thinker@branda.to>
parents:
681
diff
changeset
|
41 var paint = mb_rt.paint_color_new(1, 0.5, 0.5, 0.5); |
86c6ebf1de25
Add JS binding for sh_rect_t
Thinker K.F. Li <thinker@branda.to>
parents:
681
diff
changeset
|
42 paint.fill(rect); |
86c6ebf1de25
Add JS binding for sh_rect_t
Thinker K.F. Li <thinker@branda.to>
parents:
681
diff
changeset
|
43 root.add_shape(rect); |
86c6ebf1de25
Add JS binding for sh_rect_t
Thinker K.F. Li <thinker@branda.to>
parents:
681
diff
changeset
|
44 |
742
24038e7a365b
Reorder instructions to invalidate coords correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
734
diff
changeset
|
45 /* test removing a coord */ |
24038e7a365b
Reorder instructions to invalidate coords correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
734
diff
changeset
|
46 var rm_coord = mb_rt.coord_new(root); |
24038e7a365b
Reorder instructions to invalidate coords correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
734
diff
changeset
|
47 var rm_rect = mb_rt.rect_new(150, 150, 50, 50, 10, 10); |
24038e7a365b
Reorder instructions to invalidate coords correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
734
diff
changeset
|
48 paint.fill(rm_rect); |
24038e7a365b
Reorder instructions to invalidate coords correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
734
diff
changeset
|
49 rm_coord.add_shape(rm_rect); |
24038e7a365b
Reorder instructions to invalidate coords correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
734
diff
changeset
|
50 setTimeout(function() { rm_coord.remove(); }, 3000); |
24038e7a365b
Reorder instructions to invalidate coords correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
734
diff
changeset
|
51 |
644 | 52 /* Moving a path */ |
565
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
563
diff
changeset
|
53 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
|
54 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
|
55 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
|
56 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
|
57 coord.add_shape(path); |
565
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
563
diff
changeset
|
58 |
567
a12c3448afb6
Add dummy paint_color templates
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
59 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
|
60 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
|
61 sys.puts(paint); |
569
f87a368e847a
Functions of stroke and fill a shape
Thinker K.F. Li <thinker@branda.to>
parents:
568
diff
changeset
|
62 paint.stroke(path); |
567
a12c3448afb6
Add dummy paint_color templates
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
63 |
570
49e79253b6d3
Functions of setting/getting stroke width of a shape
Thinker K.F. Li <thinker@branda.to>
parents:
569
diff
changeset
|
64 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
|
65 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
|
66 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
|
67 |
576
5a68e2bcea17
Set font styles for stext in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
574
diff
changeset
|
68 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
|
69 var blks = [[5, face, 20]]; |
5a68e2bcea17
Set font styles for stext in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
574
diff
changeset
|
70 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
|
71 stext.set_style(blks); |
5a68e2bcea17
Set font styles for stext in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
574
diff
changeset
|
72 paint.fill(stext); |
5a68e2bcea17
Set font styles for stext in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
574
diff
changeset
|
73 coord.add_shape(stext); |
5a68e2bcea17
Set font styles for stext in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
574
diff
changeset
|
74 |
571
13b15b7a463b
Redraw all and changed in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
570
diff
changeset
|
75 mb_rt.redraw_all(); |
704
d950487bd9f9
Flush mb_rt, immediately, after redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents:
699
diff
changeset
|
76 mb_rt.flush(); |
571
13b15b7a463b
Redraw all and changed in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
570
diff
changeset
|
77 |
13b15b7a463b
Redraw all and changed in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
570
diff
changeset
|
78 var i = 0; |
13b15b7a463b
Redraw all and changed in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
570
diff
changeset
|
79 setInterval(function() { |
13b15b7a463b
Redraw all and changed in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
570
diff
changeset
|
80 var deg = (i++) * 0.1; |
699
0b98bdc53215
Add binding for color changing of paint_color_t in JS
Thinker K.F. Li <thinker@branda.to>
parents:
697
diff
changeset
|
81 coord[2] = (i % 40) * 5; |
571
13b15b7a463b
Redraw all and changed in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
570
diff
changeset
|
82 mb_rt.redraw_changed(); |
733
163f0d9e6382
Add binding for linear and radial paints for JS
Thinker K.F. Li <thinker@branda.to>
parents:
725
diff
changeset
|
83 mb_rt.flush(); |
624 | 84 }, 20); |
549
6ec4d7e90480
Nodejs testcase in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
85 setTimeout(function() { sys.puts("timeout"); }, 1000); |
676
f264b50c469c
Bind subject of mouse_event to JS object of coord
Thinker K.F. Li <thinker@branda.to>
parents:
644
diff
changeset
|
86 |
680
a588eefd3f04
Refactor to xnjsmb_coord_mod().
Thinker K.F. Li <thinker@branda.to>
parents:
679
diff
changeset
|
87 sys.puts(root.mouse_event); |
676
f264b50c469c
Bind subject of mouse_event to JS object of coord
Thinker K.F. Li <thinker@branda.to>
parents:
644
diff
changeset
|
88 var observer; |
f264b50c469c
Bind subject of mouse_event to JS object of coord
Thinker K.F. Li <thinker@branda.to>
parents:
644
diff
changeset
|
89 /* Mouse button pressed */ |
680
a588eefd3f04
Refactor to xnjsmb_coord_mod().
Thinker K.F. Li <thinker@branda.to>
parents:
679
diff
changeset
|
90 observer = root.mouse_event.add_event_observer(4, function(evt) { |
699
0b98bdc53215
Add binding for color changing of paint_color_t in JS
Thinker K.F. Li <thinker@branda.to>
parents:
697
diff
changeset
|
91 var c = 1 - (i % 40) / 40; |
0b98bdc53215
Add binding for color changing of paint_color_t in JS
Thinker K.F. Li <thinker@branda.to>
parents:
697
diff
changeset
|
92 sys.puts(c); |
0b98bdc53215
Add binding for color changing of paint_color_t in JS
Thinker K.F. Li <thinker@branda.to>
parents:
697
diff
changeset
|
93 |
679
799c852b9065
Extract event info from C object to JS object
Thinker K.F. Li <thinker@branda.to>
parents:
676
diff
changeset
|
94 sys.puts("mouse " + evt.x + " " + evt.y); |
699
0b98bdc53215
Add binding for color changing of paint_color_t in JS
Thinker K.F. Li <thinker@branda.to>
parents:
697
diff
changeset
|
95 sys.puts(c); |
0b98bdc53215
Add binding for color changing of paint_color_t in JS
Thinker K.F. Li <thinker@branda.to>
parents:
697
diff
changeset
|
96 sys.puts(paint.set_color); |
0b98bdc53215
Add binding for color changing of paint_color_t in JS
Thinker K.F. Li <thinker@branda.to>
parents:
697
diff
changeset
|
97 paint.set_color(c, 1, 1, 1); |
0b98bdc53215
Add binding for color changing of paint_color_t in JS
Thinker K.F. Li <thinker@branda.to>
parents:
697
diff
changeset
|
98 mb_rt.redraw_changed(); |
0b98bdc53215
Add binding for color changing of paint_color_t in JS
Thinker K.F. Li <thinker@branda.to>
parents:
697
diff
changeset
|
99 mb_rt.flush(); |
676
f264b50c469c
Bind subject of mouse_event to JS object of coord
Thinker K.F. Li <thinker@branda.to>
parents:
644
diff
changeset
|
100 }); |
679
799c852b9065
Extract event info from C object to JS object
Thinker K.F. Li <thinker@branda.to>
parents:
676
diff
changeset
|
101 |
799c852b9065
Extract event info from C object to JS object
Thinker K.F. Li <thinker@branda.to>
parents:
676
diff
changeset
|
102 var kbobserver; |
799c852b9065
Extract event info from C object to JS object
Thinker K.F. Li <thinker@branda.to>
parents:
676
diff
changeset
|
103 /* Keyboard event */ |
681
b601a4d6f7d1
Change kbevent to kbevents and hide X_MB_kbevents()
Thinker K.F. Li <thinker@branda.to>
parents:
680
diff
changeset
|
104 kbobserver = mb_rt.kbevents.add_event_observer(6, function(evt) { |
679
799c852b9065
Extract event info from C object to JS object
Thinker K.F. Li <thinker@branda.to>
parents:
676
diff
changeset
|
105 sys.puts("keycode = " + evt.keycode); |
799c852b9065
Extract event info from C object to JS object
Thinker K.F. Li <thinker@branda.to>
parents:
676
diff
changeset
|
106 sys.puts("sym = " + evt.sym); |
799c852b9065
Extract event info from C object to JS object
Thinker K.F. Li <thinker@branda.to>
parents:
676
diff
changeset
|
107 }); |