Re: Co-ordinate conversion question
Re: Co-ordinate conversion question
- Subject: Re: Co-ordinate conversion question
- From: Rob Keniger <email@hidden>
- Date: Sat, 29 Nov 2008 16:46:13 +1000
On 29/11/2008, at 4:01 PM, Christian Graus wrote:
NSPoint pt = [NSEvent mouseLocation];
NSRect rcTV = [tableView bounds];
pt = [tableView convertPoint:pt fromView:nil];
So, now the first line gives me the mouse position on the screen. The
second gives me the bounds of my control, because the co-ordinates
are right
to left, so I assume I need to work out the width of the control b/c
I want
to know if the mouse is within the first 16 pixels of the item, from
the
left. Finally, I am trying to turn my screen relative point into a
point
relative to the table view. Nothing I've tried in this regard, is
doing
anything that resembles what I expect ( an x value between 0 and the
width
of the control ). how do I do that?
[NSEvent mouseLocation] returns the position of the mouse in the base
coordinate system. -convertPoint:fromView: converts from the window
coordinate system. You need to use -convertPointFromBase:.
To get the position of the mouse in your view you'd do this:
NSPoint pointInView=[myView convertPointFromBase: [NSEvent
mouseLocation]];
//check if the mouse is in the left 16 pixels of the view
if(NSPointInRect(pointInView, NSMakeRect(0,0,16.0,NSWidth([myView
bounds])))
{
//do something
}
--
Rob Keniger
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please 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