[Bf-blender-cvs] [277a51dfb69] greasepencil-refactor: GPencil: Cleanup - Replace more loops with LISTBASE_FOREACH

Antonio Vazquez noreply at git.blender.org
Fri Jan 24 10:36:35 CET 2020


Commit: 277a51dfb69aa6847b4ec541c817feec8406801d
Author: Antonio Vazquez
Date:   Fri Jan 24 10:36:12 2020 +0100
Branches: greasepencil-refactor
https://developer.blender.org/rB277a51dfb69aa6847b4ec541c817feec8406801d

GPencil: Cleanup - Replace more loops with LISTBASE_FOREACH

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

M	source/blender/blenkernel/intern/gpencil.c
M	source/blender/blenloader/intern/readfile.c
M	source/blender/blenloader/intern/versioning_270.c
M	source/blender/blenloader/intern/versioning_280.c
M	source/blender/blenloader/intern/writefile.c
M	source/blender/editors/armature/armature_naming.c
M	source/blender/editors/gpencil/annotate_draw.c
M	source/blender/editors/gpencil/gpencil_armature.c
M	source/blender/editors/gpencil/gpencil_data.c
M	source/blender/editors/gpencil/gpencil_edit.c
M	source/blender/editors/gpencil/gpencil_fill.c
M	source/blender/editors/gpencil/gpencil_intern.h
M	source/blender/editors/gpencil/gpencil_merge.c
M	source/blender/editors/gpencil/gpencil_ops_versioning.c
M	source/blender/editors/gpencil/gpencil_sculpt_paint.c
M	source/blender/editors/gpencil/gpencil_utils.c
M	source/blender/editors/gpencil/gpencil_vertex_ops.c
M	source/blender/editors/gpencil/gpencil_vertex_paint.c
M	source/blender/editors/gpencil/gpencil_weight_paint.c
M	source/blender/editors/object/object_add.c
M	source/blender/editors/object/object_transform.c
M	source/blender/editors/space_view3d/view3d_gizmo_ruler.c
M	source/blender/editors/transform/transform_gizmo_3d.c
M	source/blender/gpencil_modifiers/intern/MOD_gpencilarmature.c
M	source/blender/gpencil_modifiers/intern/MOD_gpencilarray.c
M	source/blender/gpencil_modifiers/intern/MOD_gpencilhook.c
M	source/blender/gpencil_modifiers/intern/MOD_gpencillattice.c
M	source/blender/gpencil_modifiers/intern/MOD_gpencilmirror.c
M	source/blender/gpencil_modifiers/intern/MOD_gpencilmultiply.c
M	source/blender/gpencil_modifiers/intern/MOD_gpencilnoise.c
M	source/blender/gpencil_modifiers/intern/MOD_gpenciloffset.c
M	source/blender/gpencil_modifiers/intern/MOD_gpencilsimplify.c
M	source/blender/gpencil_modifiers/intern/MOD_gpencilsmooth.c
M	source/blender/gpencil_modifiers/intern/MOD_gpencilsubdiv.c
M	source/blender/gpencil_modifiers/intern/MOD_gpencilthick.c
M	source/blender/gpencil_modifiers/intern/MOD_gpencilvertexcolor.c
M	source/blender/makesrna/intern/rna_gpencil.c

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

diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c
index 4c2de74e5a9..c8be8914db1 100644
--- a/source/blender/blenkernel/intern/gpencil.c
+++ b/source/blender/blenkernel/intern/gpencil.c
@@ -302,7 +302,7 @@ bGPDframe *BKE_gpencil_frame_addcopy(bGPDlayer *gpl, int cframe)
   new_frame = BKE_gpencil_frame_duplicate(gpl->actframe);
 
   /* Find frame to insert it before */
