可可中的定制形状跟踪区域 [英] custom shaped tracking area in cocoa
问题描述
如何在可可粉中创建自定义形状的跟踪区域? 在可可中,我只能找到矩形作为跟踪区域.
How to create a custom shaped tracking area in cocoa ? In cocoa I could only find rectangles as tracking area.
Carbon通过HIViewNewTrackingArea提供了此功能, 任何HIShapeRef都可以注册为跟踪区域.可可中有类似的东西吗?
Carbon provided this functionality through HIViewNewTrackingArea , through which any HIShapeRef could be registered as a tracking area.Do we have something similar to this in cocoa ?
我的形状很复杂,我想在不同区域更改鼠标光标.
I have a complex shape in which I want to change mouse cursors at different regions.
我尝试的一种方法是制作一个覆盖整个区域的大跟踪矩形,然后 使用mouseMoved事件更改光标.
One approach I tried was making a big tracking rectangle covering the whole area, and then changing cursor using mouseMoved events.
您能提出其他建议吗?
如果可可中有类似HIViewNewTrackingArea这样的api,那会更容易.
It would have been easier if there was a similar api like HIViewNewTrackingArea in cocoa.
谢谢.
推荐答案
在Cocoa框架中,跟踪区域仅是矩形的.您可以覆盖整个区域,然后创建一个NSBezierPath(您可以一直保持它,但不抚摸或填充),并通过-containsPoint:询问该点是否在其中.
Tracking areas are only rectangular in the Cocoa frameworks. You could cover your entire area, then create an NSBezierPath (which you keep around but do not stroke or fill) and ask it if the point is inside it via -containsPoint:.
当路径提供自定义形状的点击检测机制时,跟踪区域会激活"鼠标跟踪.
The tracking area "activates" mouse tracking while the path provides your custom-shaped hit detection mechanism.
这篇关于可可中的定制形状跟踪区域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!