3
votes

What I want to do

I have a circular custom NSView subclass, and I want to change the appearance of the cursor when the mouse is hovering over the circular portions of the view, but not when over the portions of the view's rectangle that fall outside the circle.

Here's an illustration. I would have inlined it with an image tag, but I'm too new to partake of such awesome features.

What I know so far

I know how to change the appearance of the cursor through NSCursor. I think that the best way to accomplish this for a rectangular view would be with a cursor rectangle. I know that I could receive mouseMoved events (and ought to turn them off when the mouse isn't over this view, using mouseEntered and mouseExited), and have a simple, inexpensive way to determine if a point lies in the region of interest.

So what's the problem then?

As far as I can tell, the system does not send mouseMoved events to a view that is not the first responder. Therefore, if I want to get mouseMoved events when the mouse is hovering over my view, I need to steal firstResponder status from whoever currently has it. If a text view has the focus, simply moving the mouse over such a view would steal it away, which is simply unacceptable from a usability standpoint.

Therefore, my question boils down to: is there a better way to do this? Can I get mouseMoved events without being the first responder?

Thanks!

I would have added the following tags: custom-views mouse-events NSCursor firstResponder But again, I'm an SA noob so I can't.

2

2 Answers

2
votes

I think you may just need to override the acceptsFirstResponder method in your NSView to return YES. If you don't, then the view won't receive any event information.

1
votes

Does it have to be a circular area? If anywhere within the rectangular bounds of the view is acceptable, you could use a cursor rect.