[Bf-blender-cvs] [7dc728e1976] asset-greasepencil: GPencil: Keep selected asset if working in Edit mode

Antonio Vazquez noreply at git.blender.org
Thu Jul 29 23:18:27 CEST 2021


Commit: 7dc728e1976559ca2cea3969a2401d82955f95a0
Author: Antonio Vazquez
Date:   Thu Jul 29 23:17:53 2021 +0200
Branches: asset-greasepencil
https://developer.blender.org/rB7dc728e1976559ca2cea3969a2401d82955f95a0

GPencil: Keep selected asset if working in Edit mode

In this way, after import the asset it can be transformed if it's in Edit mode.

For other modes the strokes are unselected.

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

M	source/blender/editors/gpencil/gpencil_asset.c

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

diff --git a/source/blender/editors/gpencil/gpencil_asset.c b/source/blender/editors/gpencil/gpencil_asset.c
index b32d210fd3f..7bda069c2aa 100644
--- a/source/blender/editors/gpencil/gpencil_asset.c
+++ b/source/blender/editors/gpencil/gpencil_asset.c
@@ -342,10 +342,19 @@ static bool gpencil_asset_create(const bContext *C,
   /* Mark as asset. */
   ED_asset_mark_id(C, &gpd->id);
 
-  /* Retime frame number to start by 1. Must be done after generate the render preview. */
+  /* Retime frame number to start by 1. Must be done after generate the render preview.
+   * Use same loop to deselect all. */
   LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) {
     LISTBASE_FOREACH (bGPDframe *, gpf, &gpl->frames) {
       gpf->framenum -= f_min - 1;
+      LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) {
+        gps->flag &= ~GP_STROKE_SELECT;
+        bGPDspoint *pt;
+        int i;
+        for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) {
+          pt->flag &= ~GP_SPOINT_SELECT;
+        }
+      }
     }
   }
 
@@ -865,6 +874,34 @@ static Material *gpencil_asset_material_get_from_id(ID *id, const int slot_index
   return material;
 }
 
+/* Helper: Set the selection of the imported strokes. */
+static void gpencil_asset_set_selection(tGPDasset *tgpa, const bool enable)
+{
+
+  for (int index = 0; index < tgpa->data_len; index++) {
+    tGPDAssetStroke *data = &tgpa->data[index];
+    bGPDstroke *gps = data->gps;
+    if (enable) {
+      gps->flag |= GP_STROKE_SELECT;
+    }
+    else {
+      gps->flag &= ~GP_STROKE_SELECT;
+    }
+
+    bGPDspoint *pt;
+    int i;
+
+    for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) {
+      if (enable) {
+        pt->flag |= GP_SPOINT_SELECT;
+      }
+      else {
+        pt->flag &= ~GP_SPOINT_SELECT;
+      }
+    }
+  }
+}
+
 /* Helper: Append all strokes from the asset in the target data block. */
 static bool gpencil_asset_append_strokes(tGPDasset *tgpa)
 {
@@ -983,6 +1020,20 @@ static bool gpencil_asset_append_strokes(tGPDasset *tgpa)
     }
   }
 
+  /* Unselect any stroke. */
+  LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd_target->layers) {
+    LISTBASE_FOREACH (bGPDframe *, gpf, &gpl->frames) {
+      LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) {
+        gps->flag &= ~GP_STROKE_SELECT;
+        bGPDspoint *pt;
+        int i;
+        for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) {
+          pt->flag &= ~GP_SPOINT_SELECT;
+        }
+      }
+    }
+  }
+
   /* Prepare 2D cage. */
   gpencil_2d_cage_calc(tgpa);
   BKE_gpencil_centroid_3d(tgpa->gpd_asset, tgpa->asset_center);
@@ -1253,6 +1304,9 @@ static int gpencil_asset_import_modal(bContext *C, wmOperator *op, const wmEvent
             ED_area_status_text(tgpa->area, NULL);
             ED_workspace_status_text(C, NULL);
             WM_cursor_modal_restore(win);
+            /* Apply selection depending of mode. */
+            gpencil_asset_set_selection(tgpa, GPENCIL_EDIT_MODE(tgpa->gpd));
+
             gpencil_asset_import_exit(C, op);
             return OPERATOR_FINISHED;
           }
@@ -1291,6 +1345,8 @@ static int gpencil_asset_import_modal(bContext *C, wmOperator *op, const wmEvent
       ED_area_status_text(tgpa->area, NULL);
       ED_workspace_status_text(C, NULL);
       WM_cursor_modal_restore(win);
+      /* Apply selection depending of mode. */
+      gpencil_asset_set_selection(tgpa, GPENCIL_EDIT_MODE(tgpa->gpd));
 
       /* Clean up temp data. */
       gpencil_asset_import_exit(C, op);



More information about the Bf-blender-cvs mailing list