Am Sonntag, den 28.01.2007, 15:55 +0200 schrieb Dobai-Pataky Bálint:
Hi,
cause it seems to be a bigger problem i changed your code a little
bit.
I don’t want to sound harsh but i think, that you don’t understand the
Gdk concepts very well. I suggest to read the Xlib manuals from
O’Reilly. Gdk is very close to the Xlib and so these are the best docs
you can get.
Cheers
detlef
#!/usr/bin/ruby
require ‘gtk2’
class Lay < Gtk::Layout
class LayLabel < Gtk::EventBox
def initialize(text)
@x=0
@y=0
@text=text
@dragging=false
@myobject=Gtk::Label.new(@text)
super()
add(@myobject)
signal_connect(‘event’){|me,event|
if @xorgc.nil? and self.realized?
@xorgc = Gdk::GC.new parent.bin_window
@xorgc.function = Gdk::GC::INVERT
end
case event.event_type
when Gdk::Event::BUTTON_PRESS
@xshift=event.x
@yshift=event.y
@dragging=true
@w,@[email protected]_requisition
parent.bin_window.draw_rectangle(@xorgc,false,@x-1,@y-1,@w+1,@h+1)
@lastx=@xshift
@lasty=@yshift
when Gdk::Event::MOTION_NOTIFY
parent.bin_window.draw_rectangle(@xorgc,false,@x+@lastx-@xshift-1,@y
+@lasty-@yshift-1,@w+1,@h+1)
parent.bin_window.draw_rectangle(@xorgc,false,@x
+event.x-@xshift-1,@y+event.y-@yshift-1,@w+1,@h+1)
@lastx=event.x
@lasty=event.y
when Gdk::Event::BUTTON_RELEASE
@dragging=false
parent.bin_window.draw_rectangle(@xorgc,false,@x+@lastx-@xshift-1,@y
+@lasty-@yshift-1,@w+1,@h+1)
@x=event.x+@x-@xshift
@y=event.y+@y-@yshift
parent.move(self)
end
}
end
attr_accessor :x
attr_accessor :y
attr_accessor :text
end
def initialize
super
@mygc=nil
@clearmygc=nil
w,h=size
end
def put(gtk_type,x,y)
case gtk_type
when “text”
l=LayLabel.new(“test text”)
l.x=x
l.y=y
end
super(l,x,y)
end
def move(ch,x=ch.x,y=ch.y)
ch.x=x
ch.y=y
super
end
end
lay=Lay.new
lay.put(“text”,100,100)
lay.put(“text”,200,200)
lay.put(“text”,300,300)
@w = Gtk::Window.new
@w.signal_connect(‘destroy’){Gtk.main_quit}
@w.set_default_size(500, 500)
@w.add(lay)
@w.show_all
Gtk.main
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