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

Testing RoR helper functions

I was looking around for a way to test your helper functions in Ruby on Rails and stumbled over a plugin called helper_test that helps you set it up.

You can find it at nubyonrails.com.

Follow the instructions on the web site in order to install the plugin and generate your test files.

« Previous Page

Close
E-mail It