[Bf-blender-cvs] [546fe10b332] tracking_tools: MCE: Mask tool improvements

Sebastian Koenig noreply at git.blender.org
Mon Jul 19 15:17:45 CEST 2021


Commit: 546fe10b332a104e85aa90a52c0d1a75db7cd206
Author: Sebastian Koenig
Date:   Mon Jul 19 15:08:09 2021 +0200
Branches: tracking_tools
https://developer.blender.org/rB546fe10b332a104e85aa90a52c0d1a75db7cd206

MCE: Mask tool improvements

The mask tool now respects the settings for new handle_type in the tool
settings for new points. This makes it work more like a proper tool.

However, now it does not use the active point anymore as a reference for the handle_type
settings of new points as it was until 2.93.
So e.g. if the user starts to draw a mask with handle_type Auto and
changes the active point to Vector, every new point
drawn with the mask tool will still have handle_type Auto. Overall I
think the new behavior is better though.
Also, the user does not need to keep Ctrl pressed to draw a mask.
Instead, the tool will draw a mask point on every click, unless the mouse
is close to an existing point, then it will work like the tweak tool.

The user can hold down Ctrl to activate the add_feather_vertex_slide
tool.

===================================================================

M	release/scripts/presets/keyconfig/keymap_data/blender_default.py
M	release/scripts/startup/bl_operators/__init__.py
A	release/scripts/startup/bl_operators/mask.py
M	release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
M	source/blender/editors/mask/mask_add.c
M	source/blender/editors/mask/mask_intern.h
M	source/blender/editors/mask/mask_select.c

===================================================================

diff --git a/release/scripts/presets/keyconfig/keymap_data/blender_default.py b/release/scripts/presets/keyconfig/keymap_data/blender_default.py
index 662faebdc78..34345d8aff1 100644
--- a/release/scripts/presets/keyconfig/keymap_data/blender_default.py
+++ b/release/scripts/presets/keyconfig/keymap_data/blender_default.py
@@ -6042,9 +6042,8 @@ def km_clip_editor_tool_mask_add_vertex(params):
         "Mask Editing: Add Vertex and Slide",
         {"space_type": 'CLIP_EDITOR', "region_type": 'WINDOW'},
         {"items": [
-            ("mask.add_vertex_slide", {"type": 'LEFTMOUSE', "value": 'PRESS', "ctrl": True}, None),
-            ("mask.slide_point", {"type": 'LEFTMOUSE', "value": 'PRESS'}, None),
-            ("mask.slide_spline_curvature", {"type": 'LEFTMOUSE', "value": 'PRESS'}, None),
+            ("mask.draw_mask", {"type": 'LEFTMOUSE', "value": 'PRESS'}, None),
+            ("mask.add_feather_vertex_slide", {"type": 'LEFTMOUSE', "value": 'PRESS', "ctrl": True}, None),
         ]},
     )
 
