如何检测画布边框而不是其内容上的单击?在Flex中
如何检测画布边框上的点击,而不是其内容?
我知道我可以验证范围 event.mouseX (Y),但我的画布有圆角,在某些情况下看起来是一个圆圈,有什么方法可以知道画布的边框是否在指针下方?
我有:
Canvas.setStyle ("borderColor", 0xFF0000);
Canvas.setStyle ("borderStyle", "solid");
Canvas.setStyle ("BorderThickness", 10);
How I can detect a click on the border of a canvas, not its contents?.
I am aware that I can validate ranges event.mouseX (Y), but my canvas has rounded corners and in some cases appears to be a circle, is there any way of knowing if the border of the canvas is under the pointer?
I have:
Canvas.setStyle ("borderColor", 0xFF0000);
Canvas.setStyle ("borderStyle", "solid");
Canvas.setStyle ("BorderThickness", 10);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
从 10px 的厚度来看,如果用户点击边框或画布,真正的问题是什么?您是否有单击画布时调用的事件侦听器?如果是这样,也许您应该优化这些侦听器以调整从画布内容而不是画布本身分派的事件。
Judging by a 10px thickness what is the real problem if the user clicks on the border or the canvas? Do you have event listeners that are being invoked when the canvas is clicked on? If so, maybe you should refine those listeners to tune into the events dispatched from the contents of the canvas rather than the canvas itself.
我对这个特定主题不太了解,但是您是否考虑过建立某种选择机制?
您可以拥有一个从不显示的图形缓冲区,但将所有内容绘制到其中。每一个你想要区分的东西都用不同的颜色绘制。这样,对于任何鼠标事件,您都可以找出鼠标所在的位置,包括以其自己的颜色绘制的边框,并将适当的事件传递给该对象。
如果您找不到任何其他方法,则可能仅作为最后的手段有用。
I don't know much about this particular topic, but have you thought about setting up some sort of picking mechanism?
You can have a graphics buffer that you never display, but draw everything to. Each thing you'd like to distinguish you draw in a different color. That way you can, for any mouse event, figure out what the mouse was over, including the border which would be drawn in its own color, and pass the appropriate event to that object.
Probably only useful as a last resort, if you can't find any other way of doing it.
拥有一张比前面的画布大 10 像素且包含实际内容的画布怎么样?然后,背面画布会注册一次点击,而正面画布则不会注册您的实际内容。
How about having one canvas that is 10px larger than the one in front of it with your actual content. Then that back canvas register for a click and the front one with your actual content not.