[gjs/cairo: 10/18] [cairo] Add a Context override



commit aae4d2833d4c9914b7e983377b376bcc3f078bb1
Author: Johan Dahlin <johan gnome org>
Date:   Sun Feb 21 15:53:56 2010 -0300

    [cairo] Add a Context override

 modules/cairo-context.c |   52 +++++++++++++++++++++++++++++++++++++++++++++++
 modules/cairo-private.h |    1 +
 modules/cairo.c         |    1 +
 3 files changed, 54 insertions(+), 0 deletions(-)
---
diff --git a/modules/cairo-context.c b/modules/cairo-context.c
index e9964c9..53ee63a 100644
--- a/modules/cairo-context.c
+++ b/modules/cairo-context.c
@@ -23,6 +23,8 @@
 #include <config.h>
 
 #include <gjs/gjs.h>
+#include <gi/override.h>
+
 #include <cairo.h>
 #include "cairo-private.h"
 
@@ -140,3 +142,53 @@ gjs_cairo_context_get_cr(JSContext *context,
 
     return priv->cr;
 }
+
+static JSBool
+context_to_g_argument(JSContext      *context,
+                      jsval           value,
+                      GITypeInfo     *type_info,
+                      const char     *arg_name,
+                      GjsArgumentType argument_type,
+                      GITransfer      transfer,
+                      gboolean        may_be_null,
+                      GArgument      *arg)
+{
+    JSObject *obj;
+    cairo_t *cr;
+
+    obj = JSVAL_TO_OBJECT(value);
+    cr = gjs_cairo_context_get_cr(context, obj);
+    if (!cr)
+        return JS_FALSE;
+
+    arg->v_pointer = cr;
+    return JS_TRUE;
+}
+
+static JSBool
+context_from_g_argument(JSContext  *context,
+                        jsval      *value_p,
+                        GITypeInfo *type_info,
+                        GArgument  *arg)
+{
+    JSObject *obj;
+
+    obj = gjs_cairo_context_from_cr(context, (cairo_t*)arg->v_pointer);
+    if (!obj)
+        return JS_FALSE;
+
+    *value_p = OBJECT_TO_JSVAL(obj);
+    return JS_TRUE;
+}
+
+static GjsArgOverrideInfo override_info = {
+    context_to_g_argument,
+    context_from_g_argument,
+    NULL
+};
+
+void
+gjs_cairo_context_init(JSContext *context)
+{
+    gjs_arg_override_register("cairo", "Context", &override_info);
+}
diff --git a/modules/cairo-private.h b/modules/cairo-private.h
index 7e5575b..346475c 100644
--- a/modules/cairo-private.h
+++ b/modules/cairo-private.h
@@ -41,6 +41,7 @@ cairo_t *gjs_cairo_context_get_cr(JSContext *context,
                                   JSObject *object);
 JSObject * gjs_cairo_context_from_cr(JSContext *context,
                                      cairo_t *cr);
+void gjs_cairo_context_init(JSContext *context);
 
 /* surface */
 jsval gjs_cairo_surface_create_proto(JSContext *context, JSObject *module,
diff --git a/modules/cairo.c b/modules/cairo.c
index 965b962..5d01df8 100644
--- a/modules/cairo.c
+++ b/modules/cairo.c
@@ -37,6 +37,7 @@ gjs_js_define_cairo_stuff(JSContext      *context,
                                          "Context", NULL);
     if (obj == JSVAL_NULL)
         return JS_FALSE;
+    gjs_cairo_context_init(context);
 
     obj = gjs_cairo_surface_create_proto(context, module_obj,
                                          "Surface", NULL);



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