Class: Cairo::Region
- Inherits:
-
Object
- Object
- Cairo::Region
- Defined in:
- lib/cairo/region.rb,
ext/cairo/rb_cairo_region.c
Instance Method Summary collapse
- #== ⇒ Object
- #[] ⇒ Object
- #contains_point? ⇒ Boolean
- #contains_rectangle ⇒ Object
- #dup ⇒ Object
- #each_rectangle ⇒ Object
- #empty? ⇒ Boolean
- #extents ⇒ Object
- #initialize ⇒ Object constructor
- #intersect! ⇒ Object
- #num_rectangles ⇒ Object
- #rectangles ⇒ Object
- #subtract! ⇒ Object
- #translate! ⇒ Object
- #union! ⇒ Object
- #xor! ⇒ Object
Constructor Details
#initialize ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'ext/cairo/rb_cairo_region.c', line 68
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);
DATA_PTR (self) = region;
return Qnil;
}
|
Instance Method Details
#== ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'ext/cairo/rb_cairo_region.c', line 118
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));
}
|
#[] ⇒ Object
157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'ext/cairo/rb_cairo_region.c', line 157
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? ⇒ Boolean
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'ext/cairo/rb_cairo_region.c', line 222
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 ⇒ Object
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 |
# File 'ext/cairo/rb_cairo_region.c', line 177
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 ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'ext/cairo/rb_cairo_region.c', line 105
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 ⇒ Object
3 4 5 6 7 8 |
# 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? ⇒ Boolean
171 172 173 174 175 |
# File 'ext/cairo/rb_cairo_region.c', line 171
static VALUE
cr_region_is_empty (VALUE self)
{
return CBOOL2RVAL (cairo_region_is_empty (_SELF));
}
|
#extents ⇒ Object
131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'ext/cairo/rb_cairo_region.c', line 131
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));
}
|
#intersect! ⇒ Object
#num_rectangles ⇒ Object
145 146 147 148 149 150 151 152 153 154 155 |
# File 'ext/cairo/rb_cairo_region.c', line 145
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 ⇒ Object
10 11 12 |
# File 'lib/cairo/region.rb', line 10 def rectangles each_rectangle.to_a end |
#subtract! ⇒ Object
#translate! ⇒ Object
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 |
# File 'ext/cairo/rb_cairo_region.c', line 254
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;
}
|