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>2019-05-28 17:48:48 +0300
committerCampbell Barton <ideasman42@gmail.com>2019-05-28 17:52:43 +0300
commite4ac8ab212769b569334d0cd15d4bf04f42cbc89 (patch)
tree62cc58acd12f6f1bf974ff810900fa231d918354 /source/blender/windowmanager
parenta7ebb4b7d96b129d3ac1950ee415754b282bfbc4 (diff)
WM: support X/Y axis cursor wrapping
Operator flags to wrap on a single axis. D4865 by @Gvgeo with updates. Resolves T64585
Diffstat (limited to 'source/blender/windowmanager')
-rw-r--r--source/blender/windowmanager/WM_api.h2
-rw-r--r--source/blender/windowmanager/WM_types.h26
-rw-r--r--source/blender/windowmanager/gizmo/intern/wm_gizmo_map.c2
-rw-r--r--source/blender/windowmanager/intern/wm_cursors.c18
-rw-r--r--source/blender/windowmanager/intern/wm_event_system.c39
-rw-r--r--source/blender/windowmanager/intern/wm_operator_type.c15
6 files changed, 66 insertions, 36 deletions
diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h
index a5eb892841c..de6db8876f7 100644
--- a/source/blender/windowmanager/WM_api.h
+++ b/source/blender/windowmanager/WM_api.h
@@ -184,7 +184,7 @@ bool WM_cursor_set_from_tool(struct wmWindow *win, const ScrArea *sa, const AReg
void WM_cursor_modal_set(struct wmWindow *win, int curs);
void WM_cursor_modal_restore(struct wmWindow *win);
void WM_cursor_wait(bool val);
-void WM_cursor_grab_enable(struct wmWindow *win, bool wrap, bool hide, int bounds[4]);
+void WM_cursor_grab_enable(struct wmWindow *win, int wrap, bool hide, int bounds[4]);
void WM_cursor_grab_disable(struct wmWindow *win, const int mouse_ungrab_xy[2]);
void WM_cursor_time(struct wmWindow *win, int nr);
diff --git a/source/blender/windowmanager/WM_types.h b/source/blender/windowmanager/WM_types.h
index eddea3b2062..00c43450de7 100644
--- a/source/blender/windowmanager/WM_types.h
+++ b/source/blender/windowmanager/WM_types.h
@@ -141,21 +141,33 @@ enum {
OPTYPE_UNDO = (1 << 1), /* do undo push after after */
OPTYPE_BLOCKING = (1 << 2), /* let blender grab all input from the WM (X11) */
OPTYPE_MACRO = (1 << 3),
- OPTYPE_GRAB_CURSOR =
- (1 << 4), /* grabs the cursor and optionally enables continuous cursor wrapping */
- OPTYPE_PRESET = (1 << 5), /* show preset menu */
+
+ /* grabs the cursor and optionally enables continuous cursor wrapping. */
+ OPTYPE_GRAB_CURSOR_XY = (1 << 4),
+ OPTYPE_GRAB_CURSOR_X = (1 << 5), /* Only X axis. */
+ OPTYPE_GRAB_CURSOR_Y = (1 << 6), /* Only Y axis. */
+
+ OPTYPE_PRESET = (1 << 7), /* show preset menu */
/* some operators are mainly for internal use
* and don't make sense to be accessed from the
* search menu, even if poll() returns true.
* currently only used for the search toolbox */
- OPTYPE_INTERNAL = (1 << 6),
+ OPTYPE_INTERNAL = (1 << 8),
- OPTYPE_LOCK_BYPASS = (1 << 7), /* Allow operator to run when interface is locked */
+ OPTYPE_LOCK_BYPASS = (1 << 9), /* Allow operator to run when interface is locked */
OPTYPE_UNDO_GROUPED =
- (1 << 8), /* Special type of undo which doesn't store itself multiple times */
+ (1 << 10), /* Special type of undo which doesn't store itself multiple times */
OPTYPE_USE_EVAL_DATA =
- (1 << 9), /* Need evaluated data (i.e. a valid, up-to-date depsgraph for current context) */
+ (1 << 11), /* Need evaluated data (i.e. a valid, up-to-date depsgraph for current context) */
+};
+
+/* Wrap Axis. */
+enum {
+ CURSOR_WRAP_NONE = 0,
+ CURSOR_WRAP_X,
+ CURSOR_WRAP_Y,
+ CURSOR_WRAP_XY,
};
/* context to call operator in for WM_operator_name_call */
diff --git a/source/blender/windowmanager/gizmo/intern/wm_gizmo_map.c b/source/blender/windowmanager/gizmo/intern/wm_gizmo_map.c
index 6783a294500..ba9d59e82d6 100644
--- a/source/blender/windowmanager/gizmo/intern/wm_gizmo_map.c
+++ b/source/blender/windowmanager/gizmo/intern/wm_gizmo_map.c
@@ -1038,7 +1038,7 @@ void wm_gizmomap_modal_set(
gzmap->gzmap_context.modal = gz;
if ((gz->flag & WM_GIZMO_MOVE_CURSOR) && (event->is_motion_absolute == false)) {
- WM_cursor_grab_enable(win, true, true, NULL);
+ WM_cursor_grab_enable(win, CURSOR_WRAP_XY, true, NULL);
copy_v2_v2_int(gzmap->gzmap_context.event_xy, &event->x);
gzmap->gzmap_context.event_grabcursor = win->grabcursor;
}
diff --git a/source/blender/windowmanager/intern/wm_cursors.c b/source/blender/windowmanager/intern/wm_cursors.c
index 58cfc350b17..eeea3bf498c 100644
--- a/source/blender/windowmanager/intern/wm_cursors.c
+++ b/source/blender/windowmanager/intern/wm_cursors.c
@@ -223,12 +223,13 @@ void WM_cursor_wait(bool val)
/**
* \param bounds: can be NULL
*/
-void WM_cursor_grab_enable(wmWindow *win, bool wrap, bool hide, int bounds[4])
+void WM_cursor_grab_enable(wmWindow *win, int wrap, bool hide, int bounds[4])
{
/* Only grab cursor when not running debug.
* It helps not to get a stuck WM when hitting a breakpoint
* */
GHOST_TGrabCursorMode mode = GHOST_kGrabNormal;
+ GHOST_TAxisFlag mode_axis = GHOST_kAxisX | GHOST_kGrabAxisY;
if (bounds) {
wm_cursor_position_to_ghost(win, &bounds[0], &bounds[1]);
@@ -240,12 +241,20 @@ void WM_cursor_grab_enable(wmWindow *win, bool wrap, bool hide, int bounds[4])
}
else if (wrap) {
mode = GHOST_kGrabWrap;
+
+ if (wrap == CURSOR_WRAP_X) {
+ mode_axis = GHOST_kAxisX;
+ }
+ if (wrap == CURSOR_WRAP_Y) {
+ mode_axis = GHOST_kGrabAxisY;
+ }
}
+
if ((G.debug & G_DEBUG) == 0) {
if (win->ghostwin) {
/* Note: There is no tabletdata on Windows if no tablet device is connected. */
if (win->eventstate->is_motion_absolute == false) {
- GHOST_SetCursorGrab(win->ghostwin, mode, bounds, NULL);
+ GHOST_SetCursorGrab(win->ghostwin, mode, mode_axis, bounds, NULL);
}
win->grabcursor = mode;
@@ -260,10 +269,11 @@ void WM_cursor_grab_disable(wmWindow *win, const int mouse_ungrab_xy[2])
if (mouse_ungrab_xy) {
int mouse_xy[2] = {mouse_ungrab_xy[0], mouse_ungrab_xy[1]};
wm_cursor_position_to_ghost(win, &mouse_xy[0], &mouse_xy[1]);
- GHOST_SetCursorGrab(win->ghostwin, GHOST_kGrabDisable, NULL, mouse_xy);
+ GHOST_SetCursorGrab(
+ win->ghostwin, GHOST_kGrabDisable, GHOST_kGrabAxisNone, NULL, mouse_xy);
}
else {
- GHOST_SetCursorGrab(win->ghostwin, GHOST_kGrabDisable, NULL, NULL);
+ GHOST_SetCursorGrab(win->ghostwin, GHOST_kGrabDisable, GHOST_kGrabAxisNone, NULL, NULL);
}
win->grabcursor = GHOST_kGrabDisable;
diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c
index 51b2ca6a3d0..ac2bf1985d4 100644
--- a/source/blender/windowmanager/intern/wm_event_system.c
+++ b/source/blender/windowmanager/intern/wm_event_system.c
@@ -1469,26 +1469,20 @@ static int wm_operator_invoke(bContext *C,
*/
if (ot->flag & OPTYPE_BLOCKING || (op->opm && op->opm->type->flag & OPTYPE_BLOCKING)) {
int bounds[4] = {-1, -1, -1, -1};
- bool wrap;
-
- if (event == NULL) {
- wrap = false;
- }
- else if (op->opm) {
- wrap = (U.uiflag & USER_CONTINUOUS_MOUSE) &&
- ((op->opm->flag & OP_IS_MODAL_GRAB_CURSOR) ||
- (op->opm->type->flag & OPTYPE_GRAB_CURSOR));
- }
- else {
- wrap = (U.uiflag & USER_CONTINUOUS_MOUSE) &&
- ((op->flag & OP_IS_MODAL_GRAB_CURSOR) || (ot->flag & OPTYPE_GRAB_CURSOR));
- }
-
- /* exception, cont. grab in header is annoying */
- if (wrap) {
- ARegion *ar = CTX_wm_region(C);
- if (ar && ELEM(ar->regiontype, RGN_TYPE_HEADER, RGN_TYPE_TOOL_HEADER, RGN_TYPE_FOOTER)) {
- wrap = false;
+ int wrap = CURSOR_WRAP_NONE;
+
+ if (event && (U.uiflag & USER_CONTINUOUS_MOUSE)) {
+ const wmOperator *op_test = op->opm ? op->opm : op;
+ const wmOperatorType *ot_test = op_test->type;
+ if ((ot_test->flag & OPTYPE_GRAB_CURSOR_XY) ||
+ (op_test->flag & OP_IS_MODAL_GRAB_CURSOR)) {
+ wrap = CURSOR_WRAP_XY;
+ }
+ else if (ot_test->flag & OPTYPE_GRAB_CURSOR_X) {
+ wrap = CURSOR_WRAP_X;
+ }
+ else if (ot_test->flag & OPTYPE_GRAB_CURSOR_Y) {
+ wrap = CURSOR_WRAP_Y;
}
}
@@ -1497,6 +1491,11 @@ static int wm_operator_invoke(bContext *C,
ARegion *ar = CTX_wm_region(C);
ScrArea *sa = CTX_wm_area(C);
+ /* Wrap only in X for header. */
+ if (ar && ELEM(ar->regiontype, RGN_TYPE_HEADER, RGN_TYPE_TOOL_HEADER, RGN_TYPE_FOOTER)) {
+ wrap = CURSOR_WRAP_X;
+ }
+
if (ar && ar->regiontype == RGN_TYPE_WINDOW &&
BLI_rcti_isect_pt_v(&ar->winrct, &event->x)) {
winrect = &ar->winrct;
diff --git a/source/blender/windowmanager/intern/wm_operator_type.c b/source/blender/windowmanager/intern/wm_operator_type.c
index 179b4402200..7ae28f3f448 100644
--- a/source/blender/windowmanager/intern/wm_operator_type.c
+++ b/source/blender/windowmanager/intern/wm_operator_type.c
@@ -430,9 +430,18 @@ static int wm_macro_modal(bContext *C, wmOperator *op, const wmEvent *event)
* */
if (op->opm->type->flag & OPTYPE_BLOCKING) {
int bounds[4] = {-1, -1, -1, -1};
- const bool wrap = ((U.uiflag & USER_CONTINUOUS_MOUSE) &&
- ((op->opm->flag & OP_IS_MODAL_GRAB_CURSOR) ||
- (op->opm->type->flag & OPTYPE_GRAB_CURSOR)));
+ int wrap = CURSOR_WRAP_NONE;
+
+ if ((op->opm->flag & OP_IS_MODAL_GRAB_CURSOR) ||
+ (op->opm->type->flag & OPTYPE_GRAB_CURSOR_XY)) {
+ wrap = CURSOR_WRAP_XY;
+ }
+ else if (op->opm->type->flag & OPTYPE_GRAB_CURSOR_X) {
+ wrap = CURSOR_WRAP_X;
+ }
+ else if (op->opm->type->flag & OPTYPE_GRAB_CURSOR_Y) {
+ wrap = CURSOR_WRAP_Y;
+ }
if (wrap) {
ARegion *ar = CTX_wm_region(C);