Another stupid Morphic Question
Andreas Raab
andreas.raab at gmx.de
Tue May 1 08:07:09 UTC 2007
Andrew P. Black wrote:
> The key phrase was: "If handlesMouseDown: answers false, that means that
> your object
> doesn't handle mouse down events, _so somebody else has to decide how
> to handle them_". So by setting handlesMouseDown to false, I was making
> the morph react to mouse down, which is a bit counter-intuitive. The
> way to make it _not_ respond to mouse down is to have handlesMouseDown:
> answer true, but to have a mouseDown: evt method that does nothing.
That is correct. It's a bit counter-intuitive because it's the world
which implements the default behavior of dragging objects. In other
words the action is contextual (objects in the world can be dragged) not
builtin.
> OK, so the converse is true. if I want my circles to handle Mouse Down,
> then they need to answer true to handlesMouseDown: (that's easy), and
> then there needs to be a mouseDown: evt method that does the "right
> thing". However, the right thing is very complicated! I tried the
> following, based on Tom's code:
This code seems both overly complicated as well as at least somewhat
buggy (grabMorph:from: should only be used for owner-less morphs). Try
the following instead:
rect := RectangleMorph new.
rect extent: 100 at 100.
circle := EllipseMorph new.
circle extent: 100 at 100.
rect addMorphCentered: circle.
rect on: #mouseDown send: #value to:["ignore drags"].
circle on: #mouseDown send: #value
to:[circle world primaryHand grabMorph: circle].
rect openInWorld.
> I could probably find all of the bits of code that I need, to handle
> mouse move and so on, taking care of the offset between mouse click
> event and the origin of the Morph that I'm moving — most of the code
> must be in HaloMorph. But this was the Default Behavior of the circle
> before I embedded it in the rectangle — surely there must be an easier
> way to get that default behavior back, other than duplicating the code
> from whereever it is hidden!
Well, by far the easiest way is to use a PasteUpMorph instead of a
RectangleMorph - PasteUps have this behavior builtin.
Cheers,
- Andreas
More information about the Squeak-dev
mailing list
|