# class Cairo::GradientPattern

### Public Instance Methods

add_color_stop(*args) click to toggle source

Cairo::GradientPattern

    static VALUE
    cr_gradient_pattern_add_color_stop_generic (int argc, VALUE *argv, VALUE self)
    {
      VALUE offset, red, green, blue, alpha;
      int n;

      n = rb_scan_args (argc, argv, "23", &offset, &red, &green, &blue, &alpha);

      if (n == 2)
        {
          VALUE color = red;

          color = cr_color_parse (color);
          if (rb_cairo__is_kind_of (color, rb_cCairo_Color_Base))
            red = rb_funcall (rb_funcall (color, id_to_rgb, 0), id_to_a, 0);
        }

      if (n == 2 && rb_cairo__is_kind_of (red, rb_cArray))
        {
          VALUE ary = red;
          n = RARRAY_LEN (ary) + 1;

          red = rb_ary_entry (ary, 0);
          green = rb_ary_entry (ary, 1);
          blue = rb_ary_entry (ary, 2);
          alpha = rb_ary_entry (ary, 3);
        }

      if (n == 4 || (n == 5 && NIL_P (alpha)))
        {
          cairo_pattern_add_color_stop_rgb (_SELF (self), NUM2DBL (offset),
                                            NUM2DBL (red), NUM2DBL (green),
                                            NUM2DBL (blue));
        }
      else if (n == 5)
        {
          cairo_pattern_add_color_stop_rgba (_SELF (self), NUM2DBL (offset),
                                             NUM2DBL (red), NUM2DBL (green),
                                             NUM2DBL (blue), NUM2DBL (alpha));
        }
      else
        {
          VALUE inspected;

          inspected = rb_funcall (rb_ary_new4 (argc, argv), id_inspect, 0);
          rb_raise (rb_eArgError,
                    "invalid argument: %s (expect "
                    "(offset, color_name), "
                    "(offset, color_hex_triplet), "
                    "(offset, Cairo::Color::RGB), "
                    "(offset, Cairo::Color::CMYK), "
                    "(offset, Cairo::Color::HSV), "
                    "(offset, red, green, blue), "
                    "(offset, [red, green, blue]), "
                    "(offset, red, green, blue, alpha) or "
                    "(offset, [red, green, blue, alpha])"
                    ")",
                    RVAL2CSTR (inspected));
        }

      cr_pattern_check_status (_SELF (self));
      return self;
    }

Also aliased as: add_color_stop_rgb, add_color_stop_rgba
add_color_stop_rgb(*args)
Alias for: add_color_stop
add_color_stop_rgba(*args)
Alias for: add_color_stop
color_stop_count() click to toggle source

    static VALUE
    cr_gradient_pattern_get_color_stop_count (VALUE self)
    {
      cairo_status_t status;
      int count;

      status = cairo_pattern_get_color_stop_count (_SELF (self), &count);
      rb_cairo_check_status (status);
      return INT2NUM (count);
    }

get_color_stop_color(p1) click to toggle source

    static VALUE
    cr_gradient_pattern_get_color_stop_color (VALUE self, VALUE index)
    {
      VALUE result, offset, rgba;

      result = cr_gradient_pattern_get_color_stop_rgba (self, index);
      offset = rb_ary_shift (result);
      rgba = result;

      return rb_ary_new3 (2, offset, cr_color_parse (rgba));
    }

get_color_stop_rgba(p1) click to toggle source

    static VALUE
    cr_gradient_pattern_get_color_stop_rgba (VALUE self, VALUE index)
    {
      cairo_status_t status;
      double offset, red, green, blue, alpha;

      status = cairo_pattern_get_color_stop_rgba (_SELF (self), NUM2INT (index),
                                                  &offset, &red, &green, &blue,
                                                  &alpha);
      rb_cairo_check_status (status);
      return rb_ary_new3 (5, rb_float_new (offset),
                          rb_float_new (red), rb_float_new (green),
                          rb_float_new (blue), rb_float_new (alpha));
    }