[Newbies] Why mouseDown only called for the first morph?
peace_the_dreamer at yahoo.com
Wed Oct 20 06:05:45 UTC 2010
--- On Tue, 10/19/10, Clemens Eisserer <linuxhippy at gmail.com> wrote:
> From: Clemens Eisserer <linuxhippy at gmail.com>
> Subject: [Newbies] Why mouseDown only called for the first morph?
> To: beginners at lists.squeakfoundation.org
> Date: Tuesday, October 19, 2010, 10:04 AM
> I am new to Squeak and I try to write a tic-tac-toe like
> I have a BorderedMorpth as board to which I add some
> EllipseMorphs as childs:
> > for: 1 to : ...... [
> > child := OwnEllipseMoph new.
> > bordered addMoprh: child.
> > child bounds: xPos at yPos corner:
> (xPos+fieldSize-5)@(yPos+fieldSize-5). ]
> The result looks like the following image: http://188.8.131.52/morph.png
> All the EllipseMorphs are identical and change their color
> at mouseDown:
> > handlesMouseDown: evt
> > ^ true
> > mouseDown: evt
> > self color: Color green.
> > ^true
> The problem is that I only receive mouseDown on the first
> EllipseMorph I add.
> When I click on the other EllipseMorphs nothing happens.
> Any idea what the problem could be? Could it be the
> confuses Morph's event handling?
Morphs have several ways of handling events. The way you picked I had problems with. Sending an myMorph on: #mousedown send: #message seems to work best for me.
If you want to debug what you are doing bringing up an inspector on a morph or exploring the parent morph might prove useful. #haltOnce might prove helpful too.
Offhand I would guess that the first one works because its topLeft corresponds to the top left of the parent morph and the other ones don't.
Events are dispatched by translating them in to local coordinates for some value of local. When something doesn't work most programmers try a different way rather than track down the problem. Event debugging is both difficult and patches are of course prone to break things elsewhere. There is some very brittle code here.
For examples of things that work look at how polygons get their handles to handle events.
Yours in curiosity and service, --Jerome Peace
More information about the Beginners