sfml3.rb

Class: SFML::VideoMode

Inherits:
Object
  • Object
show all
Defined in:
ext/window/video_mode.c,
ext/window/video_mode.c

Overview

A width/height/bits-per-pixel triple describing a display mode, as used for fullscreen windows.

The +width+/+height+/+bits+ accessors below are declared with rb_define_attr rather than rb_define_method; YARD's C parser cannot handle that declaration form (a confirmed YARD bug), so they are documented here instead of above their (nonexistent, ivar-backed) definitions.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#new(width, height, bits_per_pixel) ⇒ VideoMode

Creates a video mode with the given width, height and bits_per_pixel.



63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'ext/window/video_mode.c', line 63

static VALUE VideoMode_initialize(VALUE self, VALUE rb_width, VALUE rb_height, VALUE rb_bits) {
    sfVideoMode* mode = Get_Mode_Struct(self);

    mode->size.x = (unsigned)NUM2UINT(rb_width);
    mode->size.y = (unsigned)NUM2UINT(rb_height);
    mode->bitsPerPixel = (unsigned)NUM2UINT(rb_bits);

    rb_iv_set(self, "@width", rb_width);
    rb_iv_set(self, "@height", rb_height);
    rb_iv_set(self, "@bits", rb_bits);

    return self;
}

Instance Attribute Details

#bits ⇒ Integer (readonly)

Bits per pixel.

Returns:

  • (Integer) —

    bits per pixel

#height ⇒ Integer (readonly)

Height in pixels.

Returns:

  • (Integer) —

    height in pixels

#width ⇒ Integer (readonly)

Width in pixels.

Returns:

  • (Integer) —

    width in pixels

Class Method Details

.desktop_mode ⇒ VideoMode

Returns the current desktop video mode.

Returns:

Returns:

  • (VideoMode) —

    the current desktop video mode



83
84
85
# File 'ext/window/video_mode.c', line 83

static VALUE VideoMode_desktop_mode(VALUE klass) {
    return VideoMode_from_c(sfVideoMode_getDesktopMode());
}

.fullscreen_modes ⇒ Array<VideoMode>

Returns all fullscreen video modes supported by the current desktop.

Returns:

Returns:

  • (Array<VideoMode>) —

    all video modes supported in fullscreen mode, sorted from best to worst



94
95
96
97
98
99
100
101
102
103
104
# File 'ext/window/video_mode.c', line 94

static VALUE VideoMode_fullscreen_modes(VALUE klass) {
    size_t count = 0;
    const sfVideoMode* modes = sfVideoMode_getFullscreenModes(&count);
    VALUE array = rb_ary_new_capa((long)count);

    for (size_t i = 0; i < count; i++) {
        rb_ary_push(array, VideoMode_from_c(modes[i]));
    }

    return array;
}

Instance Method Details

#==(other) ⇒ Boolean

Returns true if other has the same size and bit depth.

Returns:

  • (Boolean)

Returns:

  • (Boolean)


136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'ext/window/video_mode.c', line 136

static VALUE VideoMode_eql(VALUE self, VALUE rb_other) {
    sfVideoMode a = *Get_Mode_Struct(self);
    sfVideoMode b;

    if (!rb_obj_is_kind_of(rb_other, rb_cMode)) {
        return Qfalse;
    }

    b = *Get_Mode_Struct(rb_other);

    return BOOL2RB(a.size.x == b.size.x && a.size.y == b.size.y &&
                   a.bitsPerPixel == b.bitsPerPixel);
}

#valid? ⇒ Boolean

Returns true if this mode is valid for fullscreen use.

Returns:

  • (Boolean)

Returns:

  • (Boolean) —

    whether this mode is valid for fullscreen use on the current desktop



113
114
115
# File 'ext/window/video_mode.c', line 113

static VALUE VideoMode_is_available(VALUE self) {
    return BOOL2RB(sfVideoMode_isValid(*Get_Mode_Struct(self)));
}

#size ⇒ Vector2

Returns width and height as a Vector2.

Returns:

Returns:

  • (Vector2) —

    width and height as a vector



123
124
125
126
127
# File 'ext/window/video_mode.c', line 123

static VALUE VideoMode_get_size(VALUE self) {
    sfVideoMode* mode = Get_Mode_Struct(self);

    return vec2f_to_rb((sfVector2f){(float)mode->size.x, (float)mode->size.y});
}

#valid? ⇒ Boolean

Returns true if this mode is valid for fullscreen use.

Returns:

  • (Boolean)

Returns:

  • (Boolean) —

    whether this mode is valid for fullscreen use on the current desktop



113
114
115
# File 'ext/window/video_mode.c', line 113

static VALUE VideoMode_is_available(VALUE self) {
    return BOOL2RB(sfVideoMode_isValid(*Get_Mode_Struct(self)));
}