NSView and Cursor rects
NSView and Cursor rects
- Subject: NSView and Cursor rects
- From: "Bruce Johnson" <email@hidden>
- Date: Mon, 4 Jun 2007 16:43:51 -0700
I working on signaling the mouseEntered and mouseExit events from a
subclassed NSView. The goal is to change the cursor when the mouse moves
over my custom view.
The view is is inset from the parent window (the view does not cover the
entire window)
I'm having some trouble signaling the mouse events
The setup in my subclassed NSView:
//overriding this method
- (void)viewDidMoveToWindow
{
NSRect bounds = [self bounds];
cursorTrackingRect = [self addTrackingRect: [self convertRect:
[self bounds] fromView: nil]
owner: self
userData: NULL
assumeInside: NO];
NSLog(@"**DEBUG\tcontent view bounds = %@",
NSStringFromRect([self convertRect: [self bounds] fromView: nil]));
}
This results in this:
**DEBUG content view bounds = {{-337.499, 316}, {309, 309}}
the output of [self bounds] is orginal bounds = {{0, 0}, {309, 309}}
Then in the mouse event functions I override: (from the apple docs...)
- (void)mouseEntered: (NSEvent *)theEvent
{
wasAcceptingMouseEvents = [[self window] acceptsMouseMovedEvents];
[[self window] setAcceptsMouseMovedEvents: YES];
[[self window] makeFirstResponder: self];
printf("**DEBUG\tmouse Entered\n"); fflush(stdout);
}
and
- (void)mouseExited: (NSEvent *)theEvent
{
[[self window] setAcceptsMouseMovedEvents: wasAcceptingMouseEvents];
printf("**DEBUG\tmouse Exited\n"); fflush(stdout);
}
This triggers the mouse enter and exit debug strings to be fired when the
mouse is in the lower left-hand corner of the window, not over the view
itself.
The view is located at:
{{182,160}, {308,308}} in the window's coordinates.
Am I doing something obviously wrong? I've tried adding back the "offset"
of the view's location in the window, but I just chasing my tail.
Any ideas?
--
----
Bruce Johnson
email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden