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

- (Object) index (readonly)

- (Object) name (readonly)

Class Method Details

+ (Array<SDL2::Display>) displays

Get all connected displays.

Returns:



973
974
975
976
977
978
979
980
981
# File 'video.c', line 973

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

- (Rect) bounds

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

Returns:



1063
1064
1065
1066
1067
1068
# File 'video.c', line 1063

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

- (SDL2::Display::Mode) closest_mode(mode)

Get the available display mode closest match to mode.

Parameters:

Returns:



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

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

- (SDL2::Display::Mode) current_mode

Get the current display mode.

Returns:

See Also:



1015
1016
1017
1018
1019
1020
# File 'video.c', line 1015

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

- (SDL2::Display::Mode) desktop_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:



1033
1034
1035
1036
1037
1038
# File 'video.c', line 1033

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

- (Array<SDL2::Display::Mode>) modes

Get available display modes of the display.

Returns:



994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
# File 'video.c', line 994

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