Class: SDL2::Rect
- Inherits:
-
Object
- Object
- SDL2::Rect
- Defined in:
- ext/sdl2_ext/video.c,
ext/sdl2_ext/video.c
Overview
This class represents a rectangle in SDL2.
Any rectangle is represented by four attributes x, y, w, and h, and these four attributes must be integer.
Instance Attribute Summary collapse
-
#h ⇒ Integer
Height of the rectangle.
-
#w ⇒ Integer
Width of the rectangle.
-
#x ⇒ Integer
X coordinate of the left-top point of the rectangle.
-
#y ⇒ Integer
Y coordinate of the left-top point of the rectangle.
Class Method Summary collapse
-
.[](*args) ⇒ SDL2::Rect
Alias of new.
Instance Method Summary collapse
-
#initialize(*args) ⇒ SDL2::Rect
constructor
Create a new SDL2::Rect object.
-
#inspect ⇒ String
Inspection string for debug.
-
#intersection(other) ⇒ SDL2::Rect?
Returns the intersection rect of self and other.
-
#union(other) ⇒ SDL2::Rect
Returns the minimal rect containing self and other.
Constructor Details
#initialize(x, y, w, h) ⇒ SDL2::Rect #initialize ⇒ SDL2::Rect
Create a new SDL2::Rect object
3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 |
# File 'ext/sdl2_ext/video.c', line 3049
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
#h ⇒ Integer
Height of the rectangle
#w ⇒ Integer
Width of the rectangle
#x ⇒ Integer
X coordinate of the left-top point of the rectangle
#y ⇒ Integer
Y coordinate of the left-top point of the rectangle
Class Method Details
.[](*args) ⇒ SDL2::Rect
Alias of new. See #initialize.
Instance Method Details
#inspect ⇒ String
Inspection string for debug
3070 3071 3072 3073 3074 3075 |
# File 'ext/sdl2_ext/video.c', line 3070
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);
}
|
#intersection(other) ⇒ SDL2::Rect?
3091 3092 3093 3094 3095 3096 3097 3098 3099 |
# File 'ext/sdl2_ext/video.c', line 3091
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;
}
}
|
#union(other) ⇒ SDL2::Rect
3108 3109 3110 3111 3112 3113 |
# File 'ext/sdl2_ext/video.c', line 3108
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;
}
|