• 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: Converting to Window Coordinates
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Converting to Window Coordinates


  • Subject: RE: Converting to Window Coordinates
  • From: Lee Ann Rucker <email@hidden>
  • Date: Wed, 22 Apr 2015 14:13:33 +0000
  • Thread-topic: Converting to Window Coordinates

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


  • Follow-Ups:
    • Re: Converting to Window Coordinates
      • From: Dave <email@hidden>
References: 
 >Converting to Window Coordinates (From: Dave <email@hidden>)
 >RE: Converting to Window Coordinates (From: Lee Ann Rucker <email@hidden>)
 >Re: Converting to Window Coordinates (From: Dave <email@hidden>)
 >RE: Converting to Window Coordinates (From: Lee Ann Rucker <email@hidden>)
 >Re: Converting to Window Coordinates (From: Dave <email@hidden>)
 >RE: Converting to Window Coordinates (From: Lee Ann Rucker <email@hidden>)
 >Re: Converting to Window Coordinates (From: Dave <email@hidden>)

  • Prev by Date: Re: Converting to Window Coordinates
  • Next by Date: Re: Converting to Window Coordinates
  • Previous by thread: Re: Converting to Window Coordinates
  • Next by thread: Re: Converting to Window Coordinates
  • Index(es):
    • Date
    • Thread