summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeenz <geenz@geenzo.com>2013-01-22 15:37:01 -0500
committerGeenz <geenz@geenzo.com>2013-01-22 15:37:01 -0500
commit29e747c4f17818816c502a3aa653b828e689be4a (patch)
tree4bb9ed177ca1d03777560c121173a361b7118e91
parent1bbbaf8dd69a08a3e7c570e6ad14f57a4f6e91cb (diff)
And thus, the demonic mouse position conversions from view space to screen space were tamed.
-rw-r--r--indra/llcommon/llsys.cpp2
-rw-r--r--indra/llwindow/llopenglview-objc.h22
-rw-r--r--indra/llwindow/llopenglview-objc.mm50
-rw-r--r--indra/llwindow/llwindowmacosx-objc.mm2
-rw-r--r--indra/newview/llappviewermacosx.cpp2
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 <sys/sysctl.h>
# include <sys/utsname.h>
# include <stdint.h>
-# include <Carbon/Carbon.h>
+# include <CoreServices/CoreServices.h>
# include <stdexcept>
# include <mach/host_info.h>
# include <mach/mach_host.h>
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 <Carbon/Carbon.h>
+#include <ApplicationServices/ApplicationServices.h>
#include "lldir.h"
#include <signal.h>
#include <CoreAudio/CoreAudio.h> // for systemwide mute