class Gtk2SVG::Main

Attributes

doc[RW]
height[R]
svg[RW]
width[R]

Public Class Methods

new(svg, irb: false, title: 'window', debug: @debug) click to toggle source
# File lib/gtk2svg.rb, line 296
def initialize(svg, irb: false, title: 'window', debug: @debug)
  
  @svg, @debug = svg, debug
  @doc = Svgle.new(svg, callback: self, debug: debug)

  @area = area = Gtk::DrawingArea.new
  
  doc = @doc
  
  def @doc.element_by_id(id)
    self.root.element("//*[@id='#{id}']")
  end            
  

  

  client_code = []
  
  puts ('title: ' + title.inspect).debug if @debug
  window = Gtk::Window.new title
  @width, @height = %i(width height).map{|x| @doc.root.attributes[x].to_i }
  
  if @width and @height then
    window.set_default_size(@width, @height)
  end
  
  @dirty = true
  
  @doc.root.xpath('//script').each {|x| eval x.text.unescape }
  
  area.signal_connect("expose_event") do      

    if @dirty then
      
      Thread.new { @doc.root.xpath('//script').each {|x| eval x.text.unescape } }

      @instructions = Gtk2SVG::Render.new(@doc, debug: debug).to_a
    end
    
    drawing = DrawingInstructions.new area, debug: debug
    drawing.render @instructions
    @dirty = false
    
  end
  
  area.add_events(Gdk::Event::POINTER_MOTION_MASK) 

  area.signal_connect('motion_notify_event') do |item,  event|

    @doc.root.xpath('//*[@onmousemove]').each do |x|
                
      eval x.onmousemove() if x.hotspot? event.x, event.y
      
    end
  end

  area.add_events(Gdk::Event::BUTTON_PRESS_MASK) 

  area.signal_connect "button_press_event" do |item,event| 

    @doc.root.xpath('//*[@onmousedown]').each do |x|
                
      eval x.onmousedown() if x.hotspot? event.x, event.y
      
    end        
  end      
  
  window.add(area).show_all


  @doc.root.xpath('//*[@onload]').each do |x|
              
    eval x.onload()
    
  end
  
  #Thread.new do
  #  3.times { x1 -= 1; @area.queue_draw; sleep 0.1}
  #end

  window.show_all.signal_connect("destroy"){Gtk.main_quit}

  irb ? Thread.new {Gtk.main  } : Gtk.main
end

Public Instance Methods

onmousemove(x,y) click to toggle source
# File lib/gtk2svg.rb, line 381
def onmousemove(x,y)
  
end
refresh() click to toggle source
# File lib/gtk2svg.rb, line 385
def refresh()    
end
svg=(svg) click to toggle source
# File lib/gtk2svg.rb, line 388
def svg=(svg)
  @svg = svg
  @doc = Svgle.new(svg, callback: self)
end
timeout(duration, loopx=true) { || ... } click to toggle source
# File lib/gtk2svg.rb, line 393
def timeout(duration, loopx=true)
  
  GLib::Timeout.add(duration) do 
    yield
    @area.queue_draw
    loopx
  end

end