From d5b96163f7f5ad341d5e252f88c4126b562317b3 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sun, 6 May 2012 15:59:57 +0000 Subject: code cleanup: add getCursorGrabModeIsWarp(), makes the intent more clear where we check for mouse warping. --- intern/ghost/intern/GHOST_SystemCocoa.mm | 9 +++------ intern/ghost/intern/GHOST_SystemWin32.cpp | 5 +---- intern/ghost/intern/GHOST_SystemX11.cpp | 5 +---- intern/ghost/intern/GHOST_Window.h | 7 +++++++ 4 files changed, 12 insertions(+), 14 deletions(-) (limited to 'intern/ghost') diff --git a/intern/ghost/intern/GHOST_SystemCocoa.mm b/intern/ghost/intern/GHOST_SystemCocoa.mm index 898171b344e..77d9e39a752 100644 --- a/intern/ghost/intern/GHOST_SystemCocoa.mm +++ b/intern/ghost/intern/GHOST_SystemCocoa.mm @@ -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; } diff --git a/intern/ghost/intern/GHOST_SystemWin32.cpp b/intern/ghost/intern/GHOST_SystemWin32.cpp index b00ff690cfa..9f2728a581f 100644 --- a/intern/ghost/intern/GHOST_SystemWin32.cpp +++ b/intern/ghost/intern/GHOST_SystemWin32.cpp @@ -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; diff --git a/intern/ghost/intern/GHOST_SystemX11.cpp b/intern/ghost/intern/GHOST_SystemX11.cpp index 6a2e6f59717..cabec06301a 100644 --- a/intern/ghost/intern/GHOST_SystemX11.cpp +++ b/intern/ghost/intern/GHOST_SystemX11.cpp @@ -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; diff --git a/intern/ghost/intern/GHOST_Window.h b/intern/ghost/intern/GHOST_Window.h index 323e0fa3418..23f1b044b60 100644 --- a/intern/ghost/intern/GHOST_Window.h +++ b/intern/ghost/intern/GHOST_Window.h @@ -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]; -- cgit v1.2.3