[Bf-blender-cvs] [5be7c40] GPencil_EditStrokes: Drawing code refactoring: Move out logic for testing if a stroke can be drawn into a separate function

Joshua Leung noreply at git.blender.org
Fri Oct 10 12:26:00 CEST 2014


Commit: 5be7c4055202db63187488092fd546e530cb5205
Author: Joshua Leung
Date:   Fri Oct 10 12:24:48 2014 +1300
Branches: GPencil_EditStrokes
https://developer.blender.org/rB5be7c4055202db63187488092fd546e530cb5205

Drawing code refactoring: Move out logic for testing if a stroke can be drawn into a separate function

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

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

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

diff --git a/source/blender/editors/gpencil/drawgpencil.c b/source/blender/editors/gpencil/drawgpencil.c
index 0b59c80..27bba7e 100644
--- a/source/blender/editors/gpencil/drawgpencil.c
+++ b/source/blender/editors/gpencil/drawgpencil.c
@@ -470,7 +470,38 @@ static void gp_draw_stroke(bGPDspoint *points, int totpoints, short thickness_s,
 	}
 }
 
-/* ----- General Drawing ------ */
+/* ----- Strokes Drawing ------ */
+
+/* Helper for doing all the checks on whether a stroke can be drawn */
+static bool gp_can_draw_stroke(const bGPDstroke *gps, const int dflag)
+{
+	/* skip stroke if it isn't in the right display space for this drawing context */
+	/* 1) 3D Strokes */
+	if ((dflag & GP_DRAWDATA_ONLY3D) && !(gps->flag & GP_STROKE_3DSPACE))
+		return false;
+	if (!(dflag & GP_DRAWDATA_ONLY3D) && (gps->flag & GP_STROKE_3DSPACE))
+		return false;
+		
+	/* 2) Screen Space 2D Strokes */
+	if ((dflag & GP_DRAWDATA_ONLYV2D) && !(gps->flag & GP_STROKE_2DSPACE))
+		return false;
+	if (!(dflag & GP_DRAWDATA_ONLYV2D) && (gps->flag & GP_STROKE_2DSPACE))
+		return false;
+		
+	/* 3) Image Space (2D) */
+	if ((dflag & GP_DRAWDATA_ONLYI2D) && !(gps->flag & GP_STROKE_2DIMAGE))
+		return false;
+	if (!(dflag & GP_DRAWDATA_ONLYI2D) && (gps->flag & GP_STROKE_2DIMAGE))
+		return false;
+		
+		
+	/* skip stroke if it doesn't have any valid data */
+	if ((gps->points == NULL) || (gps->totpoints < 1))
+		return false;
+		
+	/* stroke can be drawn */
+	return true;
+}
 
 /* draw a set of strokes */
 static void gp_draw_strokes(bGPDframe *gpf, int offsx, int offsy, int winx, int winy, int dflag,
@@ -482,20 +513,8 @@ static void gp_draw_strokes(bGPDframe *gpf, int offsx, int offsy, int winx, int
 	glColor4fv(color);
 	
 	for (gps = gpf->strokes.first; gps; gps = gps->next) {
-		/* check if stroke can be drawn - checks here generally fall into pairs */
-		if ((dflag & GP_DRAWDATA_ONLY3D) && !(gps->flag & GP_STROKE_3DSPACE))
-			continue;
-		if (!(dflag & GP_DRAWDATA_ONLY3D) && (gps->flag & GP_STROKE_3DSPACE))
-			continue;
-		if ((dflag & GP_DRAWDATA_ONLYV2D) && !(gps->flag & GP_STROKE_2DSPACE))
-			continue;
-		if (!(dflag & GP_DRAWDATA_ONLYV2D) && (gps->flag & GP_STROKE_2DSPACE))
-			continue;
-		if ((dflag & GP_DRAWDATA_ONLYI2D) && !(gps->flag & GP_STROKE_2DIMAGE))
-			continue;
-		if (!(dflag & GP_DRAWDATA_ONLYI2D) && (gps->flag & GP_STROKE_2DIMAGE))
-			continue;
-		if ((gps->points == NULL) || (gps->totpoints < 1))
+		/* check if stroke can be drawn */
+		if (gp_can_draw_stroke(gps, dflag) == false)
 			continue;
 		
 		/* check which stroke-drawer to use */
@@ -546,6 +565,8 @@ static void gp_draw_strokes(bGPDframe *gpf, int offsx, int offsy, int winx, int
 	}
 }
 
+/* ----- General Drawing ------ */
+
 /* draw grease-pencil datablock */
 static void gp_draw_data(bGPdata *gpd, int offsx, int offsy, int winx, int winy, int cfra, int dflag)
 {




More information about the Bf-blender-cvs mailing list