RE: Converting to Window Coordinates
RE: Converting to Window Coordinates
- Subject: RE: Converting to Window Coordinates
- From: Lee Ann Rucker <email@hidden>
- Date: Tue, 21 Apr 2015 22:27:04 +0000
- Thread-topic: Converting to Window Coordinates
[NSWindow mouseLocationOutsideOfEventStream]
Returns the current location of the pointer reckoned in the window’s base coordinate system.
________________________________________
From: cocoa-dev-bounces+lrucker=email@hidden [cocoa-dev-bounces+lrucker=email@hidden] on behalf of Dave [email@hidden]
Sent: Tuesday, April 21, 2015 2:04 PM
To: Cocoa Developers
Subject: Re: Converting to Window Coordinates
Hi Again,
Yes, I wondered about multiple monitors but it seems to work ok, I’ve got 3 monitors hooked up and it works regardless of where they are, probably because [NSScreen screens] objectAtIndex:0] is the screen with the main menu and all windows are relative to that?
The content view and the window view have the same rectangle, so that works too, although maybe I ought to change is as you’ve suggested?
Yes, the coordinates are from the Mouse.
All the Best
Dave
> On 21 Apr 2015, at 18:12, Lee Ann Rucker <email@hidden> wrote:
>
> Your screen flipping code is a good start, but it's not going to work with multiple monitors. That's why knowing where it comes from would be helpful - for instance, if it's the current mouse point, there are definitely better ways to do this.
>
> 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"
>
> And if it doesn't find a subview, it will return myContentView so you'll need a check for that. "if (myCocoaControlView == myContentView)" will work fine.
> ________________________________________
> From: cocoa-dev-bounces+lrucker=email@hidden [cocoa-dev-bounces+lrucker=email@hidden] on behalf of Dave [email@hidden]
> Sent: Tuesday, April 21, 2015 9:46 AM
> To: Cocoa Developers
> Subject: Re: Converting to Window Coordinates
>
> Hi Lee Ann,
>
> I was pretty sure the theGlobalPoint is Top, Left relative, but wasn't sure how to convert it, I tried a few things and this seems to work:
>
> myContentView = myPhantomWindow.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 = [myContentView hitTest:myWindowPoint];
> if (myCocoaControlView != nil)
> {
>
> LogIfDave(@"FoundView: %@ ",NSStringFromClass([myCocoaControlView class]));
> }
>
> I don’t want it too report having found the Point in the Content View, what’s the best way to handle this? I could compare the view returned to window.contentView or I could
>
>
>
> Thanks a lot
> Dave
>
>
>> On 21 Apr 2015, at 17:06, Lee Ann Rucker <email@hidden> wrote:
>>
>> How are you getting your global point? There are non-Cocoa parts of the OS that do use top-left instead of bottom-left origins, so those will need converting.
>> ________________________________________
>> From: cocoa-dev-bounces+lrucker=email@hidden [cocoa-dev-bounces+lrucker=email@hidden] on behalf of Dave [email@hidden]
>> Sent: Tuesday, April 21, 2015 8:53 AM
>> To: Cocoa Developers
>> Subject: Converting to Window Coordinates
>>
>> I meant add this:
>>
>> Global: {183.45703125, 92.41015625}
>> Window: {183.45703125, -619.58984375}
>>
>> These are the values I get when I run the code. From looking at Y it looks like I need to flip the Y Coordinate, but I’m not sure where/how to do this?
>>
>> TheY = 92 on the Global Point represents a point near the top of the Screen.
>>
>> Cheers
>> Dave
>>
>>
>> Hi All,
>>
>> I have the following code in a Window Controller.
>>
>> myWorkRect.origin = theGlobalPoint;
>> myWorkRect.size = NSMakeSize(1,1);
>> myWorkRect = [self.window convertRectFromScreen:myWorkRect];
>> myWindowPoint = myWorkRect.origin;
>>
>> myCocoaControlView = [myContentView hitTest: myWindowPoint];
>>
>> I have a Point in Global (Screen) space and I want to check if that point is inside a view of the associated window. I had hoped the code above would do the trick but it seems not.
>>
>> The Global point is within a View in the Window, and when this code gets called hitTest always returned the Frame View (not the deepest View that intersects the point) as the documentation says, just to see what would happen, I overrode hitTest in the Content View and now it returns nil.
>>
>> What am I do doing wrong?
>>
>> Thanks a lot for any help,
>> 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
_______________________________________________
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