Direct2D (31) : 命中测试 - ID2D1Geometry.FillContainsPoint()、StrokeContainsPoint()


uses Direct2D, D2D1;

const
  penWidth = 25;
var
  iGeometry: ID2D1EllipseGeometry;

procedure TForm1.FormCreate(Sender: TObject);
begin
  D2DFactory.CreateEllipseGeometry(D2D1Ellipse(D2D1PointF(120, 90), 80, 50), iGeometry);
end;

procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
var
  bFill, bStroke: LongBool;
  intBool: Integer;
  str: string;
begin
  iGeometry.FillContainsPoint(Point(X,Y), TD2DMatrix3x2F.Identity, 0, bFill);
  iGeometry.StrokeContainsPoint(Point(X,Y), penWidth, nil, TD2DMatrix3x2F.Identity, 0, bStroke);
  intBool := 0;
  Inc(intBool, Integer(bFill) shl 1);
  Inc(intBool, Integer(bStroke) shl 2);
  case intBool of
    0: str := '无命中';
    2: str := '命中椭圆';
    4: str := '命中椭圆边缘';
    6: str := '同时命中椭圆及边缘';
  end;
  Caption := str;
end;

procedure TForm1.FormPaint(Sender: TObject);
var
  cvs: TDirect2DCanvas;
begin
  cvs := TDirect2DCanvas.Create(Canvas, ClientRect);
  cvs.BeginDraw;
  cvs.Brush.Color := clYellow;
  cvs.FillGeometry(iGeometry);

  cvs.Pen.Color := clRed;
  cvs.Pen.Brush.Handle.SetOpacity(0.5);
  cvs.Pen.Width := penWidth;
  cvs.DrawGeometry(iGeometry);

  cvs.Pen.Brush.Handle.SetOpacity(1);
  cvs.Pen.Width := 1;
  cvs.DrawGeometry(iGeometry);
  cvs.EndDraw;
  cvs.Free;
end;


效果图:

o_201104081.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值