[Bf-blender-cvs] [4de69e3e1ae] greasepencil-object: Cleanup: Function to avoid code duplication

Antonio Vazquez noreply at git.blender.org
Fri Dec 15 12:35:15 CET 2017


Commit: 4de69e3e1ae2aa3936d474de75987a4dbaa4ad7d
Author: Antonio Vazquez
Date:   Fri Dec 15 11:44:38 2017 +0100
Branches: greasepencil-object
https://developer.blender.org/rB4de69e3e1ae2aa3936d474de75987a4dbaa4ad7d

Cleanup: Function to avoid code duplication

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

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

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

diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c
index a9dea2ca39c..376ff234774 100644
--- a/source/blender/editors/gpencil/gpencil_paint.c
+++ b/source/blender/editors/gpencil/gpencil_paint.c
@@ -1090,6 +1090,19 @@ static float gp_stroke_eraser_calc_influence(tGPsdata *p, const int mval[2], con
 	return fac;
 }
 
+/* helper to free a stroke */
+static void gp_free_stroke(bGPdata *gpd, bGPDframe *gpf, bGPDstroke *gps)
+{
+	if (gps->points) {
+		BKE_gpencil_free_stroke_weights(gps);
+		MEM_freeN(gps->points);
+	}
+	if (gps->triangles)
+		MEM_freeN(gps->triangles);
+	BLI_freelinkN(&gpf->strokes, gps);
+	BKE_gpencil_batch_cache_dirty(gpd);
+}
+
 /* eraser tool - evaluation per stroke */
 /* TODO: this could really do with some optimization (KD-Tree/BVH?) */
 static void gp_stroke_eraser_dostroke(tGPsdata *p,
@@ -1109,14 +1122,7 @@ static void gp_stroke_eraser_dostroke(tGPsdata *p,
 
 	if (gps->totpoints == 0) {
 		/* just free stroke */
-		if (gps->points) {
-			BKE_gpencil_free_stroke_weights(gps);
-			MEM_freeN(gps->points);
-		}
-		if (gps->triangles)
-			MEM_freeN(gps->triangles);
-		BLI_freelinkN(&gpf->strokes, gps);
-		BKE_gpencil_batch_cache_dirty(p->gpd);
+		gp_free_stroke(p->gpd, gpf, gps);
 	}
 	else if (gps->totpoints == 1) {
 		/* only process if it hasn't been masked out... */
@@ -1129,15 +1135,7 @@ static void gp_stroke_eraser_dostroke(tGPsdata *p,
 				/* only check if point is inside */
 				if (len_v2v2_int(mval, pc1) <= radius) {
 					/* free stroke */
-					// XXX: pressure sensitive eraser should apply here too?
-					if (gps->points) {
-						BKE_gpencil_free_stroke_weights(gps);
-						MEM_freeN(gps->points);
-					}
-					if (gps->triangles)
-						MEM_freeN(gps->triangles);
-					BLI_freelinkN(&gpf->strokes, gps);
-					BKE_gpencil_batch_cache_dirty(p->gpd);
+					gp_free_stroke(p->gpd, gpf, gps);
 				}
 			}
 		}
@@ -1160,14 +1158,7 @@ static void gp_stroke_eraser_dostroke(tGPsdata *p,
 				/* only check if point is inside */
 				if (len_v2v2_int(mval, pc1) <= radius) {
 					/* free stroke */
-					if (gps->points) {
-						BKE_gpencil_free_stroke_weights(gps);
-						MEM_freeN(gps->points);
-					}
-					if (gps->triangles)
-						MEM_freeN(gps->triangles);
-					BLI_freelinkN(&gpf->strokes, gps);
-					BKE_gpencil_batch_cache_dirty(p->gpd);
+					gp_free_stroke(p->gpd, gpf, gps);
 					return;
 				}
 			}



More information about the Bf-blender-cvs mailing list