Class: SDL2::Display

Inherits:
Object
  • Object
show all
Defined in:
ext/sdl2_ext/video.c,
ext/sdl2_ext/video.c

Overview

This class represents displays, screens, or monitors.

This means that if you use dual screen, Display.displays returns two displays.

This class handles color depth, resolution, and refresh rate of displays.

Defined Under Namespace

Classes: Mode

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#indexInteger (readonly)

The index of the display, 0 origin

Returns:

  • (Integer)

#nameStirng (readonly)

The name of the display

Returns:

  • (Stirng)

Class Method Details

.displaysArray<SDL2::Display>

Get all connected displays.

Returns:



1002
1003
1004
1005
1006
1007
1008
1009
1010
# File 'ext/sdl2_ext/video.c', line 1002

static VALUE Display_s_displays(VALUE self)
{
    int i;
    int num_displays = HANDLE_ERROR(SDL_GetNumVideoDisplays());
    VALUE displays = rb_ary_new2(num_displays);
    for (i=0; i<num_displays; ++i)
        rb_ary_push(displays, Display_new(i));
    return displays;
}

Instance Method Details

#boundsRect

Get the desktop area represented by the display, with the primary display located at (0, 0).

Returns:



1092
1093
1094
1095
1096
1097
# File 'ext/sdl2_ext/video.c', line 1092

static VALUE Display_bounds(VALUE self)
{
    VALUE rect = rb_obj_alloc(cRect);
    HANDLE_ERROR(SDL_GetDisplayBounds(Display_index_int(self), Get_SDL_Rect(rect)));
    return rect;
}

#closest_mode(mode) ⇒ SDL2::Display::Mode

Get the available display mode closest match to mode.

Parameters:

Returns:



1077
1078
1079
1080
1081
1082
1083
1084
# File 'ext/sdl2_ext/video.c', line 1077

static VALUE Display_closest_mode(VALUE self, VALUE mode)
{
    SDL_DisplayMode closest;
    if (!SDL_GetClosestDisplayMode(Display_index_int(self), Get_SDL_DisplayMode(mode),
                                   &closest))
        SDL_ERROR();
    return DisplayMode_new(&closest);
}

#current_modeSDL2::Display::Mode

Get the current display mode.

Returns:

See Also:



1044
1045
1046
1047
1048
1049
# File 'ext/sdl2_ext/video.c', line 1044

static VALUE Display_current_mode(VALUE self)
{
    SDL_DisplayMode mode;
    HANDLE_ERROR(SDL_GetCurrentDisplayMode(Display_index_int(self), &mode));
    return DisplayMode_new(&mode);
}

#desktop_modeSDL2::Display::Mode

Get the desktop display mode.

Normally, the return value of this method is same as #current_mode. However, when you use fullscreen and chagne the resolution, this method returns the previous native display mode, and not the current mode.

Returns:



1062
1063
1064
1065
1066
1067
# File 'ext/sdl2_ext/video.c', line 1062

static VALUE Display_desktop_mode(VALUE self)
{
    SDL_DisplayMode mode;
    HANDLE_ERROR(SDL_GetDesktopDisplayMode(Display_index_int(self), &mode));
    return DisplayMode_new(&mode);
}

#modesArray<SDL2::Display::Mode>

Get available display modes of the display.

Returns:



1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
# File 'ext/sdl2_ext/video.c', line 1023

static VALUE Display_modes(VALUE self)
{
    int i;
    int index = Display_index_int(self);
    int num_modes = SDL_GetNumDisplayModes(index);
    VALUE modes = rb_ary_new2(num_modes);
    for (i=0; i<num_modes; ++i) {
        SDL_DisplayMode mode;
        HANDLE_ERROR(SDL_GetDisplayMode(index, i, &mode));
        rb_ary_push(modes, DisplayMode_new(&mode));
    }
    return modes;
}