class Cairo::SolidPattern - cairo-1.14.1 Documentation

# class Cairo::SolidPattern

### Public Class Methods

new(*args) click to toggle source

    static VALUE
    cr_solid_pattern_initialize (int argc, VALUE *argv, VALUE self)
    {
      VALUE red, green, blue, alpha;
      int n;
      cairo_pattern_t *pattern;

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

      if (n == 1)
        {
          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 == 1 && rb_cairo__is_kind_of (red, rb_cArray) &&
          (RARRAY_LEN (red) == 3 || RARRAY_LEN (red) == 4))
        {
          VALUE ary = red;
          n = RARRAY_LEN (ary);

          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 == 3)
        {
          pattern = cairo_pattern_create_rgb (NUM2DBL (red),
                                              NUM2DBL (green),
                                              NUM2DBL (blue));
        }
      else if (n == 4)
        {
          pattern = cairo_pattern_create_rgba (NUM2DBL (red),
                                               NUM2DBL (green),
                                               NUM2DBL (blue),
                                               NUM2DBL (alpha));
        }
      else
        {
          VALUE inspected;

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

      cr_pattern_check_status (pattern);
      DATA_PTR (self) = pattern;
      return Qnil;
    }

### Public Instance Methods

color() click to toggle source

    static VALUE
    cr_solid_pattern_get_color (VALUE self)
    {
      return cr_color_parse (cr_solid_pattern_get_rgba (self));
    }

rgba() click to toggle source

    static VALUE
    cr_solid_pattern_get_rgba (VALUE self)
    {
      double red, green, blue, alpha;

      rb_cairo_check_status (cairo_pattern_get_rgba (_SELF (self),
                                                     &red, &green, &blue, &alpha));
      return rb_ary_new3 (4,
                          rb_float_new (red), rb_float_new (green),
                          rb_float_new (blue), rb_float_new (alpha));
    }