[Bf-blender-cvs] [db916edb056] greasepencil-refactor: GPencil: New parameter to add stroke at head

Antonio Vazquez noreply at git.blender.org
Sat Jan 25 13:10:10 CET 2020


Commit: db916edb05614d12e5f0ab9953b39bde7f23a03a
Author: Antonio Vazquez
Date:   Sat Jan 25 13:09:20 2020 +0100
Branches: greasepencil-refactor
https://developer.blender.org/rBdb916edb05614d12e5f0ab9953b39bde7f23a03a

GPencil: New parameter to add stroke at head

This makes the BKE_gpencil_stroke_add function more flexible.

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

M	source/blender/blenkernel/BKE_gpencil.h
M	source/blender/blenkernel/intern/gpencil.c
M	source/blender/editors/gpencil/gpencil_add_monkey.c
M	source/blender/editors/gpencil/gpencil_add_stroke.c

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

diff --git a/source/blender/blenkernel/BKE_gpencil.h b/source/blender/blenkernel/BKE_gpencil.h
index 5305309c012..c0425709c0b 100644
--- a/source/blender/blenkernel/BKE_gpencil.h
+++ b/source/blender/blenkernel/BKE_gpencil.h
@@ -143,10 +143,8 @@ void BKE_gpencil_stroke_add_points(struct bGPDstroke *gps,
                                    const int totpoints,
                                    const float mat[4][4]);
 
