Class: PandaCanvas::DrawingAgent

Inherits:
Object
  • Object
show all
Defined in:
lib/panda_canvas/drawing_agent.rb

Overview

DrawingAgent is used to capture drawing method calls and pass them to the active window and a TextPlay image in the correct order.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(window, image) ⇒ DrawingAgent

Initializes the clean object in a given window for method call capturing. TexPlay image is used for TexPlay drawing methods.



17
18
19
20
21
# File 'lib/panda_canvas/drawing_agent.rb', line 17

def initialize(window, image)
  @canvas_calls = []
  @window = window
  @image = image
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args) ⇒ Object

Capures and stores all missing method calls in the instance.



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

def method_missing(sym, *args)
  if DrawingMethods::CANVAS_CALLS.include? sym
    @canvas_calls << [sym, *args]
  elsif Gosu::Image.public_instance_methods.include? sym
    @image.send sym, *args
  elsif @window.respond_to? sym
    @window.send sym, *args
  else
    super
  end
end

Instance Attribute Details

#canvas_callsObject

Array of methods that need to be passed to canvas.



9
10
11
# File 'lib/panda_canvas/drawing_agent.rb', line 9

def canvas_calls
  @canvas_calls
end

#frameObject

Current frame number.



12
13
14
# File 'lib/panda_canvas/drawing_agent.rb', line 12

def frame
  @frame
end