Library Lines;

{define Debug}

{$ifndef Debug}
{$R-,I-,D-,L-,S-,V-,W-,G+}
{$endif}

{$R LINES}

Uses
  WinTypes,WinProcs,Strings,WinDOS;

{$I ADD-IN.INC}

Const
  LineThick : Integer = 2;
  DiscMode : Boolean = True;

  CLBVer : VerString = '1.70';

{$D Lines Add-In for Clysbar. (C) 1992 by clySmic Software. All Rights Resv'd.}

{-----------------------------------------------}

{ --- Perform Add-In's initialization --- }

Function InitAddIn(CurVer : PChar) : InitResult; Export;

Begin
  Randomize;

  { Version check }
  If StrComp(CurVer,CLBVer) <> 0
    Then InitAddIn := InitNotOk
    Else InitAddIn := InitOk;
End {InitAddIn};

{-----------------------------------------------}

{ --- Paint on the button (Clysbar does the background) --- }

Procedure PaintAddIn(Wnd : HWnd; DC : HDC; Pressed : Boolean); Export;

Begin
End {DrawAddIn};

{-----------------------------------------------}

{ --- Tell Clysbar what kind of timer we need --- }

Function TimerNeeded : Integer; Export;

Begin
  TimerNeeded := ait_Fast;
End {TimerNeeded};

{-----------------------------------------------}

{ --- Proc called when timer expires, perform timed duties --- }

Procedure AddInTimer(Wnd : HWnd; DC : HDC); Export;

Const
  xSav : Integer = 5;
  ySav : Integer = 5;

Var
  Rect : TRect;
  OldPen,ThePen : HPen;

Begin
  { If add-in is never uncovered, Wnd will be NULL }
  If wnd = 0
    Then Exit;

  { Don't draw over button "edges" }
  GetClientRect(Wnd,Rect);
  InflateRect(Rect,-6,-6);

  { Draw a random line in a random color }
  ThePen := CreatePen(ps_Solid,LineThick,RGB(Random(256),Random(256),Random(256)));
  OldPen := SelectObject(DC,ThePen);

  If DiscMode 
    Then Begin
           { Disconnected lines }
           MoveTo(Dc,Random(Rect.Right-2) + Rect.Left-2,
                     Random(Rect.Bottom-2) + Rect.Top-2);
           LineTo(Dc,Random(Rect.Right-2) + Rect.Left-2,
                     Random(Rect.Bottom-2) + Rect.Top-2);
         End
    Else Begin
           { Connected lines }
           MoveTo(DC,xSav,ySav);
           xSav := Random(Rect.Right-2) + Rect.Left-2;
           ySav := Random(Rect.Bottom-2) + Rect.Top-2;
           LineTo(DC,xSav,ySav);
         End;

  { Clean up }
  SelectObject(DC,OldPen);
  DeleteObject(ThePen);
End {AddInTimer};

{-----------------------------------------------}

{ --- Proc called when button pressed --- }

Procedure AddInPressed(Wnd : HWnd; DC : HDC); Export;

Begin
  LineThick := Random(4) + 1;    {1..4}

  DiscMode := Not DiscMode;

  PaintAddIn(Wnd,DC,False);
End {AddInPressed};

{-----------------------------------------------}

{ --- Exit processing for Add-In --- }

Procedure ExitAddIn; Export;

Begin
End {ExitAddIn};

{-----------------------------------------------}

{ --- Clysbar queries Add-In about itself (N.B.: not implemented yet) --- }

Procedure AddInAbout(Str1,Str2 : PChar;
                     Var TheIcon : HIcon;
                     Var TitleCol,TxCol,BkCol : TColorRef); Export;

Begin
  StrCopy(Str1,'Lines V1.70');
  StrCopy(Str2,'A Random Line Drawer'#13'© 1992 by clySmic Software.'#13'All Rights Reserved.');

  TheIcon := LoadIcon(hInstance,'ABOUT');

  TitleCol := RGB(255,0,255);
  TxCol := RGB(128,0,128);
  BkCol := RGB(255,255,255);
End {AddInAbout};

{-----------------------------------------------}

Exports InitAddIn    Index 1,
        PaintAddIn   Index 2,
        TimerNeeded  Index 3,
        AddInTimer   Index 4,
        AddInPressed Index 5,
        ExitAddIn    Index 6,
        AddInAbout   Index 7;

Begin
End.
