home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Generous Efforts of Many
/
gemcd.zip
/
GEM.CD.E.po
/
NDA:CLOCKS:ANACLOCK
/
ANACLOCK.PAS.txt
next >
Wrap
Text File
|
2010-05-14
|
7KB
|
305 lines
{$DeskAcc 60 -1 'Analog Clock'}
{$LongGlobals+}
{ Welcome to the Desk Accessory 'Analog Clock'!
This DA Displays an Analog Clock in a window. }
Program AnaClock;
uses
Qdintf, GSIntf, MiscTools,ConsoleIO;
var
Update: Integer;
MyWindOpen: Boolean;
MyWind: NewWindowParamBlk;
MyWindPtr: WindowPtr;
theTime: packed array[0..20] of byte;
GlobalHour: integer;
procedure DrawTheTime;
forward;
procedure QuickHand(count:integer);
forward;
procedure DoTheHour;
forward;
Procedure EraseTheFace;
var
face_area: rect;
begin
with face_area do
begin
top := 20;
left := 10;
bottom:= 81;
right := 216;
end;
SetSolidPenPat(15);
FrameRect(face_area);
PaintRect(face_area);
SetSolidPenPat( 0);
end;
Function DAOpen: WindowPtr;
Begin
If MyWindOpen then
SelectWindow(MyWindPtr)
Else
begin
with myWind do
begin
param_length := sizeof(NewWindowParamBlk);
wFrame := $C0A0;
wTitle := @'Analog Clock';
wRefCon := 0;
wZoom.top := 0;
wZoom.left := 0;
wZoom.bottom := 0;
wZoom.right := 0;
wColor := nil;
wYOrigin := 10;
wXOrigin := 50;
wDataH := 0;
wDataW := 0;
wMaxH := 0;
wMaxW := 0;
wScrollVer := 0;
wScrollHor := 0;
wPageVer := 0;
wPageHor := 0;
wInfoRefCon := 0;
wInfoHeight := 0;
wFrameDefProc:= nil;
wInfoDefProc := nil;
wContDefProc := nil;
wPosition.top := 70; { X Width: 225 pixels }
wPosition.left := 50; { Y Width: 90 [-11] pixels }
wPosition.bottom := 160;
wPosition.right := 275;
wPlane := -1;
wStorage := nil;
end;
MyWindPtr := NewWindow(MyWind);
SetSysWindow(MyWindPtr);
end;
DAOpen := MyWindPtr;
Update := 0;
MyWindOpen := True;
end; { END OF DAOPEN }
procedure DAClose;
begin
CloseWindow(MyWindPtr);
MyWindOpen := False;
Update := 0;
end; { END OF DACLOSE }
procedure DAAction( Code: Integer; Param: LongInt );
var
currPort: GrafPtr;
begin
case Code of
DAEvent: begin
if EventRecordPtr(param)^.what = updateEvt then begin
BeginUpdate(myWindPtr);
Update := 0;
DrawTheTime;
EndUpdate(myWindPtr);
end
end;
DARun: begin
currport := GetPort;
SetPort(GrafPtr(MyWindPtr));
DrawTheTime;
SetPort(currPort);
end;
DACursor: ;
DAMenu: begin
end;
DAUndo,
DACut,
DACopy,
DAPaste,
DAClear: Code := 1;
end;
end; { END OF DAACTION }
procedure DAInit(Code: Integer);
begin
if Code = 0 then begin
{ Desk Shutdown call, make sure window is closed }
if MyWindOpen then DAClose;
end
else begin
{ Desk startup call, set flag for my window }
MyWindOpen := false;
end;
end; { END OF DAINIT }
procedure DrawTheTime;
var
c,
t,
week,
month,
day,
year,
hour,
minute,
second : integer;
begin
ReadTimeHex(week,month,day,year,hour,minute,second);
{ GlobalHour is set so that }
GlobalHour := hour; { "DoTheHour" can tell the }
{ hour. }
ReadAsciiTime(@theTime);
for c := 0 to 19 do
TheTime[c] := BitAnd(TheTime[c],$7F);
MoveTo(40,8);
DrawCString(@thetime);
MoveTo(0,9);
LineTo(225,9);
Moveto(0,0);
Lineto(0,9);
MoveTo(224,0);
LineTo(224,9);
{ Now Draw the Digital Clock } {48,112}
MoveTo(48,112); { Vert. from 10-90: 80 steps }
{ Horz. from 0-225: 225 steps }
{ Draw Time Numerals }
if update = 0 then begin
MoveTo(102,18);
DrawString('12');
MoveTo(216,51);
DrawString('3');
MoveTo(2,51);
DrawString('9');
MoveTo(107,89);
DrawString('6');
MoveTo(111,45); { Center Dot . }
LineTo(111,45);
MoveTo(2,18);
DrawString('V.1.5');
MoveTo(174,18);
DrawString('Feb/88');
MoveTo(2,89);
DrawString('By G. Grant');
Update := 1; { Don't do this again unless needed. }
{ Now, That's all done. }
end; { of the Credits, etc. UPDATE }
{ ------------------------- The Main Thingy ------------------------- }
EraseTheFace; { Clear the face of the clock, excluding numerals. }
QuickHand(minute); { Draw the Minute Hand. }
QuickHand(second); { Draw the Second Hand. }
DoTheHour; { Draw the Hour hand ( the short one. ) }
end;
procedure QuickHand(count: integer);
var
x,y: integer;
begin
case count of
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15:
begin {^x: 225,^y: 80}
if count <9 then
begin
x := 111+ ( count * 11);
y := 20;
end;
if count >8 then
begin
x := 215;
y := 20 + ( ( count - 8) * 4) - 3;
end;
MoveTo(111,45);
LineTo(x,y);
end;
end;
case count of
16,17,18,19,20,21,22,23,24,25,26,27,28,29,30:
begin {^x: 225,^y: 80}
if count <23 then
begin
x := 215;
y := 46 + ( ( count - 15) * 4) - 3;
end;
if count >22 then
begin
x := 215 - ( ( count - 21) * 11) - 5;
y := 80;
end;
MoveTo(111,45);
LineTo(x,y);
end;
end;
case count of
31,32,33,34,35,36,37,38,39,40,41,42,43,44,45:
begin {^x: 225,^y: 80}
if count <38 then
begin
x := 111 - ( ( count - 30) * 11 );
y := 80;
end;
if count >37 then
begin
x := 10;
y := 80 - ( ( count - 37) * 4) - 3;
end;
MoveTo(111,45);
LineTo(x,y);
end;
end;
case count of
46,47,48,49,50,51,52,53,54,55,56,57,58,59,60:
begin {^x: 225,^y: 80}
if count <53 then
begin
x := 10;
y := 45 - ( ( count - 45 ) * 3);
end;
if count >52 then
begin
x := 21 + ( ( count - 52 ) * 11);
y := 20;
end;
MoveTo(111,45);
LineTo(x,y);
end;
end;
end;
procedure DoTheHour;
begin
MoveTo(111,45); { The center dot [axis] }
case GlobalHour of
1 ,13 : LineTo(124,35); {} { 111,46}
2 ,14 : LineTo(137,40);
3 ,15 : LineTo(150,45); {}
4 ,16 : LineTo(137,50);
5 ,17 : LineTo(124,55);
6 ,18 : LineTo(111,60); {}
7 ,19 : LineTo( 98,55);
8 ,20 : LineTo( 85,50);
9 ,21 : LineTo( 72,45); {}
10,22 : LineTo( 85,40);
11,23 : LineTo( 98,35);
12, 0 : LineTo(111,30); {}
end; { of CASE }
end; { of DoTheHour }
begin { Look Ma, NO PROGRAM! }
end. { In an NDA, the DAxxx PROCEDUREs are called independantly }