Class: Gtk2HTML::Main

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(html, irb: false) ⇒ Main

Returns a new instance of Main.



362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
# File 'lib/gtk2html.rb', line 362

def initialize(html, irb: false)
  
  @html = html
  @doc = Htmle.new(html, callback: self)
  
  @area = area = Gtk::DrawingArea.new
  client_code = []
  
  window = Gtk::Window.new
  
  @width = 320
  @height = 240
  @window = window
  window.set_default_size(@width, @height)
  
  @dirty = true
  
  
  area.signal_connect("expose_event") do      
    
    width, height = window.size

    @dirty = true if [@width, @height] != [width, height]

    
    if @dirty then

      Thread.new { @doc.root.xpath('//script').each {|x| eval x.text.unescape } }
      
      @width, @height = window.size
      instructions = Gtk2HTML::Render.new(@doc, @width, @height).to_a

      @layout_instructions = Gtk2HTML::Layout.new(instructions).to_a

    end

    drawing = Gtk2HTML::DrawingInstructions.new area
    drawing.render @layout_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
  window.show_all.signal_connect("destroy"){Gtk.main_quit}

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

Instance Attribute Details

#docObject

Returns the value of attribute doc.



359
360
361
# File 'lib/gtk2html.rb', line 359

def doc
  @doc
end

#heightObject (readonly)

Returns the value of attribute height.



360
361
362
# File 'lib/gtk2html.rb', line 360

def height
  @height
end

#htmlObject

Returns the value of attribute html.



359
360
361
# File 'lib/gtk2html.rb', line 359

def html
  @html
end

#widthObject (readonly)

Returns the value of attribute width.



360
361
362
# File 'lib/gtk2html.rb', line 360

def width
  @width
end

#windowObject (readonly)

Returns the value of attribute window.



360
361
362
# File 'lib/gtk2html.rb', line 360

def window
  @window
end

Instance Method Details

#onmousemove(x, y) ⇒ Object



432
433
434
# File 'lib/gtk2html.rb', line 432

def onmousemove(x,y)
  
end

#refreshObject



436
437
438
439
# File 'lib/gtk2html.rb', line 436

def refresh()
  @dirty = true
  @area.queue_draw
end