Newbie question: ConstantShapeMorph?

Bill Spight bspight at pacbell.net
Mon Dec 30 23:40:05 UTC 2002


Dear Bob,

Thanks very much. :-)

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.

> 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.

>         ^super extent: (x at y) rounded
> 

x at y is rounded because drawing requires an integral number of pixels.

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

> 
> Where aspectRatio is an instance variable set to the desired x/y ratio.

Bueno!

Bill



More information about the Squeak-dev mailing list