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
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 104 105 106 107 108 109 110 111 |
# File 'ext/cairo/rb_cairo_region.c', line 76
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;
}
|
Instance Method Details
#== ⇒ Object
126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'ext/cairo/rb_cairo_region.c', line 126
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
165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'ext/cairo/rb_cairo_region.c', line 165
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
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 |
# File 'ext/cairo/rb_cairo_region.c', line 230
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
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 221 222 223 224 225 226 227 228 |
# File 'ext/cairo/rb_cairo_region.c', line 185
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
113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'ext/cairo/rb_cairo_region.c', line 113
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
179 180 181 182 183 |
# File 'ext/cairo/rb_cairo_region.c', line 179
static VALUE
cr_region_is_empty (VALUE self)
{
return CBOOL2RVAL (cairo_region_is_empty (_SELF));
}
|
#extents ⇒ Object
139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'ext/cairo/rb_cairo_region.c', line 139
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
153 154 155 156 157 158 159 160 161 162 163 |
# File 'ext/cairo/rb_cairo_region.c', line 153
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
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 288 289 290 291 292 293 294 295 |
# File 'ext/cairo/rb_cairo_region.c', line 262
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;
}
|