[seed] cairo: Add Pattern class



commit 4c53e9cd0bace34580c045fb33372262431e2dcd
Author: Robert Carr <racarr svn gnome org>
Date:   Thu May 14 16:10:02 2009 -0400

    cairo: Add Pattern class
---
 modules/cairo/Makefile.am          |    1 +
 modules/cairo/seed-cairo-pattern.c |   77 ++++++++++++++++++++++++++++++++++++
 modules/cairo/seed-cairo-pattern.h |   21 ++++++++++
 modules/cairo/seed-cairo.c         |    4 +-
 4 files changed, 102 insertions(+), 1 deletions(-)

diff --git a/modules/cairo/Makefile.am b/modules/cairo/Makefile.am
index cdf797f..5bcad71 100644
--- a/modules/cairo/Makefile.am
+++ b/modules/cairo/Makefile.am
@@ -11,6 +11,7 @@ libcairo_la_SOURCES = \
 	seed-cairo-surface.c \
 	seed-cairo-image-surface.c \
 	seed-cairo-matrix.c \
+	seed-cairo-pattern.c \
 	seed-cairo-enums.c 
 
 libcairo_la_CFLAGS = \
diff --git a/modules/cairo/seed-cairo-pattern.c b/modules/cairo/seed-cairo-pattern.c
new file mode 100644
index 0000000..991b578
--- /dev/null
+++ b/modules/cairo/seed-cairo-pattern.c
@@ -0,0 +1,77 @@
+#include <seed.h>
+#include <cairo/cairo.h>
+
+#include "seed-cairo.h"
+#include "seed-cairo-matrix.h"
+
+#define CAIRO_PATTERN_PRIV(obj) ((cairo_pattern_t *)seed_object_get_private(obj))
+
+#define CHECK_PATTERN(obj, res) ({					\
+      if (!seed_object_is_of_class (ctx, obj, seed_cairo_pattern_class)){ \
+	seed_make_exception (ctx, exception, "ArgumentError", "Object is not a Cairo Pattern"); \
+	return seed_make_##res (ctx);					\
+      }									\
+      if (!seed_object_get_private (obj)){				\
+	seed_make_exception (ctx, exception, "ArgumentError", "Cairo pattern has been destroyed"); \
+	return seed_make_##res (ctx);}})
+
+#define CHECK_THIS() if (!seed_object_get_private (this_object)){	\
+    seed_make_exception (ctx, exception, "ArgumentError", "Cairo pattern has been destroyed"); \
+    return seed_make_undefined (ctx);}
+
+#define CHECK_THIS_BOOL(res) if (!seed_object_get_private (this_object)){ \
+    seed_make_exception (ctx, exception, "ArgumentError", "Cairo pattern has been destroyed"); return FALSE;} 
+
+
+  
+
+SeedClass seed_cairo_pattern_class;
+
+SeedClass
+seed_get_cairo_pattern_class ()
+{
+  return seed_cairo_pattern_class;
+}
+
+static void
+seed_cairo_pattern_finalize (SeedObject obj)
+{
+  cairo_pattern_t *s = CAIRO_PATTERN_PRIV(obj);
+  if (s)
+    cairo_pattern_destroy (s);
+}
+
+cairo_pattern_t *
+seed_object_to_cairo_pattern (SeedContext ctx, SeedObject obj, SeedException *exception)
+{
+  if (seed_object_is_of_class (ctx, obj, seed_cairo_pattern_class))
+    return CAIRO_PATTERN_PRIV (obj);
+  seed_make_exception (ctx, exception, "ArgumentError", "Object is not a Cairo Pattern");
+  return NULL;
+}
+
+SeedObject
+seed_object_from_cairo_pattern (SeedContext ctx, cairo_pattern_t *surf)
+{
+  SeedObject jsobj;
+  
+  jsobj = cairo_pattern_get_user_data (surf, seed_get_cairo_key());
+  if (jsobj)
+    return jsobj;
+  
+  jsobj = seed_make_object (ctx, seed_cairo_pattern_class, surf);
+  cairo_pattern_set_user_data (surf, seed_get_cairo_key(), jsobj, seed_cairo_destroy_func);
+  return jsobj;
+}
+
+void
+seed_define_cairo_pattern (SeedContext ctx,
+			   SeedObject namespace_ref)
+{
+  seed_class_definition pattern_def = seed_empty_class;
+  
+  pattern_def.class_name = "Pattern";
+  pattern_def.finalize = seed_cairo_pattern_finalize;
+  
+  seed_cairo_pattern_class = seed_create_class (&pattern_def);
+}
diff --git a/modules/cairo/seed-cairo-pattern.h b/modules/cairo/seed-cairo-pattern.h
new file mode 100644
index 0000000..a250b7d
--- /dev/null
+++ b/modules/cairo/seed-cairo-pattern.h
@@ -0,0 +1,21 @@
+#ifndef _SEED_CAIRO_PATTERN_H
+#define _SEED_CAIRO_PATTERN_H
+
+#include <seed.h>
+#include <cairo/cairo.h>
+
+SeedClass
+seed_get_cairo_pattern_class ();
+
+cairo_pattern_t *
+seed_object_to_cairo_pattern (SeedContext ctx, SeedObject obj, SeedException *exception);
+
+SeedObject
+seed_object_from_cairo_pattern (SeedContext ctx, cairo_pattern_t *surf);
+
+void
+seed_define_cairo_pattern (SeedContext ctx,
+			   SeedObject namespace_ref);
+
+
+#endif
diff --git a/modules/cairo/seed-cairo.c b/modules/cairo/seed-cairo.c
index e92194d..0f8142d 100644
--- a/modules/cairo/seed-cairo.c
+++ b/modules/cairo/seed-cairo.c
@@ -5,7 +5,7 @@
 #include "seed-cairo-image-surface.h"
 #include "seed-cairo-enums.h"
 #include "seed-cairo-matrix.h"
-
+#include "seed-cairo-pattern.h"
 
 SeedEngine *eng;
 
@@ -1652,9 +1652,11 @@ seed_module_init(SeedEngine * local_eng)
   
   // Temporary hack until API changes.
   seed_value_protect (eng->context, namespace_ref);
+
   seed_define_cairo_enums (eng->context, namespace_ref);
   seed_define_cairo_surface (eng->context, namespace_ref);
   seed_define_cairo_matrix (eng->context, namespace_ref);
+  seed_define_cairo_pattern (eng->context, namespace_ref);
   
   cairo_def.class_name = "CairoContext";
   cairo_def.static_functions = cairo_funcs;



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