Class: BadSdl::Engine::Engines

Inherits:
BadSdl::Engine show all
Defined in:
lib/bad_sdl/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 BadSdl::Engine

#surface

Instance Method Summary collapse

Methods inherited from BadSdl::Engine

#on, #on_handlers, #painter

Constructor Details

#initialize(opts) ⇒ Engines

Returns a new instance of Engines.



10
11
12
13
14
# File 'lib/bad_sdl/engine/engines.rb', line 10

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

Instance Attribute Details

#enginesObject (readonly)

Returns the value of attribute engines.



16
17
18
# File 'lib/bad_sdl/engine/engines.rb', line 16

def engines
  @engines
end

Instance Method Details

#current_engineObject



18
19
20
# File 'lib/bad_sdl/engine/engines.rb', line 18

def current_engine
  @engines[@current_idx]
end

#handle_event(event) ⇒ Object



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

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

#paint_to(surface) ⇒ Object



32
33
34
35
36
37
38
39
40
41
# File 'lib/bad_sdl/engine/engines.rb', line 32

def paint_to(surface)      
  result = false
              
  result = true if super(surface)
  
  if ce = current_engine
    result = true if ce.paint_to(surface)
  end
  return result
end

#quitObject



43
44
45
46
# File 'lib/bad_sdl/engine/engines.rb', line 43

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