Select: Add 'deselect on nothing' behavior to tracking editor.
authorBastien Montagne <montagne29@wanadoo.fr>
Mon, 29 Apr 2019 15:29:05 +0000 (17:29 +0200)
committerBastien Montagne <montagne29@wanadoo.fr>
Tue, 30 Apr 2019 09:34:22 +0000 (11:34 +0200)
Part of T63995.

release/scripts/presets/keyconfig/keymap_data/blender_default.py
source/blender/editors/space_clip/tracking_select.c

index 1129af2..7f7fa44 100644 (file)
@@ -2646,7 +2646,7 @@ def km_clip_editor(params):
          {"properties": [("position", 'PATHSTART')]}),
         ("clip.change_frame", {"type": 'LEFTMOUSE', "value": 'PRESS'}, None),
         ("clip.select", {"type": params.select_mouse, "value": 'PRESS'},
-         {"properties": [("extend", False)]}),
+         {"properties": [("extend", False), ("deselect_all", not params.legacy)]}),
         ("clip.select", {"type": params.select_mouse, "value": 'PRESS', "shift": True},
          {"properties": [("extend", True)]}),
         *_template_items_select_actions(params, "clip.select_all"),
index d144fc6..2b70aec 100644 (file)
@@ -280,7 +280,7 @@ void ed_tracking_deselect_all_plane_tracks(ListBase *plane_tracks_base)
   }
 }
 
-static int mouse_select(bContext *C, float co[2], int extend)
+static int mouse_select(bContext *C, float co[2], const bool extend, const bool deselect_all)
 {
   SpaceClip *sc = CTX_wm_space_clip(C);
   MovieClip *clip = ED_space_clip_get_clip(sc);
@@ -295,6 +295,15 @@ static int mouse_select(bContext *C, float co[2], int extend)
   track = find_nearest_track(sc, tracksbase, co, &distance_to_track);
   plane_track = find_nearest_plane_track(sc, plane_tracks_base, co, &distance_to_plane_track);
 
+  /* Do not select beyond some reasonable distance, that is useless and
+   * prevents the 'deselect on nothing' behavior. */
+  if (distance_to_track > 0.05f) {
+    track = NULL;
+  }
+  if (distance_to_plane_track > 0.05f) {
+    plane_track = NULL;
+  }
+
   /* Between track and plane we choose closest to the mouse for selection here. */
   if (track && plane_track) {
     if (distance_to_track < distance_to_plane_track) {
@@ -305,11 +314,11 @@ static int mouse_select(bContext *C, float co[2], int extend)
     }
   }
 
-  if (!extend) {
-    ed_tracking_deselect_all_plane_tracks(plane_tracks_base);
-  }
-
   if (track) {
+    if (!extend) {
+      ed_tracking_deselect_all_plane_tracks(plane_tracks_base);
+    }
+
     int area = track_mouse_area(C, co, track);
 
     if (!extend || !TRACK_VIEW_SELECTED(sc, track)) {
@@ -352,6 +361,10 @@ static int mouse_select(bContext *C, float co[2], int extend)
     clip->tracking.act_track = NULL;
     clip->tracking.act_plane_track = plane_track;
   }
+  else if (deselect_all) {
+    ed_tracking_deselect_all_tracks(tracksbase);
+    ed_tracking_deselect_all_plane_tracks(plane_tracks_base);
+  }
 
   if (!extend) {
     sc->xlockof = 0.0f;
@@ -380,12 +393,12 @@ static bool select_poll(bContext *C)
 static int select_exec(bContext *C, wmOperator *op)
 {
   float co[2];
-  int extend;
 
   RNA_float_get_array(op->ptr, "location", co);
-  extend = RNA_boolean_get(op->ptr, "extend");
+  const bool extend = RNA_boolean_get(op->ptr, "extend");
+  const bool deselect_all = RNA_boolean_get(op->ptr, "deselect_all");
 
-  return mouse_select(C, co, extend);
+  return mouse_select(C, co, extend, deselect_all);
 }
 
 static int select_invoke(bContext *C, wmOperator *op, const wmEvent *event)
@@ -433,11 +446,19 @@ void CLIP_OT_select(wmOperatorType *ot)
   ot->flag = OPTYPE_UNDO;
 
   /* properties */
+  PropertyRNA *prop;
   RNA_def_boolean(ot->srna,
                   "extend",
                   0,
                   "Extend",
                   "Extend selection rather than clearing the existing selection");
+  prop = RNA_def_boolean(ot->srna,
+                         "deselect_all",
+                         false,
+                         "Deselect On Nothing",
+                         "Deselect all when nothing under the cursor");
+  RNA_def_property_flag(prop, PROP_SKIP_SAVE);
+
   RNA_def_float_vector(
       ot->srna,
       "location",