Mercurial > MadButterfly
annotate nodejs/coord.cc @ 1442:66609545f7a6
Remove the animation between scene. We need to fix this and put itback latter.
author | wycc |
---|---|
date | Mon, 11 Apr 2011 13:09:48 +0800 |
parents | 4be04f29fa70 |
children | ef3908d9a3d2 |
rev | line source |
---|---|
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
810
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:
810
diff
changeset
|
2 // vim: sw=4:ts=8:sts=4 |
557
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
3 #include <stdio.h> |
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
4 #include <v8.h> |
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
5 |
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
6 extern "C" { |
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
7 #include "mb.h" |
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
8 #include "mb_X_supp.h" |
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
9 #include "mb_tools.h" |
1056
88bd0eee2b00
Rename X_supp_njs.[ch] to njs_mb_supp.[ch].
Thinker K.F. Li <thinker@codemud.net>
parents:
843
diff
changeset
|
10 #include "njs_mb_supp.h" |
1434
4be04f29fa70
Add functions to search for the text recursively inside coord_t tree. Once we find the first instance, we change the text of it. We need to think about how to manage the multiple segment texts, which is composed of several tspan.
wycc
parents:
1423
diff
changeset
|
11 #include <string.h> |
557
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
12 } |
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
13 |
560
ce7a35abcb0d
Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
557
diff
changeset
|
14 #include "mbfly_njs.h" |
ce7a35abcb0d
Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
557
diff
changeset
|
15 |
ce7a35abcb0d
Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
557
diff
changeset
|
16 #ifndef ASSERT |
ce7a35abcb0d
Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
557
diff
changeset
|
17 #define ASSERT(x) |
ce7a35abcb0d
Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
557
diff
changeset
|
18 #endif |
743
dd1f3382d6a4
Create a persistent handle for coords and shapes correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
742
diff
changeset
|
19 #define OK 0 |
dd1f3382d6a4
Create a persistent handle for coords and shapes correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
742
diff
changeset
|
20 |
739
4916c3a3fe3c
Design doc for life-cycle of MB objects for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
695
diff
changeset
|
21 /*! \page jsgc How to Manage Life-cycle of Objects for Javascript. |
4916c3a3fe3c
Design doc for life-cycle of MB objects for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
695
diff
changeset
|
22 * |
4916c3a3fe3c
Design doc for life-cycle of MB objects for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
695
diff
changeset
|
23 * The life-cycle of MadButterfly ojects are simple. A object is live |
4916c3a3fe3c
Design doc for life-cycle of MB objects for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
695
diff
changeset
|
24 * when it is created and dead when it is free. When a coord or shape |
4916c3a3fe3c
Design doc for life-cycle of MB objects for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
695
diff
changeset
|
25 * is free, it is also removed from the tree. There is not way to |
4916c3a3fe3c
Design doc for life-cycle of MB objects for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
695
diff
changeset
|
26 * remove a coord or a shape without freeing it. So, if you want to |
4916c3a3fe3c
Design doc for life-cycle of MB objects for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
695
diff
changeset
|
27 * remove a coord or a shape object from the tree, you can only free |
4916c3a3fe3c
Design doc for life-cycle of MB objects for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
695
diff
changeset
|
28 * it. |
4916c3a3fe3c
Design doc for life-cycle of MB objects for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
695
diff
changeset
|
29 * |
4916c3a3fe3c
Design doc for life-cycle of MB objects for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
695
diff
changeset
|
30 * Javascript, in conventional, does not free an object. It has GC, |
4916c3a3fe3c
Design doc for life-cycle of MB objects for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
695
diff
changeset
|
31 * the engine, being used, will free an object if it is no more |
4916c3a3fe3c
Design doc for life-cycle of MB objects for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
695
diff
changeset
|
32 * referenced. So, we had better provide a removing function, but |
4916c3a3fe3c
Design doc for life-cycle of MB objects for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
695
diff
changeset
|
33 * actually free an object. In idea situation, a new MB object would |
4916c3a3fe3c
Design doc for life-cycle of MB objects for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
695
diff
changeset
|
34 * be created for and attached on the JS object, when an object added |
4916c3a3fe3c
Design doc for life-cycle of MB objects for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
695
diff
changeset
|
35 * back to the tree. But, it means we need to keep states of an |
4916c3a3fe3c
Design doc for life-cycle of MB objects for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
695
diff
changeset
|
36 * object and create a new one with the same states later. It is |
4916c3a3fe3c
Design doc for life-cycle of MB objects for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
695
diff
changeset
|
37 * complicated. So, once an object is removed, it is invalidated. |
4916c3a3fe3c
Design doc for life-cycle of MB objects for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
695
diff
changeset
|
38 * |
4916c3a3fe3c
Design doc for life-cycle of MB objects for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
695
diff
changeset
|
39 * I hope someone would implement a higher abstract layer, in JS, to |
4916c3a3fe3c
Design doc for life-cycle of MB objects for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
695
diff
changeset
|
40 * implement the idea model that recreate a new object when an |
4916c3a3fe3c
Design doc for life-cycle of MB objects for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
695
diff
changeset
|
41 * invalidated JS object being added back. |
4916c3a3fe3c
Design doc for life-cycle of MB objects for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
695
diff
changeset
|
42 * |
4916c3a3fe3c
Design doc for life-cycle of MB objects for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
695
diff
changeset
|
43 * An invalid object is the one with NULL internal field and obj.valid |
4916c3a3fe3c
Design doc for life-cycle of MB objects for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
695
diff
changeset
|
44 * == false. The binding of MadButterfly hold a reference to every |
4916c3a3fe3c
Design doc for life-cycle of MB objects for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
695
diff
changeset
|
45 * object added to the tree of a mbrt (runtime object), and remove the |
4916c3a3fe3c
Design doc for life-cycle of MB objects for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
695
diff
changeset
|
46 * reference and invalidate it when it being removed. |
4916c3a3fe3c
Design doc for life-cycle of MB objects for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
695
diff
changeset
|
47 * |
741
d8764f10e141
Remove a coord from the tree in JS
Thinker K.F. Li <thinker@codemud.net>
parents:
739
diff
changeset
|
48 * For coords, they are always attached to the tree when it is valid. |
d8764f10e141
Remove a coord from the tree in JS
Thinker K.F. Li <thinker@codemud.net>
parents:
739
diff
changeset
|
49 * So, binding hold a persistent reference to it. The reference is |
d8764f10e141
Remove a coord from the tree in JS
Thinker K.F. Li <thinker@codemud.net>
parents:
739
diff
changeset
|
50 * purged when a coord being removed from the tree and being |
d8764f10e141
Remove a coord from the tree in JS
Thinker K.F. Li <thinker@codemud.net>
parents:
739
diff
changeset
|
51 * invalidated. |
d8764f10e141
Remove a coord from the tree in JS
Thinker K.F. Li <thinker@codemud.net>
parents:
739
diff
changeset
|
52 * |
d8764f10e141
Remove a coord from the tree in JS
Thinker K.F. Li <thinker@codemud.net>
parents:
739
diff
changeset
|
53 * For any shape, it is not attached to the tree at begining, but is |
d8764f10e141
Remove a coord from the tree in JS
Thinker K.F. Li <thinker@codemud.net>
parents:
739
diff
changeset
|
54 * attached to a tree laterly, or is collected by GC. The binding |
d8764f10e141
Remove a coord from the tree in JS
Thinker K.F. Li <thinker@codemud.net>
parents:
739
diff
changeset
|
55 * hold a weak reference for a new shape, and upgrade to a strong |
d8764f10e141
Remove a coord from the tree in JS
Thinker K.F. Li <thinker@codemud.net>
parents:
739
diff
changeset
|
56 * reference when the shape being added to the tree. |
739
4916c3a3fe3c
Design doc for life-cycle of MB objects for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
695
diff
changeset
|
57 */ |
4916c3a3fe3c
Design doc for life-cycle of MB objects for JS
Thinker K.F. Li <thinker@codemud.net>
parents:
695
diff
changeset
|
58 |
557
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
59 using namespace v8; |
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
60 |
684
b346e4699e55
Add more comment for JS binding
Thinker K.F. Li <thinker@branda.to>
parents:
680
diff
changeset
|
61 /*! \defgroup xnjsmb_coord JS binding for coord objects. |
b346e4699e55
Add more comment for JS binding
Thinker K.F. Li <thinker@branda.to>
parents:
680
diff
changeset
|
62 * \ingroup xnjsmb |
b346e4699e55
Add more comment for JS binding
Thinker K.F. Li <thinker@branda.to>
parents:
680
diff
changeset
|
63 * |
b346e4699e55
Add more comment for JS binding
Thinker K.F. Li <thinker@branda.to>
parents:
680
diff
changeset
|
64 * @{ |
b346e4699e55
Add more comment for JS binding
Thinker K.F. Li <thinker@branda.to>
parents:
680
diff
changeset
|
65 */ |
741
d8764f10e141
Remove a coord from the tree in JS
Thinker K.F. Li <thinker@codemud.net>
parents:
739
diff
changeset
|
66 /*! \brief Invalidate JS objects for coords and shapes in a subtree. |
d8764f10e141
Remove a coord from the tree in JS
Thinker K.F. Li <thinker@codemud.net>
parents:
739
diff
changeset
|
67 * |
d8764f10e141
Remove a coord from the tree in JS
Thinker K.F. Li <thinker@codemud.net>
parents:
739
diff
changeset
|
68 * \param self is the object of the root of subtree. |
d8764f10e141
Remove a coord from the tree in JS
Thinker K.F. Li <thinker@codemud.net>
parents:
739
diff
changeset
|
69 * |
d8764f10e141
Remove a coord from the tree in JS
Thinker K.F. Li <thinker@codemud.net>
parents:
739
diff
changeset
|
70 * \sa \ref jsgc |
d8764f10e141
Remove a coord from the tree in JS
Thinker K.F. Li <thinker@codemud.net>
parents:
739
diff
changeset
|
71 */ |
d8764f10e141
Remove a coord from the tree in JS
Thinker K.F. Li <thinker@codemud.net>
parents:
739
diff
changeset
|
72 static void |
745
4ccb0553e804
Refactor code of free C objects into xnjsmb_coord_free_subtree
Thinker K.F. Li <thinker@codemud.net>
parents:
744
diff
changeset
|
73 xnjsmb_coord_invalidate_subtree(coord_t *coord) { |
742
24038e7a365b
Reorder instructions to invalidate coords correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
741
diff
changeset
|
74 Persistent<Object> *child_hdl; |
24038e7a365b
Reorder instructions to invalidate coords correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
741
diff
changeset
|
75 Persistent<Object> *mem_hdl; |
745
4ccb0553e804
Refactor code of free C objects into xnjsmb_coord_free_subtree
Thinker K.F. Li <thinker@codemud.net>
parents:
744
diff
changeset
|
76 coord_t *child; |
4ccb0553e804
Refactor code of free C objects into xnjsmb_coord_free_subtree
Thinker K.F. Li <thinker@codemud.net>
parents:
744
diff
changeset
|
77 shape_t *mem; |
741
d8764f10e141
Remove a coord from the tree in JS
Thinker K.F. Li <thinker@codemud.net>
parents:
739
diff
changeset
|
78 Handle<Value> _false = Boolean::New(0); |
d8764f10e141
Remove a coord from the tree in JS
Thinker K.F. Li <thinker@codemud.net>
parents:
739
diff
changeset
|
79 |
745
4ccb0553e804
Refactor code of free C objects into xnjsmb_coord_free_subtree
Thinker K.F. Li <thinker@codemud.net>
parents:
744
diff
changeset
|
80 /* Invalidate all coords in the subtree */ |
4ccb0553e804
Refactor code of free C objects into xnjsmb_coord_free_subtree
Thinker K.F. Li <thinker@codemud.net>
parents:
744
diff
changeset
|
81 FOR_COORDS_PREORDER(coord, child) { |
4ccb0553e804
Refactor code of free C objects into xnjsmb_coord_free_subtree
Thinker K.F. Li <thinker@codemud.net>
parents:
744
diff
changeset
|
82 child_hdl = (Persistent<Object> *)mb_prop_get(&child->obj.props, |
4ccb0553e804
Refactor code of free C objects into xnjsmb_coord_free_subtree
Thinker K.F. Li <thinker@codemud.net>
parents:
744
diff
changeset
|
83 PROP_JSOBJ); |
1416
c60a978f98b1
Fix issue of seg. fault at xnjsmb_coord_invalidate_subtree().
Thinker K.F. Li <thinker@codemud.net>
parents:
1415
diff
changeset
|
84 /* There is no associated JS object. Perhaps, it is created |
c60a978f98b1
Fix issue of seg. fault at xnjsmb_coord_invalidate_subtree().
Thinker K.F. Li <thinker@codemud.net>
parents:
1415
diff
changeset
|
85 * by xnjsmb_coord_clone_from_subtree(). |
c60a978f98b1
Fix issue of seg. fault at xnjsmb_coord_invalidate_subtree().
Thinker K.F. Li <thinker@codemud.net>
parents:
1415
diff
changeset
|
86 */ |
c60a978f98b1
Fix issue of seg. fault at xnjsmb_coord_invalidate_subtree().
Thinker K.F. Li <thinker@codemud.net>
parents:
1415
diff
changeset
|
87 if(child_hdl == NULL) { |
c60a978f98b1
Fix issue of seg. fault at xnjsmb_coord_invalidate_subtree().
Thinker K.F. Li <thinker@codemud.net>
parents:
1415
diff
changeset
|
88 preorder_coord_skip_subtree(child); |
c60a978f98b1
Fix issue of seg. fault at xnjsmb_coord_invalidate_subtree().
Thinker K.F. Li <thinker@codemud.net>
parents:
1415
diff
changeset
|
89 continue; |
c60a978f98b1
Fix issue of seg. fault at xnjsmb_coord_invalidate_subtree().
Thinker K.F. Li <thinker@codemud.net>
parents:
1415
diff
changeset
|
90 } |
c60a978f98b1
Fix issue of seg. fault at xnjsmb_coord_invalidate_subtree().
Thinker K.F. Li <thinker@codemud.net>
parents:
1415
diff
changeset
|
91 |
745
4ccb0553e804
Refactor code of free C objects into xnjsmb_coord_free_subtree
Thinker K.F. Li <thinker@codemud.net>
parents:
744
diff
changeset
|
92 SET(*child_hdl, "valid", _false); |
4ccb0553e804
Refactor code of free C objects into xnjsmb_coord_free_subtree
Thinker K.F. Li <thinker@codemud.net>
parents:
744
diff
changeset
|
93 WRAP(*child_hdl, NULL); |
766
be0e02948c1d
Improve resource management for coords, shapes and paints.
Thinker K.F. Li <thinker@codemud.net>
parents:
749
diff
changeset
|
94 child_hdl->Dispose(); |
746
1dbc74a14199
Delete internal reference ob binding when invalidating coords and/or shapes
Thinker K.F. Li <thinker@codemud.net>
parents:
745
diff
changeset
|
95 delete child_hdl; |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
810
diff
changeset
|
96 |
745
4ccb0553e804
Refactor code of free C objects into xnjsmb_coord_free_subtree
Thinker K.F. Li <thinker@codemud.net>
parents:
744
diff
changeset
|
97 /* Invalidate members of a coord */ |
4ccb0553e804
Refactor code of free C objects into xnjsmb_coord_free_subtree
Thinker K.F. Li <thinker@codemud.net>
parents:
744
diff
changeset
|
98 FOR_COORD_SHAPES(child, mem) { |
4ccb0553e804
Refactor code of free C objects into xnjsmb_coord_free_subtree
Thinker K.F. Li <thinker@codemud.net>
parents:
744
diff
changeset
|
99 mem_hdl = (Persistent<Object> *)mb_prop_get(&mem->obj.props, |
4ccb0553e804
Refactor code of free C objects into xnjsmb_coord_free_subtree
Thinker K.F. Li <thinker@codemud.net>
parents:
744
diff
changeset
|
100 PROP_JSOBJ); |
1416
c60a978f98b1
Fix issue of seg. fault at xnjsmb_coord_invalidate_subtree().
Thinker K.F. Li <thinker@codemud.net>
parents:
1415
diff
changeset
|
101 /* There is no associated JS object. Perhaps, it is |
c60a978f98b1
Fix issue of seg. fault at xnjsmb_coord_invalidate_subtree().
Thinker K.F. Li <thinker@codemud.net>
parents:
1415
diff
changeset
|
102 * created by xnjsmb_coord_clone_from_subtree(). |
c60a978f98b1
Fix issue of seg. fault at xnjsmb_coord_invalidate_subtree().
Thinker K.F. Li <thinker@codemud.net>
parents:
1415
diff
changeset
|
103 */ |
c60a978f98b1
Fix issue of seg. fault at xnjsmb_coord_invalidate_subtree().
Thinker K.F. Li <thinker@codemud.net>
parents:
1415
diff
changeset
|
104 if(mem_hdl == NULL) |
c60a978f98b1
Fix issue of seg. fault at xnjsmb_coord_invalidate_subtree().
Thinker K.F. Li <thinker@codemud.net>
parents:
1415
diff
changeset
|
105 continue; |
c60a978f98b1
Fix issue of seg. fault at xnjsmb_coord_invalidate_subtree().
Thinker K.F. Li <thinker@codemud.net>
parents:
1415
diff
changeset
|
106 |
745
4ccb0553e804
Refactor code of free C objects into xnjsmb_coord_free_subtree
Thinker K.F. Li <thinker@codemud.net>
parents:
744
diff
changeset
|
107 SET(*mem_hdl, "valid", _false); |
4ccb0553e804
Refactor code of free C objects into xnjsmb_coord_free_subtree
Thinker K.F. Li <thinker@codemud.net>
parents:
744
diff
changeset
|
108 WRAP(*mem_hdl, NULL); |
766
be0e02948c1d
Improve resource management for coords, shapes and paints.
Thinker K.F. Li <thinker@codemud.net>
parents:
749
diff
changeset
|
109 mem_hdl->Dispose(); |
746
1dbc74a14199
Delete internal reference ob binding when invalidating coords and/or shapes
Thinker K.F. Li <thinker@codemud.net>
parents:
745
diff
changeset
|
110 delete mem_hdl; |
745
4ccb0553e804
Refactor code of free C objects into xnjsmb_coord_free_subtree
Thinker K.F. Li <thinker@codemud.net>
parents:
744
diff
changeset
|
111 } |
4ccb0553e804
Refactor code of free C objects into xnjsmb_coord_free_subtree
Thinker K.F. Li <thinker@codemud.net>
parents:
744
diff
changeset
|
112 } |
4ccb0553e804
Refactor code of free C objects into xnjsmb_coord_free_subtree
Thinker K.F. Li <thinker@codemud.net>
parents:
744
diff
changeset
|
113 } |
4ccb0553e804
Refactor code of free C objects into xnjsmb_coord_free_subtree
Thinker K.F. Li <thinker@codemud.net>
parents:
744
diff
changeset
|
114 |
4ccb0553e804
Refactor code of free C objects into xnjsmb_coord_free_subtree
Thinker K.F. Li <thinker@codemud.net>
parents:
744
diff
changeset
|
115 /*! \brief Free C objects for coords and shapes in a subtree. |
4ccb0553e804
Refactor code of free C objects into xnjsmb_coord_free_subtree
Thinker K.F. Li <thinker@codemud.net>
parents:
744
diff
changeset
|
116 * |
4ccb0553e804
Refactor code of free C objects into xnjsmb_coord_free_subtree
Thinker K.F. Li <thinker@codemud.net>
parents:
744
diff
changeset
|
117 * \param self is the object of the root of subtree. |
4ccb0553e804
Refactor code of free C objects into xnjsmb_coord_free_subtree
Thinker K.F. Li <thinker@codemud.net>
parents:
744
diff
changeset
|
118 * |
4ccb0553e804
Refactor code of free C objects into xnjsmb_coord_free_subtree
Thinker K.F. Li <thinker@codemud.net>
parents:
744
diff
changeset
|
119 * \sa \ref jsgc |
4ccb0553e804
Refactor code of free C objects into xnjsmb_coord_free_subtree
Thinker K.F. Li <thinker@codemud.net>
parents:
744
diff
changeset
|
120 */ |
4ccb0553e804
Refactor code of free C objects into xnjsmb_coord_free_subtree
Thinker K.F. Li <thinker@codemud.net>
parents:
744
diff
changeset
|
121 static void |
4ccb0553e804
Refactor code of free C objects into xnjsmb_coord_free_subtree
Thinker K.F. Li <thinker@codemud.net>
parents:
744
diff
changeset
|
122 xnjsmb_coord_free_subtree(redraw_man_t *rdman, coord_t *coord) { |
4ccb0553e804
Refactor code of free C objects into xnjsmb_coord_free_subtree
Thinker K.F. Li <thinker@codemud.net>
parents:
744
diff
changeset
|
123 coord_t *child, *last_child; |
4ccb0553e804
Refactor code of free C objects into xnjsmb_coord_free_subtree
Thinker K.F. Li <thinker@codemud.net>
parents:
744
diff
changeset
|
124 shape_t *mem, *last_mem; |
4ccb0553e804
Refactor code of free C objects into xnjsmb_coord_free_subtree
Thinker K.F. Li <thinker@codemud.net>
parents:
744
diff
changeset
|
125 int r; |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
810
diff
changeset
|
126 |
744
6a988e23ad2a
A dirty implementation of removing subtree
Thinker K.F. Li <thinker@codemud.net>
parents:
743
diff
changeset
|
127 rdman_coord_changed(rdman, coord); |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
810
diff
changeset
|
128 |
744
6a988e23ad2a
A dirty implementation of removing subtree
Thinker K.F. Li <thinker@codemud.net>
parents:
743
diff
changeset
|
129 last_child = NULL; |
6a988e23ad2a
A dirty implementation of removing subtree
Thinker K.F. Li <thinker@codemud.net>
parents:
743
diff
changeset
|
130 FOR_COORDS_POSTORDER(coord, child) { |
6a988e23ad2a
A dirty implementation of removing subtree
Thinker K.F. Li <thinker@codemud.net>
parents:
743
diff
changeset
|
131 if(last_child != NULL) { |
768
13669b28826d
Fix issue of memory leaking for coord objects.
Thinker K.F. Li <thinker@codemud.net>
parents:
766
diff
changeset
|
132 r = rdman_coord_free(rdman, last_child); |
744
6a988e23ad2a
A dirty implementation of removing subtree
Thinker K.F. Li <thinker@codemud.net>
parents:
743
diff
changeset
|
133 if(r != OK) |
6a988e23ad2a
A dirty implementation of removing subtree
Thinker K.F. Li <thinker@codemud.net>
parents:
743
diff
changeset
|
134 THROW_noret("Unknown error"); |
6a988e23ad2a
A dirty implementation of removing subtree
Thinker K.F. Li <thinker@codemud.net>
parents:
743
diff
changeset
|
135 } |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
810
diff
changeset
|
136 |
745
4ccb0553e804
Refactor code of free C objects into xnjsmb_coord_free_subtree
Thinker K.F. Li <thinker@codemud.net>
parents:
744
diff
changeset
|
137 /* Free members of a coord */ |
744
6a988e23ad2a
A dirty implementation of removing subtree
Thinker K.F. Li <thinker@codemud.net>
parents:
743
diff
changeset
|
138 last_mem = NULL; |
741
d8764f10e141
Remove a coord from the tree in JS
Thinker K.F. Li <thinker@codemud.net>
parents:
739
diff
changeset
|
139 FOR_COORD_SHAPES(child, mem) { |
744
6a988e23ad2a
A dirty implementation of removing subtree
Thinker K.F. Li <thinker@codemud.net>
parents:
743
diff
changeset
|
140 if(last_mem != NULL) { |
6a988e23ad2a
A dirty implementation of removing subtree
Thinker K.F. Li <thinker@codemud.net>
parents:
743
diff
changeset
|
141 r = rdman_shape_free(rdman, last_mem); |
6a988e23ad2a
A dirty implementation of removing subtree
Thinker K.F. Li <thinker@codemud.net>
parents:
743
diff
changeset
|
142 if(r != OK) |
6a988e23ad2a
A dirty implementation of removing subtree
Thinker K.F. Li <thinker@codemud.net>
parents:
743
diff
changeset
|
143 THROW_noret("Unknown error"); |
6a988e23ad2a
A dirty implementation of removing subtree
Thinker K.F. Li <thinker@codemud.net>
parents:
743
diff
changeset
|
144 } |
6a988e23ad2a
A dirty implementation of removing subtree
Thinker K.F. Li <thinker@codemud.net>
parents:
743
diff
changeset
|
145 |
6a988e23ad2a
A dirty implementation of removing subtree
Thinker K.F. Li <thinker@codemud.net>
parents:
743
diff
changeset
|
146 last_mem = mem; |
741
d8764f10e141
Remove a coord from the tree in JS
Thinker K.F. Li <thinker@codemud.net>
parents:
739
diff
changeset
|
147 } |
744
6a988e23ad2a
A dirty implementation of removing subtree
Thinker K.F. Li <thinker@codemud.net>
parents:
743
diff
changeset
|
148 if(last_mem != NULL) { |
6a988e23ad2a
A dirty implementation of removing subtree
Thinker K.F. Li <thinker@codemud.net>
parents:
743
diff
changeset
|
149 r = rdman_shape_free(rdman, last_mem); |
6a988e23ad2a
A dirty implementation of removing subtree
Thinker K.F. Li <thinker@codemud.net>
parents:
743
diff
changeset
|
150 if(r != OK) |
6a988e23ad2a
A dirty implementation of removing subtree
Thinker K.F. Li <thinker@codemud.net>
parents:
743
diff
changeset
|
151 THROW_noret("Unknown error"); |
6a988e23ad2a
A dirty implementation of removing subtree
Thinker K.F. Li <thinker@codemud.net>
parents:
743
diff
changeset
|
152 } |
6a988e23ad2a
A dirty implementation of removing subtree
Thinker K.F. Li <thinker@codemud.net>
parents:
743
diff
changeset
|
153 |
6a988e23ad2a
A dirty implementation of removing subtree
Thinker K.F. Li <thinker@codemud.net>
parents:
743
diff
changeset
|
154 last_child = child; |
6a988e23ad2a
A dirty implementation of removing subtree
Thinker K.F. Li <thinker@codemud.net>
parents:
743
diff
changeset
|
155 } |
6a988e23ad2a
A dirty implementation of removing subtree
Thinker K.F. Li <thinker@codemud.net>
parents:
743
diff
changeset
|
156 if(last_child != NULL) { |
768
13669b28826d
Fix issue of memory leaking for coord objects.
Thinker K.F. Li <thinker@codemud.net>
parents:
766
diff
changeset
|
157 r = rdman_coord_free(rdman, last_child); |
744
6a988e23ad2a
A dirty implementation of removing subtree
Thinker K.F. Li <thinker@codemud.net>
parents:
743
diff
changeset
|
158 if(r != OK) |
6a988e23ad2a
A dirty implementation of removing subtree
Thinker K.F. Li <thinker@codemud.net>
parents:
743
diff
changeset
|
159 THROW_noret("Unknown error"); |
741
d8764f10e141
Remove a coord from the tree in JS
Thinker K.F. Li <thinker@codemud.net>
parents:
739
diff
changeset
|
160 } |
d8764f10e141
Remove a coord from the tree in JS
Thinker K.F. Li <thinker@codemud.net>
parents:
739
diff
changeset
|
161 } |
d8764f10e141
Remove a coord from the tree in JS
Thinker K.F. Li <thinker@codemud.net>
parents:
739
diff
changeset
|
162 |
680
a588eefd3f04
Refactor to xnjsmb_coord_mod().
Thinker K.F. Li <thinker@branda.to>
parents:
667
diff
changeset
|
163 static void |
a588eefd3f04
Refactor to xnjsmb_coord_mod().
Thinker K.F. Li <thinker@branda.to>
parents:
667
diff
changeset
|
164 xnjsmb_coord_mod(Handle<Object> self, coord_t *coord) { |
a588eefd3f04
Refactor to xnjsmb_coord_mod().
Thinker K.F. Li <thinker@branda.to>
parents:
667
diff
changeset
|
165 Persistent<Object> *self_hdl; |
a588eefd3f04
Refactor to xnjsmb_coord_mod().
Thinker K.F. Li <thinker@branda.to>
parents:
667
diff
changeset
|
166 subject_t *subject; |
a588eefd3f04
Refactor to xnjsmb_coord_mod().
Thinker K.F. Li <thinker@branda.to>
parents:
667
diff
changeset
|
167 Handle<Value> subject_o; |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
810
diff
changeset
|
168 |
680
a588eefd3f04
Refactor to xnjsmb_coord_mod().
Thinker K.F. Li <thinker@branda.to>
parents:
667
diff
changeset
|
169 /* Keep associated js object in property store for retrieving, |
a588eefd3f04
Refactor to xnjsmb_coord_mod().
Thinker K.F. Li <thinker@branda.to>
parents:
667
diff
changeset
|
170 * later, without create new js object. |
a588eefd3f04
Refactor to xnjsmb_coord_mod().
Thinker K.F. Li <thinker@branda.to>
parents:
667
diff
changeset
|
171 */ |
743
dd1f3382d6a4
Create a persistent handle for coords and shapes correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
742
diff
changeset
|
172 self_hdl = new Persistent<Object>(); |
dd1f3382d6a4
Create a persistent handle for coords and shapes correctly
Thinker K.F. Li <thinker@codemud.net>
parents:
742
diff
changeset
|
173 *self_hdl = Persistent<Object>::New(self); |
680
a588eefd3f04
Refactor to xnjsmb_coord_mod().
Thinker K.F. Li <thinker@branda.to>
parents:
667
diff
changeset
|
174 mb_prop_set(&coord->obj.props, PROP_JSOBJ, self_hdl); |
a588eefd3f04
Refactor to xnjsmb_coord_mod().
Thinker K.F. Li <thinker@branda.to>
parents:
667
diff
changeset
|
175 |
a588eefd3f04
Refactor to xnjsmb_coord_mod().
Thinker K.F. Li <thinker@branda.to>
parents:
667
diff
changeset
|
176 subject = coord->mouse_event; |
a588eefd3f04
Refactor to xnjsmb_coord_mod().
Thinker K.F. Li <thinker@branda.to>
parents:
667
diff
changeset
|
177 subject_o = export_xnjsmb_auto_subject_new(subject); |
a588eefd3f04
Refactor to xnjsmb_coord_mod().
Thinker K.F. Li <thinker@branda.to>
parents:
667
diff
changeset
|
178 SET(self, "mouse_event", subject_o); |
741
d8764f10e141
Remove a coord from the tree in JS
Thinker K.F. Li <thinker@codemud.net>
parents:
739
diff
changeset
|
179 SET(self, "valid", Boolean::New(1)); |
680
a588eefd3f04
Refactor to xnjsmb_coord_mod().
Thinker K.F. Li <thinker@branda.to>
parents:
667
diff
changeset
|
180 } |
a588eefd3f04
Refactor to xnjsmb_coord_mod().
Thinker K.F. Li <thinker@branda.to>
parents:
667
diff
changeset
|
181 |
661
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
182 static float |
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
183 coord_get_index(coord_t *coord, Handle<Object> self, int idx, |
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
184 const char **err) { |
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
185 if(idx < 0 || idx >= 6) { |
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
186 *err = "Invalid index: out of range"; |
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
187 return 0; |
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
188 } |
557
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
189 |
661
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
190 return coord_get_matrix(coord)[idx]; |
557
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
191 } |
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
192 |
661
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
193 static float |
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
194 coord_set_index(coord_t *coord, Handle<Object> self, |
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
195 int idx, float v, const char **err) { |
560
ce7a35abcb0d
Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
557
diff
changeset
|
196 Handle<Object> js_rt; |
557
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
197 redraw_man_t *rdman; |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
810
diff
changeset
|
198 |
661
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
199 if(idx < 0 || idx >= 6) { |
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
200 *err = "Invalid index: out of range"; |
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
201 return 0; |
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
202 } |
557
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
203 |
1423
d82a828e8e26
Optimize the performance. If properties is not changed, we don't call rdman_coord_changed.
wycc
parents:
1416
diff
changeset
|
204 if (coord_get_matrix(coord)[idx] == v) return v; |
d82a828e8e26
Optimize the performance. If properties is not changed, we don't call rdman_coord_changed.
wycc
parents:
1416
diff
changeset
|
205 |
661
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
206 coord_get_matrix(coord)[idx] = v; |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
810
diff
changeset
|
207 |
560
ce7a35abcb0d
Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
557
diff
changeset
|
208 js_rt = GET(self, "mbrt")->ToObject(); |
ce7a35abcb0d
Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
557
diff
changeset
|
209 rdman = xnjsmb_rt_rdman(js_rt); |
557
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
210 rdman_coord_changed(rdman, coord); |
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
211 |
661
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
212 return v; |
557
0ca8437a91fa
Implement Indexed Property interceptors
Thinker K.F. Li <thinker@branda.to>
parents:
diff
changeset
|
213 } |
560
ce7a35abcb0d
Function to instantiate coord for Javascript
Thinker K.F. Li <thinker@branda.to>
parents:
557
diff
changeset
|
214 |
661
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
215 static void |
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
216 xnjsmb_coord_add_shape(coord_t *coord, Handle<Object> self, |
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
217 shape_t *shape, const char **err) { |
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
218 Handle<Object> js_rt; |
748
56a5e08cd8af
Make shapes can be removed from the tree
Thinker K.F. Li <thinker@codemud.net>
parents:
746
diff
changeset
|
219 Persistent<Object> *shape_hdl; |
566
6639d386db78
Function of add a shape to a coord in Javascript.
Thinker K.F. Li <thinker@branda.to>
parents:
563
diff
changeset
|
220 redraw_man_t *rdman; |
6639d386db78
Function of add a shape to a coord in Javascript.
Thinker K.F. Li <thinker@branda.to>
parents:
563
diff
changeset
|
221 int r; |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
810
diff
changeset
|
222 |
661
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
223 js_rt = GET(self, "mbrt")->ToObject(); |
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
224 rdman = xnjsmb_rt_rdman(js_rt); |
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
225 r = rdman_add_shape(rdman, shape, coord); |
566
6639d386db78
Function of add a shape to a coord in Javascript.
Thinker K.F. Li <thinker@branda.to>
parents:
563
diff
changeset
|
226 if(r != 0) |
661
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
227 *err = "Unknown error"; |
748
56a5e08cd8af
Make shapes can be removed from the tree
Thinker K.F. Li <thinker@codemud.net>
parents:
746
diff
changeset
|
228 |
56a5e08cd8af
Make shapes can be removed from the tree
Thinker K.F. Li <thinker@codemud.net>
parents:
746
diff
changeset
|
229 /* see \ref jsgc */ |
56a5e08cd8af
Make shapes can be removed from the tree
Thinker K.F. Li <thinker@codemud.net>
parents:
746
diff
changeset
|
230 shape_hdl = (Persistent<Object> *)mb_prop_get(&shape->obj.props, |
56a5e08cd8af
Make shapes can be removed from the tree
Thinker K.F. Li <thinker@codemud.net>
parents:
746
diff
changeset
|
231 PROP_JSOBJ); |
56a5e08cd8af
Make shapes can be removed from the tree
Thinker K.F. Li <thinker@codemud.net>
parents:
746
diff
changeset
|
232 shape_hdl->ClearWeak(); |
778
61c217f8cec8
Fix bug of transformation from user space to image space.
Thinker K.F. Li <thinker@codemud.net>
parents:
768
diff
changeset
|
233 rdman_shape_changed(rdman, shape); |
566
6639d386db78
Function of add a shape to a coord in Javascript.
Thinker K.F. Li <thinker@branda.to>
parents:
563
diff
changeset
|
234 } |
6639d386db78
Function of add a shape to a coord in Javascript.
Thinker K.F. Li <thinker@branda.to>
parents:
563
diff
changeset
|
235 |
741
d8764f10e141
Remove a coord from the tree in JS
Thinker K.F. Li <thinker@codemud.net>
parents:
739
diff
changeset
|
236 static void |
745
4ccb0553e804
Refactor code of free C objects into xnjsmb_coord_free_subtree
Thinker K.F. Li <thinker@codemud.net>
parents:
744
diff
changeset
|
237 xnjsmb_coord_remove(coord_t *coord, Handle<Object> self) { |
4ccb0553e804
Refactor code of free C objects into xnjsmb_coord_free_subtree
Thinker K.F. Li <thinker@codemud.net>
parents:
744
diff
changeset
|
238 Handle<Object> js_rt; |
4ccb0553e804
Refactor code of free C objects into xnjsmb_coord_free_subtree
Thinker K.F. Li <thinker@codemud.net>
parents:
744
diff
changeset
|
239 redraw_man_t *rdman; |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
810
diff
changeset
|
240 |
745
4ccb0553e804
Refactor code of free C objects into xnjsmb_coord_free_subtree
Thinker K.F. Li <thinker@codemud.net>
parents:
744
diff
changeset
|
241 if(!GET(self, "valid")->ToBoolean()->Value()) /* Invalidated object */ |
4ccb0553e804
Refactor code of free C objects into xnjsmb_coord_free_subtree
Thinker K.F. Li <thinker@codemud.net>
parents:
744
diff
changeset
|
242 THROW_noret("Invalid object"); |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
810
diff
changeset
|
243 |
745
4ccb0553e804
Refactor code of free C objects into xnjsmb_coord_free_subtree
Thinker K.F. Li <thinker@codemud.net>
parents:
744
diff
changeset
|
244 js_rt = GET(self, "mbrt")->ToObject(); |
4ccb0553e804
Refactor code of free C objects into xnjsmb_coord_free_subtree
Thinker K.F. Li <thinker@codemud.net>
parents:
744
diff
changeset
|
245 rdman = xnjsmb_rt_rdman(js_rt); |
4ccb0553e804
Refactor code of free C objects into xnjsmb_coord_free_subtree
Thinker K.F. Li <thinker@codemud.net>
parents:
744
diff
changeset
|
246 |
4ccb0553e804
Refactor code of free C objects into xnjsmb_coord_free_subtree
Thinker K.F. Li <thinker@codemud.net>
parents:
744
diff
changeset
|
247 xnjsmb_coord_invalidate_subtree(coord); |
4ccb0553e804
Refactor code of free C objects into xnjsmb_coord_free_subtree
Thinker K.F. Li <thinker@codemud.net>
parents:
744
diff
changeset
|
248 xnjsmb_coord_free_subtree(rdman, coord); |
741
d8764f10e141
Remove a coord from the tree in JS
Thinker K.F. Li <thinker@codemud.net>
parents:
739
diff
changeset
|
249 } |
d8764f10e141
Remove a coord from the tree in JS
Thinker K.F. Li <thinker@codemud.net>
parents:
739
diff
changeset
|
250 |
1377
8ecee58c85c6
Fix issue of crashing for cloned subtree
Thinker K.F. Li <thinker@codemud.net>
parents:
1372
diff
changeset
|
251 static void |
8ecee58c85c6
Fix issue of crashing for cloned subtree
Thinker K.F. Li <thinker@codemud.net>
parents:
1372
diff
changeset
|
252 _xnjsmb_coord_clone_from_subtree_mod(Handle<Object> src, Handle<Value> ret) { |
8ecee58c85c6
Fix issue of crashing for cloned subtree
Thinker K.F. Li <thinker@codemud.net>
parents:
1372
diff
changeset
|
253 Handle<Object> js_rt; |
8ecee58c85c6
Fix issue of crashing for cloned subtree
Thinker K.F. Li <thinker@codemud.net>
parents:
1372
diff
changeset
|
254 Handle<Object> ret_obj = ret->ToObject(); |
1416
c60a978f98b1
Fix issue of seg. fault at xnjsmb_coord_invalidate_subtree().
Thinker K.F. Li <thinker@codemud.net>
parents:
1415
diff
changeset
|
255 coord_t *ret_coord, *child; |
c60a978f98b1
Fix issue of seg. fault at xnjsmb_coord_invalidate_subtree().
Thinker K.F. Li <thinker@codemud.net>
parents:
1415
diff
changeset
|
256 Handle<Object> child_obj; |
1377
8ecee58c85c6
Fix issue of crashing for cloned subtree
Thinker K.F. Li <thinker@codemud.net>
parents:
1372
diff
changeset
|
257 |
8ecee58c85c6
Fix issue of crashing for cloned subtree
Thinker K.F. Li <thinker@codemud.net>
parents:
1372
diff
changeset
|
258 js_rt = GET(src, "mbrt")->ToObject(); |
8ecee58c85c6
Fix issue of crashing for cloned subtree
Thinker K.F. Li <thinker@codemud.net>
parents:
1372
diff
changeset
|
259 SET(ret_obj, "mbrt", js_rt); |
1416
c60a978f98b1
Fix issue of seg. fault at xnjsmb_coord_invalidate_subtree().
Thinker K.F. Li <thinker@codemud.net>
parents:
1415
diff
changeset
|
260 |
c60a978f98b1
Fix issue of seg. fault at xnjsmb_coord_invalidate_subtree().
Thinker K.F. Li <thinker@codemud.net>
parents:
1415
diff
changeset
|
261 /* Only root of the subtree is warpped. Descendants of subtree |
c60a978f98b1
Fix issue of seg. fault at xnjsmb_coord_invalidate_subtree().
Thinker K.F. Li <thinker@codemud.net>
parents:
1415
diff
changeset
|
262 * are not wrapped by JS object. We have no any method to access |
c60a978f98b1
Fix issue of seg. fault at xnjsmb_coord_invalidate_subtree().
Thinker K.F. Li <thinker@codemud.net>
parents:
1415
diff
changeset
|
263 * children and members of a coord, now. So, it is fine. But, |
c60a978f98b1
Fix issue of seg. fault at xnjsmb_coord_invalidate_subtree().
Thinker K.F. Li <thinker@codemud.net>
parents:
1415
diff
changeset
|
264 * sometime later, we will provide APIs for traveling a tree. At |
c60a978f98b1
Fix issue of seg. fault at xnjsmb_coord_invalidate_subtree().
Thinker K.F. Li <thinker@codemud.net>
parents:
1415
diff
changeset
|
265 * that time, we need to create wrappers for all descendants. |
c60a978f98b1
Fix issue of seg. fault at xnjsmb_coord_invalidate_subtree().
Thinker K.F. Li <thinker@codemud.net>
parents:
1415
diff
changeset
|
266 */ |
c60a978f98b1
Fix issue of seg. fault at xnjsmb_coord_invalidate_subtree().
Thinker K.F. Li <thinker@codemud.net>
parents:
1415
diff
changeset
|
267 ret_coord = (coord_t *)UNWRAP(ret_obj); |
c60a978f98b1
Fix issue of seg. fault at xnjsmb_coord_invalidate_subtree().
Thinker K.F. Li <thinker@codemud.net>
parents:
1415
diff
changeset
|
268 xnjsmb_coord_mod(ret_obj, ret_coord); |
1377
8ecee58c85c6
Fix issue of crashing for cloned subtree
Thinker K.F. Li <thinker@codemud.net>
parents:
1372
diff
changeset
|
269 } |
8ecee58c85c6
Fix issue of crashing for cloned subtree
Thinker K.F. Li <thinker@codemud.net>
parents:
1372
diff
changeset
|
270 |
1372
0afd598a0b30
Add clone_from_subtree() for coord object of nodejs
Thinker K.F. Li <thinker@codemud.net>
parents:
1056
diff
changeset
|
271 static coord_t * |
0afd598a0b30
Add clone_from_subtree() for coord object of nodejs
Thinker K.F. Li <thinker@codemud.net>
parents:
1056
diff
changeset
|
272 xnjsmb_coord_clone_from_subtree(coord_t *coord, Handle<Object> self, |
0afd598a0b30
Add clone_from_subtree() for coord object of nodejs
Thinker K.F. Li <thinker@codemud.net>
parents:
1056
diff
changeset
|
273 coord_t *src, const char **err) { |
0afd598a0b30
Add clone_from_subtree() for coord object of nodejs
Thinker K.F. Li <thinker@codemud.net>
parents:
1056
diff
changeset
|
274 Handle<Object> js_rt; |
0afd598a0b30
Add clone_from_subtree() for coord object of nodejs
Thinker K.F. Li <thinker@codemud.net>
parents:
1056
diff
changeset
|
275 redraw_man_t *rdman; |
0afd598a0b30
Add clone_from_subtree() for coord object of nodejs
Thinker K.F. Li <thinker@codemud.net>
parents:
1056
diff
changeset
|
276 coord_t *cloning; |
0afd598a0b30
Add clone_from_subtree() for coord object of nodejs
Thinker K.F. Li <thinker@codemud.net>
parents:
1056
diff
changeset
|
277 |
0afd598a0b30
Add clone_from_subtree() for coord object of nodejs
Thinker K.F. Li <thinker@codemud.net>
parents:
1056
diff
changeset
|
278 js_rt = GET(self, "mbrt")->ToObject(); |
0afd598a0b30
Add clone_from_subtree() for coord object of nodejs
Thinker K.F. Li <thinker@codemud.net>
parents:
1056
diff
changeset
|
279 ASSERT(js_rt != NULL); |
0afd598a0b30
Add clone_from_subtree() for coord object of nodejs
Thinker K.F. Li <thinker@codemud.net>
parents:
1056
diff
changeset
|
280 rdman = xnjsmb_rt_rdman(js_rt); |
0afd598a0b30
Add clone_from_subtree() for coord object of nodejs
Thinker K.F. Li <thinker@codemud.net>
parents:
1056
diff
changeset
|
281 |
0afd598a0b30
Add clone_from_subtree() for coord object of nodejs
Thinker K.F. Li <thinker@codemud.net>
parents:
1056
diff
changeset
|
282 cloning = rdman_coord_clone_from_subtree(rdman, coord, src); |
0afd598a0b30
Add clone_from_subtree() for coord object of nodejs
Thinker K.F. Li <thinker@codemud.net>
parents:
1056
diff
changeset
|
283 if(cloning == NULL) { |
0afd598a0b30
Add clone_from_subtree() for coord object of nodejs
Thinker K.F. Li <thinker@codemud.net>
parents:
1056
diff
changeset
|
284 *err = "can not clone a subtree (allocate memory)"; |
0afd598a0b30
Add clone_from_subtree() for coord object of nodejs
Thinker K.F. Li <thinker@codemud.net>
parents:
1056
diff
changeset
|
285 return NULL; |
0afd598a0b30
Add clone_from_subtree() for coord object of nodejs
Thinker K.F. Li <thinker@codemud.net>
parents:
1056
diff
changeset
|
286 } |
1416
c60a978f98b1
Fix issue of seg. fault at xnjsmb_coord_invalidate_subtree().
Thinker K.F. Li <thinker@codemud.net>
parents:
1415
diff
changeset
|
287 rdman_coord_changed(rdman, cloning); |
1372
0afd598a0b30
Add clone_from_subtree() for coord object of nodejs
Thinker K.F. Li <thinker@codemud.net>
parents:
1056
diff
changeset
|
288 |
0afd598a0b30
Add clone_from_subtree() for coord object of nodejs
Thinker K.F. Li <thinker@codemud.net>
parents:
1056
diff
changeset
|
289 return cloning; |
0afd598a0b30
Add clone_from_subtree() for coord object of nodejs
Thinker K.F. Li <thinker@codemud.net>
parents:
1056
diff
changeset
|
290 } |
0afd598a0b30
Add clone_from_subtree() for coord object of nodejs
Thinker K.F. Li <thinker@codemud.net>
parents:
1056
diff
changeset
|
291 |
749
ed59e659a202
Implement binding for hide/show for shapes and coords
Thinker K.F. Li <thinker@codemud.net>
parents:
748
diff
changeset
|
292 static void |
ed59e659a202
Implement binding for hide/show for shapes and coords
Thinker K.F. Li <thinker@codemud.net>
parents:
748
diff
changeset
|
293 xnjsmb_coord_show(coord_t *coord, Handle<Object> self) { |
ed59e659a202
Implement binding for hide/show for shapes and coords
Thinker K.F. Li <thinker@codemud.net>
parents:
748
diff
changeset
|
294 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
|
295 redraw_man_t *rdman; |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
810
diff
changeset
|
296 |
749
ed59e659a202
Implement binding for hide/show for shapes and coords
Thinker K.F. Li <thinker@codemud.net>
parents:
748
diff
changeset
|
297 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
|
298 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
|
299 rdman = xnjsmb_rt_rdman(js_rt); |
1423
d82a828e8e26
Optimize the performance. If properties is not changed, we don't call rdman_coord_changed.
wycc
parents:
1416
diff
changeset
|
300 if ((coord->flags & COF_HIDDEN) == 0) return; |
749
ed59e659a202
Implement binding for hide/show for shapes and coords
Thinker K.F. Li <thinker@codemud.net>
parents:
748
diff
changeset
|
301 coord_show(coord); |
ed59e659a202
Implement binding for hide/show for shapes and coords
Thinker K.F. Li <thinker@codemud.net>
parents:
748
diff
changeset
|
302 rdman_coord_changed(rdman, coord); |
ed59e659a202
Implement binding for hide/show for shapes and coords
Thinker K.F. Li <thinker@codemud.net>
parents:
748
diff
changeset
|
303 } |
ed59e659a202
Implement binding for hide/show for shapes and coords
Thinker K.F. Li <thinker@codemud.net>
parents:
748
diff
changeset
|
304 |
ed59e659a202
Implement binding for hide/show for shapes and coords
Thinker K.F. Li <thinker@codemud.net>
parents:
748
diff
changeset
|
305 static void |
ed59e659a202
Implement binding for hide/show for shapes and coords
Thinker K.F. Li <thinker@codemud.net>
parents:
748
diff
changeset
|
306 xnjsmb_coord_hide(coord_t *coord, Handle<Object> self) { |
ed59e659a202
Implement binding for hide/show for shapes and coords
Thinker K.F. Li <thinker@codemud.net>
parents:
748
diff
changeset
|
307 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
|
308 redraw_man_t *rdman; |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
810
diff
changeset
|
309 |
749
ed59e659a202
Implement binding for hide/show for shapes and coords
Thinker K.F. Li <thinker@codemud.net>
parents:
748
diff
changeset
|
310 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
|
311 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
|
312 rdman = xnjsmb_rt_rdman(js_rt); |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
810
diff
changeset
|
313 |
1423
d82a828e8e26
Optimize the performance. If properties is not changed, we don't call rdman_coord_changed.
wycc
parents:
1416
diff
changeset
|
314 if ((coord->flags & COF_HIDDEN) != 0) return; |
749
ed59e659a202
Implement binding for hide/show for shapes and coords
Thinker K.F. Li <thinker@codemud.net>
parents:
748
diff
changeset
|
315 coord_hide(coord); |
ed59e659a202
Implement binding for hide/show for shapes and coords
Thinker K.F. Li <thinker@codemud.net>
parents:
748
diff
changeset
|
316 rdman_coord_changed(rdman, coord); |
ed59e659a202
Implement binding for hide/show for shapes and coords
Thinker K.F. Li <thinker@codemud.net>
parents:
748
diff
changeset
|
317 } |
ed59e659a202
Implement binding for hide/show for shapes and coords
Thinker K.F. Li <thinker@codemud.net>
parents:
748
diff
changeset
|
318 |
810
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
778
diff
changeset
|
319 static void |
829
379fd510ba38
Define accessor for the opacity attribute of the coord
wycc
parents:
822
diff
changeset
|
320 xnjsmb_coord_set_opacity(Handle<Object> self, coord_t *coord, Handle<Value> value, const char **str) |
379fd510ba38
Define accessor for the opacity attribute of the coord
wycc
parents:
822
diff
changeset
|
321 { |
810
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
778
diff
changeset
|
322 Handle<Object> js_rt; |
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
778
diff
changeset
|
323 redraw_man_t *rdman; |
829
379fd510ba38
Define accessor for the opacity attribute of the coord
wycc
parents:
822
diff
changeset
|
324 |
810
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
778
diff
changeset
|
325 js_rt = GET(self, "mbrt")->ToObject(); |
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
778
diff
changeset
|
326 ASSERT(js_rt != NULL); |
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
778
diff
changeset
|
327 rdman = xnjsmb_rt_rdman(js_rt); |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
810
diff
changeset
|
328 |
1423
d82a828e8e26
Optimize the performance. If properties is not changed, we don't call rdman_coord_changed.
wycc
parents:
1416
diff
changeset
|
329 if (coord_get_opacity(coord) == value->NumberValue()) return; |
829
379fd510ba38
Define accessor for the opacity attribute of the coord
wycc
parents:
822
diff
changeset
|
330 |
379fd510ba38
Define accessor for the opacity attribute of the coord
wycc
parents:
822
diff
changeset
|
331 coord_set_opacity(coord, value->NumberValue()); |
810
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
778
diff
changeset
|
332 rdman_coord_changed(rdman, coord); |
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
778
diff
changeset
|
333 } |
84853c8559cf
Support opacity on coords
Thinker K.F. Li <thinker@codemud.net>
parents:
778
diff
changeset
|
334 |
829
379fd510ba38
Define accessor for the opacity attribute of the coord
wycc
parents:
822
diff
changeset
|
335 static Handle<Value> |
379fd510ba38
Define accessor for the opacity attribute of the coord
wycc
parents:
822
diff
changeset
|
336 xnjsmb_coord_get_opacity(Handle<Object> self, coord_t *coord, |
379fd510ba38
Define accessor for the opacity attribute of the coord
wycc
parents:
822
diff
changeset
|
337 const char **err) { |
379fd510ba38
Define accessor for the opacity attribute of the coord
wycc
parents:
822
diff
changeset
|
338 float opacity; |
379fd510ba38
Define accessor for the opacity attribute of the coord
wycc
parents:
822
diff
changeset
|
339 |
379fd510ba38
Define accessor for the opacity attribute of the coord
wycc
parents:
822
diff
changeset
|
340 opacity = coord_get_opacity(coord); |
379fd510ba38
Define accessor for the opacity attribute of the coord
wycc
parents:
822
diff
changeset
|
341 return Number::New(opacity); |
379fd510ba38
Define accessor for the opacity attribute of the coord
wycc
parents:
822
diff
changeset
|
342 } |
379fd510ba38
Define accessor for the opacity attribute of the coord
wycc
parents:
822
diff
changeset
|
343 |
843
2bcacd29d95f
Define accessor for x and y to implement absolute location
wycc
parents:
829
diff
changeset
|
344 #define cc(i) (coord_get_matrix(coord)[i]) |
2bcacd29d95f
Define accessor for x and y to implement absolute location
wycc
parents:
829
diff
changeset
|
345 static void |
2bcacd29d95f
Define accessor for x and y to implement absolute location
wycc
parents:
829
diff
changeset
|
346 xnjsmb_coord_set_y(Handle<Object> self, coord_t *coord, Handle<Value> value, const char **str) |
2bcacd29d95f
Define accessor for x and y to implement absolute location
wycc
parents:
829
diff
changeset
|
347 { |
2bcacd29d95f
Define accessor for x and y to implement absolute location
wycc
parents:
829
diff
changeset
|
348 Handle<Object> js_rt; |
2bcacd29d95f
Define accessor for x and y to implement absolute location
wycc
parents:
829
diff
changeset
|
349 redraw_man_t *rdman; |
2bcacd29d95f
Define accessor for x and y to implement absolute location
wycc
parents:
829
diff
changeset
|
350 co_aix y,ty; |
2bcacd29d95f
Define accessor for x and y to implement absolute location
wycc
parents:
829
diff
changeset
|
351 co_aix xx,yy; |
2bcacd29d95f
Define accessor for x and y to implement absolute location
wycc
parents:
829
diff
changeset
|
352 |
2bcacd29d95f
Define accessor for x and y to implement absolute location
wycc
parents:
829
diff
changeset
|
353 js_rt = GET(self, "mbrt")->ToObject(); |
2bcacd29d95f
Define accessor for x and y to implement absolute location
wycc
parents:
829
diff
changeset
|
354 ASSERT(js_rt != NULL); |
2bcacd29d95f
Define accessor for x and y to implement absolute location
wycc
parents:
829
diff
changeset
|
355 rdman = xnjsmb_rt_rdman(js_rt); |
2bcacd29d95f
Define accessor for x and y to implement absolute location
wycc
parents:
829
diff
changeset
|
356 |
2bcacd29d95f
Define accessor for x and y to implement absolute location
wycc
parents:
829
diff
changeset
|
357 |
2bcacd29d95f
Define accessor for x and y to implement absolute location
wycc
parents:
829
diff
changeset
|
358 ty = value->NumberValue(); |
2bcacd29d95f
Define accessor for x and y to implement absolute location
wycc
parents:
829
diff
changeset
|
359 xx = GET(self,"_x")->ToNumber()->NumberValue(); |
2bcacd29d95f
Define accessor for x and y to implement absolute location
wycc
parents:
829
diff
changeset
|
360 yy = GET(self,"_y")->ToNumber()->NumberValue(); |
2bcacd29d95f
Define accessor for x and y to implement absolute location
wycc
parents:
829
diff
changeset
|
361 y = ty-cc(3)*xx-cc(4)*yy; |
2bcacd29d95f
Define accessor for x and y to implement absolute location
wycc
parents:
829
diff
changeset
|
362 coord_get_matrix(coord)[5] = y; |
2bcacd29d95f
Define accessor for x and y to implement absolute location
wycc
parents:
829
diff
changeset
|
363 rdman_coord_changed(rdman, coord); |
2bcacd29d95f
Define accessor for x and y to implement absolute location
wycc
parents:
829
diff
changeset
|
364 } |
2bcacd29d95f
Define accessor for x and y to implement absolute location
wycc
parents:
829
diff
changeset
|
365 |
2bcacd29d95f
Define accessor for x and y to implement absolute location
wycc
parents:
829
diff
changeset
|
366 static Handle<Value> |
2bcacd29d95f
Define accessor for x and y to implement absolute location
wycc
parents:
829
diff
changeset
|
367 xnjsmb_coord_get_y(Handle<Object> self, coord_t *coord, |
2bcacd29d95f
Define accessor for x and y to implement absolute location
wycc
parents:
829
diff
changeset
|
368 const char **err) { |
2bcacd29d95f
Define accessor for x and y to implement absolute location
wycc
parents:
829
diff
changeset
|
369 co_aix y; |
2bcacd29d95f
Define accessor for x and y to implement absolute location
wycc
parents:
829
diff
changeset
|
370 co_aix xx,yy; |
2bcacd29d95f
Define accessor for x and y to implement absolute location
wycc
parents:
829
diff
changeset
|
371 |
2bcacd29d95f
Define accessor for x and y to implement absolute location
wycc
parents:
829
diff
changeset
|
372 xx = GET(self,"_x")->ToNumber()->NumberValue(); |
2bcacd29d95f
Define accessor for x and y to implement absolute location
wycc
parents:
829
diff
changeset
|
373 yy = GET(self,"_y")->ToNumber()->NumberValue(); |
2bcacd29d95f
Define accessor for x and y to implement absolute location
wycc
parents:
829
diff
changeset
|
374 |
2bcacd29d95f
Define accessor for x and y to implement absolute location
wycc
parents:
829
diff
changeset
|
375 y = cc(3)*xx+cc(4)*yy+cc(5); |
2bcacd29d95f
Define accessor for x and y to implement absolute location
wycc
parents:
829
diff
changeset
|
376 return Number::New(y); |
2bcacd29d95f
Define accessor for x and y to implement absolute location
wycc
parents:
829
diff
changeset
|
377 } |
2bcacd29d95f
Define accessor for x and y to implement absolute location
wycc
parents:
829
diff
changeset
|
378 static void |
2bcacd29d95f
Define accessor for x and y to implement absolute location
wycc
parents:
829
diff
changeset
|
379 xnjsmb_coord_set_x(Handle<Object> self, coord_t *coord, Handle<Value> value, const char **str) |
2bcacd29d95f
Define accessor for x and y to implement absolute location
wycc
parents:
829
diff
changeset
|
380 { |
2bcacd29d95f
Define accessor for x and y to implement absolute location
wycc
parents:
829
diff
changeset
|
381 Handle<Object> js_rt; |
2bcacd29d95f
Define accessor for x and y to implement absolute location
wycc
parents:
829
diff
changeset
|
382 redraw_man_t *rdman; |
2bcacd29d95f
Define accessor for x and y to implement absolute location
wycc
parents:
829
diff
changeset
|
383 co_aix x,tx; |
2bcacd29d95f
Define accessor for x and y to implement absolute location
wycc
parents:
829
diff
changeset
|
384 co_aix xx,yy; |
2bcacd29d95f
Define accessor for x and y to implement absolute location
wycc
parents:
829
diff
changeset
|
385 |
2bcacd29d95f
Define accessor for x and y to implement absolute location
wycc
parents:
829
diff
changeset
|
386 xx = GET(self,"_x")->ToNumber()->NumberValue(); |
2bcacd29d95f
Define accessor for x and y to implement absolute location
wycc
parents:
829
diff
changeset
|
387 yy = GET(self,"_y")->ToNumber()->NumberValue(); |
2bcacd29d95f
Define accessor for x and y to implement absolute location
wycc
parents:
829
diff
changeset
|
388 js_rt = GET(self, "mbrt")->ToObject(); |
2bcacd29d95f
Define accessor for x and y to implement absolute location
wycc
parents:
829
diff
changeset
|
389 ASSERT(js_rt != NULL); |
2bcacd29d95f
Define accessor for x and y to implement absolute location
wycc
parents:
829
diff
changeset
|
390 rdman = xnjsmb_rt_rdman(js_rt); |
2bcacd29d95f
Define accessor for x and y to implement absolute location
wycc
parents:
829
diff
changeset
|
391 |
2bcacd29d95f
Define accessor for x and y to implement absolute location
wycc
parents:
829
diff
changeset
|
392 tx = value->NumberValue(); |
2bcacd29d95f
Define accessor for x and y to implement absolute location
wycc
parents:
829
diff
changeset
|
393 x = tx-cc(0)*xx-cc(1)*yy; |
2bcacd29d95f
Define accessor for x and y to implement absolute location
wycc
parents:
829
diff
changeset
|
394 coord_get_matrix(coord)[2] = x; |
2bcacd29d95f
Define accessor for x and y to implement absolute location
wycc
parents:
829
diff
changeset
|
395 rdman_coord_changed(rdman, coord); |
2bcacd29d95f
Define accessor for x and y to implement absolute location
wycc
parents:
829
diff
changeset
|
396 } |
2bcacd29d95f
Define accessor for x and y to implement absolute location
wycc
parents:
829
diff
changeset
|
397 |
2bcacd29d95f
Define accessor for x and y to implement absolute location
wycc
parents:
829
diff
changeset
|
398 static Handle<Value> |
2bcacd29d95f
Define accessor for x and y to implement absolute location
wycc
parents:
829
diff
changeset
|
399 xnjsmb_coord_get_x(Handle<Object> self, coord_t *coord, |
2bcacd29d95f
Define accessor for x and y to implement absolute location
wycc
parents:
829
diff
changeset
|
400 const char **err) { |
2bcacd29d95f
Define accessor for x and y to implement absolute location
wycc
parents:
829
diff
changeset
|
401 co_aix x; |
2bcacd29d95f
Define accessor for x and y to implement absolute location
wycc
parents:
829
diff
changeset
|
402 co_aix xx,yy; |
2bcacd29d95f
Define accessor for x and y to implement absolute location
wycc
parents:
829
diff
changeset
|
403 |
2bcacd29d95f
Define accessor for x and y to implement absolute location
wycc
parents:
829
diff
changeset
|
404 xx = GET(self,"_x")->ToNumber()->NumberValue(); |
2bcacd29d95f
Define accessor for x and y to implement absolute location
wycc
parents:
829
diff
changeset
|
405 yy = GET(self,"_y")->ToNumber()->NumberValue(); |
2bcacd29d95f
Define accessor for x and y to implement absolute location
wycc
parents:
829
diff
changeset
|
406 |
2bcacd29d95f
Define accessor for x and y to implement absolute location
wycc
parents:
829
diff
changeset
|
407 x = cc(0)*xx+cc(1)*yy+cc(2); |
2bcacd29d95f
Define accessor for x and y to implement absolute location
wycc
parents:
829
diff
changeset
|
408 return Number::New(x); |
2bcacd29d95f
Define accessor for x and y to implement absolute location
wycc
parents:
829
diff
changeset
|
409 } |
1434
4be04f29fa70
Add functions to search for the text recursively inside coord_t tree. Once we find the first instance, we change the text of it. We need to think about how to manage the multiple segment texts, which is composed of several tspan.
wycc
parents:
1423
diff
changeset
|
410 |
4be04f29fa70
Add functions to search for the text recursively inside coord_t tree. Once we find the first instance, we change the text of it. We need to think about how to manage the multiple segment texts, which is composed of several tspan.
wycc
parents:
1423
diff
changeset
|
411 static int |
4be04f29fa70
Add functions to search for the text recursively inside coord_t tree. Once we find the first instance, we change the text of it. We need to think about how to manage the multiple segment texts, which is composed of several tspan.
wycc
parents:
1423
diff
changeset
|
412 xnjsmb_coord_set_text_recursive(coord_t *coord, Handle<Object> self, |
4be04f29fa70
Add functions to search for the text recursively inside coord_t tree. Once we find the first instance, we change the text of it. We need to think about how to manage the multiple segment texts, which is composed of several tspan.
wycc
parents:
1423
diff
changeset
|
413 const char *txt) { |
4be04f29fa70
Add functions to search for the text recursively inside coord_t tree. Once we find the first instance, we change the text of it. We need to think about how to manage the multiple segment texts, which is composed of several tspan.
wycc
parents:
1423
diff
changeset
|
414 shape_t *sh; |
4be04f29fa70
Add functions to search for the text recursively inside coord_t tree. Once we find the first instance, we change the text of it. We need to think about how to manage the multiple segment texts, which is composed of several tspan.
wycc
parents:
1423
diff
changeset
|
415 coord_t *child; |
4be04f29fa70
Add functions to search for the text recursively inside coord_t tree. Once we find the first instance, we change the text of it. We need to think about how to manage the multiple segment texts, which is composed of several tspan.
wycc
parents:
1423
diff
changeset
|
416 Handle<Object> rt; |
4be04f29fa70
Add functions to search for the text recursively inside coord_t tree. Once we find the first instance, we change the text of it. We need to think about how to manage the multiple segment texts, which is composed of several tspan.
wycc
parents:
1423
diff
changeset
|
417 redraw_man_t *rdman; |
4be04f29fa70
Add functions to search for the text recursively inside coord_t tree. Once we find the first instance, we change the text of it. We need to think about how to manage the multiple segment texts, which is composed of several tspan.
wycc
parents:
1423
diff
changeset
|
418 |
4be04f29fa70
Add functions to search for the text recursively inside coord_t tree. Once we find the first instance, we change the text of it. We need to think about how to manage the multiple segment texts, which is composed of several tspan.
wycc
parents:
1423
diff
changeset
|
419 FOR_COORD_SHAPES(coord, sh) { |
4be04f29fa70
Add functions to search for the text recursively inside coord_t tree. Once we find the first instance, we change the text of it. We need to think about how to manage the multiple segment texts, which is composed of several tspan.
wycc
parents:
1423
diff
changeset
|
420 printf("shape type %d\n",sh->obj.obj_type); |
4be04f29fa70
Add functions to search for the text recursively inside coord_t tree. Once we find the first instance, we change the text of it. We need to think about how to manage the multiple segment texts, which is composed of several tspan.
wycc
parents:
1423
diff
changeset
|
421 if (sh->obj.obj_type == MBO_STEXT) { |
4be04f29fa70
Add functions to search for the text recursively inside coord_t tree. Once we find the first instance, we change the text of it. We need to think about how to manage the multiple segment texts, which is composed of several tspan.
wycc
parents:
1423
diff
changeset
|
422 sh_stext_set_text(sh, txt); |
4be04f29fa70
Add functions to search for the text recursively inside coord_t tree. Once we find the first instance, we change the text of it. We need to think about how to manage the multiple segment texts, which is composed of several tspan.
wycc
parents:
1423
diff
changeset
|
423 /* |
4be04f29fa70
Add functions to search for the text recursively inside coord_t tree. Once we find the first instance, we change the text of it. We need to think about how to manage the multiple segment texts, which is composed of several tspan.
wycc
parents:
1423
diff
changeset
|
424 * Mark changed. |
4be04f29fa70
Add functions to search for the text recursively inside coord_t tree. Once we find the first instance, we change the text of it. We need to think about how to manage the multiple segment texts, which is composed of several tspan.
wycc
parents:
1423
diff
changeset
|
425 */ |
4be04f29fa70
Add functions to search for the text recursively inside coord_t tree. Once we find the first instance, we change the text of it. We need to think about how to manage the multiple segment texts, which is composed of several tspan.
wycc
parents:
1423
diff
changeset
|
426 rt = GET(self, "mbrt")->ToObject(); |
4be04f29fa70
Add functions to search for the text recursively inside coord_t tree. Once we find the first instance, we change the text of it. We need to think about how to manage the multiple segment texts, which is composed of several tspan.
wycc
parents:
1423
diff
changeset
|
427 ASSERT(rt != NULL); |
4be04f29fa70
Add functions to search for the text recursively inside coord_t tree. Once we find the first instance, we change the text of it. We need to think about how to manage the multiple segment texts, which is composed of several tspan.
wycc
parents:
1423
diff
changeset
|
428 rdman = xnjsmb_rt_rdman(rt); |
4be04f29fa70
Add functions to search for the text recursively inside coord_t tree. Once we find the first instance, we change the text of it. We need to think about how to manage the multiple segment texts, which is composed of several tspan.
wycc
parents:
1423
diff
changeset
|
429 |
4be04f29fa70
Add functions to search for the text recursively inside coord_t tree. Once we find the first instance, we change the text of it. We need to think about how to manage the multiple segment texts, which is composed of several tspan.
wycc
parents:
1423
diff
changeset
|
430 if(sh_get_coord(sh)) |
4be04f29fa70
Add functions to search for the text recursively inside coord_t tree. Once we find the first instance, we change the text of it. We need to think about how to manage the multiple segment texts, which is composed of several tspan.
wycc
parents:
1423
diff
changeset
|
431 rdman_shape_changed(rdman, sh); |
4be04f29fa70
Add functions to search for the text recursively inside coord_t tree. Once we find the first instance, we change the text of it. We need to think about how to manage the multiple segment texts, which is composed of several tspan.
wycc
parents:
1423
diff
changeset
|
432 return 1; |
4be04f29fa70
Add functions to search for the text recursively inside coord_t tree. Once we find the first instance, we change the text of it. We need to think about how to manage the multiple segment texts, which is composed of several tspan.
wycc
parents:
1423
diff
changeset
|
433 } |
4be04f29fa70
Add functions to search for the text recursively inside coord_t tree. Once we find the first instance, we change the text of it. We need to think about how to manage the multiple segment texts, which is composed of several tspan.
wycc
parents:
1423
diff
changeset
|
434 } |
4be04f29fa70
Add functions to search for the text recursively inside coord_t tree. Once we find the first instance, we change the text of it. We need to think about how to manage the multiple segment texts, which is composed of several tspan.
wycc
parents:
1423
diff
changeset
|
435 for((child) = STAILQ_HEAD((coord)->children); |
4be04f29fa70
Add functions to search for the text recursively inside coord_t tree. Once we find the first instance, we change the text of it. We need to think about how to manage the multiple segment texts, which is composed of several tspan.
wycc
parents:
1423
diff
changeset
|
436 (child) != NULL; |
4be04f29fa70
Add functions to search for the text recursively inside coord_t tree. Once we find the first instance, we change the text of it. We need to think about how to manage the multiple segment texts, which is composed of several tspan.
wycc
parents:
1423
diff
changeset
|
437 (child) = STAILQ_NEXT(coord_t, sibling, (child))) { |
4be04f29fa70
Add functions to search for the text recursively inside coord_t tree. Once we find the first instance, we change the text of it. We need to think about how to manage the multiple segment texts, which is composed of several tspan.
wycc
parents:
1423
diff
changeset
|
438 /* Invalidate members of a coord */ |
4be04f29fa70
Add functions to search for the text recursively inside coord_t tree. Once we find the first instance, we change the text of it. We need to think about how to manage the multiple segment texts, which is composed of several tspan.
wycc
parents:
1423
diff
changeset
|
439 if ( xnjsmb_coord_set_text_recursive(child, self, txt)) |
4be04f29fa70
Add functions to search for the text recursively inside coord_t tree. Once we find the first instance, we change the text of it. We need to think about how to manage the multiple segment texts, which is composed of several tspan.
wycc
parents:
1423
diff
changeset
|
440 return 1; |
4be04f29fa70
Add functions to search for the text recursively inside coord_t tree. Once we find the first instance, we change the text of it. We need to think about how to manage the multiple segment texts, which is composed of several tspan.
wycc
parents:
1423
diff
changeset
|
441 } |
4be04f29fa70
Add functions to search for the text recursively inside coord_t tree. Once we find the first instance, we change the text of it. We need to think about how to manage the multiple segment texts, which is composed of several tspan.
wycc
parents:
1423
diff
changeset
|
442 return 0; |
4be04f29fa70
Add functions to search for the text recursively inside coord_t tree. Once we find the first instance, we change the text of it. We need to think about how to manage the multiple segment texts, which is composed of several tspan.
wycc
parents:
1423
diff
changeset
|
443 |
4be04f29fa70
Add functions to search for the text recursively inside coord_t tree. Once we find the first instance, we change the text of it. We need to think about how to manage the multiple segment texts, which is composed of several tspan.
wycc
parents:
1423
diff
changeset
|
444 } |
4be04f29fa70
Add functions to search for the text recursively inside coord_t tree. Once we find the first instance, we change the text of it. We need to think about how to manage the multiple segment texts, which is composed of several tspan.
wycc
parents:
1423
diff
changeset
|
445 |
4be04f29fa70
Add functions to search for the text recursively inside coord_t tree. Once we find the first instance, we change the text of it. We need to think about how to manage the multiple segment texts, which is composed of several tspan.
wycc
parents:
1423
diff
changeset
|
446 static void |
4be04f29fa70
Add functions to search for the text recursively inside coord_t tree. Once we find the first instance, we change the text of it. We need to think about how to manage the multiple segment texts, which is composed of several tspan.
wycc
parents:
1423
diff
changeset
|
447 xnjsmb_coord_set_text(coord_t *coord, Handle<Object> self, |
4be04f29fa70
Add functions to search for the text recursively inside coord_t tree. Once we find the first instance, we change the text of it. We need to think about how to manage the multiple segment texts, which is composed of several tspan.
wycc
parents:
1423
diff
changeset
|
448 const char *txt) { |
4be04f29fa70
Add functions to search for the text recursively inside coord_t tree. Once we find the first instance, we change the text of it. We need to think about how to manage the multiple segment texts, which is composed of several tspan.
wycc
parents:
1423
diff
changeset
|
449 printf("text=%s\n",txt); |
4be04f29fa70
Add functions to search for the text recursively inside coord_t tree. Once we find the first instance, we change the text of it. We need to think about how to manage the multiple segment texts, which is composed of several tspan.
wycc
parents:
1423
diff
changeset
|
450 xnjsmb_coord_set_text_recursive(coord,self,txt); |
4be04f29fa70
Add functions to search for the text recursively inside coord_t tree. Once we find the first instance, we change the text of it. We need to think about how to manage the multiple segment texts, which is composed of several tspan.
wycc
parents:
1423
diff
changeset
|
451 } |
4be04f29fa70
Add functions to search for the text recursively inside coord_t tree. Once we find the first instance, we change the text of it. We need to think about how to manage the multiple segment texts, which is composed of several tspan.
wycc
parents:
1423
diff
changeset
|
452 |
4be04f29fa70
Add functions to search for the text recursively inside coord_t tree. Once we find the first instance, we change the text of it. We need to think about how to manage the multiple segment texts, which is composed of several tspan.
wycc
parents:
1423
diff
changeset
|
453 |
843
2bcacd29d95f
Define accessor for x and y to implement absolute location
wycc
parents:
829
diff
changeset
|
454 #undef m |
2bcacd29d95f
Define accessor for x and y to implement absolute location
wycc
parents:
829
diff
changeset
|
455 |
661
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
456 #include "coord-inc.h" |
562
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
457 |
684
b346e4699e55
Add more comment for JS binding
Thinker K.F. Li <thinker@branda.to>
parents:
680
diff
changeset
|
458 /*! \brief This function used by \ref xnjsmb_mb_rt to wrap coord object. |
b346e4699e55
Add more comment for JS binding
Thinker K.F. Li <thinker@branda.to>
parents:
680
diff
changeset
|
459 */ |
666
b6fb543d69ee
Use binding generator to implement mb_rt
Thinker K.F. Li <thinker@branda.to>
parents:
661
diff
changeset
|
460 Handle<Value> export_xnjsmb_auto_coord_new(coord_t *coord) { |
695 | 461 return xnjsmb_auto_coord_new(coord); |
666
b6fb543d69ee
Use binding generator to implement mb_rt
Thinker K.F. Li <thinker@branda.to>
parents:
661
diff
changeset
|
462 } |
b6fb543d69ee
Use binding generator to implement mb_rt
Thinker K.F. Li <thinker@branda.to>
parents:
661
diff
changeset
|
463 |
562
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
464 /*! \brief Initialize Javascript object for root coord of a runtime. |
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
465 * |
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
466 * \param js_rt is the runtime object to create the root object for. |
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
467 * |
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
468 * After the function, js_rt.root is the object for root coord in |
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
469 * Javascript. |
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
470 */ |
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
471 void |
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
472 xnjsmb_coord_mkroot(Handle<Object> js_rt) { |
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
473 redraw_man_t *rdman; |
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
474 coord_t *root; |
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
475 Handle<Object> obj; |
661
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
476 static int init_flag = 0; |
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
477 |
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
478 if(!init_flag) { |
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
479 xnjsmb_auto_coord_init(); |
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
480 init_flag = 1; |
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
481 } |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
810
diff
changeset
|
482 |
562
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
483 rdman = xnjsmb_rt_rdman(js_rt); |
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
484 root = rdman_get_root(rdman); |
661
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
485 obj = xnjsmb_auto_coord_new(root).As<Object>(); |
90c7726bc953
Replace part code of coord.cc by the code generated by generator
Thinker K.F. Li <thinker@branda.to>
parents:
566
diff
changeset
|
486 SET(obj, "mbrt", js_rt); |
562
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
487 |
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
488 SET(js_rt, "root", obj); |
1b6402f07cd4
Make root coord availabe for Javascript code
Thinker K.F. Li <thinker@branda.to>
parents:
560
diff
changeset
|
489 } |
684
b346e4699e55
Add more comment for JS binding
Thinker K.F. Li <thinker@branda.to>
parents:
680
diff
changeset
|
490 |
b346e4699e55
Add more comment for JS binding
Thinker K.F. Li <thinker@branda.to>
parents:
680
diff
changeset
|
491 /* @} */ |