Morphic relative placement?

Naveen Neelakantam neelakan at uiuc.edu
Fri Apr 7 17:07:38 UTC 2006


To get the absolute position of an owner, you can use "self owner  
position".  You can thereby convert between absolute and relative  
coordinates of a submorph.

You should set coordinates for the bounding box of a submorph, which  
indirectly sets its position (NOTE: that the "position" message  
returns "bounds topLeft" in Morph).  To set the bounding box, you can  
use "self bounds: aRectangle", where aRectangle uses absolute world  
coordinates.

In general, things seem to work better if you use a bounding box  
slightly larger than the graphics rendered by your morph (and the  
"expandBy:" message in Rectangle might be useful for doing this).   
The bounding box is meant to be a rough approximation of the area  
rendered by a morph, so as a heads up you might want to look at  
redefining the "containsPoint:" message to precisely define the  
region covered by your morph so that things like MouseEvent's are  
delivered only when appropriate.

At least that is the best way I've found...

Naveen

On Apr 7, 2006, at 10:52 AM, Brian Greskamp wrote:

> I'm building a schematic editor where I need to control the  
> relative placement of a submorph inside its owner morph.  In the  
> view, I have a morph representing a circuit.  Each CircuitMorph has  
> arbitrarily many child CircuitMorphs.  In the model, each Circuit  
> stores a fixed point position relative to it's parent Circuit's  
> upper left corner.
>
> I tried to render the view doing the naive thing; each CircuitMorph  
> does: "self position: model position".  The problem is that "Morph  
> >> position:" seems to be setting the *absolute* position within  
> the world rather than position relative to the owner.  How do I set  
> a position relative to the owner?
>
> Thanks for helping a Morphic newbie.
> --Brian
>
> -- 
> Brian Greskamp
> 4238 Siebel Center
> 201 N. Goodwin Ave.
> Urbana, IL 61801
>




More information about the Squeak-dev mailing list