changeset 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 6639d386db78
files nodejs/mbfly_njs.cc nodejs/mbfly_njs.h nodejs/shapes.cc nodejs/testcase.js
diffstat 4 files changed, 111 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/nodejs/mbfly_njs.cc	Mon Jun 07 19:18:20 2010 +0800
+++ b/nodejs/mbfly_njs.cc	Mon Jun 07 22:37:51 2010 +0800
@@ -105,6 +105,8 @@
     rt_proto_temp = mb_rt_func->PrototypeTemplate();
     func = FunctionTemplate::New(xnjsmb_coord_new);
     SET(rt_proto_temp, "coord_new", func);
+
+    xnjsmb_shapes_init_mb_rt_temp(mb_rt_func);
     
     target->Set(String::New("mb_rt"), mb_rt_func->GetFunction());    
 }
--- a/nodejs/mbfly_njs.h	Mon Jun 07 19:18:20 2010 +0800
+++ b/nodejs/mbfly_njs.h	Mon Jun 07 22:37:51 2010 +0800
@@ -23,4 +23,8 @@
 v8::Handle<v8::Value> xnjsmb_coord_new(const v8::Arguments &args);
 void xnjsmb_coord_mkroot(v8::Handle<v8::Object> js_rt);
 
+/* From shapes.cc */
+void xnjsmb_shapes_init_mb_rt_temp(v8::Handle<v8::FunctionTemplate> rt_temp);
+
+
 #endif /* __MBFLY_NJS_H_ */
--- a/nodejs/shapes.cc	Mon Jun 07 19:18:20 2010 +0800
+++ b/nodejs/shapes.cc	Mon Jun 07 22:37:51 2010 +0800
@@ -7,7 +7,7 @@
 
 using namespace v8;
 
-/*! \defgroup shape_temp Templates for shape and derive.
+/*! \defgroup shape_temp Templates for shape and derivations.
  *
  * @{
  */
@@ -56,3 +56,103 @@
 
 /* @} */
 
+/*! \defgroup path_temp Templates for path objects.
+ *
+ * @{
+ */
+static Persistent<FunctionTemplate> xnjsmb_path_temp;
+
+/*! \brief Callback of constructor of path objects for Javascript.
+ */
+static Handle<Value>
+xnjsmb_shape_path(const Arguments &args) {
+    shape_t *sh;
+    redraw_man_t *rdman;
+    Handle<Object> self = args.This(); // path object
+    Handle<Object> rt;
+    char *dstr;
+    int argc;
+
+    argc = args.Length();
+    if(argc != 2)
+	THROW("Invalid number of arugments (!= 1)");
+    if(!args[0]->IsString())
+	THROW("Invalid argument type (should be a string)");
+    if(!args[1]->IsObject())
+	THROW("Invalid argument type (should be an object)");
+
+    String::Utf8Value dutf8(args[0]->ToString());
+    dstr = *dutf8;
+
+    rt = args[1]->ToObject();
+    rdman = xnjsmb_rt_rdman(rt);
+    sh = rdman_shape_path_new(rdman, dstr);
+
+    WRAP(self, sh);
+
+    return Null();
+}
+
+/*! \brief Initial function template for constructor of path objects.
+ */
+static void
+xnjsmb_init_path_temp(void) {
+    Handle<FunctionTemplate> temp;
+    Handle<ObjectTemplate> inst_temp;
+
+    temp = FunctionTemplate::New(xnjsmb_shape_path);
+    temp->Inherit(xnjsmb_shape_temp);
+    temp->SetClassName(String::New("path"));
+
+    inst_temp = temp->InstanceTemplate();
+    inst_temp->SetInternalFieldCount(1);
+
+    xnjsmb_path_temp = Persistent<FunctionTemplate>::New(temp);
+}
+
+/*! \brief Callback function of mb_rt.path_new().
+ */
+static Handle<Value>
+xnjsmb_shape_path_new(const Arguments &args) {
+    HandleScope scope;
+    Handle<Object> self = args.This(); // runtime object
+    Handle<Object> path_obj;
+    Handle<Value> path_args[2];
+    int argc;
+
+    argc = args.Length();
+    if(argc != 1)
+	THROW("Invalid number of arugments (!= 1)");
+    if(!args[0]->IsString())
+	THROW("Invalid argument type (shoud be a string)");
+
+    path_args[0] = args[0];
+    path_args[1] = self;
+    
+    path_obj = xnjsmb_path_temp->GetFunction()->NewInstance(2, path_args);
+    
+    scope.Close(path_obj);
+    return path_obj;
+}
+
+/* @} */
+
+/*! \brief Set properties of template of mb_rt.
+ */
+void
+xnjsmb_shapes_init_mb_rt_temp(Handle<FunctionTemplate> rt_temp) {
+    Handle<FunctionTemplate> path_new_temp;
+    Handle<ObjectTemplate> rt_proto_temp;
+    static int temp_init_flag = 0;
+
+    if(temp_init_flag == 0) {
+	xnjsmb_init_shape_temp();
+	xnjsmb_init_path_temp();
+	temp_init_flag = 1;
+    }
+
+    rt_proto_temp = rt_temp->PrototypeTemplate();
+    
+    path_new_temp = FunctionTemplate::New(xnjsmb_shape_path_new);
+    SET(rt_proto_temp, "path_new", path_new_temp);
+}
--- a/nodejs/testcase.js	Mon Jun 07 19:18:20 2010 +0800
+++ b/nodejs/testcase.js	Mon Jun 07 22:37:51 2010 +0800
@@ -11,4 +11,8 @@
 sys.puts("coord matrix: " + 
 	 [coord[0], coord[1], coord[2], coord[3], coord[4], coord[5]]);
 
+sys.puts(mb_rt.path_new);
+var path = mb_rt.path_new("m 100,100 L 200,200");
+sys.puts(path);
+
 setTimeout(function() { sys.puts("timeout"); }, 1000);