From: Dobai-Pataky B. <dp...@gm...> - 2009-01-29 08:43:55
|
require 'gtk2' w=Gtk::Window.new("attempt").set_size_request(300,600) w.signal_connect("destroy"){Gtk.main_quit} w.add(eb=Gtk::EventBox.new.add(im=Gtk::Image.new)) points=Array.new im.signal_connect('expose-event',points){|me,ev,pts| cr=me.window.create_cairo_context.set_line_cap(Cairo::LineCap::ROUND).set_line_width(10) pc=nil pts.each{|c| pc=c if pc.nil? cr.move_to(pc[0],pc[1]) cr.line_to(c[0],c[1]) pc=c } cr.stroke } eb.signal_connect("button-press-event",points,im){|me,ev,pts,im| pts.push([ev.x,ev.y]) im.queue_draw_area(0, 0, im.allocation.width, im.allocation.height) } w.show_all Gtk.main |