{相关常量}
//D2D1_GEOMETRY_RELATION = type Integer;
D2D1_GEOMETRY_RELATION_UNKNOWN      = 0;  //未知
D2D1_GEOMETRY_RELATION_DISJOINT     = 1;  //不相交
D2D1_GEOMETRY_RELATION_IS_CONTAINED = 2;  //属于
D2D1_GEOMETRY_RELATION_CONTAINS     = 3;  //包含
D2D1_GEOMETRY_RELATION_OVERLAP      = 4;  //重叠


测试代码:

uses Direct2D, D2D1;

procedure TForm1.FormPaint(Sender: TObject);
const
  arr1: array[0..3] of string = ('红色', '黄色', '绿色', '蓝色');
  arr2: array[1..4] of string = ('不相交于', '属于', '包含', '相交于');
  arrColor: array[0..3] of TColor = (clRed, clYellow, clGreen, clBlue);
var
  cvs: TDirect2DCanvas;
  iEllipseGeometry: ID2D1EllipseGeometry;
  iRectangleGeometrys: array[0..3] of ID2D1RectangleGeometry;
  i,h: Integer;
  x: D2D1_GEOMETRY_RELATION;
  strArr: array[0..3] of string;
begin
  D2DFactory.CreateEllipseGeometry(D2D1Ellipse(D2D1PointF(150, 150), 50, 50), iEllipseGeometry);
  D2DFactory.CreateRectangleGeometry(D2D1RectF(90, 90, 210, 210), iRectangleGeometrys[0]);
  D2DFactory.CreateRectangleGeometry(D2D1RectF(130, 130, 170, 170), iRectangleGeometrys[1]);
  D2DFactory.CreateRectangleGeometry(D2D1RectF(70, 130, 110, 170), iRectangleGeometrys[2]);
  D2DFactory.CreateRectangleGeometry(D2D1RectF(220, 130, 260, 170), iRectangleGeometrys[3]);

  for i := 0 to 3 do
  begin
    iEllipseGeometry.CompareWithGeometry(iRectangleGeometrys[i], TD2DMatrix3x2F.Identity, 0, x);
    strArr[i] := Format('圆 "%s"'#9'%s矩形', [arr2[x], arr1[i]]);
  end;

  cvs := TDirect2DCanvas.Create(Canvas, ClientRect);
  cvs.BeginDraw;
  cvs.RenderTarget.Clear(D2D1ColorF(clWhite));

  for i := 0 to 3 do
  begin
    cvs.Brush.Color := arrColor[i];
    cvs.FillGeometry(iRectangleGeometrys[i]);
  end;

  cvs.Font.Size := 10;
  cvs.Brush.Color := clWhite;
  h := cvs.TextHeight(strArr[0]);
  for i := 0 to 3 do cvs.TextOut(8, h*i+5, strArr[i]);

  cvs.EndDraw;
  cvs.Free;
end;


效果图:



posted on 2011-04-07 22:32  万一  阅读(1611)  评论(0编辑  收藏  举报