annotate nodejs/testcase.js @ 880:ac3e8492ad74 abs_n_rel_center

Formalize path data for MadButterfly. Inkscape and other editors would omit 'l' or 'L' after 'm' or 'M'. MadButterfly can not handle it, now. So, we work around it at SVG parser.
author Thinker K.F. Li <thinker@codemud.net>
date Sat, 25 Sep 2010 18:46:37 +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: 781
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: 781
diff changeset
2 // vim: sw=4:ts=8:sts=4
549
6ec4d7e90480 Nodejs testcase in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
3 var mbfly = require("mbfly");
6ec4d7e90480 Nodejs testcase in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
4 var r = mbfly.Hello(" test");
6ec4d7e90480 Nodejs testcase in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
5 var sys = require("sys");
6ec4d7e90480 Nodejs testcase in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
6 sys.puts(r);
6ec4d7e90480 Nodejs testcase in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
7
756
cceac4ba259e Support drawing at root window for X Window
Thinker K.F. Li <thinker@codemud.net>
parents: 749
diff changeset
8 var display_name = ":0.0";
781
9367508842b2 testcase.js accept argument from command line
Thinker K.F. Li <thinker@codemud.net>
parents: 778
diff changeset
9 if(process.argv.length == 3)
9367508842b2 testcase.js accept argument from command line
Thinker K.F. Li <thinker@codemud.net>
parents: 778
diff changeset
10 display_name = process.argv[2];
756
cceac4ba259e Support drawing at root window for X Window
Thinker K.F. Li <thinker@codemud.net>
parents: 749
diff changeset
11
cceac4ba259e Support drawing at root window for X Window
Thinker K.F. Li <thinker@codemud.net>
parents: 749
diff changeset
12 var mb_rt = new mbfly.mb_rt(display_name, 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
13 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
14 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
15 [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
16 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
17 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
18 [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
19
643
a65720721c60 Fix issue of exception of internal field.
Thinker K.F. Li <thinker@branda.to>
parents: 624
diff changeset
20 /* Testcase for image shapes */
a65720721c60 Fix issue of exception of internal field.
Thinker K.F. Li <thinker@branda.to>
parents: 624
diff changeset
21 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
22 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
23 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
24 var paint = mb_rt.paint_image_new(img_data);
778
61c217f8cec8 Fix bug of transformation from user space to image space.
Thinker K.F. Li <thinker@codemud.net>
parents: 756
diff changeset
25 var img_coord = mb_rt.coord_new(root);
643
a65720721c60 Fix issue of exception of internal field.
Thinker K.F. Li <thinker@branda.to>
parents: 624
diff changeset
26 paint.fill(img);
778
61c217f8cec8 Fix bug of transformation from user space to image space.
Thinker K.F. Li <thinker@codemud.net>
parents: 756
diff changeset
27 img_coord.add_shape(img);
643
a65720721c60 Fix issue of exception of internal field.
Thinker K.F. Li <thinker@branda.to>
parents: 624
diff changeset
28
734
5ac257be7bc0 Testcase for linear and radial paint for JS
Thinker K.F. Li <thinker@branda.to>
parents: 733
diff changeset
29 /* 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
30 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
31 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
32 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
33 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
34 paint.fill(rect);
5ac257be7bc0 Testcase for linear and radial paint for JS
Thinker K.F. Li <thinker@branda.to>
parents: 733
diff changeset
35 root.add_shape(rect);
5ac257be7bc0 Testcase for linear and radial paint for JS
Thinker K.F. Li <thinker@branda.to>
parents: 733
diff changeset
36
5ac257be7bc0 Testcase for linear and radial paint for JS
Thinker K.F. Li <thinker@branda.to>
parents: 733
diff changeset
37 /* 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
38 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
39 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
40 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
41 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
42 paint.fill(rect);
5ac257be7bc0 Testcase for linear and radial paint for JS
Thinker K.F. Li <thinker@branda.to>
parents: 733
diff changeset
43 root.add_shape(rect);
5ac257be7bc0 Testcase for linear and radial paint for JS
Thinker K.F. Li <thinker@branda.to>
parents: 733
diff changeset
44
690
86c6ebf1de25 Add JS binding for sh_rect_t
Thinker K.F. Li <thinker@branda.to>
parents: 681
diff changeset
45 /* test alpha blending and rectangle */
86c6ebf1de25 Add JS binding for sh_rect_t
Thinker K.F. Li <thinker@branda.to>
parents: 681
diff changeset
46 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
47 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
48 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
49 paint.fill(rect);
86c6ebf1de25 Add JS binding for sh_rect_t
Thinker K.F. Li <thinker@branda.to>
parents: 681
diff changeset
50 root.add_shape(rect);
86c6ebf1de25 Add JS binding for sh_rect_t
Thinker K.F. Li <thinker@branda.to>
parents: 681
diff changeset
51
749
ed59e659a202 Implement binding for hide/show for shapes and coords
Thinker K.F. Li <thinker@codemud.net>
parents: 748
diff changeset
52 /* test hide of shapes */
ed59e659a202 Implement binding for hide/show for shapes and coords
Thinker K.F. Li <thinker@codemud.net>
parents: 748
diff changeset
53 var sw = 1;
ed59e659a202 Implement binding for hide/show for shapes and coords
Thinker K.F. Li <thinker@codemud.net>
parents: 748
diff changeset
54 setInterval(function() {
ed59e659a202 Implement binding for hide/show for shapes and coords
Thinker K.F. Li <thinker@codemud.net>
parents: 748
diff changeset
55 if(sw) {
ed59e659a202 Implement binding for hide/show for shapes and coords
Thinker K.F. Li <thinker@codemud.net>
parents: 748
diff changeset
56 rect.hide();
ed59e659a202 Implement binding for hide/show for shapes and coords
Thinker K.F. Li <thinker@codemud.net>
parents: 748
diff changeset
57 sw = 0;
ed59e659a202 Implement binding for hide/show for shapes and coords
Thinker K.F. Li <thinker@codemud.net>
parents: 748
diff changeset
58 } else {
ed59e659a202 Implement binding for hide/show for shapes and coords
Thinker K.F. Li <thinker@codemud.net>
parents: 748
diff changeset
59 rect.show();
ed59e659a202 Implement binding for hide/show for shapes and coords
Thinker K.F. Li <thinker@codemud.net>
parents: 748
diff changeset
60 sw = 1;
ed59e659a202 Implement binding for hide/show for shapes and coords
Thinker K.F. Li <thinker@codemud.net>
parents: 748
diff changeset
61 }
ed59e659a202 Implement binding for hide/show for shapes and coords
Thinker K.F. Li <thinker@codemud.net>
parents: 748
diff changeset
62 }, 1000);
ed59e659a202 Implement binding for hide/show for shapes and coords
Thinker K.F. Li <thinker@codemud.net>
parents: 748
diff changeset
63
ed59e659a202 Implement binding for hide/show for shapes and coords
Thinker K.F. Li <thinker@codemud.net>
parents: 748
diff changeset
64 /* test hide of coord */
ed59e659a202 Implement binding for hide/show for shapes and coords
Thinker K.F. Li <thinker@codemud.net>
parents: 748
diff changeset
65 var cw = 1;
ed59e659a202 Implement binding for hide/show for shapes and coords
Thinker K.F. Li <thinker@codemud.net>
parents: 748
diff changeset
66 setInterval(function() {
ed59e659a202 Implement binding for hide/show for shapes and coords
Thinker K.F. Li <thinker@codemud.net>
parents: 748
diff changeset
67 if(sw) {
ed59e659a202 Implement binding for hide/show for shapes and coords
Thinker K.F. Li <thinker@codemud.net>
parents: 748
diff changeset
68 coord.hide();
ed59e659a202 Implement binding for hide/show for shapes and coords
Thinker K.F. Li <thinker@codemud.net>
parents: 748
diff changeset
69 cw = 0;
ed59e659a202 Implement binding for hide/show for shapes and coords
Thinker K.F. Li <thinker@codemud.net>
parents: 748
diff changeset
70 } else {
ed59e659a202 Implement binding for hide/show for shapes and coords
Thinker K.F. Li <thinker@codemud.net>
parents: 748
diff changeset
71 coord.show();
ed59e659a202 Implement binding for hide/show for shapes and coords
Thinker K.F. Li <thinker@codemud.net>
parents: 748
diff changeset
72 cw = 1;
ed59e659a202 Implement binding for hide/show for shapes and coords
Thinker K.F. Li <thinker@codemud.net>
parents: 748
diff changeset
73 }
ed59e659a202 Implement binding for hide/show for shapes and coords
Thinker K.F. Li <thinker@codemud.net>
parents: 748
diff changeset
74 }, 3000);
ed59e659a202 Implement binding for hide/show for shapes and coords
Thinker K.F. Li <thinker@codemud.net>
parents: 748
diff changeset
75
742
24038e7a365b Reorder instructions to invalidate coords correctly
Thinker K.F. Li <thinker@codemud.net>
parents: 734
diff changeset
76 /* test removing a coord */
24038e7a365b Reorder instructions to invalidate coords correctly
Thinker K.F. Li <thinker@codemud.net>
parents: 734
diff changeset
77 var rm_coord = mb_rt.coord_new(root);
748
56a5e08cd8af Make shapes can be removed from the tree
Thinker K.F. Li <thinker@codemud.net>
parents: 743
diff changeset
78 var rm_rect1 = mb_rt.rect_new(150, 150, 50, 50, 10, 10);
56a5e08cd8af Make shapes can be removed from the tree
Thinker K.F. Li <thinker@codemud.net>
parents: 743
diff changeset
79 paint.fill(rm_rect1);
56a5e08cd8af Make shapes can be removed from the tree
Thinker K.F. Li <thinker@codemud.net>
parents: 743
diff changeset
80 rm_coord.add_shape(rm_rect1);
56a5e08cd8af Make shapes can be removed from the tree
Thinker K.F. Li <thinker@codemud.net>
parents: 743
diff changeset
81 var rm_rect2 = mb_rt.rect_new(100, 150, 50, 50, 10, 10);
56a5e08cd8af Make shapes can be removed from the tree
Thinker K.F. Li <thinker@codemud.net>
parents: 743
diff changeset
82 paint.fill(rm_rect2);
56a5e08cd8af Make shapes can be removed from the tree
Thinker K.F. Li <thinker@codemud.net>
parents: 743
diff changeset
83 rm_coord.add_shape(rm_rect2);
743
dd1f3382d6a4 Create a persistent handle for coords and shapes correctly
Thinker K.F. Li <thinker@codemud.net>
parents: 742
diff changeset
84 setTimeout(function() {
dd1f3382d6a4 Create a persistent handle for coords and shapes correctly
Thinker K.F. Li <thinker@codemud.net>
parents: 742
diff changeset
85 rm_coord.remove();
dd1f3382d6a4 Create a persistent handle for coords and shapes correctly
Thinker K.F. Li <thinker@codemud.net>
parents: 742
diff changeset
86 mb_rt.redraw_changed();
dd1f3382d6a4 Create a persistent handle for coords and shapes correctly
Thinker K.F. Li <thinker@codemud.net>
parents: 742
diff changeset
87 mb_rt.flush();
dd1f3382d6a4 Create a persistent handle for coords and shapes correctly
Thinker K.F. Li <thinker@codemud.net>
parents: 742
diff changeset
88 }, 3000);
742
24038e7a365b Reorder instructions to invalidate coords correctly
Thinker K.F. Li <thinker@codemud.net>
parents: 734
diff changeset
89
748
56a5e08cd8af Make shapes can be removed from the tree
Thinker K.F. Li <thinker@codemud.net>
parents: 743
diff changeset
90 /* test removing a shape */
56a5e08cd8af Make shapes can be removed from the tree
Thinker K.F. Li <thinker@codemud.net>
parents: 743
diff changeset
91 setTimeout(function() {
56a5e08cd8af Make shapes can be removed from the tree
Thinker K.F. Li <thinker@codemud.net>
parents: 743
diff changeset
92 rm_rect1.remove();
56a5e08cd8af Make shapes can be removed from the tree
Thinker K.F. Li <thinker@codemud.net>
parents: 743
diff changeset
93 mb_rt.redraw_changed();
56a5e08cd8af Make shapes can be removed from the tree
Thinker K.F. Li <thinker@codemud.net>
parents: 743
diff changeset
94 mb_rt.flush();
56a5e08cd8af Make shapes can be removed from the tree
Thinker K.F. Li <thinker@codemud.net>
parents: 743
diff changeset
95 }, 2000);
56a5e08cd8af Make shapes can be removed from the tree
Thinker K.F. Li <thinker@codemud.net>
parents: 743
diff changeset
96
644
c9f8c7e6f57e Add comment
Thinker K.F. Li <thinker@branda.to>
parents: 643
diff changeset
97 /* Moving a path */
565
c0bc60448913 Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents: 563
diff changeset
98 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
99 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
100 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
101 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
102 coord.add_shape(path);
565
c0bc60448913 Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents: 563
diff changeset
103
567
a12c3448afb6 Add dummy paint_color templates
Thinker K.F. Li <thinker@branda.to>
parents: 566
diff changeset
104 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
105 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
106 sys.puts(paint);
569
f87a368e847a Functions of stroke and fill a shape
Thinker K.F. Li <thinker@branda.to>
parents: 568
diff changeset
107 paint.stroke(path);
567
a12c3448afb6 Add dummy paint_color templates
Thinker K.F. Li <thinker@branda.to>
parents: 566
diff changeset
108
570
49e79253b6d3 Functions of setting/getting stroke width of a shape
Thinker K.F. Li <thinker@branda.to>
parents: 569
diff changeset
109 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
110 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
111 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
112
576
5a68e2bcea17 Set font styles for stext in Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 574
diff changeset
113 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
114 var blks = [[5, face, 20]];
5a68e2bcea17 Set font styles for stext in Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 574
diff changeset
115 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
116 stext.set_style(blks);
5a68e2bcea17 Set font styles for stext in Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 574
diff changeset
117 paint.fill(stext);
5a68e2bcea17 Set font styles for stext in Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 574
diff changeset
118 coord.add_shape(stext);
5a68e2bcea17 Set font styles for stext in Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 574
diff changeset
119
571
13b15b7a463b Redraw all and changed in Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 570
diff changeset
120 mb_rt.redraw_all();
704
d950487bd9f9 Flush mb_rt, immediately, after redraw_all()
Thinker K.F. Li <thinker@branda.to>
parents: 699
diff changeset
121 mb_rt.flush();
571
13b15b7a463b Redraw all and changed in Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 570
diff changeset
122
13b15b7a463b Redraw all and changed in Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 570
diff changeset
123 var i = 0;
13b15b7a463b Redraw all and changed in Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 570
diff changeset
124 setInterval(function() {
13b15b7a463b Redraw all and changed in Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 570
diff changeset
125 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
126 coord[2] = (i % 40) * 5;
571
13b15b7a463b Redraw all and changed in Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 570
diff changeset
127 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
128 mb_rt.flush();
624
d45c928f6523 Add SVG parser sample code.
wycc
parents: 576
diff changeset
129 }, 20);
549
6ec4d7e90480 Nodejs testcase in Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
130 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
131
680
a588eefd3f04 Refactor to xnjsmb_coord_mod().
Thinker K.F. Li <thinker@branda.to>
parents: 679
diff changeset
132 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
133 var observer;
f264b50c469c Bind subject of mouse_event to JS object of coord
Thinker K.F. Li <thinker@branda.to>
parents: 644
diff changeset
134 /* Mouse button pressed */
680
a588eefd3f04 Refactor to xnjsmb_coord_mod().
Thinker K.F. Li <thinker@branda.to>
parents: 679
diff changeset
135 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
136 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
137 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
138
679
799c852b9065 Extract event info from C object to JS object
Thinker K.F. Li <thinker@branda.to>
parents: 676
diff changeset
139 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
140 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
141 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
142 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
143 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
144 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
145 });
679
799c852b9065 Extract event info from C object to JS object
Thinker K.F. Li <thinker@branda.to>
parents: 676
diff changeset
146
778
61c217f8cec8 Fix bug of transformation from user space to image space.
Thinker K.F. Li <thinker@codemud.net>
parents: 756
diff changeset
147 var resize_sw = 0;
61c217f8cec8 Fix bug of transformation from user space to image space.
Thinker K.F. Li <thinker@codemud.net>
parents: 756
diff changeset
148 setInterval(function() {
61c217f8cec8 Fix bug of transformation from user space to image space.
Thinker K.F. Li <thinker@codemud.net>
parents: 756
diff changeset
149 var sz;
61c217f8cec8 Fix bug of transformation from user space to image space.
Thinker K.F. Li <thinker@codemud.net>
parents: 756
diff changeset
150
61c217f8cec8 Fix bug of transformation from user space to image space.
Thinker K.F. Li <thinker@codemud.net>
parents: 756
diff changeset
151 resize_sw++;
61c217f8cec8 Fix bug of transformation from user space to image space.
Thinker K.F. Li <thinker@codemud.net>
parents: 756
diff changeset
152
61c217f8cec8 Fix bug of transformation from user space to image space.
Thinker K.F. Li <thinker@codemud.net>
parents: 756
diff changeset
153 sz = (resize_sw % 20) - 10;
61c217f8cec8 Fix bug of transformation from user space to image space.
Thinker K.F. Li <thinker@codemud.net>
parents: 756
diff changeset
154 if(sz < 0)
61c217f8cec8 Fix bug of transformation from user space to image space.
Thinker K.F. Li <thinker@codemud.net>
parents: 756
diff changeset
155 sz = -sz;
61c217f8cec8 Fix bug of transformation from user space to image space.
Thinker K.F. Li <thinker@codemud.net>
parents: 756
diff changeset
156 sz = 2 - sz / 10;
61c217f8cec8 Fix bug of transformation from user space to image space.
Thinker K.F. Li <thinker@codemud.net>
parents: 756
diff changeset
157
61c217f8cec8 Fix bug of transformation from user space to image space.
Thinker K.F. Li <thinker@codemud.net>
parents: 756
diff changeset
158 img_coord[0] = sz;
61c217f8cec8 Fix bug of transformation from user space to image space.
Thinker K.F. Li <thinker@codemud.net>
parents: 756
diff changeset
159 img_coord[4] = sz;
61c217f8cec8 Fix bug of transformation from user space to image space.
Thinker K.F. Li <thinker@codemud.net>
parents: 756
diff changeset
160 mb_rt.redraw_changed();
61c217f8cec8 Fix bug of transformation from user space to image space.
Thinker K.F. Li <thinker@codemud.net>
parents: 756
diff changeset
161 mb_rt.flush();
61c217f8cec8 Fix bug of transformation from user space to image space.
Thinker K.F. Li <thinker@codemud.net>
parents: 756
diff changeset
162 }, 50);
61c217f8cec8 Fix bug of transformation from user space to image space.
Thinker K.F. Li <thinker@codemud.net>
parents: 756
diff changeset
163
679
799c852b9065 Extract event info from C object to JS object
Thinker K.F. Li <thinker@branda.to>
parents: 676
diff changeset
164 var kbobserver;
799c852b9065 Extract event info from C object to JS object
Thinker K.F. Li <thinker@branda.to>
parents: 676
diff changeset
165 /* Keyboard event */
681
b601a4d6f7d1 Change kbevent to kbevents and hide X_MB_kbevents()
Thinker K.F. Li <thinker@branda.to>
parents: 680
diff changeset
166 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
167 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
168 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
169 });