zoukankan      html  css  js  c++  java
  • GdiPlus[35]: IGPGraphicsPath (二) 命中测试


    IGPGraphicsPath.IsVisible        //指定点是否在路径内
    IGPGraphicsPath.IsOutlineVisible //指定点是否在路径轮廓上
    

    本例测试图:



    本例代码:

    unit Unit1;
    
    interface
    
    uses
      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.
    
  • 相关阅读:
    游戏AI系列内容 咋样才能做个有意思的AI呢
    图片缩放的相关处理
    Lua 安全调用 metatable 的简单应用
    让Lua自己把文件夹下面的所有文件自动加载起来吧
    【原创】有利于提高xenomai 实时性的一些配置建议
    环境篇:Docker
    环境篇:Virtualbox+Vagrant安装Centos7
    环境篇:VMware Workstation安装Centos7
    软件篇:前端保姆->VSCode
    大数据篇:ElasticSearch
  • 原文地址:https://www.cnblogs.com/del/p/1626373.html
Copyright © 2011-2022 走看看