Class: Hemi::Render::Window

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/hemi/render/window.rb

Constant Summary collapse

DEFAULT_WINDOW_WIDTH =
640
DEFAULT_WINDOW_HEIGHT =
480

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(width = DEFAULT_WINDOW_WIDTH, height = DEFAULT_WINDOW_HEIGHT) ⇒ Window

Returns a new instance of Window.



8
9
10
# File 'lib/hemi/render/window.rb', line 8

def initialize(width = DEFAULT_WINDOW_WIDTH, height = DEFAULT_WINDOW_HEIGHT)
  @size = Size.new(width: width, height: height)
end

Instance Attribute Details

#sizeObject (readonly)

Returns the value of attribute size.



12
13
14
# File 'lib/hemi/render/window.rb', line 12

def size
  @size
end

Class Method Details

.rendererObject



33
34
35
# File 'lib/hemi/render/window.rb', line 33

def self.renderer
  instance.renderer
end

.wipe_screenObject



28
29
30
31
# File 'lib/hemi/render/window.rb', line 28

def self.wipe_screen
  instance.renderer.draw_color = [0, 0, 0]
  instance.renderer.fill_rect(SDL2::Rect.new(0, 0, *instance.size))
end

Instance Method Details

#rendererObject



14
15
16
# File 'lib/hemi/render/window.rb', line 14

def renderer
  @renderer ||= sdl_window.create_renderer(-1, 0)
end

#sdl_windowObject



18
19
20
21
22
23
24
25
26
# File 'lib/hemi/render/window.rb', line 18

def sdl_window
  @sdl_window ||= SDL2::Window.create(
    "Hemi",
    SDL2::Window::POS_CENTERED,
    SDL2::Window::POS_CENTERED,
    *size,
    0
  )
end