changeset 568:d796e6b8b97e Android_Skia

Real initialize a paint_color_t object for paint_color JS obj
author Thinker K.F. Li <thinker@branda.to>
date Wed, 09 Jun 2010 14:10:58 +0800
parents a12c3448afb6
children f87a368e847a
files nodejs/paints.cc nodejs/testcase.js
diffstat 2 files changed, 56 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/nodejs/paints.cc	Wed Jun 09 12:28:03 2010 +0800
+++ b/nodejs/paints.cc	Wed Jun 09 14:10:58 2010 +0800
@@ -8,21 +8,46 @@
 
 using namespace v8;
 
+#ifndef ASSERT
+#define ASSERT(x)
+#endif
 
-/*! \brief Base type of all types of paints.
- */
-static Handle<Value>
-xnjsmb_paint(const Arguments &args) {
-}
 
 /*! \brief Constructor of color paint_color_t object for Javascript.
  */
 static Handle<Value>
 xnjsmb_paint_color(const Arguments &args) {
+    int argc = args.Length();
+    Handle<Object> self = args.This();
+    Handle<Object> rt;
+    redraw_man_t *rdman;
+    paint_t *paint;
+    float r, g, b, a;
+
+    if(argc != 5)
+	THROW("Invalid number of arguments (!= 5)");
+    if(!args[0]->IsObject() || !args[1]->IsNumber() ||
+       !args[2]->IsNumber() || !args[3]->IsNumber() ||
+       !args[4]->IsNumber())
+	THROW("Invalid argument type");
+
+    rt = args[0]->ToObject();
+    r = args[1]->ToNumber()->Value();
+    g = args[2]->ToNumber()->Value();
+    b = args[3]->ToNumber()->Value();
+    a = args[4]->ToNumber()->Value();
+
+    rdman = xnjsmb_rt_rdman(rt);
+    paint = rdman_paint_color_new(rdman, r, g, b, a);
+    ASSERT(sh != NULL);
+
+    WRAP(self, paint);
+
+    return Null();
 }
 
-static Persistent<FunctionTemplate> paint_temp;
-static Persistent<FunctionTemplate> paint_color_temp;
+static Persistent<FunctionTemplate> xnjsmb_paint_temp;
+static Persistent<FunctionTemplate> xnjsmb_paint_color_temp;
 
 /*! \brief Create and return a paint_color object.
  */
@@ -32,7 +57,7 @@
     Handle<Object> rt = args.This();
     Handle<Object> paint_color_obj;
     Handle<Function> paint_color_func;
-    Handle<Value> pc_args[4];
+    Handle<Value> pc_args[5];
     int argc;
     int i;
 
@@ -48,14 +73,14 @@
     pc_args[2] = args[1];	// g
     pc_args[3] = args[2];	// b
     pc_args[4] = args[3];	// a
-    paint_color_func = paint_color_temp->GetFunction();
-    paint_color_obj = paint_color_func->NewInstance(1, pc_args);
+    paint_color_func = xnjsmb_paint_color_temp->GetFunction();
+    paint_color_obj = paint_color_func->NewInstance(5, pc_args);
 
     scope.Close(paint_color_obj);
     return paint_color_obj;
 }
 
-static Persistent<FunctionTemplate> paint_color_new_temp;
+static Persistent<FunctionTemplate> xnjsmb_paint_color_new_temp;
 
 /*! \brief Create templates for paint types.
  *
@@ -64,18 +89,28 @@
 static void
 xnjsmb_init_paints(void) {
     Handle<FunctionTemplate> temp;
+    Handle<ObjectTemplate> inst_temp;
     
-    temp = FunctionTemplate::New(xnjsmb_paint);
-    paint_temp = Persistent<FunctionTemplate>::New(temp);
-    paint_temp->SetClassName(String::New("paint"));
+    /*
+     * Base type of paint types.
+     */
+    temp = FunctionTemplate::New();
+    xnjsmb_paint_temp = Persistent<FunctionTemplate>::New(temp);
+    xnjsmb_paint_temp->SetClassName(String::New("paint"));
 
+    /*
+     * Paint color
+     */
     temp = FunctionTemplate::New(xnjsmb_paint_color);
-    paint_color_temp = Persistent<FunctionTemplate>::New(temp);
-    paint_color_temp->SetClassName(String::New("paint_color"));
-    paint_color_temp->Inherit(paint_temp);
+    xnjsmb_paint_color_temp = Persistent<FunctionTemplate>::New(temp);
+    xnjsmb_paint_color_temp->SetClassName(String::New("paint_color"));
+    xnjsmb_paint_color_temp->Inherit(xnjsmb_paint_temp);
+    
+    inst_temp = xnjsmb_paint_color_temp->InstanceTemplate();
+    inst_temp->SetInternalFieldCount(1);
 
     temp = FunctionTemplate::New(xnjsmb_paint_color_new);
-    paint_color_new_temp = Persistent<FunctionTemplate>::New(temp);
+    xnjsmb_paint_color_new_temp = Persistent<FunctionTemplate>::New(temp);
 }
 
 void xnjsmb_paints_init_mb_rt_temp(Handle<FunctionTemplate> rt_temp) {
@@ -88,5 +123,5 @@
     }
 
     rt_proto_temp = rt_temp->PrototypeTemplate();
-    SET(rt_proto_temp, "paint_color_new", paint_color_new_temp);
+    SET(rt_proto_temp, "paint_color_new", xnjsmb_paint_color_new_temp);
 }
--- a/nodejs/testcase.js	Wed Jun 09 12:28:03 2010 +0800
+++ b/nodejs/testcase.js	Wed Jun 09 14:10:58 2010 +0800
@@ -18,5 +18,7 @@
 coord.add_shape(path);
 
 sys.puts(mb_rt.paint_color_new);
+var paint = mb_rt.paint_color_new(1, 1, 1, 1);
+sys.puts(paint);
 
 setTimeout(function() { sys.puts("timeout"); }, 1000);