Re: Converting to Window Coordinates
Re: Converting to Window Coordinates
- Subject: Re: Converting to Window Coordinates
- From: Dave <email@hidden>
- Date: Wed, 22 Apr 2015 17:10:15 +0100
Yes, good idea, I’ll change it.
Is hit testing the content view the only way to tell which window a point falls within? At the moment I loop though all windows until I find one which works, but is a bit inefficient.
I’d like a windowForScreenPoint: type method.
Thanks again for all your help. I’d love to know how many developer hours have been spent in the history of Cocoa figuring out how and where to flip the Y coordinate. I don’t know about anyone else but I find it really hard work trying to think bottom up when designing NIBS etc. I really can’t understand why it was ever defined to be bottom left, does anyone know why?
All the Best
Dave
> On 22 Apr 2015, at 15:13, Lee Ann Rucker <email@hidden> wrote:
>
> There's also +[NSEvent mouseLocation], which gives you the position in the same screen coordinate space the windows use.
>
>> Do I have to worry about this? It seems to work, but the window I am testing in is a plain (no title bar etc) window, so the content view and the window Frame coincide, do I need to add this for safety in case the window does have a title bar?
>
> It's always best to future-proof your code, just in case some day you decide to reuse it on a window with a title or if for some odd reason your view's base coordinates aren't what you expect.
> ________________________________________
> From: cocoa-dev-bounces+lrucker=email@hidden [cocoa-dev-bounces+lrucker=email@hidden] on behalf of Dave [email@hidden]
> Sent: Wednesday, April 22, 2015 3:55 AM
> To: Cocoa Developers
> Subject: Re: Converting to Window Coordinates
>
> Hi Again Lee Ann,
>
> Thanks a lot for this, one thing though, how do I tell which window the position is in? At present I loop through all my open windows and apply run “hitTest” on the content view until I find one.
>
>> Another thing you've missed: converting to myContentView's coordinate space from the window's space, with [myContentView convertPoint:myWindowPoint fromView:nil] - "If aView is nil, this method instead converts from window base coordinates"
>
> Do I have to worry about this? It seems to work, but the window I am testing in is a plain (no title bar etc) window, so the content view and the window Frame coincide, do I need to add this for safety in case the window does have a title bar?
>
> Here is the code I am using, it seems for work ok:
>
> myContentView = self.window.contentView;
>
> myGlobalPoint.x = theGlobalPoint.x;
> myGlobalPoint.y = NSMaxY([[[NSScreen screens] objectAtIndex:0] frame]) - theGlobalPoint.y; //Flip
>
> myWorkRect.origin = myGlobalPoint;
> myWorkRect.size = NSMakeSize(1,1);
> myWorkRect = [self.window convertRectFromScreen:myWorkRect];
> myWindowPoint = myWorkRect.origin;
>
> myCocoaControlView = (LTWViewBase*) [myContentView hitTest:myWindowPoint];
> if (myCocoaControlView != nil)
> {
> if ([myCocoaControlView class] == [myContentView class])
> myCocoaControlView = nil;
>
> else if ([[myCocoaControlView class] isSubclassOfClass:[LTWViewBase class]] == NO)
> myCocoaControlView = nil;
> }
>
> All the Best
> Dave
>
> _______________________________________________
>
> 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
_______________________________________________
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