[Bf-blender-cvs] [b96a1ac2634] soc-2020-greasepencil-curve: GPencil: Add 'select all' operator for curve

Falk David noreply at git.blender.org
Tue Jun 9 14:32:36 CEST 2020


Commit: b96a1ac26346e9dfae52744d8db82abac5cf4abf
Author: Falk David
Date:   Tue Jun 9 14:31:52 2020 +0200
Branches: soc-2020-greasepencil-curve
https://developer.blender.org/rBb96a1ac26346e9dfae52744d8db82abac5cf4abf

GPencil: Add 'select all' operator for curve

Change the 'select all' operator so that, if the stroke
is in curve edit mode, it selects the curve handles.

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

M	source/blender/editors/gpencil/gpencil_intern.h
M	source/blender/editors/gpencil/gpencil_select.c
M	source/blender/editors/gpencil/gpencil_utils.c
M	source/blender/editors/include/ED_gpencil.h

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

diff --git a/source/blender/editors/gpencil/gpencil_intern.h b/source/blender/editors/gpencil/gpencil_intern.h
index 4e101031ed5..0ad47e4265d 100644
--- a/source/blender/editors/gpencil/gpencil_intern.h
+++ b/source/blender/editors/gpencil/gpencil_intern.h
@@ -728,6 +728,51 @@ struct GP_EditableStrokes_Iter {
   } \
   (void)0
 
+/**
+ * Iterate over all strokes in edit curve mode in the current context,
+ * to perform some operations on the stroke.
+ *
+ * \param gpl: The identifier to use for the layer of the stroke being processed.
+ *                    Choose a suitable value to avoid name clashes.
+ * \param gps: The identifier to use for current stroke being processed.
+ *                    Choose a suitable value to avoid name clashes.
+ */
+#define GP_CURVE_EDIT_STROKES_BEGIN(gpstroke_iter, C, gpl, gps) \
+  { \
+    struct GP_EditableStrokes_Iter gpstroke_iter = {{{0}}}; \
+    Depsgraph *depsgraph_ = CTX_data_ensure_evaluated_depsgraph(C); \
+    Object *obact_ = CTX_data_active_object(C); \
+    Object *ob_eval_ = (Object *)DEG_get_evaluated_id(depsgraph_, &obact_->id); \
+    bGPdata *gpd_ = (bGPdata *)ob_eval_->data; \
+    const bool is_multiedit_ = (bool)GPENCIL_MULTIEDIT_SESSIONS_ON(gpd_); \
+    LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd_->layers) { \
+      if (BKE_gpencil_layer_is_editable(gpl)) { \
+        bGPDframe *init_gpf_ = (is_multiedit_) ? gpl->frames.first : gpl->actframe; \
+        for (bGPDframe *gpf_ = init_gpf_; gpf_; gpf_ = gpf_->next) { \
+          if ((gpf_ == gpl->actframe) || ((gpf_->flag & GP_FRAME_SELECT) && is_multiedit_)) { \
+            BKE_gpencil_parent_matrix_get(depsgraph_, obact_, gpl, gpstroke_iter.diff_mat); \
+            invert_m4_m4(gpstroke_iter.inverse_diff_mat, gpstroke_iter.diff_mat); \
+            /* loop over strokes */ \
+            LISTBASE_FOREACH (bGPDstroke *, gps, &gpf_->strokes) { \
+              /* skip strokes that are invalid for current view */ \
+              if (ED_gpencil_stroke_can_use(C, gps) == false) \
+                continue; \
+              if (gps->flag & GP_STROKE_CURVE_MODE) \
+                continue; \
+    /* ... Do Stuff With Strokes ...  */
+
+#define GP_CURVE_EDIT_STROKES_END(gpstroke_iter) \
+  } \
+  } \
+  if (!is_multiedit_) { \
+    break; \
+  } \
+  } \
+  } \
+  } \
+  } \
+  (void)0
+
 /* ****************************************************** */
 
 #endif /* __GPENCIL_INTERN_H__ */
diff --git a/source/blender/editors/gpencil/gpencil_select.c b/source/blender/editors/gpencil/gpencil_select.c
index c41b2993a80..9b361ff2dea 100644
--- a/source/blender/editors/gpencil/gpencil_select.c
+++ b/source/blender/editors/gpencil/gpencil_select.c
@@ -172,7 +172,12 @@ static int gpencil_select_all_exec(bContext *C, wmOperator *op)
     }
   }
 
