Procházet zdrojové kódy

Merge pull request #1289 from kwhatmough/next

Fix mouse capture on Mac for while buttons are down. This fixes Pan and ...
Sean Taylor před 12 roky
rodič
revize
426fd9d487
1 změnil soubory, kde provedl 41 přidání a 13 odebrání
  1. 41 13
      gameplay/src/PlatformMacOSX.mm

+ 41 - 13
gameplay/src/PlatformMacOSX.mm

@@ -1000,11 +1000,9 @@ static CVReturn MyDisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTime
 
 }
 
-- (void)mouseMoved:(NSEvent*) event 
+// helper function to handle mouse capture
+bool getMousePointForEvent(NSPoint& point, NSEvent* event)
 {
-    NSPoint point = [self convertPoint:[event locationInWindow] fromView:nil];
-    
-    float y;
     if (__mouseCaptured)
     {
         if (__mouseCapturedFirstPass)
@@ -1012,36 +1010,61 @@ static CVReturn MyDisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTime
             // Discard the first mouseMoved event following transition into capture
             // since it contains bogus x,y data.
             __mouseCapturedFirstPass = false;
-            return;
+            return false;
         }
-
+        
         point.x = [event deltaX];
         point.y = [event deltaY];
-
+        
         NSWindow* window = __view.window;
         NSRect rect = window.frame;
         CGPoint centerPoint;
         centerPoint.x = rect.origin.x + (rect.size.width / 2);
         centerPoint.y = rect.origin.y + (rect.size.height / 2);
         CGDisplayMoveCursorToPoint(CGDisplayPrimaryDisplay(NULL), centerPoint);
-        y = point.y;
     }
     else
     {
-        y = __height - point.y;
+        point.y = __height - point.y;
     }
+
+    return true;
+}
+
+- (void)mouseMoved:(NSEvent*) event
+{
+    NSPoint point = [self convertPoint:[event locationInWindow] fromView:nil];
     
+    if (!getMousePointForEvent(point, event))
+    {
+        return;
+    }
+
     [__view->gameLock lock];
-    gameplay::Platform::mouseEventInternal(Mouse::MOUSE_MOVE, point.x, y, 0);
+    gameplay::Platform::mouseEventInternal(Mouse::MOUSE_MOVE, point.x, point.y, 0);
     [__view->gameLock unlock];
 }
 
 - (void) mouseDragged: (NSEvent*) event
 {
     NSPoint point = [self convertPoint:[event locationInWindow] fromView:nil];
-    if (__leftMouseDown && !__mouseCaptured)
+    if (__leftMouseDown)
     {
-        [self mouse: Mouse::MOUSE_MOVE orTouchEvent: Touch::TOUCH_MOVE x: point.x y: __height - point.y s: 0];
+        if (__mouseCaptured)
+        {
+            if (!getMousePointForEvent(point, event))
+            {
+                return;
+            }
+            
+            [__view->gameLock lock];
+            gameplay::Platform::mouseEventInternal(Mouse::MOUSE_MOVE, point.x, point.y, 0);
+            [__view->gameLock unlock];
+        }
+        else
+        {
+            [self mouse: Mouse::MOUSE_MOVE orTouchEvent: Touch::TOUCH_MOVE x: point.x y: __height - point.y s: 0];
+        }
     }
 }
 
@@ -1069,10 +1092,15 @@ static CVReturn MyDisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTime
 {
     NSPoint point = [self convertPoint:[event locationInWindow] fromView:nil];
     
+    if (!getMousePointForEvent(point, event))
+    {
+        return;
+    }
+    
     // In right-mouse case, whether __rightMouseDown is true or false
     // this should not matter, mouse move is still occuring
     [__view->gameLock lock];
-    gameplay::Platform::mouseEventInternal(Mouse::MOUSE_MOVE, point.x, __height - point.y, 0);
+    gameplay::Platform::mouseEventInternal(Mouse::MOUSE_MOVE, point.x, point.y, 0);
     [__view->gameLock unlock];
 }