[cairo-commit] rcairo/packages/cairo/ext rb_cairo_pattern.c, 1.13, 1.14

Kouhei Sutou commit at pdx.freedesktop.org
Wed Oct 12 08:22:03 PDT 2005


Committed by: kou

Update of /cvs/cairo/rcairo/packages/cairo/ext
In directory gabe:/tmp/cvs-serv3672/packages/cairo/ext

Modified Files:
	rb_cairo_pattern.c 
Log Message:
* packages/cairo/ext/rb_cairo_pattern.c: Added
  Cairo::GradientPattern#add_color_stop_rgb and
  Cairo::GradientPattern#add_color_stop for convenience.


Index: rb_cairo_pattern.c
===================================================================
RCS file: /cvs/cairo/rcairo/packages/cairo/ext/rb_cairo_pattern.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- rb_cairo_pattern.c	11 Oct 2005 13:23:49 -0000	1.13
+++ rb_cairo_pattern.c	12 Oct 2005 15:21:56 -0000	1.14
@@ -168,6 +168,45 @@
 
 /* Cairo::GradientPattern */
 static VALUE
+cr_gradient_pattern_add_color_stop_rgb (int argc, VALUE *argv, VALUE self)
+{
+  VALUE offset, red, green, blue;
+  int n;
+  
+  n = rb_scan_args (argc, argv, "22", &offset, &red, &green, &blue);
+
+  if (n == 2 && rb_obj_is_kind_of (red, rb_cArray))
+    {
+      VALUE ary = red;
+      n = RARRAY (ary)->len + 1;
+      
+      red = rb_ary_entry (ary, 0);
+      green = rb_ary_entry (ary, 1);
+      blue = rb_ary_entry (ary, 2);
+    }
+
+  if (n == 4)
+    {
+      cairo_pattern_add_color_stop_rgb (_SELF (self), NUM2DBL (offset),
+                                        NUM2DBL (red), NUM2DBL (green),
+                                        NUM2DBL (blue));
+    }
+  else
+    {
+      VALUE inspected_arg = rb_inspect (rb_ary_new4 (argc, argv));
+      rb_raise (rb_eArgError,
+                "invalid argument: %s (expect "
+                "(offset, red, green, blue) or "
+                "(offset, [red, green, blue])"
+                ")",
+                StringValuePtr (inspected_arg));
+    }
+
+  cr_pattern_check_status (_SELF (self));
+  return self;
+}
+
+static VALUE
 cr_gradient_pattern_add_color_stop_rgba (int argc, VALUE *argv, VALUE self)
 {
   VALUE offset, red, green, blue, alpha;
@@ -175,8 +214,7 @@
   
   n = rb_scan_args (argc, argv, "23", &offset, &red, &green, &blue, &alpha);
 
-  if (n == 2 && rb_obj_is_kind_of (red, rb_cArray) &&
-      (RARRAY (red)->len == 3 || RARRAY (red)->len == 4))
+  if (n == 2 && rb_obj_is_kind_of (red, rb_cArray))
     {
       VALUE ary = red;
       n = RARRAY (ary)->len + 1;
@@ -201,13 +239,15 @@
     }
   else
     {
+      VALUE inspected_arg = rb_inspect (rb_ary_new4 (argc, argv));
       rb_raise (rb_eArgError,
-                "invalid argument (expect "
+                "invalid argument: %s (expect "
                 "(offset, red, green, blue), "
                 "(offset, [red, green, blue]), "
                 "(offset, red, green, blue, alpha) or "
                 "(offset, [red, green, blue, alpha])"
-                ")");
+                ")",
+                StringValuePtr (inspected_arg));
     }
 
   cr_pattern_check_status (_SELF (self));
@@ -299,8 +339,12 @@
   rb_cCairo_GradientPattern =
     rb_define_class_under (rb_mCairo, "GradientPattern", rb_cCairo_Pattern);
 
+  rb_define_method (rb_cCairo_GradientPattern, "add_color_stop_rgb",
+                    cr_gradient_pattern_add_color_stop_rgb, -1);
   rb_define_method (rb_cCairo_GradientPattern, "add_color_stop_rgba",
                     cr_gradient_pattern_add_color_stop_rgba, -1);
+  rb_define_alias (rb_cCairo_GradientPattern,
+                   "add_color_stop", "add_color_stop_rgba");
 
   rb_cCairo_LinearPattern =
     rb_define_class_under (rb_mCairo, "LinearPattern",



More information about the cairo-commit mailing list