Mercurial > MadButterfly
comparison nodejs/examples/simple/testcase.js @ 939:a74b4d986a91
Move examples for nodejs into nodejs/examples/ sub-directories.
See INSTALL.txt. Use nodejs/examples/run.sh to run examples.
For example,
cd nodejs/examples; ./run.sh examples/testsvg/testsvg.js
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Fri, 12 Nov 2010 17:39:04 +0800 |
parents | nodejs/testcase.js@586e50f82c1f |
children |
comparison
equal
deleted
inserted
replaced
938:13b9acbbe9a3 | 939:a74b4d986a91 |
---|---|
1 // -*- indent-tabs-mode: t; tab-width: 8; c-basic-offset: 4; -*- | |
2 // vim: sw=4:ts=8:sts=4 | |
3 var mbfly = require("mbfly"); | |
4 var r = mbfly.Hello(" test"); | |
5 var sys = require("sys"); | |
6 sys.puts(r); | |
7 | |
8 var display_name = ":0.0"; | |
9 if(process.argv.length == 3) | |
10 display_name = process.argv[2]; | |
11 | |
12 var mb_rt = new mbfly.mb_rt(display_name, 300, 200); | |
13 var root = mb_rt.root; | |
14 sys.puts("root matrix: " + | |
15 [root[0], root[1], root[2], root[3], root[4], root[5]]); | |
16 var coord = mb_rt.coord_new(root); | |
17 sys.puts("coord matrix: " + | |
18 [coord[0], coord[1], coord[2], coord[3], coord[4], coord[5]]); | |
19 | |
20 /* Testcase for image shapes */ | |
21 var img = mb_rt.image_new(10, 10, 50, 50); | |
22 var ldr = mbfly.img_ldr_new("."); | |
23 var img_data = ldr.load("sample.png"); | |
24 var paint = mb_rt.paint_image_new(img_data); | |
25 var img_coord = mb_rt.coord_new(root); | |
26 paint.fill(img); | |
27 img_coord.add_shape(img); | |
28 | |
29 /* test linear paint and rectangle */ | |
30 var rect = mb_rt.rect_new(100, 100, 50, 50, 10, 10); | |
31 sys.puts(mb_rt.paint_linear_new); | |
32 var paint = mb_rt.paint_linear_new(100, 100, 150, 150); | |
33 paint.set_stops([[0, 0, 1, 0, 1], [1, 0, 0, 1, 1]]); | |
34 paint.fill(rect); | |
35 root.add_shape(rect); | |
36 | |
37 /* test radial paint and rectangle */ | |
38 var rect = mb_rt.rect_new(150, 100, 50, 50, 10, 10); | |
39 sys.puts(mb_rt.paint_radial_new); | |
40 var paint = mb_rt.paint_radial_new(175, 125, 25); | |
41 paint.set_stops([[0, 0, 1, 0, 1], [1, 0, 0, 1, 1]]); | |
42 paint.fill(rect); | |
43 root.add_shape(rect); | |
44 | |
45 /* test alpha blending and rectangle */ | |
46 var rect = mb_rt.rect_new(40, 40, 100, 100, 10, 10); | |
47 sys.puts(mb_rt.paint_color_new); | |
48 var paint = mb_rt.paint_color_new(1, 0.5, 0.5, 0.5); | |
49 paint.fill(rect); | |
50 root.add_shape(rect); | |
51 | |
52 /* test hide of shapes */ | |
53 var sw = 1; | |
54 setInterval(function() { | |
55 if(sw) { | |
56 rect.hide(); | |
57 sw = 0; | |
58 } else { | |
59 rect.show(); | |
60 sw = 1; | |
61 } | |
62 }, 1000); | |
63 | |
64 /* test hide of coord */ | |
65 var cw = 1; | |
66 setInterval(function() { | |
67 if(sw) { | |
68 coord.hide(); | |
69 cw = 0; | |
70 } else { | |
71 coord.show(); | |
72 cw = 1; | |
73 } | |
74 }, 3000); | |
75 | |
76 /* test removing a coord */ | |
77 var rm_coord = mb_rt.coord_new(root); | |
78 var rm_rect1 = mb_rt.rect_new(150, 150, 50, 50, 10, 10); | |
79 paint.fill(rm_rect1); | |
80 rm_coord.add_shape(rm_rect1); | |
81 var rm_rect2 = mb_rt.rect_new(100, 150, 50, 50, 10, 10); | |
82 paint.fill(rm_rect2); | |
83 rm_coord.add_shape(rm_rect2); | |
84 setTimeout(function() { | |
85 rm_coord.remove(); | |
86 mb_rt.redraw_changed(); | |
87 mb_rt.flush(); | |
88 }, 3000); | |
89 | |
90 /* test removing a shape */ | |
91 setTimeout(function() { | |
92 rm_rect1.remove(); | |
93 mb_rt.redraw_changed(); | |
94 mb_rt.flush(); | |
95 }, 2000); | |
96 | |
97 /* Moving a path */ | |
98 sys.puts(mb_rt.path_new); | |
99 var path = mb_rt.path_new("m 100,50 L 120,50 L 200,150 L 180,150 z"); | |
100 sys.puts(path); | |
101 sys.puts(coord.add_shape); | |
102 coord.add_shape(path); | |
103 | |
104 sys.puts(mb_rt.paint_color_new); | |
105 var paint = mb_rt.paint_color_new(1, 1, 1, 1); | |
106 sys.puts(paint); | |
107 paint.stroke(path); | |
108 | |
109 sys.puts(path.stroke_width); | |
110 path.stroke_width = 2; | |
111 sys.puts(path.stroke_width); | |
112 | |
113 var face = mb_rt.font_face_query("courier", 2, 100); | |
114 var blks = [[5, face, 20]]; | |
115 var stext = mb_rt.stext_new("Hello", 100, 50); | |
116 stext.set_style(blks); | |
117 paint.fill(stext); | |
118 coord.add_shape(stext); | |
119 | |
120 mb_rt.redraw_all(); | |
121 mb_rt.flush(); | |
122 | |
123 var i = 0; | |
124 setInterval(function() { | |
125 var deg = (i++) * 0.1; | |
126 coord[2] = (i % 40) * 5; | |
127 mb_rt.redraw_changed(); | |
128 mb_rt.flush(); | |
129 }, 20); | |
130 setTimeout(function() { sys.puts("timeout"); }, 1000); | |
131 | |
132 sys.puts(root.mouse_event); | |
133 var observer; | |
134 /* Mouse button pressed */ | |
135 observer = root.mouse_event.add_event_observer(4, function(evt) { | |
136 var c = 1 - (i % 40) / 40; | |
137 sys.puts(c); | |
138 | |
139 sys.puts("mouse " + evt.x + " " + evt.y); | |
140 sys.puts(c); | |
141 sys.puts(paint.set_color); | |
142 paint.set_color(c, 1, 1, 1); | |
143 mb_rt.redraw_changed(); | |
144 mb_rt.flush(); | |
145 }); | |
146 | |
147 var resize_sw = 0; | |
148 setInterval(function() { | |
149 var sz; | |
150 | |
151 resize_sw++; | |
152 | |
153 sz = (resize_sw % 20) - 10; | |
154 if(sz < 0) | |
155 sz = -sz; | |
156 sz = 2 - sz / 10; | |
157 | |
158 img_coord[0] = sz; | |
159 img_coord[4] = sz; | |
160 mb_rt.redraw_changed(); | |
161 mb_rt.flush(); | |
162 }, 50); | |
163 | |
164 var kbobserver; | |
165 /* Keyboard event */ | |
166 kbobserver = mb_rt.kbevents.add_event_observer(6, function(evt) { | |
167 sys.puts("keycode = " + evt.keycode); | |
168 sys.puts("sym = " + evt.sym); | |
169 }); |