Revision: 23942
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=23942
Author:   damien78
Date:     2009-10-19 12:49:45 +0200 (Mon, 19 Oct 2009)

Log Message:
-----------
Cocoa : 
- fix#19592 : implemented updated continuous grab feature (fixing compilation 
issues)
- fix some 10.6 & 64bit warnings

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

Modified: trunk/blender/intern/ghost/intern/GHOST_SystemCocoa.h
===================================================================
--- trunk/blender/intern/ghost/intern/GHOST_SystemCocoa.h       2009-10-19 
10:37:50 UTC (rev 23941)
+++ trunk/blender/intern/ghost/intern/GHOST_SystemCocoa.h       2009-10-19 
10:49:45 UTC (rev 23942)
@@ -228,34 +228,7 @@
      * @return Indication whether the event was handled. 
      */
     GHOST_TSuccess handleKeyEvent(void *eventPtr);
-
-    /**
-     * Handles all basic Mac application stuff for a mouse down event.
-     * @param eventPtr An NSEvent pointer (casted to void* to enable 
compilation in standard C++)
-     * @return Indication whether the event was handled. 
-     */
-   // bool handleMouseDown(void *eventPtr);
-
-    /**
-     * Handles a Mac menu command.
-     * @param menuResult A Mac menu/item identifier.
-     * @return Indication whether the event was handled. 
-     */
-   // bool handleMenuCommand(GHOST_TInt32 menuResult);
     
-    /* callback for blender generated events */
-//     static OSStatus blendEventHandlerProc(EventHandlerCallRef handler, 
EventRef event, void* userData);
-
-
-    /**
-     * Callback for Mac Timer tasks that expire.
-     * @param tmTask Pointer to the timer task that expired.
-     */
-    //static void s_timerCallback(TMTaskPtr tmTask);
-       
-    /** Event handler reference. */
-    //EventHandlerRef m_handler;
-       
        /** Start time at initialization. */
        GHOST_TUns64 m_start_time;
        
@@ -266,7 +239,12 @@
     GHOST_TUns32 m_modifierMask;
 
     /** Ignores window size messages (when window is dragged). */
-    bool m_ignoreWindowSizedMessages;    
+    bool m_ignoreWindowSizedMessages;   
+       
+       /** Stores the mouse cursor delta due to setting a new cursor position
+        * Needed because cocoa event delta cursor move takes setCursorPosition 
changes too.
+        */
+       GHOST_TInt32 m_cursorDelta_x, m_cursorDelta_y;
 };
 
 #endif // _GHOST_SYSTEM_COCOA_H_

