[gjs/cairo] [cairo] Add context.fill



commit 46bee4028f05385f15f0426b2776cfd14d7e272b
Author: Johan Dahlin <johan gnome org>
Date:   Wed Feb 17 22:13:18 2010 -0200

    [cairo] Add context.fill
    
    Port over an example from the tutorial as well

 Makefile-examples.am    |    1 +
 examples/cairo/fill.js  |   11 +++++++++++
 modules/cairo-context.c |   20 ++++++++++++++++++++
 3 files changed, 32 insertions(+), 0 deletions(-)
---
diff --git a/Makefile-examples.am b/Makefile-examples.am
index b2c3b59..cce1196 100644
--- a/Makefile-examples.am
+++ b/Makefile-examples.am
@@ -1,4 +1,5 @@
 EXTRA_DIST +=			        \
+	examples/cairo/fill.js                 \
 	examples/cairo/stroke.js                 \
 	examples/clutter.js		\
 	examples/gio-cat.js                 \
diff --git a/examples/cairo/fill.js b/examples/cairo/fill.js
new file mode 100644
index 0000000..57dc17e
--- /dev/null
+++ b/examples/cairo/fill.js
@@ -0,0 +1,11 @@
+const Cairo = imports.cairo;
+
+let surface = new Cairo.ImageSurface(Cairo.Format.ARGB32, 120, 120);
+let cr = new Cairo.Context(surface);
+cr.scale(120, 120);
+
+cr.set_source_rgb(0, 0, 0);
+cr.rectangle(0.25, 0.25, 0.5, 0.5);
+cr.fill();
+
+surface.write_to_png("fill.png");
diff --git a/modules/cairo-context.c b/modules/cairo-context.c
index ce5e343..c2389ad 100644
--- a/modules/cairo-context.c
+++ b/modules/cairo-context.c
@@ -112,6 +112,25 @@ cairo_context_finalize(JSContext *context,
 }
 
 static JSBool
+fill_func(JSContext *context,
+          JSObject  *obj,
+          uintN      argc,
+          jsval     *argv,
+          jsval     *retval)
+{
+    cairo_t *cr;
+
+    if (argc > 1) {
+        /* FIXME: set exception */
+        return JS_FALSE;
+    }
+
+    cr = gjs_cairo_context_get_cr(context, obj);
+    cairo_fill(cr);
+
+    return JS_TRUE;
+}
+static JSBool
 rectangle_func(JSContext *context,
                JSObject  *obj,
                uintN      argc,
@@ -254,6 +273,7 @@ static JSPropertySpec gjs_js_cairo_context_proto_props[] = {
 };
 
 static JSFunctionSpec gjs_js_cairo_context_proto_funcs[] = {
+    { "fill", fill_func, 0, 0 },
     { "rectangle", rectangle_func, 0, 0 },
     { "scale", scale_func, 0, 0 },
     { "set_line_width", set_line_width_func, 0, 0 },



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