Reputation: 5354
What is the difference between these three methods of getting mouse coordinates:
[NSWindow convertBaseToScreen]
[NSEvent* locationInWindow]
[NSWindow mouseLocationOutsideOfEventStream]
I already checked the documentation, but the descriptions were too technical. Could someone explain the difference between these three in simpler terms?
Upvotes: 3
Views: 1680
Reputation: 237110
Every window and every view has its own coordinate system, which (unless you've modified it) starts at (0, 0) in the bottom-left and counts up and to the right. -[NSEvent locationInWindow]
gives you the location where the event took place the window's coordinate system (that is, (0, 0) is the bottom-left of the window). -[NSWindow convertBaseToScreen:]
takes a coordinate in the window's coordinate system and converts it to screen coordinates, so that (0, 0) now means the bottom-left of the whole screen.
-[NSWindow mouseLocationOutsideOfEventStream]
gives you the location (in the coordinate system of the window you send it to) where the mouse is right now, unrelated to any event. This is rarely useful information.
Upvotes: 6