Mercurial > MadButterfly
comparison 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 |
comparison
equal
deleted
inserted
replaced
564:0cd1511272d2 | 565:c0bc60448913 |
---|---|
5 #include <mb.h> | 5 #include <mb.h> |
6 } | 6 } |
7 | 7 |
8 using namespace v8; | 8 using namespace v8; |
9 | 9 |
10 /*! \defgroup shape_temp Templates for shape and derive. | 10 /*! \defgroup shape_temp Templates for shape and derivations. |
11 * | 11 * |
12 * @{ | 12 * @{ |
13 */ | 13 */ |
14 static Persistent<FunctionTemplate> xnjsmb_shape_temp; | 14 static Persistent<FunctionTemplate> xnjsmb_shape_temp; |
15 | 15 |
54 SET(proto_temp, "hide", method_temp); | 54 SET(proto_temp, "hide", method_temp); |
55 } | 55 } |
56 | 56 |
57 /* @} */ | 57 /* @} */ |
58 | 58 |
59 /*! \defgroup path_temp Templates for path objects. | |
60 * | |
61 * @{ | |
62 */ | |
63 static Persistent<FunctionTemplate> xnjsmb_path_temp; | |
64 | |
65 /*! \brief Callback of constructor of path objects for Javascript. | |
66 */ | |
67 static Handle<Value> | |
68 xnjsmb_shape_path(const Arguments &args) { | |
69 shape_t *sh; | |
70 redraw_man_t *rdman; | |
71 Handle<Object> self = args.This(); // path object | |
72 Handle<Object> rt; | |
73 char *dstr; | |
74 int argc; | |
75 | |
76 argc = args.Length(); | |
77 if(argc != 2) | |
78 THROW("Invalid number of arugments (!= 1)"); | |
79 if(!args[0]->IsString()) | |
80 THROW("Invalid argument type (should be a string)"); | |
81 if(!args[1]->IsObject()) | |
82 THROW("Invalid argument type (should be an object)"); | |
83 | |
84 String::Utf8Value dutf8(args[0]->ToString()); | |
85 dstr = *dutf8; | |
86 | |
87 rt = args[1]->ToObject(); | |
88 rdman = xnjsmb_rt_rdman(rt); | |
89 sh = rdman_shape_path_new(rdman, dstr); | |
90 | |
91 WRAP(self, sh); | |
92 | |
93 return Null(); | |
94 } | |
95 | |
96 /*! \brief Initial function template for constructor of path objects. | |
97 */ | |
98 static void | |
99 xnjsmb_init_path_temp(void) { | |
100 Handle<FunctionTemplate> temp; | |
101 Handle<ObjectTemplate> inst_temp; | |
102 | |
103 temp = FunctionTemplate::New(xnjsmb_shape_path); | |
104 temp->Inherit(xnjsmb_shape_temp); | |
105 temp->SetClassName(String::New("path")); | |
106 | |
107 inst_temp = temp->InstanceTemplate(); | |
108 inst_temp->SetInternalFieldCount(1); | |
109 | |
110 xnjsmb_path_temp = Persistent<FunctionTemplate>::New(temp); | |
111 } | |
112 | |
113 /*! \brief Callback function of mb_rt.path_new(). | |
114 */ | |
115 static Handle<Value> | |
116 xnjsmb_shape_path_new(const Arguments &args) { | |
117 HandleScope scope; | |
118 Handle<Object> self = args.This(); // runtime object | |
119 Handle<Object> path_obj; | |
120 Handle<Value> path_args[2]; | |
121 int argc; | |
122 | |
123 argc = args.Length(); | |
124 if(argc != 1) | |
125 THROW("Invalid number of arugments (!= 1)"); | |
126 if(!args[0]->IsString()) | |
127 THROW("Invalid argument type (shoud be a string)"); | |
128 | |
129 path_args[0] = args[0]; | |
130 path_args[1] = self; | |
131 | |
132 path_obj = xnjsmb_path_temp->GetFunction()->NewInstance(2, path_args); | |
133 | |
134 scope.Close(path_obj); | |
135 return path_obj; | |
136 } | |
137 | |
138 /* @} */ | |
139 | |
140 /*! \brief Set properties of template of mb_rt. | |
141 */ | |
142 void | |
143 xnjsmb_shapes_init_mb_rt_temp(Handle<FunctionTemplate> rt_temp) { | |
144 Handle<FunctionTemplate> path_new_temp; | |
145 Handle<ObjectTemplate> rt_proto_temp; | |
146 static int temp_init_flag = 0; | |
147 | |
148 if(temp_init_flag == 0) { | |
149 xnjsmb_init_shape_temp(); | |
150 xnjsmb_init_path_temp(); | |
151 temp_init_flag = 1; | |
152 } | |
153 | |
154 rt_proto_temp = rt_temp->PrototypeTemplate(); | |
155 | |
156 path_new_temp = FunctionTemplate::New(xnjsmb_shape_path_new); | |
157 SET(rt_proto_temp, "path_new", path_new_temp); | |
158 } |