From 29e747c4f17818816c502a3aa653b828e689be4a Mon Sep 17 00:00:00 2001 From: Geenz Date: Tue, 22 Jan 2013 15:37:01 -0500 Subject: And thus, the demonic mouse position conversions from view space to screen space were tamed. --- indra/llcommon/llsys.cpp | 2 +- indra/llwindow/llopenglview-objc.h | 22 +++++++++++++++ indra/llwindow/llopenglview-objc.mm | 50 +++++++++++++++++++++++++++++++++++ indra/llwindow/llwindowmacosx-objc.mm | 2 +- indra/newview/llappviewermacosx.cpp | 2 +- 5 files changed, 75 insertions(+), 3 deletions(-) diff --git a/indra/llcommon/llsys.cpp b/indra/llcommon/llsys.cpp index c96f2191f3..2a8eea88b6 100644 --- a/indra/llcommon/llsys.cpp +++ b/indra/llcommon/llsys.cpp @@ -67,7 +67,7 @@ using namespace llsd; # include # include # include -# include +# include # include # include # include diff --git a/indra/llwindow/llopenglview-objc.h b/indra/llwindow/llopenglview-objc.h index 8412621392..dd2f35aafc 100644 --- a/indra/llwindow/llopenglview-objc.h +++ b/indra/llwindow/llopenglview-objc.h @@ -39,4 +39,26 @@ unsigned int mModifiers; } +- (NSPoint)convertToScreenFromLocalPoint:(NSPoint)point relativeToView:(NSView *)view; +- (NSPoint)flipPoint:(NSPoint)aPoint; + +@end + +@interface NSScreen (PointConversion) + +/* + Returns the screen where the mouse resides + */ ++ (NSScreen *)currentScreenForMouseLocation; + +/* + Allows you to convert a point from global coordinates to the current screen coordinates. + */ +- (NSPoint)convertPointToScreenCoordinates:(NSPoint)aPoint; + +/* + Allows to flip the point coordinates, so y is 0 at the top instead of the bottom. x remains the same + */ +- (NSPoint)flipPoint:(NSPoint)aPoint; + @end diff --git a/indra/llwindow/llopenglview-objc.mm b/indra/llwindow/llopenglview-objc.mm index 25669b25d3..ca66143b78 100644 --- a/indra/llwindow/llopenglview-objc.mm +++ b/indra/llwindow/llopenglview-objc.mm @@ -8,6 +8,35 @@ #import "llopenglview-objc.h" +@implementation NSScreen (PointConversion) + ++ (NSScreen *)currentScreenForMouseLocation +{ + NSPoint mouseLocation = [NSEvent mouseLocation]; + + NSEnumerator *screenEnumerator = [[NSScreen screens] objectEnumerator]; + NSScreen *screen; + while ((screen = [screenEnumerator nextObject]) && !NSMouseInRect(mouseLocation, screen.frame, NO)) + ; + + return screen; +} + +- (NSPoint)convertPointToScreenCoordinates:(NSPoint)aPoint +{ + float normalizedX = fabs(fabs(self.frame.origin.x) - fabs(aPoint.x)); + float normalizedY = aPoint.y - self.frame.origin.y; + + return NSMakePoint(normalizedX, normalizedY); +} + +- (NSPoint)flipPoint:(NSPoint)aPoint +{ + return NSMakePoint(aPoint.x, self.frame.size.height - aPoint.y); +} + +@end + @implementation LLOpenGLView - (void)viewDidMoveToWindow @@ -349,6 +378,27 @@ callMouseExit(); } +- (NSPoint)convertToScreenFromLocalPoint:(NSPoint)point relativeToView:(NSView *)view +{ + NSScreen *currentScreen = [NSScreen currentScreenForMouseLocation]; + if(currentScreen) + { + NSPoint windowPoint = [view convertPoint:point toView:nil]; + NSPoint screenPoint = [[view window] convertBaseToScreen:windowPoint]; + NSPoint flippedScreenPoint = [currentScreen flipPoint:screenPoint]; + flippedScreenPoint.y += [currentScreen frame].origin.y; + + return flippedScreenPoint; + } + + return NSZeroPoint; +} + +- (NSPoint)flipPoint:(NSPoint)aPoint +{ + return NSMakePoint(aPoint.x, self.frame.size.height - aPoint.y); +} + - (BOOL) becomeFirstResponder { NSLog(@"Window gained focus!"); diff --git a/indra/llwindow/llwindowmacosx-objc.mm b/indra/llwindow/llwindowmacosx-objc.mm index 1a64c94b2d..b6e5767203 100644 --- a/indra/llwindow/llwindowmacosx-objc.mm +++ b/indra/llwindow/llwindowmacosx-objc.mm @@ -298,7 +298,7 @@ void convertWindowToScreen(NSWindowRef window, float *coord) NSPoint point; point.x = coord[0]; point.y = coord[1]; - point = [(LLNSWindow*)window convertBaseToScreen:point]; + point = [(LLNSWindow*)window convertToScreenFromLocalPoint:point relativeToView:[(LLNSWindow*)window contentView]]; coord[0] = point.x; coord[1] = point.y; } diff --git a/indra/newview/llappviewermacosx.cpp b/indra/newview/llappviewermacosx.cpp index b199405a66..6e0becb518 100644 --- a/indra/newview/llappviewermacosx.cpp +++ b/indra/newview/llappviewermacosx.cpp @@ -41,7 +41,7 @@ #include "llmd5.h" #include "llfloaterworldmap.h" #include "llurldispatcher.h" -#include +#include #include "lldir.h" #include #include // for systemwide mute -- cgit v1.2.3