Hi,
I’m having difficulties drawing a rectangle in a drawingarea (in a
table). New to ruby-gnome, i’m trying some stuff out. This is what i
tried (rectangle should be in the big blue area):
require ‘gtk2’
window = Gtk::Window.new
window.border_width = 10
window.set_default_size(1200,800)
window.set_window_position(1)
window.title = “xxxx”
window.signal_connect(‘delete_event’) { false }
window.signal_connect(‘destroy’) { Gtk.main_quit }
table = Gtk::Table.new(15, 15, true)
window.add(table)
label = Gtk::Label.new(“Hello world”)
color = Gdk::Color.parse("#003366")
color2 = Gdk::Color.parse("#8295A8")
label.modify_fg(Gtk::STATE_NORMAL, color)
eb = Gtk::EventBox.new()
eb.add(label)
eb.modify_bg(Gtk::STATE_NORMAL, color2)
button = Gtk::Button.new(‘click!’)
table.attach_defaults(button, 10, 11, 1, 2)
table.attach_defaults(eb, 0, 8, 0, 1)
button.signal_connect(‘clicked’) do
label.text = “changed”
end
eb2 = Gtk::EventBox.new()
eb2.modify_bg(Gtk::STATE_NORMAL, color2)
table.attach_defaults(eb2, 0, 12, 2, 15)
button1 = Gtk::Button.new(“Pixel by pixel …”)
button2 = Gtk::Button.new(“you choose my fate”)
slabel1 = Gtk::Label.new(“test”)
fixed = Gtk::Fixed.new
#fixed.put(button1, 0, 0)
#fixed.put(button2, 20, 30)
fixed.put(slabel1, 100, 150)
eb2.add(fixed)
area = Gtk::DrawingArea.new
area.set_size_request(50,50)
area.signal_connect(“expose_event”) do
alloc = area.allocation
area.window.draw_rectangle(area.style.fg_gc(area.state), true,
100, 0, 100, 100)
end
table.attach_defaults(area, 0, 12, 2, 15)
window.show_all
Gtk.main