Class: SDL2::Rect
- Inherits:
-
Object
- Object
- SDL2::Rect
- Defined in:
- video.c,
video.c
Overview
This class represents a rectangle in SDL2.
Any rectanle is represented by four attributes x, y, w, and h, and these four attributes must be integer.
Instance Attribute Summary (collapse)
-
- (Integer) h
Height of the rectangle.
-
- (Integer) w
Width of the rectangle.
-
- (Integer) x
X coordiante of the left-top point of the rectangle.
-
- (Integer) y
Y coordiante of the left-top point of the rectangle.
Class Method Summary (collapse)
-
+ (SDL2::Rect) [](*args)
Alias of new.
Instance Method Summary (collapse)
-
- (SDL2::Rect) initialize
constructor
Create a new SDL2::Rect object.
-
- (String) inspect
Inspection string for debug.
-
- (SDL2::Rect?) intersection(other)
Returns the intersection rect of self and other.
-
- (SDL2::Rect) union(other)
Returns the minimal rect containing self and other.
Constructor Details
- (SDL2::Rect) initialze(x, y, w, h) - (SDL2::Rect) initialize
Create a new SDL2::Rect object
2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 |
# File 'video.c', line 2355
static VALUE Rect_initialize(int argc, VALUE* argv, VALUE self)
{
VALUE x, y, w, h;
rb_scan_args(argc, argv, "04", &x, &y, &w, &h);
if (argc == 0) {
/* do nothing*/
} else if (argc == 4) {
SDL_Rect* rect;
Data_Get_Struct(self, SDL_Rect, rect);
rect->x = NUM2INT(x); rect->y = NUM2INT(y);
rect->w = NUM2INT(w); rect->h = NUM2INT(h);
} else {
rb_raise(rb_eArgError, "wrong number of arguments (%d for 0 or 4)", argc);
}
return Qnil;
}
|
Instance Attribute Details
- (Integer) h
Height of the rectangle
- (Integer) w
Width of the rectangle
- (Integer) x
X coordiante of the left-top point of the rectangle
- (Integer) y
Y coordiante of the left-top point of the rectangle
Class Method Details
+ (SDL2::Rect) [](*args)
Alias of new. See #initialize.
Instance Method Details
- (String) inspect
Inspection string for debug
2376 2377 2378 2379 2380 2381 |
# File 'video.c', line 2376
static VALUE Rect_inspect(VALUE self)
{
SDL_Rect* rect = Get_SDL_Rect(self);
return rb_sprintf("<SDL2::Rect: x=%d y=%d w=%d h=%d>",
rect->x, rect->y, rect->w, rect->h);
}
|
- (SDL2::Rect?) intersection(other)
2397 2398 2399 2400 2401 2402 2403 2404 2405 |
# File 'video.c', line 2397
static VALUE Rect_intersection(VALUE self, VALUE other)
{
VALUE result = Rect_s_allocate(cRect);
if (SDL_IntersectRect(Get_SDL_Rect(self), Get_SDL_Rect(other), Get_SDL_Rect(result))) {
return result;
} else {
return Qnil;
}
}
|
- (SDL2::Rect) union(other)
2414 2415 2416 2417 2418 2419 |
# File 'video.c', line 2414
static VALUE Rect_union(VALUE self, VALUE other)
{
VALUE result = Rect_s_allocate(cRect);
SDL_UnionRect(Get_SDL_Rect(self), Get_SDL_Rect(other), Get_SDL_Rect(result));
return result;
}
|