[Bf-blender-cvs] [fdcf9c270fc] temp-gpencil-interpolate: GPencil: Basic Select Index stroke value

Antonio Vazquez noreply at git.blender.org
Sun Dec 20 12:26:17 CET 2020


Commit: fdcf9c270fc64bcf4a87840c21b448a385f83b55
Author: Antonio Vazquez
Date:   Fri Dec 18 12:20:16 2020 +0100
Branches: temp-gpencil-interpolate
https://developer.blender.org/rBfdcf9c270fc64bcf4a87840c21b448a385f83b55

GPencil: Basic Select Index stroke value

This is the first step to be able to make a relationship between strokes using select order and the concept of active stroke.

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

M	source/blender/blenkernel/BKE_gpencil.h
M	source/blender/blenkernel/BKE_gpencil_curve.h
M	source/blender/blenkernel/intern/gpencil.c
M	source/blender/blenkernel/intern/gpencil_curve.c
M	source/blender/blenkernel/intern/gpencil_geom.c
M	source/blender/editors/gpencil/gpencil_data.c
M	source/blender/editors/gpencil/gpencil_edit.c
M	source/blender/editors/gpencil/gpencil_edit_curve.c
M	source/blender/editors/gpencil/gpencil_merge.c
M	source/blender/editors/gpencil/gpencil_primitive.c
M	source/blender/editors/gpencil/gpencil_select.c
M	source/blender/editors/gpencil/gpencil_utils.c
M	source/blender/makesdna/DNA_gpencil_types.h
M	source/blender/makesrna/intern/rna_gpencil.c

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

diff --git a/source/blender/blenkernel/BKE_gpencil.h b/source/blender/blenkernel/BKE_gpencil.h
index df5711f5120..bccfd8805eb 100644
--- a/source/blender/blenkernel/BKE_gpencil.h
+++ b/source/blender/blenkernel/BKE_gpencil.h
@@ -101,8 +101,11 @@ void BKE_gpencil_tag(struct bGPdata *gpd);
 void BKE_gpencil_batch_cache_dirty_tag(struct bGPdata *gpd);
 void BKE_gpencil_batch_cache_free(struct bGPdata *gpd);
 
-void BKE_gpencil_stroke_sync_selection(struct bGPDstroke *gps);
-void BKE_gpencil_curve_sync_selection(struct bGPDstroke *gps);
+void BKE_gpencil_stroke_sync_selection(struct bGPdata *gpd, struct bGPDstroke *gps);
+void BKE_gpencil_curve_sync_selection(struct bGPdata *gpd, struct bGPDstroke *gps);
+void BKE_gpencil_stroke_select_index_set(struct bGPdata *gpd,
+                                         struct bGPDstroke *gps,
+                                         const bool reset);
 
 struct bGPDframe *BKE_gpencil_frame_addnew(struct bGPDlayer *gpl, int cframe);
 struct bGPDframe *BKE_gpencil_frame_addcopy(struct bGPDlayer *gpl, int cframe);
