diff --git a/release/scripts/startup/bl_operators/mask.py b/release/scripts/startup/bl_operators/mask.py index 1f4317b9e9e..c5cc78f8f55 100644 --- a/release/scripts/startup/bl_operators/mask.py +++ b/release/scripts/startup/bl_operators/mask.py @@ -58,6 +58,7 @@ class MASK_OT_draw_mask(Operator): 'INVOKE_REGION_WIN', MASK_OT_add_vertex={ "type": self.type, + "ignore_existing": True, } ) diff --git a/source/blender/editors/mask/mask_add.c b/source/blender/editors/mask/mask_add.c index b508a567795..e974f2df1b2 100644 --- a/source/blender/editors/mask/mask_add.c +++ b/source/blender/editors/mask/mask_add.c @@ -530,19 +530,13 @@ static int add_vertex_exec(bContext *C, wmOperator *op) float co[2]; RNA_float_get_array(op->ptr, "location", co); - /* TODO(sergey): This is to get a quick proof-of-concept behavior fer the "Draw a Mask" tool. - * The idea is to add new vertex unless clicking on an existing one. When clicking on the - * existing one select it, and let it to be slid. - * For the final implementation we'd either need to introduce new operator, or a new property - * to enable this behavior. */ - if (mask_layer != NULL) { - MaskMouseSelectProperties properties; - properties.extend = false; - properties.deselect = true; - properties.deselect_all = false; - properties.toggle = false; - - if (ED_mask_select_mouse_pick(C, co, &properties)) { + if (RNA_boolean_get(op->ptr, "ignore_existing") && mask_layer != NULL) { + const float threshold = ED_mask_select_threshold_get(); + MaskSpline *spline; + const MaskSplinePoint *point = ED_mask_point_find_nearest( + C, mask, co, threshold, NULL, &spline, NULL, NULL); + + if (point != NULL) { ED_mask_view_lock_state_restore_no_jump(C, &lock_state); return OPERATOR_FINISHED; } @@ -634,6 +628,8 @@ void MASK_OT_add_vertex(wmOperatorType *ot) ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; /* properties */ + PropertyRNA *prop; + RNA_def_float_vector(ot->srna, "location", 2, @@ -645,6 +641,13 @@ void MASK_OT_add_vertex(wmOperatorType *ot) -1.0f, 1.0f); + prop = RNA_def_boolean(ot->srna, + "ignore_existing", + false, + "Use Existing", + "Don't add vertices at the location of existing vertex"); + RNA_def_property_flag(prop, PROP_SKIP_SAVE); + ot->prop = RNA_def_enum(ot->srna, "type", editcurve_handle_type_items, 1, "Type", "Spline type"); } diff --git a/source/blender/editors/mask/mask_intern.h b/source/blender/editors/mask/mask_intern.h index 49053ad06df..dc46e91123f 100644 --- a/source/blender/editors/mask/mask_intern.h +++ b/source/blender/editors/mask/mask_intern.h @@ -109,6 +109,8 @@ typedef struct MaskMouseSelectProperties { bool toggle; } MaskMouseSelectProperties; +int ED_mask_select_threshold_get(void); + bool ED_mask_select_mouse_pick(struct bContext *C, float co[2], const MaskMouseSelectProperties *properties); diff --git a/source/blender/editors/mask/mask_ops.c b/source/blender/editors/mask/mask_ops.c index 442c3c4ae07..5706a310764 100644 --- a/source/blender/editors/mask/mask_ops.c +++ b/source/blender/editors/mask/mask_ops.c @@ -267,7 +267,7 @@ bool ED_mask_spline_under_mouse_get(const bContext *C, MaskLayer **r_mask_layer, MaskSpline **r_mask_spline) { - const float threshold = 19.0f; + const float threshold = ED_mask_select_threshold_get(); ScrArea *area = CTX_wm_area(C); SpaceClip *sc = CTX_wm_space_clip(C); float closest_dist_squared = 0.0f; diff --git a/source/blender/editors/mask/mask_select.c b/source/blender/editors/mask/mask_select.c index ea4dbd6068a..9724a3bd8d4 100644 --- a/source/blender/editors/mask/mask_select.c +++ b/source/blender/editors/mask/mask_select.c @@ -251,6 +251,11 @@ void MASK_OT_select_all(wmOperatorType *ot) /** \name Select (Cursor Pick) Operator * \{ */ +int ED_mask_select_threshold_get(void) +{ + return 19; +} + bool ED_mask_select_mouse_pick(bContext *C, float co[2], const MaskMouseSelectProperties *properties) @@ -260,7 +265,7 @@ bool ED_mask_select_mouse_pick(bContext *C, MaskSpline *spline; MaskSplinePoint *point = NULL; eMaskWhichHandle which_handle; - const float threshold = 19; + const float threshold = ED_mask_select_threshold_get(); MaskViewLockState lock_state; ED_mask_view_lock_state_store(C, &lock_state);