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

Returns a new instance of Display.



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

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

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

Class Method Details

.[](display_id) ⇒ Object



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

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

.countObject



30
31
32
# File 'lib/sdl2/display.rb', line 30

def self.count
  SDL2.get_num_video_displays()
end

.count!Object



34
35
36
37
38
# File 'lib/sdl2/display.rb', line 34

def self.count!
  total = count
  SDL2.raise_error_if total < 0
  return total
end

.firstObject



40
41
42
# File 'lib/sdl2/display.rb', line 40

def self.first
  self[0]
end

Instance Method Details

#boundsObject



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

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



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

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

#closest_display_mode(wanted) ⇒ Object



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

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

#closest_display_mode!(wanted) ⇒ Object



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

def closest_display_mode!(wanted)
  found = closest_display_mode(wanted)
  SDL2.raise_error_if(found.nil?)
  return found
end

#modesObject



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

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