[seed] libseed: Add GObject.__property_type, for looking up pproperty types, and use this in Clutter.Actor.



commit ff83d4a17766d0402ed6810f9572e1cb0f7d74eb
Author: Robert Carr <racarr svn gnome org>
Date:   Wed May 13 23:33:19 2009 -0400

    libseed: Add GObject.__property_type, for looking up pproperty types, and use this in Clutter.Actor.animatev, so you no longer have to pass [GObject.TYPE_BLA, bla]
---
 .../clutter-pad/examples/animated-rectangle.js     |   10 +++---
 extensions/Clutter.js                              |    4 +-
 libseed/seed-engine.c                              |   36 +++++++++++++++++--
 3 files changed, 39 insertions(+), 11 deletions(-)

diff --git a/examples/clutter-pad/examples/animated-rectangle.js b/examples/clutter-pad/examples/animated-rectangle.js
index c257d85..d2ae869 100644
--- a/examples/clutter-pad/examples/animated-rectangle.js
+++ b/examples/clutter-pad/examples/animated-rectangle.js
@@ -17,10 +17,10 @@ for (i = 0; i < 4; i++){
     
    rect.anim = rect.animate(Clutter.AnimationMode.EASE_OUT_BOUNCE, 1500+500*i,
 		     {
-			 height: [GObject.TYPE_INT, 100],
-			 width: [GObject.TYPE_INT, 100],
-			 x: [GObject.TYPE_INT, stage.width - 100*(i+1)],
-			 y: [GObject.TYPE_INT, stage.height - 100],
-			rotation_angle_z: [GObject.TYPE_DOUBLE, 360],
+			 height: 100,
+			 width: 100,
+			 x: stage.width - 100*(i+1),
+			 y: stage.height - 100,
+			 rotation_angle_z: 360,
 		     });
 }
diff --git a/extensions/Clutter.js b/extensions/Clutter.js
index f8eef45..33565c7 100644
--- a/extensions/Clutter.js
+++ b/extensions/Clutter.js
@@ -5,8 +5,8 @@ Clutter.Actor.prototype.animate = function(mode, duration, json)
 	var properties = new Array();
 	var endvalues = new Array();
 	for (var prop in json)	{
-		properties.push(prop);
-		endvalues.push(json[prop]);
+	    properties.push(prop);
+	    endvalues.push([this.__property_type(prop), json[prop]]);
 	}
 	return this.animatev(mode, duration, properties.length, 
 			     properties, endvalues);
diff --git a/libseed/seed-engine.c b/libseed/seed-engine.c
index 0e316c7..25ec6cf 100644
--- a/libseed/seed-engine.c
+++ b/libseed/seed-engine.c
@@ -246,6 +246,35 @@ seed_gobject_equals (JSContextRef ctx,
 }
 
 static JSValueRef
+seed_gobject_property_type (JSContextRef ctx,
+			    JSObjectRef function,
+			    JSObjectRef this_object,
+			    size_t argumentCount,
+			    const JSValueRef arguments[], 
+			    JSValueRef * exception)
+{
+  GParamSpec *spec;
+  gchar *name;
+  GObject *this;
+  
+  if (argumentCount != 1)
+    {
+      seed_make_exception (ctx, exception, "ArgumentError",
+			   "__property_type expects 1 argument"
+			   "got %zd", argumentCount);
+      return JSValueMakeNull (ctx);
+    }
+  
+  this = seed_value_to_object (ctx, this_object, exception);
+  name = seed_value_to_string (ctx, arguments[0], exception);
+  
+  spec = g_object_class_find_property (G_OBJECT_GET_CLASS (this), name);
+  g_free (name);
+  
+  return seed_value_from_long (ctx, spec->value_type, exception);
+}
+
+static JSValueRef
 seed_gobject_ref_count (JSContextRef ctx,
 			JSObjectRef function,
 			JSObjectRef this_object,
@@ -975,10 +1004,9 @@ seed_gobject_constructor_convert_to_type (JSContextRef ctx,
 }
 
 JSStaticFunction gobject_static_funcs[] = {
-  {"equals", seed_gobject_equals, 0}
-  ,
-  {"__debug_ref_count", seed_gobject_ref_count, 0}
-  ,
+  {"equals", seed_gobject_equals, 0},
+  {"__debug_ref_count", seed_gobject_ref_count, 0},
+  {"__property_type", seed_gobject_property_type, 0},
   {0, 0, 0}
 };
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]