Newbie question: ConstantShapeMorph?

Bob Arning arning at charm.net
Tue Dec 31 00:59:23 UTC 2002


Bill,

Mostly right on in your interpretation.

On Mon, 30 Dec 2002 15:40:05 -0800 Bill Spight <bspight at pacbell.net> wrote:
>Let me see if I understand what is going on.
>
>> You could override the #extent: method to do something like:
>> 
>
>In resizing the morph is sent an #extent: message. We make sure the new
>extent has the correct proportions.

Yup.

>> extent: aPoint
>> 
>>         x _ aPoint x.
>>         y _ aPoint y.
>>         (y * aspectRatio) > x ifTrue: [
>>                 x _ y * aspectRatio
>>         ] ifFalse: [
>>                 y _ x / aspectRatio
>>         ].
>Doing it this way makes for the greater extent, which is faster when
>expanding.

I could easily have picked smaller rather than greater. Since it wasn't specified, I flipped a coin.

>
>>         ^super extent: (x at y) rounded
>> 
>
>x at y is rounded because drawing requires an integral number of pixels.

I think the low-level stuff mostly handles non-integers, but there are at least a few places where fractional coordinates have caused problems for me before, so I tried to be sure the code would run without actually running it.

>Sending this message to super avoids the extra processing if it were
>sent to self. (And also avoids an infinite loop when rounding).

Well, the infinite loop is "the" issue here. If the last line were

	^self extent: (x at y) rounded

you would be in for a long wait (as in "How long does it take a proton to decay?").

Cheers,
Bob



More information about the Squeak-dev mailing list