Forum: Ruby-Gnome 2 ruby + cairo problem

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
7988f36d0ee9050e8f1d646db55a9eb0?d=identicon&s=25 Gergely Kontra (Guest)
on 2007-03-24 19:40
(Received via mailing list)
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
Ee6ffca720cc428d70247dcd7377dd48?d=identicon&s=25 Kouhei Sutou (Guest)
on 2007-03-25 13:50
(Received via mailing list)
Hi,

In <e4246bc80703241139q197ba320i66550ad6228444d5@mail.gmail.com>
  "[ruby-gnome2-devel-en] ruby + cairo problem" on Sat, 24 Mar 2007
19:39:40 +0100,
  "Gergely Kontra" <pihentagy@gmail.com> 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/GtkWidg...

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...
This topic is locked and can not be replied to.