Mercurial > MadButterfly
annotate nodejs/shapes.cc @ 565:c0bc60448913 Android_Skia
Constructor for path objects in Javascript domain
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Mon, 07 Jun 2010 22:37:51 +0800 |
parents | 0cd1511272d2 |
children | f87a368e847a |
rev | line source |
---|---|
564 | 1 #include <v8.h> |
2 #include "mbfly_njs.h" | |
3 | |
4 extern "C" { | |
5 #include <mb.h> | |
6 } | |
7 | |
8 using namespace v8; | |
9 | |
565
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
10 /*! \defgroup shape_temp Templates for shape and derivations. |
564 | 11 * |
12 * @{ | |
13 */ | |
14 static Persistent<FunctionTemplate> xnjsmb_shape_temp; | |
15 | |
16 static Handle<Value> | |
17 xnjsmb_shape_show(const Arguments &args) { | |
18 shape_t *sh; | |
19 Handle<Object> self; | |
20 | |
21 self = args.This(); | |
22 sh = (shape_t *)UNWRAP(self); | |
23 sh_show(sh); | |
24 | |
25 return Null(); | |
26 } | |
27 | |
28 static Handle<Value> | |
29 xnjsmb_shape_hide(const Arguments &args) { | |
30 shape_t *sh; | |
31 Handle<Object> self; | |
32 | |
33 self = args.This(); | |
34 sh = (shape_t *)UNWRAP(self); | |
35 sh_hide(sh); | |
36 | |
37 return Null(); | |
38 } | |
39 | |
40 static void | |
41 xnjsmb_init_shape_temp(void) { | |
42 Handle<FunctionTemplate> temp; | |
43 Handle<ObjectTemplate> proto_temp; | |
44 Handle<FunctionTemplate> method_temp; | |
45 | |
46 temp = FunctionTemplate::New(); | |
47 temp->SetClassName(String::New("shape")); | |
48 xnjsmb_shape_temp = Persistent<FunctionTemplate>::New(temp); | |
49 proto_temp = temp->PrototypeTemplate(); | |
50 | |
51 method_temp = FunctionTemplate::New(xnjsmb_shape_show); | |
52 SET(proto_temp, "show", method_temp); | |
53 method_temp = FunctionTemplate::New(xnjsmb_shape_hide); | |
54 SET(proto_temp, "hide", method_temp); | |
55 } | |
56 | |
57 /* @} */ | |
58 | |
565
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
59 /*! \defgroup path_temp Templates for path objects. |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
60 * |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
61 * @{ |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
62 */ |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
63 static Persistent<FunctionTemplate> xnjsmb_path_temp; |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
64 |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
65 /*! \brief Callback of constructor of path objects for Javascript. |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
66 */ |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
67 static Handle<Value> |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
68 xnjsmb_shape_path(const Arguments &args) { |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
69 shape_t *sh; |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
70 redraw_man_t *rdman; |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
71 Handle<Object> self = args.This(); // path object |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
72 Handle<Object> rt; |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
73 char *dstr; |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
74 int argc; |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
75 |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
76 argc = args.Length(); |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
77 if(argc != 2) |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
78 THROW("Invalid number of arugments (!= 1)"); |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
79 if(!args[0]->IsString()) |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
80 THROW("Invalid argument type (should be a string)"); |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
81 if(!args[1]->IsObject()) |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
82 THROW("Invalid argument type (should be an object)"); |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
83 |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
84 String::Utf8Value dutf8(args[0]->ToString()); |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
85 dstr = *dutf8; |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
86 |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
87 rt = args[1]->ToObject(); |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
88 rdman = xnjsmb_rt_rdman(rt); |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
89 sh = rdman_shape_path_new(rdman, dstr); |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
90 |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
91 WRAP(self, sh); |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
92 |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
93 return Null(); |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
94 } |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
95 |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
96 /*! \brief Initial function template for constructor of path objects. |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
97 */ |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
98 static void |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
99 xnjsmb_init_path_temp(void) { |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
100 Handle<FunctionTemplate> temp; |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
101 Handle<ObjectTemplate> inst_temp; |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
102 |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
103 temp = FunctionTemplate::New(xnjsmb_shape_path); |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
104 temp->Inherit(xnjsmb_shape_temp); |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
105 temp->SetClassName(String::New("path")); |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
106 |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
107 inst_temp = temp->InstanceTemplate(); |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
108 inst_temp->SetInternalFieldCount(1); |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
109 |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
110 xnjsmb_path_temp = Persistent<FunctionTemplate>::New(temp); |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
111 } |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
112 |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
113 /*! \brief Callback function of mb_rt.path_new(). |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
114 */ |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
115 static Handle<Value> |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
116 xnjsmb_shape_path_new(const Arguments &args) { |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
117 HandleScope scope; |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
118 Handle<Object> self = args.This(); // runtime object |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
119 Handle<Object> path_obj; |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
120 Handle<Value> path_args[2]; |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
121 int argc; |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
122 |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
123 argc = args.Length(); |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
124 if(argc != 1) |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
125 THROW("Invalid number of arugments (!= 1)"); |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
126 if(!args[0]->IsString()) |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
127 THROW("Invalid argument type (shoud be a string)"); |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
128 |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
129 path_args[0] = args[0]; |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
130 path_args[1] = self; |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
131 |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
132 path_obj = xnjsmb_path_temp->GetFunction()->NewInstance(2, path_args); |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
133 |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
134 scope.Close(path_obj); |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
135 return path_obj; |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
136 } |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
137 |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
138 /* @} */ |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
139 |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
140 /*! \brief Set properties of template of mb_rt. |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
141 */ |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
142 void |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
143 xnjsmb_shapes_init_mb_rt_temp(Handle<FunctionTemplate> rt_temp) { |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
144 Handle<FunctionTemplate> path_new_temp; |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
145 Handle<ObjectTemplate> rt_proto_temp; |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
146 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
|
147 |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
148 if(temp_init_flag == 0) { |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
149 xnjsmb_init_shape_temp(); |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
150 xnjsmb_init_path_temp(); |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
151 temp_init_flag = 1; |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
152 } |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
153 |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
154 rt_proto_temp = rt_temp->PrototypeTemplate(); |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
155 |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
156 path_new_temp = FunctionTemplate::New(xnjsmb_shape_path_new); |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
157 SET(rt_proto_temp, "path_new", path_new_temp); |
c0bc60448913
Constructor for path objects in Javascript domain
Thinker K.F. Li <thinker@branda.to>
parents:
564
diff
changeset
|
158 } |