class R2dEngine::App

Attributes

doc[R]

Public Instance Methods

clear() click to toggle source
# File lib/r2dsvg/r2dsvg_module.rb, line 473
def clear()
  @window.clear
end
read(s, title=@title) click to toggle source
# File lib/r2dsvg/r2dsvg_module.rb, line 477
def read(s, title=@title)
  @loaded = false
  @window.clear
  svg, _ = RXFHelper.read(s)    
  doc = Svgle.new(svg, callback: self, debug: @debug)
  instructions = Render.new(doc, debug: @debug).to_a

  
  drawing = DrawingInstructions.new @window, debug: @debug
  puts ('instructions: ' + instructions.inspect).debug if @debug

  @width, @height = %i(width height).map{|x| doc.root.attributes[x].to_i }
  @window.set title: title, width: @width, height: @height        
  
  threads = []
  
  threads << Thread.new do
    doc.root.xpath('//script').each {|x| eval x.text.unescape }      
    drawing.render instructions    
  end
  
  threads.join

  @loaded = true
  @doc = doc
  
end
refresh() click to toggle source
# File lib/r2dsvg/r2dsvg_module.rb, line 505
def refresh()
  puts 'do nothing' if @debug
end

Private Instance Methods

keyboard(action, event) { |x| ... } click to toggle source
# File lib/r2dsvg/r2dsvg_module.rb, line 512
def keyboard(action, event)
  
  doc = @doc
  
  @doc.root.xpath("//*[@on#{action}]").each do |x|

    if block_given? then
      valid = yield(x)
      statement = x.method(('on' + action.to_s).to_sym).call()
      puts 'statement: ' + statement.inspect if @debug
      eval statement if valid
    else
      statement = x.method(('on' + action.to_s).to_sym).call()
      puts 'statement: ' + statement.inspect if @debug
      eval statement
    end
  
  end
  
  @doc.event[action].each {|name| method(name).call event }
      
end
mouse(action, event) { |x| ... } click to toggle source
# File lib/r2dsvg/r2dsvg_module.rb, line 535
def mouse(action, event)
  
  doc = @doc
  
  @doc.root.xpath("//*[@on#{action}]").each do |x|

    #puts 'x.class: ' + x.inspect if @debug
    if x.obj and x.obj.contains? event.x, event.y then
      
        
      if not x.active? then
        x.active = true
      elsif action == :mouseenter
        next
      end
                
      if block_given? then
        valid = yield(x)
        statement = x.method(('on' + action.to_s).to_sym).call()
        puts 'statement: ' + statement.inspect if @debug
        eval statement if valid
      else
        statement = x.method(('on' + action.to_s).to_sym).call()
        puts 'statement: ' + statement.inspect if @debug
        eval statement
      end
      
    else
      
      if x.active? then
        x.active = false
        onleave
      end
    end
  
  end
      
end
onleave() click to toggle source
# File lib/r2dsvg/r2dsvg_module.rb, line 574
def onleave()

  @doc.root.xpath("//*[@onmouseleave]").each do |x|
    puts 'onleave'.info if @debug
    eval x.method(:onmouseleave).call()
  end

end