Class: SDL2::Display

Inherits:
Object
  • Object
show all
Defined in:
lib/sdl2/display.rb,
lib/sdl2/display/mode.rb,
lib/sdl2/display/modes.rb

Overview

Abstract representation of what SDL calls a “Display”

Defined Under Namespace

Classes: Mode, Modes

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(display_id) ⇒ Display

Initialize a new display for index display_id



14
15
16
# File 'lib/sdl2/display.rb', line 14

def initialize(display_id)
  @id = display_id.to_i # It should be an integer.
end

Instance Attribute Details

#idObject (readonly)

Every display has an id, an index.



11
12
13
# File 'lib/sdl2/display.rb', line 11

def id
  @id
end

Class Method Details

.[](display_id) ⇒ Object

Get the display instance for index display_id



24
25
26
27
28
29
30
# File 'lib/sdl2/display.rb', line 24

def self.[](display_id)
  if (idx = display_id.to_i) < count
    return Display.new(display_id)
  else
    return nil
  end
end

.countObject

Get the number of displays



33
34
35
# File 'lib/sdl2/display.rb', line 33

def self.count
  SDL2.get_num_video_displays!()
end

.firstObject

Return the first display



43
44
45
# File 'lib/sdl2/display.rb', line 43

def self.first
  self[0]
end

.numObject

An alias for count, the number of displays



38
39
40
# File 'lib/sdl2/display.rb', line 38

def self.num
  self.count
end

Instance Method Details

#boundsObject

Returns the bounds



62
63
64
65
66
67
68
69
70
# File 'lib/sdl2/display.rb', line 62

def bounds
  rect = SDL2::Rect.new
  if SDL2.get_display_bounds(@id, rect) == 0
    return rect
  else
    rect.pointer.free
    return nil
  end
end

#bounds!Object



72
73
74
75
76
# File 'lib/sdl2/display.rb', line 72

def bounds!
  rect = bounds()
  SDL2.raise_error_if rect.nil?
  return rect
end

#closest_display_mode(wanted) ⇒ Object

Retrieve a display mode closest to a requested ideal. May return nil



49
50
51
52
# File 'lib/sdl2/display.rb', line 49

def closest_display_mode(wanted)
  closest = SDL2::Display::Mode.new # Make a new structure.
  return SDL2.get_closest_display_mode(@id, wanted, closest)
end

#current_display_modeObject

Get the current display mode



55
56
57
58
59
# File 'lib/sdl2/display.rb', line 55

def current_display_mode
  display_mode = SDL2::Display::Mode.new
  SDL2.get_current_display_mode!(@id, display_mode)
  display_mode
end

#modesObject

Every display has many modes



19
20
21
# File 'lib/sdl2/display.rb', line 19

def modes
  @modes ||= Modes.new(self)
end