Skip to content

Instantly share code, notes, and snippets.

@garaemon
Created May 8, 2011 13:57
Show Gist options
  • Save garaemon/961389 to your computer and use it in GitHub Desktop.
Save garaemon/961389 to your computer and use it in GitHub Desktop.
cairo and gtk on ruby
# -*- coding: utf-8 -*-
require 'cairo'
require 'gtk2'
format = Cairo::FORMAT_ARGB32
width = 300
height = 200
radius = height / 3
window = Gtk::Window.new('Graph')
window.set_default_size(width, height)
window.signal_connect('destroy') do
Gtk.main_quit
end
area = Gtk::DrawingArea.new
area.signal_connect('expose_event') do
context = area.window.create_cairo_context
# background
context.set_source_rgb(1, 1, 1) # white
context.rectangle(0, 0, width, height)
context.fill
context.set_source_rgb(1, 0, 0) # red
context.arc(width / 2, height / 2, radius, 0, 2 * Math::PI)
context.fill
# text string
context.set_source_rgb(0, 0, 0)
context.set_font_size( 12 )
context.move_to(0,100)
str = "文字コードの自動判別 -- Text String"
context.show_text( str )
end
window.add(area)
window.show_all
Gtk.main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment