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>2017-08-24 10:04:28 +0300
committerCampbell Barton <ideasman42@gmail.com>2017-08-24 10:04:28 +0300
commite20c825b05e00954995fe2ed74e7fb409d09abe8 (patch)
tree4491775682a618cb6e2e902bfe4ec61d72966d7b
parent134e927965c9871df8a9e13806f1cd48f4d43f16 (diff)
Manipulator: modal callback can now cancel & pass events
Re-use operator return flags for manipulator modal & invoke, this means manipulators can allow navigation or other events to be handled as they run - see T52499
-rw-r--r--release/scripts/templates_py/manipulator_custom_geometry.py2
-rw-r--r--source/blender/editors/manipulator_library/manipulator_types/arrow2d_manipulator.c4
-rw-r--r--source/blender/editors/manipulator_library/manipulator_types/arrow3d_manipulator.c8
-rw-r--r--source/blender/editors/manipulator_library/manipulator_types/cage2d_manipulator.c10
-rw-r--r--source/blender/editors/manipulator_library/manipulator_types/dial3d_manipulator.c9
-rw-r--r--source/blender/editors/manipulator_library/manipulator_types/grab3d_manipulator.c12
-rw-r--r--source/blender/editors/manipulator_library/manipulator_types/primitive3d_manipulator.c4
-rw-r--r--source/blender/editors/transform/transform_manipulator.c4
-rw-r--r--source/blender/editors/transform/transform_manipulator2d.c4
-rw-r--r--source/blender/makesrna/intern/rna_wm_manipulator.c24
-rw-r--r--source/blender/windowmanager/manipulators/intern/wm_manipulator.c2
-rw-r--r--source/blender/windowmanager/manipulators/intern/wm_manipulator_group.c21
-rw-r--r--source/blender/windowmanager/manipulators/intern/wm_manipulator_map.c51
-rw-r--r--source/blender/windowmanager/manipulators/wm_manipulator_fn.h4
-rw-r--r--source/blender/windowmanager/manipulators/wm_manipulator_wmapi.h5
15 files changed, 107 insertions, 57 deletions
diff --git a/release/scripts/templates_py/manipulator_custom_geometry.py b/release/scripts/templates_py/manipulator_custom_geometry.py
index 38f7a358b2a..0f1ab72f9ef 100644
--- a/release/scripts/templates_py/manipulator_custom_geometry.py
+++ b/release/scripts/templates_py/manipulator_custom_geometry.py
@@ -93,6 +93,7 @@ class MyCustomShapeWidget(Manipulator):
def invoke(self, context, event):
self.init_mouse_y = event.mouse_y
self.init_value = self.target_get_value("offset")
+ return {'RUNNING_MODAL'}
def exit(self, context, cancel):
context.area.header_text_set()
@@ -108,6 +109,7 @@ class MyCustomShapeWidget(Manipulator):
value = self.init_value + delta
self.target_set_value("offset", value)
context.area.header_text_set("My Manipulator: %.4f" % value)
+ return {'RUNNING_MODAL'}
class MyCustomShapeWidgetGroup(ManipulatorGroup):
diff --git a/source/blender/editors/manipulator_library/manipulator_types/arrow2d_manipulator.c b/source/blender/editors/manipulator_library/manipulator_types/arrow2d_manipulator.c
index 1185bec2a2d..67583d28668 100644
--- a/source/blender/editors/manipulator_library/manipulator_types/arrow2d_manipulator.c
+++ b/source/blender/editors/manipulator_library/manipulator_types/arrow2d_manipulator.c
@@ -123,7 +123,7 @@ static void manipulator_arrow2d_setup(wmManipulator *mpr)
mpr->flag |= WM_MANIPULATOR_DRAW_MODAL;
}
-static void manipulator_arrow2d_invoke(
+static int manipulator_arrow2d_invoke(
bContext *UNUSED(C), wmManipulator *mpr, const wmEvent *UNUSED(event))
{
ManipulatorInteraction *inter = MEM_callocN(sizeof(ManipulatorInteraction), __func__);
@@ -132,6 +132,8 @@ static void manipulator_arrow2d_invoke(
WM_manipulator_calc_matrix_final(mpr, inter->init_matrix_final);
mpr->interaction_data = inter;
+
+ return OPERATOR_RUNNING_MODAL;
}
static int manipulator_arrow2d_test_select(
diff --git a/source/blender/editors/manipulator_library/manipulator_types/arrow3d_manipulator.c b/source/blender/editors/manipulator_library/manipulator_types/arrow3d_manipulator.c
index 61f5a7b2786..5c984de2e27 100644
--- a/source/blender/editors/manipulator_library/manipulator_types/arrow3d_manipulator.c
+++ b/source/blender/editors/manipulator_library/manipulator_types/arrow3d_manipulator.c
@@ -235,7 +235,7 @@ static void manipulator_arrow_draw(const bContext *UNUSED(C), wmManipulator *mpr
* Calculate arrow offset independent from prop min value,
* meaning the range will not be offset by min value first.
*/
-static void manipulator_arrow_modal(
+static int manipulator_arrow_modal(
bContext *C, wmManipulator *mpr, const wmEvent *event,
eWM_ManipulatorTweak tweak_flag)
{
@@ -352,6 +352,8 @@ static void manipulator_arrow_modal(
/* tag the region for redraw */
ED_region_tag_redraw(ar);
WM_event_add_mousemove(C);
+
+ return OPERATOR_RUNNING_MODAL;
}
static void manipulator_arrow_setup(wmManipulator *mpr)
@@ -363,7 +365,7 @@ static void manipulator_arrow_setup(wmManipulator *mpr)
arrow->data.range_fac = 1.0f;
}
-static void manipulator_arrow_invoke(
+static int manipulator_arrow_invoke(
bContext *UNUSED(C), wmManipulator *mpr, const wmEvent *event)
{
ArrowManipulator3D *arrow = (ArrowManipulator3D *)mpr;
@@ -384,6 +386,8 @@ static void manipulator_arrow_invoke(
WM_manipulator_calc_matrix_final(mpr, inter->init_matrix_final);
mpr->interaction_data = inter;
+
+ return OPERATOR_RUNNING_MODAL;
}
static void manipulator_arrow_property_update(wmManipulator *mpr, wmManipulatorProperty *mpr_prop)
diff --git a/source/blender/editors/manipulator_library/manipulator_types/cage2d_manipulator.c b/source/blender/editors/manipulator_library/manipulator_types/cage2d_manipulator.c
index 40ef5f48492..311c8acde9e 100644
--- a/source/blender/editors/manipulator_library/manipulator_types/cage2d_manipulator.c
+++ b/source/blender/editors/manipulator_library/manipulator_types/cage2d_manipulator.c
@@ -479,7 +479,7 @@ static void manipulator_rect_transform_setup(wmManipulator *mpr)
mpr->flag |= WM_MANIPULATOR_DRAW_MODAL;
}
-static void manipulator_rect_transform_invoke(
+static int manipulator_rect_transform_invoke(
bContext *C, wmManipulator *mpr, const wmEvent *event)
{
RectTransformInteraction *data = MEM_callocN(sizeof(RectTransformInteraction), "cage_interaction");
@@ -493,9 +493,11 @@ static void manipulator_rect_transform_invoke(
}
mpr->interaction_data = data;
+
+ return OPERATOR_RUNNING_MODAL;
}
-static void manipulator_rect_transform_modal(
+static int manipulator_rect_transform_modal(
bContext *C, wmManipulator *mpr, const wmEvent *event,
eWM_ManipulatorTweak UNUSED(tweak_flag))
{
@@ -514,7 +516,7 @@ static void manipulator_rect_transform_modal(
if (manipulator_window_project_2d(
C, mpr, (const float[2]){UNPACK2(event->mval)}, 2, false, point_local) == false)
{
- return;
+ return OPERATOR_RUNNING_MODAL;
}
float value_x = (point_local[0] - data->orig_mouse[0]);
@@ -636,6 +638,8 @@ static void manipulator_rect_transform_modal(
/* tag the region for redraw */
ED_region_tag_redraw(CTX_wm_region(C));
+
+ return OPERATOR_RUNNING_MODAL;
}
static void manipulator_rect_transform_property_update(wmManipulator *mpr, wmManipulatorProperty *mpr_prop)
diff --git a/source/blender/editors/manipulator_library/manipulator_types/dial3d_manipulator.c b/source/blender/editors/manipulator_library/manipulator_types/dial3d_manipulator.c
index f7511c581ed..257ccfa88d8 100644
--- a/source/blender/editors/manipulator_library/manipulator_types/dial3d_manipulator.c
+++ b/source/blender/editors/manipulator_library/manipulator_types/dial3d_manipulator.c
@@ -71,7 +71,7 @@
/* to use custom dials exported to geom_dial_manipulator.c */
// #define USE_MANIPULATOR_CUSTOM_DIAL
-static void manipulator_dial_modal(
+static int manipulator_dial_modal(
bContext *C, wmManipulator *mpr, const wmEvent *event,
eWM_ManipulatorTweak tweak_flag);
@@ -384,7 +384,7 @@ static void manipulator_dial_draw(const bContext *C, wmManipulator *mpr)
}
}
-static void manipulator_dial_modal(
+static int manipulator_dial_modal(
bContext *C, wmManipulator *mpr, const wmEvent *event,
eWM_ManipulatorTweak UNUSED(tweak_flag))
{
@@ -408,6 +408,7 @@ static void manipulator_dial_modal(
if (WM_manipulator_target_property_is_valid(mpr_prop)) {
WM_manipulator_target_property_value_set(C, mpr, mpr_prop, inter->init_prop_angle + angle_delta);
}
+ return OPERATOR_RUNNING_MODAL;
}
@@ -419,7 +420,7 @@ static void manipulator_dial_setup(wmManipulator *mpr)
copy_v3_v3(mpr->matrix_basis[2], dir_default);
}
-static void manipulator_dial_invoke(
+static int manipulator_dial_invoke(
bContext *UNUSED(C), wmManipulator *mpr, const wmEvent *event)
{
DialInteraction *inter = MEM_callocN(sizeof(DialInteraction), __func__);
@@ -433,6 +434,8 @@ static void manipulator_dial_invoke(
}
mpr->interaction_data = inter;
+
+ return OPERATOR_RUNNING_MODAL;
}
/* -------------------------------------------------------------------- */
diff --git a/source/blender/editors/manipulator_library/manipulator_types/grab3d_manipulator.c b/source/blender/editors/manipulator_library/manipulator_types/grab3d_manipulator.c
index 38e350762c1..a714dd0f061 100644
--- a/source/blender/editors/manipulator_library/manipulator_types/grab3d_manipulator.c
+++ b/source/blender/editors/manipulator_library/manipulator_types/grab3d_manipulator.c
@@ -77,7 +77,7 @@ static void manipulator_grab_matrix_basis_get(const wmManipulator *mpr, float r_
add_v3_v3(r_matrix[3], grab->prop_co);
}
-static void manipulator_grab_modal(
+static int manipulator_grab_modal(
bContext *C, wmManipulator *mpr, const wmEvent *event,
eWM_ManipulatorTweak tweak_flag);
@@ -236,7 +236,7 @@ static void manipulator_grab_draw(const bContext *C, wmManipulator *mpr)
glDisable(GL_BLEND);
}
-static void manipulator_grab_modal(
+static int manipulator_grab_modal(
bContext *C, wmManipulator *mpr, const wmEvent *event,
eWM_ManipulatorTweak UNUSED(tweak_flag))
{
@@ -255,7 +255,7 @@ static void manipulator_grab_modal(
(manipulator_window_project_2d(
C, mpr, (const float[2]){UNPACK2(event->mval)}, 2, false, mval_proj_curr) == false))
{
- return;
+ return OPERATOR_RUNNING_MODAL;
}
sub_v2_v2v2(prop_delta, mval_proj_curr, mval_proj_init);
prop_delta[2] = 0.0f;
@@ -269,9 +269,11 @@ static void manipulator_grab_modal(
}
ED_region_tag_redraw(ar);
+
+ return OPERATOR_RUNNING_MODAL;
}
-static void manipulator_grab_invoke(
+static int manipulator_grab_invoke(
bContext *UNUSED(C), wmManipulator *mpr, const wmEvent *event)
{
GrabInteraction *inter = MEM_callocN(sizeof(GrabInteraction), __func__);
@@ -298,6 +300,8 @@ static void manipulator_grab_invoke(
}
mpr->interaction_data = inter;
+
+ return OPERATOR_RUNNING_MODAL;
}
diff --git a/source/blender/editors/manipulator_library/manipulator_types/primitive3d_manipulator.c b/source/blender/editors/manipulator_library/manipulator_types/primitive3d_manipulator.c
index 44878a24430..eea14f2033f 100644
--- a/source/blender/editors/manipulator_library/manipulator_types/primitive3d_manipulator.c
+++ b/source/blender/editors/manipulator_library/manipulator_types/primitive3d_manipulator.c
@@ -145,7 +145,7 @@ static void manipulator_primitive_setup(wmManipulator *mpr)
mpr->flag |= WM_MANIPULATOR_DRAW_MODAL;
}
-static void manipulator_primitive_invoke(
+static int manipulator_primitive_invoke(
bContext *UNUSED(C), wmManipulator *mpr, const wmEvent *UNUSED(event))
{
ManipulatorInteraction *inter = MEM_callocN(sizeof(ManipulatorInteraction), __func__);
@@ -153,6 +153,8 @@ static void manipulator_primitive_invoke(
WM_manipulator_calc_matrix_final(mpr, inter->init_matrix_final);
mpr->interaction_data = inter;
+
+ return OPERATOR_RUNNING_MODAL;
}
/* -------------------------------------------------------------------- */
diff --git a/source/blender/editors/transform/transform_manipulator.c b/source/blender/editors/transform/transform_manipulator.c
index 8825d1e55bc..84892ee7641 100644
--- a/source/blender/editors/transform/transform_manipulator.c
+++ b/source/blender/editors/transform/transform_manipulator.c
@@ -1139,7 +1139,7 @@ static ManipulatorGroup *manipulatorgroup_init(wmManipulatorGroup *mgroup)
/**
* Custom handler for manipulator widgets
*/
-static void manipulator_modal(
+static int manipulator_modal(
bContext *C, wmManipulator *widget, const wmEvent *UNUSED(event),
eWM_ManipulatorTweak UNUSED(tweak_flag))
{
@@ -1154,6 +1154,8 @@ static void manipulator_modal(
}
ED_region_tag_redraw(ar);
+
+ return OPERATOR_RUNNING_MODAL;
}
static void WIDGETGROUP_manipulator_setup(const bContext *UNUSED(C), wmManipulatorGroup *mgroup)
diff --git a/source/blender/editors/transform/transform_manipulator2d.c b/source/blender/editors/transform/transform_manipulator2d.c
index 2059d646551..96c87039fbf 100644
--- a/source/blender/editors/transform/transform_manipulator2d.c
+++ b/source/blender/editors/transform/transform_manipulator2d.c
@@ -167,7 +167,7 @@ BLI_INLINE void manipulator2d_origin_to_region(ARegion *ar, float *r_origin)
/**
* Custom handler for manipulator widgets
*/
-static void manipulator2d_modal(
+static int manipulator2d_modal(
bContext *C, wmManipulator *widget, const wmEvent *UNUSED(event),
eWM_ManipulatorTweak UNUSED(tweak_flag))
{
@@ -179,6 +179,8 @@ static void manipulator2d_modal(
WM_manipulator_set_matrix_location(widget, origin);
ED_region_tag_redraw(ar);
+
+ return OPERATOR_RUNNING_MODAL;
}
void ED_widgetgroup_manipulator2d_setup(const bContext *UNUSED(C), wmManipulatorGroup *mgroup)
diff --git a/source/blender/makesrna/intern/rna_wm_manipulator.c b/source/blender/makesrna/intern/rna_wm_manipulator.c
index e6bf68c4f3e..4f94b996046 100644
--- a/source/blender/makesrna/intern/rna_wm_manipulator.c
+++ b/source/blender/makesrna/intern/rna_wm_manipulator.c
@@ -136,7 +136,7 @@ static int rna_manipulator_test_select_cb(
return intersect_id;
}
-static void rna_manipulator_modal_cb(
+static int rna_manipulator_modal_cb(
struct bContext *C, struct wmManipulator *mpr, const struct wmEvent *event,
eWM_ManipulatorTweak tweak_flag)
{
@@ -154,7 +154,13 @@ static void rna_manipulator_modal_cb(
RNA_parameter_set_lookup(&list, "event", &event);
RNA_parameter_set_lookup(&list, "tweak", &tweak_flag_int);
mgroup->type->ext.call((bContext *)C, &mpr_ptr, func, &list);
+
+ void *ret;
+ RNA_parameter_get_lookup(&list, "result", &ret);
+ int ret_enum = *(int *)ret;
+
RNA_parameter_list_free(&list);
+ return ret_enum;
}
static void rna_manipulator_setup_cb(
@@ -174,7 +180,7 @@ static void rna_manipulator_setup_cb(
}
-static void rna_manipulator_invoke_cb(
+static int rna_manipulator_invoke_cb(
struct bContext *C, struct wmManipulator *mpr, const struct wmEvent *event)
{
extern FunctionRNA rna_Manipulator_invoke_func;
@@ -189,7 +195,13 @@ static void rna_manipulator_invoke_cb(
RNA_parameter_set_lookup(&list, "context", &C);
RNA_parameter_set_lookup(&list, "event", &event);
mgroup->type->ext.call((bContext *)C, &mpr_ptr, func, &list);
+
+ void *ret;
+ RNA_parameter_get_lookup(&list, "result", &ret);
+ int ret_enum = *(int *)ret;
+
RNA_parameter_list_free(&list);
+ return ret_enum;
}
static void rna_manipulator_exit_cb(
@@ -949,10 +961,10 @@ static void rna_def_manipulator(BlenderRNA *brna, PropertyRNA *cprop)
parm = RNA_def_pointer(func, "event", "Event", "", "");
RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED);
/* TODO, shuold be a enum-flag */
- parm = RNA_def_enum(func, "tweak", tweak_actions, 0, "Tweak", "");
+ parm = RNA_def_enum_flag(func, "tweak", tweak_actions, 0, "Tweak", "");
RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
- RNA_def_property_flag(parm, PROP_ENUM_FLAG);
-
+ parm = RNA_def_enum_flag(func, "result", rna_enum_operator_return_items, OPERATOR_CANCELLED, "result", "");
+ RNA_def_function_return(func, parm);
/* wmManipulator.property_update */
/* TODO */
@@ -969,6 +981,8 @@ static void rna_def_manipulator(BlenderRNA *brna, PropertyRNA *cprop)
RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED);
parm = RNA_def_pointer(func, "event", "Event", "", "");
RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED);
+ parm = RNA_def_enum_flag(func, "result", rna_enum_operator_return_items, OPERATOR_CANCELLED, "result", "");
+ RNA_def_function_return(func, parm);
/* wmManipulator.exit */
func = RNA_def_function(srna, "exit", NULL);
diff --git a/source/blender/windowmanager/manipulators/intern/wm_manipulator.c b/source/blender/windowmanager/manipulators/intern/wm_manipulator.c
index fe7dbb56d6e..316254202fa 100644
--- a/source/blender/windowmanager/manipulators/intern/wm_manipulator.c
+++ b/source/blender/windowmanager/manipulators/intern/wm_manipulator.c
@@ -204,7 +204,7 @@ void WM_manipulator_unlink(ListBase *manipulatorlist, wmManipulatorMap *mmap, wm
wm_manipulatormap_highlight_set(mmap, C, NULL, 0);
}
if (mpr->state & WM_MANIPULATOR_STATE_MODAL) {
- wm_manipulatormap_modal_set(mmap, C, NULL, NULL);
+ wm_manipulatormap_modal_set(mmap, C, mpr, NULL, false);
}
/* Unlink instead of setting so we don't run callbacks. */
if (mpr->state & WM_MANIPULATOR_STATE_SELECT) {
diff --git a/source/blender/windowmanager/manipulators/intern/wm_manipulator_group.c b/source/blender/windowmanager/manipulators/intern/wm_manipulator_group.c
index 6f322933e2a..808051560bc 100644
--- a/source/blender/windowmanager/manipulators/intern/wm_manipulator_group.c
+++ b/source/blender/windowmanager/manipulators/intern/wm_manipulator_group.c
@@ -98,7 +98,7 @@ void wm_manipulatorgroup_free(bContext *C, wmManipulatorGroup *mgroup)
wm_manipulatormap_highlight_set(mmap, C, NULL, 0);
}
if (mmap->mmap_context.modal && mmap->mmap_context.modal->parent_mgroup == mgroup) {
- wm_manipulatormap_modal_set(mmap, C, NULL, NULL);
+ wm_manipulatormap_modal_set(mmap, C, mmap->mmap_context.modal, NULL, false);
}
for (wmManipulator *mpr = mgroup->manipulators.first, *mpr_next; mpr; mpr = mpr_next) {
@@ -313,7 +313,7 @@ static void manipulator_tweak_finish(bContext *C, wmOperator *op, const bool can
if (mtweak->mpr_modal->type->exit) {
mtweak->mpr_modal->type->exit(C, mtweak->mpr_modal, cancel);
}
- wm_manipulatormap_modal_set(mtweak->mmap, C, NULL, NULL);
+ wm_manipulatormap_modal_set(mtweak->mmap, C, mtweak->mpr_modal, NULL, false);
MEM_freeN(mtweak);
}
@@ -359,11 +359,12 @@ static int manipulator_tweak_modal(bContext *C, wmOperator *op, const wmEvent *e
}
/* handle manipulator */
- if (mpr->custom_modal) {
- mpr->custom_modal(C, mpr, event, mtweak->flag);
- }
- else if (mpr->type->modal) {
- mpr->type->modal(C, mpr, event, mtweak->flag);
+ wmManipulatorFnModal modal_fn = mpr->custom_modal ? mpr->custom_modal : mpr->type->modal;
+ int retval = modal_fn(C, mpr, event, mtweak->flag);
+
+ if ((retval & OPERATOR_RUNNING_MODAL) == 0) {
+ manipulator_tweak_finish(C, op, (retval & OPERATOR_CANCELLED) != 0);
+ return OPERATOR_FINISHED;
}
/* always return PASS_THROUGH so modal handlers
@@ -385,7 +386,7 @@ static int manipulator_tweak_invoke(bContext *C, wmOperator *op, const wmEvent *
/* activate highlighted manipulator */
- wm_manipulatormap_modal_set(mmap, C, event, mpr);
+ wm_manipulatormap_modal_set(mmap, C, mpr, event, true);
/* XXX temporary workaround for modal manipulator operator
* conflicting with modal operator attached to manipulator */
@@ -395,6 +396,10 @@ static int manipulator_tweak_invoke(bContext *C, wmOperator *op, const wmEvent *
}
}
+ /* Couldn't start the manipulator. */
+ if ((mpr->state & WM_MANIPULATOR_STATE_MODAL) == 0) {
+ return OPERATOR_PASS_THROUGH;
+ }
ManipulatorTweakData *mtweak = MEM_mallocN(sizeof(ManipulatorTweakData), __func__);
diff --git a/source/blender/windowmanager/manipulators/intern/wm_manipulator_map.c b/source/blender/windowmanager/manipulators/intern/wm_manipulator_map.c
index 4273bc75cc9..9155c03db2a 100644
--- a/source/blender/windowmanager/manipulators/intern/wm_manipulator_map.c
+++ b/source/blender/windowmanager/manipulators/intern/wm_manipulator_map.c
@@ -638,18 +638,21 @@ void wm_manipulatormaps_handled_modal_update(
if (mpr && (mpr->op_data.type != NULL) &&
(mpr->op_data.type == handler->op->type))
{
- if (mpr->custom_modal) {
- mpr->custom_modal(C, mpr, event, 0);
- }
- else if (mpr->type->modal) {
- mpr->type->modal(C, mpr, event, 0);
+ wmManipulatorFnModal modal_fn = mpr->custom_modal ? mpr->custom_modal : mpr->type->modal;
+ if (modal_fn != NULL) {
+ int retval = modal_fn(C, mpr, event, 0);
+ /* The manipulator is tried to the operator, we can't choose when to exit. */
+ BLI_assert(retval & OPERATOR_RUNNING_MODAL);
+ UNUSED_VARS_NDEBUG(retval);
}
}
}
/* operator not running anymore */
else {
wm_manipulatormap_highlight_set(mmap, C, NULL, 0);
- wm_manipulatormap_modal_set(mmap, C, event, NULL);
+ if (mpr) {
+ wm_manipulatormap_modal_set(mmap, C, mpr, NULL, false);
+ }
}
/* restore the area */
@@ -836,24 +839,33 @@ wmManipulator *wm_manipulatormap_highlight_get(wmManipulatorMap *mmap)
return mmap->mmap_context.highlight;
}
+/**
+ * Caller should call exit when (enable == False).
+ */
void wm_manipulatormap_modal_set(
- wmManipulatorMap *mmap, bContext *C, const wmEvent *event, wmManipulator *mpr)
+ wmManipulatorMap *mmap, bContext *C, wmManipulator *mpr, const wmEvent *event, bool enable)
{
- if (mpr && C) {
+ if (enable) {
+ BLI_assert(mmap->mmap_context.modal == NULL);
+
/* 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 &&
+ (mpr->type->modal || mpr->custom_modal))
+ {
+ retval = mpr->type->invoke(C, mpr, event);
+ }
+
+ if ((retval & OPERATOR_RUNNING_MODAL) == 0) {
+ return;
+ }
mpr->state |= WM_MANIPULATOR_STATE_MODAL;
mmap->mmap_context.modal = mpr;
if (mpr->op_data.type) {
- /* first activate the manipulator itself */
- if (mpr->type->invoke &&
- (mpr->type->modal || mpr->custom_modal))
- {
- mpr->type->invoke(C, mpr, event);
- }
-
WM_operator_name_call_ptr(C, mpr->op_data.type, WM_OP_INVOKE_DEFAULT, &mpr->op_data.ptr);
/* we failed to hook the manipulator to the operator handler or operator was cancelled, return */
@@ -863,20 +875,13 @@ void wm_manipulatormap_modal_set(
}
return;
}
- else {
- if (mpr->type->invoke &&
- (mpr->type->modal || mpr->custom_modal))
- {
- mpr->type->invoke(C, mpr, event);
- }
- }
if (grab_cursor) {
WM_cursor_grab_enable(CTX_wm_window(C), true, true, NULL);
}
}
else {
- mpr = mmap->mmap_context.modal;
+ BLI_assert(ELEM(mmap->mmap_context.modal, NULL, mpr));
/* deactivate, manipulator but first take care of some stuff */
if (mpr) {
diff --git a/source/blender/windowmanager/manipulators/wm_manipulator_fn.h b/source/blender/windowmanager/manipulators/wm_manipulator_fn.h
index a92648455d4..d44d010df68 100644
--- a/source/blender/windowmanager/manipulators/wm_manipulator_fn.h
+++ b/source/blender/windowmanager/manipulators/wm_manipulator_fn.h
@@ -50,10 +50,10 @@ typedef void (*wmManipulatorFnSetup)(struct wmManipulator *);
typedef void (*wmManipulatorFnDraw)(const struct bContext *, struct wmManipulator *);
typedef void (*wmManipulatorFnDrawSelect)(const struct bContext *, struct wmManipulator *, int);
typedef int (*wmManipulatorFnTestSelect)(struct bContext *, struct wmManipulator *, const struct wmEvent *);
-typedef void (*wmManipulatorFnModal)(struct bContext *, struct wmManipulator *, const struct wmEvent *, eWM_ManipulatorTweak);
+typedef int (*wmManipulatorFnModal)(struct bContext *, struct wmManipulator *, const struct wmEvent *, eWM_ManipulatorTweak);
typedef void (*wmManipulatorFnPropertyUpdate)(struct wmManipulator *, struct wmManipulatorProperty *);
typedef void (*wmManipulatorFnMatrixWorldGet)(const struct wmManipulator *, float[4][4]);
-typedef void (*wmManipulatorFnInvoke)(struct bContext *, struct wmManipulator *, const struct wmEvent *);
+typedef int (*wmManipulatorFnInvoke)(struct bContext *, struct wmManipulator *, const struct wmEvent *);
typedef void (*wmManipulatorFnExit)(struct bContext *, struct wmManipulator *, const bool);
typedef int (*wmManipulatorFnCursorGet)(struct wmManipulator *);
typedef void (*wmManipulatorFnSelectRefresh)(struct wmManipulator *);
diff --git a/source/blender/windowmanager/manipulators/wm_manipulator_wmapi.h b/source/blender/windowmanager/manipulators/wm_manipulator_wmapi.h
index cc1bf398764..87cf711a60b 100644
--- a/source/blender/windowmanager/manipulators/wm_manipulator_wmapi.h
+++ b/source/blender/windowmanager/manipulators/wm_manipulator_wmapi.h
@@ -82,8 +82,9 @@ void wm_manipulatormap_highlight_set(
struct wmManipulator *mpr, int part);
struct wmManipulator *wm_manipulatormap_highlight_get(struct wmManipulatorMap *mmap);
void wm_manipulatormap_modal_set(
- struct wmManipulatorMap *mmap, bContext *C,
- const struct wmEvent *event, struct wmManipulator *mpr);
+ struct wmManipulatorMap *mmap, bContext *C, struct wmManipulator *mpr,
+ const struct wmEvent *event, bool enable);
+
struct wmManipulator *wm_manipulatormap_modal_get(struct wmManipulatorMap *mmap);
struct wmManipulator **wm_manipulatormap_selected_get(wmManipulatorMap *mmap, int *r_selected_len);
struct ListBase *wm_manipulatormap_groups_get(wmManipulatorMap *mmap);