-  for (bGPDframe *gpf = gpl->frames.first; gpf; gpf = gpf->next) {
+  LISTBASE_FOREACH (bGPDframe *, gpf, &gpl->frames) {
     if (gpf->framenum > cframe) {
       /* Add it here */
       BLI_insertlinkbefore(&gpl->frames, gpf, new_frame);
@@ -1288,7 +1288,7 @@ bool BKE_gpencil_data_minmax(const bGPdata *gpd, float r_min[3], float r_max[3])
     bGPDframe *gpf = gpl->actframe;
 
     if (gpf != NULL) {
-      for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) {
+      LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) {
         changed = BKE_gpencil_stroke_minmax(gps, false, r_min, r_max);
       }
     }
@@ -1380,8 +1380,8 @@ void BKE_gpencil_transform(bGPdata *gpd, float mat[4][4])
       continue;
     }
 
-    for (bGPDframe *gpf = gpl->frames.first; gpf; gpf = gpf->next) {
-      for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) {
+    LISTBASE_FOREACH (bGPDframe *, gpf, &gpl->frames) {
+      LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) {
         bGPDspoint *pt;
         int i;
 
@@ -2237,7 +2237,7 @@ void BKE_gpencil_get_range_selected(bGPDlayer *gpl, int *r_initframe, int *r_end
   *r_initframe = gpl->actframe->framenum;
   *r_endframe = gpl->actframe->framenum;
 
-  for (bGPDframe *gpf = gpl->frames.first; gpf; gpf = gpf->next) {
+  LISTBASE_FOREACH (bGPDframe *, gpf, &gpl->frames) {
     if (gpf->flag & GP_FRAME_SELECT) {
       if (gpf->framenum < *r_initframe) {
         *r_initframe = gpf->framenum;
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index bad7260025e..79edaaa5f2b 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -7212,7 +7212,7 @@ static void lib_link_gpencil(FileData *fd, Main *main)
   for (bGPdata *gpd = main->gpencils.first; gpd; gpd = gpd->id.next) {
     if (gpd->id.tag & LIB_TAG_NEED_LINK) {
       /* Layers */
-      for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) {
+      LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) {
         /* Layer -> Parent References */
         gpl->parent = newlibadr(fd, gpd->id.lib, gpl->parent);
       }
@@ -11227,7 +11227,7 @@ static void expand_gpencil(FileData *fd, Main *mainvar, bGPdata *gpd)
     expand_animdata(fd, mainvar, gpd->adt);
   }
 
-  for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) {
+  LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) {
     expand_doit(fd, mainvar, gpl->parent);
   }
 
diff --git a/source/blender/blenloader/intern/versioning_270.c b/source/blender/blenloader/intern/versioning_270.c
index a04a2a99c94..87957b550c5 100644
--- a/source/blender/blenloader/intern/versioning_270.c
+++ b/source/blender/blenloader/intern/versioning_270.c
@@ -1130,7 +1130,7 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *bmain)
       /* Ensure that the datablock's onion-skinning toggle flag
        * stays in sync with the status of the actual layers
        */
-      for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) {
+      LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) {
         if (gpl->flag & GP_LAYER_ONIONSKIN) {
           enabled = true;
         }
@@ -1358,7 +1358,7 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *bmain)
         if (BLI_listbase_is_empty(&gpd->palettes)) {
           /* create palette */
           bGPDpalette *palette = BKE_gpencil_palette_addnew(gpd, "GP_Palette");
-          for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) {
+          LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) {
             /* create color using layer name */
             bGPDpalettecolor *palcolor = BKE_gpencil_palettecolor_addnew(palette, gpl->info);
             if (palcolor != NULL) {
@@ -1386,8 +1386,8 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *bmain)
               ARRAY_SET_ITEMS(gpl->tintcolor, 0.0f, 0.0f, 0.0f, 0.0f);
 
               /* flush relevant layer-settings to strokes */
-              for (bGPDframe *gpf = gpl->frames.first; gpf; gpf = gpf->next) {
-                for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) {
+              LISTBASE_FOREACH (bGPDframe *, gpf, &gpl->frames) {
+                LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) {
                   /* set stroke to palette and force recalculation */
                   BLI_strncpy(gps->colorname, gpl->info, sizeof(gps->colorname));
                   gps->thickness = gpl->thickness;
diff --git a/source/blender/blenloader/intern/versioning_280.c b/source/blender/blenloader/intern/versioning_280.c
index 0e8d120bb29..34351ac8869 100644
--- a/source/blender/blenloader/intern/versioning_280.c
+++ b/source/blender/blenloader/intern/versioning_280.c
@@ -576,7 +576,7 @@ static void do_versions_fix_annotations(bGPdata *gpd)
   for (const bGPDpalette *palette = gpd->palettes.first; palette; palette = palette->next) {
     for (bGPDpalettecolor *palcolor = palette->colors.first; palcolor; palcolor = palcolor->next) {
       /* fix layers */
-      for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) {
+      LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) {
         /* unlock/unhide layer */
         gpl->flag &= ~GP_LAYER_LOCKED;
         gpl->flag &= ~GP_LAYER_HIDE;
@@ -585,8 +585,8 @@ static void do_versions_fix_annotations(bGPdata *gpd)
         /* disable tint */
         gpl->tintcolor[3] = 0.0f;
 
-        for (bGPDframe *gpf = gpl->frames.first; gpf; gpf = gpf->next) {
-          for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) {
+        LISTBASE_FOREACH (bGPDframe *, gpf, &gpl->frames) {
+          LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) {
             if ((gps->colorname[0] != '\0') && (STREQ(gps->colorname, palcolor->info))) {
               /* copy color settings */
               copy_v4_v4(gpl->color, palcolor->color);
@@ -1553,7 +1553,7 @@ void do_versions_after_linking_280(Main *bmain, ReportList *UNUSED(reports))
         if (gpd == NULL) {
           continue;
         }
-        for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) {
+        LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) {
           if (STREQ(gpl->info, "RulerData3D")) {
             gpl->flag |= GP_LAYER_IS_RULER;
             break;
@@ -2592,7 +2592,7 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain)
     }
     if (!DNA_struct_elem_find(fd->filesdna, "bGPDlayer", "short", "line_change")) {
       for (bGPdata *gpd = bmain->gpencils.first; gpd; gpd = gpd->id.next) {
-        for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) {
+        LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) {
           gpl->line_change = gpl->thickness;
           if ((gpl->thickness < 1) || (gpl->thickness > 10)) {
             gpl->thickness = 3;
@@ -3162,7 +3162,7 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain)
     /* init Annotations onion skin */
     if (!DNA_struct_elem_find(fd->filesdna, "bGPDlayer", "int", "gstep")) {
       for (bGPdata *gpd = bmain->gpencils.first; gpd; gpd = gpd->id.next) {
-        for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) {
+        LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) {
           ARRAY_SET_ITEMS(gpl->gcolor_prev, 0.302f, 0.851f, 0.302f);
           ARRAY_SET_ITEMS(gpl->gcolor_next, 0.250f, 0.1f, 1.0f);
         }
@@ -3587,7 +3587,7 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain)
         if (gpd->flag & GP_DATA_ANNOTATIONS) {
           continue;
         }
-        for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) {
+        LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) {
           /* default channel color */
           ARRAY_SET_ITEMS(gpl->color, 0.2f, 0.2f, 0.2f);
         }
@@ -3692,9 +3692,9 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain)
     /* init grease pencil stroke gradients */
     if (!DNA_struct_elem_find(fd->filesdna, "bGPDstroke", "float", "gradient_f")) {
       for (bGPdata *gpd = bmain->gpencils.first; gpd; gpd = gpd->id.next) {
-        for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) {
-          for (bGPDframe *gpf = gpl->frames.first; gpf; gpf = gpf->next) {
-            for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) {
+        LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) {
+          LISTBASE_FOREACH (bGPDframe *, gpf, &gpl->frames) {
+            LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) {
               gps->gradient_f = 1.0f;
               gps->gradient_s[0] = 1.0f;
               gps->gradient_s[1] = 1.0f;
@@ -4198,9 +4198,9 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain)
       /* Initialize new grease pencil uv scale parameter. */
       if (!DNA_struct_elem_find(fd->filesdna, "bGPDstroke", "float", "uv_scale")) {
         for (bGPdata *gpd = bmain->gpencils.first; gpd; gpd = gpd->id.next) {
-          for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) {
-            for (bGPDframe *gpf = gpl->frames.first; gpf; gpf = gpf->next) {
-              for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) {
+          LISTBASE_FOREACH (bGPDlayer *, gpl, &gpd->layers) {
+            LISTBASE_FOREACH (bGPDframe *, gpf, &gpl->frames) {
+              LISTBASE_FOREACH (bGPDstroke *, gps, &gpf->strokes) {
                 gps->uv_scale = 1.0f;
               }
             }
@@ -4370,7 +4370,7 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain)
     {
       if (!DNA_struct_elem_find(fd->filesdna, "bGPDlayer", "float", "vertex_paint_opacity")) {
         for (bGPdata *gpd = bmain->gpencils.first; gpd; gpd

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list