From 0c857a4f1462a909b111ec4533e1c1f5ab54af4f Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Wed, 7 Oct 2009 21:19:35 +0000 Subject: - made ungrab a second function - WM_cursor_ungrab - ungrab can restore the position of the mouse clamped to the window bounds (much nicer for transform) --- intern/ghost/GHOST_C-api.h | 2 +- intern/ghost/GHOST_IWindow.h | 2 +- intern/ghost/intern/GHOST_C-api.cpp | 4 ++-- intern/ghost/intern/GHOST_Window.cpp | 4 ++-- intern/ghost/intern/GHOST_Window.h | 4 ++-- intern/ghost/intern/GHOST_WindowX11.cpp | 24 ++++++++++++++++++++++-- intern/ghost/intern/GHOST_WindowX11.h | 2 +- 7 files changed, 31 insertions(+), 11 deletions(-) (limited to 'intern/ghost') diff --git a/intern/ghost/GHOST_C-api.h b/intern/ghost/GHOST_C-api.h index 35391d3f4cf..00d2cdb1e3b 100644 --- a/intern/ghost/GHOST_C-api.h +++ b/intern/ghost/GHOST_C-api.h @@ -376,7 +376,7 @@ extern GHOST_TSuccess GHOST_SetCursorPosition(GHOST_SystemHandle systemhandle, * @return Indication of success. */ extern GHOST_TSuccess GHOST_SetCursorGrab(GHOST_WindowHandle windowhandle, - int grab, int warp); + int grab, int warp, int restore); /*************************************************************************************** ** Access to mouse button and keyboard states. diff --git a/intern/ghost/GHOST_IWindow.h b/intern/ghost/GHOST_IWindow.h index 44ddf9a7cfb..993b41a4d4f 100644 --- a/intern/ghost/GHOST_IWindow.h +++ b/intern/ghost/GHOST_IWindow.h @@ -271,7 +271,7 @@ public: * @param grab The new grab state of the cursor. * @return Indication of success. */ - virtual GHOST_TSuccess setCursorGrab(bool grab, bool warp) { return GHOST_kSuccess; }; + virtual GHOST_TSuccess setCursorGrab(bool grab, bool warp, bool restore) { return GHOST_kSuccess; }; }; diff --git a/intern/ghost/intern/GHOST_C-api.cpp b/intern/ghost/intern/GHOST_C-api.cpp index b86c4703ea2..e225ad4fd90 100644 --- a/intern/ghost/intern/GHOST_C-api.cpp +++ b/intern/ghost/intern/GHOST_C-api.cpp @@ -355,11 +355,11 @@ GHOST_TSuccess GHOST_SetCursorPosition(GHOST_SystemHandle systemhandle, GHOST_TSuccess GHOST_SetCursorGrab(GHOST_WindowHandle windowhandle, - int grab, int warp) + int grab, int warp, int restore) { GHOST_IWindow* window = (GHOST_IWindow*) windowhandle; - return window->setCursorGrab(grab?true:false, warp?true:false); + return window->setCursorGrab(grab?true:false, warp?true:false, restore?true:false); } diff --git a/intern/ghost/intern/GHOST_Window.cpp b/intern/ghost/intern/GHOST_Window.cpp index 531674607d1..94feb83e003 100644 --- a/intern/ghost/intern/GHOST_Window.cpp +++ b/intern/ghost/intern/GHOST_Window.cpp @@ -98,12 +98,12 @@ GHOST_TSuccess GHOST_Window::setCursorVisibility(bool visible) } } -GHOST_TSuccess GHOST_Window::setCursorGrab(bool grab, bool warp) +GHOST_TSuccess GHOST_Window::setCursorGrab(bool grab, bool warp, bool restore) { if(m_cursorGrabbed == grab) return GHOST_kSuccess; - if (setWindowCursorGrab(grab, warp)) { + if (setWindowCursorGrab(grab, warp, restore)) { m_cursorGrabbed = grab; return GHOST_kSuccess; } diff --git a/intern/ghost/intern/GHOST_Window.h b/intern/ghost/intern/GHOST_Window.h index 36e4bac6dae..786918716c5 100644 --- a/intern/ghost/intern/GHOST_Window.h +++ b/intern/ghost/intern/GHOST_Window.h @@ -175,7 +175,7 @@ public: * @param grab The new grab state of the cursor. * @return Indication of success. */ - virtual GHOST_TSuccess setCursorGrab(bool grab, bool warp); + virtual GHOST_TSuccess setCursorGrab(bool grab, bool warp, bool restore); /** * Sets the window "modified" status, indicating unsaved changes @@ -247,7 +247,7 @@ protected: * Sets the cursor grab on the window using * native window system calls. */ - virtual GHOST_TSuccess setWindowCursorGrab(bool grab, bool warp) { return GHOST_kSuccess; }; + virtual GHOST_TSuccess setWindowCursorGrab(bool grab, bool warp, bool restore) { return GHOST_kSuccess; }; /** * Sets the cursor shape on the window using diff --git a/intern/ghost/intern/GHOST_WindowX11.cpp b/intern/ghost/intern/GHOST_WindowX11.cpp index c2dc1048ea0..d197b534352 100644 --- a/intern/ghost/intern/GHOST_WindowX11.cpp +++ b/intern/ghost/intern/GHOST_WindowX11.cpp @@ -1400,7 +1400,7 @@ setWindowCursorVisibility( GHOST_TSuccess GHOST_WindowX11:: setWindowCursorGrab( - bool grab, bool warp + bool grab, bool warp, bool restore ){ if(grab) { if(warp) { @@ -1416,7 +1416,27 @@ setWindowCursorGrab( if(m_cursorWarp) { /* are we exiting warp */ setWindowCursorVisibility(true); /* Almost works without but important otherwise the mouse GHOST location can be incorrect on exit */ - m_system->setCursorPosition(m_cursorWarpInitPos[0], m_cursorWarpInitPos[1]); + if(restore) { + GHOST_Rect bounds; + GHOST_TInt32 x_new, y_new, x_rel, y_rel; + + getClientBounds(bounds); + + x_new= m_cursorWarpInitPos[0]+m_cursorWarpAccumPos[0]; + y_new= m_cursorWarpInitPos[1]+m_cursorWarpAccumPos[1]; + + screenToClient(x_new, y_new, x_rel, y_rel); + + if(x_rel < 0) x_new = (x_new-x_rel) + 2; + if(y_rel < 0) y_new = (y_new-y_rel) + 2; + if(x_rel > bounds.getWidth()) x_new -= (x_rel-bounds.getWidth()) + 2; + if(y_rel > bounds.getHeight()) y_new -= (y_rel-bounds.getHeight()) + 2; + m_system->setCursorPosition(x_new, y_new); + + } + else { + m_system->setCursorPosition(m_cursorWarpInitPos[0], m_cursorWarpInitPos[1]); + } setCursorWarpAccum(0, 0); m_cursorWarp= false; diff --git a/intern/ghost/intern/GHOST_WindowX11.h b/intern/ghost/intern/GHOST_WindowX11.h index 08fba3e2be8..eb0689ab410 100644 --- a/intern/ghost/intern/GHOST_WindowX11.h +++ b/intern/ghost/intern/GHOST_WindowX11.h @@ -256,7 +256,7 @@ protected: */ GHOST_TSuccess setWindowCursorGrab( - bool grab, bool warp + bool grab, bool warp, bool restore ); /** -- cgit v1.2.3