comparison nodejs/mbfly_njs.cc @ 1067:7b4e80ab671a openvg

merge from default branch
author Thinker K.F. Li <thinker@codemud.net>
date Wed, 01 Dec 2010 12:25:56 +0800
parents 88bd0eee2b00
children 3eaf708b52c3
comparison
equal deleted inserted replaced
630:bd18951b51d5 1067:7b4e80ab671a
1 // -*- indent-tabs-mode: t; tab-width: 8; c-basic-offset: 4; -*-
2 // vim: sw=4:ts=8:sts=4
1 #include <stdio.h> 3 #include <stdio.h>
4 #include <string.h>
2 #include <v8.h> 5 #include <v8.h>
3 6
4 extern "C" { 7 extern "C" {
5 #include "X_supp_njs.h" 8 #include "njs_mb_supp.h"
6 } 9 }
7 10
8 #include "mbfly_njs.h" 11 #include "mbfly_njs.h"
9 12
10 using namespace v8; 13 using namespace v8;
11 14
15 /*! \defgroup xnjsmb_mb_rt JS binding for MB runtime.
16 * \ingroup xnjsmb
17 *
18 * @{
19 */
20 static coord_t *
21 xnjsmb_coord_new(njs_runtime_t *rt, coord_t *parent, const char **err) {
22 coord_t *coord;
23 redraw_man_t *rdman;
24
25 rdman = njs_mb_rdman(rt);
26 coord = rdman_coord_new(rdman, parent);
27 if(coord == NULL) {
28 *err = "Can not allocate a redraw_man_t";
29 return NULL;
30 }
31 rdman_coord_changed(rdman, coord);
32
33 return coord;
34 }
35
36 static void
37 xnjsmb_mb_rt_objs_mod(Handle<Object> mbrt, Handle<Value> ret) {
38 Handle<Object> ret_obj = ret->ToObject();
39
40 SET(ret_obj, "mbrt", mbrt);
41 }
42
43 #define xnjsmb_auto_coord_new export_xnjsmb_auto_coord_new
44
45 static void
46 xnjsmb_redraw_changed(njs_runtime_t *rt) {
47 redraw_man_t *rdman;
48
49 rdman = njs_mb_rdman(rt);
50 rdman_redraw_changed(rdman);
51 }
52
53 static void
54 xnjsmb_redraw_all(njs_runtime_t *rt) {
55 redraw_man_t *rdman;
56
57 rdman = njs_mb_rdman(rt);
58 rdman_redraw_all(rdman);
59 }
60
61 static void
62 xnjsmb_handle_single_event(njs_runtime_t *rt, void *evt) {
63 njs_mb_handle_single_event(rt, evt);
64 }
65
66 static void
67 xnjsmb_no_more_event(njs_runtime_t *rt) {
68 njs_mb_no_more_event(rt);
69 }
70
71 static njs_runtime_t *
72 _njs_mb_new(Handle<Object> self, char *display_name,
73 int width, int height) {
74 njs_runtime_t *obj;
75 subject_t *subject;
76 Handle<Value> subject_o;
77
78 obj = njs_mb_new(display_name, width, height);
79 WRAP(self, obj); /* mkroot need a wrapped object, but
80 * it is wrapped after returning of
81 * this function. So, we wrap it
82 * here. */
83 xnjsmb_coord_mkroot(self);
84
85 subject = njs_mb_kbevents(obj);
86 subject_o = export_xnjsmb_auto_subject_new(subject);
87 SET(self, "kbevents", subject_o);
88
89 return obj;
90 }
91
92 static njs_runtime_t *
93 _njs_mb_new_with_win(Handle<Object> self, void *display,
94 long win) {
95 njs_runtime_t *obj;
96 subject_t *subject;
97 Handle<Value> subject_o;
98
99 obj = njs_mb_new_with_win(display, win);
100 WRAP(self, obj); /* mkroot need a wrapped object, but
101 * it is wrapped after returning of
102 * this function. So, we wrap it
103 * here. */
104 xnjsmb_coord_mkroot(self);
105
106 subject = njs_mb_kbevents(obj);
107 subject_o = export_xnjsmb_auto_subject_new(subject);
108 SET(self, "kbevents", subject_o);
109
110 return obj;
111 }
112
12 /*! \defgroup njs_template_cb Callback functions for v8 engine and nodejs. 113 /*! \defgroup njs_template_cb Callback functions for v8 engine and nodejs.
13 * 114 *
14 * @{ 115 * @{
15 */ 116 */
16 117
17 /*! \brief to Create a njs runtime object for MadButterfly. 118 /*
18 * 119 * Redirect following function to respective exported version from
19 * Three arguments are requried. They are 120 * other modules. Since gen_v8_binding.m4 make all functions static,
20 * - display name, 121 * we need a exported version to call them indrectly from other
21 * - width, and 122 * modules.
22 * - height.
23 */ 123 */
24 static Handle<Value> 124 #define xnjsmb_auto_path_new export_xnjsmb_auto_path_new
25 xnjsmb_new(const Arguments &args) { 125 #define xnjsmb_auto_stext_new export_xnjsmb_auto_stext_new
26 HandleScope scope; 126 #define xnjsmb_auto_image_new export_xnjsmb_auto_image_new
27 int argc; 127 #define xnjsmb_auto_rect_new export_xnjsmb_auto_rect_new
28 Handle<Value> exc; 128 #define xnjsmb_auto_paint_color_new export_xnjsmb_auto_paint_color_new
29 njs_runtime_t *rt; 129 #define xnjsmb_auto_paint_image_new export_xnjsmb_auto_paint_image_new
30 char *display_name; 130 #define xnjsmb_auto_paint_linear_new export_xnjsmb_auto_paint_linear_new
31 int width, height; 131 #define xnjsmb_auto_paint_radial_new export_xnjsmb_auto_paint_radial_new
32 Handle<Object> self;
33 132
34 argc = args.Length(); 133 #include "mbfly_njs-inc.h"
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 134
94 /* @} */ 135 /* @} */
95 136
96 /*! \brief Get rdman associated with the runtime. 137 /*! \brief Get rdman associated with the runtime.
97 */ 138 */
100 HandleScope scope; 141 HandleScope scope;
101 njs_runtime_t *rt; 142 njs_runtime_t *rt;
102 redraw_man_t *rdman; 143 redraw_man_t *rdman;
103 144
104 rt = (njs_runtime_t *)UNWRAP(mbrt); 145 rt = (njs_runtime_t *)UNWRAP(mbrt);
105 rdman = X_njs_MB_rdman(rt); 146 rdman = njs_mb_rdman(rt);
106 147
107 return rdman; 148 return rdman;
108 } 149 }
109 150
110 Handle<Value> 151 Handle<Value>
111 hello_func(const Arguments &args) { 152 hello_func(const Arguments &args) {
124 target->Set(String::New("Hello"), func->GetFunction()); 165 target->Set(String::New("Hello"), func->GetFunction());
125 166
126 /* 167 /*
127 * Initialize template for MadButterfly runtime objects. 168 * Initialize template for MadButterfly runtime objects.
128 */ 169 */
129 mb_rt_func = FunctionTemplate::New(xnjsmb_new); 170 xnjsmb_auto_mb_rt_init();
130 mb_rt_func->SetClassName(String::New("mb_rt")); 171 xnjsmb_auto_mb_rt_display_init();
131 172 xnjsmb_auto_mb_rt_with_win_init();
132 rt_instance_temp = mb_rt_func->InstanceTemplate(); 173 njs_mb_reg_timer_man();
133 rt_instance_temp->SetInternalFieldCount(1); 174 njs_mb_reg_IO_man();
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 175
145 /* 176 /*
146 * Add properties to mb_rt templates for other modules. 177 * Add properties to mb_rt templates for other modules.
147 */ 178 */
148 xnjsmb_shapes_init_mb_rt_temp(mb_rt_func); 179 xnjsmb_shapes_init_mb_rt_temp(xnjsmb_auto_mb_rt_temp);
149 xnjsmb_paints_init_mb_rt_temp(mb_rt_func); 180 xnjsmb_paints_init_mb_rt_temp(xnjsmb_auto_mb_rt_temp);
150 xnjsmb_font_init_mb_rt_temp(mb_rt_func); 181 xnjsmb_font_init_mb_rt_temp(xnjsmb_auto_mb_rt_temp);
151 182 xnjsmb_img_ldr_init_mb_rt_temp(target);
152 target->Set(String::New("mb_rt"), mb_rt_func->GetFunction()); 183 xnjsmb_observer_init();
184
185 target->Set(String::New("mb_rt"),
186 xnjsmb_auto_mb_rt_temp->GetFunction());
187 target->Set(String::New("mb_rt_with_win"),
188 xnjsmb_auto_mb_rt_with_win_temp->GetFunction());
153 } 189 }
190
191 /* @} */