class Cairo::Region
Public Class Methods
new(*args)
click to toggle source
static VALUE
cr_region_initialize (int argc, VALUE *argv, VALUE self)
{
cairo_region_t *region;
if (argc == 0)
{
region = cairo_region_create ();
}
else
{
int i;
cairo_rectangle_int_t *rectangles;
rectangles = ALLOCA_N (cairo_rectangle_int_t, argc);
for (i = 0; i < argc; i++)
{
VALUE rb_rectangle;
rb_rectangle = rb_check_array_type (argv[i]);
if (RARRAY_LEN (rb_rectangle) != 4)
rb_raise (rb_eArgError,
"invalid argument (expect "
"() or ([x, y, width, height], ...): %s",
rb_cairo__inspect (rb_ary_new4 (argc, argv)));
rectangles[i].x = NUM2INT (RARRAY_PTR (rb_rectangle)[0]);
rectangles[i].y = NUM2INT (RARRAY_PTR (rb_rectangle)[1]);
rectangles[i].width = NUM2INT (RARRAY_PTR (rb_rectangle)[2]);
rectangles[i].height = NUM2INT (RARRAY_PTR (rb_rectangle)[3]);
}
region = cairo_region_create_rectangles (rectangles, argc);
}
cr_region_check_status (region);
RTYPEDDATA_DATA (self) = region;
return Qnil;
}
Public Instance Methods
==(p1)
click to toggle source
static VALUE
cr_region_equal (VALUE self, VALUE other)
{
cairo_region_t *region, *other_region;
if (!rb_cairo__is_kind_of (other, rb_cCairo_Region))
return Qfalse;
region = _SELF;
other_region = RVAL2CRREGION (other);
return CBOOL2RVAL (cairo_region_equal (region, other_region));
}
[](p1)
click to toggle source
static VALUE
cr_region_get_rectangle (VALUE self, VALUE index)
{
cairo_region_t *region;
cairo_rectangle_int_t extents;
region = _SELF;
cairo_region_get_rectangle (region, NUM2INT (index), &extents);
cr_region_check_status (region);
return rb_ary_new3 (4,
INT2NUM (extents.x), INT2NUM (extents.y),
INT2NUM (extents.width), INT2NUM (extents.height));
}
contains_point?(*args)
click to toggle source
static VALUE
cr_region_containts_point (int argc, VALUE *argv, VALUE self)
{
cairo_region_t *region;
int x, y;
VALUE arg1, arg2;
const char *error_message =
"invalid argument (expect "
"(x, y) or ([x, y])): %s";
rb_scan_args (argc, argv, "11", &arg1, &arg2);
region = _SELF;
if (argc == 1)
{
VALUE point;
point = rb_check_array_type (arg1);
if (RARRAY_LEN (point) != 4)
rb_raise (rb_eArgError, error_message,
rb_cairo__inspect (rb_ary_new4 (argc, argv)));
x = NUM2INT (RARRAY_PTR (point)[0]);
y = NUM2INT (RARRAY_PTR (point)[1]);
}
else
{
x = NUM2INT (arg1);
y = NUM2INT (arg2);
}
return CBOOL2RVAL (cairo_region_contains_point (region, x, y));
}
contains_rectangle(*args)
click to toggle source
static VALUE
cr_region_containts_rectangle (int argc, VALUE *argv, VALUE self)
{
cairo_region_t *region;
cairo_rectangle_int_t rectangle;
cairo_region_overlap_t overlap;
VALUE arg1, arg2, arg3, arg4;
const char *error_message =
"invalid argument (expect "
"(x, y, width, height) or ([x, y, width, height])): %s";
rb_scan_args (argc, argv, "13", &arg1, &arg2, &arg3, &arg4);
region = _SELF;
if (argc == 1)
{
VALUE rb_rectangle;
rb_rectangle = rb_check_array_type (arg1);
if (RARRAY_LEN (rb_rectangle) != 4)
rb_raise (rb_eArgError, error_message,
rb_cairo__inspect (rb_ary_new4 (argc, argv)));
rectangle.x = NUM2INT (RARRAY_PTR (rb_rectangle)[0]);
rectangle.y = NUM2INT (RARRAY_PTR (rb_rectangle)[1]);
rectangle.width = NUM2INT (RARRAY_PTR (rb_rectangle)[2]);
rectangle.height = NUM2INT (RARRAY_PTR (rb_rectangle)[3]);
}
else if (argc == 4)
{
rectangle.x = NUM2INT (arg1);
rectangle.y = NUM2INT (arg2);
rectangle.width = NUM2INT (arg3);
rectangle.height = NUM2INT (arg4);
}
else
{
rb_raise (rb_eArgError, error_message,
rb_cairo__inspect (rb_ary_new4 (argc, argv)));
}
overlap = cairo_region_contains_rectangle (region, &rectangle);
cr_region_check_status (region);
return INT2NUM (overlap);
}
dup()
click to toggle source
static VALUE
cr_region_dup (VALUE self)
{
cairo_region_t *copied_region;
VALUE rb_copied_region;
copied_region = cairo_region_copy (_SELF);
cr_region_check_status (copied_region);
rb_copied_region = CRREGION2RVAL (copied_region);
cairo_region_destroy (copied_region);
return rb_copied_region;
}
each_rectangle() { |self| ... }
click to toggle source
# File lib/cairo/region.rb, line 3 def each_rectangle return to_enum(:each_rectangle) unless block_given? num_rectangles.times.each do |i| yield(self[i]) end end
empty?()
click to toggle source
static VALUE
cr_region_is_empty (VALUE self)
{
return CBOOL2RVAL (cairo_region_is_empty (_SELF));
}
extents()
click to toggle source
static VALUE
cr_region_get_extents (VALUE self)
{
cairo_region_t *region;
cairo_rectangle_int_t extents;
region = _SELF;
cairo_region_get_extents (region, &extents);
cr_region_check_status (region);
return rb_ary_new3 (4,
INT2NUM (extents.x), INT2NUM (extents.y),
INT2NUM (extents.width), INT2NUM (extents.height));
}
num_rectangles()
click to toggle source
static VALUE
cr_region_num_rectangles (VALUE self)
{
cairo_region_t *region;
int num_rectangles;
region = _SELF;
num_rectangles = cairo_region_num_rectangles (region);
cr_region_check_status (region);
return INT2NUM (num_rectangles);
}
rectangles()
click to toggle source
# File lib/cairo/region.rb, line 10 def rectangles each_rectangle.to_a end
translate!(*args)
click to toggle source
static VALUE
cr_region_translate (int argc, VALUE *argv, VALUE self)
{
cairo_region_t *region;
int x, y;
VALUE arg1, arg2;
const char *error_message =
"invalid argument (expect "
"(x, y) or ([x, y])): %s";
rb_scan_args (argc, argv, "11", &arg1, &arg2);
region = _SELF;
if (argc == 1)
{
VALUE point;
point = rb_check_array_type (arg1);
if (RARRAY_LEN (point) != 4)
rb_raise (rb_eArgError, error_message,
rb_cairo__inspect (rb_ary_new4 (argc, argv)));
x = NUM2INT (RARRAY_PTR (point)[0]);
y = NUM2INT (RARRAY_PTR (point)[1]);
}
else
{
x = NUM2INT (arg1);
y = NUM2INT (arg2);
}
cairo_region_translate (region, x, y);
cr_region_check_status (region);
return Qnil;
}