如何判断点击了哪个(对象)控件?

How to determine which (object) control has been clicked?

我正在寻求一些建议 "how to determine which (object) control has been clicked"?

在 mouse:over 我隐藏角控件(和边框):

图片 -> https://github.com/Robinyo/my-2d-diagram-editor/blob/master/client/content/images/my-2d-diagram-editor-with-ports.png

在 mouse:down 我使用 getCenterPoint()(mouse:over 目标)开始画线:

图片 -> https://github.com/Robinyo/my-2d-diagram-editor/blob/master/client/content/images/my-2d-diagram-editor-with-connections.png

在 mouse:move 我更新了(连接器)线 x2 和 y2,在 mouse:up 我使用 getCenterPoint() (mouse:over 目标)作为线的终点。

我想做的是使用最近的连接点(ml、mt、mr、mb)而不是 getCenterPoint()。

如果您的应用程序允许,请更新到最新的 fabric js,因为此修复是最近的。

然后在鼠标上移时您可以检查:

object.__corner

那应该有值 'mt'、'mr'...等等。 请注意,如果我没记错的话,fabricjs 首先检查对象,如果失败,则检查角落点击。

(target.containsPoint(xy) || target._findTargetCorner(pointer))

这意味着它将首先检查边界框,然后检查角点。换句话说,角落定位将只在角落的外部起作用。