Class: SFML::VideoMode

Inherits:
Object
  • Object
show all
Defined in:
lib/sfml/window/video_mode.rb

Overview

Video mode = (width, height, bits-per-pixel). Used when creating windows.

SFML::VideoMode.new(800, 600)
SFML::VideoMode.desktop_mode

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(width, height, bits_per_pixel = 32) ⇒ VideoMode

Returns a new instance of VideoMode.



9
10
11
12
13
14
# File 'lib/sfml/window/video_mode.rb', line 9

def initialize(width, height, bits_per_pixel = 32)
  @width = Integer(width)
  @height = Integer(height)
  @bits_per_pixel = Integer(bits_per_pixel)
  freeze
end

Instance Attribute Details

#bits_per_pixelObject (readonly)

Returns the value of attribute bits_per_pixel.



7
8
9
# File 'lib/sfml/window/video_mode.rb', line 7

def bits_per_pixel
  @bits_per_pixel
end

#heightObject (readonly)

Returns the value of attribute height.



7
8
9
# File 'lib/sfml/window/video_mode.rb', line 7

def height
  @height
end

#widthObject (readonly)

Returns the value of attribute width.



7
8
9
# File 'lib/sfml/window/video_mode.rb', line 7

def width
  @width
end

Class Method Details

.desktop_modeObject



16
17
18
# File 'lib/sfml/window/video_mode.rb', line 16

def self.desktop_mode
  from_native(C::Window.sfVideoMode_getDesktopMode)
end

.from_native(struct) ⇒ Object

:nodoc:



47
48
49
# File 'lib/sfml/window/video_mode.rb', line 47

def self.from_native(struct) # :nodoc:
  new(struct[:size][:x], struct[:size][:y], struct[:bits_per_pixel])
end

.fullscreen_modesObject

All video modes the current display supports for true-fullscreen window creation, sorted from most to least pixels. Filter by bpp or aspect ratio in Ruby as needed.



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/sfml/window/video_mode.rb', line 23

def self.fullscreen_modes
  count_buf = FFI::MemoryPointer.new(:size_t)
  array_ptr = C::Window.sfVideoMode_getFullscreenModes(count_buf)
  n = count_buf.read(:size_t)
  return [] if array_ptr.null? || n.zero?

  stride = C::Window::VideoMode.size
  Array.new(n) do |i|
    from_native(C::Window::VideoMode.new(array_ptr + i * stride))
  end
end

Instance Method Details

#sizeObject



42
# File 'lib/sfml/window/video_mode.rb', line 42

def size = Vector2.new(@width, @height)

#to_nativeObject

:nodoc:



51
52
53
54
55
56
57
# File 'lib/sfml/window/video_mode.rb', line 51

def to_native # :nodoc:
  C::Window::VideoMode.new.tap do |m|
    m[:size][:x] = @width
    m[:size][:y] = @height
    m[:bits_per_pixel] = @bits_per_pixel
  end
end

#to_sObject Also known as: inspect



44
# File 'lib/sfml/window/video_mode.rb', line 44

def to_s = "#<SFML::VideoMode #{@width}x#{@height}@#{@bits_per_pixel}>"

#valid?Boolean

Does the display actually support this mode at fullscreen? Always ‘true` for windowed-mode use (only fullscreen is constrained to the OS’s allowed mode list).

Returns:

  • (Boolean)


38
39
40
# File 'lib/sfml/window/video_mode.rb', line 38

def valid?
  C::Window.sfVideoMode_isValid(to_native)
end