{

  Copyright (c) 1997-2003 by CoolDev.Com. Part of CoolControls package.

}

{$I versions.inc}
unit PolygonesUnit;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  CoolPolygons, ExtCtrls, CoolTools, StdCtrls, CoolCtrls;

type
  TPolygonesForm = class(TForm)
    ScrollBox: TScrollBox;
    ButtonClearPoints: TButton;
    ButtonOk: TButton;
    ButtonCancel: TButton;
    CoolPolygones: TCoolPolygones;
    ButtonClearPolygones: TButton;
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure ButtonOkClick(Sender: TObject);
    procedure ButtonClearPointsClick(Sender: TObject);
    procedure ButtonClearPolygonesClick(Sender: TObject);
  private
    FPolygones: TPolygones;
    procedure SetPolygones(Value: TPolygones);
  public
    property Polygones: TPolygones read FPolygones write SetPolygones;
  end;

var
  PolygonesForm: TPolygonesForm;

implementation

{$R *.DFM}

procedure TPolygonesForm.SetPolygones(Value: TPolygones);
begin
  FPolygones.Assign(Value);
end;

procedure TPolygonesForm.FormCreate(Sender: TObject);
begin
  FPolygones := TPolygones.Create(Self);
  CoolPolygones.PaintBorders := True;
end;

procedure TPolygonesForm.FormDestroy(Sender: TObject);
begin
  FPolygones.Free;
end;

procedure TPolygonesForm.FormActivate(Sender: TObject);
begin
  CoolPolygones.Polygones.Assign(FPolygones);
end;

procedure TPolygonesForm.ButtonOkClick(Sender: TObject);
begin
  FPolygones.Assign(CoolPolygones.Polygones);
end;

procedure TPolygonesForm.ButtonClearPointsClick(Sender: TObject);
begin
  CoolPolygones.Points.Clear;
end;

procedure TPolygonesForm.ButtonClearPolygonesClick(Sender: TObject);
var
  s: string;
begin
  s := '';

  if InputQuery('Clear Polygones', 'Polygone # (empty if all):', s) then
  try
    if (s = '') then
      CoolPolygones.Polygones.Clear else
      {$IFDEF DELPHI5_OR_ABOVE}
      CoolPolygones.Polygones.Delete(StrToInt(s));  
      {$ELSE}
      CoolPolygones.Polygones[StrToInt(s)].Free;
      {$ENDIF}
  except
  end;
end;

end.