diff --git a/source/blender/blenkernel/BKE_gpencil_curve.h b/source/blender/blenkernel/BKE_gpencil_curve.h
index 2d42bb36949..9cbe67af9c1 100644
--- a/source/blender/blenkernel/BKE_gpencil_curve.h
+++ b/source/blender/blenkernel/BKE_gpencil_curve.h
@@ -50,8 +50,12 @@ struct bGPDcurve *BKE_gpencil_stroke_editcurve_generate(struct bGPDstroke *gps,
 void BKE_gpencil_stroke_editcurve_update(struct bGPdata *gpd,
                                          struct bGPDlayer *gpl,
                                          struct bGPDstroke *gps);
-void BKE_gpencil_editcurve_stroke_sync_selection(struct bGPDstroke *gps, struct bGPDcurve *gpc);
-void BKE_gpencil_stroke_editcurve_sync_selection(struct bGPDstroke *gps, struct bGPDcurve *gpc);
+void BKE_gpencil_editcurve_stroke_sync_selection(struct bGPdata *gpd,
+                                                 struct bGPDstroke *gps,
+                                                 struct bGPDcurve *gpc);
+void BKE_gpencil_stroke_editcurve_sync_selection(struct bGPdata *gpd,
+                                                 struct bGPDstroke *gps,
+                                                 struct bGPDcurve *gpc);
 void BKE_gpencil_strokes_selected_update_editcurve(struct bGPdata *gpd);
 void BKE_gpencil_strokes_selected_sync_selection_editcurve(struct bGPdata *gpd);
 void BKE_gpencil_stroke_update_geometry_from_editcurve(struct bGPDstroke *gps,
diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c
index f68a390db64..16bfef1f7a9 100644
--- a/source/blender/blenkernel/intern/gpencil.c
+++ b/source/blender/blenkernel/intern/gpencil.c
@@ -1091,7 +1091,7 @@ bGPdata *BKE_gpencil_data_duplicate(Main *bmain, const bGPdata *gpd_src, bool in
  * Ensure selection status of stroke is in sync with its points.
  * \param gps: Grease pencil stroke
  */
-void BKE_gpencil_stroke_sync_selection(bGPDstroke *gps)
+void BKE_gpencil_stroke_sync_selection(bGPdata *gpd, bGPDstroke *gps)
 {
   bGPDspoint *pt;
   int i;
@@ -1105,6 +1105,7 @@ void BKE_gpencil_stroke_sync_selection(bGPDstroke *gps)
    * so initially, we must deselect
    */
   gps->flag &= ~GP_STROKE_SELECT;
+  BKE_gpencil_stroke_select_index_set(NULL, gps, true);
 
   for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) {
     if (pt->flag & GP_SPOINT_SELECT) {
@@ -1112,9 +1113,13 @@ void BKE_gpencil_stroke_sync_selection(bGPDstroke *gps)
       break;
     }
   }
+
+  if (gps->flag & GP_STROKE_SELECT) {
+    BKE_gpencil_stroke_select_index_set(gpd, gps, false);
+  }
 }
 
-void BKE_gpencil_curve_sync_selection(bGPDstroke *gps)
+void BKE_gpencil_curve_sync_selection(bGPdata *gpd, bGPDstroke *gps)
 {
   bGPDcurve *gpc = gps->editcurve;
   if (gpc == NULL) {
@@ -1122,6 +1127,7 @@ void BKE_gpencil_curve_sync_selection(bGPDstroke *gps)
   }
 
   gps->flag &= ~GP_STROKE_SELECT;
+  BKE_gpencil_stroke_select_index_set(NULL, gps, true);
   gpc->flag &= ~GP_CURVE_SELECT;
 
   bool is_selected = false;
@@ -1144,6 +1150,19 @@ void BKE_gpencil_curve_sync_selection(bGPDstroke *gps)
   if (is_selected) {
     gpc->flag |= GP_CURVE_SELECT;
     gps->flag |= GP_STROKE_SELECT;
+    BKE_gpencil_stroke_select_index_set(gpd, gps, false);
+  }
+}
+
+/* Assign unique stroke ID for selection. */
+void BKE_gpencil_stroke_select_index_set(bGPdata *gpd, bGPDstroke *gps, const bool reset)
+{
+  if (!reset) {
+    gpd->select_last_index++;
+    gps->select_index = gpd->select_last_index;
+  }
+  else {
+    gps->select_index = 0;
   }
 }
 
@@ -2469,6 +2488,11 @@ bool BKE_gpencil_from_image(
           pt->flag |= GP_SPOINT_SELECT;
         }
       }
+
+      if (gps->flag & GP_STROKE_SELECT) {
+        BKE_gpencil_stroke_select_index_set(gpd, gps, false);
+      }
+
       BKE_gpencil_stroke_geometry_update(gpd, gps);
     }
   }
