[gjs/cairo: 11/12] [cairo] Add a Context override
- From: Johan Dahlin <johan src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs/cairo: 11/12] [cairo] Add a Context override
- Date: Sun, 21 Feb 2010 19:07:35 +0000 (UTC)
commit 3f639d36b6892fc2ee71deb52bfbba711a5a593b
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 f8d36da..d052248 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"
@@ -135,3 +137,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 c8bb1a9..f6d1130 100644
--- a/modules/cairo-private.h
+++ b/modules/cairo-private.h
@@ -40,6 +40,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 *parent);
diff --git a/modules/cairo.c b/modules/cairo.c
index 9e99b9a..915f090 100644
--- a/modules/cairo.c
+++ b/modules/cairo.c
@@ -38,6 +38,7 @@ gjs_js_define_cairo_stuff(JSContext *context,
!JS_DefineProperty(context, module_obj, "Context",
obj, NULL, NULL, GJS_MODULE_PROP_FLAGS))
return JS_FALSE;
+ gjs_cairo_context_init(context);
obj = gjs_cairo_surface_create_proto(context, NULL);
if (obj == JSVAL_NULL ||
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]