unit KHairLin;
{
   A hairline component promised to be 1 pxl thick allways.

   Author:  Vesa Lappalainen
   Date:    25.2.1998
   Changes:

}

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ExtCtrls, kavesimu;

type
  THairLineDirection = (hldVertical,hldHorizontal,hldRaising,hldSinking);

  THairLine = class(TaSimuObject)
  private
    { Private declarations }
    FLineDirection : THairLineDirection;
  protected
    { Protected declarations }
  public
    { Public declarations }
    constructor Create(AOwner:TComponent);     override;
    procedure SetLineDirection(value:THairLineDirection); virtual;
    procedure Paint; override;
  published
    { Published declarations }
    property LineDirection : THairLineDirection read FLineDirection
      write SetLineDirection default hldVertical;
  end;

procedure Register;

implementation

const eps = 0.0000000001;


procedure Register;
begin
  RegisterComponents('Kave2000', [THairLine]);
end;


//-----------------------------------------------------------------------------
procedure THairLine.SetLineDirection(value:THairLineDirection); //  virtual;
begin
  FLineDirection := value;
  with Box do
  case LineDirection of
    hldVertical   : if ( dp.y > eps*2 ) then dp.x := eps
                    else Set4(p.x,p.y,eps,dp.x);
    hldHorizontal : if ( dp.x > eps*2 ) then dp.y := eps
                    else Set4(p.x,p.y,dp.y,eps);
    hldRaising    : ;
    hldSinking    : ;
  end;
  Invalidate;
end;


//-----------------------------------------------------------------------------
procedure THairLine.Paint; //  override;
  procedure DoLine(x1,y1,x2,y2:integer);
  begin
    With Canvas do begin
      MoveTo(x1,y1); LineTo(x2,y2);
    end;  
  end;
begin
  case LineDirection of
    hldVertical   : DoLine(0,0,0,Height);
    hldHorizontal : DoLine(0,0,Width,0);
    hldRaising    : DoLine(0,0,Width,Height);
    hldSinking    : DoLine(Width,0,0,Height);
  end;
end;


//-----------------------------------------------------------------------------
constructor THairLine.Create(AOwner:TComponent); //      override;
begin
  inherited;
  Box.dp.y := eps;
end;




end.

