class Gtk2HTML::DrawingInstructions

Attributes

layout[RW]
widgets[R]

Public Class Methods

new(layout=nil) click to toggle source
# File lib/gtk2html.rb, line 272
def initialize(layout=nil)

  @layout = layout if layout
  @widgets = []

end

Public Instance Methods

draw_box(margin, coords, padding, style) click to toggle source
# File lib/gtk2html.rb, line 279
def draw_box(margin, coords, padding, style)

  h2 = style.clone
  h2.delete :color

  x1, y1, x2, y2 = coords

  width = x2 - x1
  height = y2 - y1

  gc = gc_ini(h2)
  @layout.bin_window.draw_rectangle(gc, 1, x1, y1, width, height)
end
draw_layout(text, coords, style) click to toggle source
# File lib/gtk2html.rb, line 294
def draw_layout(text, coords, style)

  x, y = coords

  text ||= ''
  h2 = style.clone
  h2.delete :'background-color'      
  
  layout = Pango::Layout.new(Gdk::Pango.context)
  layout.font_description = Pango::FontDescription.\
                                         new('Sans ' + style[:'font-size'])
  layout.text = text
        
  gc = gc_ini(h2)
  @layout.bin_window.draw_layout(gc, x, y, layout)
end
render(a) click to toggle source
# File lib/gtk2html.rb, line 314
def render(a)      
  draw a
end
script(args) click to toggle source
# File lib/gtk2html.rb, line 318
def script(args)

end
window(args) click to toggle source
# File lib/gtk2html.rb, line 311
def window(args)
end

Private Instance Methods

draw(a) click to toggle source
# File lib/gtk2html.rb, line 325
def draw(a)

  return unless a
  
  if a.first.is_a? Symbol then
    
    name, margin, coords, padding, style, _, *children = a                  
     
    method(name).call(margin, coords, padding, style) if name =~ /^draw_/
    
    draw children
    
  elsif a.first.is_a? String and not a.first.empty?

    coords, style = a[1..-1]#remaining
    method(:draw_layout).call(a.first, coords, style)
    
  else
  
    a.each do |row|

      next unless row

      x = row

      case row[0].class.to_s.to_sym

      when :Symbol
        
        name, margin, coords, padding, style, _, *children = x
                
        method(name).call(margin, coords, padding, style) if name =~ /^draw_/
        draw children
        
      when :'Rexle::Element::Value' then

        next if x.empty?

        coords, style = row[1..-1]#remaining
        
        method(:draw_layout).call(*row)

      when :Array
        
        draw row
        
      else    
        
        name, *args = x

        method(name).call(args) if name =~ /^draw_/
        draw row[-1]
      end

    end
  end
    
end
gc_ini(style) click to toggle source
# File lib/gtk2html.rb, line 403
def gc_ini(style)
  
  gc = Gdk::GC.new(@layout.bin_window)

  color, bgcolor = style[:color], style[:'background-color']

  gc.set_foreground(set_colour(color)) if color
  gc.set_foreground(set_colour(bgcolor)) if bgcolor
  
  gc
end
set_colour(c) click to toggle source
# File lib/gtk2html.rb, line 384
def set_colour(c)

  colour = case c
  when /^rgb/
    regex = /rgb\((\d{1,3}), *(\d{1,3}), *(\d{1,3})\)$/
    r, g, b = c.match(regex).captures.map {|x| x.to_i * 257}
    colour = Gdk::Color.new(r, g, b)
  when /^#/
      Gdk::Color.parse(c)
  else
      Gdk::Color.parse(c)
  end
  
  colormap = Gdk::Colormap.system
  colormap.alloc_color(colour,   false, true)

  colour
end