[cairo-commit] rcairo/src cairo.def, 1.4, 1.5 rb_cairo.h, 1.7, 1.8 rb_cairo_path.c, 1.7, 1.8
Kouhei Sutou
commit at pdx.freedesktop.org
Tue May 22 04:25:50 PDT 2007
Committed by: kou
Update of /cvs/cairo/rcairo/src
In directory kemper:/tmp/cvs-serv3691/src
Modified Files:
cairo.def rb_cairo.h rb_cairo_path.c
Log Message:
* src/rb_cairo_path.c (Cairo::PathMoveTo, Cairo::PathLineTo,
Cairo::PathCurveTo, Cairo::PathClosePath): defined each path data
type as class.
Index: cairo.def
===================================================================
RCS file: /cvs/cairo/rcairo/src/cairo.def,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- cairo.def 20 May 2007 09:18:49 -0000 1.4
+++ cairo.def 22 May 2007 11:25:39 -0000 1.5
@@ -3,6 +3,11 @@
rb_mCairo DATA
rb_cCairo_Context DATA
rb_cCairo_Path DATA
+ rb_cCairo_PathData DATA
+ rb_cCairo_PathMoveTo DATA
+ rb_cCairo_PathLineTo DATA
+ rb_cCairo_PathCurveTo DATA
+ rb_cCairo_PathClosePath DATA
rb_cCairo_Matrix DATA
rb_cCairo_Pattern DATA
rb_cCairo_SolidPattern DATA
Index: rb_cairo.h
===================================================================
RCS file: /cvs/cairo/rcairo/src/rb_cairo.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- rb_cairo.h 20 May 2007 08:46:06 -0000 1.7
+++ rb_cairo.h 22 May 2007 11:25:39 -0000 1.8
@@ -59,6 +59,10 @@
RUBY_CAIRO_VAR VALUE rb_cCairo_Point;
RUBY_CAIRO_VAR VALUE rb_cCairo_Path;
RUBY_CAIRO_VAR VALUE rb_cCairo_PathData;
+RUBY_CAIRO_VAR VALUE rb_cCairo_PathMoveTo;
+RUBY_CAIRO_VAR VALUE rb_cCairo_PathLineTo;
+RUBY_CAIRO_VAR VALUE rb_cCairo_PathCurveTo;
+RUBY_CAIRO_VAR VALUE rb_cCairo_PathClosePath;
RUBY_CAIRO_VAR VALUE rb_cCairo_Matrix;
RUBY_CAIRO_VAR VALUE rb_cCairo_Pattern;
RUBY_CAIRO_VAR VALUE rb_cCairo_SolidPattern;
Index: rb_cairo_path.c
===================================================================
RCS file: /cvs/cairo/rcairo/src/rb_cairo_path.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- rb_cairo_path.c 6 May 2007 10:10:50 -0000 1.7
+++ rb_cairo_path.c 22 May 2007 11:25:39 -0000 1.8
@@ -19,11 +19,21 @@
VALUE rb_cCairo_Point;
VALUE rb_cCairo_Path;
VALUE rb_cCairo_PathData;
+VALUE rb_cCairo_PathMoveTo;
+VALUE rb_cCairo_PathLineTo;
+VALUE rb_cCairo_PathCurveTo;
+VALUE rb_cCairo_PathClosePath;
static ID id_new, id_current_path;
static ID id_at_x, id_at_y, id_at_type, id_at_points, id_at_context;
static VALUE
+cr_point_new (VALUE x, VALUE y)
+{
+ return rb_funcall (rb_cCairo_Point, id_new, 2, x, y);
+}
+
+static VALUE
cr_point_initialize (VALUE self, VALUE x, VALUE y)
{
rb_ivar_set (self, id_at_x, x);
@@ -93,21 +103,126 @@
static VALUE
cr_path_data_to_ruby_object (cairo_path_data_t *data)
{
+ VALUE rb_data = Qnil;
+
+ switch (data->header.type)
+ {
+ case CAIRO_PATH_MOVE_TO:
+ rb_data = rb_funcall (rb_cCairo_PathMoveTo, id_new, 2,
+ rb_float_new (data[1].point.x),
+ rb_float_new (data[1].point.y));
+ break;
+ case CAIRO_PATH_LINE_TO:
+ rb_data = rb_funcall (rb_cCairo_PathLineTo, id_new, 2,
+ rb_float_new (data[1].point.x),
+ rb_float_new (data[1].point.y));
+ break;
+ case CAIRO_PATH_CURVE_TO:
+ rb_data = rb_funcall (rb_cCairo_PathCurveTo, id_new, 6,
+ rb_float_new (data[1].point.x),
+ rb_float_new (data[1].point.y),
+ rb_float_new (data[2].point.x),
+ rb_float_new (data[2].point.y),
+ rb_float_new (data[3].point.x),
+ rb_float_new (data[3].point.y));
+ break;
+ case CAIRO_PATH_CLOSE_PATH:
+ rb_data = rb_funcall (rb_cCairo_PathClosePath, id_new, 0);
+ break;
+ }
+
+ return rb_data;
+
int i;
VALUE points;
points = rb_ary_new ();
for (i = 1; i < data->header.length; i++)
{
- rb_ary_push (points, rb_funcall (rb_cCairo_Point, id_new, 2,
- rb_float_new (data[i].point.x),
- rb_float_new (data[i].point.y)));
+ rb_ary_push (points, cr_point_new (rb_float_new (data[i].point.x),
+ rb_float_new (data[i].point.y)));
}
return rb_funcall (rb_cCairo_PathData, id_new, 2,
INT2FIX (data->header.type), points);
}
+
+static VALUE
+cr_path_move_to_initialize (int argc, VALUE *argv, VALUE self)
+{
+ VALUE point, x, y;
+
+ rb_scan_args (argc, argv, "11", &x, &y);
+
+ if (argc == 1)
+ point = x;
+ else
+ point = cr_point_new (x, y);
+
+ return cr_path_data_initialize (self,
+ INT2NUM (CAIRO_PATH_MOVE_TO),
+ rb_ary_new3 (1, point));
+}
+
+static VALUE
+cr_path_line_to_initialize (int argc, VALUE *argv, VALUE self)
+{
+ VALUE point, x, y;
+
+ rb_scan_args (argc, argv, "11", &x, &y);
+
+ if (argc == 1)
+ point = x;
+ else
+ point = cr_point_new (x, y);
+
+ return cr_path_data_initialize (self,
+ INT2NUM (CAIRO_PATH_LINE_TO),
+ rb_ary_new3 (1, point));
+}
+
+static VALUE
+cr_path_curve_to_initialize (int argc, VALUE *argv, VALUE self)
+{
+ VALUE point1, point2, point3, x1, y1, x2, y2, x3, y3;
+
+ rb_scan_args (argc, argv, "33", &x1, &y1, &x2, &y2, &x3, &y3);
+
+ if (argc == 3)
+ {
+ point1 = x1;
+ point2 = y1;
+ point3 = x2;
+ }
+ else if (argc == 6)
+ {
+ point1 = cr_point_new (x1, y1);
+ point2 = cr_point_new (x2, y2);
+ point3 = cr_point_new (x3, y3);
+ }
+ else
+ {
+ VALUE inspected_arg = rb_inspect (rb_ary_new4 (argc, argv));
+ rb_raise (rb_eArgError,
+ "invalid argument: %s (expect "
+ "(point1, point2, point3) or "
+ "(x1, y1, x2, y2, x3, y3))",
+ StringValuePtr (inspected_arg));
+ }
+
+ return cr_path_data_initialize (self, INT2NUM (CAIRO_PATH_CURVE_TO),
+ rb_ary_new3 (3, point1, point2, point3));
+}
+
+static VALUE
+cr_path_close_path_initialize (VALUE self)
+{
+ return cr_path_data_initialize (self, INT2NUM (CAIRO_PATH_CLOSE_PATH),
+ rb_ary_new ());
+}
+
+
static void
cr_path_free (void *ptr)
{
@@ -310,6 +425,27 @@
rb_define_alias (rb_cCairo_PathData, "to_ary", "to_a");
+ rb_cCairo_PathMoveTo =
+ rb_define_class_under (rb_mCairo, "PathMoveTo", rb_cCairo_PathData);
+ rb_define_method (rb_cCairo_PathMoveTo, "initialize",
+ cr_path_move_to_initialize, -1);
+
+ rb_cCairo_PathLineTo =
+ rb_define_class_under (rb_mCairo, "PathLineTo", rb_cCairo_PathData);
+ rb_define_method (rb_cCairo_PathLineTo, "initialize",
+ cr_path_line_to_initialize, -1);
+
+ rb_cCairo_PathCurveTo =
+ rb_define_class_under (rb_mCairo, "PathCurveTo", rb_cCairo_PathData);
+ rb_define_method (rb_cCairo_PathCurveTo, "initialize",
+ cr_path_curve_to_initialize, -1);
+
+ rb_cCairo_PathClosePath =
+ rb_define_class_under (rb_mCairo, "PathClosePath", rb_cCairo_PathData);
+ rb_define_method (rb_cCairo_PathClosePath, "initialize",
+ cr_path_close_path_initialize, 0);
+
+
rb_cCairo_Path = rb_define_class_under (rb_mCairo, "Path", rb_cObject);
rb_define_alloc_func (rb_cCairo_Path, cr_path_allocate);
More information about the cairo-commit
mailing list