Class: SDL2::Engine::Engines

Inherits:
SDL2::Engine show all
Defined in:
lib/sdl2/engine/engines.rb

Overview

An engine multiplexor. Only has one focus, but that focus can change.

Direct Known Subclasses

Application

Instance Attribute Summary collapse

Attributes inherited from SDL2::Engine

#surface

Instance Method Summary collapse

Methods inherited from SDL2::Engine

#on, #on_handlers

Constructor Details

#initialize(opts) ⇒ Engines

Returns a new instance of Engines.



9
10
11
12
13
# File 'lib/sdl2/engine/engines.rb', line 9

def initialize(opts)
  super(opts)
  @engines = [] #opts[:engines] || []
  @current_idx = 0
end

Instance Attribute Details

#enginesObject (readonly)

Returns the value of attribute engines.



15
16
17
# File 'lib/sdl2/engine/engines.rb', line 15

def engines
  @engines
end

Instance Method Details

#current_engineObject



17
18
19
# File 'lib/sdl2/engine/engines.rb', line 17

def current_engine
  @engines[@current_idx]
end

#handle_event(event) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/sdl2/engine/engines.rb', line 21

def handle_event(event)
  return true if super(event) # self swallowed event.
  if current_engine
    puts "Passing to current engine."if SDL2::PrintDebug
    return true if current_engine.handle_event(event)
  end
  puts "Unable to handle"if SDL2::PrintDebug
  return false # if we get to here.
end

#paint_to(surface) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/sdl2/engine/engines.rb', line 31

def paint_to(surface)
  if ce = current_engine
    return ce.paint_to(surface)
  else
    return false
  end
end

#quitObject



39
40
41
42
# File 'lib/sdl2/engine/engines.rb', line 39

def quit()
  @engines.each(&:quit)
  super()
end