[Bf-blender-cvs] [c760ab0ddad] master: Cleanup: Graph Editor, refactor selection operators

Maxime Casas noreply at git.blender.org
Mon Nov 30 17:15:32 CET 2020


Commit: c760ab0ddade365914196ce2703edad110b38cfd
Author: Maxime Casas
Date:   Mon Nov 30 16:35:42 2020 +0100
Branches: master
https://developer.blender.org/rBc760ab0ddade365914196ce2703edad110b38cfd

Cleanup: Graph Editor, refactor selection operators

Extract initialisation code of box selection into separate functions.

No functional changes.

Reviewed By: zeddb, sybren

Differential Revision: https://developer.blender.org/D9196

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

M	source/blender/editors/space_graph/graph_select.c

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

diff --git a/source/blender/editors/space_graph/graph_select.c b/source/blender/editors/space_graph/graph_select.c
index 13f2219d7af..007f99e3ce5 100644
--- a/source/blender/editors/space_graph/graph_select.c
+++ b/source/blender/editors/space_graph/graph_select.c
@@ -501,84 +501,113 @@ void GRAPH_OT_select_all(wmOperatorType *ot)
  * The selection backend is also reused for the Lasso and Circle select operators.
  */
 
-/* Box Select only selects keyframes now, as overshooting handles often get caught too,
- * which means that they may be inadvertently moved as well. However, incl_handles overrides
- * this, and allow handles to be considered independently too.
- * Also, for convenience, handles should get same status as keyframe (if it was within bounds).
- */
-static void box_select_graphkeys(bAnimContext *ac,
-                                 const rctf *rectf_view,
-                                 short mode,
-                                 short selectmode,
-                                 bool incl_handles,
-                                 void *data)
-{
-  ListBase anim_data = {NULL, NULL};
-  bAnimListElem *ale;
-  int filter, mapping_flag;
 
-  SpaceGraph *sipo = (SpaceGraph *)ac->sl;
-  KeyframeEditData ked;
-  KeyframeEditFunc ok_cb, select_cb;
-  View2D *v2d = &ac->region->v2d;
-  rctf rectf, scaled_rectf;
+static rctf initialize_box_select_coords(const bAnimContext *ac, const rctf *rectf_view)
+{
+  const View2D *v2d = &ac->region->v2d;
+  rctf rectf;
 
   /* Convert mouse coordinates to frame ranges and
    * channel coordinates corrected for view pan/zoom. */
   UI_view2d_region_to_view_rctf(v2d, rectf_view, &rectf);
+  return rectf;
+}
 
-  /* filter data */
-  filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_CURVE_VISIBLE | ANIMFILTER_NODUPLIS);
+static ListBase initialize_box_select_anim_data(const SpaceGraph *sipo, bAnimContext *ac)
+{
+  ListBase anim_data = {NULL, NULL};
+
+  int filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_CURVE_VISIBLE | ANIMFILTER_NODUPLIS);
   if (sipo->flag & SIPO_SELCUVERTSONLY) {
     filter |= ANIMFILTER_FOREDIT | ANIMFILTER_SELEDIT;
   }
   ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
 
-  /* get beztriple editing/validation funcs  */
-  select_cb = ANIM_editkeyframes_select(selectmode);
-  ok_cb = ANIM_editkeyframes_ok(mode);
+  return anim_data;
+}
 
