[Q][morphic] absolute and relative coordinates

Andreas Raab andreas.raab at gmx.de
Tue Sep 2 21:05:19 UTC 2003


> I have constructed morph that consists of several submorphs (circles
> and lines) and embedded this morph into an owning morph. The circles
> and lines were create with ablsolute coordinates, i.e. as if the
> upperLeft corner of my morph was 0 at 0. 

If you assume that the upper left corner is 0 at 0 then it's a relative (not
absolute) coordinate as the screen position will be obtained relatively to
the position of the owner morph. Morphic generally (but not always) uses
global coordinates, so that when a morph is within another one its
coordinates change when its owner coordinates change.

Here is an example:

| m1 m2 m3 |
m1 := Morph new.
m1 extent: 400 at 400.
m1 openInWorld.
m2 := Morph new.
m2 position: 200 at 200.
"the second morph is now roughly at the center of the first one"
m1 addMorphFront: m2.

"now let's move the first morph and add a third one"
m1 position: m1 position+100.
m3 := Morph new.
m3 position: 200 at 200.
m1 addMorph: m3.

The third morph will be positioned at a different place than the second one
due to using global coordinates.

> Once my morph is embedded into its owner its upperLeft corner
> certainly is not 0 at 0 anymore and any *new* circles and lines I add
> then end up outside the morph's bounding rectangle.

Yes, this is essentially the same as what you see in the above. If the
morph's position is different than adding new morphs will put them at
different relative (but the same global) position. At least in most cases.

> I can add topLeft to all coordinates and things appear where they
> should.
> 
> What is the standard way of doing this, i.e. manipulationg a morph
> in-situ and contruction a morph ? 

What you are doing is correct. You have to add the topLeft corner to the
relative position of the morph.

Cheers,
  - Andreas



More information about the Squeak-dev mailing list