diff --git a/release/scripts/startup/bl_operators/__init__.py b/release/scripts/startup/bl_operators/__init__.py
index 078b32f5e2a..5cae875272f 100644
--- a/release/scripts/startup/bl_operators/__init__.py
+++ b/release/scripts/startup/bl_operators/__init__.py
@@ -35,6 +35,7 @@ _modules = [
     "file",
     "geometry_nodes",
     "image",
+    "mask",
     "mesh",
     "node",
     "object",
diff --git a/release/scripts/startup/bl_operators/mask.py b/release/scripts/startup/bl_operators/mask.py
new file mode 100644
index 00000000000..a2469d2f2e2
--- /dev/null
+++ b/release/scripts/startup/bl_operators/mask.py
@@ -0,0 +1,63 @@
+# ##### BEGIN GPL LICENSE BLOCK #####
+#
+#  This program is free software; you can redistribute it and/or
+#  modify it under the terms of the GNU General Public License
+#  as published by the Free Software Foundation; either version 2
+#  of the License, or (at your option) any later version.
+#
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU General Public License for more details.
+#
+#  You should have received a copy of the GNU General Public License
+#  along with this program; if not, write to the Free Software Foundation,
+#  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# ##### END GPL LICENSE BLOCK #####
+
+# <pep8 compliant>
+import bpy
+from bpy.types import Operator
+from bpy.props import EnumProperty
+
+
+class MASK_OT_draw_mask(Operator):
+    """Smart code to draw a mask"""
+    bl_label = "Draw a mask"
+    bl_idname = "mask.draw_mask"
+
+    type: EnumProperty(
+        name="Type",
+        items=(
+	        ('AUTO', "Auto", ""),
+	        ('VECTOR', "Vector", ""),
+	        ('ALIGNED', "Aligned Single", ""),
+	        ('ALIGNED_DOUBLESIDE', "Aligned", ""),
+	        ('FREE', "Free", ""),
+        ),
+    )
+
+    def execute(self, context):
+        return bpy.ops.mask.add_vertex_slide(
+            MASK_OT_add_vertex={
+                "type": self.type,
+            }
+        )
+
+    def invoke(self, context, _event):
+        bpy.ops.mask.add_vertex_slide(
+            'INVOKE_REGION_WIN',
+            MASK_OT_add_vertex={
+                "type": self.type,
+            }
+        )
+
+        # ignore return from operators above because they are 'RUNNING_MODAL',
+        # and cause this one not to be freed. T24671.
+        return {'FINISHED'}
+
+
+classes = (
+    MASK_OT_draw_mask,
+)
diff --git a/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py b/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
index 4f5feb13358..d1cc1cfbe95 100644
--- a/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
+++ b/release/scripts/startup/bl_ui/space_toolsystem_toolbar.py
@@ -2505,13 +2505,13 @@ class _defs_mask_tools:
     def add_vertex_slide():
         def draw_settings(_context, layout, tool):
             tool_settings = _context.tool_settings
-            props = tool.operator_properties("mask.add_vertex")
+            props = tool.operator_properties("mask.draw_mask")
             row = layout.row()
             row.label(text="Mask Settings")
             row.prop(props, "type")
 
         return dict(
-            idname="builtin.add_vertex_slide",
+            idname="builtin.draw_mask",
             label="Draw a Mask",
             icon="ops.curve.extrude_move",
             widget=None,
diff --git a/source/blender/editors/mask/mask_add.c b/source/blender/editors/mask/mask_add.c
index 01678887656..65a9b416f65 100644
--- a/source/blender/editors/mask/mask_add.c
+++ b/source/blender/editors/mask/mask_add.c
@@ -297,10 +297,8 @@ static bool add_vertex_subdivide(const bContext *C, Mask *mask, const float co[2
   return false;
 }
 
-static bool add_vertex_extrude(const bContext *C,
-                               Mask *mask,
-                               MaskLayer *mask_layer,
-                               const float co[2], int handle_type)
+static bool add_vertex_extrude(
+    const bContext *C, Mask *mask, MaskLayer *mask_layer, const float co[2], int handle_type)
 {
   Scene *scene = CTX_data_scene(C);
   const float ctime = CFRA;
@@ -397,7 +395,8 @@ static bool add_vertex_extrude(const bContext *C,
   return true;
 }
 
-static bool add_vertex_new(const bContext *C, Mask *mask, MaskLayer *mask_layer, const float co[2], int handle_type)
+static bool add_vertex_new(
+    const bContext *C, Mask *mask, MaskLayer *mask_layer, const float co[2], int handle_type)
 {
   Scene *scene = CTX_data_scene(C);
   const float ctime = CFRA;
@@ -529,6 +528,23 @@ 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)) {
+      return OPERATOR_FINISHED;
+    }
+  }
+
   /* TODO: having an active point but no active spline is possible, why? */
   if (mask_layer && mask_layer->act_spline && mask_layer->act_point &&
       MASKPOINT_ISSEL_ANY(mask_layer->act_point)) {
@@ -571,19 +587,19 @@ static int add_vertex_invoke(bContext *C, wmOperator *op, const wmEvent *event)
 
   RNA_float_set_array(op->ptr, "location", co);
 
-return add_vertex_exec(C, op);
+  return add_vertex_exec(C, op);
 }
 
 void MASK_OT_add_vertex(wmOperatorType *ot)
 {
- 	static const EnumPropertyItem editcurve_handle_type_items[] = {
-	    {HD_AUTO, "AUTO", 0, "Auto", ""},
-	    {HD_VECT, "VECTOR", 0, "Vector", ""},
-	    {HD_ALIGN, "ALIGNED", 0, "Aligned Single", ""},
-	    {HD_ALIGN_DOUBLESIDE, "ALIGNED_DOUBLESIDE", 0, "Aligned", ""},
-	    {HD_FREE, "FREE", 0, "Free", ""},
-	    {0, NULL, 0, NULL, NULL},
-	};
+  static const EnumPropertyItem editcurve_handle_type_items[] = {
+      {HD_AUTO, "AUTO", 0, "Auto", ""},
+      {HD_VECT, "VECTOR", 0, "Vector", ""},
+      {HD_ALIGN, "ALIGNED", 0, "Aligned Single", ""},
+      {HD_ALIGN_DOUBLESIDE, "ALIGNED_DOUBLESIDE", 0, "Aligned", ""},
+      {HD_FREE, "FREE", 0, "Free", ""},
+      {0, NULL, 0, NULL, NULL},
+  };
 
   /* identifiers */
   ot->name = "Add Vertex";
diff --git a/source/blender/editors/mask/mask_intern.h b/source/blender/editors/mask/mask_intern.h
index ee1784011ea..4842982e489 100644
--- a/source/blender/editors/mask/mask_intern.h
+++ b/source/blender/editors/mask/mask_intern.h
@@ -90,6 +90,24 @@ void ED_mask_layer_select_set(struct MaskLayer *mask_layer, const bool do_select
 void ED_mask_select_toggle_all(struct Mask *mask, int action);
 void ED_mask_select_flush_all(struct Mask *mask);
 
+typedef struct MaskMouseSelectProperties {
+  /* Extend selection instead of deselecting everything first. */
+  bool extend;
+
+  /* Remove from selection. */
+  bool deselect;
+
+  /* Deselect all when nothing under the cursor. */
+  bool deselect_all;
+
+  /* Toggle the selection. */
+  bool toggle;
+} MaskMouseSelectProperties;
+
+bool ED_mask_select_mouse_pick(struct bContext *C,
+                               float co[2],
+                               const MaskMouseSelectProperties *properties);
+
 /* mask_editor.c */
 bool ED_maskedit_poll(struct bContext *C);
 bool ED_maskedit_mask_poll(struct bContext *C);
diff --git a/source/blender/editors/mask/mask_select.c b/source/blender/editors/mask/mask_select.c
index 3bb05a27c54..e05e29cbf96 100644
--- a/source/blender/editors/mask/mask_select.c
+++ b/source/blender/editors/mask/mask_select.c
@@ -251,41 +251,37 @@ void MASK_OT_select_all(wmOperatorType *ot)
 /** \name Select (Cursor Pick) Operator
  * \{ */
 
-static int select_exec(bContext *C, wmOperator *op)
+bool ED_mask_select_mouse_pick(bContext *C,
+                               float co[2],
+                               const MaskMouseSelectProperties *properties)
 {
   Mask *mask = CTX_data_edit_mask(C);
   MaskLayer *mask_layer;
   MaskSpline *spline;
   MaskSplinePoint *point = NULL;
-  float co[2];
-  bool extend = RNA_boolean_get(op->ptr, "extend");
-  bool deselect = RNA_boolean_get(op->ptr, "deselect");
-  bool toggle = RNA_boolean_get(op->ptr, "toggle");
-  const bool deselect_all = RNA_boolean_get(op->ptr, "deselect_all");
   eMaskWhichHandle which_handle;
   const float threshold = 19;
 
   MaskViewLockState lock_state;
   ED_mask_view_lock_state_store(C, &lock_state);
 
-  RNA_float_get_array(op->ptr, "location", co);
-
   point = ED_mask_point_find_nearest(
       C, mask, co, threshold, &mask_layer, &spline, &which_handle, NULL);
 
-  if (extend == false && deselect == false && toggle == false) {
+  if (properties->extend == false && properties->deselect == false &&
+      

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list