[Bf-blender-cvs] [3437544] GPencil_EditStrokes: Code cleanup: Moving from custom macro-based loopers to the context-based method

Joshua Leung noreply at git.blender.org
Sat Oct 11 14:39:24 CEST 2014


Commit: 3437544b885d6961e46ac9a84388a931e3e09e53
Author: Joshua Leung
Date:   Sun Oct 12 01:38:16 2014 +1300
Branches: GPencil_EditStrokes
https://developer.blender.org/rB3437544b885d6961e46ac9a84388a931e3e09e53

Code cleanup: Moving from custom macro-based loopers to the context-based method

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

M	source/blender/blenkernel/BKE_context.h
M	source/blender/blenkernel/intern/context.c
M	source/blender/editors/gpencil/gpencil_intern.h
M	source/blender/editors/gpencil/gpencil_select.c

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

diff --git a/source/blender/blenkernel/BKE_context.h b/source/blender/blenkernel/BKE_context.h
index 877e376..ae0ef9c 100644
--- a/source/blender/blenkernel/BKE_context.h
+++ b/source/blender/blenkernel/BKE_context.h
@@ -56,6 +56,9 @@ struct Text;
 struct ImBuf;
 struct EditBone;
 struct bPoseChannel;
+struct bGPdata;
+struct bGPDlayer;
+struct bGPDframe;
 struct wmWindow;
 struct wmWindowManager;
 struct SpaceText;
@@ -275,6 +278,14 @@ struct bPoseChannel *CTX_data_active_pose_bone(const bContext *C);
 int CTX_data_selected_pose_bones(const bContext *C, ListBase *list);
 int CTX_data_visible_pose_bones(const bContext *C, ListBase *list);
 
+struct bGPdata *CTX_data_gpencil_data(const bContext *C);
+struct bGPDlayer *CTX_data_active_gpencil_layer(const bContext *C);
+struct bGPDframe *CTX_data_active_gpencil_frame(const bContext *C);
+int CTX_data_visible_gpencil_layers(const bContext *C, ListBase *list);
+int CTX_data_editable_gpencil_layers(const bContext *C, ListBase *list);
+int CTX_data_editable_gpencil_strokes(const bContext *C, ListBase *list);
+
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/source/blender/blenkernel/intern/context.c b/source/blender/blenkernel/intern/context.c
index de285f8..4d207a5 100644
--- a/source/blender/blenkernel/intern/context.c
+++ b/source/blender/blenkernel/intern/context.c
@@ -37,6 +37,7 @@
 #include "DNA_windowmanager_types.h"
 #include "DNA_object_types.h"
 #include "DNA_linestyle_types.h"
+#include "DNA_gpencil_types.h"
 
 #include "BLI_listbase.h"
 #include "BLI_string.h"
@@ -1090,3 +1091,34 @@ int CTX_data_visible_pose_bones(const bContext *C, ListBase *list)
 {
 	return ctx_data_collection_get(C, "visible_pose_bones", list);
 }
