Revision: 24040
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=24040
Author:   damien78
Date:     2009-10-21 17:39:32 +0200 (Wed, 21 Oct 2009)

Log Message:
-----------
Cocoa / Mac:
- fix set mouse cursor position in case of multi-display setting. Enables 
continuous grab to work when blender window is on a secondary display

Modified Paths:
--------------
    trunk/blender/intern/ghost/intern/GHOST_SystemCocoa.mm
    trunk/blender/intern/ghost/intern/GHOST_WindowCocoa.h
    trunk/blender/intern/ghost/intern/GHOST_WindowCocoa.mm

Modified: trunk/blender/intern/ghost/intern/GHOST_SystemCocoa.mm
===================================================================
--- trunk/blender/intern/ghost/intern/GHOST_SystemCocoa.mm      2009-10-21 
14:33:52 UTC (rev 24039)
+++ trunk/blender/intern/ghost/intern/GHOST_SystemCocoa.mm      2009-10-21 
15:39:32 UTC (rev 24040)
@@ -797,7 +797,9 @@
 
 
        
-
+/**
+ * @note : returns coordinates in Cocoa screen coordinates
+ */
 GHOST_TSuccess GHOST_SystemCocoa::getCursorPosition(GHOST_TInt32& x, 
GHOST_TInt32& y) const
 {
     NSPoint mouseLoc = [NSEvent mouseLocation];
@@ -808,18 +810,25 @@
     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];
        
+       //Set position relative to current screen
+       xf -= screenRect.origin.x;
+       yf -= screenRect.origin.y;
+       
        //Quartz Display Services uses the old coordinates (top left origin)
-       yf = [[NSScreen mainScreen] frame].size.height -yf;
-       
-       //CGAssociateMouseAndMouseCursorPosition(false);
-       CGWarpMouseCursorPosition(CGPointMake(xf, yf));
-       //CGAssociateMouseAndMouseCursorPosition(true);
+       yf = screenRect.size.height -yf;
 
+       CGDisplayMoveCursorToPoint([[[windowScreen deviceDescription] 
objectForKey:@"NSScreenNumber"] unsignedIntValue], CGPointMake(xf, yf));
+
     return GHOST_kSuccess;
 }
 
@@ -1174,10 +1183,10 @@
                                                
                                                //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);

Modified: trunk/blender/intern/ghost/intern/GHOST_WindowCocoa.h
===================================================================
--- trunk/blender/intern/ghost/intern/GHOST_WindowCocoa.h       2009-10-21 
14:33:52 UTC (rev 24039)
+++ trunk/blender/intern/ghost/intern/GHOST_WindowCocoa.h       2009-10-21 
15:39:32 UTC (rev 24040)
@@ -170,6 +170,12 @@
        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.
         * @return Indication of success.

Modified: trunk/blender/intern/ghost/intern/GHOST_WindowCocoa.mm
===================================================================
--- trunk/blender/intern/ghost/intern/GHOST_WindowCocoa.mm      2009-10-21 
14:33:52 UTC (rev 24039)
+++ trunk/blender/intern/ghost/intern/GHOST_WindowCocoa.mm      2009-10-21 
15:39:32 UTC (rev 24040)
@@ -515,6 +515,13 @@
        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.


_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to