Ruby + cairo problem

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

Hi,

In [email protected]
“[ruby-gnome2-devel-en] ruby + cairo problem” on Sat, 24 Mar 2007
19:39:40 +0100,
“Gergely K.” [email protected] wrote:

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?

GtkAllocation’s description may help you:

A GtkAllocation of a widget represents region which has
been allocated to the widget by its parent. It is a
subregion of its parents allocation. See the section
called "Size Allocation" for more information.

gint x; the X position of the widget's area relative to
        its parents allocation.
gint y; the Y position of the widget's area relative to
        its parents allocation.
gint width; the width of the widget's allocated area.
gint height; the height of the widget's allocated area.

from
http://developer.gnome.org/doc/API/2.4/gtk/GtkWidget.html#GtkAllocation

x and y are relative to their parents allocation.

Thanks,

kou


Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net’s Techsay panel and you’ll get the chance to share
your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV