Manipulator: make grab-cursor a manipulator flag
As with operators, allow manipulators to grab the cursor. Previously this was enabled for all 3D manipulators.
This commit is contained in:
@@ -1177,14 +1177,17 @@ static ManipulatorGroup *manipulatorgroup_init(wmManipulatorGroup *mgroup)
|
||||
#define MANIPULATOR_NEW_ARROW(v, draw_style) { \
|
||||
man->manipulators[v] = WM_manipulator_new_ptr(wt_arrow, mgroup, NULL); \
|
||||
RNA_enum_set(man->manipulators[v]->ptr, "draw_style", draw_style); \
|
||||
WM_manipulator_set_flag(man->manipulators[v], WM_MANIPULATOR_GRAB_CURSOR, true); \
|
||||
} ((void)0)
|
||||
#define MANIPULATOR_NEW_DIAL(v, draw_options) { \
|
||||
man->manipulators[v] = WM_manipulator_new_ptr(wt_dial, mgroup, NULL); \
|
||||
RNA_enum_set(man->manipulators[v]->ptr, "draw_options", draw_options); \
|
||||
WM_manipulator_set_flag(man->manipulators[v], WM_MANIPULATOR_GRAB_CURSOR, true); \
|
||||
} ((void)0)
|
||||
#define MANIPULATOR_NEW_PRIM(v, draw_style) { \
|
||||
man->manipulators[v] = WM_manipulator_new_ptr(wt_prim, mgroup, NULL); \
|
||||
RNA_enum_set(man->manipulators[v]->ptr, "draw_style", draw_style); \
|
||||
WM_manipulator_set_flag(man->manipulators[v], WM_MANIPULATOR_GRAB_CURSOR, true); \
|
||||
} ((void)0)
|
||||
|
||||
/* add/init widgets - order matters! */
|
||||
@@ -1604,6 +1607,7 @@ static void WIDGETGROUP_xform_cage_refresh(const bContext *C, wmManipulatorGroup
|
||||
manipulator_prepare_mat(C, v3d, rv3d, &tbounds);
|
||||
|
||||
WM_manipulator_set_flag(mpr, WM_MANIPULATOR_HIDDEN, false);
|
||||
WM_manipulator_set_flag(mpr, WM_MANIPULATOR_GRAB_CURSOR, true);
|
||||
|
||||
float dims[3];
|
||||
sub_v3_v3v3(dims, rv3d->tw_axis_max, rv3d->tw_axis_min);
|
||||
|
||||
@@ -401,6 +401,7 @@ RNA_MANIPULATOR_GENERIC_FLAG_RW_DEF(flag_use_draw_value, flag, WM_MANIPULATOR_DR
|
||||
RNA_MANIPULATOR_GENERIC_FLAG_RW_DEF(flag_use_draw_offset_scale, flag, WM_MANIPULATOR_DRAW_OFFSET_SCALE);
|
||||
RNA_MANIPULATOR_GENERIC_FLAG_NEG_RW_DEF(flag_use_draw_scale, flag, WM_MANIPULATOR_DRAW_OFFSET_SCALE);
|
||||
RNA_MANIPULATOR_GENERIC_FLAG_RW_DEF(flag_hide, flag, WM_MANIPULATOR_HIDDEN);
|
||||
RNA_MANIPULATOR_GENERIC_FLAG_RW_DEF(flag_use_grab_cursor, flag, WM_MANIPULATOR_GRAB_CURSOR);
|
||||
|
||||
/* wmManipulator.state */
|
||||
RNA_MANIPULATOR_FLAG_RO_DEF(state_is_highlight, state, WM_MANIPULATOR_STATE_HIGHLIGHT);
|
||||
@@ -1087,6 +1088,13 @@ static void rna_def_manipulator(BlenderRNA *brna, PropertyRNA *cprop)
|
||||
prop, "rna_Manipulator_flag_hide_get", "rna_Manipulator_flag_hide_set");
|
||||
RNA_def_property_ui_text(prop, "Hide", "");
|
||||
RNA_def_property_update(prop, NC_SCREEN | NA_EDITED, NULL);
|
||||
/* WM_MANIPULATOR_GRAB_CURSOR */
|
||||
prop = RNA_def_property(srna, "use_grab_cursor", PROP_BOOLEAN, PROP_NONE);
|
||||
RNA_def_property_boolean_funcs(
|
||||
prop, "rna_Manipulator_flag_use_grab_cursor_get", "rna_Manipulator_flag_use_grab_cursor_set");
|
||||
RNA_def_property_ui_text(prop, "Grab Cursor", "");
|
||||
RNA_def_property_update(prop, NC_SCREEN | NA_EDITED, NULL);
|
||||
|
||||
/* WM_MANIPULATOR_DRAW_HOVER */
|
||||
prop = RNA_def_property(srna, "use_draw_hover", PROP_BOOLEAN, PROP_NONE);
|
||||
RNA_def_property_boolean_funcs(
|
||||
|
||||
@@ -80,6 +80,10 @@ typedef enum eWM_ManipulatorFlag {
|
||||
* This simply skips scale when calculating the final matrix.
|
||||
* Needed when the manipulator needs to align with the interface underneath it. */
|
||||
WM_MANIPULATOR_DRAW_NO_SCALE = (1 << 5),
|
||||
/**
|
||||
* Hide the cursor and lock it's position while interacting with this manipulator.
|
||||
*/
|
||||
WM_MANIPULATOR_GRAB_CURSOR = (1 << 6),
|
||||
} eWM_ManipulatorFlag;
|
||||
|
||||
/**
|
||||
|
||||
@@ -112,6 +112,9 @@ struct wmManipulatorMap {
|
||||
struct wmManipulator *modal;
|
||||
/* array for all selected manipulators */
|
||||
struct wmManipulatorMapSelectState select;
|
||||
/* cursor location at point of entering modal (see: WM_MANIPULATOR_GRAB_CURSOR) */
|
||||
int event_xy[2];
|
||||
short event_grabcursor;
|
||||
} mmap_context;
|
||||
};
|
||||
|
||||
|
||||
@@ -886,9 +886,9 @@ void wm_manipulatormap_modal_set(
|
||||
{
|
||||
if (enable) {
|
||||
BLI_assert(mmap->mmap_context.modal == NULL);
|
||||
wmWindow *win = CTX_wm_window(C);
|
||||
|
||||
/* For now only grab cursor for 3D manipulators. */
|
||||
bool grab_cursor = (mpr->parent_mgroup->type->flag & WM_MANIPULATORGROUPTYPE_3D) != 0;
|
||||
int retval = OPERATOR_RUNNING_MODAL;
|
||||
|
||||
if (mpr->type->invoke &&
|
||||
@@ -904,6 +904,17 @@ void wm_manipulatormap_modal_set(
|
||||
mpr->state |= WM_MANIPULATOR_STATE_MODAL;
|
||||
mmap->mmap_context.modal = mpr;
|
||||
|
||||
if ((mpr->flag & WM_MANIPULATOR_GRAB_CURSOR) &&
|
||||
(WM_event_is_absolute(event) == false))
|
||||
{
|
||||
WM_cursor_grab_enable(win, true, true, NULL);
|
||||
copy_v2_v2_int(mmap->mmap_context.event_xy, &event->x);
|
||||
mmap->mmap_context.event_grabcursor = win->grabcursor;
|
||||
}
|
||||
else {
|
||||
mmap->mmap_context.event_xy[0] = INT_MAX;
|
||||
}
|
||||
|
||||
struct wmManipulatorOpElem *mpop = WM_manipulator_operator_get(mpr, mpr->highlight_part);
|
||||
if (mpop && mpop->type) {
|
||||
WM_operator_name_call_ptr(C, mpop->type, WM_OP_INVOKE_DEFAULT, &mpop->ptr);
|
||||
@@ -915,10 +926,6 @@ void wm_manipulatormap_modal_set(
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (grab_cursor) {
|
||||
WM_cursor_grab_enable(CTX_wm_window(C), true, true, NULL);
|
||||
}
|
||||
}
|
||||
else {
|
||||
BLI_assert(ELEM(mmap->mmap_context.modal, NULL, mpr));
|
||||
@@ -931,7 +938,18 @@ void wm_manipulatormap_modal_set(
|
||||
mmap->mmap_context.modal = NULL;
|
||||
|
||||
if (C) {
|
||||
WM_cursor_grab_disable(CTX_wm_window(C), NULL);
|
||||
wmWindow *win = CTX_wm_window(C);
|
||||
if (mmap->mmap_context.event_xy[0] != INT_MAX) {
|
||||
/* Check if some other part of Blender (typically operators)
|
||||
* have adjusted the grab mode since it was set.
|
||||
* If so: warp, so we have a predictable outcome. */
|
||||
if (mmap->mmap_context.event_grabcursor == win->grabcursor) {
|
||||
WM_cursor_grab_disable(win, mmap->mmap_context.event_xy);
|
||||
}
|
||||
else {
|
||||
WM_cursor_warp(win, UNPACK2(mmap->mmap_context.event_xy));
|
||||
}
|
||||
}
|
||||
ED_region_tag_redraw(CTX_wm_region(C));
|
||||
WM_event_add_mousemove(C);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user