Class: RbSDL2::Display

Inherits:
Object
  • Object
show all
Includes:
DisplayOrientation
Defined in:
lib/rb_sdl2/display.rb

Defined Under Namespace

Modules: DisplayOrientation

Class Method Summary collapse

Instance Method Summary collapse

Methods included from DisplayOrientation

#flipped_landscape?, #flipped_portrait?, #landscape?, #portrait?

Constructor Details

#initialize(num) ⇒ Display

Returns a new instance of Display.



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

def initialize(num)
  @num = num
end

Class Method Details

.displaysObject

Raises:



4
5
6
7
8
# File 'lib/rb_sdl2/display.rb', line 4

def displays
  count = ::SDL.GetNumVideoDisplays
  raise RbSDL2Error if count < 0
  count.times.map { |num| Display.new(num) }
end

Instance Method Details

#boundsObject

Raises:



15
16
17
18
19
20
# File 'lib/rb_sdl2/display.rb', line 15

def bounds
  rect = Rect.new
  err = ::SDL.GetDisplayBounds(index, rect)
  raise RbSDL2Error if err < 0
  rect.to_a
end

#closest_display_mode(**display_mode) ⇒ Object

Raises:



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/rb_sdl2/display.rb', line 24

def closest_display_mode(**display_mode)
  mode ||= DisplayMode.new(**display_mode)
  closest = DisplayMode.new
  err = ::SDL.GetClosestDisplayMode(self, mode, closest)
  raise RbSDL2Error if err.null?
  closest
  # 利用可能なディスプレイモードが検索され, 要求と最も近いモードがclosestに代入される.
  # modeのformatとrefresh_rateが0の場合, デスクトップのモードとなる.
  # モードは, サイズを最優先で検索し, ピクセル形式は次の優先度となる.
  # そして最後に更新周期をチェックする. 利用可能なモードが要求に対して小さすぎる場合, NULLを戻す.
end

#current_display_modeObject

Raises:



36
37
38
39
40
41
# File 'lib/rb_sdl2/display.rb', line 36

def current_display_mode
  obj = DisplayMode.new
  err = ::SDL.GetCurrentDisplayMode(index, obj)
  raise RbSDL2Error if err < 0
  obj
end

#desktop_display_modeObject

Raises:



43
44
45
46
47
48
# File 'lib/rb_sdl2/display.rb', line 43

def desktop_display_mode
  obj = DisplayMode.new
  err = ::SDL.GetDesktopDisplayMode(index, obj)
  raise RbSDL2Error if err < 0
  obj
end

#display_modesObject

Raises:



50
51
52
53
54
55
56
57
58
59
# File 'lib/rb_sdl2/display.rb', line 50

def display_modes
  num = ::SDL.GetNumDisplayModes(index)
  raise RbSDL2Error if num < 0
  num.times.map do |mode_index|
    obj = DisplayMode.new
    err = ::SDL.GetDisplayMode(index, mode_index, obj)
    raise RbSDL2Error if err < 0
    obj
  end
end

#dpiObject

ディスプレイピクセルの斜め、水平、垂直方向の DPI を配列で戻す。

Raises:



62
63
64
65
66
67
# File 'lib/rb_sdl2/display.rb', line 62

def dpi
  d_h_v_dpi = Array.new(3) { ::FFI::MemoryPointer.new(:float) }
  err = ::SDL.GetDisplayDPI(index, *d_h_v_dpi)
  raise RbSDL2Error if err < 0
  d_h_v_dpi.map { |v| v.read_float }
end

#indexObject Also known as: to_int



69
# File 'lib/rb_sdl2/display.rb', line 69

def index = @num

#inspectObject



72
73
74
# File 'lib/rb_sdl2/display.rb', line 72

def inspect
  "#<#{self.class.name} name=#{name.inspect} bounds=#{bounds} dpi=#{dpi}>"
end

#nameObject Also known as: to_s

Raises:



76
77
78
79
80
# File 'lib/rb_sdl2/display.rb', line 76

def name
  ptr = ::SDL.GetDisplayName(index)
  raise RbSDL2Error if ptr.null?
  SDL.ptr_to_str(ptr)
end

#orientationObject



83
# File 'lib/rb_sdl2/display.rb', line 83

def orientation = ::SDL.GetDisplayOrientation(index)

#usable_boundsObject

Raises:



96
97
98
99
100
101
# File 'lib/rb_sdl2/display.rb', line 96

def usable_bounds
  rect = Rect.new
  err = ::SDL.GetDisplayUsableBounds(index, rect)
  raise RbSDL2Error if err < 0
  rect.to_a
end