|
From: cix <mc...@gm...> - 2002-01-24 22:29:15
|
Hi,
I am using fltk/ruby for two o three weeks now, but I still have some
problems.
I wrote a small example which reproduce the condition I don't understand.
I have a Group (Container) containing a Widget (Contained).
It should be a square containing a label/button.
The Group handle "hides" the Widget' one, so that I never reach
Contained::handle(e) if not removing Container::handle(e).
I don't know how to solve the problem. Did I miss somehing?
If you have time, there is a minor problem explained in the comment of the
initializer of "Contained".
Thanks!
cix
#========================
# contained.rb
#========================
require 'fltk'
class Contained < Fltk::Widget
include Fltk::Drawable
#-------------------
def initialize(parent, name, pos_x, pos_y)
@name = name
# I would like to create this box larger than the name
# but Fltk.width(name) gives me a core dump. What can I do?
@w = name.length*7+8 # Temporary trick
@h = 20
@x = pos_x
@y = pos_y
super(@x - @w/2, @y - @h/2, @w, @h,'')
@parent = parent
@enter = false
end
#-------------------
def mX
x + @w/2
end
def mY
y + @h/2
end
#-------------------
def draw
super()
color(Fltk::BLACK)
rectf(0,0,@w,@h)
end
#-------------------
def handle(e)
puts 'in Contained::handle'
super(e)
case e
when Fltk::ENTER
@parent.active_child(self)
@enter = true
#@parent.redraw
redraw
return true
when Fltk::LEAVE
@parent.active_child(self)
@enter = false
#@parent.redraw
redraw
return true
else
return false
end
end
end
#========================
# container.rb
#========================
require 'fltk'
require 'contained'
class Container < Fltk::Group
include Fltk::Drawable
#-------------------
def initialize(label)
super(400,400,label)
add(Thought.new(self, 'contained',200,200))
group_end
@cur = nil
end
#-------------------
def handle(e)
if( Fltk.event_button != 1 )
return false
end
case e
when Fltk::PUSH
puts 'Fltk::PUSH'
return true
when Fltk::DRAG
puts 'Fltk::DRAG'
if( @cur )
@cur.position(Fltk.event_x, Fltk.event_y)
end
redraw
return true
end
return false
end
#-------------------
def active_child(obj)
print "mark_item(#{obj.inspect})\n"
@cur = obj
end
end
#=======================
class MyWindow < Fltk::Window
def initialize(label)
super(400,400,label)
@canvas = Container.new("#{label} exp")
end
end
w = MyWindow.new("gMind")
w.show
FLTK::font(FLTK::HELVETICA,14)
Fltk.run
|