code cleanup: add getCursorGrabModeIsWarp(), makes the intent more clear where we...
authorCampbell Barton <ideasman42@gmail.com>
Sun, 6 May 2012 15:59:57 +0000 (15:59 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Sun, 6 May 2012 15:59:57 +0000 (15:59 +0000)
intern/ghost/intern/GHOST_SystemCocoa.mm
intern/ghost/intern/GHOST_SystemWin32.cpp
intern/ghost/intern/GHOST_SystemX11.cpp
intern/ghost/intern/GHOST_Window.h

index 898171b..77d9e39 100644 (file)
@@ -1280,7 +1280,7 @@ 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 && (window->getCursorGrabMode() != GHOST_kGrabDisable) && (window->getCursorGrabMode() != GHOST_kGrabNormal))
+       if (window && window->getCursorGrabModeIsWarp())
                return GHOST_kExitCancel;
        
        //Check open windows if some changes are not saved
@@ -1329,7 +1329,7 @@ bool GHOST_SystemCocoa::handleOpenDocumentRequest(void *filepathStr)
        }       
        
        //Discard event if we are in cursor grab sequence, it'll lead to "stuck cursor" situation if the alert panel is raised
-       if (window && (window->getCursorGrabMode() != GHOST_kGrabDisable) && (window->getCursorGrabMode() != GHOST_kGrabNormal))
+       if (window && window->getCursorGrabModeIsWarp())
                return GHOST_kExitCancel;
 
        //Check open windows if some changes are not saved
@@ -1493,10 +1493,7 @@ GHOST_TSuccess GHOST_SystemCocoa::handleMouseEvent(void *eventPtr)
                                /* TODO: CHECK IF THIS IS A TABLET EVENT */
                                bool is_tablet = false;
 
-                               if (is_tablet &&
-                                   (grab_mode != GHOST_kGrabDisable) &&
-                                   (grab_mode != GHOST_kGrabNormal))
-                               {
+                               if (is_tablet && window->getCursorGrabModeIsWarp()) {
                                        grab_mode = GHOST_kGrabDisable;
                                }
 
index b00ff69..9f2728a 100644 (file)
@@ -652,10 +652,7 @@ GHOST_EventCursor* GHOST_SystemWin32::processCursorEvent(GHOST_TEventType type,
        /* TODO: CHECK IF THIS IS A TABLET EVENT */
        bool is_tablet = false;
 
-       if (is_tablet == false &&
-           window->getCursorGrabMode() != GHOST_kGrabDisable &&
-           window->getCursorGrabMode() != GHOST_kGrabNormal)
-       {
+       if (is_tablet == false && window->getCursorGrabModeIsWarp()) {
                GHOST_TInt32 x_new= x_screen;
                GHOST_TInt32 y_new= y_screen;
                GHOST_TInt32 x_accum, y_accum;
index 6a2e6f5..cabec06 100644 (file)
@@ -478,10 +478,7 @@ GHOST_SystemX11::processEvent(XEvent *xe)
                        bool is_tablet = false;
 #endif
 
-                       if(is_tablet == false &&
-                          window->getCursorGrabMode() != GHOST_kGrabDisable &&
-                          window->getCursorGrabMode() != GHOST_kGrabNormal)
-                       {
+                       if (is_tablet == false && window->getCursorGrabModeIsWarp()) {
                                GHOST_TInt32 x_new= xme.x_root;
                                GHOST_TInt32 y_new= xme.y_root;
                                GHOST_TInt32 x_accum, y_accum;
index 323e0fa..23f1b04 100644 (file)
@@ -161,6 +161,7 @@ public:
         */
        inline virtual bool getCursorVisibility() const;
        inline virtual GHOST_TGrabCursorMode getCursorGrabMode() const;
+       inline virtual bool getCursorGrabModeIsWarp() 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);
@@ -362,6 +363,12 @@ inline GHOST_TGrabCursorMode GHOST_Window::getCursorGrabMode() const
        return m_cursorGrab;
 }
 
+inline bool GHOST_Window::getCursorGrabModeIsWarp() const
+{
+       return  (m_cursorGrab == GHOST_kGrabWrap) ||
+               (m_cursorGrab == GHOST_kGrabHide);
+}
+
 inline void GHOST_Window::getCursorGrabInitPos(GHOST_TInt32 &x, GHOST_TInt32 &y) const
 {
        x = m_cursorGrabInitPos[0];