[gjs/cairo: 12/18] [cairo] Add an abstract Pattern prototype



commit 2a3c5133b704cd6e0bed9085db014bd23e05f94d
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 |   94 +++++++++++++++++++++++++++++++++++++++++++++++
 modules/cairo-private.h |   14 +++++++
 modules/cairo.c         |    6 +++
 4 files changed, 115 insertions(+), 0 deletions(-)
---
diff --git a/Makefile-modules.am b/Makefile-modules.am
index 53d0872..3c51e9e 100644
--- a/Makefile-modules.am
+++ b/Makefile-modules.am
@@ -90,6 +90,7 @@ cairoNative_la_SOURCES =		\
 	modules/cairo-surface.c \
 	modules/cairo-image-surface.c \
 	modules/cairo-pdf-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..7ac129a
--- /dev/null
+++ b/modules/cairo-pattern.c
@@ -0,0 +1,94 @@
+/* -*- 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 JSFunctionSpec gjs_cairo_pattern_proto_funcs[] = {
+    // getMatrix
+    // 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 346475c..855ef30 100644
--- a/modules/cairo-private.h
+++ b/modules/cairo-private.h
@@ -63,5 +63,19 @@ jsval gjs_cairo_pdf_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 5d01df8..5713719 100644
--- a/modules/cairo.c
+++ b/modules/cairo.c
@@ -58,6 +58,12 @@ gjs_js_define_cairo_stuff(JSContext      *context,
     if (obj == JSVAL_NULL)
         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]