Class: BadSdl::Engine

Inherits:
Object
  • Object
show all
Defined in:
lib/bad_sdl/engine.rb,
lib/bad_sdl/engine/engines.rb,
lib/bad_sdl/engine/block_engine.rb

Overview

Input/Output engine.

Direct Known Subclasses

BlockEngine, Engines

Defined Under Namespace

Classes: BlockEngine, Engines

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Engine

Returns a new instance of Engine.



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

def initialize(opts = {})

  # TODO: ??
end

Instance Attribute Details

#surfaceObject (readonly)

Returns the value of attribute surface.



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

def surface
  @surface
end

Instance Method Details

#handle_event(event) ⇒ Object



34
35
36
37
38
39
40
41
42
43
# File 'lib/bad_sdl/engine.rb', line 34

def handle_event(event)

  on_handlers.each_pair do |event_hash, handler|

    return true if handler.call(event) if event == event_hash

  end
  
  return false # if we get to here.
end

#on(*args, &block) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/bad_sdl/engine.rb', line 25

def on(*args, &block)
  raise "Must specify EVENTTYPEs to handle" if args.empty?
  raise "Must give block to call on event" if args.empty? unless block.nil?
  args.each do |event_hash|
    raise "Expected Hash: #{event_hash.inspect}" unless event_hash.kind_of? Hash
    on_handlers[event_hash] = block
  end
end

#on_handlersObject



21
22
23
# File 'lib/bad_sdl/engine.rb', line 21

def on_handlers
  @on_handlers ||= {}
end

#paint_to(surface) ⇒ Object

This routine should be overridden.



46
47
48
49
50
51
52
53
54
55
# File 'lib/bad_sdl/engine.rb', line 46

def paint_to(surface)
  result = false
        
  painter.each do |one|
    
    result = true if one.call(surface)
  end
  
  return result
end

#painter(&block) ⇒ Object



57
58
59
60
61
62
63
# File 'lib/bad_sdl/engine.rb', line 57

def painter(&block)
  @painter ||= []
  @painter << block unless block.nil?      
  
  @painter
  
end

#quitObject



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

def quit()

end