[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [23908] trunk/blender: wrap the mouse within the region while grabbing so on release the current view never changes and less likelyhood of loosing the cursor when running blender on 2+ screens .

Campbell Barton ideasman42 at gmail.com
Sat Oct 17 21:32:28 CEST 2009


Revision: 23908
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=23908
Author:   campbellbarton
Date:     2009-10-17 21:32:28 +0200 (Sat, 17 Oct 2009)

Log Message:
-----------
wrap the mouse within the region while grabbing so on release the current view never changes and less likelyhood of loosing the cursor when running blender on 2+ screens. (assuming the 3d view isnt stretched over both)

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/source/blender/editors/animation/anim_filter.c
    trunk/blender/source/blender/editors/interface/interface_handlers.c
    trunk/blender/source/blender/makesrna/intern/rna_userdef.c
    trunk/blender/source/blender/makesrna/intern/rna_wm.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-17 16:52:09 UTC (rev 23907)
+++ trunk/blender/intern/ghost/GHOST_C-api.h	2009-10-17 19:32:28 UTC (rev 23908)
@@ -372,11 +372,13 @@
  * events when the mouse is outside the window. X11 only, others
  * do this automatically.
  * @param windowhandle The handle to the window
- * @param	grab The new grab state of the cursor.
+ * @param	mode The new grab state of the cursor.
+ * @param	bounds The grab ragion (optional) - left,top,right,bottom
  * @return	Indication of success.
  */
 extern GHOST_TSuccess GHOST_SetCursorGrab(GHOST_WindowHandle windowhandle,
-												GHOST_TGrabCursorMode mode);
+												GHOST_TGrabCursorMode mode,
+												int* bounds);
 
 /***************************************************************************************
  ** Access to mouse button and keyboard states.

Modified: trunk/blender/intern/ghost/GHOST_IWindow.h
===================================================================
--- trunk/blender/intern/ghost/GHOST_IWindow.h	2009-10-17 16:52:09 UTC (rev 23907)
+++ trunk/blender/intern/ghost/GHOST_IWindow.h	2009-10-17 19:32:28 UTC (rev 23908)
@@ -271,7 +271,7 @@
 	 * @param	grab The new grab state of the cursor.
 	 * @return	Indication of success.
 	 */
-	virtual GHOST_TSuccess setCursorGrab(GHOST_TGrabCursorMode mode) { return GHOST_kSuccess; };
+	virtual GHOST_TSuccess setCursorGrab(GHOST_TGrabCursorMode mode, GHOST_Rect *bounds) { return GHOST_kSuccess; };
 
 };
 

Modified: trunk/blender/intern/ghost/intern/GHOST_C-api.cpp
===================================================================
--- trunk/blender/intern/ghost/intern/GHOST_C-api.cpp	2009-10-17 16:52:09 UTC (rev 23907)
+++ trunk/blender/intern/ghost/intern/GHOST_C-api.cpp	2009-10-17 19:32:28 UTC (rev 23908)
@@ -355,11 +355,21 @@
 
 
 GHOST_TSuccess GHOST_SetCursorGrab(GHOST_WindowHandle windowhandle,
-										GHOST_TGrabCursorMode mode)
+										GHOST_TGrabCursorMode mode,
+										int *bounds)
 {
 	GHOST_IWindow* window = (GHOST_IWindow*) windowhandle;
+	GHOST_Rect bounds_rect, bounds_win;
+
+	if(bounds) {
+		/* if this is X11 specific we need a function that converts */
+		window->getClientBounds(bounds_win);
+		window->clientToScreen(bounds[0], bounds_win.getHeight() - bounds[1], bounds_rect.m_l, bounds_rect.m_t);
+		window->clientToScreen(bounds[2], bounds_win.getHeight() - bounds[3], bounds_rect.m_r, bounds_rect.m_b);
+
+	}
 	
-	return window->setCursorGrab(mode);
+	return window->setCursorGrab(mode, bounds ? &bounds_rect:NULL);
 }
 
 

Modified: trunk/blender/intern/ghost/intern/GHOST_SystemX11.cpp
===================================================================
--- trunk/blender/intern/ghost/intern/GHOST_SystemX11.cpp	2009-10-17 16:52:09 UTC (rev 23907)
+++ trunk/blender/intern/ghost/intern/GHOST_SystemX11.cpp	2009-10-17 19:32:28 UTC (rev 23908)
@@ -395,7 +395,9 @@
 				GHOST_TInt32 x_accum, y_accum;
 				GHOST_Rect bounds;
 
-				window->getClientBounds(bounds);
+				/* fallback to window bounds */
+				if(window->getCursorGrabBounds(bounds)==GHOST_kFailure)
+					window->getClientBounds(bounds);
 
 				/* could also clamp to screen bounds
 				 * wrap with a window outside the view will fail atm  */

