[gjs: 12/45] [cairo] Add an abstract Gradient prototype



commit 0dbdeed2281316c338ab6b8cf9c9fbd4f077586c
Author: Johan Dahlin <johan gnome org>
Date:   Mon Feb 22 13:45:43 2010 -0300

    [cairo] Add an abstract Gradient prototype

 Makefile-modules.am      |    1 +
 modules/cairo-gradient.c |   98 ++++++++++++++++++++++++++++++++++++++++++++++
 modules/cairo-private.h  |    4 ++
 modules/cairo.c          |    8 +++-
 4 files changed, 110 insertions(+), 1 deletions(-)
---
diff --git a/Makefile-modules.am b/Makefile-modules.am
index 702da15..63b5d92 100644
--- a/Makefile-modules.am
+++ b/Makefile-modules.am
@@ -93,6 +93,7 @@ cairoNative_la_SOURCES =		\
 	modules/cairo-pdf-surface.c \
 	modules/cairo-svg-surface.c \
 	modules/cairo-pattern.c \
+	modules/cairo-gradient.c \
 	modules/cairo.c
 
 
diff --git a/modules/cairo-gradient.c b/modules/cairo-gradient.c
new file mode 100644
index 0000000..daef51c
--- /dev/null
+++ b/modules/cairo-gradient.c
@@ -0,0 +1,98 @@
+/* -*- 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("CairoGradient", gjs_cairo_gradient)
+
+static void
+gjs_cairo_gradient_finalize(JSContext *context,
+                            JSObject  *obj)
+{
+    gjs_cairo_pattern_finalize_pattern(context, obj);
+}
+
+/* Properties */
+static JSPropertySpec gjs_cairo_gradient_proto_props[] = {
+    { NULL }
+};
+
+/* Methods */
+
+static JSBool
+addColorStopRGB_func(JSContext *context,
+                     JSObject  *object,
+                     uintN      argc,
+                     jsval     *argv,
+                     jsval     *retval)
+{
+    double offset, red, green, blue;
+    cairo_pattern_t *pattern;
+
+    if (!gjs_parse_args(context, "addColorStopRGB", "ffff", argc, argv,
+                        "offset", &offset,
+                        "red", &red,
+                        "green", &green,
+                        "blue", &blue))
+        return JS_FALSE;
+
+    pattern = gjs_cairo_pattern_get_pattern(context, object);
+    cairo_pattern_add_color_stop_rgb(pattern, offset, red, green, blue);
+
+    return JS_TRUE;
+}
+
+static JSBool
+addColorStopRGBA_func(JSContext *context,
+                     JSObject  *object,
+                     uintN      argc,
+                     jsval     *argv,
+                     jsval     *retval)
+{
+    double offset, red, green, blue, alpha;
+    cairo_pattern_t *pattern;
+
+    if (!gjs_parse_args(context, "addColorStopRGBA", "fffff", argc, argv,
+                        "offset", &offset,
+                        "red", &red,
+                        "green", &green,
+                        "blue", &blue,
+                        "alpha", &alpha))
+        return JS_FALSE;
+
+    pattern = gjs_cairo_pattern_get_pattern(context, object);
+    cairo_pattern_add_color_stop_rgba(pattern, offset, red, green, blue, alpha);
+
+    return JS_TRUE;
+}
+
+static JSFunctionSpec gjs_cairo_gradient_proto_funcs[] = {
+    { "addColorStopRGB", addColorStopRGB_func, 0, 0 },
+    { "addColorStopRGBA", addColorStopRGBA_func, 0, 0 },
+    // getColorStopRGB
+    // getColorStopRGBA
+    { NULL }
+};
diff --git a/modules/cairo-private.h b/modules/cairo-private.h
index a2cd5f4..e1d920c 100644
--- a/modules/cairo-private.h
+++ b/modules/cairo-private.h
@@ -89,5 +89,9 @@ void gjs_cairo_pattern_construct(JSContext *context, JSObject *obj, cairo_patter
 void gjs_cairo_pattern_finalize_pattern(JSContext *context, JSObject *obj);
 cairo_pattern_t * gjs_cairo_pattern_get_pattern(JSContext *context, JSObject *object);
 
+/* gradient */
+jsval gjs_cairo_gradient_create_proto(JSContext *context, JSObject *module,
+                                     const char *proto_name, JSObject *parent);
+
 #endif /* __CAIRO_PRIVATE_H__ */
 
diff --git a/modules/cairo.c b/modules/cairo.c
index a47f388..19c6501 100644
--- a/modules/cairo.c
+++ b/modules/cairo.c
@@ -31,7 +31,7 @@ gjs_js_define_cairo_stuff(JSContext      *context,
                           JSObject       *module_obj)
 {
     jsval obj;
-    JSObject *surface_proto;
+    JSObject *surface_proto, *pattern_proto;
 
     obj = gjs_cairo_context_create_proto(context, module_obj,
                                          "Context", NULL);
@@ -77,6 +77,12 @@ gjs_js_define_cairo_stuff(JSContext      *context,
                                          "Pattern", NULL);
     if (obj == JSVAL_NULL)
         return JS_FALSE;
+    pattern_proto = JSVAL_TO_OBJECT(obj);
+
+    obj = gjs_cairo_gradient_create_proto(context, module_obj,
+                                         "Gradient", pattern_proto);
+    if (obj == JSVAL_NULL)
+        return JS_FALSE;
 
     return JS_TRUE;
 }



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