我正在开发一个自定义控件,它在其上绘制曲线,并允许用户通过单击更改曲线的属性。现在捕捉曲线本身的事件非常困难,因为它们可能非常薄(根据用户要求)
不知何故,我想增加曲线的命中选择。 我有一个解决方案,但它真的很贵,因为我的图表中有大量的曲线。那就是为什么我在寻找一种逻辑,通过它我可以在鼠标指针周围找到有限的曲线。
我尝试过HitTest()但它没有帮助。 我搜索了很多解决方案,但没有收获。
如果某人能够对这一主题有所了解并建议我正确的方向继续下去,那将是一个很大的帮助。
提前致谢。
答案 0 :(得分:0)
您必须自己实现此功能。您可以做的是收听基础线的MouseEnter / MouseLeave,如果您在初始MouseEnter / Leave计数的某个半径内获得了mousedown,则将其作为命中。
例如,在伪代码中:
OnMouseEnter()
{
this.hittestPoint = currentMousePoint;
}
OnMouseLeave()
{
this.hitTestPoint = currentMousePoint;
}
OnMouseDown()
{
// Looking for mousedown within a 5 pixel radius of the line.
// Increase/decrease according to experimentation
const double radius = 5;
// Note see Euclidean distance for distance between vectors
// http://en.wikipedia.org/wiki/Euclidean_distance
double deltaX = (hitTestPoint.X - currentPoint.X);
double deltaY = (hitTestPoint.Y - currentPoint.Y);
double distance = Math.Sqrt(deltaX*deltaX + deltaY*deltaY);
if(distance < radius)
{
// Hittest detected!
}
}