Drawing with Cairo in Ruby-Gtk2
With my rekindled love for Ruby I started hang around in #ruby-lang again and got the question how you use Cairo to draw inside a Ruby-Gtk2 program. I cooked up a small example and figured that sharing it here might be useful for others as well.
Otherwise you can just enjoy the cleanness of Ruby
#!/usr/bin/env ruby
require 'gtk2'
window = Gtk::Window.new
window.signal_connect("delete-event") do
Gtk.main_quit
true
end
area = Gtk::DrawingArea.new
area.set_size_request(100,100)
area.signal_connect("expose-event") do
cairo = area.window.create_cairo_context
cairo.rectangle(10, 10, 50, 50)
cairo.fill
true
end
window.add(area)
window.show_all
Gtk.main