begin external class WindowTools; MainWindow class Watch_window; begin ref(Button) Quit_B, Start_B; ref(SubWindow) Clock, Watch; text DT, Old_DT, Start = "Start", Stop = "Stop", Clear = "Clear", Quit = "Quit", Zero_time = "00:00.00"; real Start_time; integer Acc_time, This_run; Boolean Pause, Done; procedure Display_clock; begin DT :- DateTime; if DT <> Old_DT then begin Clock.Clear.DrawCenterText(DT); Old_DT :- Copy(DT); end if; end Display_clock; procedure Display_watch(Always); Boolean Always; begin text procedure Val1(N); integer N; begin text V; Val1 :- V :- Blanks(1); V.PutInt(N); end Val1; text procedure Val2(N); integer N; begin Val2 :- Val1(N//10) & Val1(Mod(N,10)); end Val2; text ST; integer Tx; Tx := if Pause then 0 else Entier(10*(ClockTime-Start_time)); if Tx <> This_run or Pause or Always then begin This_run := Tx; Tx := Acc_time + Tx; ST :- Val2(Mod(Tx,36000)//600) & ":" & Val2(Mod(Tx,600)//10) & "." & Val1(Mod(Tx,10)); Watch.Clear.DrawCenterText(ST); end if; end Display_watch; procedure Run_watch; begin while not Done do begin Display_clock; if not Pause then Display_watch(false); Handle_pending_events; end while; end Run_watch; procedure Start_watch; begin if Pause then begin Start_time := ClockTime; This_run := 0; Pause := false; end if; end Start_watch; procedure Stop_watch; begin if not Pause then begin Acc_time := Acc_time + This_run; Pause := true; end if; end Start_watch; procedure Clear_watch; begin Acc_time := This_run := 0; Start_time := ClockTime; Display_watch(true); end Clear_watch; procedure Perform(Command); text Command; begin if Command = Start then Start_watch else if Command = Stop then Stop_watch else if Command = Clear then Clear_watch else if Command = Quit then Done := true; end Perform; SetSize(400,200); Show; Start_B :- MakeButton(Start); MakeButton(Stop); MakeButton(Clear); Quit_B :- MakeButton(Quit); Quit_B.PlaceAt(Max_x-Quit_B.Width-SubWindowSpacing, SubWindowSpacing); Watch :- new SubWindow(this Watch_window).PlaceBelow(Start_B); Watch.SetTypeFace("helvetica", 24, true, false); Watch.SetSize(1.25*Watch.Width_of_text(Zero_time),1.5*Watch.Font_height); Watch.DrawCenterText(Zero_time); Watch.Show; Clock :- new SubWindow(this Watch_window); Clock.SetTypeFace("helvetica", 18, false, false); Clock.SetSize(1.25*Clock.Width_of_text(DateTime), 1.5*Clock.Font_height); Clock.PlaceDownLeft; Display_clock; Clock.Show; Pause := true; Clear_watch; Run_watch; end Watch_window; new Watch_window("Stopwatch"); end