Re: mouse location
Re: mouse location
- Subject: Re: mouse location
- From: David Martin <email@hidden>
- Date: Wed, 7 Aug 2002 19:02:25 +0200
On Monday, August 5, 2002, at 04:27 , Sirin Nitinawarat wrote:
I need an application that can track the location of the mouse in the
view and show it instantaneously. right now I use the [NSevent
mouselocation] but the point is relative to the screen. not the view
( i already convert it using [self convertPoint:p fromView:nil] of
NSView. But it doesn't work. (Still it's not related to the view)
In your view implementation, you should override -[NSResponder
mouseMoved:] with something like that:
- (void)mouseMoved:(NSEvent *)event
{
NSPoint mousePositionInView = [self convertPoint:[event
locationInWindow] fromView:nil];
if (NSMouseInRect(mousePositionInView, [self visibleRect], NO)) {
[[NSNotificationCenter defaultCenter]
postNotificationName:@"GWMouseMoved"
object:[NSValue
valueWithPoint:mousePositionInView]];
}
}
and in the -awakeFromNib, you should add the following line:
[[self window] setAcceptsMouseMovedEvents:YES];
Your window doesn't track mouse moved events by default, so you have to
activate it.
David
_______________________________________________
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.