Morphic relative placement?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Morphic relative placement?

Brian Greskamp
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


Reply | Threaded
Open this post in threaded view
|

Re: Morphic relative placement?

Naveen Neelakantam
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
>


Reply | Threaded
Open this post in threaded view
|

Re: Morphic relative placement?

Brian Greskamp
Naveen Neelakantam wrote:
> 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.
Yep.  I guess I wasn't thinking.  That should work just fine.

--Brian

--
Brian Greskamp
4238 Siebel Center
201 N. Goodwin Ave.
Urbana, IL 61801


Reply | Threaded
Open this post in threaded view
|

Re: Morphic relative placement?

Yoshiki Ohshima
  Hello,

At Fri, 07 Apr 2006 12:20:39 -0500,
Brian Greskamp wrote:
>
> Naveen Neelakantam wrote:
> > 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.
> Yep.  I guess I wasn't thinking.  That should work just fine.

  Almost.  Because Morphs can be rotated and scaled, just offsetting
may not be enough (you may not want to have rotation in something
named "circuit," but parhaps scaling?).

  The examples in, for example HaloMorph>>startDrag:with: shows
something like:

        positionOffset _ dragHandle center - (target point: target position in: owner).

i.e., offsetting by #- and the use of #point:in: would be what you
want.

  Hope this helps,

-- Yoshiki