[seed] cairo: seed-cairo-surface should use properties where possible
- From: Robert Carr <racarr src gnome org>
- To: svn-commits-list gnome org
- Subject: [seed] cairo: seed-cairo-surface should use properties where possible
- Date: Thu, 14 May 2009 22:57:35 -0400 (EDT)
commit b0bc6e5f5b1d3d9246b292ca8b3a6a4eb0eec808
Author: Robert Carr <racarr svn gnome org>
Date: Thu May 14 13:12:06 2009 -0400
cairo: seed-cairo-surface should use properties where possible
---
modules/cairo/seed-cairo-image-surface.c | 3 +-
modules/cairo/seed-cairo-surface.c | 185 +++++++++++++++---------------
2 files changed, 95 insertions(+), 93 deletions(-)
diff --git a/modules/cairo/seed-cairo-image-surface.c b/modules/cairo/seed-cairo-image-surface.c
index 676546e..de5b820 100644
--- a/modules/cairo/seed-cairo-image-surface.c
+++ b/modules/cairo/seed-cairo-image-surface.c
@@ -123,7 +123,8 @@ seed_define_cairo_image_surface (SeedContext ctx,
seed_cairo_image_surface_class = seed_create_class (&image_def);
image_surface_constructor_ref = seed_make_constructor (ctx,
- seed_cairo_image_surface_class,
+ NULL,
+ //seed_cairo_image_surface_class,
seed_cairo_construct_image_surface);
seed_object_set_property (ctx, namespace_ref, "ImageSurface", image_surface_constructor_ref);
}
diff --git a/modules/cairo/seed-cairo-surface.c b/modules/cairo/seed-cairo-surface.c
index 3d2b126..2b7699b 100644
--- a/modules/cairo/seed-cairo-surface.c
+++ b/modules/cairo/seed-cairo-surface.c
@@ -6,18 +6,22 @@
#define CAIRO_SURFACE_PRIV(obj) ((cairo_surface_t *)seed_object_get_private(obj))
-#define CHECK_SURFACE(obj, res) ({ \
- if (!seed_object_is_of_class (ctx, obj, seed_cairo_surface_class)){ \
- seed_make_exception (ctx, exception, "ArgumentError", "Object is not a Cairo Surface"); \
- return seed_make_##res (ctx);\
- } \
- if (!seed_object_get_private (obj)){ \
- seed_make_exception (ctx, exception, "ArgumentError", "Cairo surface has been destroyed"); \
- return seed_make_##res (ctx);}})
-
-#define CHECK_THIS(res) if (!seed_object_get_private (this_object)){ \
+#define CHECK_SURFACE(obj, res) ({ \
+ if (!seed_object_is_of_class (ctx, obj, seed_cairo_surface_class)){ \
+ seed_make_exception (ctx, exception, "ArgumentError", "Object is not a Cairo Surface"); \
+ return seed_make_##res (ctx); \
+ } \
+ if (!seed_object_get_private (obj)){ \
+ seed_make_exception (ctx, exception, "ArgumentError", "Cairo surface 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 surface has been destroyed"); \
- return seed_make_##res (ctx);}
+ return seed_make_undefined (ctx);}
+
+#define CHECK_THIS_BOOL(res) if (!seed_object_get_private (this_object)){ \
+ seed_make_exception (ctx, exception, "ArgumentError", "Cairo surface has been destroyed"); return FALSE;}
+
@@ -71,7 +75,7 @@ seed_cairo_surface_create_similar (SeedContext ctx,
gint width, height;
cairo_surface_t *surface, *ret;
cairo_content_t content;
- CHECK_THIS(null);
+ CHECK_THIS();
if (argument_count != 3)
{
EXPECTED_EXCEPTION("create_similar", "3 arguments");
@@ -90,25 +94,21 @@ seed_cairo_surface_create_similar (SeedContext ctx,
static SeedValue
seed_cairo_surface_status (SeedContext ctx,
- SeedObject function,
SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
+ SeedString property_name,
SeedException *exception)
{
- CHECK_THIS(null);
+ CHECK_THIS();
return seed_value_from_long (ctx, cairo_surface_status (seed_object_to_cairo_surface(ctx, this_object, exception)), exception);
}
static SeedValue
seed_cairo_surface_get_content (SeedContext ctx,
- SeedObject function,
SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
+ SeedString property_name,
SeedException *exception)
{
- CHECK_THIS(null);
+ CHECK_THIS();
return seed_value_from_long (ctx, cairo_surface_get_content (seed_object_to_cairo_surface(ctx, this_object, exception)), exception);
}
@@ -120,7 +120,7 @@ seed_cairo_surface_finish (SeedContext ctx,
const SeedValue arguments[],
SeedException *exception)
{
- CHECK_THIS(undefined);
+ CHECK_THIS();
cairo_surface_finish (seed_object_to_cairo_surface(ctx, this_object, exception));
return seed_make_undefined (ctx);
}
@@ -133,7 +133,7 @@ seed_cairo_surface_flush (SeedContext ctx,
const SeedValue arguments[],
SeedException *exception)
{
- CHECK_THIS(null);
+ CHECK_THIS();
cairo_surface_flush (seed_object_to_cairo_surface(ctx, this_object, exception));
return seed_make_undefined (ctx);
}
@@ -148,7 +148,7 @@ seed_cairo_surface_mark_dirty_rectangle(SeedContext ctx,
{
cairo_surface_t *surf;
guint x, y, width, height;
- CHECK_THIS(undefined);
+ CHECK_THIS();
if (argument_count != 4)
{
EXPECTED_EXCEPTION("mark_dirty_rectangle", "4 arguments");
@@ -172,51 +172,51 @@ seed_cairo_surface_mark_dirty (SeedContext ctx,
const SeedValue arguments[],
SeedException *exception)
{
- CHECK_THIS(undefined);
+ CHECK_THIS();
cairo_surface_mark_dirty (seed_object_to_cairo_surface(ctx, this_object, exception));
return seed_make_undefined (ctx);
}
-static SeedValue
+static gboolean
seed_cairo_surface_set_device_offset(SeedContext ctx,
- SeedObject function,
SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
+ SeedString property_name,
+ SeedValue value,
SeedException *exception)
{
cairo_surface_t *surf;
gdouble x, y;
- CHECK_THIS(null);
- if (argument_count != 2)
+ SeedValue jsx, jsy;
+ CHECK_THIS_BOOL();
+
+ if (!seed_value_is_object (ctx, value))
{
- EXPECTED_EXCEPTION("set_device_offset", "2 arguments");
+ seed_make_exception(ctx, exception, "ArgumentError", "Cairo.Surface.device_offset must be an array [x,y]");
+ return FALSE;
}
+
+ jsx = seed_object_get_property_at_index (ctx, (SeedObject) value, 0, exception);
+ jsy = seed_object_get_property_at_index (ctx, (SeedObject) value, 1, exception);
+
surf = seed_object_to_cairo_surface (ctx, this_object, exception);
- x = seed_value_to_double (ctx, arguments[0], exception);
- y = seed_value_to_double (ctx, arguments[1], exception);
+ x = seed_value_to_double (ctx, jsx, exception);
+ y = seed_value_to_double (ctx, jsy, exception);
cairo_surface_set_device_offset (surf, x, y);
-
- return seed_make_undefined (ctx);
+ return TRUE;
}
static SeedValue
seed_cairo_surface_get_device_offset(SeedContext ctx,
- SeedObject function,
SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
+ SeedString property_name,
SeedException *exception)
{
SeedValue offsets[2];
cairo_surface_t *surf;
gdouble x, y;
- CHECK_THIS(null);
- if (argument_count != 0)
- {
- EXPECTED_EXCEPTION("get_device_offset", "no arguments");
- }
+ CHECK_THIS();
+
surf = seed_object_to_cairo_surface (ctx, this_object, exception);
cairo_surface_get_device_offset (surf, &x, &y);
@@ -226,46 +226,46 @@ seed_cairo_surface_get_device_offset(SeedContext ctx,
return seed_make_array (ctx, offsets, 2, exception);
}
-static SeedValue
+static gboolean
seed_cairo_surface_set_fallback_resolution(SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException *exception)
+ SeedObject this_object,
+ SeedString property_name,
+ SeedValue value,
+ SeedException *exception)
{
cairo_surface_t *surf;
gdouble x, y;
- CHECK_THIS(null);
- if (argument_count != 2)
+ SeedValue jsx, jsy;
+ CHECK_THIS_BOOL();
+
+ if (!seed_value_is_object (ctx, value))
{
- EXPECTED_EXCEPTION("set_fallback_resolution", "2 arguments");
+ seed_make_exception(ctx, exception, "ArgumentError", "Cairo.Surface.fallback_resolution must be an array [x,y]");
+ return FALSE;
}
+
+ jsx = seed_object_get_property_at_index (ctx, (SeedObject) value, 0, exception);
+ jsy = seed_object_get_property_at_index (ctx, (SeedObject) value, 1, exception);
+
surf = seed_object_to_cairo_surface (ctx, this_object, exception);
- x = seed_value_to_double (ctx, arguments[0], exception);
- y = seed_value_to_double (ctx, arguments[1], exception);
+ x = seed_value_to_double (ctx, jsx, exception);
+ y = seed_value_to_double (ctx, jsy, exception);
cairo_surface_set_fallback_resolution (surf, x, y);
-
- return seed_make_undefined (ctx);
+ return TRUE;
}
static SeedValue
seed_cairo_surface_get_fallback_resolution(SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException *exception)
+ SeedObject this_object,
+ SeedString property_name,
+ SeedException *exception)
{
SeedValue offsets[2];
cairo_surface_t *surf;
gdouble x, y;
- CHECK_THIS(null);
- if (argument_count != 0)
- {
- EXPECTED_EXCEPTION("get_fallback_resolution", "no arguments");
- }
+ CHECK_THIS();
+
surf = seed_object_to_cairo_surface (ctx, this_object, exception);
cairo_surface_get_fallback_resolution (surf, &x, &y);
@@ -277,38 +277,36 @@ seed_cairo_surface_get_fallback_resolution(SeedContext ctx,
static SeedValue
seed_cairo_surface_get_type (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException *exception)
+ SeedObject this_object,
+ SeedString property_name,
+ SeedException *exception)
{
- CHECK_THIS(null);
+ CHECK_THIS();
return seed_value_from_long (ctx, cairo_surface_get_type (seed_object_to_cairo_surface(ctx, this_object, exception)), exception);
}
static SeedValue
seed_cairo_surface_copy_page (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException *exception)
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException *exception)
{
- CHECK_THIS(undefined);
+ CHECK_THIS();
cairo_surface_copy_page (seed_object_to_cairo_surface(ctx, this_object, exception));
return seed_make_undefined (ctx);
}
static SeedValue
seed_cairo_surface_show_page (SeedContext ctx,
- SeedObject function,
- SeedObject this_object,
- gsize argument_count,
- const SeedValue arguments[],
- SeedException *exception)
+ SeedObject function,
+ SeedObject this_object,
+ gsize argument_count,
+ const SeedValue arguments[],
+ SeedException *exception)
{
- CHECK_THIS(undefined);
+ CHECK_THIS();
cairo_surface_show_page (seed_object_to_cairo_surface(ctx, this_object, exception));
return seed_make_undefined (ctx);
}
@@ -321,7 +319,7 @@ seed_cairo_surface_has_show_text_glyphs(SeedContext ctx,
const SeedValue arguments[],
SeedException *exception)
{
- CHECK_THIS(null);
+ CHECK_THIS();
return seed_value_from_boolean (ctx,
cairo_surface_has_show_text_glyphs (seed_object_to_cairo_surface(ctx, this_object, exception)), exception);
}
@@ -329,24 +327,26 @@ seed_cairo_surface_has_show_text_glyphs(SeedContext ctx,
seed_static_function surface_funcs[] = {
{"create_similar", seed_cairo_surface_create_similar, 0},
- {"status", seed_cairo_surface_status, 0},
{"finish", seed_cairo_surface_finish, 0},
{"flush", seed_cairo_surface_flush, 0},
// {"get_font_options", seed_cairo_surface_get_font_options, 0},
- {"get_content", seed_cairo_surface_get_content, 0},
{"mark_dirty", seed_cairo_surface_mark_dirty, 0},
{"mark_dirty_rectangle", seed_cairo_surface_mark_dirty_rectangle, 0},
- {"set_device_offset", seed_cairo_surface_set_device_offset, 0},
- {"get_device_offset", seed_cairo_surface_get_device_offset, 0},
- {"set_fallback_resolution", seed_cairo_surface_set_fallback_resolution, 0},
- {"get_fallback_resolution", seed_cairo_surface_get_fallback_resolution, 0},
- {"get_type", seed_cairo_surface_get_type, 0},
{"copy_page", seed_cairo_surface_copy_page, 0},
{"show_page", seed_cairo_surface_show_page, 0},
{"has_show_text_glyphs", seed_cairo_surface_has_show_text_glyphs, 0},
{0,0,0}
};
+seed_static_value surface_values[] = {
+ {"type", seed_cairo_surface_get_type, 0, SEED_PROPERTY_ATTRIBUTE_READ_ONLY | SEED_PROPERTY_ATTRIBUTE_DONT_DELETE},
+ {"content", seed_cairo_surface_get_content, 0, SEED_PROPERTY_ATTRIBUTE_READ_ONLY | SEED_PROPERTY_ATTRIBUTE_DONT_DELETE},
+ {"status", seed_cairo_surface_status, 0, SEED_PROPERTY_ATTRIBUTE_READ_ONLY | SEED_PROPERTY_ATTRIBUTE_DONT_DELETE},
+ {"device_offset", seed_cairo_surface_get_device_offset, seed_cairo_surface_set_device_offset, SEED_PROPERTY_ATTRIBUTE_READ_ONLY | SEED_PROPERTY_ATTRIBUTE_DONT_DELETE},
+ {"fallback_resolution", seed_cairo_surface_get_fallback_resolution, seed_cairo_surface_set_fallback_resolution, SEED_PROPERTY_ATTRIBUTE_READ_ONLY | SEED_PROPERTY_ATTRIBUTE_DONT_DELETE},
+ {0, 0, 0, 0}
+};
+
void
seed_define_cairo_surface (SeedContext ctx,
SeedObject namespace_ref)
@@ -356,6 +356,7 @@ seed_define_cairo_surface (SeedContext ctx,
surface_def.class_name = "CairoSurface";
surface_def.finalize = seed_cairo_surface_finalize;
surface_def.static_functions = surface_funcs;
+ surface_def.static_values = surface_values;
seed_cairo_surface_class = seed_create_class (&surface_def);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]