Modified: trunk/blender/intern/ghost/intern/GHOST_Window.cpp
===================================================================
--- trunk/blender/intern/ghost/intern/GHOST_Window.cpp	2009-10-17 16:52:09 UTC (rev 23907)
+++ trunk/blender/intern/ghost/intern/GHOST_Window.cpp	2009-10-17 19:32:28 UTC (rev 23908)
@@ -97,12 +97,18 @@
 	}
 }
 
-GHOST_TSuccess GHOST_Window::setCursorGrab(GHOST_TGrabCursorMode mode)
+GHOST_TSuccess GHOST_Window::setCursorGrab(GHOST_TGrabCursorMode mode, GHOST_Rect *bounds)
 {
 	if(m_cursorGrab == mode)
 		return GHOST_kSuccess;
 
 	if (setWindowCursorGrab(mode)) {
+
+		if(mode==GHOST_kGrabDisable)
+			m_cursorGrabBounds.m_l= m_cursorGrabBounds.m_r= -1;
+		else if (bounds) {
+			m_cursorGrabBounds= *bounds;
+		}
 		m_cursorGrab = mode;
 		return GHOST_kSuccess;
 	}
@@ -111,6 +117,12 @@
 	}
 }
 
+GHOST_TSuccess GHOST_Window::getCursorGrabBounds(GHOST_Rect& bounds)
+{
+	bounds= m_cursorGrabBounds;
+	return (bounds.m_l==-1 && bounds.m_r==-1) ? GHOST_kFailure : GHOST_kSuccess;
+}
+
 GHOST_TSuccess GHOST_Window::setCursorShape(GHOST_TStandardCursor cursorShape)
 {
 	if (setWindowCursorShape(cursorShape)) {

Modified: trunk/blender/intern/ghost/intern/GHOST_Window.h
===================================================================
--- trunk/blender/intern/ghost/intern/GHOST_Window.h	2009-10-17 16:52:09 UTC (rev 23907)
+++ trunk/blender/intern/ghost/intern/GHOST_Window.h	2009-10-17 19:32:28 UTC (rev 23908)
@@ -171,12 +171,18 @@
 
 	/**
 	 * Sets the cursor grab.
-	 * @param	grab The new grab state of the cursor.
+	 * @param	mode The new grab state of the cursor.
 	 * @return	Indication of success.
 	 */
-	virtual GHOST_TSuccess setCursorGrab(GHOST_TGrabCursorMode mode);
+	virtual GHOST_TSuccess setCursorGrab(GHOST_TGrabCursorMode mode, GHOST_Rect *bounds);
 
 	/**
+	 * Gets the cursor grab region, if unset the window is used.
+	 * reset when grab is disabled.
+	 */
+	virtual GHOST_TSuccess getCursorGrabBounds(GHOST_Rect& bounds);
+
+	/**
 	 * Sets the window "modified" status, indicating unsaved changes
 	 * @param isUnsavedChanges Unsaved changes or not
 	 * @return Indication of success.
@@ -281,6 +287,9 @@
 	/** Accumulated offset from m_cursorGrabInitPos. */
 	GHOST_TInt32 m_cursorGrabAccumPos[2];
 
+	/** Wrap the cursor within this region. */
+	GHOST_Rect m_cursorGrabBounds;
+
 	/** The current shape of the cursor */
 	GHOST_TStandardCursor m_cursorShape;
     

Modified: trunk/blender/intern/ghost/intern/GHOST_WindowX11.cpp
===================================================================
--- trunk/blender/intern/ghost/intern/GHOST_WindowX11.cpp	2009-10-17 16:52:09 UTC (rev 23907)
+++ trunk/blender/intern/ghost/intern/GHOST_WindowX11.cpp	2009-10-17 19:32:28 UTC (rev 23908)
@@ -1421,6 +1421,7 @@
 
 		/* Almost works without but important otherwise the mouse GHOST location can be incorrect on exit */
 		setCursorGrabAccum(0, 0);
+		m_cursorGrabBounds.m_l= m_cursorGrabBounds.m_r= -1; /* disable */
 		XUngrabPointer(m_display, CurrentTime);
 	}
 

Modified: trunk/blender/source/blender/editors/animation/anim_filter.c
===================================================================
--- trunk/blender/source/blender/editors/animation/anim_filter.c	2009-10-17 16:52:09 UTC (rev 23907)
+++ trunk/blender/source/blender/editors/animation/anim_filter.c	2009-10-17 19:32:28 UTC (rev 23908)
@@ -78,6 +78,7 @@
 
 #include "BKE_animsys.h"
 #include "BKE_action.h"
+#include "BKE_fcurve.h"
 #include "BKE_context.h"
 #include "BKE_global.h"
 #include "BKE_key.h"
@@ -669,7 +670,7 @@
 						 * then free the MEM_alloc'd string
 						 */
 						if (rna_path) {
-							ale->key_data= list_find_fcurve(&act->curves, rna_path, 0);
+							ale->key_data= (void *)list_find_fcurve(&act->curves, rna_path, 0);
 							MEM_freeN(rna_path);
 						}
 					}

