Mercurial > MadButterfly
comparison nodejs/mbfly_njs.cc @ 666:b6fb543d69ee
Use binding generator to implement mb_rt
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Wed, 04 Aug 2010 21:35:40 +0800 |
parents | dc32c1c140ae |
children | fc29a343ce7c |
comparison
equal
deleted
inserted
replaced
665:7db0b76c9480 | 666:b6fb543d69ee |
---|---|
1 #include <stdio.h> | 1 #include <stdio.h> |
2 #include <string.h> | |
2 #include <v8.h> | 3 #include <v8.h> |
3 | 4 |
4 extern "C" { | 5 extern "C" { |
5 #include "X_supp_njs.h" | 6 #include "X_supp_njs.h" |
6 } | 7 } |
7 | 8 |
8 #include "mbfly_njs.h" | 9 #include "mbfly_njs.h" |
9 | 10 |
10 using namespace v8; | 11 using namespace v8; |
11 | 12 |
13 static coord_t * | |
14 xnjsmb_coord_new(njs_runtime_t *rt, coord_t *parent, const char **err) { | |
15 coord_t *coord; | |
16 redraw_man_t *rdman; | |
17 | |
18 rdman = X_njs_MB_rdman(rt); | |
19 coord = rdman_coord_new(rdman, parent); | |
20 if(coord == NULL) { | |
21 *err = "Can not allocate a redraw_man_t"; | |
22 return NULL; | |
23 } | |
24 | |
25 return coord; | |
26 } | |
27 | |
28 static void | |
29 xnjsmb_coord_mod(Handle<Object> mbrt, Handle<Value> ret) { | |
30 Handle<Object> ret_obj = ret->ToObject(); | |
31 | |
32 SET(ret_obj, "mbrt", mbrt); | |
33 } | |
34 | |
35 #define xnjsmb_auto_coord_new export_xnjsmb_auto_coord_new | |
36 | |
37 static void | |
38 xnjsmb_redraw_changed(njs_runtime_t *rt) { | |
39 redraw_man_t *rdman; | |
40 | |
41 rdman = X_njs_MB_rdman(rt); | |
42 rdman_redraw_changed(rdman); | |
43 } | |
44 | |
45 static void | |
46 xnjsmb_redraw_all(njs_runtime_t *rt) { | |
47 redraw_man_t *rdman; | |
48 | |
49 rdman = X_njs_MB_rdman(rt); | |
50 rdman_redraw_all(rdman); | |
51 } | |
52 | |
53 static njs_runtime_t * | |
54 _X_njs_MB_new(Handle<Object> self, char *display_name, | |
55 int width, int height) { | |
56 njs_runtime_t *obj; | |
57 | |
58 obj = X_njs_MB_new(display_name, width, height); | |
59 WRAP(self, obj); /* mkroot need a wrapped object, but | |
60 * it is wrapped after returning of | |
61 * this function. So, we wrap it | |
62 * here. */ | |
63 X_njs_MB_init_handle_connection(obj); | |
64 xnjsmb_coord_mkroot(self); | |
65 | |
66 return obj; | |
67 } | |
68 | |
12 /*! \defgroup njs_template_cb Callback functions for v8 engine and nodejs. | 69 /*! \defgroup njs_template_cb Callback functions for v8 engine and nodejs. |
13 * | 70 * |
14 * @{ | 71 * @{ |
15 */ | 72 */ |
16 | 73 |
17 /*! \brief to Create a njs runtime object for MadButterfly. | 74 #include "mbfly_njs-inc.h" |
18 * | |
19 * Three arguments are requried. They are | |
20 * - display name, | |
21 * - width, and | |
22 * - height. | |
23 */ | |
24 static Handle<Value> | |
25 xnjsmb_new(const Arguments &args) { | |
26 HandleScope scope; | |
27 int argc; | |
28 Handle<Value> exc; | |
29 njs_runtime_t *rt; | |
30 char *display_name; | |
31 int width, height; | |
32 Handle<Object> self; | |
33 | |
34 argc = args.Length(); | |
35 if(argc != 3) { | |
36 exc = Exception::Error(String::New("Need 3 arguments.")); | |
37 return ThrowException(exc); | |
38 } | |
39 | |
40 if(!args[0]->IsString() || !args[1]->IsInt32() || !args[2]->IsInt32()) { | |
41 exc = Exception::Error(String::New("Invalid argument type.")); | |
42 return ThrowException(exc); | |
43 } | |
44 | |
45 String::Utf8Value disp_utf8(args[0]->ToString()); | |
46 display_name = *disp_utf8; | |
47 width = args[1]->Int32Value(); | |
48 height = args[2]->Int32Value(); | |
49 rt = X_njs_MB_new(display_name, width, height); | |
50 | |
51 self = args.This(); | |
52 WRAP(self, rt); | |
53 xnjsmb_coord_mkroot(self); | |
54 | |
55 X_njs_MB_init_handle_connection(rt); | |
56 | |
57 return Null(); | |
58 } | |
59 | |
60 static Handle<Value> | |
61 xnjsmb_handle_connection(const Arguments &args) { | |
62 } | |
63 | |
64 static Handle<Value> | |
65 xnjsmb_rt_redraw_changed(const Arguments &args) { | |
66 Handle<Object> self = args.This(); | |
67 njs_runtime_t *rt; | |
68 redraw_man_t *rdman; | |
69 | |
70 rdman = xnjsmb_rt_rdman(self); | |
71 rdman_redraw_changed(rdman); | |
72 | |
73 rt = (njs_runtime_t *)UNWRAP(self); | |
74 X_njs_MB_flush(rt); | |
75 | |
76 return Null(); | |
77 } | |
78 | |
79 static Handle<Value> | |
80 xnjsmb_rt_redraw_all(const Arguments &args) { | |
81 Handle<Object> self = args.This(); | |
82 njs_runtime_t *rt; | |
83 redraw_man_t *rdman; | |
84 | |
85 rdman = xnjsmb_rt_rdman(self); | |
86 rdman_redraw_all(rdman); | |
87 | |
88 rt = (njs_runtime_t *)UNWRAP(self); | |
89 X_njs_MB_flush(rt); | |
90 | |
91 return Null(); | |
92 } | |
93 | 75 |
94 /* @} */ | 76 /* @} */ |
95 | 77 |
96 /*! \brief Get rdman associated with the runtime. | 78 /*! \brief Get rdman associated with the runtime. |
97 */ | 79 */ |
124 target->Set(String::New("Hello"), func->GetFunction()); | 106 target->Set(String::New("Hello"), func->GetFunction()); |
125 | 107 |
126 /* | 108 /* |
127 * Initialize template for MadButterfly runtime objects. | 109 * Initialize template for MadButterfly runtime objects. |
128 */ | 110 */ |
129 mb_rt_func = FunctionTemplate::New(xnjsmb_new); | 111 xnjsmb_auto_mb_rt_init(); |
130 mb_rt_func->SetClassName(String::New("mb_rt")); | |
131 | |
132 rt_instance_temp = mb_rt_func->InstanceTemplate(); | |
133 rt_instance_temp->SetInternalFieldCount(1); | |
134 | |
135 rt_proto_temp = mb_rt_func->PrototypeTemplate(); | |
136 func = FunctionTemplate::New(xnjsmb_coord_new); | |
137 SET(rt_proto_temp, "coord_new", func); | |
138 | |
139 func = FunctionTemplate::New(xnjsmb_rt_redraw_changed); | |
140 SET(rt_proto_temp, "redraw_changed", func); | |
141 | |
142 func = FunctionTemplate::New(xnjsmb_rt_redraw_all); | |
143 SET(rt_proto_temp, "redraw_all", func); | |
144 | 112 |
145 /* | 113 /* |
146 * Add properties to mb_rt templates for other modules. | 114 * Add properties to mb_rt templates for other modules. |
147 */ | 115 */ |
148 xnjsmb_shapes_init_mb_rt_temp(mb_rt_func); | 116 xnjsmb_shapes_init_mb_rt_temp(xnjsmb_auto_mb_rt_temp); |
149 xnjsmb_paints_init_mb_rt_temp(mb_rt_func); | 117 xnjsmb_paints_init_mb_rt_temp(xnjsmb_auto_mb_rt_temp); |
150 xnjsmb_font_init_mb_rt_temp(mb_rt_func); | 118 xnjsmb_font_init_mb_rt_temp(xnjsmb_auto_mb_rt_temp); |
151 xnjsmb_img_ldr_init_mb_rt_temp(target); | 119 xnjsmb_img_ldr_init_mb_rt_temp(target); |
152 | 120 |
153 target->Set(String::New("mb_rt"), mb_rt_func->GetFunction()); | 121 target->Set(String::New("mb_rt"), |
122 xnjsmb_auto_mb_rt_temp->GetFunction()); | |
154 } | 123 } |