IGPGraphicsPath.SetMarker    //建立一个标记
IGPGraphicsPath.ClearMarkers //取消全部标记


在路径中每建立一个图形都可以同时做个 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;

posted on 2009-12-18 21:45  万一  阅读(2244)  评论(0编辑  收藏  举报