unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, Menus, Spin;

type
  TForm1 = class(TForm)
    RadioGroup1: TRadioGroup;
    MainMenu1: TMainMenu;
    Datei1: TMenuItem;
    Schlieen1: TMenuItem;
    Panel1: TPanel;
    Image1: TImage;
    Neu1: TMenuItem;
    SpinEdit1: TSpinEdit;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    SpinEdit2: TSpinEdit;
    Button1: TButton;
    procedure Schlieen1Click(Sender: TObject);
    procedure Image1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure Neu1Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation
var xp,yp:array[0..200] of integer;
n,b,h:integer; xmin,ymin:integer;
{$R *.lfm}

procedure TForm1.Schlieen1Click(Sender: TObject);
begin
close
end;

procedure TForm1.Image1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
 if button=mbLeft then
   If radioGroup1.itemIndex=0 then
    begin
     n:=n+1;
     xp[n]:=x;
     yp[n]:=y;
     image1.Canvas.Pen.Color:=clblack;
     Image1.Canvas.rectangle(x+3,y+3,x-3,y-3);
      if n>1 then
        begin
        image1.Canvas.MoveTo(xp[n-1],yp[n-1]);
        image1.Canvas.LineTo(xp[n],yp[n]);
          if ssalt in shift then
           image1.Canvas.LineTo(xp[1],yp[1]);
       end;
       end
 else
 begin
 xmin:=x;
 ymin:=y;
 b:=spinedit1.value;
 h:=spinedit2.value;
 image1.canvas.Pen.color:=clblack;
 Image1.Canvas.Brush.Style:=bsclear;
 image1.Canvas.Rectangle(xmin-b,ymin-h,xmin,ymin);
end;
end;


procedure TForm1.Neu1Click(Sender: TObject);
begin
radiogroup1.ItemIndex:=0;
Image1.canvas.Brush.Style:=bssolid;
Image1.canvas.pen.Color:=clwhite;
image1.Canvas.Rectangle(0,0,Image1.width,Image1.height);
n:=0;
end;

procedure TForm1.Button1Click(Sender: TObject);
var i:integer;
begin
 for i:=1 to n do
   begin
    if (((xp[i]> (xmin-b)) and (xp[i]<xmin))
    and ((yp[i]>(ymin-h)) and (yp[i]<ymin)))
    and (((xp[i+1]> (xmin-b)) and (xp[i+1]<xmin))
    and  ((yp[i+1]> (ymin-h)) and (yp[i+1]<ymin)))
    then
    begin
    image1.Canvas.pen.Color:=clred;
    image1.Canvas.MoveTo(xp[i+1],yp[i+1]);
    image1.Canvas.LineTo(xp[i],yp[i]);
   end;end;
    if (((xp[n]> (xmin-b)) and (xp[n]<xmin))
    and ((yp[n]>(ymin-h)) and (yp[n]<ymin)))
    and (((xp[1]> (xmin-b)) and (xp[1]<xmin))
    and  ((yp[1]> (ymin-h)) and (yp[1]<ymin)))
    then
    begin
    image1.Canvas.pen.Color:=clred;
    image1.Canvas.MoveTo(xp[n],yp[n]);
    image1.Canvas.LineTo(xp[1],yp[1]);
    end;

end;

end.
