annotate nodejs/shapes.cc @ 1401:2fc1f54a1a3b

Mainly fix the clone_from_subtree to update the children of the parent node. We need to clearify all related codes in the future to make the logic more clear.
author wycc
date Sun, 03 Apr 2011 18:12:42 +0800
parents df6ee4568ca2
children
rev   line source
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 780
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: 780
diff changeset
2 // vim: sw=4:ts=8:sts=4
564
0cd1511272d2 Make base type for shapes.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
3 #include <v8.h>
0cd1511272d2 Make base type for shapes.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
4 #include "mbfly_njs.h"
0cd1511272d2 Make base type for shapes.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
5
683
7685c57e29d0 Migrate JS shapes binding to gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 675
diff changeset
6 #include <string.h>
7685c57e29d0 Migrate JS shapes binding to gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 675
diff changeset
7
564
0cd1511272d2 Make base type for shapes.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
8 extern "C" {
0cd1511272d2 Make base type for shapes.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
9 #include <mb.h>
0cd1511272d2 Make base type for shapes.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
10 }
0cd1511272d2 Make base type for shapes.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
11
570
49e79253b6d3 Functions of setting/getting stroke width of a shape
Thinker K.F. Li <thinker@branda.to>
parents: 569
diff changeset
12 #ifndef ASSERT
49e79253b6d3 Functions of setting/getting stroke width of a shape
Thinker K.F. Li <thinker@branda.to>
parents: 569
diff changeset
13 #define ASSERT(x)
49e79253b6d3 Functions of setting/getting stroke width of a shape
Thinker K.F. Li <thinker@branda.to>
parents: 569
diff changeset
14 #endif
49e79253b6d3 Functions of setting/getting stroke width of a shape
Thinker K.F. Li <thinker@branda.to>
parents: 569
diff changeset
15
748
56a5e08cd8af Make shapes can be removed from the tree
Thinker K.F. Li <thinker@codemud.net>
parents: 743
diff changeset
16 #define OK 0
56a5e08cd8af Make shapes can be removed from the tree
Thinker K.F. Li <thinker@codemud.net>
parents: 743
diff changeset
17
564
0cd1511272d2 Make base type for shapes.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
18 using namespace v8;
0cd1511272d2 Make base type for shapes.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
19
684
b346e4699e55 Add more comment for JS binding
Thinker K.F. Li <thinker@branda.to>
parents: 683
diff changeset
20 /*! \defgroup xnjsmb_shapes JS binding for shapes.
683
7685c57e29d0 Migrate JS shapes binding to gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 675
diff changeset
21 * \ingroup xnjsmb
564
0cd1511272d2 Make base type for shapes.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
22 *
0cd1511272d2 Make base type for shapes.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
23 * @{
0cd1511272d2 Make base type for shapes.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
24 */
748
56a5e08cd8af Make shapes can be removed from the tree
Thinker K.F. Li <thinker@codemud.net>
parents: 743
diff changeset
25 /*! \brief This function is called when GC collecting a shape.
56a5e08cd8af Make shapes can be removed from the tree
Thinker K.F. Li <thinker@codemud.net>
parents: 743
diff changeset
26 *
56a5e08cd8af Make shapes can be removed from the tree
Thinker K.F. Li <thinker@codemud.net>
parents: 743
diff changeset
27 * It was installed by Persistent<Object>::MakeWeak().
56a5e08cd8af Make shapes can be removed from the tree
Thinker K.F. Li <thinker@codemud.net>
parents: 743
diff changeset
28 */
56a5e08cd8af Make shapes can be removed from the tree
Thinker K.F. Li <thinker@codemud.net>
parents: 743
diff changeset
29 static void
56a5e08cd8af Make shapes can be removed from the tree
Thinker K.F. Li <thinker@codemud.net>
parents: 743
diff changeset
30 xnjsmb_shape_recycled(Persistent<Value> obj, void *parameter) {
56a5e08cd8af Make shapes can be removed from the tree
Thinker K.F. Li <thinker@codemud.net>
parents: 743
diff changeset
31 Persistent<Object> *self_hdl = (Persistent<Object> *)parameter;
56a5e08cd8af Make shapes can be removed from the tree
Thinker K.F. Li <thinker@codemud.net>
parents: 743
diff changeset
32 Handle<Object> js_rt;
56a5e08cd8af Make shapes can be removed from the tree
Thinker K.F. Li <thinker@codemud.net>
parents: 743
diff changeset
33 redraw_man_t *rdman;
56a5e08cd8af Make shapes can be removed from the tree
Thinker K.F. Li <thinker@codemud.net>
parents: 743
diff changeset
34 shape_t *shape;
56a5e08cd8af Make shapes can be removed from the tree
Thinker K.F. Li <thinker@codemud.net>
parents: 743
diff changeset
35
56a5e08cd8af Make shapes can be removed from the tree
Thinker K.F. Li <thinker@codemud.net>
parents: 743
diff changeset
36 shape = (shape_t *)UNWRAP(*self_hdl);
56a5e08cd8af Make shapes can be removed from the tree
Thinker K.F. Li <thinker@codemud.net>
parents: 743
diff changeset
37 if(shape == NULL)
56a5e08cd8af Make shapes can be removed from the tree
Thinker K.F. Li <thinker@codemud.net>
parents: 743
diff changeset
38 return;
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 780
diff changeset
39
748
56a5e08cd8af Make shapes can be removed from the tree
Thinker K.F. Li <thinker@codemud.net>
parents: 743
diff changeset
40 WRAP(*self_hdl, NULL);
56a5e08cd8af Make shapes can be removed from the tree
Thinker K.F. Li <thinker@codemud.net>
parents: 743
diff changeset
41
56a5e08cd8af Make shapes can be removed from the tree
Thinker K.F. Li <thinker@codemud.net>
parents: 743
diff changeset
42 js_rt = GET(*self_hdl, "mbrt")->ToObject();
56a5e08cd8af Make shapes can be removed from the tree
Thinker K.F. Li <thinker@codemud.net>
parents: 743
diff changeset
43 rdman = xnjsmb_rt_rdman(js_rt);
56a5e08cd8af Make shapes can be removed from the tree
Thinker K.F. Li <thinker@codemud.net>
parents: 743
diff changeset
44 rdman_shape_changed(rdman, shape);
56a5e08cd8af Make shapes can be removed from the tree
Thinker K.F. Li <thinker@codemud.net>
parents: 743
diff changeset
45 rdman_shape_free(rdman, shape);
764
194e24d8ecab Delete weak handle for shape objects before GC
Thinker K.F. Li <thinker@codemud.net>
parents: 749
diff changeset
46
766
be0e02948c1d Improve resource management for coords, shapes and paints.
Thinker K.F. Li <thinker@codemud.net>
parents: 764
diff changeset
47 self_hdl->Dispose();
764
194e24d8ecab Delete weak handle for shape objects before GC
Thinker K.F. Li <thinker@codemud.net>
parents: 749
diff changeset
48 delete self_hdl;
748
56a5e08cd8af Make shapes can be removed from the tree
Thinker K.F. Li <thinker@codemud.net>
parents: 743
diff changeset
49 }
56a5e08cd8af Make shapes can be removed from the tree
Thinker K.F. Li <thinker@codemud.net>
parents: 743
diff changeset
50
683
7685c57e29d0 Migrate JS shapes binding to gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 675
diff changeset
51 static void
743
dd1f3382d6a4 Create a persistent handle for coords and shapes correctly
Thinker K.F. Li <thinker@codemud.net>
parents: 690
diff changeset
52 xnjsmb_shape_mod(Handle<Object> self, shape_t *sh) {
dd1f3382d6a4 Create a persistent handle for coords and shapes correctly
Thinker K.F. Li <thinker@codemud.net>
parents: 690
diff changeset
53 Persistent<Object> *self_hdl;
766
be0e02948c1d Improve resource management for coords, shapes and paints.
Thinker K.F. Li <thinker@codemud.net>
parents: 764
diff changeset
54 static int count = 0;
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 780
diff changeset
55
743
dd1f3382d6a4 Create a persistent handle for coords and shapes correctly
Thinker K.F. Li <thinker@codemud.net>
parents: 690
diff changeset
56 /* Keep associated js object in property store for retrieving,
dd1f3382d6a4 Create a persistent handle for coords and shapes correctly
Thinker K.F. Li <thinker@codemud.net>
parents: 690
diff changeset
57 * later, without create new js object.
dd1f3382d6a4 Create a persistent handle for coords and shapes correctly
Thinker K.F. Li <thinker@codemud.net>
parents: 690
diff changeset
58 */
dd1f3382d6a4 Create a persistent handle for coords and shapes correctly
Thinker K.F. Li <thinker@codemud.net>
parents: 690
diff changeset
59 self_hdl = new Persistent<Object>();
dd1f3382d6a4 Create a persistent handle for coords and shapes correctly
Thinker K.F. Li <thinker@codemud.net>
parents: 690
diff changeset
60 *self_hdl = Persistent<Object>::New(self);
dd1f3382d6a4 Create a persistent handle for coords and shapes correctly
Thinker K.F. Li <thinker@codemud.net>
parents: 690
diff changeset
61 mb_prop_set(&sh->obj.props, PROP_JSOBJ, self_hdl);
748
56a5e08cd8af Make shapes can be removed from the tree
Thinker K.F. Li <thinker@codemud.net>
parents: 743
diff changeset
62
56a5e08cd8af Make shapes can be removed from the tree
Thinker K.F. Li <thinker@codemud.net>
parents: 743
diff changeset
63 self_hdl->MakeWeak(self_hdl, xnjsmb_shape_recycled);
766
be0e02948c1d Improve resource management for coords, shapes and paints.
Thinker K.F. Li <thinker@codemud.net>
parents: 764
diff changeset
64
be0e02948c1d Improve resource management for coords, shapes and paints.
Thinker K.F. Li <thinker@codemud.net>
parents: 764
diff changeset
65 /* XXX: should be remove. It is for trace recycle of shape */
be0e02948c1d Improve resource management for coords, shapes and paints.
Thinker K.F. Li <thinker@codemud.net>
parents: 764
diff changeset
66 count++;
be0e02948c1d Improve resource management for coords, shapes and paints.
Thinker K.F. Li <thinker@codemud.net>
parents: 764
diff changeset
67 if(count > 10000) {
be0e02948c1d Improve resource management for coords, shapes and paints.
Thinker K.F. Li <thinker@codemud.net>
parents: 764
diff changeset
68 V8::LowMemoryNotification();
be0e02948c1d Improve resource management for coords, shapes and paints.
Thinker K.F. Li <thinker@codemud.net>
parents: 764
diff changeset
69 count = 0;
be0e02948c1d Improve resource management for coords, shapes and paints.
Thinker K.F. Li <thinker@codemud.net>
parents: 764
diff changeset
70 }
743
dd1f3382d6a4 Create a persistent handle for coords and shapes correctly
Thinker K.F. Li <thinker@codemud.net>
parents: 690
diff changeset
71 }
dd1f3382d6a4 Create a persistent handle for coords and shapes correctly
Thinker K.F. Li <thinker@codemud.net>
parents: 690
diff changeset
72
885
2b492008ce26 Told redraw manager that a text is dirty when change its text at JS
Thinker K.F. Li <thinker@codemud.net>
parents: 822
diff changeset
73 static void
2b492008ce26 Told redraw manager that a text is dirty when change its text at JS
Thinker K.F. Li <thinker@codemud.net>
parents: 822
diff changeset
74 xnjsmb_sh_stext_set_text(shape_t *sh, Handle<Object> self,
2b492008ce26 Told redraw manager that a text is dirty when change its text at JS
Thinker K.F. Li <thinker@codemud.net>
parents: 822
diff changeset
75 const char *txt) {
2b492008ce26 Told redraw manager that a text is dirty when change its text at JS
Thinker K.F. Li <thinker@codemud.net>
parents: 822
diff changeset
76 Handle<Object> rt;
2b492008ce26 Told redraw manager that a text is dirty when change its text at JS
Thinker K.F. Li <thinker@codemud.net>
parents: 822
diff changeset
77 redraw_man_t *rdman;
2b492008ce26 Told redraw manager that a text is dirty when change its text at JS
Thinker K.F. Li <thinker@codemud.net>
parents: 822
diff changeset
78
2b492008ce26 Told redraw manager that a text is dirty when change its text at JS
Thinker K.F. Li <thinker@codemud.net>
parents: 822
diff changeset
79 sh_stext_set_text(sh, txt);
2b492008ce26 Told redraw manager that a text is dirty when change its text at JS
Thinker K.F. Li <thinker@codemud.net>
parents: 822
diff changeset
80
2b492008ce26 Told redraw manager that a text is dirty when change its text at JS
Thinker K.F. Li <thinker@codemud.net>
parents: 822
diff changeset
81 /*
2b492008ce26 Told redraw manager that a text is dirty when change its text at JS
Thinker K.F. Li <thinker@codemud.net>
parents: 822
diff changeset
82 * Mark changed.
2b492008ce26 Told redraw manager that a text is dirty when change its text at JS
Thinker K.F. Li <thinker@codemud.net>
parents: 822
diff changeset
83 */
2b492008ce26 Told redraw manager that a text is dirty when change its text at JS
Thinker K.F. Li <thinker@codemud.net>
parents: 822
diff changeset
84 rt = GET(self, "mbrt")->ToObject();
2b492008ce26 Told redraw manager that a text is dirty when change its text at JS
Thinker K.F. Li <thinker@codemud.net>
parents: 822
diff changeset
85 ASSERT(rt != NULL);
2b492008ce26 Told redraw manager that a text is dirty when change its text at JS
Thinker K.F. Li <thinker@codemud.net>
parents: 822
diff changeset
86 rdman = xnjsmb_rt_rdman(rt);
2b492008ce26 Told redraw manager that a text is dirty when change its text at JS
Thinker K.F. Li <thinker@codemud.net>
parents: 822
diff changeset
87
2b492008ce26 Told redraw manager that a text is dirty when change its text at JS
Thinker K.F. Li <thinker@codemud.net>
parents: 822
diff changeset
88 if(sh_get_coord(sh))
2b492008ce26 Told redraw manager that a text is dirty when change its text at JS
Thinker K.F. Li <thinker@codemud.net>
parents: 822
diff changeset
89 rdman_shape_changed(rdman, sh);
2b492008ce26 Told redraw manager that a text is dirty when change its text at JS
Thinker K.F. Li <thinker@codemud.net>
parents: 822
diff changeset
90 }
2b492008ce26 Told redraw manager that a text is dirty when change its text at JS
Thinker K.F. Li <thinker@codemud.net>
parents: 822
diff changeset
91
780
16d8a1d48717 Doc for xnjsmb_sh_stext_set_style
Thinker K.F. Li <thinker@codemud.net>
parents: 767
diff changeset
92 /*! \brief Set style blocks for a stext object from JS.
16d8a1d48717 Doc for xnjsmb_sh_stext_set_style
Thinker K.F. Li <thinker@codemud.net>
parents: 767
diff changeset
93 *
16d8a1d48717 Doc for xnjsmb_sh_stext_set_style
Thinker K.F. Li <thinker@codemud.net>
parents: 767
diff changeset
94 * A style block is style setting of a chip of text. It is a 3-tuple,
16d8a1d48717 Doc for xnjsmb_sh_stext_set_style
Thinker K.F. Li <thinker@codemud.net>
parents: 767
diff changeset
95 * includes number of charaters, a font face, and font size. This
16d8a1d48717 Doc for xnjsmb_sh_stext_set_style
Thinker K.F. Li <thinker@codemud.net>
parents: 767
diff changeset
96 * function need a list of 3-tuples to set style of text chips of the
16d8a1d48717 Doc for xnjsmb_sh_stext_set_style
Thinker K.F. Li <thinker@codemud.net>
parents: 767
diff changeset
97 * stext.
16d8a1d48717 Doc for xnjsmb_sh_stext_set_style
Thinker K.F. Li <thinker@codemud.net>
parents: 767
diff changeset
98 */
743
dd1f3382d6a4 Create a persistent handle for coords and shapes correctly
Thinker K.F. Li <thinker@codemud.net>
parents: 690
diff changeset
99 static void
689
a05a4a27ff46 Fix bug of losting rdman in xnjsmb_sh_stext_set_style
Thinker K.F. Li <thinker@branda.to>
parents: 688
diff changeset
100 xnjsmb_sh_stext_set_style(shape_t *sh, Handle<Object> self,
a05a4a27ff46 Fix bug of losting rdman in xnjsmb_sh_stext_set_style
Thinker K.F. Li <thinker@branda.to>
parents: 688
diff changeset
101 Handle<Value> blks, const char **err) {
683
7685c57e29d0 Migrate JS shapes binding to gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 675
diff changeset
102 Array *blksobj;
7685c57e29d0 Migrate JS shapes binding to gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 675
diff changeset
103 Array *blkobj;
7685c57e29d0 Migrate JS shapes binding to gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 675
diff changeset
104 mb_style_blk_t *mb_blks;
7685c57e29d0 Migrate JS shapes binding to gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 675
diff changeset
105 int nblks;
689
a05a4a27ff46 Fix bug of losting rdman in xnjsmb_sh_stext_set_style
Thinker K.F. Li <thinker@branda.to>
parents: 688
diff changeset
106 Handle<Object> rt;
a05a4a27ff46 Fix bug of losting rdman in xnjsmb_sh_stext_set_style
Thinker K.F. Li <thinker@branda.to>
parents: 688
diff changeset
107 redraw_man_t *rdman;
683
7685c57e29d0 Migrate JS shapes binding to gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 675
diff changeset
108 int r;
7685c57e29d0 Migrate JS shapes binding to gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 675
diff changeset
109 int i;
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 780
diff changeset
110
683
7685c57e29d0 Migrate JS shapes binding to gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 675
diff changeset
111 blksobj = Array::Cast(*blks);
7685c57e29d0 Migrate JS shapes binding to gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 675
diff changeset
112 nblks = blksobj->Length();
7685c57e29d0 Migrate JS shapes binding to gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 675
diff changeset
113 mb_blks = new mb_style_blk_t[nblks];
7685c57e29d0 Migrate JS shapes binding to gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 675
diff changeset
114 for(i = 0; i < nblks; i++) {
7685c57e29d0 Migrate JS shapes binding to gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 675
diff changeset
115 blkobj = Array::Cast(*blksobj->Get(i));
7685c57e29d0 Migrate JS shapes binding to gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 675
diff changeset
116 mb_blks[i].n_chars = blkobj->Get(0)->ToInt32()->Value();
7685c57e29d0 Migrate JS shapes binding to gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 675
diff changeset
117 mb_blks[i].face = (mb_font_face_t *)UNWRAP(blkobj->Get(1)->ToObject());
7685c57e29d0 Migrate JS shapes binding to gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 675
diff changeset
118 mb_blks[i].font_sz = blkobj->Get(2)->ToNumber()->Value();
7685c57e29d0 Migrate JS shapes binding to gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 675
diff changeset
119 }
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 780
diff changeset
120
683
7685c57e29d0 Migrate JS shapes binding to gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 675
diff changeset
121 r = sh_stext_set_style(sh, mb_blks, nblks);
7685c57e29d0 Migrate JS shapes binding to gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 675
diff changeset
122 if(r != 0) {
7685c57e29d0 Migrate JS shapes binding to gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 675
diff changeset
123 *err = "Unknown error";
7685c57e29d0 Migrate JS shapes binding to gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 675
diff changeset
124 return;
7685c57e29d0 Migrate JS shapes binding to gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 675
diff changeset
125 }
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 780
diff changeset
126
689
a05a4a27ff46 Fix bug of losting rdman in xnjsmb_sh_stext_set_style
Thinker K.F. Li <thinker@branda.to>
parents: 688
diff changeset
127 /*
a05a4a27ff46 Fix bug of losting rdman in xnjsmb_sh_stext_set_style
Thinker K.F. Li <thinker@branda.to>
parents: 688
diff changeset
128 * Mark changed.
a05a4a27ff46 Fix bug of losting rdman in xnjsmb_sh_stext_set_style
Thinker K.F. Li <thinker@branda.to>
parents: 688
diff changeset
129 */
a05a4a27ff46 Fix bug of losting rdman in xnjsmb_sh_stext_set_style
Thinker K.F. Li <thinker@branda.to>
parents: 688
diff changeset
130 rt = GET(self, "mbrt")->ToObject();
a05a4a27ff46 Fix bug of losting rdman in xnjsmb_sh_stext_set_style
Thinker K.F. Li <thinker@branda.to>
parents: 688
diff changeset
131 ASSERT(rt != NULL);
a05a4a27ff46 Fix bug of losting rdman in xnjsmb_sh_stext_set_style
Thinker K.F. Li <thinker@branda.to>
parents: 688
diff changeset
132 rdman = xnjsmb_rt_rdman(rt);
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 780
diff changeset
133
688
cadebc13be2f Mark stext changed when its style being changed
Thinker K.F. Li <thinker@branda.to>
parents: 687
diff changeset
134 if(sh_get_coord(sh))
cadebc13be2f Mark stext changed when its style being changed
Thinker K.F. Li <thinker@branda.to>
parents: 687
diff changeset
135 rdman_shape_changed(rdman, sh);
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 780
diff changeset
136
683
7685c57e29d0 Migrate JS shapes binding to gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 675
diff changeset
137 delete mb_blks;
564
0cd1511272d2 Make base type for shapes.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
138 }
0cd1511272d2 Make base type for shapes.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
139
0cd1511272d2 Make base type for shapes.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
140 static Handle<Value>
683
7685c57e29d0 Migrate JS shapes binding to gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 675
diff changeset
141 xnjsmb_shape_stroke_width_get(Handle<Object> self, shape_t *sh,
7685c57e29d0 Migrate JS shapes binding to gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 675
diff changeset
142 const char **err) {
7685c57e29d0 Migrate JS shapes binding to gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 675
diff changeset
143 float stroke_width;
564
0cd1511272d2 Make base type for shapes.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
144
683
7685c57e29d0 Migrate JS shapes binding to gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 675
diff changeset
145 stroke_width = sh_get_stroke_width(sh);
7685c57e29d0 Migrate JS shapes binding to gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 675
diff changeset
146 return Number::New(stroke_width);
564
0cd1511272d2 Make base type for shapes.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
147 }
0cd1511272d2 Make base type for shapes.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
148
683
7685c57e29d0 Migrate JS shapes binding to gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 675
diff changeset
149 static void
7685c57e29d0 Migrate JS shapes binding to gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 675
diff changeset
150 xnjsmb_shape_stroke_width_set(Handle<Object> self, shape_t *sh,
7685c57e29d0 Migrate JS shapes binding to gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 675
diff changeset
151 Handle<Value> value, const char **err) {
7685c57e29d0 Migrate JS shapes binding to gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 675
diff changeset
152 float stroke_width;
7685c57e29d0 Migrate JS shapes binding to gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 675
diff changeset
153 Handle<Object> rt;
7685c57e29d0 Migrate JS shapes binding to gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 675
diff changeset
154 redraw_man_t *rdman;
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 780
diff changeset
155
683
7685c57e29d0 Migrate JS shapes binding to gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 675
diff changeset
156 stroke_width = value->Int32Value();
7685c57e29d0 Migrate JS shapes binding to gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 675
diff changeset
157 sh_set_stroke_width(sh, stroke_width);
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 780
diff changeset
158
570
49e79253b6d3 Functions of setting/getting stroke width of a shape
Thinker K.F. Li <thinker@branda.to>
parents: 569
diff changeset
159 /*
49e79253b6d3 Functions of setting/getting stroke width of a shape
Thinker K.F. Li <thinker@branda.to>
parents: 569
diff changeset
160 * Mark changed.
49e79253b6d3 Functions of setting/getting stroke width of a shape
Thinker K.F. Li <thinker@branda.to>
parents: 569
diff changeset
161 */
49e79253b6d3 Functions of setting/getting stroke width of a shape
Thinker K.F. Li <thinker@branda.to>
parents: 569
diff changeset
162 rt = GET(self, "mbrt")->ToObject();
49e79253b6d3 Functions of setting/getting stroke width of a shape
Thinker K.F. Li <thinker@branda.to>
parents: 569
diff changeset
163 ASSERT(rt != NULL);
49e79253b6d3 Functions of setting/getting stroke width of a shape
Thinker K.F. Li <thinker@branda.to>
parents: 569
diff changeset
164 rdman = xnjsmb_rt_rdman(rt);
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 780
diff changeset
165
576
5a68e2bcea17 Set font styles for stext in Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 574
diff changeset
166 if(sh_get_coord(sh))
5a68e2bcea17 Set font styles for stext in Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 574
diff changeset
167 rdman_shape_changed(rdman, sh);
570
49e79253b6d3 Functions of setting/getting stroke width of a shape
Thinker K.F. Li <thinker@branda.to>
parents: 569
diff changeset
168 }
49e79253b6d3 Functions of setting/getting stroke width of a shape
Thinker K.F. Li <thinker@branda.to>
parents: 569
diff changeset
169
690
86c6ebf1de25 Add JS binding for sh_rect_t
Thinker K.F. Li <thinker@branda.to>
parents: 689
diff changeset
170 static void
749
ed59e659a202 Implement binding for hide/show for shapes and coords
Thinker K.F. Li <thinker@codemud.net>
parents: 748
diff changeset
171 xnjsmb_shape_show(shape_t *sh, Handle<Object> self) {
ed59e659a202 Implement binding for hide/show for shapes and coords
Thinker K.F. Li <thinker@codemud.net>
parents: 748
diff changeset
172 Handle<Object> js_rt;
ed59e659a202 Implement binding for hide/show for shapes and coords
Thinker K.F. Li <thinker@codemud.net>
parents: 748
diff changeset
173 redraw_man_t *rdman;
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 780
diff changeset
174
749
ed59e659a202 Implement binding for hide/show for shapes and coords
Thinker K.F. Li <thinker@codemud.net>
parents: 748
diff changeset
175 js_rt = GET(self, "mbrt")->ToObject();
ed59e659a202 Implement binding for hide/show for shapes and coords
Thinker K.F. Li <thinker@codemud.net>
parents: 748
diff changeset
176 ASSERT(js_rt != NULL);
ed59e659a202 Implement binding for hide/show for shapes and coords
Thinker K.F. Li <thinker@codemud.net>
parents: 748
diff changeset
177 rdman = xnjsmb_rt_rdman(js_rt);
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 780
diff changeset
178
749
ed59e659a202 Implement binding for hide/show for shapes and coords
Thinker K.F. Li <thinker@codemud.net>
parents: 748
diff changeset
179 sh_show(sh);
ed59e659a202 Implement binding for hide/show for shapes and coords
Thinker K.F. Li <thinker@codemud.net>
parents: 748
diff changeset
180 rdman_shape_changed(rdman, sh);
ed59e659a202 Implement binding for hide/show for shapes and coords
Thinker K.F. Li <thinker@codemud.net>
parents: 748
diff changeset
181 }
ed59e659a202 Implement binding for hide/show for shapes and coords
Thinker K.F. Li <thinker@codemud.net>
parents: 748
diff changeset
182
ed59e659a202 Implement binding for hide/show for shapes and coords
Thinker K.F. Li <thinker@codemud.net>
parents: 748
diff changeset
183 static void
ed59e659a202 Implement binding for hide/show for shapes and coords
Thinker K.F. Li <thinker@codemud.net>
parents: 748
diff changeset
184 xnjsmb_shape_hide(shape_t *sh, Handle<Object> self) {
ed59e659a202 Implement binding for hide/show for shapes and coords
Thinker K.F. Li <thinker@codemud.net>
parents: 748
diff changeset
185 Handle<Object> js_rt;
ed59e659a202 Implement binding for hide/show for shapes and coords
Thinker K.F. Li <thinker@codemud.net>
parents: 748
diff changeset
186 redraw_man_t *rdman;
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 780
diff changeset
187
749
ed59e659a202 Implement binding for hide/show for shapes and coords
Thinker K.F. Li <thinker@codemud.net>
parents: 748
diff changeset
188 js_rt = GET(self, "mbrt")->ToObject();
ed59e659a202 Implement binding for hide/show for shapes and coords
Thinker K.F. Li <thinker@codemud.net>
parents: 748
diff changeset
189 ASSERT(js_rt != NULL);
ed59e659a202 Implement binding for hide/show for shapes and coords
Thinker K.F. Li <thinker@codemud.net>
parents: 748
diff changeset
190 rdman = xnjsmb_rt_rdman(js_rt);
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 780
diff changeset
191
749
ed59e659a202 Implement binding for hide/show for shapes and coords
Thinker K.F. Li <thinker@codemud.net>
parents: 748
diff changeset
192 sh_hide(sh);
ed59e659a202 Implement binding for hide/show for shapes and coords
Thinker K.F. Li <thinker@codemud.net>
parents: 748
diff changeset
193 rdman_shape_changed(rdman, sh);
ed59e659a202 Implement binding for hide/show for shapes and coords
Thinker K.F. Li <thinker@codemud.net>
parents: 748
diff changeset
194 }
ed59e659a202 Implement binding for hide/show for shapes and coords
Thinker K.F. Li <thinker@codemud.net>
parents: 748
diff changeset
195
ed59e659a202 Implement binding for hide/show for shapes and coords
Thinker K.F. Li <thinker@codemud.net>
parents: 748
diff changeset
196 static void
748
56a5e08cd8af Make shapes can be removed from the tree
Thinker K.F. Li <thinker@codemud.net>
parents: 743
diff changeset
197 xnjsmb_shape_remove(shape_t *sh, Handle<Object> self) {
56a5e08cd8af Make shapes can be removed from the tree
Thinker K.F. Li <thinker@codemud.net>
parents: 743
diff changeset
198 Handle<Object> js_rt;
56a5e08cd8af Make shapes can be removed from the tree
Thinker K.F. Li <thinker@codemud.net>
parents: 743
diff changeset
199 redraw_man_t *rdman;
56a5e08cd8af Make shapes can be removed from the tree
Thinker K.F. Li <thinker@codemud.net>
parents: 743
diff changeset
200 Persistent<Object> *self_hdl;
56a5e08cd8af Make shapes can be removed from the tree
Thinker K.F. Li <thinker@codemud.net>
parents: 743
diff changeset
201 int r;
56a5e08cd8af Make shapes can be removed from the tree
Thinker K.F. Li <thinker@codemud.net>
parents: 743
diff changeset
202
56a5e08cd8af Make shapes can be removed from the tree
Thinker K.F. Li <thinker@codemud.net>
parents: 743
diff changeset
203 self_hdl = (Persistent<Object> *)mb_prop_get(&sh->obj.props,
56a5e08cd8af Make shapes can be removed from the tree
Thinker K.F. Li <thinker@codemud.net>
parents: 743
diff changeset
204 PROP_JSOBJ);
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 780
diff changeset
205
748
56a5e08cd8af Make shapes can be removed from the tree
Thinker K.F. Li <thinker@codemud.net>
parents: 743
diff changeset
206 SET(*self_hdl, "valid", Boolean::New(0));
56a5e08cd8af Make shapes can be removed from the tree
Thinker K.F. Li <thinker@codemud.net>
parents: 743
diff changeset
207 WRAP(*self_hdl, NULL);
56a5e08cd8af Make shapes can be removed from the tree
Thinker K.F. Li <thinker@codemud.net>
parents: 743
diff changeset
208
56a5e08cd8af Make shapes can be removed from the tree
Thinker K.F. Li <thinker@codemud.net>
parents: 743
diff changeset
209 js_rt = GET(*self_hdl, "mbrt")->ToObject();
56a5e08cd8af Make shapes can be removed from the tree
Thinker K.F. Li <thinker@codemud.net>
parents: 743
diff changeset
210 ASSERT(js_rt != NULL);
56a5e08cd8af Make shapes can be removed from the tree
Thinker K.F. Li <thinker@codemud.net>
parents: 743
diff changeset
211 rdman = xnjsmb_rt_rdman(js_rt);
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 780
diff changeset
212
748
56a5e08cd8af Make shapes can be removed from the tree
Thinker K.F. Li <thinker@codemud.net>
parents: 743
diff changeset
213 rdman_shape_changed(rdman, sh);
56a5e08cd8af Make shapes can be removed from the tree
Thinker K.F. Li <thinker@codemud.net>
parents: 743
diff changeset
214 r = rdman_shape_free(rdman, sh);
56a5e08cd8af Make shapes can be removed from the tree
Thinker K.F. Li <thinker@codemud.net>
parents: 743
diff changeset
215 if(r != OK)
56a5e08cd8af Make shapes can be removed from the tree
Thinker K.F. Li <thinker@codemud.net>
parents: 743
diff changeset
216 THROW_noret("Can not free a shape for unknown reason");
56a5e08cd8af Make shapes can be removed from the tree
Thinker K.F. Li <thinker@codemud.net>
parents: 743
diff changeset
217
766
be0e02948c1d Improve resource management for coords, shapes and paints.
Thinker K.F. Li <thinker@codemud.net>
parents: 764
diff changeset
218 self_hdl->Dispose();
748
56a5e08cd8af Make shapes can be removed from the tree
Thinker K.F. Li <thinker@codemud.net>
parents: 743
diff changeset
219 delete self_hdl;
56a5e08cd8af Make shapes can be removed from the tree
Thinker K.F. Li <thinker@codemud.net>
parents: 743
diff changeset
220 }
56a5e08cd8af Make shapes can be removed from the tree
Thinker K.F. Li <thinker@codemud.net>
parents: 743
diff changeset
221
56a5e08cd8af Make shapes can be removed from the tree
Thinker K.F. Li <thinker@codemud.net>
parents: 743
diff changeset
222 static void
690
86c6ebf1de25 Add JS binding for sh_rect_t
Thinker K.F. Li <thinker@branda.to>
parents: 689
diff changeset
223 xnjsmb_sh_rect_set(shape_t *sh, Handle<Object> self, float x, float y,
86c6ebf1de25 Add JS binding for sh_rect_t
Thinker K.F. Li <thinker@branda.to>
parents: 689
diff changeset
224 float w, float h, float rx, float ry) {
86c6ebf1de25 Add JS binding for sh_rect_t
Thinker K.F. Li <thinker@branda.to>
parents: 689
diff changeset
225 Handle<Object> rt;
86c6ebf1de25 Add JS binding for sh_rect_t
Thinker K.F. Li <thinker@branda.to>
parents: 689
diff changeset
226 redraw_man_t *rdman;
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 780
diff changeset
227
690
86c6ebf1de25 Add JS binding for sh_rect_t
Thinker K.F. Li <thinker@branda.to>
parents: 689
diff changeset
228 sh_rect_set(sh, x, y, w, h, rx, ry);
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 780
diff changeset
229
690
86c6ebf1de25 Add JS binding for sh_rect_t
Thinker K.F. Li <thinker@branda.to>
parents: 689
diff changeset
230 /*
86c6ebf1de25 Add JS binding for sh_rect_t
Thinker K.F. Li <thinker@branda.to>
parents: 689
diff changeset
231 * Mark changed.
86c6ebf1de25 Add JS binding for sh_rect_t
Thinker K.F. Li <thinker@branda.to>
parents: 689
diff changeset
232 */
86c6ebf1de25 Add JS binding for sh_rect_t
Thinker K.F. Li <thinker@branda.to>
parents: 689
diff changeset
233 rt = GET(self, "mbrt")->ToObject();
86c6ebf1de25 Add JS binding for sh_rect_t
Thinker K.F. Li <thinker@branda.to>
parents: 689
diff changeset
234 ASSERT(rt != NULL);
86c6ebf1de25 Add JS binding for sh_rect_t
Thinker K.F. Li <thinker@branda.to>
parents: 689
diff changeset
235 rdman = xnjsmb_rt_rdman(rt);
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 780
diff changeset
236
690
86c6ebf1de25 Add JS binding for sh_rect_t
Thinker K.F. Li <thinker@branda.to>
parents: 689
diff changeset
237 if(sh_get_coord(sh))
86c6ebf1de25 Add JS binding for sh_rect_t
Thinker K.F. Li <thinker@branda.to>
parents: 689
diff changeset
238 rdman_shape_changed(rdman, sh);
86c6ebf1de25 Add JS binding for sh_rect_t
Thinker K.F. Li <thinker@branda.to>
parents: 689
diff changeset
239 }
86c6ebf1de25 Add JS binding for sh_rect_t
Thinker K.F. Li <thinker@branda.to>
parents: 689
diff changeset
240
564
0cd1511272d2 Make base type for shapes.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
241 /* @} */
0cd1511272d2 Make base type for shapes.
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
242
683
7685c57e29d0 Migrate JS shapes binding to gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 675
diff changeset
243 #include "shapes-inc.h"
7685c57e29d0 Migrate JS shapes binding to gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 675
diff changeset
244
687
da12923a789a Migrate paints.cc to use gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 684
diff changeset
245 /*! \defgroup xnjsmb_shapes_wraps Exported wrapper makers for shapes
683
7685c57e29d0 Migrate JS shapes binding to gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 675
diff changeset
246 * \ingroup xnjsmb_shapes
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 780
diff changeset
247 *
687
da12923a789a Migrate paints.cc to use gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 684
diff changeset
248 * These functions are used by methods of mb_rt to wrap shape objects
da12923a789a Migrate paints.cc to use gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 684
diff changeset
249 * as Javascript objects.
565
c0bc60448913 Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents: 564
diff changeset
250 *
c0bc60448913 Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents: 564
diff changeset
251 * @{
c0bc60448913 Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents: 564
diff changeset
252 */
683
7685c57e29d0 Migrate JS shapes binding to gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 675
diff changeset
253 Handle<Value>
7685c57e29d0 Migrate JS shapes binding to gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 675
diff changeset
254 export_xnjsmb_auto_path_new(shape_t *sh) {
7685c57e29d0 Migrate JS shapes binding to gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 675
diff changeset
255 return xnjsmb_auto_path_new(sh);
565
c0bc60448913 Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents: 564
diff changeset
256 }
c0bc60448913 Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents: 564
diff changeset
257
683
7685c57e29d0 Migrate JS shapes binding to gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 675
diff changeset
258 Handle<Value>
7685c57e29d0 Migrate JS shapes binding to gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 675
diff changeset
259 export_xnjsmb_auto_stext_new(shape_t *sh) {
7685c57e29d0 Migrate JS shapes binding to gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 675
diff changeset
260 return xnjsmb_auto_stext_new(sh);
565
c0bc60448913 Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents: 564
diff changeset
261 }
c0bc60448913 Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents: 564
diff changeset
262
683
7685c57e29d0 Migrate JS shapes binding to gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 675
diff changeset
263 Handle<Value>
7685c57e29d0 Migrate JS shapes binding to gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 675
diff changeset
264 export_xnjsmb_auto_image_new(shape_t *sh) {
7685c57e29d0 Migrate JS shapes binding to gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 675
diff changeset
265 return xnjsmb_auto_image_new(sh);
565
c0bc60448913 Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents: 564
diff changeset
266 }
c0bc60448913 Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents: 564
diff changeset
267
690
86c6ebf1de25 Add JS binding for sh_rect_t
Thinker K.F. Li <thinker@branda.to>
parents: 689
diff changeset
268 Handle<Value>
86c6ebf1de25 Add JS binding for sh_rect_t
Thinker K.F. Li <thinker@branda.to>
parents: 689
diff changeset
269 export_xnjsmb_auto_rect_new(shape_t *sh) {
86c6ebf1de25 Add JS binding for sh_rect_t
Thinker K.F. Li <thinker@branda.to>
parents: 689
diff changeset
270 return xnjsmb_auto_rect_new(sh);
86c6ebf1de25 Add JS binding for sh_rect_t
Thinker K.F. Li <thinker@branda.to>
parents: 689
diff changeset
271 }
86c6ebf1de25 Add JS binding for sh_rect_t
Thinker K.F. Li <thinker@branda.to>
parents: 689
diff changeset
272
565
c0bc60448913 Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents: 564
diff changeset
273 /* @} */
c0bc60448913 Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents: 564
diff changeset
274
687
da12923a789a Migrate paints.cc to use gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 684
diff changeset
275 /*! \defgroup xnjsmb_shapes_cons Constructor of shapes
683
7685c57e29d0 Migrate JS shapes binding to gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 675
diff changeset
276 * \ingroup xnjsmb_shapes
574
a2faee809514 Implement stext type for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 570
diff changeset
277 *
a2faee809514 Implement stext type for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 570
diff changeset
278 * @{
a2faee809514 Implement stext type for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 570
diff changeset
279 */
683
7685c57e29d0 Migrate JS shapes binding to gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 675
diff changeset
280 shape_t *
7685c57e29d0 Migrate JS shapes binding to gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 675
diff changeset
281 xnjsmb_path_new(njs_runtime_t *rt, const char *d) {
574
a2faee809514 Implement stext type for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 570
diff changeset
282 redraw_man_t *rdman;
683
7685c57e29d0 Migrate JS shapes binding to gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 675
diff changeset
283 shape_t *sh;
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 780
diff changeset
284
1053
df6ee4568ca2 Rename X_njs_MB_* to njs_mb_* for nodejs plugin.
Thinker K.F. Li <thinker@codemud.net>
parents: 885
diff changeset
285 rdman = njs_mb_rdman(rt);
683
7685c57e29d0 Migrate JS shapes binding to gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 675
diff changeset
286 sh = rdman_shape_path_new(rdman, d);
767
9d430b084a13 Free string allocated by code generator
Thinker K.F. Li <thinker@codemud.net>
parents: 766
diff changeset
287 /* Code generator supposes that callee should free the memory */
9d430b084a13 Free string allocated by code generator
Thinker K.F. Li <thinker@codemud.net>
parents: 766
diff changeset
288 free((void *)d);
822
586e50f82c1f Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents: 780
diff changeset
289
683
7685c57e29d0 Migrate JS shapes binding to gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 675
diff changeset
290 return sh;
574
a2faee809514 Implement stext type for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 570
diff changeset
291 }
a2faee809514 Implement stext type for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 570
diff changeset
292
683
7685c57e29d0 Migrate JS shapes binding to gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 675
diff changeset
293 shape_t *
7685c57e29d0 Migrate JS shapes binding to gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 675
diff changeset
294 xnjsmb_stext_new(njs_runtime_t *rt, const char *txt, float x, float y) {
7685c57e29d0 Migrate JS shapes binding to gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 675
diff changeset
295 redraw_man_t *rdman;
576
5a68e2bcea17 Set font styles for stext in Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 574
diff changeset
296 shape_t *sh;
5a68e2bcea17 Set font styles for stext in Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 574
diff changeset
297
1053
df6ee4568ca2 Rename X_njs_MB_* to njs_mb_* for nodejs plugin.
Thinker K.F. Li <thinker@codemud.net>
parents: 885
diff changeset
298 rdman = njs_mb_rdman(rt);
683
7685c57e29d0 Migrate JS shapes binding to gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 675
diff changeset
299 sh = rdman_shape_stext_new(rdman, txt, x, y);
767
9d430b084a13 Free string allocated by code generator
Thinker K.F. Li <thinker@codemud.net>
parents: 766
diff changeset
300 /* Code generator supposes that callee should free the memory */
9d430b084a13 Free string allocated by code generator
Thinker K.F. Li <thinker@codemud.net>
parents: 766
diff changeset
301 free((void *)txt);
576
5a68e2bcea17 Set font styles for stext in Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 574
diff changeset
302
683
7685c57e29d0 Migrate JS shapes binding to gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 675
diff changeset
303 return sh;
574
a2faee809514 Implement stext type for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 570
diff changeset
304 }
a2faee809514 Implement stext type for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 570
diff changeset
305
683
7685c57e29d0 Migrate JS shapes binding to gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 675
diff changeset
306 shape_t *
7685c57e29d0 Migrate JS shapes binding to gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 675
diff changeset
307 xnjsmb_image_new(njs_runtime_t *rt, float x, float y, float w, float h) {
641
f60d8fa1c55b Javascript binding for shape_image_t
Thinker K.F. Li <thinker@branda.to>
parents: 576
diff changeset
308 redraw_man_t *rdman;
683
7685c57e29d0 Migrate JS shapes binding to gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 675
diff changeset
309 shape_t *sh;
641
f60d8fa1c55b Javascript binding for shape_image_t
Thinker K.F. Li <thinker@branda.to>
parents: 576
diff changeset
310
1053
df6ee4568ca2 Rename X_njs_MB_* to njs_mb_* for nodejs plugin.
Thinker K.F. Li <thinker@codemud.net>
parents: 885
diff changeset
311 rdman = njs_mb_rdman(rt);
683
7685c57e29d0 Migrate JS shapes binding to gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 675
diff changeset
312 sh = rdman_shape_image_new(rdman, x, y, w, h);
641
f60d8fa1c55b Javascript binding for shape_image_t
Thinker K.F. Li <thinker@branda.to>
parents: 576
diff changeset
313
683
7685c57e29d0 Migrate JS shapes binding to gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 675
diff changeset
314 return sh;
641
f60d8fa1c55b Javascript binding for shape_image_t
Thinker K.F. Li <thinker@branda.to>
parents: 576
diff changeset
315 }
f60d8fa1c55b Javascript binding for shape_image_t
Thinker K.F. Li <thinker@branda.to>
parents: 576
diff changeset
316
690
86c6ebf1de25 Add JS binding for sh_rect_t
Thinker K.F. Li <thinker@branda.to>
parents: 689
diff changeset
317 shape_t *
86c6ebf1de25 Add JS binding for sh_rect_t
Thinker K.F. Li <thinker@branda.to>
parents: 689
diff changeset
318 xnjsmb_rect_new(njs_runtime_t *rt, float x, float y, float w, float h,
86c6ebf1de25 Add JS binding for sh_rect_t
Thinker K.F. Li <thinker@branda.to>
parents: 689
diff changeset
319 float rx, float ry, const char **err) {
86c6ebf1de25 Add JS binding for sh_rect_t
Thinker K.F. Li <thinker@branda.to>
parents: 689
diff changeset
320 redraw_man_t *rdman;
86c6ebf1de25 Add JS binding for sh_rect_t
Thinker K.F. Li <thinker@branda.to>
parents: 689
diff changeset
321 shape_t *sh;
86c6ebf1de25 Add JS binding for sh_rect_t
Thinker K.F. Li <thinker@branda.to>
parents: 689
diff changeset
322
1053
df6ee4568ca2 Rename X_njs_MB_* to njs_mb_* for nodejs plugin.
Thinker K.F. Li <thinker@codemud.net>
parents: 885
diff changeset
323 rdman = njs_mb_rdman(rt);
690
86c6ebf1de25 Add JS binding for sh_rect_t
Thinker K.F. Li <thinker@branda.to>
parents: 689
diff changeset
324 sh = rdman_shape_rect_new(rdman, x, y, w, h, rx, ry);
86c6ebf1de25 Add JS binding for sh_rect_t
Thinker K.F. Li <thinker@branda.to>
parents: 689
diff changeset
325 if(sh == NULL) {
86c6ebf1de25 Add JS binding for sh_rect_t
Thinker K.F. Li <thinker@branda.to>
parents: 689
diff changeset
326 *err = "Can not create a sh_rect_t";
86c6ebf1de25 Add JS binding for sh_rect_t
Thinker K.F. Li <thinker@branda.to>
parents: 689
diff changeset
327 return NULL;
86c6ebf1de25 Add JS binding for sh_rect_t
Thinker K.F. Li <thinker@branda.to>
parents: 689
diff changeset
328 }
86c6ebf1de25 Add JS binding for sh_rect_t
Thinker K.F. Li <thinker@branda.to>
parents: 689
diff changeset
329
86c6ebf1de25 Add JS binding for sh_rect_t
Thinker K.F. Li <thinker@branda.to>
parents: 689
diff changeset
330 return sh;
86c6ebf1de25 Add JS binding for sh_rect_t
Thinker K.F. Li <thinker@branda.to>
parents: 689
diff changeset
331 }
86c6ebf1de25 Add JS binding for sh_rect_t
Thinker K.F. Li <thinker@branda.to>
parents: 689
diff changeset
332
641
f60d8fa1c55b Javascript binding for shape_image_t
Thinker K.F. Li <thinker@branda.to>
parents: 576
diff changeset
333 /* @} */
f60d8fa1c55b Javascript binding for shape_image_t
Thinker K.F. Li <thinker@branda.to>
parents: 576
diff changeset
334
565
c0bc60448913 Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents: 564
diff changeset
335 /*! \brief Set properties of template of mb_rt.
683
7685c57e29d0 Migrate JS shapes binding to gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 675
diff changeset
336 * \ingroup xnjsmb_shapes
565
c0bc60448913 Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents: 564
diff changeset
337 */
c0bc60448913 Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents: 564
diff changeset
338 void
c0bc60448913 Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents: 564
diff changeset
339 xnjsmb_shapes_init_mb_rt_temp(Handle<FunctionTemplate> rt_temp) {
574
a2faee809514 Implement stext type for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 570
diff changeset
340 HandleScope scope;
a2faee809514 Implement stext type for Javascript
Thinker K.F. Li <thinker@branda.to>
parents: 570
diff changeset
341 Handle<FunctionTemplate> path_new_temp, stext_new_temp;
641
f60d8fa1c55b Javascript binding for shape_image_t
Thinker K.F. Li <thinker@branda.to>
parents: 576
diff changeset
342 Handle<FunctionTemplate> image_new_temp;
565
c0bc60448913 Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents: 564
diff changeset
343 Handle<ObjectTemplate> rt_proto_temp;
c0bc60448913 Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents: 564
diff changeset
344 static int temp_init_flag = 0;
c0bc60448913 Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents: 564
diff changeset
345
c0bc60448913 Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents: 564
diff changeset
346 if(temp_init_flag == 0) {
683
7685c57e29d0 Migrate JS shapes binding to gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 675
diff changeset
347 xnjsmb_auto_shape_init();
7685c57e29d0 Migrate JS shapes binding to gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 675
diff changeset
348 xnjsmb_auto_path_init();
7685c57e29d0 Migrate JS shapes binding to gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 675
diff changeset
349 xnjsmb_auto_stext_init();
7685c57e29d0 Migrate JS shapes binding to gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 675
diff changeset
350 xnjsmb_auto_image_init();
690
86c6ebf1de25 Add JS binding for sh_rect_t
Thinker K.F. Li <thinker@branda.to>
parents: 689
diff changeset
351 xnjsmb_auto_rect_init();
565
c0bc60448913 Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents: 564
diff changeset
352 temp_init_flag = 1;
c0bc60448913 Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents: 564
diff changeset
353 }
683
7685c57e29d0 Migrate JS shapes binding to gen_v8_binding.m4
Thinker K.F. Li <thinker@branda.to>
parents: 675
diff changeset
354 return;
565
c0bc60448913 Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents: 564
diff changeset
355 }