Modified: trunk/blender/source/blender/editors/interface/interface_handlers.c
===================================================================
--- trunk/blender/source/blender/editors/interface/interface_handlers.c	2009-10-17 16:52:09 UTC (rev 23907)
+++ trunk/blender/source/blender/editors/interface/interface_handlers.c	2009-10-17 19:32:28 UTC (rev 23908)
@@ -3750,7 +3750,7 @@
 	/* number editing */
 	if(state == BUTTON_STATE_NUM_EDITING) {
 		if(ui_is_a_warp_but(but))
-			WM_cursor_grab(CTX_wm_window(C), TRUE, TRUE);
+			WM_cursor_grab(CTX_wm_window(C), TRUE, TRUE, NULL);
 		ui_numedit_begin(but, data);
 	} else if(data->state == BUTTON_STATE_NUM_EDITING) {
 		ui_numedit_end(but, data);

Modified: trunk/blender/source/blender/makesrna/intern/rna_userdef.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_userdef.c	2009-10-17 16:52:09 UTC (rev 23907)
+++ trunk/blender/source/blender/makesrna/intern/rna_userdef.c	2009-10-17 19:32:28 UTC (rev 23908)
@@ -52,6 +52,7 @@
 	WM_event_add_notifier(C, NC_WINDOW, NULL);
 }
 
+#if 0
 static void rna_userdef_lmb_select_set(PointerRNA *ptr,int value)
 {
 	UserDef *userdef = (UserDef*)ptr->data;
@@ -64,7 +65,6 @@
 		userdef->flag &= ~USER_LMOUSESELECT;
 }
 
-#if 0
 static void rna_userdef_rmb_select_set(PointerRNA *ptr,int value)
 {
 	rna_userdef_lmb_select_set(ptr, !value);

Modified: trunk/blender/source/blender/makesrna/intern/rna_wm.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_wm.c	2009-10-17 16:52:09 UTC (rev 23907)
+++ trunk/blender/source/blender/makesrna/intern/rna_wm.c	2009-10-17 19:32:28 UTC (rev 23908)
@@ -680,8 +680,9 @@
 static void rna_def_keyconfig(BlenderRNA *brna)
 {
 	StructRNA *srna;
-	FunctionRNA *func;
-	PropertyRNA *prop, *parm;
+	// FunctionRNA *func;
+	// PropertyRNA *parm;
+	PropertyRNA *prop;
 
 	static EnumPropertyItem map_type_items[] = {
 		{KMI_TYPE_KEYBOARD, "KEYBOARD", 0, "Keyboard", ""},

Modified: trunk/blender/source/blender/windowmanager/WM_api.h
===================================================================
--- trunk/blender/source/blender/windowmanager/WM_api.h	2009-10-17 16:52:09 UTC (rev 23907)
+++ trunk/blender/source/blender/windowmanager/WM_api.h	2009-10-17 19:32:28 UTC (rev 23908)
@@ -76,7 +76,7 @@
 void		WM_cursor_modal		(struct wmWindow *win, int curs);
 void		WM_cursor_restore	(struct wmWindow *win);
 void		WM_cursor_wait		(int val);
-void		WM_cursor_grab(struct wmWindow *win, int wrap, int hide);
+void		WM_cursor_grab(struct wmWindow *win, int wrap, int hide, int *bounds);
 void		WM_cursor_ungrab(struct wmWindow *win);
 void		WM_timecursor		(struct wmWindow *win, int nr);
 

Modified: trunk/blender/source/blender/windowmanager/intern/wm_cursors.c
===================================================================
--- trunk/blender/source/blender/windowmanager/intern/wm_cursors.c	2009-10-17 16:52:09 UTC (rev 23907)
+++ trunk/blender/source/blender/windowmanager/intern/wm_cursors.c	2009-10-17 19:32:28 UTC (rev 23908)
@@ -163,26 +163,27 @@
 	}
 }
 
-void WM_cursor_grab(wmWindow *win, int wrap, int hide)
+void WM_cursor_grab(wmWindow *win, int wrap, int hide, int *bounds)
 {
 	/* Only grab cursor when not running debug.

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list