+
+bGPdata *CTX_data_gpencil_data(const bContext *C)
+{
+	return ctx_data_pointer_get(C, "gpencil_data");
+}
+
+bGPDlayer *CTX_data_active_gpencil_layer(const bContext *C)
+{
+	return ctx_data_pointer_get(C, "active_gpencil_layer");
+}
+
+bGPDframe *CTX_data_active_gpencil_frame(const bContext *C)
+{
+	return ctx_data_pointer_get(C, "active_gpencil_frame");
+}
+
+int CTX_data_visible_gpencil_layers(const bContext *C, ListBase *list)
+{
+	return ctx_data_collection_get(C, "visible_gpencil_layers", list);
+}
+
+int CTX_data_editable_gpencil_layers(const bContext *C, ListBase *list)
+{
+	return ctx_data_collection_get(C, "editable_gpencil_layers", list);
+}
+
+int CTX_data_editable_gpencil_strokes(const bContext *C, ListBase *list)
+{
+	return ctx_data_collection_get(C, "editable_gpencil_strokes", list);
+}
+
diff --git a/source/blender/editors/gpencil/gpencil_intern.h b/source/blender/editors/gpencil/gpencil_intern.h
index e69afa9..ac1104e 100644
--- a/source/blender/editors/gpencil/gpencil_intern.h
+++ b/source/blender/editors/gpencil/gpencil_intern.h
@@ -72,31 +72,6 @@ bool gp_stroke_inside_circle(const int mval[2], const int UNUSED(mvalo[2]),
 /* gpencil_paint.c */
 void gp_point_to_xy(struct ARegion *ar, struct View2D *v2d, struct rctf *subrect, struct bGPDstroke *gps, struct bGPDspoint *pt,
                     int *r_x, int *r_y);
-					
-/* Stroke Loopers -------------------------------------- */
-
-/* Loop over all visible and selectable strokes 
- * - gpd: (bGPdata *) Grease Pencil datablock in use
- * - gps: (bGPDstroke *) identifier for the stroke found
- */
-#define GP_VISIBLE_STROKES_ITER_BEGIN(gpd, gps) \
-	{                                                                   \
-		bGPDlayer *gpl;                                                 \
-		for (gpl = (gpd)->layers.first; gpl; gpl = gpl->next) {         \
-			if (!(gpl->flag & (GP_LAYER_HIDE | GP_LAYER_LOCKED)) &&     \
-			    (gpl->actframe))                                        \
-			{                                                           \
-				bGPDframe *gpf = gpl->actframe;                         \
-				bGPDstroke *gps;                                        \
-				for (gps = gpf->strokes.first; gps; gps = gps->next) {	
-					
-					/* ... code for operating on this stroke ... */
-				
-#define GP_STROKES_ITER_END \
-				}                                                       \
-			}                                                           \
-		}                                                               \
-	} (void)0
 
 /* ***************************************************** */
 /* Operator Defines */
diff --git a/source/blender/editors/gpencil/gpencil_select.c b/source/blender/editors/gpencil/gpencil_select.c
index 2d27f66..7d17d63 100644
--- a/source/blender/editors/gpencil/gpencil_select.c
+++ b/source/blender/editors/gpencil/gpencil_select.c
@@ -102,18 +102,18 @@ static int gpencil_select_all_exec(bContext *C, wmOperator *op)
 	if (action == SEL_TOGGLE) {
 		action = SEL_SELECT;
 		
-		GP_VISIBLE_STROKES_ITER_BEGIN(gpd, gps)
+		CTX_DATA_BEGIN(C, bGPDstroke *, gps, editable_gpencil_strokes)
 		{
 			if (gps->flag & GP_STROKE_SELECT) {
 				action = SEL_DESELECT;
 				break; // XXX: this only gets out of the inner loop...
 			}
 		}
-		GP_STROKES_ITER_END;
+		CTX_DATA_END;
 	}
 	
 	/* select or deselect all strokes */
-	GP_VISIBLE_STROKES_ITER_BEGIN(gpd, gps)
+	CTX_DATA_BEGIN(C, bGPDstroke *, gps, editable_gpencil_strokes)
 	{
 		bGPDspoint *pt;
 		int i;
@@ -143,7 +143,7 @@ static int gpencil_select_all_exec(bContext *C, wmOperator *op)
 		else
 			gps->flag &= ~GP_STROKE_SELECT;
 	}
-	GP_STROKES_ITER_END;
+	CTX_DATA_END;
 	
 	/* updates */
 	WM_event_add_notifier(C, NC_GPENCIL | NA_SELECTED, NULL);
@@ -313,12 +313,12 @@ static int gpencil_circle_select_exec(bContext *C, wmOperator *op)
 	
 	
 	/* find visible strokes, and select if hit */
-	GP_VISIBLE_STROKES_ITER_BEGIN(gpd, gps)
+	CTX_DATA_BEGIN(C, bGPDstroke *, gps, editable_gpencil_strokes)
 	{
 		changed |= gp_stroke_do_circle_sel(gps, ar, &ar->v2d, subrect, 
 										   mx, my, radius, select, &rect);
 	}
-	GP_STROKES_ITER_END;
+	CTX_DATA_END;
 	
 	/* updates */
 	if (changed) {
@@ -418,7 +418,7 @@ static int gpencil_select_exec(bContext *C, wmOperator *op)
 	
 	/* First Pass: Find stroke point which gets hit */
 	/* XXX: maybe we should go from the top of the stack down instead... */
-	GP_VISIBLE_STROKES_ITER_BEGIN(gpd, gps)
+	CTX_DATA_BEGIN(C, bGPDstroke *, gps, editable_gpencil_strokes)
 	{
 		bGPDspoint *pt;
 		int i;
@@ -445,7 +445,7 @@ static int gpencil_select_exec(bContext *C, wmOperator *op)
 		if (hit_index == -1) 
 			continue;
 	}
-	GP_STROKES_ITER_END;
+	CTX_DATA_END;
 	
 	/* Abort if nothing hit... */
 	if (ELEM(NULL, hit_stroke, hit_point)) {
@@ -459,7 +459,7 @@ static int gpencil_select_exec(bContext *C, wmOperator *op)
 	
 	/* If not extending selection, deselect everything else */
 	if (extend == false) {
-		GP_VISIBLE_STROKES_ITER_BEGIN(gpd, gps)
+		CTX_DATA_BEGIN(C, bGPDstroke *, gps, editable_gpencil_strokes)
 		{			
 			/* deselect stroke and its points if selected */
 			if (gps->flag & GP_STROKE_SELECT) {
@@ -475,7 +475,7 @@ static int gpencil_select_exec(bContext *C, wmOperator *op)
 				gps->flag &= ~GP_STROKE_SELECT;
 			}
 		}
-		GP_STROKES_ITER_END;
+		CTX_DATA_END;
 	}
 	
 	/* Perform selection operations... */




More information about the Bf-blender-cvs mailing list