Class: SDL2::Rect

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialze(x, y, w, h) ⇒ SDL2::Rect #initializeSDL2::Rect

Create a new SDL2::Rect object

Overloads:

  • #initialze(x, y, w, h) ⇒ SDL2::Rect

    Create a new SDL2::Rect object

    Parameters:

    • x (Integer)

      X coordiante of the left-top point of the rectangle

    • y (Integer)

      Y coordiante of the left-top point of the rectangle

    • w (Integer)

      Width of the rectangle

    • h (Integer)

      Height of the rectangle

  • #initializeSDL2::Rect

    Create a new SDL2::Rect object whose x, w, w, and h are all zero.



2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
# File 'video.c', line 2584

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;
        TypedData_Get_Struct(self, SDL_Rect, &SDL_Rect_data_type, 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

#hInteger

Height of the rectangle

Returns:

  • (Integer)

#wInteger

Width of the rectangle

Returns:

  • (Integer)

#xInteger

X coordiante of the left-top point of the rectangle

Returns:

  • (Integer)

#yInteger

Y coordiante of the left-top point of the rectangle

Returns:

  • (Integer)

Class Method Details

.[](x, y, w, h) ⇒ SDL2::Rect

Alias of new. See #initialize.

Parameters:

  • x (Integer)

    X coordiante of the left-top point of the rectangle

  • y (Integer)

    Y coordiante of the left-top point of the rectangle

  • w (Integer)

    Width of the rectangle

  • h (Integer)

    Height of the rectangle

Returns:

Instance Method Details

#inspectString

Inspection string for debug

Returns:

  • (String)


2605
2606
2607
2608
2609
2610
# File 'video.c', line 2605

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?

Returns the intersection rect of self and other.

If there is no intersection, returns nil.

Parameters:

Returns:



2626
2627
2628
2629
2630
2631
2632
2633
2634
# File 'video.c', line 2626

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

Returns the minimal rect containing self and other

Parameters:

Returns:



2643
2644
2645
2646
2647
2648
# File 'video.c', line 2643

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;
}