-struct bGPDstroke *BKE_gpencil_stroke_add(struct bGPDframe *gpf,
-                                          int mat_idx,
-                                          int totpoints,
-                                          short thickness);
+struct bGPDstroke *BKE_gpencil_stroke_add(
+    struct bGPDframe *gpf, int mat_idx, int totpoints, short thickness, const bool insert_at_head);
 
 struct bGPDstroke *BKE_gpencil_stroke_add_existing_style(struct bGPDframe *gpf,
                                                          struct bGPDstroke *existing,
diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c
index 1efe0ed0371..a2333224415 100644
--- a/source/blender/blenkernel/intern/gpencil.c
+++ b/source/blender/blenkernel/intern/gpencil.c
@@ -474,7 +474,8 @@ void BKE_gpencil_stroke_add_points(bGPDstroke *gps,
 }
 
 /* Create a new stroke, with pre-allocated data buffers */
-bGPDstroke *BKE_gpencil_stroke_add(bGPDframe *gpf, int mat_idx, int totpoints, short thickness)
+bGPDstroke *BKE_gpencil_stroke_add(
+    bGPDframe *gpf, int mat_idx, int totpoints, short thickness, const bool insert_at_head)
 {
   /* allocate memory for a new stroke */
   bGPDstroke *gps = MEM_callocN(sizeof(bGPDstroke), "gp_stroke");
@@ -500,8 +501,13 @@ bGPDstroke *BKE_gpencil_stroke_add(bGPDframe *gpf, int mat_idx, int totpoints, s
 
   gps->mat_nr = mat_idx;
 
-  /* add to frame */
-  BLI_addtail(&gpf->strokes, gps);
+  /* Add to frame. */
+  if (!insert_at_head) {
+    BLI_addtail(&gpf->strokes, gps);
+  }
+  else {
+    BLI_addhead(&gpf->strokes, gps);
+  }
 
   return gps;
 }
@@ -510,7 +516,7 @@ bGPDstroke *BKE_gpencil_stroke_add(bGPDframe *gpf, int mat_idx, int totpoints, s
 bGPDstroke *BKE_gpencil_stroke_add_existing_style(
     bGPDframe *gpf, bGPDstroke *existing, int mat_idx, int totpoints, short thickness)
 {
-  bGPDstroke *gps = BKE_gpencil_stroke_add(gpf, mat_idx, totpoints, thickness);
+  bGPDstroke *gps = BKE_gpencil_stroke_add(gpf, mat_idx, totpoints, thickness, false);
   /* Copy run-time color data so that strokes added in the modifier has the style.
    * There are depsgraph reference pointers inside,
    * change the copy function if interfere with future drawing implementation. */
@@ -3618,7 +3624,7 @@ bool BKE_gpencil_from_image(SpaceImage *sima, bGPDframe *gpf, const float size,
     bGPDspoint *pt;
     for (int row = 0; row < img_y; row++) {
       /* Create new stroke */
-      bGPDstroke *gps = BKE_gpencil_stroke_add(gpf, 0, img_x, size * 1000);
+      bGPDstroke *gps = BKE_gpencil_stroke_add(gpf, 0, img_x, size * 1000, false);
       done = true;
       for (int col = 0; col < img_x; col++) {
         IMB_sampleImageAtLocation(ibuf, col, row, true, color);
diff --git a/source/blender/editors/gpencil/gpencil_add_monkey.c b/source/blender/editors/gpencil/gpencil_add_monkey.c
index 5c624c82638..c7447be3739 100644
--- a/source/blender/editors/gpencil/gpencil_add_monkey.c
+++ b/source/blender/editors/gpencil/gpencil_add_monkey.c
@@ -858,115 +858,115 @@ void ED_gpencil_create_monkey(bContext *C, Object *ob, float mat[4][4])
   bGPDframe *frameLines = BKE_gpencil_frame_addnew(Lines, CFRA);
 
   /* generate strokes */
-  gps = BKE_gpencil_stroke_add(frameFills, color_Skin, 270, 75);
+  gps = BKE_gpencil_stroke_add(frameFills, color_Skin, 270, 75, false);
   BKE_gpencil_stroke_add_points(gps, data0, 270, mat);
   BKE_gpencil_stroke_geometry_update(gps);
 
-  gps = BKE_gpencil_stroke_add(frameFills, color_Skin_Shadow, 33, 60);
+  gps = BKE_gpencil_stroke_add(frameFills, color_Skin_Shadow, 33, 60, false);
   BKE_gpencil_stroke_add_points(gps, data1, 33, mat);
   BKE_gpencil_stroke_geometry_update(gps);
 
-  gps = BKE_gpencil_stroke_add(frameFills, color_Skin_Shadow, 18, 60);
+  gps = BKE_gpencil_stroke_add(frameFills, color_Skin_Shadow, 18, 60, false);
   BKE_gpencil_stroke_add_points(gps, data2, 18, mat);
   BKE_gpencil_stroke_geometry_update(gps);
 
-  gps = BKE_gpencil_stroke_add(frameFills, color_Skin_Light, 64, 60);
+  gps = BKE_gpencil_stroke_add(frameFills, color_Skin_Light, 64, 60, false);
   BKE_gpencil_stroke_add_points(gps, data3, 64, mat);
   BKE_gpencil_stroke_geometry_update(gps);
 
-  gps = BKE_gpencil_stroke_add(frameFills, color_Skin_Light, 33, 60);
+  gps = BKE_gpencil_stroke_add(frameFills, color_Skin_Light, 33, 60, false);
   BKE_gpencil_stroke_add_points(gps, data4, 33, mat);
   BKE_gpencil_stroke_geometry_update(gps);
 
-  gps = BKE_gpencil_stroke_add(frameFills, color_Skin_Light, 64, 60);
+  gps = BKE_gpencil_stroke_add(frameFills, color_Skin_Light, 64, 60, false);
   BKE_gpencil_stroke_add_points(gps, data5, 64, mat);
   BKE_gpencil_stroke_geometry_update(gps);
 
-  gps = BKE_gpencil_stroke_add(frameFills, color_Skin_Light, 33, 60);
+  gps = BKE_gpencil_stroke_add(frameFills, color_Skin_Light, 33, 60, false);
   BKE_gpencil_stroke_add_points(gps, data6, 33, mat);
   BKE_gpencil_stroke_geometry_update(gps);
 
-  gps = BKE_gpencil_stroke_add(frameFills, color_Skin_Light, 18, 40);
+  gps = BKE_gpencil_stroke_add(frameFills, color_Skin_Light, 18, 40, false);
   BKE_gpencil_stroke_add_points(gps, data7, 18, mat);
   BKE_gpencil_stroke_geometry_update(gps);
 
-  gps = BKE_gpencil_stroke_add(frameFills, color_Eyes, 49, 60);
+  gps = BKE_gpencil_stroke_add(frameFills, color_Eyes, 49, 60, false);
   BKE_gpencil_stroke_add_points(gps, data8, 49, mat);
   BKE_gpencil_stroke_geometry_update(gps);
 
-  gps = BKE_gpencil_stroke_add(frameFills, color_Skin_Shadow, 33, 60);
+  gps = BKE_gpencil_stroke_add(frameFills, color_Skin_Shadow, 33, 60, false);
   BKE_gpencil_stroke_add_points(gps, data9, 33, mat);
   BKE_gpencil_stroke_geometry_update(gps);
 
-  gps = BKE_gpencil_stroke_add(frameFills, color_Eyes, 49, 60);
+  gps = BKE_gpencil_stroke_add(frameFills, color_Eyes, 49, 60, false);
   BKE_gpencil_stroke_add_points(gps, data10, 49, mat);
   BKE_gpencil_stroke_geometry_update(gps);
 
-  gps = BKE_gpencil_stroke_add(frameFills, color_Skin_Shadow, 18, 40);
+  gps = BKE_gpencil_stroke_add(frameFills, color_Skin_Shadow, 18, 40, false);
   BKE_gpencil_stroke_add_points(gps, data11, 18, mat);
   BKE_gpencil_stroke_geometry_update(gps);
 
-  gps = BKE_gpencil_stroke_add(frameFills, color_Skin_Shadow, 18, 40);
+  gps = BKE_gpencil_stroke_add(frameFills, color_Skin_Shadow, 18, 40, false);
   BKE_gpencil_stroke_add_points(gps, data12, 18, mat);
   BKE_gpencil_stroke_geometry_update(gps);
 
-  gps = BKE_gpencil_stroke_add(frameLines, color_Black, 33, 60);
+  gps = BKE_gpencil_stroke_add(frameLines, color_Black, 33, 60, false);
   BKE_gpencil_stroke_add_points(gps, data13, 33, mat);
   BKE_gpencil_stroke_geometry_update(gps);
 
-  gps = BKE_gpencil_stroke_add(frameLines, color_Black, 33, 60);
+  gps = BKE_gpencil_stroke_add(frameLines, color_Black, 33, 60, false);
   BKE_gpencil_stroke_add_points(gps, data14, 33, mat);
   BKE_gpencil_stroke_geometry_update(gps);
 
-  gps = BKE_gpencil_stroke_add(frameLines, color_Black, 65, 60);
+  gps = BKE_gpencil_stroke_add(frameLines, color_Black, 65, 60, false);
   BKE_gpencil_stroke_add_points(gps, data15, 65, mat);
   BKE_gpencil_stroke_geometry_update(gps);
 
-  gps = BKE_gpencil_stroke_add(frameLines, color_Black, 34, 60);
+  gps = BKE_gpencil_stroke_add(frameLines, color_Black, 34, 60, false);
   BKE_gpencil_stroke_add_points(gps, data16, 34, mat);
   BKE_gpencil_stroke_geometry_update(gps);
 
-  gps = BKE_gpencil_stroke_add(frameLines, color_Black, 33, 60);
+  gps = BKE_gpencil_stroke_add(frameLines, color_Black, 33, 60, false);
   BKE_gpencil_stroke_add_points(gps, data17, 33, mat);
   BKE_gpencil_stroke_geometry_update(gps);
 
-  gps = BKE_gpencil_stroke_add(frameLines, color_Black, 33, 40);
+  gps = BKE_gpencil_stroke_add(frameLines, color_Black, 33, 40, false);
   BKE_gpencil_stroke_add_points(gps, data18, 33, mat);
   BKE_gpencil_stroke_geometry_update(gps);
 
-  gps = BKE_gpencil_stroke_add(frameLines, color_Black, 34, 40);
+  gps = BKE_gpencil_stroke_add(frameLines, color_Black, 34, 40, false);
   BKE_gpencil_stroke_add_points(gps, data19, 34, mat);
   BKE_gpencil_stroke_geometry_update(gps);
 
-  gps = BKE_gpencil_stroke_add(frameLines, color_Black, 33, 60);
+  gps = BKE_gpencil_stroke_add(frameLines, color_Black, 33, 60, false);
   BKE_gpencil_stroke_add_points(gps, data20, 33, mat);
   BKE_gpencil_stroke_geometry_update(gps);
 
-  gps = BKE_gpencil_stroke_add(frameLines, color_Black, 64, 60);
+  gps = BKE_gpencil_stroke_add(frameLines, color_Black, 64, 60, false);
   BKE_gpencil_stroke_add_points(gps, data21, 64, mat);
   BKE_gpencil_stroke_geometry_update(gps);
 
-  gps = BKE_gpencil_stroke_add(frameLines, color_Pupils, 26, 60);
+  gps = BKE_gpencil_stroke_add(frameLines, color_Pupils, 26, 60, false);
   BKE_gpencil_stroke_add_points(gps, data22, 26, mat);
   BKE_gpencil_stroke_geometry_update(gps);
 
-  gps = BKE_gpencil_stroke_add(frameLines, color_Pupils, 26, 60);
+  gps = BKE_gpencil_stroke_add(frameLines, color_Pupils, 26, 60, false);
   BKE_gpencil_stroke_add_points(gps, data23, 26, mat);
   BKE_gpencil_stroke_geometry_update(gps);
 
-  gps = BKE_gpencil_stroke_add(frameLines, color_Black, 33, 60);
+  gps = BKE_gpencil_stroke_add(frameLines, color_Black, 33, 60, false);
   BKE_gpencil_stroke_add_points(gps, data24, 33, mat);
   BKE_gpencil_stroke_geometry_update(gps);
 
-  gps = BKE_gpencil_stroke_add(frameLines, color_Black, 18, 40);
+  gps = BKE_gpencil_stroke_add(frameLines, color_Black, 18, 40, false);
   BKE_gpencil_stroke_add_points(gps, data25, 18, mat);
   BKE_gpencil_stroke_geometry_update(gps);
 
-  gps = BKE_gpencil_stroke_add(frameLines, color_Black, 18, 40);
+  gps = BKE_gpencil_stroke_add(frameLines, color_Black, 18, 40, false);
   BKE_gpencil_stroke_add_points(gps, data26, 18, mat);
   BKE_gpencil_stroke_geometry_update(gps)

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list