在路徑中每建立一個圖形都可以同時做個 Marker,
真正使用這些個標記時, 主要通過 IGPGraphicsPathIterator 的 NextMarker() 方法.
下面是建立並遍歷 Marker 的演示代碼, 暫未使用 IGPGraphicsPathIterator.
uses GdiPlus;
procedure TForm1.FormCreate(Sender: TObject);
var
Pt1,Pt2: TGPPoint;
Rect: TGPRect;
Path: IGPGraphicsPath;
i: Integer;
str: string;
begin
Pt1.Initialize(20, 20);
Pt2.Initialize(150, 150);
Rect.InitializeFromLTRB(Pt1.X, Pt1.Y, Pt2.X , Pt2.Y);
Path := TGPGraphicsPath.Create;
{ 路徑有四個圖形(或叫子路徑構成), 並在每個圖形後做了 marker; 第一個前不需要也作不上. }
Path.AddRectangle(Rect);
Path.SetMarker;
Path.AddEllipse(Rect);
Path.SetMarker;
Path.AddLine(Pt1.X, Pt1.Y, Pt2.X, Pt2.Y);
Path.SetMarker;
Path.AddLine(Pt1.X, Pt2.Y, Pt2.X, Pt1.Y);
Path.SetMarker;
{ 檢索看看都是哪個點上有 Marker, 它的類型標識是 $20 }
str := '';
for i := 0 to Path.PointCount - 1 do
if Path.PathTypes[i] and $20 = $20 then
str := str + IntToStr(i+1) + ' ';
ShowMessage(TrimRight(str)); // 4 17 19 21
{ 執行 ClearMarkers, 重新檢索看看 }
Path.ClearMarkers;
str := '';
for i := 0 to Path.PointCount - 1 do
if Path.PathTypes[i] and $20 = $20 then
str := str + IntToStr(i+1) + ' ';
ShowMessage(TrimRight(str)); // 當然不會再有了
end;
使用 IGPGraphicsPathIterator 檢索 Marker 的例子:
uses GdiPlus;
var
Path: IGPGraphicsPath;
PathIterator: IGPGraphicsPathIterator;
procedure TForm1.FormCreate(Sender: TObject);
var
Pt1,Pt2: TGPPoint;
Rect: TGPRect;
begin
Pt1.Initialize(20, 20);
Pt2.Initialize(150, 150);
Rect.InitializeFromLTRB(Pt1.X, Pt1.Y, Pt2.X , Pt2.Y);
Path := TGPGraphicsPath.Create;
//建立四個圖形並添加兩個標記
Path.AddRectangle(Rect);
Path.SetMarker;
Path.AddEllipse(Rect);
Path.AddLine(Pt1.X, Pt1.Y, Pt2.X, Pt2.Y);
Path.SetMarker;
Path.AddLine(Pt1.X, Pt2.Y, Pt2.X, Pt1.Y);
//建立 PathIterator
PathIterator := TGPGraphicsPathIterator.Create(Path);
end;
procedure TForm1.Button1Click(Sender: TObject);
var
m1,m2: Integer;
i: Integer;
begin
i := 0;
PathIterator.Rewind;
while PathIterator.NextMarker(m1, m2) > 0 do
begin
Inc(i);
ShowMessageFmt('第 %d - %d 個標記的范圍: %d - %d', [i-1, i, m1, m2]);
end;
{
第 0 - 1 個標記的范圍: 0 - 3
第 1 - 2 個標記的范圍: 4 - 18
第 2 - 3 個標記的范圍: 19 - 20
} //就添加了兩個標記怎麼會檢索出三個范圍呢? 兩個點把路徑分成了三段!
end;
//IGPGraphicsPathIterator.NextMarker 的第二種用法
procedure TForm1.Button2Click(Sender: TObject);
var
i,r: Integer;
begin
i := 0;
PathIterator.Rewind;
while True do
begin
r := PathIterator.NextMarker(Path);
if r = 0 then Break;
Inc(i);
ShowMessageFmt('第 %d - %d 個標記間共有 %d 個點', [i-1, i, r]);
end;
{
第 0 - 1 個標記間共有 4 個點
第 1 - 2 個標記間共有 15 個點
第 2 - 3 個標記間共有 2 個點
}
end;