Hi!
I’ve a problem with cairo. When I have a DrawingArea in a VBox, and
don’t know what’s wrong with the code (see the attached image: it
seems that allocation has incorrect values).
Does anybody know what could be the problem?
thanks
Gergo
require ‘gtk2’
class Diagram < Gtk::DrawingArea
def initialize
super
set_size_request 200, 200
signal_connect("expose_event") {|w,e|
cr = self.window().create_cairo_context
cr.rectangle e.area.x, e.area.y, e.area.width, e.area.height
cr.clip
draw cr
false
}
end
def draw cr
xcenter = allocation.x + allocation.width / 2
ycenter = allocation.y + allocation.height / 2
puts “origin: (#{allocation.x}, #{allocation.y})
size:(#{allocation.width}, #{allocation.height})”
cr.circle xcenter, ycenter, [allocation.width / 2,
allocation.height / 2].min
cr.stroke
cr.move_to allocation.x, allocation.y
cr.line_to allocation.x+allocation.width,
allocation.y+allocation.height
cr.move_to allocation.x+allocation.width, allocation.y
cr.line_to allocation.x, allocation.y+allocation.height
cr.stroke
end
end
class App < Gtk::Window
def initialize
super
self.title = “Cairo”
signal_connect(“delete_event”){quit}
signal_connect(“destroy”){quit}
add(hbox = Gtk::VBox.new)
hbox.pack_start Gtk::Label.new(‘cairo’), false, false
hbox.pack_start Gtk::Label.new(‘cairo’), false, false
hbox.pack_start Diagram.new, true, true
hbox.pack_start Gtk::Label.new(‘cairo’), false, false
hbox.pack_start Gtk::Label.new(‘cairo’), false, false
hbox.pack_start Gtk::Label.new(‘cairo’), false, false
hbox.pack_start Gtk::Label.new(‘cairo’), false, false
show_all
end
def quit
Gtk.main_quit
end
end
App.new
Gtk.main