Class: SDL2::Display

Inherits:
Object
  • Object
show all
Defined in:
video.c,
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)

#nameString (readonly)

The name of the display

Returns:

  • (String)

Class Method Details

.displaysArray<SDL2::Display>

Get all connected displays.

Returns:



1008
1009
1010
1011
1012
1013
1014
1015
1016
# File 'video.c', line 1008

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:



1098
1099
1100
1101
1102
1103
# File 'video.c', line 1098

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:



1083
1084
1085
1086
1087
1088
1089
1090
# File 'video.c', line 1083

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:



1050
1051
1052
1053
1054
1055
# File 'video.c', line 1050

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:



1068
1069
1070
1071
1072
1073
# File 'video.c', line 1068

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:



1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
# File 'video.c', line 1029

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