[gjs/cairo: 14/18] [cairo] Add a LinearGradient prototype
- From: Johan Dahlin <johan src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs/cairo: 14/18] [cairo] Add a LinearGradient prototype
- Date: Mon, 22 Feb 2010 22:13:38 +0000 (UTC)
commit bcdfc25037345ecf5044d89cb182277fdd3b15e0
Author: Johan Dahlin <johan gnome org>
Date: Mon Feb 22 13:57:37 2010 -0300
[cairo] Add a LinearGradient prototype
Makefile-modules.am | 1 +
modules/cairo-linear-gradient.c | 77 +++++++++++++++++++++++++++++++++++++++
modules/cairo-private.h | 4 ++
modules/cairo.c | 8 ++++-
4 files changed, 89 insertions(+), 1 deletions(-)
---
diff --git a/Makefile-modules.am b/Makefile-modules.am
index e7f63dc..c848f52 100644
--- a/Makefile-modules.am
+++ b/Makefile-modules.am
@@ -92,6 +92,7 @@ cairoNative_la_SOURCES = \
modules/cairo-pdf-surface.c \
modules/cairo-pattern.c \
modules/cairo-gradient.c \
+ modules/cairo-linear-gradient.c \
modules/cairo.c
diff --git a/modules/cairo-linear-gradient.c b/modules/cairo-linear-gradient.c
new file mode 100644
index 0000000..21e8adb
--- /dev/null
+++ b/modules/cairo-linear-gradient.c
@@ -0,0 +1,77 @@
+/* -*- 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("CairoLinearGradient", gjs_cairo_linear_gradient)
+
+static JSBool
+gjs_cairo_linear_gradient_constructor(JSContext *context,
+ JSObject *obj,
+ uintN argc,
+ jsval *argv,
+ jsval *retval)
+{
+ double x0, y0, x1, y1;
+ cairo_pattern_t *pattern;
+ cairo_status_t status;
+
+ if (!gjs_check_constructing(context))
+ return JS_FALSE;
+
+ if (!gjs_parse_args(context, "LinearGradient", "ffff", argc, argv,
+ "x0", &x0,
+ "y0", &y0,
+ "x1", &x1,
+ "y1", &y1))
+ return JS_FALSE;
+
+ pattern = cairo_pattern_create_linear(x0, y0, x1, y1);
+ status = cairo_pattern_status(pattern);
+ if (status != CAIRO_STATUS_SUCCESS) {
+ gjs_throw(context, "Failed to create cairo pattern: %s",
+ cairo_status_to_string(status));
+ return JS_FALSE;
+ }
+ gjs_cairo_pattern_construct(context, obj, pattern);
+
+ return JS_TRUE;
+}
+
+static void
+gjs_cairo_linear_gradient_finalize(JSContext *context,
+ JSObject *obj)
+{
+ gjs_cairo_pattern_finalize_pattern(context, obj);
+}
+
+static JSPropertySpec gjs_cairo_linear_gradient_proto_props[] = {
+ { NULL }
+};
+
+static JSFunctionSpec gjs_cairo_linear_gradient_proto_funcs[] = {
+ { NULL }
+};
diff --git a/modules/cairo-private.h b/modules/cairo-private.h
index 2a5af5f..10cdf36 100644
--- a/modules/cairo-private.h
+++ b/modules/cairo-private.h
@@ -81,5 +81,9 @@ cairo_pattern_t * gjs_cairo_pattern_get_pattern(JSContext *context, JSObject *ob
jsval gjs_cairo_gradient_create_proto(JSContext *context, JSObject *module,
const char *proto_name, JSObject *parent);
+/* linear gradient */
+jsval gjs_cairo_linear_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 4b0f84c..1d9eeb7 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, *pattern_proto;
+ JSObject *surface_proto, *pattern_proto, *gradient_proto;
obj = gjs_cairo_context_create_proto(context, module_obj,
"Context", NULL);
@@ -69,6 +69,12 @@ gjs_js_define_cairo_stuff(JSContext *context,
"Gradient", pattern_proto);
if (obj == JSVAL_NULL)
return JS_FALSE;
+ gradient_proto = JSVAL_TO_OBJECT(obj);
+
+ obj = gjs_cairo_linear_gradient_create_proto(context, module_obj,
+ "LinearGradient", gradient_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]