Modified: trunk/blender/intern/ghost/intern/GHOST_SystemCocoa.mm
===================================================================
--- trunk/blender/intern/ghost/intern/GHOST_SystemCocoa.mm      2009-10-19 
10:37:50 UTC (rev 23941)
+++ trunk/blender/intern/ghost/intern/GHOST_SystemCocoa.mm      2009-10-19 
10:49:45 UTC (rev 23942)
@@ -565,6 +565,8 @@
 {
        m_modifierMask =0;
        m_pressedMouseButtons =0;
+       m_cursorDelta_x=0;
+       m_cursorDelta_y=0;
        m_displayManager = new GHOST_DisplayManagerCocoa ();
        GHOST_ASSERT(m_displayManager, "GHOST_SystemCocoa::GHOST_SystemCocoa(): 
m_displayManager==0\n");
        m_displayManager->initialize();
@@ -873,15 +875,6 @@
                 
                 if (timerMgr->fireTimers(getMilliSeconds())) {
                 anyProcessed = true;
-                }
-                
-                        if (getFullScreen()) {
-                // Check if the full-screen window is dirty
-                GHOST_IWindow* window = m_windowManager->getFullScreenWindow();
-                if (((GHOST_WindowCarbon*)window)->getFullScreenDirty()) {
-                pushEvent( new GHOST_Event(getMilliSeconds(), 
GHOST_kEventWindowUpdate, window) );
-                anyProcessed = true;
-                }
                 }*/
                
                do {
@@ -999,6 +992,12 @@
 
 GHOST_TUns8 GHOST_SystemCocoa::handleQuitRequest()
 {
+       GHOST_Window* window = 
(GHOST_Window*)m_windowManager->getActiveWindow();
+       
+       //Discard quit event if we are in cursor grab sequence
+       if ((window->getCursorGrabMode() != GHOST_kGrabDisable) && 
(window->getCursorGrabMode() != GHOST_kGrabNormal))
+               return GHOST_kExitCancel;
+       
        //Check open windows if some changes are not saved
        if (m_windowManager->getAnyModifiedState())
        {
@@ -1129,27 +1128,78 @@
                                        //No tablet event included : do nothing
                                        break;
                        }
+                       
                case NSMouseMoved:
-                       {
-                               if(window->getCursorWarp()) {
-                                       GHOST_TInt32 x_warp, y_warp, x_accum, 
y_accum;
-                                       
-                                       window->getCursorWarpPos(x_warp, 
y_warp);
-                                       
-                                       window->getCursorWarpAccum(x_accum, 
y_accum);
-                                       x_accum += [event deltaX];
-                                       y_accum += -[event deltaY]; //Strange 
Apple implementation (inverted coordinates for the deltaY) ...
-                                       window->setCursorWarpAccum(x_accum, 
y_accum);
-                                       
-                                       pushEvent(new GHOST_EventCursor([event 
timestamp], GHOST_kEventCursorMove, window, x_warp+x_accum, y_warp+y_accum));
-                               } 
-                               else { //Normal cursor operation: send mouse 
position in window
-                                       NSPoint mousePos = [event 
locationInWindow];
-                                       pushEvent(new GHOST_EventCursor([event 
timestamp], GHOST_kEventCursorMove, window, mousePos.x, mousePos.y));
-                                       window->setCursorWarpAccum(0, 0); 
//Mouse motion occured between two cursor warps, so we can reset the delta 
counter
+                               switch (window->getCursorGrabMode()) {
+                                       case GHOST_kGrabHide: //Cursor hidden 
grab operation : no cursor move
+                                       {
+                                               GHOST_TInt32 x_warp, y_warp, 
x_accum, y_accum;
+                                               
+                                               
window->getCursorGrabInitPos(x_warp, y_warp);
+                                               
+                                               
window->getCursorGrabAccum(x_accum, y_accum);
+                                               x_accum += [event deltaX];
+                                               y_accum += -[event deltaY]; 
//Strange Apple implementation (inverted coordinates for the deltaY) ...
+                                               
window->setCursorGrabAccum(x_accum, y_accum);
+                                               
+                                               pushEvent(new 
GHOST_EventCursor([event timestamp], GHOST_kEventCursorMove, window, 
x_warp+x_accum, y_warp+y_accum));
+                                       }
+                                               break;
+                                       case GHOST_kGrabWrap: //Wrap cursor at 
area/window boundaries
+                                       {
+                                               NSPoint mousePos = [event 
locationInWindow];
+                                               GHOST_TInt32 x_mouse= 
mousePos.x;
+                                               GHOST_TInt32 y_mouse= 
mousePos.y;
+                                               GHOST_TInt32 x_accum, y_accum, 
x_cur, y_cur;
+                                               GHOST_Rect bounds, 
windowBounds, correctedBounds;
+                                               
+                                               /* fallback to window bounds */
+                                               
if(window->getCursorGrabBounds(bounds)==GHOST_kFailure)
+                                                       
window->getClientBounds(bounds);
+                                               
+                                               //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);
+                                               
+                                               //Update accumulation counts
+                                               
window->getCursorGrabAccum(x_accum, y_accum);
+                                               x_accum += [event 
deltaX]-m_cursorDelta_x;
+                                               y_accum += -[event 
deltaY]-m_cursorDelta_y; //Strange Apple implementation (inverted coordinates 
for the deltaY) ...
+                                               
window->setCursorGrabAccum(x_accum, y_accum);
+                                               
+                                               
+                                               //Warp mouse cursor if needed
+                                               x_mouse += [event 
deltaX]-m_cursorDelta_x;
+                                               y_mouse += -[event 
deltaY]-m_cursorDelta_y;
+                                               
correctedBounds.wrapPoint(x_mouse, y_mouse, 2);
+                                               
+                                               //Compensate for mouse moved 
event taking cursor position set into account
+                                               m_cursorDelta_x = 
x_mouse-mousePos.x;
+                                               m_cursorDelta_y = 
y_mouse-mousePos.y;
+                                               
+                                               //Set new cursor position
+                                               window->clientToScreen(x_mouse, 
y_mouse, x_cur, y_cur);
+                                               setCursorPosition(x_cur, 
y_cur); /* wrap */
+                                               
+                                               //Post event
+                                               
window->getCursorGrabInitPos(x_cur, y_cur);
+                                               pushEvent(new 
GHOST_EventCursor([event timestamp], GHOST_kEventCursorMove, window, x_cur + 
x_accum, y_cur + y_accum));
+                                       }
+                                               break;
+                                       default:
+                                       {
+                                               //Normal cursor operation: send 
mouse position in window
+                                               NSPoint mousePos = [event 
locationInWindow];
+                                               pushEvent(new 
GHOST_EventCursor([event timestamp], GHOST_kEventCursorMove, window, 
mousePos.x, mousePos.y));
+                                               m_cursorDelta_x=0;
+                                               m_cursorDelta_y=0; //Mouse 
motion occured between two cursor warps, so we can reset the delta counter
+                                       }
+                                               break;
                                }
                                break;
-                       }
                        
                case NSScrollWheel:
                        {
@@ -1323,74 +1373,3 @@
        
        [pool drain];
 }
-
-#pragma mark Carbon stuff to remove
-
-#ifdef WITH_CARBON
-
-
-OSErr GHOST_SystemCarbon::sAEHandlerLaunch(const AppleEvent *event, AppleEvent 
*reply, SInt32 refCon)
-{
-       //GHOST_SystemCarbon* sys = (GHOST_SystemCarbon*) refCon;
-       
-       return noErr;
-}
-
-OSErr GHOST_SystemCarbon::sAEHandlerOpenDocs(const AppleEvent *event, 
AppleEvent *reply, SInt32 refCon)
-{
-       //GHOST_SystemCarbon* sys = (GHOST_SystemCarbon*) refCon;
-       AEDescList docs;
-       SInt32 ndocs;
-       OSErr err;
-       
-       err = AEGetParamDesc(event, keyDirectObject, typeAEList, &docs);
-       if (err != noErr)  return err;
-       
-       err = AECountItems(&docs, &ndocs);
-       if (err==noErr) {
-               int i;
-               
-               for (i=0; i<ndocs; i++) {
-                       FSSpec fss;
-                       AEKeyword kwd;
-                       DescType actType;
-                       Size actSize;
-                       
-                       err = AEGetNthPtr(&docs, i+1, typeFSS, &kwd, &actType, 
&fss, sizeof(fss), &actSize);
-                       if (err!=noErr)
-                               break;
-                       
-                       if (i==0) {
-                               FSRef fsref;
-                               
-                               if (FSpMakeFSRef(&fss, &fsref)!=noErr)
-                                       break;
-                               if (FSRefMakePath(&fsref, (UInt8*) 
g_firstFileBuf, sizeof(g_firstFileBuf))!=noErr)
-                                       break;
-                               
-                               g_hasFirstFile = true;
-                       }
-               }
-       }
-       
-       AEDisposeDesc(&docs);
-       
-       return err;
-}
-
-OSErr GHOST_SystemCarbon::sAEHandlerPrintDocs(const AppleEvent *event, 
AppleEvent *reply, SInt32 refCon)
-{
-       //GHOST_SystemCarbon* sys = (GHOST_SystemCarbon*) refCon;
-       
-       return noErr;
-}
-
-OSErr GHOST_SystemCarbon::sAEHandlerQuit(const AppleEvent *event, AppleEvent 
*reply, SInt32 refCon)
-{
-       GHOST_SystemCarbon* sys = (GHOST_SystemCarbon*) refCon;
-       
-       sys->pushEvent( new GHOST_Event(sys->getMilliSeconds(), 
GHOST_kEventQuit, NULL) );
-       
-       return noErr;
-}
-#endif
\ No newline at end of file

Modified: trunk/blender/intern/ghost/intern/GHOST_Window.h
===================================================================
--- trunk/blender/intern/ghost/intern/GHOST_Window.h    2009-10-19 10:37:50 UTC 
(rev 23941)
+++ trunk/blender/intern/ghost/intern/GHOST_Window.h    2009-10-19 10:49:45 UTC 
(rev 23942)
@@ -159,6 +159,7 @@
         */
        inline virtual bool getCursorVisibility() const;
        inline virtual GHOST_TGrabCursorMode getCursorGrabMode() const;
+       inline virtual void getCursorGrabInitPos(GHOST_TInt32 &x, GHOST_TInt32 
&y) const;
        inline virtual void getCursorGrabAccum(GHOST_TInt32 &x, GHOST_TInt32 
&y) const;
        inline virtual void setCursorGrabAccum(GHOST_TInt32 x, GHOST_TInt32 y);
 
@@ -327,6 +328,12 @@
        return m_cursorGrab;
 }
 
+inline void GHOST_Window::getCursorGrabInitPos(GHOST_TInt32 &x, GHOST_TInt32 
&y) const
+{
+       x = m_cursorGrabInitPos[0];
+       y = m_cursorGrabInitPos[1];
+}
+
 inline void GHOST_Window::getCursorGrabAccum(GHOST_TInt32 &x, GHOST_TInt32 &y) 
const
 {
        x= m_cursorGrabAccumPos[0];

Modified: trunk/blender/intern/ghost/intern/GHOST_WindowCocoa.h

@@ Diff output truncated at 10240 characters. @@

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

Reply via email to