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

Log Message:
-----------
Adjustments to continuous grab
- Use an enum for grab modes rather then boolean options.
 -- GHOST_kGrabNormal: continuous grab userpref disabled
 -- GHOST_kGrabWrap: wrap the mouse at the screen bounds *
 -- GHOST_kGrabHide: hide the mouse while grabbing and restore the mouse where 
it was initially pressed *

GrabWrap is nice for transform and tools where you want some idea where the 
cursor is, previously I found both restoring the mouse at its original location 
and restoring at a clamped location was confusing with operators like 
transform, wrapping is not ideal but IMHO the best of a bad bunch of options.
GrabHide  is for numbuts, where restoring the mouse at the initial location 
isnt so confusing.

Modified Paths:
--------------
    trunk/blender/intern/ghost/GHOST_C-api.h
    trunk/blender/intern/ghost/GHOST_IWindow.h
    trunk/blender/intern/ghost/GHOST_Rect.h
    trunk/blender/intern/ghost/GHOST_Types.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_WindowCocoa.h
    trunk/blender/intern/ghost/intern/GHOST_WindowX11.cpp
    trunk/blender/intern/ghost/intern/GHOST_WindowX11.h
    trunk/blender/source/blender/editors/interface/interface_handlers.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 10:06:14 UTC (rev 
23901)
+++ trunk/blender/intern/ghost/GHOST_C-api.h    2009-10-17 14:08:01 UTC (rev 
23902)
@@ -376,7 +376,7 @@
  * @return     Indication of success.
  */
 extern GHOST_TSuccess GHOST_SetCursorGrab(GHOST_WindowHandle windowhandle,
-                                                                               
  int grab, int warp, int restore);
+                                                                               
                GHOST_TGrabCursorMode mode);
 
 
/***************************************************************************************
  ** 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 10:06:14 UTC (rev 
23901)
+++ trunk/blender/intern/ghost/GHOST_IWindow.h  2009-10-17 14:08:01 UTC (rev 
23902)
@@ -271,7 +271,7 @@
         * @param       grab The new grab state of the cursor.
         * @return      Indication of success.
         */
-       virtual GHOST_TSuccess setCursorGrab(bool grab, bool warp, bool 
restore) { return GHOST_kSuccess; };
+       virtual GHOST_TSuccess setCursorGrab(GHOST_TGrabCursorMode mode) { 
return GHOST_kSuccess; };
 
 };
 

Modified: trunk/blender/intern/ghost/GHOST_Rect.h
===================================================================
--- trunk/blender/intern/ghost/GHOST_Rect.h     2009-10-17 10:06:14 UTC (rev 
23901)
+++ trunk/blender/intern/ghost/GHOST_Rect.h     2009-10-17 14:08:01 UTC (rev 
23902)
@@ -127,6 +127,13 @@
        virtual inline void unionPoint(GHOST_TInt32 x, GHOST_TInt32 y);
 
        /**
+        * Grows the rectangle to included a point.
+        * @param       x       The x-coordinate of the point.
+        * @param       y       The y-coordinate of the point.
+        */
+       virtual inline void wrapPoint(GHOST_TInt32 &x, GHOST_TInt32 &y, 
GHOST_TInt32 ofs);
+
+       /**
         * Returns whether the point is inside this rectangle.
         * Point on the boundary is considered inside.
         * @param x     x-coordinate of point to test.
@@ -222,6 +229,21 @@
        if (y > m_b) m_b = y;
 }
 
+inline void GHOST_Rect::wrapPoint(GHOST_TInt32 &x, GHOST_TInt32 &y, 
GHOST_TInt32 ofs)
+{
+       GHOST_TInt32 w= getWidth();
+       GHOST_TInt32 h= getHeight();
+
+       /* highly unlikely but avoid eternal loop */
+       if(w-ofs <= 0 || h-ofs <= 0)
+               return;
+
+       while(x-ofs < m_l)              x+= w;
+       while(y-ofs < m_t)              y+= h;
+       while(x+ofs > m_r)              x-= w;
+       while(y+ofs > m_b)              y-= h;
+}
+
 inline bool GHOST_Rect::isInside(GHOST_TInt32 x, GHOST_TInt32 y) const
 {
        return (x >= m_l) && (x <= m_r) && (y >= m_t) && (y <= m_b);

Modified: trunk/blender/intern/ghost/GHOST_Types.h
===================================================================
--- trunk/blender/intern/ghost/GHOST_Types.h    2009-10-17 10:06:14 UTC (rev 
23901)
+++ trunk/blender/intern/ghost/GHOST_Types.h    2009-10-17 14:08:01 UTC (rev 
23902)
@@ -341,6 +341,12 @@
        GHOST_kKeyF24
 } GHOST_TKey;
 
