[Q][ETOYS] Constrained dragging?

Ned Konz ned at bike-nomad.com
Wed Apr 28 05:47:59 UTC 2004


On Sunday 25 April 2004 12:33 am, Lothar Schenk wrote:
> How can I restrict the path of an eToy that's in the process of being
> dragged to an allowed region, or alternatively to avoid conflict with other
> eToys as obstacles?

First, you have to avoid having the morph dragged around by the hand, because 
it's much harder to control its position if the hand is dragging it.

Turn on "resist being picked up" from the menu.

Now if you make a script that is triggered on mouse down you could check the 
world's mouseX and mouseY.

You can also put a morph in a container and constrain its bounds that way (you 
can use obtrudes to test), or use overlaps to test whether it's above 
another.

The attached image is one way to do something like this:

the blue Rectangle is locked in place. It could be transparent to make it 
invisible if you want.

the roundRectangle has two scripts (shown). It's got "resist being picked up" 
turned on.

The result is that you can mouse down on the roundRectangle if its center is 
inside the Rectangle, and you can drag the roundRectangle as long as the 
mouse is within the bounds of the Rectangle.

Avoiding other morphs can be done with overlaps, colorSees, or touchesA (and 
probably other ways too).

-- 
Ned Konz
http://bike-nomad.com
GPG key ID: BEEA7EFE
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Constrain.png
Type: image/png
Size: 10513 bytes
Desc: not available
Url : http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20040427/14481783/Constrain.png


More information about the Squeak-dev mailing list