[Bf-committers] [Bf-blender-cvs] SVN commit: /data/svn/bf-blender [23679] trunk/blender: Experimental option to allow moving the mouse outside the view, " Continuous Grab" in the user-prefs.

Damien Plisson damien.plisson at yahoo.fr
Wed Oct 7 10:45:00 CEST 2009


Hi Campbell,

For MAC OS X, there are mouse position & cursor dissociate functions  
in Quartz Services, so I can include "Continuous grab" in a next Cocoa  
ghost release.

Damien

Le 7 oct. 2009 à 09:11, Campbell Barton a écrit :

> Revision: 23679
>          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=23679
> Author:   campbellbarton
> Date:     2009-10-07 09:11:10 +0200 (Wed, 07 Oct 2009)
>
> Log Message:
> -----------
> Experimental option to allow moving the mouse outside the view,  
> "Continuous Grab" in the user-prefs.
> - Useful for dragging buttons to the far right when theyd otherwise  
> hit the screen edge.
> - Useful for transform though probably NOT what you want when using  
> the transform manipulator (should make an option).
> - When enabled, number buttons use this as well as a different  
> conversion of mouse movement
>  float numbuts: mouse 1px == 1-clickstep
>  int numbuts: 2px == 1 (tried 1:1 but its too jitter prone)
>
> details...
> - access as an option to GHOST_SetCursorGrab(grab, warp)
> - Currently all operators that grab use this, could be made an  
> operator flag
> - only Ghost/X11 supported currently
>
> Modified Paths:
> --------------
>    trunk/blender/intern/ghost/GHOST_C-api.h
>    trunk/blender/intern/ghost/GHOST_IWindow.h
>    trunk/blender/intern/ghost/intern/GHOST_C-api.cpp
>    trunk/blender/intern/ghost/intern/GHOST_SystemX11.cpp
>    trunk/blender/intern/ghost/intern/GHOST_Window.cpp
>    trunk/blender/intern/ghost/intern/GHOST_Window.h
>    trunk/blender/intern/ghost/intern/GHOST_WindowX11.cpp
>    trunk/blender/intern/ghost/intern/GHOST_WindowX11.h
>    trunk/blender/release/scripts/ui/space_userpref.py
>    trunk/blender/source/blender/editors/interface/interface_handlers.c
>    trunk/blender/source/blender/makesdna/DNA_userdef_types.h
>    trunk/blender/source/blender/makesrna/intern/rna_userdef.c
>    trunk/blender/source/blender/windowmanager/WM_api.h
>    trunk/blender/source/blender/windowmanager/intern/wm_cursors.c
>    trunk/blender/source/blender/windowmanager/intern/wm_event_system.c
>
> Modified: trunk/blender/intern/ghost/GHOST_C-api.h
> ===================================================================
> --- trunk/blender/intern/ghost/GHOST_C-api.h	2009-10-07 05:26:13 UTC  
> (rev 23678)
> +++ trunk/blender/intern/ghost/GHOST_C-api.h	2009-10-07 07:11:10 UTC  
> (rev 23679)
> @@ -376,7 +376,7 @@
>  * @return	Indication of success.
>  */
> extern GHOST_TSuccess GHOST_SetCursorGrab(GHOST_WindowHandle  
> windowhandle,
> -										  int grab);
> +										  int grab, int warp);
>
> / 
> ***************************************************************************************
>  ** Access to mouse button and keyboard states.
>
> Modified: trunk/blender/intern/ghost/GHOST_IWindow.h
> ===================================================================
> --- trunk/blender/intern/ghost/GHOST_IWindow.h	2009-10-07 05:26:13  
> UTC (rev 23678)
> +++ trunk/blender/intern/ghost/GHOST_IWindow.h	2009-10-07 07:11:10  
> UTC (rev 23679)
> @@ -271,7 +271,7 @@
> 	 * @param	grab The new grab state of the cursor.
> 	 * @return	Indication of success.
> 	 */
> -	virtual GHOST_TSuccess setCursorGrab(bool grab) { return  
> GHOST_kSuccess; };
> +	virtual GHOST_TSuccess setCursorGrab(bool grab, bool warp)  
> { return GHOST_kSuccess; };
>
> };
>
>
> Modified: trunk/blender/intern/ghost/intern/GHOST_C-api.cpp
> ===================================================================
> --- trunk/blender/intern/ghost/intern/GHOST_C-api.cpp	2009-10-07  
> 05:26:13 UTC (rev 23678)
> +++ trunk/blender/intern/ghost/intern/GHOST_C-api.cpp	2009-10-07  
> 07:11:10 UTC (rev 23679)
> @@ -355,11 +355,11 @@
>
>
> GHOST_TSuccess GHOST_SetCursorGrab(GHOST_WindowHandle windowhandle,
> -								   int grab)
> +								   int grab, int warp)
> {
> 	GHOST_IWindow* window = (GHOST_IWindow*) windowhandle;
> 	
> -	return window->setCursorGrab(grab?true:false);
> +	return window->setCursorGrab(grab?true:false, warp?true:false);
> }
>
>
>
> Modified: trunk/blender/intern/ghost/intern/GHOST_SystemX11.cpp
> ===================================================================
> --- trunk/blender/intern/ghost/intern/GHOST_SystemX11.cpp	2009-10-07  
> 05:26:13 UTC (rev 23678)
> +++ trunk/blender/intern/ghost/intern/GHOST_SystemX11.cpp	2009-10-07  
> 07:11:10 UTC (rev 23679)
> @@ -374,12 +374,12 @@
> 				// Only generate a single expose event
> 				// per read of the event queue.
>
> -				g_event = new
> +				g_event = new
> 				GHOST_Event(
> 					getMilliSeconds(),
> 					GHOST_kEventWindowUpdate,
> 					window
> -				);			
> +				);
> 			}
> 			break;
> 		}
> @@ -388,14 +388,42 @@
> 		{
> 			XMotionEvent &xme = xe->xmotion;
> 			
> -			g_event = new
> -			GHOST_EventCursor(
> -				getMilliSeconds(),
> -				GHOST_kEventCursorMove,
> -				window,
> -				xme.x_root,
> -				xme.y_root
> -			);
> +			if(window->getCursorWarp()) {
> +				/* Calculate offscreen location and re-center the mouse */
> +				GHOST_TInt32 x_warp, y_warp,  x_new, y_new, x_accum, y_accum;
> +
> +				window->getCursorWarpPos(x_warp, y_warp);
> +				getCursorPosition(x_new, y_new);
> +
> +				if(x_warp != x_new || y_warp != y_new) {
> +					window->getCursorWarpAccum(x_accum, y_accum);
> +					x_accum += x_new - x_warp;
> +					y_accum += y_new - y_warp;
> +
> +					window->setCursorWarpAccum(x_accum, y_accum);
> +					setCursorPosition(x_warp, y_warp); /* reset */
> +
> +					g_event = new
> +					GHOST_EventCursor(
> +						getMilliSeconds(),
> +						GHOST_kEventCursorMove,
> +						window,
> +						x_warp + x_accum,
> +						y_warp + y_accum
> +					);
> +
> +				}
> +			}
> +			else {
> +				g_event = new
> +				GHOST_EventCursor(
> +					getMilliSeconds(),
> +					GHOST_kEventCursorMove,
> +					window,
> +					xme.x_root,
> +					xme.y_root
> +				);
> +			}
> 			break;
> 		}
>
>
> Modified: trunk/blender/intern/ghost/intern/GHOST_Window.cpp
> ===================================================================
> --- trunk/blender/intern/ghost/intern/GHOST_Window.cpp	2009-10-07  
> 05:26:13 UTC (rev 23678)
> +++ trunk/blender/intern/ghost/intern/GHOST_Window.cpp	2009-10-07  
> 07:11:10 UTC (rev 23679)
> @@ -48,12 +48,16 @@
> :
> 	m_drawingContextType(type),
> 	m_cursorVisible(true),
> -	m_cursorGrabbed(true),
> +	m_cursorGrabbed(false),
> +	m_cursorWarp(false),
> 	m_cursorShape(GHOST_kStandardCursorDefault),
> 	m_stereoVisual(stereoVisual)
> {
> 	m_isUnsavedChanges = false;
> 	
> +    m_cursorWarpAccumPos[0] = 0;
> +    m_cursorWarpAccumPos[1] = 0;
> +
>     m_fullScreen = state == GHOST_kWindowStateFullScreen;
>     if (m_fullScreen) {
>         m_fullScreenWidth = width;
> @@ -94,12 +98,12 @@
> 	}
> }
>
> -GHOST_TSuccess GHOST_Window::setCursorGrab(bool grab)
> +GHOST_TSuccess GHOST_Window::setCursorGrab(bool grab, bool warp)
> {
> 	if(m_cursorGrabbed == grab)
> 		return GHOST_kSuccess;
>
> -	if (setWindowCursorGrab(grab)) {
> +	if (setWindowCursorGrab(grab, warp)) {
> 		m_cursorGrabbed = grab;
> 		return GHOST_kSuccess;
> 	}
> @@ -150,4 +154,4 @@
> bool GHOST_Window::getModifiedState()
> {
> 	return m_isUnsavedChanges;
> -}
> \ 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-07  
> 05:26:13 UTC (rev 23678)
> +++ trunk/blender/intern/ghost/intern/GHOST_Window.h	2009-10-07  
> 07:11:10 UTC (rev 23679)
> @@ -158,6 +158,10 @@
> 	 * @return	The visibility state of the cursor.
> 	 */
> 	inline virtual bool getCursorVisibility() const;
> +	inline virtual bool getCursorWarp() const;
> +	inline virtual bool getCursorWarpPos(GHOST_TInt32 &x, GHOST_TInt32  
> &y) const;
> +	inline virtual bool getCursorWarpAccum(GHOST_TInt32 &x,  
> GHOST_TInt32 &y) const;
> +	inline virtual bool setCursorWarpAccum(GHOST_TInt32 x,  
> GHOST_TInt32 y);
>
> 	/**
> 	 * Shows or hides the cursor.
> @@ -171,7 +175,7 @@
> 	 * @param	grab The new grab state of the cursor.
> 	 * @return	Indication of success.
> 	 */
> -	virtual GHOST_TSuccess setCursorGrab(bool grab);
> +	virtual GHOST_TSuccess setCursorGrab(bool grab, bool warp);
>
> 	/**
> 	 * Sets the window "modified" status, indicating unsaved changes
> @@ -243,7 +247,7 @@
> 	 * Sets the cursor grab on the window using
> 	 * native window system calls.
> 	 */
> -	virtual GHOST_TSuccess setWindowCursorGrab(bool grab) { return  
> GHOST_kSuccess; };
> +	virtual GHOST_TSuccess setWindowCursorGrab(bool grab, bool warp)  
> { return GHOST_kSuccess; };
> 	
> 	/**
> 	 * Sets the cursor shape on the window using
> @@ -272,6 +276,15 @@
> 	/** The current grabbed state of the cursor */
> 	bool m_cursorGrabbed;
> 	
> +	/** The current warped state of the cursor */
> +	bool m_cursorWarp;
> +
> +	/** Initial grab location. */
> +	GHOST_TInt32 m_cursorWarpInitPos[2];
> +
> +	/** Accumulated offset from m_cursorWarpInitPos. */
> +	GHOST_TInt32 m_cursorWarpAccumPos[2];
> +
> 	/** The current shape of the cursor */
> 	GHOST_TStandardCursor m_cursorShape;
>
> @@ -304,6 +317,42 @@
> 	return m_cursorVisible;
> }
>
> +inline bool GHOST_Window::getCursorWarp() const
> +{
> +	return m_cursorWarp;
> +}
> +
> +inline bool GHOST_Window::getCursorWarpPos(GHOST_TInt32 &x,  
> GHOST_TInt32 &y) const
> +{
> +	if(m_cursorWarp==false)
> +		return GHOST_kFailure;
> +
> +	x= m_cursorWarpInitPos[0];
> +	y= m_cursorWarpInitPos[1];
> +	return GHOST_kSuccess;
> +}
> +
> +inline bool GHOST_Window::getCursorWarpAccum(GHOST_TInt32 &x,  
> GHOST_TInt32 &y) const
> +{
> +	if(m_cursorWarp==false)
> +		return GHOST_kFailure;
> +
> +	x= m_cursorWarpAccumPos[0];
> +	y= m_cursorWarpAccumPos[1];
> +	return GHOST_kSuccess;
> +}
> +
> +inline bool GHOST_Window::setCursorWarpAccum(GHOST_TInt32 x,  
> GHOST_TInt32 y)
> +{
> +	if(m_cursorWarp==false)
> +		return GHOST_kFailure;
> +
> +	m_cursorWarpAccumPos[0]= x;
> +	m_cursorWarpAccumPos[1]= y;
> +
> +	return GHOST_kSuccess;
> +}
> +
> inline GHOST_TStandardCursor GHOST_Window::getCursorShape() const
> {
> 	return m_cursorShape;
>
> Modified: trunk/blender/intern/ghost/intern/GHOST_WindowX11.cpp
> ===================================================================
> --- trunk/blender/intern/ghost/intern/GHOST_WindowX11.cpp	2009-10-07  
> 05:26:13 UTC (rev 23678)
> +++ trunk/blender/intern/ghost/intern/GHOST_WindowX11.cpp	2009-10-07  
> 07:11:10 UTC (rev 23679)
> @@ -1400,12 +1400,29 @@
> 	GHOST_TSuccess
> GHOST_WindowX11::
> setWindowCursorGrab(
> -	bool grab
> +	bool grab, bool warp
> ){
> -	if(grab)
> +	if(grab) {
> +		if(warp) {
> +			m_system->getCursorPosition(m_cursorWarpInitPos[0],  
> m_cursorWarpInitPos[1]);
> +
> +			setCursorWarpAccum(0, 0);
> +			setWindowCursorVisibility(false);
> +			m_cursorWarp= true;
> +		}
> 		XGrabPointer(m_display, m_window, True, ButtonPressMask|  
> ButtonReleaseMask|PointerMotionMask, GrabModeAsync, GrabModeAsync,  
> None, None, CurrentTime);
> -	else
> +	}
> +	else {
> +		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]);
> +
> +			setCursorWarpAccum(0, 0);
> +			m_cursorWarp= false;
> +		}
> 		XUngrabPointer(m_display, CurrentTime);
> +	}
>
> 	XFlush(m_display);
> 	
>
> Modified: trunk/blender/intern/ghost/intern/GHOST_WindowX11.h
> ===================================================================
> --- trunk/blender/intern/ghost/intern/GHOST_WindowX11.h	2009-10-07  
> 05:26:13 UTC (rev 23678)
> +++ trunk/blender/intern/ghost/intern/GHOST_WindowX11.h	2009-10-07  
> 07:11:10 UTC (rev 23679)
> @@ -252,10 +252,11 @@
> 	/**
> 	 * Sets the cursor grab on the window using
> 	 * native window system calls.
> +	 * @param warp	Only used when grab is enabled, hides the mouse and  
> allows gragging outside the screen.
> 	 */
> 		GHOST_TSuccess
> 	setWindowCursorGrab(
> -		bool grab
> +		bool grab, bool warp
> 	);
>
> 	/**
>
> Modified: trunk/blender/release/scripts/ui/space_userpref.py
> ===================================================================
> --- trunk/blender/release/scripts/ui/space_userpref.py	2009-10-07  
> 05:26:13 UTC (rev 23678)
> +++ trunk/blender/release/scripts/ui/space_userpref.py	2009-10-07  
> 07:11:10 UTC (rev 23679)
> @@ -109,9 +109,9 @@
> 		sub1.itemL(text="Mouse Wheel:")
> 		sub1.itemR(view, "wheel_invert_zoom", text="Invert Zoom")
> 		sub1.itemR(view, "wheel_scroll_lines", text="Scroll Lines")
> +		sub1.itemL(text="Mouse Motion:")
> +		sub1.itemR(view, "continuous_mouse", text="Continuous Grab")
> 		sub1.itemS()
> -		sub1.itemS()
> -		sub1.itemS()
> 		sub1.itemL(text="Menus:")
> 		sub1.itemR(view, "open_mouse_over")
> 		sub1.itemL(text="Menu Open Delay:")
>
> Modified: trunk/blender/source/blender/editors/interface/ 
> interface_handlers.c
> ===================================================================
> --- trunk/blender/source/blender/editors/interface/ 
> interface_handlers.c	2009-10-07 05:26:13 UTC (rev 23678)
> +++ trunk/blender/source/blender/editors/interface/ 
> interface_handlers.c	2009-10-07 07:11:10 UTC (rev 23679)
> @@ -230,6 +230,15 @@
> 	return NULL;
> }
>
>
> @@ Diff output truncated at 10240 characters. @@
>
> _______________________________________________
> Bf-blender-cvs mailing list
> Bf-blender-cvs at blender.org
> http://lists.blender.org/mailman/listinfo/bf-blender-cvs



More information about the Bf-committers mailing list