+typedef enum {
+       GHOST_kGrabDisable = 0, /* grab not set */
+       GHOST_kGrabNormal,      /* no cursor adjustments */
+       GHOST_kGrabWrap,                /* wrap the mouse location to prevent 
limiting screen bounds */
+       GHOST_kGrabHide,                /* hide the mouse while grabbing and 
restore the original location on release (numbuts) */
+} GHOST_TGrabCursorMode;
 
 typedef void* GHOST_TEventDataPtr;
 

Modified: trunk/blender/intern/ghost/intern/GHOST_C-api.cpp
===================================================================
--- trunk/blender/intern/ghost/intern/GHOST_C-api.cpp   2009-10-17 10:06:14 UTC 
(rev 23901)
+++ trunk/blender/intern/ghost/intern/GHOST_C-api.cpp   2009-10-17 14:08:01 UTC 
(rev 23902)
@@ -355,11 +355,11 @@
 
 
 GHOST_TSuccess GHOST_SetCursorGrab(GHOST_WindowHandle windowhandle,
-                                                                  int grab, 
int warp, int restore)
+                                                                               
GHOST_TGrabCursorMode mode)
 {
        GHOST_IWindow* window = (GHOST_IWindow*) windowhandle;
        
-       return window->setCursorGrab(grab?true:false, warp?true:false, 
restore?true:false);
+       return window->setCursorGrab(mode);
 }
 
 

