[squeak-dev] Rotating Morphs; how to rotate about a point other than the centre of bounds?

Chris Muller asqueaker at gmail.com
Fri Apr 7 00:08:38 UTC 2017


Hi Tim,

We made a nice analog gauge with rotating needle for our app and used
NCLineMorph from the Connectors package because it draws gorgeous --
anti-aliased, and we set the rotation center a little down from one
end, so it looks good.  Here's the code:

initializeNeedle
needle := (NCLineMorph
vertices: {
Point x: (self center x + 1) y: (self bounds origin y + 1).
Point x: (self center x + 1) y: (self bounds corner y - 4) }
     color: Color white
     borderWidth: 2
     borderColor: Color white)
rotationCenter: 0.5 at 0.9;
yourself



On Thu, Apr 6, 2017 at 5:07 PM, tim Rowledge <tim at rowledge.org> wrote:
> As part of the never ending Weather station project I’m making a rotary dial morph that can be used to display things such as barometers, speedometers, vu meters, clocks, compasses etc - pretty much anything where a needle thing rotates about a pivot in order to point to a value on a scale.
>
> Clearly one can be ultra simplistic and use a LineMorph over a CircleMorph but that isn't terribly pretty. Right now I have things set up to simply add submorphs to build whatever background and borders and tick marks are wanted, plus the needle. With an ImageMorph (or should it be a SketchMorph?) providing a picture of the dial/scale/frame it can look quite nice.
>
> However, the needle is a problem. A simple Line or PolygonMorph can be used and then it is possible to set the rotationCenter such that subsequent #rotationDegrees: make it turn about that centre. So far, so good. I’d prefer to allow arbitrary morphs for the needle - again, an image would be good in a lot of cases - but I cannot for the life of me find how to make general morphs rotate about a set point. I can use #rotationCenter: and the value is stuck in the extension as expected. If I use the halo rotate after doing that the new center point is clearly shown in the right place BUT it still rotates about the center of the bounds. I can’t find any illuminating usages of #rotationCenter to show how the new center point is used and certainly nothing that makes it look like it is ever treated as the pivot.
>
> I’ve dug into using asFlexShell and friends with no improvement. I’ve searched through the swiki. I’ve compared a 5.0 image with the 6alpha image. To cause further concern pretty much all the rotate related code I can find seems to be in the EToys package, which may mean it would go away when we make a more typical release image. Isn’t rotating morphs a relatively basic part of using them?
>
> What have I missed, or looked at without actually seeing?
>
> tim
> --
> tim Rowledge; tim at rowledge.org; http://www.rowledge.org/tim
> Strange OpCodes: LTT: Lose Timing Track
>
>
>


More information about the Squeak-dev mailing list