-  ED_gpencil_select_toggle_all(C, action);
+  if (GPENCIL_CURVE_EDIT_SESSIONS_ON(gpd)) {
+    ED_gpencil_select_curve_toggle_all(C, action);
+  }
+  else {
+    ED_gpencil_select_toggle_all(C, action);
+  }
 
   /* updates */
   DEG_id_tag_update(&gpd->id, ID_RECALC_GEOMETRY);
diff --git a/source/blender/editors/gpencil/gpencil_utils.c b/source/blender/editors/gpencil/gpencil_utils.c
index 876fa7c9874..2fd50aa3c39 100644
--- a/source/blender/editors/gpencil/gpencil_utils.c
+++ b/source/blender/editors/gpencil/gpencil_utils.c
@@ -55,6 +55,7 @@
 #include "BKE_context.h"
 #include "BKE_deform.h"
 #include "BKE_gpencil.h"
+#include "BKE_gpencil_curve.h"
 #include "BKE_gpencil_geom.h"
 #include "BKE_main.h"
 #include "BKE_material.h"
@@ -2479,6 +2480,80 @@ void ED_gpencil_select_toggle_all(bContext *C, int action)
   }
 }
 
+void ED_gpencil_select_curve_toggle_all(bContext *C, int action)
+{
+  /* if toggle, check if we need to select or deselect */
+  if (action == SEL_TOGGLE) {
+    action = SEL_SELECT;
+    GP_CURVE_EDIT_STROKES_BEGIN(gps_iter, C, gpl, gps)
+    {
+      if (gps->flag & GP_STROKE_SELECT) {
+        action = SEL_DESELECT;
+      }
+    }
+    GP_CURVE_EDIT_STROKES_END(gps_iter);
+  }
+
+  if (action == SEL_DESELECT) {
+    GP_CURVE_EDIT_STROKES_BEGIN(gps_iter, C, gpl, gps)
+    {
+      if (gps->editcurve != NULL) {
+        bGPDcurve *gpc = gps->editcurve;
+        for (int i = 0; i < gpc->tot_curve_points; i++) {
+          BezTriple *bezt = &gpc->curve_points[i];
+          bezt->f1 &= ~SELECT;
+          bezt->f2 &= ~SELECT;
+          bezt->f3 &= ~SELECT;
+        }
+        gps->flag &= ~GP_STROKE_SELECT;
+      }
+    }
+    GP_CURVE_EDIT_STROKES_END(gps_iter);
+  }
+  else {
+    CTX_DATA_BEGIN (C, bGPDstroke *, gps, editable_gpencil_strokes) {
+      bool selected = false;
+
+      /* Make sure stroke has a curve */
+      if (gps->editcurve == NULL) {
+        BKE_gpencil_stroke_curve_create(gps);
+        gps->flag |= GP_STROKE_CURVE_MODE;
+      }
+
+      bGPDcurve *gpc = gps->editcurve;
+      for (int i = 0; i < gpc->tot_curve_points; i++) {
+        BezTriple *bezt = &gpc->curve_points[i];
+        switch (action) {
+          case SEL_SELECT:
+            bezt->f1 |= SELECT;
+            bezt->f2 |= SELECT;
+            bezt->f3 |= SELECT;
+            break;
+          case SEL_INVERT:
+            bezt->f1 ^= SELECT;
+            bezt->f2 ^= SELECT;
+            bezt->f3 ^= SELECT;
+            break;
+          default:
+            break;
+        }
+
+        if (bezt->f1 & SELECT) {
+          selected = true;
+        }
+      }
+
+      if (selected) {
+        gps->flag |= GP_STROKE_SELECT;
+      }
+      else {
+        gps->flag &= ~GP_STROKE_SELECT;
+      }
+    }
+    CTX_DATA_END;
+  }
+}
+
 /* Ensure the SBuffer (while drawing stroke) size is enough to save all points of the stroke */
 tGPspoint *ED_gpencil_sbuffer_ensure(tGPspoint *buffer_array,
                                      int *buffer_size,
diff --git a/source/blender/editors/include/ED_gpencil.h b/source/blender/editors/include/ED_gpencil.h
index 0c228fc962b..126d97216a7 100644
--- a/source/blender/editors/include/ED_gpencil.h
+++ b/source/blender/editors/include/ED_gpencil.h
@@ -282,6 +282,7 @@ int ED_gpencil_select_stroke_segment(struct bGPDlayer *gpl,
                                      float r_hitb[3]);
 
 void ED_gpencil_select_toggle_all(struct bContext *C, int action);
+void ED_gpencil_select_curve_toggle_all(struct bContext *C, int action);
 
 /* Ensure stroke sbuffer size is enough */
 struct tGPspoint *ED_gpencil_sbuffer_ensure(struct tGPspoint *buffer_array,



More information about the Bf-blender-cvs mailing list