Modified: trunk/blender/intern/ghost/intern/GHOST_SystemX11.cpp
===================================================================
--- trunk/blender/intern/ghost/intern/GHOST_SystemX11.cpp       2009-10-17 
10:06:14 UTC (rev 23901)
+++ trunk/blender/intern/ghost/intern/GHOST_SystemX11.cpp       2009-10-17 
14:08:01 UTC (rev 23902)
@@ -388,31 +388,36 @@
                {
                        XMotionEvent &xme = xe->xmotion;
                        
-                       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;
+                       if(window->getCursorGrabMode() != GHOST_kGrabDisable && 
window->getCursorGrabMode() != GHOST_kGrabNormal)
+                       {
+                               GHOST_TInt32 x_new= xme.x_root;
+                               GHOST_TInt32 y_new= xme.y_root;
+                               GHOST_TInt32 x_accum, y_accum;
+                               GHOST_Rect bounds;
 
-                               window->getCursorWarpPos(x_warp, y_warp);
-                               getCursorPosition(x_new, y_new);
+                               window->getClientBounds(bounds);
 
-                               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;
+                               /* could also clamp to screen bounds
+                                * wrap with a window outside the view will 
fail atm  */
 
-                                       window->setCursorWarpAccum(x_accum, 
y_accum);
-                                       setCursorPosition(x_warp, y_warp); /* 
reset */
+                               bounds.wrapPoint(x_new, y_new, 1); /* offset of 
one incase blender is at screen bounds */
 
-                                       g_event = new
-                                       GHOST_EventCursor(
-                                               getMilliSeconds(),
-                                               GHOST_kEventCursorMove,
-                                               window,
-                                               x_warp + x_accum,
-                                               y_warp + y_accum
-                                       );
+                               window->getCursorGrabAccum(x_accum, y_accum);
 
+                               if(x_new != xme.x_root || y_new != xme.y_root) {
+                                       setCursorPosition(x_new, y_new); /* 
wrap */
+                                       window->setCursorGrabAccum(x_accum + 
(xme.x_root - x_new), y_accum + (xme.y_root - y_new));
                                }
+
+                               g_event = new
+                               GHOST_EventCursor(
+                                       getMilliSeconds(),
+                                       GHOST_kEventCursorMove,
+                                       window,
+                                       xme.x_root + x_accum,
+                                       xme.y_root + y_accum
+                               );
+
                        }
                        else {
                                g_event = new

Modified: trunk/blender/intern/ghost/intern/GHOST_Window.cpp
===================================================================
--- trunk/blender/intern/ghost/intern/GHOST_Window.cpp  2009-10-17 10:06:14 UTC 
(rev 23901)
+++ trunk/blender/intern/ghost/intern/GHOST_Window.cpp  2009-10-17 14:08:01 UTC 
(rev 23902)
@@ -48,15 +48,14 @@
 :
        m_drawingContextType(type),
        m_cursorVisible(true),
-       m_cursorGrabbed(false),
-       m_cursorWarp(false),
+       m_cursorGrab(GHOST_kGrabDisable),
        m_cursorShape(GHOST_kStandardCursorDefault),
        m_stereoVisual(stereoVisual)
 {
        m_isUnsavedChanges = false;
        
-    m_cursorWarpAccumPos[0] = 0;
-    m_cursorWarpAccumPos[1] = 0;
+    m_cursorGrabAccumPos[0] = 0;
+    m_cursorGrabAccumPos[1] = 0;
 
     m_fullScreen = state == GHOST_kWindowStateFullScreen;
     if (m_fullScreen) {
@@ -98,13 +97,13 @@
        }
 }
 
-GHOST_TSuccess GHOST_Window::setCursorGrab(bool grab, bool warp, bool restore)
+GHOST_TSuccess GHOST_Window::setCursorGrab(GHOST_TGrabCursorMode mode)
 {
-       if(m_cursorGrabbed == grab)
+       if(m_cursorGrab == mode)
                return GHOST_kSuccess;
 
-       if (setWindowCursorGrab(grab, warp, restore)) {
-               m_cursorGrabbed = grab;
+       if (setWindowCursorGrab(mode)) {
+               m_cursorGrab = mode;
                return GHOST_kSuccess;
        }
        else {

Modified: trunk/blender/intern/ghost/intern/GHOST_Window.h
===================================================================
--- trunk/blender/intern/ghost/intern/GHOST_Window.h    2009-10-17 10:06:14 UTC 
(rev 23901)
+++ trunk/blender/intern/ghost/intern/GHOST_Window.h    2009-10-17 14:08:01 UTC 
(rev 23902)
@@ -158,10 +158,9 @@
         * @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);
+       inline virtual GHOST_TGrabCursorMode getCursorGrabMode() const;
+       inline virtual void getCursorGrabAccum(GHOST_TInt32 &x, GHOST_TInt32 
&y) const;
+       inline virtual void setCursorGrabAccum(GHOST_TInt32 x, GHOST_TInt32 y);
 
        /**
         * Shows or hides the cursor.
@@ -175,7 +174,7 @@
         * @param       grab The new grab state of the cursor.
         * @return      Indication of success.
         */
-       virtual GHOST_TSuccess setCursorGrab(bool grab, bool warp, bool 
restore);
+       virtual GHOST_TSuccess setCursorGrab(GHOST_TGrabCursorMode mode);
 
        /**
         * Sets the window "modified" status, indicating unsaved changes
@@ -247,7 +246,7 @@
         * Sets the cursor grab on the window using
         * native window system calls.
         */
-       virtual GHOST_TSuccess setWindowCursorGrab(bool grab, bool warp, bool 
restore) { return GHOST_kSuccess; };
+       virtual GHOST_TSuccess setWindowCursorGrab(GHOST_TGrabCursorMode mode) 
{ return GHOST_kSuccess; };
        
        /**
         * Sets the cursor shape on the window using
@@ -274,16 +273,13 @@
        bool m_cursorVisible;
 
        /** The current grabbed state of the cursor */
-       bool m_cursorGrabbed;
-       
-       /** The current warped state of the cursor */
-       bool m_cursorWarp;
+       GHOST_TGrabCursorMode m_cursorGrab;
 
        /** Initial grab location. */
-       GHOST_TInt32 m_cursorWarpInitPos[2];
+       GHOST_TInt32 m_cursorGrabInitPos[2];
 
-       /** Accumulated offset from m_cursorWarpInitPos. */
-       GHOST_TInt32 m_cursorWarpAccumPos[2];
+       /** Accumulated offset from m_cursorGrabInitPos. */
+       GHOST_TInt32 m_cursorGrabAccumPos[2];
 
        /** The current shape of the cursor */
        GHOST_TStandardCursor m_cursorShape;
@@ -317,42 +313,23 @@
        return m_cursorVisible;
 }
 
-inline bool GHOST_Window::getCursorWarp() const
+inline GHOST_TGrabCursorMode GHOST_Window::getCursorGrabMode() const
 {
-       return m_cursorWarp;
+       return m_cursorGrab;
 }
 
-inline bool GHOST_Window::getCursorWarpPos(GHOST_TInt32 &x, GHOST_TInt32 &y) 
const
+inline void GHOST_Window::getCursorGrabAccum(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;
+       x= m_cursorGrabAccumPos[0];
+       y= m_cursorGrabAccumPos[1];
 }
 
-inline bool GHOST_Window::getCursorWarpAccum(GHOST_TInt32 &x, GHOST_TInt32 &y) 
const
+inline void GHOST_Window::setCursorGrabAccum(GHOST_TInt32 x, GHOST_TInt32 y)
 {
-       if(m_cursorWarp==false)
-               return GHOST_kFailure;
-
-       x= m_cursorWarpAccumPos[0];
-       y= m_cursorWarpAccumPos[1];
-       return GHOST_kSuccess;
+       m_cursorGrabAccumPos[0]= x;
+       m_cursorGrabAccumPos[1]= y;
 }
 

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to