[cairo-commit] rcairo/packages/cairo/ext rb_cairo_context.c, 1.19, 1.20

Kouhei Sutou commit at pdx.freedesktop.org
Tue Oct 11 07:45:44 PDT 2005


Committed by: kou

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

Modified Files:
	rb_cairo_context.c 
Log Message:
* packages/cairo/ext/rb_cairo_context.c: Provided
  Cairo::Context#set_soruce_rgba.
  (cr_arc_negative, cr_arc): cx -> xc and cy -> yc.


Index: rb_cairo_context.c
===================================================================
RCS file: /cvs/cairo/rcairo/packages/cairo/ext/rb_cairo_context.c,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- rb_cairo_context.c	11 Oct 2005 13:23:49 -0000	1.19
+++ rb_cairo_context.c	11 Oct 2005 14:45:41 -0000	1.20
@@ -112,40 +112,6 @@
 
 
 static VALUE
-cr_set_source_rgb (int argc, VALUE *argv, VALUE self)
-{
-  VALUE red, green, blue;
-  int n;
-
-  n = rb_scan_args(argc, argv, "12", &red, &green, &blue);
-
-  if (n == 1 && RTEST (rb_obj_is_kind_of (red, rb_cArray)))
-    {
-      VALUE ary = red;
-      n = RARRAY (ary)->len;
-      if (n >= 3)
-        {
-          red = rb_ary_entry (ary, 0);
-          green = rb_ary_entry (ary, 1);
-          blue = rb_ary_entry (ary, 2);
-        }
-    }
-
-  if (n < 3)
-    {
-      rb_raise (rb_eArgError, "invalid RGB");
-    }
-      
-  cairo_set_source_rgb (_SELF,
-                        NUM2DBL (red),
-                        NUM2DBL (green),
-                        NUM2DBL (blue));
-  cr_check_status (_SELF);
-  rb_ivar_set (self, cr_id_source_class, rb_cCairo_SolidPattern);
-  return self;
-}
-
-static VALUE
 cr_set_source_rgba (int argc, VALUE *argv, VALUE self)
 {
   VALUE red, green, blue, alpha;
@@ -157,7 +123,7 @@
     {
       VALUE ary = red;
       n = RARRAY (ary)->len;
-      if (n >= 4)
+      if (n >= 3)
         {
           red = rb_ary_entry (ary, 0);
           green = rb_ary_entry (ary, 1);
@@ -166,21 +132,34 @@
         }
     }
 
-  if (n < 4)
+  if (n == 3)
     {
-      return cr_set_source_rgb (argc, argv, self);
+      cairo_set_source_rgb (_SELF,
+                            NUM2DBL (red),
+                            NUM2DBL (green),
+                            NUM2DBL (blue));
     }
-  else
+  else if (n == 4)
     {
       cairo_set_source_rgba (_SELF,
                              NUM2DBL (red),
                              NUM2DBL (green),
                              NUM2DBL (blue),
                              NUM2DBL (alpha));
-      cr_check_status (_SELF);
-      rb_ivar_set (self, cr_id_source_class, rb_cCairo_SolidPattern);
-      return self;
     }
+  else
+    {
+      VALUE inspected_arg = rb_inspect (rb_ary_new4 (argc, argv));
+      rb_raise (rb_eArgError,
+                "invalid RGB%s: %s (expect "
+                "(red, green, blue), (red, green, blue, alpha), "
+                "([red, green, blue]) or ([red, green, blue, alpha]))",
+                n == 4 ? "A" : "",
+                StringValuePtr (inspected_arg));
+    }
+  cr_check_status (_SELF);
+  rb_ivar_set (self, cr_id_source_class, rb_cCairo_SolidPattern);
+  return self;
 }
 
 static VALUE
@@ -455,20 +434,20 @@
 }
 
 static VALUE
-cr_arc (VALUE self, VALUE cx, VALUE cy, VALUE radius,
+cr_arc (VALUE self, VALUE xc, VALUE yc, VALUE radius,
         VALUE angle1, VALUE angle2)
 {
-  cairo_arc (_SELF, NUM2DBL (cx), NUM2DBL (cy), NUM2DBL (radius),
+  cairo_arc (_SELF, NUM2DBL (xc), NUM2DBL (yc), NUM2DBL (radius),
              NUM2DBL (angle1), NUM2DBL (angle2));
   cr_check_status (_SELF);
   return self;
 }
 
 static VALUE
-cr_arc_negative (VALUE self, VALUE cx, VALUE cy, VALUE radius,
+cr_arc_negative (VALUE self, VALUE xc, VALUE yc, VALUE radius,
                  VALUE angle1, VALUE angle2)
 {
-  cairo_arc_negative (_SELF, NUM2DBL (cx), NUM2DBL (cy), NUM2DBL (radius),
+  cairo_arc_negative (_SELF, NUM2DBL (xc), NUM2DBL (yc), NUM2DBL (radius),
                       NUM2DBL (angle1), NUM2DBL (angle2));
   cr_check_status (_SELF);
   return self;
@@ -1021,6 +1000,8 @@
   /* Modify state */
   rb_define_method (rb_cCairo_Context, "set_operator", cr_set_operator, 1);
   rb_define_method (rb_cCairo_Context, "set_source", cr_set_source_generic, -1);
+  rb_define_method (rb_cCairo_Context, "set_source_rgba",
+                    cr_set_source_rgba, -1);
   rb_define_method (rb_cCairo_Context, "set_tolerance", cr_set_tolerance, 1);
   rb_define_method (rb_cCairo_Context, "set_antialias", cr_set_antialias, 1);
   rb_define_method (rb_cCairo_Context, "set_fill_rule", cr_set_fill_rule, 1);



More information about the cairo-commit mailing list