diff --git a/source/blender/blenkernel/intern/gpencil_curve.c b/source/blender/blenkernel/intern/gpencil_curve.c
index be14d74de7a..6707fb53aa3 100644
--- a/source/blender/blenkernel/intern/gpencil_curve.c
+++ b/source/blender/blenkernel/intern/gpencil_curve.c
@@ -781,7 +781,7 @@ void BKE_gpencil_stroke_editcurve_update(bGPdata *gpd, bGPDlayer *gpl, bGPDstrok
 /**
  * Sync the selection from stroke to editcurve
  */
-void BKE_gpencil_editcurve_stroke_sync_selection(bGPDstroke *gps, bGPDcurve *gpc)
+void BKE_gpencil_editcurve_stroke_sync_selection(bGPdata *gpd, bGPDstroke *gps, bGPDcurve *gpc)
 {
   if (gps->flag & GP_STROKE_SELECT) {
     gpc->flag |= GP_CURVE_SELECT;
@@ -808,10 +808,11 @@ void BKE_gpencil_editcurve_stroke_sync_selection(bGPDstroke *gps, bGPDcurve *gpc
 /**
  * Sync the selection from editcurve to stroke
  */
-void BKE_gpencil_stroke_editcurve_sync_selection(bGPDstroke *gps, bGPDcurve *gpc)
+void BKE_gpencil_stroke_editcurve_sync_selection(bGPdata *gpd, bGPDstroke *gps, bGPDcurve *gpc)
 {
   if (gpc->flag & GP_CURVE_SELECT) {
     gps->flag |= GP_STROKE_SELECT;
+    BKE_gpencil_stroke_select_index_set(gpd, gps, false);
 
     for (int i = 0; i < gpc->tot_curve_points - 1; i++) {
       bGPDcurve_point *gpc_pt = &gpc->curve_points[i];
@@ -865,6 +866,7 @@ void BKE_gpencil_stroke_editcurve_sync_selection(bGPDstroke *gps, bGPDcurve *gpc
   }
   else {
     gps->flag &= ~GP_STROKE_SELECT;
+    BKE_gpencil_stroke_select_index_set(NULL, gps, true);
     for (int i = 0; i < gps->totpoints; i++) {
       bGPDspoint *pt = &gps->points[i];
       pt->flag &= ~GP_SPOINT_SELECT;
@@ -1089,6 +1091,7 @@ void BKE_gpencil_stroke_update_geometry_from_editcurve(bGPDstroke *gps,
     /* deselect */
     pt->flag &= ~GP_SPOINT_SELECT;
     gps->flag &= ~GP_STROKE_SELECT;
+    BKE_gpencil_stroke_select_index_set(NULL, gps, true);
 
     return;
   }
@@ -1131,6 +1134,7 @@ void BKE_gpencil_stroke_update_geometry_from_editcurve(bGPDstroke *gps,
     pt->flag &= ~GP_SPOINT_SELECT;
   }
   gps->flag &= ~GP_STROKE_SELECT;
+  BKE_gpencil_stroke_select_index_set(NULL, gps, true);
 
   /* free temp data */
   MEM_freeN(points);
@@ -1375,7 +1379,7 @@ void BKE_gpencil_strokes_selected_update_editcurve(bGPdata *gpd)
             BKE_gpencil_stroke_editcurve_update(gpd, gpl, gps);
           }
           /* Update the selection from the stroke to the curve. */
-          BKE_gpencil_editcurve_stroke_sync_selection(gps, gps->editcurve);
+          BKE_gpencil_editcurve_stroke_sync_selection(gpd, gps, gps->editcurve);
 
           gps->flag |= GP_STROKE_NEEDS_CURVE_UPDATE;
           BKE_gpencil_stroke_geometry_update(gpd, gps);
@@ -1400,7 +1404,7 @@ void BKE_gpencil_strokes_selected_sync_selection_editcurve(bGPdata *gpd)
           bGPDcurve *gpc = gps->editcurve;
           if (gpc != NULL) {
             /* Update the selection of every stroke that has an editcurve */
-            BKE_gpencil_stroke_editcurve_sync_selection(gps, gpc);
+            BKE_gpencil_stroke_editcurve_sync_selection(gpd, gps, gpc);
           }
         }
       }
diff --git a/source/blender/blenkernel/intern/gpencil_geom.c b/source/blender/blenkernel/intern/gpencil_geom.c
index 981f5d50353..96d7bda5861 100644
--- a/source/blender/blenkernel/intern/gpencil_geom.c
+++ b/source/blender/blenkernel/intern/gpencil_geom.c
@@ -3404,6 +3404,7 @@ void BKE_gpencil_stroke_uniform_subdivide(bGPdata *gpd,
 
   if (select) {
     gps->flag |= GP_STROKE_SELECT;
+    BKE_gpencil_stroke_select_index_set(gpd, gps, false);
   }
 
   /* Free the sample points. Important to use the mutable loop here because we are erasing the list
diff --git a/source/blender/editors/gpencil/gpencil_data.c b/source/blender/editors/gpencil/gpencil_data.c
index aff109eb98e..89d39751d89 100644
--- a/source/blender/editors/gpencil/gpencil_data.c
+++ b/source/blender/editors/gpencil/gpencil_data.c
@@ -3399,9 +3399,11 @@ static int gpencil_material_select_exec(bContext *C, wmOperator *op)
 
             if (!deselected) {
               gps->flag |= GP_STROKE_SELECT;
+              BKE_gpencil_stroke_select_index_set(gpd, gps, false);
             }
             else {
               gps->flag &= ~GP_STROKE_SELECT;
+              BKE_gpencil_stroke_select_index_set(NULL, gps, true);
             }
             for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) {
               if (!deselected) {
diff --git a/source/blender/editors/gpencil/gpencil_edit.c b/source/blender/editors/gpencil/gpencil_edit.c
index 36e383cf3c2..0486afec391 100644
--- a/source/blender/editors/gpencil/gpencil_edit.c
+++ b/source/blender/editors/gpencil/gpencil_edit.c
@@ -214,7 +214,7 @@ static int gpencil_editmode_toggle_exec(bContext *C, wmOperator *op)
       if (gpc->flag & GP_CURVE_NEEDS_STROKE_UPDATE) {
         BKE_gpencil_stroke_editcurve_update(gpd, gpl, gps);
         /* Update the selection from the stroke to the curve. */
-        BKE_gpencil_editcurve_stroke_sync_selection(gps, gps->editcurve);
+        BKE_gpencil_editcurve_stroke_sync_selection(gpd, gps, gps->editcurve);
 
         gps->flag |= GP_STROKE_NEEDS_CURVE_UPDATE;
         BKE_gpencil_stroke_geometry_update(gpd, gps);
@@ -992,6 +992,7 @@ static int gpencil_duplicate_exec(bContext *C, wmOperator *op)
             pt->flag &= ~GP_SPOINT_SELECT;
           }
           gps->flag &= ~GP_STROKE_SELEC

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list