[squeak-dev] Squeak clock face

Louis LaBrunda Lou at Keystone-Software.com
Mon Dec 18 20:43:09 UTC 2017


Hi Bob and Tim,

Both your explanations were very helpful.  Thank you.  I am now able to read in a clock face
picture and pictures for the hour, minute and second hands.  I include how far from the end the
rotation point is.  This works great.  I do have a small problem that I find odd.  If a picture
of one or more of the hands is not supplied I generate a default hand similar to what is used
in ClockDialMorph.  The odd thing is that the rotation point is about 18 pixels above center.
This seems to correspond to the height of the menu bar in the main Squeak window.  But that
could just be a coincidence.

This is the code that makes a second hand:

makeSecondHandMorph
	"Make a default morph for the second hand."
	| pointerMorph |

	pointerMorph := self basicNeedleOfLength: (self height * 0.45) rounded width: 3 color: Color
red.
	pointerMorph position: pointerMorph extent * (-0.5 @ -0.95).

	"we keep track of the TransformationMorph since that is what we have to rotate"
	secondHandMorph := TransformationMorph new position: dialCenter; addMorph: pointerMorph.
	self addMorph: secondHandMorph.


and this code reads in a picture to be used as a second hand:

secondHandMorph: aFileName rotationOffset: offset
	"Set the morph for the second hand."
	| pic pointerMorph yOffset |

	pic := Form fromFileNamed: aFileName.
	pointerMorph := (self newPointerFrom: pic length: (self height * 0.45)) asMorph.
	yOffset := -1.0 + (offset / pic height).
	pointerMorph position: pointerMorph extent * (-0.5 @ yOffset).

	secondHandMorph := TransformationMorph new position: dialCenter; addMorph: pointerMorph.
	self addMorph: secondHandMorph.

again, the code that I would think would have a problem, the code that read in the picture,
works just fine.  The code that draws a simple line for the hand has the center of rotation too
high above the center.

By the way, #dialCenter is sent to the center of the clock with self center.

Any thoughts?

Lou


On Mon, 18 Dec 2017 14:15:02 -0500, Bob Arning <arning315 at comcast.net> wrote:

>
>
>On 12/18/17 1:51 PM, Louis LaBrunda wrote:
>> Hi Tim,
>>
>> Can you please explain what this does:
>>
>> 	pointerMorph position: pointerMorph extent * ( -0.5@ -0.65).
>>
>> especially what does 	"* ( -0.5@ -0.65)" do
>multiplication of a point (extent) by another point (-0.5 @ -0.65) gives 
>a point as the result. The x-coords are multiplied together and the 
>y-coords similarly. In this case, the pointerMorph will be positioned 
>centered on 0 in the x axis (from -0.5 width to +0.5 width) and mostly 
>above 0 on the y axis (from -0.65 height to +0.35 height). This likely 
>will result in pleasing rotation about 0 at 0. Of course, you could put a 
>halt in the code and check this for yourself.
>
>> and why and what do -0.5 and -0.65 relate to?
>>
>> Thanks.
>>
>> Lou
>>
>> On Fri, 15 Dec 2017 14:33:34 -0800, tim Rowledge <tim at rowledge.org> wrote:
>>
>>>> On 15-12-2017, at 2:01 PM, Louis LaBrunda <Lou at Keystone-Software.com> wrote:
>>>>   I have sub-classed RotaryDialMorph similar to Tim's ClockDialMorph.  Tim has
>>>> the hands (minute and hour) rotate around one of their ends.  I'm trying to get them to rotate
>>>> around a point say 20 pixels in from that end.  How should I do this?
>>> Take a look also at Barometer (etc) morph>>initialize to see how the fancy needle is created and positioned
>>>
>>>
>>> tim
>
>
-- 
Louis LaBrunda
Keystone Software Corp.
SkypeMe callto://PhotonDemon



More information about the Squeak-dev mailing list