[gjs: 34/45] [cairo] Add a SolidPattern
- From: Johan Dahlin <johan src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs: 34/45] [cairo] Add a SolidPattern
- Date: Tue, 2 Mar 2010 18:54:55 +0000 (UTC)
commit 407514f6d842540490b36c3492daab24a838cab3
Author: Johan Dahlin <johan gnome org>
Date: Tue Mar 2 11:50:44 2010 -0300
[cairo] Add a SolidPattern
Makefile-modules.am | 1 +
modules/cairo-pattern.c | 4 +-
modules/cairo-private.h | 8 +++
modules/cairo-solid-pattern.c | 127 +++++++++++++++++++++++++++++++++++++++++
modules/cairo.c | 5 ++
5 files changed, 143 insertions(+), 2 deletions(-)
---
diff --git a/Makefile-modules.am b/Makefile-modules.am
index 7454471..604e4a1 100644
--- a/Makefile-modules.am
+++ b/Makefile-modules.am
@@ -97,6 +97,7 @@ cairoNative_la_SOURCES = \
modules/cairo-linear-gradient.c \
modules/cairo-radial-gradient.c \
modules/cairo-surface-pattern.c \
+ modules/cairo-solid-pattern.c \
modules/cairo.c
diff --git a/modules/cairo-pattern.c b/modules/cairo-pattern.c
index a3adb52..2382fa3 100644
--- a/modules/cairo-pattern.c
+++ b/modules/cairo-pattern.c
@@ -161,8 +161,8 @@ gjs_cairo_pattern_from_pattern(JSContext *context,
g_return_val_if_fail(pattern != NULL, NULL);
switch (cairo_pattern_get_type(pattern)) {
-// case CAIRO_PATTERN_TYPE_SOLID:
-// return gjs_cairo_solid_pattern_from_pattern(context, pattern);
+ case CAIRO_PATTERN_TYPE_SOLID:
+ return gjs_cairo_solid_pattern_from_pattern(context, pattern);
case CAIRO_PATTERN_TYPE_SURFACE:
return gjs_cairo_surface_pattern_from_pattern(context, pattern);
case CAIRO_PATTERN_TYPE_LINEAR:
diff --git a/modules/cairo-private.h b/modules/cairo-private.h
index d5f3789..0b252e1 100644
--- a/modules/cairo-private.h
+++ b/modules/cairo-private.h
@@ -141,5 +141,13 @@ jsval gjs_cairo_surface_pattern_create_proto (JSContext *contex
JSObject * gjs_cairo_surface_pattern_from_pattern (JSContext *context,
cairo_pattern_t *pattern);
+/* solid pattern */
+jsval gjs_cairo_solid_pattern_create_proto (JSContext *context,
+ JSObject *module,
+ const char *proto_name,
+ JSObject *parent);
+JSObject * gjs_cairo_solid_pattern_from_pattern (JSContext *context,
+ cairo_pattern_t *pattern);
+
#endif /* __CAIRO_PRIVATE_H__ */
diff --git a/modules/cairo-solid-pattern.c b/modules/cairo-solid-pattern.c
new file mode 100644
index 0000000..b5e68c9
--- /dev/null
+++ b/modules/cairo-solid-pattern.c
@@ -0,0 +1,127 @@
+/* -*- 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("CairoSolidPattern", gjs_cairo_solid_pattern)
+
+static void
+gjs_cairo_solid_pattern_finalize(JSContext *context,
+ JSObject *obj)
+{
+ gjs_cairo_pattern_finalize_pattern(context, obj);
+}
+
+static JSPropertySpec gjs_cairo_solid_pattern_proto_props[] = {
+ { NULL }
+};
+
+static JSBool
+createRGB_func(JSContext *context,
+ JSObject *object,
+ uintN argc,
+ jsval *argv,
+ jsval *retval)
+{
+ double red, green, blue;
+ cairo_pattern_t *pattern;
+ JSObject *pattern_wrapper;
+
+ if (!gjs_parse_args(context, "createRGB", "fff", argc, argv,
+ "red", &red,
+ "green", &green,
+ "blue", &blue))
+ return JS_FALSE;
+
+ pattern = cairo_pattern_create_rgb(red, green, blue);
+ if (!gjs_cairo_check_status(context, cairo_pattern_status(pattern), "pattern"))
+ return JS_FALSE;
+
+ pattern_wrapper = gjs_cairo_solid_pattern_from_pattern(context, pattern);
+ cairo_pattern_destroy(pattern);
+
+ *retval = OBJECT_TO_JSVAL(pattern_wrapper);
+
+ return JS_TRUE;
+}
+
+static JSBool
+createRGBA_func(JSContext *context,
+ JSObject *object,
+ uintN argc,
+ jsval *argv,
+ jsval *retval)
+{
+ double red, green, blue, alpha;
+ cairo_pattern_t *pattern;
+ JSObject *pattern_wrapper;
+
+ if (!gjs_parse_args(context, "createRGBA", "ffff", argc, argv,
+ "red", &red,
+ "green", &green,
+ "blue", &blue,
+ "alpha", &alpha))
+ return JS_FALSE;
+
+ pattern = cairo_pattern_create_rgba(red, green, blue, alpha);
+ if (!gjs_cairo_check_status(context, cairo_pattern_status(pattern), "pattern"))
+ return JS_FALSE;
+
+ pattern_wrapper = gjs_cairo_solid_pattern_from_pattern(context, pattern);
+ cairo_pattern_destroy(pattern);
+
+ *retval = OBJECT_TO_JSVAL(pattern_wrapper);
+
+ return JS_TRUE;
+}
+
+static JSFunctionSpec gjs_cairo_solid_pattern_proto_funcs[] = {
+ { "createRGB", createRGB_func, 0, 0 },
+ { "createRGBA", createRGBA_func, 0, 0 },
+ { NULL }
+};
+
+JSObject *
+gjs_cairo_solid_pattern_from_pattern(JSContext *context,
+ cairo_pattern_t *pattern)
+{
+ JSObject *object;
+
+ g_return_val_if_fail(context != NULL, NULL);
+ g_return_val_if_fail(pattern != NULL, NULL);
+ g_return_val_if_fail(cairo_pattern_get_type(pattern) == CAIRO_PATTERN_TYPE_SOLID, NULL);
+
+ object = JS_NewObject(context, &gjs_cairo_solid_pattern_class, NULL, NULL);
+ if (!object) {
+ gjs_throw(context, "failed to create linear gradient pattern");
+ return NULL;
+ }
+
+ gjs_cairo_pattern_construct(context, object, pattern);
+
+ return object;
+}
+
diff --git a/modules/cairo.c b/modules/cairo.c
index ea11496..dab35cb 100644
--- a/modules/cairo.c
+++ b/modules/cairo.c
@@ -113,6 +113,11 @@ gjs_js_define_cairo_stuff(JSContext *context,
if (obj == JSVAL_NULL)
return JS_FALSE;
+ obj = gjs_cairo_solid_pattern_create_proto(context, module,
+ "SolidPattern", 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]