我有一个表单,有一个面板(align:= alClIEnt).
表格上有2个TCircle’s.
我已经设置了TCircle.Dragmode:= dmautomatic.
我想拖动圆圈并在圆圈重叠时发生一些事情.
问题是:我没有在TCircle中看到任何称为重叠的方法,也没有看到一个名为重叠的事件.我已经尝试了所有的xxxxDrag事件,但这对我的测试没有帮助.
如何查看拖动的形状何时与另一个形状重叠?
我期待其中一个DragOver,dragenter事件为我检测到这一点,但似乎并非如此.
当然在Firemonkey中必须有一些标准方法吗?
现在pas文件看起来像:
implementation{$R *.fmx}procedure TForm8.Circle1dragenter(Sender: TObject; const Data: TDragObject; const Point: TPointF);begin if Data.source = Circle1 then button1.Text:= 'dragenter';end;procedure TForm8.Circle1DragOver(Sender: TObject; const Data: TDragObject; const Point: TPointF; var Accept: Boolean);begin if (Data.source = Circle2) then button1.Text:= 'Circle2 drag';end;procedure TForm8.Circle2DragEnd(Sender: TObject);begin button1.Text:= 'DragEnd';end;procedure TForm8.Circle2dragenter(Sender: TObject; const Data: TDragObject; const Point: TPointF);begin button1.Text:= 'dragenter';end;procedure TForm8.Circle2DragLeave(Sender: TObject);begin button1.Text:= 'DragLeave';end;procedure TForm8.Circle2DragOver(Sender: TObject; const Data: TDragObject; const Point: TPointF; var Accept: Boolean);begin if Data.source = Circle2 then begin button1.Text:= 'DragOver'; Accept:= true; end;end;
dfm看起来像这样:
object Form8: TForm8 left = 0 top = 0 BIDiMode = bdleftToRight Caption = 'Form8' ClIEntHeight = 603 ClIEntWIDth = 821 Transparency = False Visible = False StyleLookup = 'backgroundstyle' object Panel1: TPanel Align = alClIEnt WIDth = 821.000000000000000000 Height = 603.000000000000000000 Taborder = 1 object button1: Tbutton position.Point = '(16,16)' WIDth = 80.000000000000000000 Height = 22.000000000000000000 Taborder = 1 Stayspressed = False Ispressed = False Text = 'button1' end object Circle1: TCircle DragMode = dmautomatic position.Point = '(248,120)' WIDth = 97.000000000000000000 Height = 105.000000000000000000 Ondragenter = Circle1dragenter OnDragOver = Circle1DragOver end object Circle2: TCircle DragMode = dmautomatic position.Point = '(168,280)' WIDth = 81.000000000000000000 Height = 65.000000000000000000 Ondragenter = Circle2dragenter OnDragLeave = Circle2DragLeave OnDragOver = Circle2DragOver OnDragEnd = Circle2DragEnd end endend解决方法 一般问题很难并且称为碰撞检测 – 您可以谷歌这个术语来找到相关的算法.
圆碰撞检测的特殊情况很简单 – 只需计算圆心之间的距离即可.如果获得的距离小于圆的半径之和,则圆重叠.
总结以上是内存溢出为你收集整理的delphi – 如何查看两个形状是否重叠全部内容,希望文章能够帮你解决delphi – 如何查看两个形状是否重叠所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)