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.



207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
# File 'lib/gtk2html.rb', line 207

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.set_default_size(@width, @height)
  
  @dirty = true
  
  
  area.signal_connect("expose_event") do      
    
    if @dirty then

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

      @instructions = Gtk2HTML::Render.new(@doc, @width, @height).to_a
    end

    drawing = DrawingInstructions.new area
    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
  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.



204
205
206
# File 'lib/gtk2html.rb', line 204

def doc
  @doc
end

#heightObject (readonly)

Returns the value of attribute height.



205
206
207
# File 'lib/gtk2html.rb', line 205

def height
  @height
end

#htmlObject

Returns the value of attribute html.



204
205
206
# File 'lib/gtk2html.rb', line 204

def html
  @html
end

#widthObject (readonly)

Returns the value of attribute width.



205
206
207
# File 'lib/gtk2html.rb', line 205

def width
  @width
end

Instance Method Details

#onmousemove(x, y) ⇒ Object



267
268
269
# File 'lib/gtk2html.rb', line 267

def onmousemove(x,y)
  
end

#refreshObject



271
272
273
274
# File 'lib/gtk2html.rb', line 271

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