GdiPlus[38]: IGPGraphicsPath (五) 路径标记
生活随笔
收集整理的這篇文章主要介紹了
GdiPlus[38]: IGPGraphicsPath (五) 路径标记
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
IGPGraphicsPath.SetMarker //建立一個(gè)標(biāo)記 IGPGraphicsPath.ClearMarkers //取消全部標(biāo)記
在路徑中每建立一個(gè)圖形都可以同時(shí)做個(gè) Marker,
真正使用這些個(gè)標(biāo)記時(shí), 主要通過 IGPGraphicsPathIterator 的 NextMarker() 方法.
下面是建立并遍歷 Marker 的演示代碼, 暫未使用 IGPGraphicsPathIterator.
uses GdiPlus;procedure TForm1.FormCreate(Sender: TObject); varPt1,Pt2: TGPPoint;Rect: TGPRect;Path: IGPGraphicsPath;i: Integer;str: string; beginPt1.Initialize(20, 20);Pt2.Initialize(150, 150);Rect.InitializeFromLTRB(Pt1.X, Pt1.Y, Pt2.X , Pt2.Y);Path := TGPGraphicsPath.Create;{ 路徑有四個(gè)圖形(或叫子路徑構(gòu)成), 并在每個(gè)圖形后做了 marker; 第一個(gè)前不需要也作不上. }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;{ 檢索看看都是哪個(gè)點(diǎn)上有 Marker, 它的類型標(biāo)識(shí)是 $20 }str := '';for i := 0 to Path.PointCount - 1 doif Path.PathTypes[i] and $20 = $20 thenstr := str + IntToStr(i+1) + ' ';ShowMessage(TrimRight(str)); // 4 17 19 21{ 執(zhí)行 ClearMarkers, 重新檢索看看 }Path.ClearMarkers;str := '';for i := 0 to Path.PointCount - 1 doif Path.PathTypes[i] and $20 = $20 thenstr := str + IntToStr(i+1) + ' ';ShowMessage(TrimRight(str)); // 當(dāng)然不會(huì)再有了 end;
使用 IGPGraphicsPathIterator 檢索 Marker 的例子:
uses GdiPlus;varPath: IGPGraphicsPath;PathIterator: IGPGraphicsPathIterator;procedure TForm1.FormCreate(Sender: TObject); varPt1,Pt2: TGPPoint;Rect: TGPRect; beginPt1.Initialize(20, 20);Pt2.Initialize(150, 150);Rect.InitializeFromLTRB(Pt1.X, Pt1.Y, Pt2.X , Pt2.Y);Path := TGPGraphicsPath.Create;//建立四個(gè)圖形并添加兩個(gè)標(biāo)記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);//建立 PathIteratorPathIterator := TGPGraphicsPathIterator.Create(Path); end;procedure TForm1.Button1Click(Sender: TObject); varm1,m2: Integer;i: Integer; begini := 0;PathIterator.Rewind;while PathIterator.NextMarker(m1, m2) > 0 dobeginInc(i);ShowMessageFmt('第 %d - %d 個(gè)標(biāo)記的范圍: %d - %d', [i-1, i, m1, m2]);end; {第 0 - 1 個(gè)標(biāo)記的范圍: 0 - 3第 1 - 2 個(gè)標(biāo)記的范圍: 4 - 18第 2 - 3 個(gè)標(biāo)記的范圍: 19 - 20 } //就添加了兩個(gè)標(biāo)記怎么會(huì)檢索出三個(gè)范圍呢? 兩個(gè)點(diǎn)把路徑分成了三段! end;//IGPGraphicsPathIterator.NextMarker 的第二種用法 procedure TForm1.Button2Click(Sender: TObject); vari,r: Integer; begini := 0;PathIterator.Rewind;while True dobeginr := PathIterator.NextMarker(Path);if r = 0 then Break;Inc(i);ShowMessageFmt('第 %d - %d 個(gè)標(biāo)記間共有 %d 個(gè)點(diǎn)', [i-1, i, r]);end; {第 0 - 1 個(gè)標(biāo)記間共有 4 個(gè)點(diǎn)第 1 - 2 個(gè)標(biāo)記間共有 15 個(gè)點(diǎn)第 2 - 3 個(gè)標(biāo)記間共有 2 個(gè)點(diǎn) } end;
總結(jié)
以上是生活随笔為你收集整理的GdiPlus[38]: IGPGraphicsPath (五) 路径标记的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: plsqldev连oracle,plsq
- 下一篇: 读《About Face 4 交互设计精