[Bf-blender-cvs] [e4ac8ab2127] master: WM: support X/Y axis cursor wrapping
Campbell Barton
noreply at git.blender.org
Tue May 28 16:52:53 CEST 2019
Commit: e4ac8ab212769b569334d0cd15d4bf04f42cbc89
Author: Campbell Barton
Date: Wed May 29 00:48:48 2019 +1000
Branches: master
https://developer.blender.org/rBe4ac8ab212769b569334d0cd15d4bf04f42cbc89
WM: support X/Y axis cursor wrapping
Operator flags to wrap on a single axis.
D4865 by @Gvgeo with updates.
Resolves T64585
===================================================================
M intern/ghost/GHOST_C-api.h
M intern/ghost/GHOST_IWindow.h
M intern/ghost/GHOST_Rect.h
M intern/ghost/GHOST_Types.h
M intern/ghost/intern/GHOST_C-api.cpp
M intern/ghost/intern/GHOST_SystemCocoa.mm
M intern/ghost/intern/GHOST_SystemSDL.cpp
M intern/ghost/intern/GHOST_SystemWin32.cpp
M intern/ghost/intern/GHOST_SystemX11.cpp
M intern/ghost/intern/GHOST_Window.cpp
M intern/ghost/intern/GHOST_Window.h
M source/blender/editors/animation/anim_markers.c
M source/blender/editors/animation/anim_ops.c
M source/blender/editors/interface/interface_handlers.c
M source/blender/editors/interface/view2d_ops.c
M source/blender/editors/mesh/editmesh_bevel.c
M source/blender/editors/mesh/editmesh_inset.c
M source/blender/editors/space_clip/clip_ops.c
M source/blender/editors/space_clip/tracking_ops.c
M source/blender/editors/space_clip/tracking_ops_plane.c
M source/blender/editors/space_graph/graph_ops.c
M source/blender/editors/space_image/image_ops.c
M source/blender/editors/space_node/node_view.c
M source/blender/editors/space_text/text_ops.c
M source/blender/editors/space_view3d/view3d_edit.c
M source/blender/editors/uvedit/uvedit_unwrap_ops.c
M source/blender/makesrna/intern/rna_wm.c
M source/blender/windowmanager/WM_api.h
M source/blender/windowmanager/WM_types.h
M source/blender/windowmanager/gizmo/intern/wm_gizmo_map.c
M source/blender/windowmanager/intern/wm_cursors.c
M source/blender/windowmanager/intern/wm_event_system.c
M source/blender/windowmanager/intern/wm_operator_type.c
===================================================================
diff --git a/intern/ghost/GHOST_C-api.h b/intern/ghost/GHOST_C-api.h
index fa783c17e8c..3238be8fd87 100644
--- a/intern/ghost/GHOST_C-api.h
+++ b/intern/ghost/GHOST_C-api.h
@@ -410,6 +410,7 @@ extern GHOST_TSuccess GHOST_SetCursorPosition(GHOST_SystemHandle systemhandle,
*/
extern GHOST_TSuccess GHOST_SetCursorGrab(GHOST_WindowHandle windowhandle,
GHOST_TGrabCursorMode mode,
+ GHOST_TAxisFlag warp_axis,
int bounds[4],
const int mouse_ungrab_xy[2]);
diff --git a/intern/ghost/GHOST_IWindow.h b/intern/ghost/GHOST_IWindow.h
index 6a9e0b9588a..8042244c536 100644
--- a/intern/ghost/GHOST_IWindow.h
+++ b/intern/ghost/GHOST_IWindow.h
@@ -314,6 +314,7 @@ class GHOST_IWindow {
* \return Indication of success.
*/
virtual GHOST_TSuccess setCursorGrab(GHOST_TGrabCursorMode /*mode*/,
+ GHOST_TAxisFlag /*wrap_axis*/,
GHOST_Rect * /*bounds*/,
GHOST_TInt32 /*mouse_ungrab_xy*/[2])
{
diff --git a/intern/ghost/GHOST_Rect.h b/intern/ghost/GHOST_Rect.h
index 831d3ef1445..88053f83fb9 100644
--- a/intern/ghost/GHOST_Rect.h
+++ b/intern/ghost/GHOST_Rect.h
@@ -125,7 +125,10 @@ class GHOST_Rect {
* \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);
+ virtual inline void wrapPoint(GHOST_TInt32 &x,
+ GHOST_TInt32 &y,
+ GHOST_TInt32 ofs,
+ GHOST_TAxisFlag axis);
/**
* Returns whether the point is inside this rectangle.
@@ -236,7 +239,11 @@ inline void GHOST_Rect::unionPoint(GHOST_TInt32 x, GHOST_TInt32 y)
if (y > m_b)
m_b = y;
}
-inline void GHOST_Rect::wrapPoint(GHOST_TInt32 &x, GHOST_TInt32 &y, GHOST_TInt32 ofs)
+
+inline void GHOST_Rect::wrapPoint(GHOST_TInt32 &x,
+ GHOST_TInt32 &y,
+ GHOST_TInt32 ofs,
+ GHOST_TAxisFlag axis)
{
GHOST_TInt32 w = getWidth();
GHOST_TInt32 h = getHeight();
@@ -246,14 +253,18 @@ inline void GHOST_Rect::wrapPoint(GHOST_TInt32 &x, GHOST_TInt32 &y, GHOST_TInt32
return;
}
- while (x - ofs < m_l)
- x += w - (ofs * 2);
- while (y - ofs < m_t)
- y += h - (ofs * 2);
- while (x + ofs > m_r)
- x -= w - (ofs * 2);
- while (y + ofs > m_b)
- y -= h - (ofs * 2);
+ if (axis & GHOST_kAxisX) {
+ while (x - ofs < m_l)
+ x += w - (ofs * 2);
+ while (x + ofs > m_r)
+ x -= w - (ofs * 2);
+ }
+ if (axis & GHOST_kGrabAxisY) {
+ while (y - ofs < m_t)
+ y += h - (ofs * 2);
+ while (y + ofs > m_b)
+ y -= h - (ofs * 2);
+ }
}
inline bool GHOST_Rect::isInside(GHOST_TInt32 x, GHOST_TInt32 y) const
diff --git a/intern/ghost/GHOST_Types.h b/intern/ghost/GHOST_Types.h
index f38154cbf94..68516c3ecf8 100644
--- a/intern/ghost/GHOST_Types.h
+++ b/intern/ghost/GHOST_Types.h
@@ -374,6 +374,13 @@ typedef enum {
GHOST_kGrabHide,
} GHOST_TGrabCursorMode;
+typedef enum {
+ /** Axis that cursor grab will wrap. */
+ GHOST_kGrabAxisNone = 0,
+ GHOST_kAxisX = (1 << 0),
+ GHOST_kGrabAxisY = (1 << 1),
+} GHOST_TAxisFlag;
+
typedef void *GHOST_TEventDataPtr;
typedef struct {
diff --git a/intern/ghost/intern/GHOST_C-api.cpp b/intern/ghost/intern/GHOST_C-api.cpp
index c8ee2e44efe..38ddf9819f9 100644
--- a/intern/ghost/intern/GHOST_C-api.cpp
+++ b/intern/ghost/intern/GHOST_C-api.cpp
@@ -324,6 +324,7 @@ GHOST_TSuccess GHOST_SetCursorPosition(GHOST_SystemHandle systemhandle,
GHOST_TSuccess GHOST_SetCursorGrab(GHOST_WindowHandle windowhandle,
GHOST_TGrabCursorMode mode,
+ GHOST_TAxisFlag wrap_axis,
int bounds[4],
const int mouse_ungrab_xy[2])
{
@@ -340,7 +341,7 @@ GHOST_TSuccess GHOST_SetCursorGrab(GHOST_WindowHandle windowhandle,
}
return window->setCursorGrab(
- mode, bounds ? &bounds_rect : NULL, mouse_ungrab_xy ? mouse_xy : NULL);
+ mode, wrap_axis, bounds ? &bounds_rect : NULL, mouse_ungrab_xy ? mouse_xy : NULL);
}
GHOST_TSuccess GHOST_GetModifierKeyState(GHOST_SystemHandle systemhandle,
diff --git a/intern/ghost/intern/GHOST_SystemCocoa.mm b/intern/ghost/intern/GHOST_SystemCocoa.mm
index f13c9d470a5..eb54ed20fe1 100644
--- a/intern/ghost/intern/GHOST_SystemCocoa.mm
+++ b/intern/ghost/intern/GHOST_SystemCocoa.mm
@@ -1590,7 +1590,9 @@ GHOST_TSuccess GHOST_SystemCocoa::handleMouseEvent(void *eventPtr)
// Warp mouse cursor if needed
GHOST_TInt32 warped_x_mouse = x_mouse;
GHOST_TInt32 warped_y_mouse = y_mouse;
- correctedBounds.wrapPoint(warped_x_mouse, warped_y_mouse, 4);
+
+ correctedBounds.wrapPoint(
+ warped_x_mouse, warped_y_mouse, 4, window->getCursorGrabAxis());
// Set new cursor position
if (x_mouse != warped_x_mouse || y_mouse != warped_y_mouse) {
diff --git a/intern/ghost/intern/GHOST_SystemSDL.cpp b/intern/ghost/intern/GHOST_SystemSDL.cpp
index 8fc7046565d..520c62719f8 100644
--- a/intern/ghost/intern/GHOST_SystemSDL.cpp
+++ b/intern/ghost/intern/GHOST_SystemSDL.cpp
@@ -369,9 +369,9 @@ void GHOST_SystemSDL::processEvent(SDL_Event *sdl_event)
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 */
- bounds.wrapPoint(x_new, y_new, 8); /* offset of one incase blender is at screen bounds */
+ /* Could also clamp to screen bounds wrap with a window outside the view will fail atm.
+ * Use offset of 8 in case the window is at screen bounds. */
+ bounds.wrapPoint(x_new, y_new, 8, window->getCursorGrabAxis());
window->getCursorGrabAccum(x_accum, y_accum);
// cant use setCursorPosition because the mouse may have no focus!
diff --git a/intern/ghost/intern/GHOST_SystemWin32.cpp b/intern/ghost/intern/GHOST_SystemWin32.cpp
index 9f7b6f75e41..0cc1b36f369 100644
--- a/intern/ghost/intern/GHOST_SystemWin32.cpp
+++ b/intern/ghost/intern/GHOST_SystemWin32.cpp
@@ -934,10 +934,9 @@ GHOST_EventCursor *GHOST_SystemWin32::processCursorEvent(GHOST_TEventType type,
window->getClientBounds(bounds);
}
- /* could also clamp to screen bounds
- * wrap with a window outside the view will fail atm */
-
- bounds.wrapPoint(x_new, y_new, 2); /* offset of one incase blender is at screen bounds */
+ /* Could also clamp to screen bounds wrap with a window outside the view will fail atm.
+ * Use offset of 8 in case the window is at screen bounds. */
+ bounds.wrapPoint(x_new, y_new, 2, window->getCursorGrabAxis());
window->getCursorGrabAccum(x_accum, y_accum);
if (x_new != x_screen || y_new != y_screen) {
diff --git a/intern/ghost/intern/GHOST_SystemX11.cpp b/intern/ghost/intern/GHOST_SystemX11.cpp
index b95e5fe3846..31411c823ae 100644
--- a/intern/ghost/intern/GHOST_SystemX11.cpp
+++ b/intern/ghost/intern/GHOST_SystemX11.cpp
@@ -868,9 +868,10 @@ void GHOST_SystemX11::processEvent(XEvent *xe)
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 */
- bounds.wrapPoint(x_new, y_new, 8); /* offset of one incase blender is at screen bounds */
+ /* Could also clamp to screen bounds wrap with a window outside the view will fail atm.
+ * Use offset of 8 in case the window is at screen bounds. */
+ bounds.wrapPoint(x_new, y_new, 8, window->getCursorGrabAxis());
+
window->getCursorGrabAccum(x_accum, y_accum);
if (x_new != xme.x_root || y_new != xme.y_root) {
diff --git a/intern/ghost/intern/GHOST_Window.cpp b/intern/ghost/intern/GHOST_Window.cpp
index 85283a34d2e..5649386063d 100644
--- a/intern/ghost/intern/GHOST_Window.cpp
+++ b/intern/ghost/intern/GHOST_Window.cpp
@@ -136,6 +136,7 @@ GHOST_TSuccess GHOST_Window::setCursorVisibility(bool visible)
}
GHOST_TSuccess GHOST_Window::setCursorGrab(GHOST_TGrabCursorMode mode,
+ GHOST_TAxisFlag wrap_axis,
GHOST_Rect *bounds,
GHOST_TInt32 mouse_ungrab_xy[2])
{
@@ -151,8 +152,9 @@ GHOST_TSuccess GHOST_Window::setCursorGrab(GHOST_TGrabCursorMode mode,
if (setWindowCursorGrab(mode)) {
- if (mode == GHOST_kGrabDisable)
+ if (mode == GHOST_kGrabDisable) {
m_cursorGrabBounds.m_l = m_cursorGrabBounds.m_r = -1;
+ }
else if (bounds) {
m_cursorGrabBounds = *bounds;
}
@@ -160,6 +162,7 @@ GHOST_TSuccess GHOST_Window::setCursorGrab(GHOST_TGrabCursorMode mode,
getClientBounds(m_cursorGrabBounds);
}
m_cursorGrab = mode;
+ m_cursorGrabAxis = wrap_axis;
return GHOST_kSuccess;
}
else {
diff --git a/intern/ghost/intern/GHOST_Window.h b/intern/ghost/intern/GHOST_Window.h
index b5399ec803e..acd0c93ff87 100644
--- a/intern/ghost/intern/GHOST_Window.h
+++ b/intern/ghost/intern/GHOST_Window.h
@@ -145,6 +145,7 @@ class GHOST_Window : public GHOST_IWindow {
inline bool getCursorVisibility() const;
inline GHOST_TGrabCursorMode getCursorGrabMode() const;
inline bool getCursorGrabModeIsWarp() const;
+ inline GHOST_TAxisFlag getCursorGrabAxis() const;
inline void getCursorGrabInitPos(GHOST_TInt32 &x, GHOST_TInt32 &y) const;
inline void getCursorGrabAccum(GHOST_TInt32 &x, GHOST_TInt32 &y) const;
inline void setCursorGrabAccum(GHOST_TInt32 x, GHOST_TInt32 y);
@@ -162,6 +163,7 @@ class GHOST_Window : public GHOST_IWindow {
* \return Indication of success.
*/
GHOST_TSuccess setCursorGrab(GHOST_TGrabCursorMode mode,
+
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list