Cocoa / Mac:
authorDamien Plisson <damien.plisson@yahoo.fr>
Wed, 21 Oct 2009 15:39:32 +0000 (15:39 +0000)
committerDamien Plisson <damien.plisson@yahoo.fr>
Wed, 21 Oct 2009 15:39:32 +0000 (15:39 +0000)
- fix set mouse cursor position in case of multi-display setting. Enables continuous grab to work when blender window is on a secondary display

intern/ghost/intern/GHOST_SystemCocoa.mm
intern/ghost/intern/GHOST_WindowCocoa.h
intern/ghost/intern/GHOST_WindowCocoa.mm

index 3b2c5ea76a37061d16d47865106681b997ca645e..2d665012bf1fa868f76200a6bb573b4f43606716 100644 (file)
@@ -797,7 +797,9 @@ GHOST_TSuccess GHOST_SystemCocoa::endFullScreen(void)
 
 
        
-
+/**
+ * @note : returns coordinates in Cocoa screen coordinates
+ */
 GHOST_TSuccess GHOST_SystemCocoa::getCursorPosition(GHOST_TInt32& x, GHOST_TInt32& y) const
 {
     NSPoint mouseLoc = [NSEvent mouseLocation];
@@ -808,17 +810,24 @@ GHOST_TSuccess GHOST_SystemCocoa::getCursorPosition(GHOST_TInt32& x, GHOST_TInt3
     return GHOST_kSuccess;
 }
 
-
+/**
+ * @note : expect Cocoa screen coordinates
+ */
 GHOST_TSuccess GHOST_SystemCocoa::setCursorPosition(GHOST_TInt32 x, GHOST_TInt32 y) const
 {
        float xf=(float)x, yf=(float)y;
+       GHOST_WindowCocoa* window = (GHOST_WindowCocoa*)m_windowManager->getActiveWindow();
+       NSScreen *windowScreen = window->getScreen();
+       NSRect screenRect = [windowScreen frame];
        
-       //Quartz Display Services uses the old coordinates (top left origin)
-       yf = [[NSScreen mainScreen] frame].size.height -yf;
+       //Set position relative to current screen
+       xf -= screenRect.origin.x;
+       yf -= screenRect.origin.y;
        
-       //CGAssociateMouseAndMouseCursorPosition(false);
-       CGWarpMouseCursorPosition(CGPointMake(xf, yf));
-       //CGAssociateMouseAndMouseCursorPosition(true);
+       //Quartz Display Services uses the old coordinates (top left origin)
+       yf = screenRect.size.height -yf;
+
+       CGDisplayMoveCursorToPoint([[[windowScreen deviceDescription] objectForKey:@"NSScreenNumber"] unsignedIntValue], CGPointMake(xf, yf));
 
     return GHOST_kSuccess;
 }
@@ -1174,10 +1183,10 @@ GHOST_TSuccess GHOST_SystemCocoa::handleMouseEvent(void *eventPtr)
                                                
                                                //Switch back to Cocoa coordinates orientation (y=0 at botton,the same as blender internal btw!), and to client coordinates
                                                window->getClientBounds(windowBounds);
-                                               bounds.m_b = (windowBounds.m_b - windowBounds.m_t) - bounds.m_b;
-                                               bounds.m_t = (windowBounds.m_b - windowBounds.m_t) - bounds.m_t;
                                                window->screenToClient(bounds.m_l,bounds.m_b, correctedBounds.m_l, correctedBounds.m_t);
                                                window->screenToClient(bounds.m_r, bounds.m_t, correctedBounds.m_r, correctedBounds.m_b);
+                                               correctedBounds.m_b = (windowBounds.m_b - windowBounds.m_t) - correctedBounds.m_b;
+                                               correctedBounds.m_t = (windowBounds.m_b - windowBounds.m_t) - correctedBounds.m_t;
                                                
                                                //Update accumulation counts
                                                window->getCursorGrabAccum(x_accum, y_accum);
index 5368d0f1e13c8ee31d9616d9717b2a5059642c5b..e3479ada5d69f8c4829e12b09668fa588f66ec2b 100644 (file)
@@ -169,6 +169,12 @@ public:
         */
        virtual void clientToScreen(GHOST_TInt32 inX, GHOST_TInt32 inY, GHOST_TInt32& outX, GHOST_TInt32& outY) const;
 
+       /**
+        * Gets the screen the window is displayed in
+        * @return The NSScreen object
+        */
+       NSScreen* getScreen();
+       
        /**
         * Sets the state of the window (normal, minimized, maximized).
         * @param state The state of the window.
index b9a598cb2653e87829479848b493a3a85c83caa7..0090d8e10385a219fa3c360516c39007ebc46abf 100644 (file)
@@ -515,6 +515,13 @@ void GHOST_WindowCocoa::clientToScreen(GHOST_TInt32 inX, GHOST_TInt32 inY, GHOST
        outY = screenCoord.y;
 }
 
+
+NSScreen* GHOST_WindowCocoa::getScreen()
+{
+       return [m_window screen];
+}
+
+
 /**
  * @note Fullscreen switch is not actual fullscreen with display capture. As this capture removes all OS X window manager features.
  * Instead, the menu bar and the dock are hidden, and the window is made borderless and enlarged.