1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
| unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
LCLType, //HRGN
LCLIntf; //CreatePolygonRgn
type
{ TForm1 }
TForm1 = class(TForm)
procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure FormPaint(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
function PointInPolygon(Point: TPoint; const Polygon: array of TPoint): Boolean;
var
rgn: HRGN;
begin
rgn := CreatePolygonRgn(Polygon, Length(Polygon), WINDING);
Result := PtInRegion(rgn, Point.X, Point.Y);
DeleteObject(rgn);
end;
procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
aPoint : Tpoint;
begin
aPoint.X := X;
aPoint.Y := Y;
if PointInPolygon(aPoint, [Point(10, 10), Point(30, 30), Point(50, 70),
Point(70, 120), Point(60, 180)])
then showmessage('In');
end;
procedure TForm1.FormPaint(Sender: TObject);
begin
with Canvas do begin
Brush.Color := clOlive;
Polygon([Point(10, 10), Point(30, 30), Point(50, 70),
Point(70, 120), Point(60, 180)]);
end;
end;
end. |
Partager