|
Class: ClockView
Object
|
+--GraphicsMedium
|
+--DisplaySurface
|
+--SimpleView
|
+--ClockView
- Package:
- stx:libwidg3
- Category:
- Views-Fun
- Version:
- rev:
1.43
date: 2023/07/06 14:36:56
- user: cg
- file: ClockView.st directory: libwidg3
- module: stx stc-classLibrary: libwidg3
xclock replacement
:-) not that I thought this clock is any better than xclock
or that the world needs clocks ...
its showing how easy it is to program in Smalltalk -
this took less than an hour to program - compare with xclock code ....
Since this is a subclass of view, you can use it as a widget in
more complex views.
Implementation note:
this class was written long before multiple threads came to ST/X;
therefore, it uses the Processors timedBlock facilities.
Today, things would be written differently.
As an excercise, you may rewrite it using an update process which
runs in the background.
copyrightCOPYRIGHT (c) 1991 by Claus Gittinger
All Rights Reserved
This software is furnished under a license and may be used
only in accordance with the terms of that license and with the
inclusion of the above copyright notice. This software may not
be provided or otherwise made available to, or used by, any
other person. No title to or ownership of the software is
hereby transferred.
accessing
-
beStopWatch
-
-
startMeasure
-
drawing
-
displayCenteredString: aString
-
-
drawArm: tick width: w len: l
-
draw an arm of the clock; argument tick specifies minute (0..59);
width is width in pixel, len is relative len - 1.0 is full
-
drawArmsFor: aTime
-
draw arms for a given time in current paint
-
redraw
-
redraw everything
-
redrawArms
-
redraw the arms
-
redrawStopWatchInfo
-
-
redrawTicks
-
redraw the ticks
-
redrawTimeFraction
-
-
showTime
-
executed every second (by timedBlock)
-
timeShown
-
-
updateArms
-
clear previous arms - draw new arms
-
updateArmsFor: aTime
-
clear previous arms - draw new arms
events
-
buttonPress: button x: x y: y
-
(comment from inherited method)
button was pressed - check my components for a hit.
-
keyPress: key x: x y: y
-
(comment from inherited method)
a key has been pressed. If there are components,
pass it to the corresponding one.
Otherwise, forward it to the superview, if there is any.
-
mapped
-
view was mapped - launch a time-scheduled updateBlock
-
sizeChanged: how from: oldExtentOrNil
-
my view has changed the size (not the contents)
-
startClock
-
launch a time-scheduled updateBlock
-
toggleStopWatch
-
self updateArmsFor:(self timeShown).
initialization
-
initialize
-
initialize the view & precompute the tick-position-table
Usage example(s):
initialize table of (normalized) x/y coordinates of ticks
|
-
middleButtonMenu
-
(comment from inherited method)
return the menu associated with the middle mouse button.
Here, return a hooked on menu, but usually redefined to provide a widget-specific
menu.
misc
-
showSeconds: aBoolean
-
toggle (and possibly redraw) the show-seconds flag
-
toggleSeconds
-
user wants to toggle the show-seconds flag
user actions
-
copyTimeDuration
-
-
destroy
-
the view was destroyed - remove time-scheduled updateBlock
-
resetStopWatch
-
in a topView:
|top clk|
top := StandardSystemView new.
top label:'ST/X clock'.
top extent:200@200.
clk := ClockView origin:0.0@0.0 corner:1.0@1.0 in:top.
top open
|
a stopWatch (click to start/stop):
|top clk|
top := StandardSystemView new.
top label:'ST/X clock'.
top extent:200@200.
clk := ClockView origin:0.0@0.0 corner:1.0@1.0 in:top.
clk beStopWatch.
top open
|
as a component:
|top frame clk fileList|
top := StandardSystemView new.
top extent:200@200.
frame := View origin:1.0@0.0 corner:1.0@50 in:top.
frame leftInset:-50; rightInset:4; topInset:2; bottomInset:2.
frame level:-1.
clk := ClockView origin:0.0@0.0 corner:1.0@1.0 in:frame.
clk showSeconds:false.
fileList := ScrollableView for:FileSelectionList in:top.
fileList origin:0@50 corner:1.0@1.0.
top open
|
|