unit Unit4;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls;
type
TForm4 =
class(TForm)
shp1: TShape;
shp2: TShape;
procedure shp2MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
procedure shp1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
procedure FormCreate(Sender: TObject);
procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
private
{ Private declarations }
procedure Simulate (X, Y: Integer);
public
{ Public declarations }
end;
var
Form4: TForm4;
implementation
{$R *.dfm}
procedure TForm4.FormCreate(Sender: TObject);
begin
Doublebuffered := True;
end;
procedure TForm4.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
Simulate(X, Y);
end;
procedure TForm4.shp1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
Simulate(shp1.Left + X, shp1.Top + Y);
end;
procedure TForm4.shp2MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
Simulate(shp2.Left + X, shp2.Top + Y);
end;
function PointInRgn(R: TRect): Boolean;
var rHandle: THandle;
p: TPoint;
begin
Result := True;
rHandle := CreateEllipticRgnIndirect(R);
if rHandle <> 0
then
begin
p := Form4.ScreenToClient(Mouse.CursorPos);
Result := PtInRegion(rHandle,p.X,p.Y);
DeleteObject(rHandle);
end;
end;
procedure TForm4.Simulate (X, Y: Integer);
var
rKreis1, rKreis2: Integer;
Kreis1posX, Kreis1posY: Integer;
Kreis2posX, Kreis2posY: Integer;
R: TRect;
begin
Refresh;
rKreis1 := shp1.Width
div 2;
rKreis2 := shp2.Width
div 2;
Kreis1posX := shp1.Left + rKreis1;
Kreis1posY := shp1.Top + rKreis1;
Kreis2posX := shp2.Left + rKreis2;
Kreis2posY := shp2.Top + rKreis2;
R.TopLeft := Point(shp2.Left - rKreis1, shp2.Top - rKreis1);
R.BottomRight := Point(shp2.Left + shp2.Width + rKreis1 +2, shp2.Top + shp2.Height + rKreis1 +2);
Canvas.MoveTo(Kreis1posX, Kreis1posY);
Canvas.Ellipse(X + rKreis1, Y + rKreis1, X - rKreis1, Y - rKreis1);
Canvas.LineTo(X, Y);
if PointInRgn(R)
then
begin
Canvas.LineTo(5 * rKreis2 * (X - Kreis2posX)
, 5 * rKreis2 * (Y - Kreis2posY));
Canvas.MoveTo(Kreis2posX, Kreis2posY);
Canvas.LineTo(-(5 * rKreis2 * (X - Kreis2posX))
, -(5 * rKreis2 * (Y - Kreis2posY)));
end;
end;
end.