-  /* init editing data */
-  memset(&ked, 0, sizeof(KeyframeEditData));
-  if (mode == BEZT_OK_REGION_LASSO) {
-    KeyframeEdit_LassoData *data_lasso = data;
-    data_lasso->rectf_scaled = &scaled_rectf;
-    ked.data = data_lasso;
-  }
-  else if (mode == BEZT_OK_REGION_CIRCLE) {
-    KeyframeEdit_CircleData *data_circle = data;
-    data_circle->rectf_scaled = &scaled_rectf;
-    ked.data = data;
-  }
-  else {
-    ked.data = &scaled_rectf;
+static void initialize_box_select_key_editing_data(const SpaceGraph *sipo,
+                                                   const bool incl_handles,
+                                                   const short mode,
+                                                   bAnimContext *ac,
+                                                   void *data,
+                                                   rctf *scaled_rectf,
+                                                   KeyframeEditData *r_ked,
+                                                   int *r_mapping_flag)
+{
+  memset(r_ked, 0, sizeof(KeyframeEditData));
+  switch (mode) {
+    case BEZT_OK_REGION_LASSO: {
+      KeyframeEdit_LassoData *data_lasso = data;
+      data_lasso->rectf_scaled = scaled_rectf;
+      r_ked->data = data_lasso;
+      break;
+    }
+    case BEZT_OK_REGION_CIRCLE: {
+      KeyframeEdit_CircleData *data_circle = data;
+      data_circle->rectf_scaled = scaled_rectf;
+      r_ked->data = data_circle;
+      break;
+    }
+    default:
+      r_ked->data = scaled_rectf;
+      break;
   }
 
   if (sipo->flag & SIPO_SELVHANDLESONLY) {
-    ked.iterflags |= KEYFRAME_ITER_HANDLES_DEFAULT_INVISIBLE;
+    r_ked->iterflags |= KEYFRAME_ITER_HANDLES_DEFAULT_INVISIBLE;
   }
 
-  /* treat handles separately? */
+  /* Enable handles selection. (used in keyframes_edit.c > KEYFRAME_OK_CHECKS macro) */
   if (incl_handles) {
-    ked.iterflags |= KEYFRAME_ITER_INCL_HANDLES;
-    mapping_flag = 0;
+    r_ked->iterflags |= KEYFRAME_ITER_INCL_HANDLES;
+    *r_mapping_flag = 0;
   }
   else {
-    mapping_flag = ANIM_UNITCONV_ONLYKEYS;
+    *r_mapping_flag = ANIM_UNITCONV_ONLYKEYS;
   }
 
-  mapping_flag |= ANIM_get_normalization_flags(ac);
+  *r_mapping_flag |= ANIM_get_normalization_flags(ac);
+}
+
+/* Box Select only selects keyframes, as overshooting handles often get caught too,
+ * which means that they may be inadvertently moved as well. However, incl_handles overrides
+ * this, and allow handles to be considered independently too.
+ * Also, for convenience, handles should get same status as keyframe (if it was within bounds).
+ */
+static void box_select_graphkeys(bAnimContext *ac,
+                                 const rctf *rectf_view,
+                                 short mode,
+                                 short selectmode,
+                                 bool incl_handles,
+                                 void *data)
+{
+  const rctf rectf = initialize_box_select_coords(ac, rectf_view);
+  SpaceGraph *sipo = (SpaceGraph *)ac->sl;
+  ListBase anim_data = initialize_box_select_anim_data(sipo, ac);
+  rctf scaled_rectf;
+  KeyframeEditData ked;
+  int mapping_flag;
+  initialize_box_select_key_editing_data(
+      sipo, incl_handles, mode, ac, data, &scaled_rectf, &ked, &mapping_flag);
+
+  /* Get beztriple editing/validation funcs.  */
+  const KeyframeEditFunc select_cb = ANIM_editkeyframes_select(selectmode);
+  const KeyframeEditFunc ok_cb = ANIM_editkeyframes_ok(mode);
 
-  /* loop over data, doing box select */
+  /* Try selecting the keyframes. */
+  bAnimListElem *ale = NULL;
+
+  /* First loop over data, doing box select. try selecting keys only. */
   for (ale = anim_data.first; ale; ale = ale->next) {
     AnimData *adt = ANIM_nla_mapping_get(ac, ale);
     FCurve *fcu = (FCurve *)ale->key_data;
     float offset;
-    float unit_scale = ANIM_unit_mapping_get_factor(
+    const float unit_scale = ANIM_unit_mapping_get_factor(
         ac->scene, ale->id, fcu, mapping_flag, &offset);
 
-    /* apply NLA mapping to all the keyframes, since it's easier than trying to
-     * guess when a callback might use something different
+    /* Apply NLA mapping to all the keyframes, since it's easier than trying to
+     * guess when a callback might use something different.
      */
     if (adt) {
       ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 0, incl_handles == 0);
@@ -589,7 +618,7 @@ static void box_select_graphkeys(bAnimContext *ac,
     scaled_rectf.ymin = rectf.ymin / unit_scale - offset;
     scaled_rectf.ymax = rectf.ymax / unit_scale - offset;
 
-    /* set horizontal range (if applicable)
+    /* Set horizontal range (if applicable).
      * NOTE: these values are only used for x-range and y-range but not region
      *      (which uses ked.data, i.e. rectf)
      */
@@ -602,7 +631,7 @@ static void box_select_graphkeys(bAnimContext *ac,
       ked.f2 = rectf.ymax;
     }
 
-    /* firstly, check if any keyframes will be hit by this */
+    /* Firstly, check if any keyframes will be hit by this. */
     if (ANIM_fcurve_keyframes_loop(&ked, fcu, NULL, ok_cb, NULL)) {
       /* select keyframes that are in the appropriate places */
       ANIM_fcurve_keyframes_loop(&ked, fcu, ok_cb, select_cb, NULL);
@@ -617,13 +646,13 @@ static void box_select_graphkeys(bAnimContext *ac,
       }
     }
 
-    /* un-apply NLA mapping from all the keyframes */
+    /* Un-apply NLA mapping from all the keyframes. */
     if (adt) {
       ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 1, incl_handles == 0);
     }
   }
 
-  /* cleanup */
+  /* Cleanup. */
   ANIM_animdata_freelist(&anim_data);
 }
 
@@ -672,12 +701,12 @@ static int graphkeys_box_select_exec(bContext *C, wmOperator *op)
   /* 'include_handles' from the operator specifies whether to include handles in the selection. */
   const bool incl_handles = RNA_boolean_get(op->ptr, "include_handles");
 
-  /* get settings from operator */
+  /* Get settings from operator. */
   WM_operator_properties_border_to_rcti(op, &rect);
 
-  /* selection 'mode' depends on whether box_select region only matters on one axis */
+  /* Selection 'mode' depends on whether box_select region only matters on one axis. */
   if (RNA_boolean_get(op->ptr, "axis_range")) {
-    /* mode depends on which axis of the range is larger to determine which axis to use
+    /* Mode depends on which axis of the range is larger to determine which axis to use
      * - Checking this in region-space is fine, as it's fundamentally still going to be a
      *   different rect size.
      * - The frame-range select option is favored over the channel one (x over y),
@@ -697,10 +726,9 @@ static int graphkeys_box_select_exec(bContext *C, wmOperator *op)
 
   BLI_rctf_rcti_copy(&rect_fl, &rect);
 
-  /* apply box_select action */
+  /* Apply box_select action. */
   box_select_graphkeys(&ac, &rect_fl, mode, selectmode, incl_handles, NULL);
-
-  /* send notifier that keyframe selection has changed */
+  /* Send notifier that keyframe selection has changed. */
   WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_SELECTED, NULL);
 
   return OPERATOR_FINISHED;
@@ -708,12 +736,12 @@ static int graphkeys_box_select_exec(bContext *C, wmOperator *op)
 
 void GRAPH_OT_select_box(wmOperatorType *ot)
 {
-  /* identifiers */
+  /* Identifiers. */
   ot->name = "Box Select";
   ot->idname = "GRAPH_OT_select_box";
   ot->description = "Select all keyframes within the specified region";
 
-  /* api callbacks */
+  /* API callbacks. */
   ot->invoke = graphkeys_box_select_invoke;
   ot->exec = graphkeys_box_select_exec;
   ot->modal = WM_gesture_box_modal;
@@ -721,10 +749,10 @@ void GRAPH_OT_select_box(wmOperatorType *ot)
 
   ot->poll = graphop_visible_keyframes_poll;
 
-  /* flags */
+  /* Flags. */
   ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
 
-  /* properties */
+  /* Properties

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list