Re: Find Mouse Location Inside CustomView
Re: Find Mouse Location Inside CustomView
- Subject: Re: Find Mouse Location Inside CustomView
- From: Daniel J Farrell <email@hidden>
- Date: Wed, 28 Jun 2006 22:22:10 +0100
Hi,
Thanks folks! Here is the finished code snip:
//get mouse position in Window
NSWindow *plotWindow = [self window];
NSPoint mousePosition = [plotWindow mouseLocationOutsideOfEventStream];
//convert to View
mousePosition = [self convertPoint:mousePosition fromView:nil];
float mX = mousePosition.x;
float mY = mousePosition.y;
//draw text showing mouse position
NSString *mousePositionString;
mousePositionString = [NSString stringWithFormat:@"(X,Y) = (%g3.3,%
g3.3)",mX,mY];
NSMutableDictionary *attributes = [NSMutableDictionary dictionary];
[mousePositionString drawAtPoint:NSMakePoint(100,100)
withAttributes:attributes];
Daniel.
On 28 Jun 2006, at 20:55, Greg Titus wrote:
See -convertPoint:fromView:. Pass "nil" as the view to convert from
to convert from window coordinates to the view's coordinates.
Hope this helps,
- Greg
On Jun 28, 2006, at 12:52 PM, Daniel J Farrell wrote:
Hi folks,
Is there a NSView method that will tell me the current coordinates
(NSPoint) of the mouse pointer relative to the NSView (in this
case it is actually a CustomView) coordinate system.
I have found NSEvent('s) -mouseLocation but this gives at NSPoint
relatively to the screen and NSWindow('s) -
mouseLocationOutsideOfEventStream and this gives an NSPoint
relative to the Window. I guess it must be possible to transform
from any or all of the different coordinate systems but just
wanted to see if there is an easy Cocoa way to do find this
information.
Regards,
Daniel
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden