Morphic coordinates.

Blake blake at kingdomrpg.com
Fri Feb 4 12:25:26 UTC 2005


I was running through the "Programming Morphic" project and managed to get  
the examples to work, but there was behavior in one that I couldn't work  
out.

You're supposed to make the morphic appear like a cross, so I wrote the  
following code:

drawOn: aCanvas
	| v h |
	v := self width // 4 @ 0 corner: self width - (self width // 4) @ self  
height.
	h := 0 @ (self height // 4) corner: self width @ (self height - (self  
height // 4)).
	aCanvas fillRectangle: v color: Color blue;
		 fillRectangle: h color: Color blue

I can plug this into a Morphic descendant (only method) and it will work,  
except that when I move the morphic, the cross doesn't move with it, or  
not quite correctly anyway. It acts a little bit like the coordinates are  
global and the code above presumes the canvas coordinates is local (as you  
can see from the code above referencing 0).

That doesn't quite seem to be the case however, or at least my attempts to  
transform the coordinates didn't work. Rotation resulted in odd behavior,  
as well, with the morph usually ending up displaying precisely one quarter  
of the cross (as if the corner were where the middle should be). Not  
always the same corner, either.

But enough on how it doesn't work<s>, what do I need to make it work?



More information about the Squeak-dev mailing list