unit MaskPiece;

interface

uses
  Windows, Messages, SysUtils, Classes, Controls, ExtCtrls, kavesimu;

type

  TMaskPiece = class(TaSimuObject)
  private
    FUpwards: boolean;
    Fxl2: integer;
    Fxu1: integer;
    Fxl1: integer;
    Fxu2: integer;
    procedure SetUpwards(const Value: boolean);
    procedure Setxl1(const Value: integer);
    procedure Setxl2(const Value: integer);
    procedure Setxu1(const Value: integer);
    procedure Setxu2(const Value: integer);
  protected
  public
    procedure Paint; override;
    constructor Create(AParent:TComponent); override;
  published
    property Upwards : boolean read FUpwards write SetUpwards;
    property xu1 : integer read Fxu1 write Setxu1;
    property xu2 : integer read Fxu2 write Setxu2;
    property xl1 : integer read Fxl1 write Setxl1;
    property xl2 : integer read Fxl2 write Setxl2;
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('Kave2000', [TMaskPiece]);
end;

{ TMaskPiece }

constructor TMaskPiece.Create(AParent: TComponent);
begin
  inherited;
  xu1 := 30;
  xu2 := 30;
  xl1 := 30;
  xl2 := 30;
end;

procedure TMaskPiece.Paint;
var points : array[0..8] of TPoint; i,x1,x2,x3,x4,w,h,c : integer;
    opposite : boolean;
begin
//  inherited;
  Canvas.Brush := Brush;
  Canvas.Pen := Pen;
  opposite := Upwards;
  w := Width - 1;
  h := Height -1;
  c := w; if ( h < w ) then c := h;
  x1 := xu1 * c div 100 ;
  x2 := xu2 * c div 100 ;
  x3 := xl1 * c div 100 ;
  x4 := xl2 * c div 100 ;

  points[0] := Point(x1,0);
  points[1] := Point(w-x2,0);
  points[2] := Point(w,x2);
  points[3] := Point(w,h-x4);
  points[4] := Point(w-x4,h);
  points[5] := Point(x3,h);
  points[6] := Point(0,h-x3);
  points[7] := Point(0,x1);
  points[8] := Point(x1,0);


//  if ( h < x1 ) then begin x1 := h; x3 := 0; end;
//  if ( h < x2 ) then begin x2 := h; x4 := 0; end;

  if ( Scale.Fac.x < 0 ) then opposite := not opposite;

  if ( opposite ) then for i:=0 to Length(points) do
    points[i].x := w-points[i].x;

  Canvas.Polygon(points);
end;

procedure TMaskPiece.SetUpwards(const Value: boolean);
begin
  FUpwards := Value;
  Invalidate;
end;

procedure TMaskPiece.Setxl1(const Value: integer);
begin
  Fxl1 := Value;
  Invalidate;
end;

procedure TMaskPiece.Setxl2(const Value: integer);
begin
  Fxl2 := Value;
  Invalidate;
end;

procedure TMaskPiece.Setxu1(const Value: integer);
begin
  Fxu1 := Value;
  Invalidate;
end;

procedure TMaskPiece.Setxu2(const Value: integer);
begin
  Fxu2 := Value;
  Invalidate;
end;

end.
