[gjs: 11/45] [cairo] Add an abstract Pattern prototype
- From: Johan Dahlin <johan src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs: 11/45] [cairo] Add an abstract Pattern prototype
- Date: Tue, 2 Mar 2010 18:52:59 +0000 (UTC)
commit 0009a48475d9c45b551b1aed8b4fc4491950bdf2
Author: Johan Dahlin <johan gnome org>
Date: Mon Feb 22 13:29:39 2010 -0300
[cairo] Add an abstract Pattern prototype
Makefile-modules.am | 1 +
modules/cairo-pattern.c | 117 +++++++++++++++++++++++++++++++++++++++++++++++
modules/cairo-private.h | 14 ++++++
modules/cairo.c | 5 ++
4 files changed, 137 insertions(+), 0 deletions(-)
---
diff --git a/Makefile-modules.am b/Makefile-modules.am
index 4d5c7a5..702da15 100644
--- a/Makefile-modules.am
+++ b/Makefile-modules.am
@@ -92,6 +92,7 @@ cairoNative_la_SOURCES = \
modules/cairo-ps-surface.c \
modules/cairo-pdf-surface.c \
modules/cairo-svg-surface.c \
+ modules/cairo-pattern.c \
modules/cairo.c
diff --git a/modules/cairo-pattern.c b/modules/cairo-pattern.c
new file mode 100644
index 0000000..5955d83
--- /dev/null
+++ b/modules/cairo-pattern.c
@@ -0,0 +1,117 @@
+/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil; -*- */
+/* Copyright 2010 litl, LLC. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#include <config.h>
+
+#include <gjs/gjs.h>
+#include <cairo.h>
+#include "cairo-private.h"
+
+GJS_DEFINE_PROTO_ABSTRACT("CairoPattern", gjs_cairo_pattern)
+
+GJS_DEFINE_PRIV_FROM_JS(GjsCairoPattern, gjs_cairo_pattern_class)
+
+static void
+gjs_cairo_pattern_finalize(JSContext *context,
+ JSObject *obj)
+{
+ GjsCairoPattern *priv;
+ priv = JS_GetPrivate(context, obj);
+ if (priv == NULL)
+ return;
+ cairo_pattern_destroy(priv->pattern);
+ g_slice_free(GjsCairoPattern, priv);
+}
+
+void
+gjs_cairo_pattern_construct(JSContext *context, JSObject *obj, cairo_pattern_t *pattern)
+{
+ GjsCairoPattern *priv;
+
+ priv = g_slice_new0(GjsCairoPattern);
+
+ g_assert(priv_from_js(context, obj) == NULL);
+ JS_SetPrivate(context, obj, priv);
+
+ priv->context = context;
+ priv->object = obj;
+ priv->pattern = pattern;
+}
+
+/* Properties */
+static JSPropertySpec gjs_cairo_pattern_proto_props[] = {
+ { NULL }
+};
+
+/* Methods */
+
+static JSBool
+getType_func(JSContext *context,
+ JSObject *object,
+ uintN argc,
+ jsval *argv,
+ jsval *retval)
+{
+ cairo_pattern_t *pattern;
+ cairo_pattern_type_t type;
+
+ if (argc > 1) {
+ gjs_throw(context, "FIXME");
+ return JS_FALSE;
+ }
+
+ pattern = gjs_cairo_pattern_get_pattern(context, object);
+ type = cairo_pattern_get_type(pattern);
+
+ *retval = INT_TO_JSVAL(type);
+ return JS_TRUE;
+}
+
+static JSFunctionSpec gjs_cairo_pattern_proto_funcs[] = {
+ // getMatrix
+ { "getType", getType_func, 0, 0 },
+ // setMatrix
+ { NULL }
+};
+
+/* Public API */
+void
+gjs_cairo_pattern_finalize_pattern(JSContext *context,
+ JSObject *obj)
+{
+ g_return_if_fail(context != NULL);
+ g_return_if_fail(obj != NULL);
+
+ gjs_cairo_pattern_finalize(context, obj);
+}
+
+cairo_pattern_t *
+gjs_cairo_pattern_get_pattern(JSContext *context,
+ JSObject *object)
+{
+ GjsCairoPattern *priv;
+ priv = JS_GetPrivate(context, object);
+ if (priv == NULL)
+ return NULL;
+ return priv->pattern;
+}
+
diff --git a/modules/cairo-private.h b/modules/cairo-private.h
index c86439b..a2cd5f4 100644
--- a/modules/cairo-private.h
+++ b/modules/cairo-private.h
@@ -75,5 +75,19 @@ jsval gjs_cairo_svg_surface_create_proto(JSContext *context, JSObject *module,
const char *proto_name, JSObject *parent);
#endif
+/* pattern */
+typedef struct {
+ void *dummy;
+ JSContext *context;
+ JSObject *object;
+ cairo_pattern_t *pattern;
+} GjsCairoPattern;
+
+jsval gjs_cairo_pattern_create_proto(JSContext *context, JSObject *module,
+ const char *proto_name, JSObject *parent);
+void gjs_cairo_pattern_construct(JSContext *context, JSObject *obj, cairo_pattern_t *pattern);
+void gjs_cairo_pattern_finalize_pattern(JSContext *context, JSObject *obj);
+cairo_pattern_t * gjs_cairo_pattern_get_pattern(JSContext *context, JSObject *object);
+
#endif /* __CAIRO_PRIVATE_H__ */
diff --git a/modules/cairo.c b/modules/cairo.c
index 8246c81..a47f388 100644
--- a/modules/cairo.c
+++ b/modules/cairo.c
@@ -73,6 +73,11 @@ gjs_js_define_cairo_stuff(JSContext *context,
return JS_FALSE;
#endif
+ obj = gjs_cairo_pattern_create_proto(context, module_obj,
+ "Pattern", NULL);
+ if (obj == JSVAL_NULL)
+ return JS_FALSE;
+
return JS_TRUE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]