unit UKlasy;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons, ExtCtrls;


Type

Figura = class(TObject)
private
	kolor : TColor;
   brush : TBrush;
   font  : TFont;
   pen   : TPen;

protected
	Canvas : TCanvas;    // tylko wskaźnik, nie usuwać!

public
	procedure Show(); virtual;

	constructor Create(parCanvas : TCanvas); virtual;
	destructor  Destroy(); virtual;
end;

Prostokat = class(Figura)
private
	x1 : Integer;
	y1 : Integer;
	x2 : Integer;
	y2 : Integer;
   R  : TRect;

public
	procedure   Show(); override;

	constructor Create(parCanvas: TCanvas; parX1, parY1, parX2, parY2 : Integer); overload;
	constructor Create(parCanvas: TCanvas; parR : TRect); overload;

	destructor  Destroy(); override;
end;

Kolo = class(Figura)
private
	x1 : Integer;
	y1 : Integer;
	x2 : Integer;
	y2 : Integer;
   R  : TRect;


public
	procedure   Show(); override;

   constructor Create(parCanvas : TCanvas; parX1, parY1, parX2, parY2 : Integer);
	destructor  Destroy(); override;
end;

Trojkat = class(Figura)
private
	x1 : Integer;
	y1 : Integer;
	x2 : Integer;
	y2 : Integer;
   R  : TRect;

public
	procedure   Show(); override;

   constructor Create(parCanvas : TCanvas; parX1, parY1, parX2, parY2 : Integer); overload;
   constructor Create(parCanvas : TCanvas; parR : TRect); overload;

	destructor  Destroy(); override;


end;

implementation
{------------------------------------------------------------------------------}
constructor Figura.Create(parCanvas : TCanvas);
begin
	Canvas := parCanvas;
end;

destructor Figura.Destroy();
begin
end;

constructor Prostokat.Create(parCanvas : TCanvas; parX1, parY1, parX2, parY2 : Integer);
begin
   inherited Create(parCanvas);

	x1 := parX1;
   y1 := parY1;
   x2 := parX2;
   y2 := parY2;
end;

procedure Figura.Show();
begin
end;

procedure Prostokat.Show();
begin
   Canvas.Rectangle(x1, y1, x2, y2);
end;

constructor Prostokat.Create(parCanvas : TCanvas; parR : TRect);
begin
   inherited Create(parCanvas);

   R := parR;
end;

destructor Prostokat.Destroy();
begin
end;

constructor Kolo.Create(parCanvas : TCanvas; parX1, parY1, parX2, parY2 : Integer);
begin
   inherited Create(parCanvas);

	x1 := parX1;
   y1 := parY1;
   x2 := parX2;
   y2 := parY2;
end;

destructor Kolo.Destroy();
begin
end;

procedure Kolo.Show();
begin
	Canvas.Ellipse(x1, y1, x2, y2);
end;

constructor Trojkat.Create(parCanvas : TCanvas; parX1, parY1, parX2, parY2 : Integer);
begin
   inherited Create(parCanvas);

	x1 := parX1;
   y1 := parY1;
   x2 := parX2;
   y2 := parY2;
end;

constructor Trojkat.Create(parCanvas : TCanvas; parR : TRect);
begin
   inherited Create(parCanvas);
	R := parR;
end;

destructor Trojkat.Destroy();
begin
end;

procedure Trojkat.Show();
var
   srodek_x : Integer;

begin
	// Canvas.Rectangle(x1, y1, x2, y2);
   // Canvas.Brush.Color := clRed;
   // Canvas.Pen.Color := clYellow;
   //
   //  x1,y1   s_x,s_y   x2,y1
   //
   // x1,y2              x2,y2
   //
   srodek_x := 0;

   srodek_x := (x2 - x1);
   srodek_x := srodek_x div 2;
   srodek_x := x1 + srodek_x;

   // rysuje od dolu w prawo do gory
   Canvas.MoveTo(x1, y2);
   Canvas.LineTo(x2, y2);
	Canvas.LineTo(srodek_x, y1);
   Canvas.LineTo(x1, y2);
end;

end.
