|
Class: ClockView
Object
|
+--GraphicsMedium
|
+--DisplaySurface
|
+--SimpleView
|
+--ClockView
- Package:
- stx:libwidg3
- Category:
- Views-Fun
- Version:
- rev:
1.40
date: 2019/05/06 08:21:45
- user: cg
- file: ClockView.st directory: libwidg3
- module: stx stc-classLibrary: libwidg3
- Author:
- Claus Gittinger (spring 91)
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.
Clock
RoundClock
Time
ProcessorScheduler
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
-
-
keyPress: key x: x y: y
-
-
mapped
-
view was mapped - launch a time-scheduled updateBlock
-
sizeChanged: how
-
my size has changed - have to clear & redraw
-
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
-
Clock start
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
|
|