[squeak-dev] Re: Building an dial with an arrow indicator.

Jerome Peace peace_the_dreamer at yahoo.com
Tue Jun 7 04:40:02 UTC 2011


Hi Rodney,

You wrote:
>
In that case, how should IndicatorMorph work?  I can duplicate
PolygonMorph>>arrowPrototype and call it IndicatorMorph>>new, but that
seems wrong for all kinds of reasons.


dial := CurvierMorph daimondOval openCenteredInWorld.
tail := dial bounds center .
arrowLen := constant.
indicator :=
Polygon arrowPrototype setVertices: { tail . tail + (Point r: arrowLen degrees: angleInDegrees) } .

dial addSubMorph: indicator.

to update indicator

dial updateIndicator: angleInDegrees
tail := self bounds center .
indicator setVertices: { tail . tail + (Point r: arrowLen degrees: angleInDegrees) } .


Basically you update the indicator by calculating a vector and adding it to where you want the tail. As it is a line it will have only two vertices.
You can compose a dial by embedding the indicator arrow as a submorph.

The code I have written is unchecked and somewhat sloppy. You will have to play with it. This should give you the general idea.

StarMorphs are an easy way to get a circle adjust one to have enough points then adjust the fatness until you have a circle. Any morph you wish can serve as the dial. An image or sketch morph allows you to use a picture as the dial background.

To get the updates to happen regularly you will have to figure out how "stepping" works.







More information about the Squeak-dev mailing list