• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Co-ordinate conversion question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >Co-ordinate conversion question (From: "Christian Graus" <email@hidden>)

  • Prev by Date: UIViewController memory warnings | didReceiveMemoryWarning | setView | releasing outlets | releasing properties
  • Next by Date: Re: Checking One Array Against Another
  • Previous by thread: Co-ordinate conversion question
  • Next by thread: Unicode in constant @"" NSStrings
  • Index(es):
    • Date
    • Thread