From b15efce277bc8b643f869e8b393ff035b64ddfd9 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Sun, 1 May 2016 21:41:30 -0300 Subject: [PATCH] Cocoa mouse code: Replaced NSPointInRect with NSMouseInRect (thanks Eric Wasylishen!) Fixes bug #3312. --- src/video/cocoa/SDL_cocoamouse.m | 4 ++-- src/video/cocoa/SDL_cocoamousetap.m | 8 ++++---- src/video/cocoa/SDL_cocoawindow.m | 9 +-------- 3 files changed, 7 insertions(+), 14 deletions(-) diff --git a/src/video/cocoa/SDL_cocoamouse.m b/src/video/cocoa/SDL_cocoamouse.m index 82bdc48b37221..aa753fc121af6 100644 --- a/src/video/cocoa/SDL_cocoamouse.m +++ b/src/video/cocoa/SDL_cocoamouse.m @@ -316,7 +316,7 @@ + (NSCursor *)invisibleCursor for (NSScreen *screen in [NSScreen screens]) { NSRect frame = [screen frame]; - if (NSPointInRect(cocoaLocation, frame)) { + if (NSMouseInRect(cocoaLocation, frame, NO)) { *x = (int) cocoaLocation.x; *y = (int) ((frame.origin.y + frame.size.height) - cocoaLocation.y); break; @@ -398,7 +398,7 @@ + (NSCursor *)invisibleCursor /* Ignore events that aren't inside the client area (i.e. title bar.) */ if ([event window]) { NSRect windowRect = [[[event window] contentView] frame]; - if (!NSPointInRect([event locationInWindow], windowRect)) { + if (!NSMouseInRect([event locationInWindow], windowRect, NO)) { return; } } diff --git a/src/video/cocoa/SDL_cocoamousetap.m b/src/video/cocoa/SDL_cocoamousetap.m index f1bd0e8d2d5b8..2075e2c0fe9cb 100644 --- a/src/video/cocoa/SDL_cocoamousetap.m +++ b/src/video/cocoa/SDL_cocoamousetap.m @@ -96,7 +96,7 @@ eventLocation = CGEventGetUnflippedLocation(event); windowRect = [nswindow contentRectForFrameRect:[nswindow frame]]; - if (!NSPointInRect(NSPointFromCGPoint(eventLocation), windowRect)) { + if (!NSMouseInRect(NSPointFromCGPoint(eventLocation), windowRect, NO)) { /* This is in CGs global screenspace coordinate system, which has a * flipped Y. @@ -109,10 +109,10 @@ newLocation.x = NSMaxX(windowRect) - 1.0; } - if (eventLocation.y < NSMinY(windowRect)) { + if (eventLocation.y <= NSMinY(windowRect)) { newLocation.y -= (NSMinY(windowRect) - eventLocation.y + 1); - } else if (eventLocation.y >= NSMaxY(windowRect)) { - newLocation.y += (eventLocation.y - NSMaxY(windowRect) + 1); + } else if (eventLocation.y > NSMaxY(windowRect)) { + newLocation.y += (eventLocation.y - NSMaxY(windowRect)); } CGWarpMouseCursorPosition(newLocation); diff --git a/src/video/cocoa/SDL_cocoawindow.m b/src/video/cocoa/SDL_cocoawindow.m index 0c89a46594236..4435d8dd0193c 100644 --- a/src/video/cocoa/SDL_cocoawindow.m +++ b/src/video/cocoa/SDL_cocoawindow.m @@ -839,14 +839,7 @@ - (void)mouseDown:(NSEvent *)theEvent /* Ignore events that aren't inside the client area (i.e. title bar.) */ if ([theEvent window]) { NSRect windowRect = [[[theEvent window] contentView] frame]; - - /* add one to size, since NSPointInRect is exclusive of the bottom - edges, which mean it misses the top of the window by one pixel - (as the origin is the bottom left). */ - windowRect.size.width += 1; - windowRect.size.height += 1; - - if (!NSPointInRect([theEvent locationInWindow], windowRect)) { + if (!NSMouseInRect([theEvent locationInWindow], windowRect, NO)) { return; } }