博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
GdiPlus[35]: IGPGraphicsPath (二) 命中测试
阅读量:7022 次
发布时间:2019-06-28

本文共 1915 字,大约阅读时间需要 6 分钟。

  hot3.png

IGPGraphicsPath.IsVisible        //指定点是否在路径内IGPGraphicsPath.IsOutlineVisible //指定点是否在路径轮廓上
本例测试图:
26153618_rIzM.gif

本例代码:

unit Unit1;interfaceuses  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,  Dialogs;type  TForm1 = class(TForm)    procedure FormCreate(Sender: TObject);    procedure FormPaint(Sender: TObject);    procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);    procedure FormResize(Sender: TObject);  end;var  Form1: TForm1;implementation{$R *.dfm}uses GdiPlus;var  Path1,Path2,Path3: IGPGraphicsPath;  Pen: IGPPen;procedure TForm1.FormCreate(Sender: TObject);var  R: TRect;begin  Pen := TGPPen.Create($FFFF0000, 3);  Path1 := TGPGraphicsPath.Create;  Path2 := TGPGraphicsPath.Create;  Path3 := TGPGraphicsPath.Create;  Path1.AddLine(0, 0, ClientWidth, ClientHeight);  R := ClientRect;  InflateRect(R, -ClientWidth div 3, -ClientHeight div 3);  OffsetRect(R, -Trunc((R.Right-R.Left) * 0.6), -Trunc((R.Bottom-R.Top) * 0.6));  Path2.AddRectangle(TGPRect.Create(R));  OffsetRect(R, R.Right-R.Left, R.Bottom-R.Top);  Path3.AddEllipse(TGPRect.Create(R));end;procedure TForm1.FormPaint(Sender: TObject);var  Graphics: IGPGraphics;begin  Graphics := TGPGraphics.Create(Handle);  with Graphics do  begin    DrawPath(Pen, Path1);    DrawPath(Pen, Path2);    DrawPath(Pen, Path3);  end;end;procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);var  Pt: TGPPoint;  str: string;begin  Pt.Initialize(X, Y);  str := '';  if Path2.IsVisible(Pt) then str := '在矩形内';  if Path3.IsVisible(Pt) then str := '在椭圆内';  if Path1.IsOutlineVisible(Pt, Pen) then str := '在直线上';  if Path2.IsOutlineVisible(Pt, Pen) then str := '在矩形的边线上';  if Path3.IsOutlineVisible(Pt, Pen) then str := '在椭圆的圆周线上';  if Text <> str then Text := str;end;procedure TForm1.FormResize(Sender: TObject);begin  OnCreate(Sender);  Repaint;end;end.

转载于:https://my.oschina.net/hermer/blog/320261

你可能感兴趣的文章
OpenGL ES testing
查看>>
Android 的窗口管理系统 (View, Canvas, WindowManager)
查看>>
从 Qt 的 delete 说开来
查看>>
[Postgres] Create a Postgres Table
查看>>
如何推断一个P2P平台是否靠谱?
查看>>
Spring学习【Spring概述】
查看>>
一起学编程(3--组织与表达)
查看>>
ROS+L2TP+IPSEC
查看>>
【Java数据结构学习笔记之一】线性表的存储结构及其代码实现
查看>>
零代码如何打造自己的实时监控预警系统
查看>>
Sql server Always On 读写分离配置方法
查看>>
鸡肋点搭配ClickJacking攻击-获取管理员权限
查看>>
垃圾收集器
查看>>
基于Redis+Kafka的首页曝光过滤方案
查看>>
关于Cocos2d-iPhone 的类库
查看>>
Facebook内部人才建设潜规则
查看>>
JSP项目开发常用技术总结
查看>>
使用x64dbg分析微信聊天函数并实现发信息
查看>>
两台Mysql数据库数据同步实现
查看>>
npm install -S -D -g 有什么区别
查看>>