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
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2009-10-08 01:19:35 +0400
committerCampbell Barton <ideasman42@gmail.com>2009-10-08 01:19:35 +0400
commit0c857a4f1462a909b111ec4533e1c1f5ab54af4f (patch)
tree97390de3a70172b7e6c47210094f78a44a019bdd
parenta4e36f24c74dfc825347752aae2e55e0247924ef (diff)
- 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)
-rw-r--r--intern/ghost/GHOST_C-api.h2
-rw-r--r--intern/ghost/GHOST_IWindow.h2
-rw-r--r--intern/ghost/intern/GHOST_C-api.cpp4
-rw-r--r--intern/ghost/intern/GHOST_Window.cpp4
-rw-r--r--intern/ghost/intern/GHOST_Window.h4
-rw-r--r--intern/ghost/intern/GHOST_WindowX11.cpp24
-rw-r--r--intern/ghost/intern/GHOST_WindowX11.h2
-rw-r--r--source/blender/editors/interface/interface_handlers.c4
-rw-r--r--source/blender/windowmanager/WM_api.h3
-rw-r--r--source/blender/windowmanager/intern/wm_cursors.c10
-rw-r--r--source/blender/windowmanager/intern/wm_event_system.c6
11 files changed, 46 insertions, 19 deletions
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
);
/**
diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c
index 385a0eec040..8dea3fa1fc3 100644
--- a/source/blender/editors/interface/interface_handlers.c
+++ b/source/blender/editors/interface/interface_handlers.c
@@ -3709,12 +3709,12 @@ static void button_activate_state(bContext *C, uiBut *but, uiHandleButtonState s
/* number editing */
if(state == BUTTON_STATE_NUM_EDITING) {
if(ui_is_a_warp_but(but))
- WM_cursor_grab(CTX_wm_window(C), 1, 1);
+ WM_cursor_grab(CTX_wm_window(C), TRUE);
ui_numedit_begin(but, data);
} else if(data->state == BUTTON_STATE_NUM_EDITING) {
ui_numedit_end(but, data);
if(ui_is_a_warp_but(but))
- WM_cursor_grab(CTX_wm_window(C), 0, -1);
+ WM_cursor_ungrab(CTX_wm_window(C), FALSE);
}
/* menu open */
if(state == BUTTON_STATE_MENU_OPEN)
diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h
index 321afec51b7..e7f5bb3b291 100644
--- a/source/blender/windowmanager/WM_api.h
+++ b/source/blender/windowmanager/WM_api.h
@@ -75,7 +75,8 @@ void WM_cursor_set (struct wmWindow *win, int curs);
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 val, int warp);
+void WM_cursor_grab(struct wmWindow *win, int warp);
+void WM_cursor_ungrab(wmWindow *win, int restore);
void WM_timecursor (struct wmWindow *win, int nr);
void *WM_paint_cursor_activate(struct wmWindowManager *wm, int (*poll)(struct bContext *C), void (*draw)(struct bContext *C, int, int, void *customdata), void *customdata);
diff --git a/source/blender/windowmanager/intern/wm_cursors.c b/source/blender/windowmanager/intern/wm_cursors.c
index d14cde56083..e33132d18b9 100644
--- a/source/blender/windowmanager/intern/wm_cursors.c
+++ b/source/blender/windowmanager/intern/wm_cursors.c
@@ -163,10 +163,16 @@ void WM_cursor_wait(int val)
}
}
-void WM_cursor_grab(wmWindow *win, int val, int warp)
+void WM_cursor_grab(wmWindow *win, int warp)
{
if(win)
- GHOST_SetCursorGrab(win->ghostwin, val, warp);
+ GHOST_SetCursorGrab(win->ghostwin, 1, warp, -1);
+}
+
+void WM_cursor_ungrab(wmWindow *win, int restore)
+{
+ if(win)
+ GHOST_SetCursorGrab(win->ghostwin, 0, -1, restore);
}
/* afer this you can call restore too */
diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c
index 54841f0e063..086fdd3665b 100644
--- a/source/blender/windowmanager/intern/wm_event_system.c
+++ b/source/blender/windowmanager/intern/wm_event_system.c
@@ -442,7 +442,7 @@ static int wm_operator_invoke(bContext *C, wmOperatorType *ot, wmEvent *event, P
else if(retval & OPERATOR_RUNNING_MODAL) {
/* grab cursor during blocking modal ops (X11) */
if(ot->flag & OPTYPE_BLOCKING)
- WM_cursor_grab(CTX_wm_window(C), 1, (U.uiflag & USER_CONTINUOUS_MOUSE));
+ WM_cursor_grab(CTX_wm_window(C), (U.uiflag & USER_CONTINUOUS_MOUSE));
}
else
WM_operator_free(op);
@@ -637,7 +637,7 @@ void WM_event_remove_handlers(bContext *C, ListBase *handlers)
CTX_wm_region_set(C, region);
}
- WM_cursor_grab(CTX_wm_window(C), 0, -1);
+ WM_cursor_ungrab(CTX_wm_window(C), TRUE);
WM_operator_free(handler->op);
}
else if(handler->ui_remove) {
@@ -835,7 +835,7 @@ static int wm_handler_operator_call(bContext *C, ListBase *handlers, wmEventHand
/* remove modal handler, operator itself should have been cancelled and freed */
if(retval & (OPERATOR_CANCELLED|OPERATOR_FINISHED)) {
- WM_cursor_grab(CTX_wm_window(C), 0, -1);
+ WM_cursor_ungrab(CTX_wm_window(C), TRUE);
BLI_remlink(handlers, handler);
wm_event_free_handler(handler);