Re: Looking for simple NSCursor example code
Re: Looking for simple NSCursor example code
- Subject: Re: Looking for simple NSCursor example code
- From: Greg Titus <email@hidden>
- Date: Fri, 2 Aug 2002 15:50:38 -0700
On Friday, August 2, 2002, at 03:21 PM, Antoine McNamara wrote:
I'm having problems getting extremely simple NSCursor code using a
cursorRect in a view to work as described in the documentation. All
the examples I can find that change the cursor do so by calling
setDocumentCursor instead of the using a cursorRect.
I need my app to display a custom cursor when the mouse lies above a
particular view. The documentation is clear on how this should be
accomplished, but I can't get even the most brain-dead program to
actually get it to switch.
Hi Antoine,
You need to do two things. First, in the documentation for
-addCursorRect:cursor:, you should notice that you are only supposed to
call this method from -resetCursorRects, and you should make sure that
you only add cursor rects for the visible portions of your view.
So instead of your -awakeFromNib method, use:
- (void)resetCursorRects
{
NSCursor *aCursor = [NSCursor IBeamCursor];
[self addCursorRect:[self visibleRect] cursor:aCursor];
[aCursor setOnMouseEntered:YES];
}
Second, something that should be documented with cursor rects but
doesn't seem to be: NSWindow's usually ignore mouse move events because
they aren't normally needed, as a performance optimization. So you need
to turn on mouse move events for your window.
The simplest way to do this is by implementing -viewDidMoveToWindow on
your view:
- (void)viewDidMoveToWindow
{
[[self window] setAcceptsMouseMovedEvents:YES];
}
Hope this helps,
- Greg
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.