Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/intern
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2009-10-17 23:32:28 +0400
committerCampbell Barton <ideasman42@gmail.com>2009-10-17 23:32:28 +0400
commit69c6a33ba1a064aa13da3ef6a74b310620cfafd5 (patch)
tree69eb569feb0f03d912391651b7fde6c66c43be98 /intern
parent484bf962c66a5ffb7592cf8e4b462dbfb8d21214 (diff)
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)
Diffstat (limited to 'intern')
-rw-r--r--intern/ghost/GHOST_C-api.h6
-rw-r--r--intern/ghost/GHOST_IWindow.h2
-rw-r--r--intern/ghost/intern/GHOST_C-api.cpp14
-rw-r--r--intern/ghost/intern/GHOST_SystemX11.cpp4
-rw-r--r--intern/ghost/intern/GHOST_Window.cpp14
-rw-r--r--intern/ghost/intern/GHOST_Window.h13
-rw-r--r--intern/ghost/intern/GHOST_WindowX11.cpp1
7 files changed, 45 insertions, 9 deletions
diff --git a/intern/ghost/GHOST_C-api.h b/intern/ghost/GHOST_C-api.h
index 93bd12437ab..bd812177f17 100644
--- a/intern/ghost/GHOST_C-api.h
+++ b/intern/ghost/GHOST_C-api.h
@@ -372,11 +372,13 @@ extern GHOST_TSuccess GHOST_SetCursorPosition(GHOST_SystemHandle systemhandle,
* 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.
diff --git a/intern/ghost/GHOST_IWindow.h b/intern/ghost/GHOST_IWindow.h
index 3ab9bef2bfa..512fad877cb 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(GHOST_TGrabCursorMode mode) { return GHOST_kSuccess; };
+ virtual GHOST_TSuccess setCursorGrab(GHOST_TGrabCursorMode mode, GHOST_Rect *bounds) { return GHOST_kSuccess; };
};
diff --git a/intern/ghost/intern/GHOST_C-api.cpp b/intern/ghost/intern/GHOST_C-api.cpp
index 5563e0d1aa8..0160df552cc 100644
--- a/intern/ghost/intern/GHOST_C-api.cpp
+++ b/intern/ghost/intern/GHOST_C-api.cpp
@@ -355,11 +355,21 @@ GHOST_TSuccess GHOST_SetCursorPosition(GHOST_SystemHandle systemhandle,
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);
}
diff --git a/intern/ghost/intern/GHOST_SystemX11.cpp b/intern/ghost/intern/GHOST_SystemX11.cpp
index 122e6c55241..774fd025b85 100644
--- a/intern/ghost/intern/GHOST_SystemX11.cpp
+++ b/intern/ghost/intern/GHOST_SystemX11.cpp
@@ -395,7 +395,9 @@ GHOST_SystemX11::processEvent(XEvent *xe)
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 */
diff --git a/intern/ghost/intern/GHOST_Window.cpp b/intern/ghost/intern/GHOST_Window.cpp
index cda6bfa06ee..33484284d7c 100644
--- a/intern/ghost/intern/GHOST_Window.cpp
+++ b/intern/ghost/intern/GHOST_Window.cpp
@@ -97,12 +97,18 @@ GHOST_TSuccess GHOST_Window::setCursorVisibility(bool visible)
}
}
-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::setCursorGrab(GHOST_TGrabCursorMode mode)
}
}
+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)) {
diff --git a/intern/ghost/intern/GHOST_Window.h b/intern/ghost/intern/GHOST_Window.h
index e66a3c2fd36..0986fc57430 100644
--- a/intern/ghost/intern/GHOST_Window.h
+++ b/intern/ghost/intern/GHOST_Window.h
@@ -171,10 +171,16 @@ public:
/**
* 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
@@ -281,6 +287,9 @@ protected:
/** 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;
diff --git a/intern/ghost/intern/GHOST_WindowX11.cpp b/intern/ghost/intern/GHOST_WindowX11.cpp
index 9914bad23c8..dba1be1b862 100644
--- a/intern/ghost/intern/GHOST_WindowX11.cpp
+++ b/intern/ghost/intern/GHOST_WindowX11.cpp
@@ -1421,6 +1421,7 @@ setWindowCursorGrab(
/* 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);
}