mirror of
https://github.com/Relintai/sdl2_frt.git
synced 2025-02-17 20:34:28 +01:00
Cocoa mouse code: Replaced NSPointInRect with NSMouseInRect (thanks Eric Wasylishen!) Fixes bug #3312.
This commit is contained in:
parent
d383502657
commit
b15efce277
@ -316,7 +316,7 @@ Cocoa_GetGlobalMouseState(int *x, int *y)
|
|||||||
|
|
||||||
for (NSScreen *screen in [NSScreen screens]) {
|
for (NSScreen *screen in [NSScreen screens]) {
|
||||||
NSRect frame = [screen frame];
|
NSRect frame = [screen frame];
|
||||||
if (NSPointInRect(cocoaLocation, frame)) {
|
if (NSMouseInRect(cocoaLocation, frame, NO)) {
|
||||||
*x = (int) cocoaLocation.x;
|
*x = (int) cocoaLocation.x;
|
||||||
*y = (int) ((frame.origin.y + frame.size.height) - cocoaLocation.y);
|
*y = (int) ((frame.origin.y + frame.size.height) - cocoaLocation.y);
|
||||||
break;
|
break;
|
||||||
@ -398,7 +398,7 @@ Cocoa_HandleMouseEvent(_THIS, NSEvent *event)
|
|||||||
/* Ignore events that aren't inside the client area (i.e. title bar.) */
|
/* Ignore events that aren't inside the client area (i.e. title bar.) */
|
||||||
if ([event window]) {
|
if ([event window]) {
|
||||||
NSRect windowRect = [[[event window] contentView] frame];
|
NSRect windowRect = [[[event window] contentView] frame];
|
||||||
if (!NSPointInRect([event locationInWindow], windowRect)) {
|
if (!NSMouseInRect([event locationInWindow], windowRect, NO)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -96,7 +96,7 @@ Cocoa_MouseTapCallback(CGEventTapProxy proxy, CGEventType type, CGEventRef event
|
|||||||
eventLocation = CGEventGetUnflippedLocation(event);
|
eventLocation = CGEventGetUnflippedLocation(event);
|
||||||
windowRect = [nswindow contentRectForFrameRect:[nswindow frame]];
|
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
|
/* This is in CGs global screenspace coordinate system, which has a
|
||||||
* flipped Y.
|
* flipped Y.
|
||||||
@ -109,10 +109,10 @@ Cocoa_MouseTapCallback(CGEventTapProxy proxy, CGEventType type, CGEventRef event
|
|||||||
newLocation.x = NSMaxX(windowRect) - 1.0;
|
newLocation.x = NSMaxX(windowRect) - 1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (eventLocation.y < NSMinY(windowRect)) {
|
if (eventLocation.y <= NSMinY(windowRect)) {
|
||||||
newLocation.y -= (NSMinY(windowRect) - eventLocation.y + 1);
|
newLocation.y -= (NSMinY(windowRect) - eventLocation.y + 1);
|
||||||
} else if (eventLocation.y >= NSMaxY(windowRect)) {
|
} else if (eventLocation.y > NSMaxY(windowRect)) {
|
||||||
newLocation.y += (eventLocation.y - NSMaxY(windowRect) + 1);
|
newLocation.y += (eventLocation.y - NSMaxY(windowRect));
|
||||||
}
|
}
|
||||||
|
|
||||||
CGWarpMouseCursorPosition(newLocation);
|
CGWarpMouseCursorPosition(newLocation);
|
||||||
|
@ -839,14 +839,7 @@ SetWindowStyle(SDL_Window * window, unsigned int style)
|
|||||||
/* Ignore events that aren't inside the client area (i.e. title bar.) */
|
/* Ignore events that aren't inside the client area (i.e. title bar.) */
|
||||||
if ([theEvent window]) {
|
if ([theEvent window]) {
|
||||||
NSRect windowRect = [[[theEvent window] contentView] frame];
|
NSRect windowRect = [[[theEvent window] contentView] frame];
|
||||||
|
if (!NSMouseInRect([theEvent locationInWindow], windowRect, NO)) {
|
||||||
/* 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)) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user