[Bf-blender-cvs] [08970951c6a] greasepencil-object: Cleanup: Group all paint creations in function

Antonio Vazquez noreply at git.blender.org
Wed Mar 14 10:10:50 CET 2018


Commit: 08970951c6ac8cdbbcbe8c2bdce313915feeaf9a
Author: Antonio Vazquez
Date:   Wed Mar 14 09:49:44 2018 +0100
Branches: greasepencil-object
https://developer.blender.org/rB08970951c6ac8cdbbcbe8c2bdce313915feeaf9a

Cleanup: Group all paint creations in function

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

M	source/blender/blenkernel/BKE_brush.h
M	source/blender/blenkernel/intern/brush.c
M	source/blender/editors/gpencil/gpencil_data.c
M	source/blender/editors/gpencil/gpencil_edit.c
M	source/blender/editors/gpencil/gpencil_paint.c
M	source/blender/editors/gpencil/gpencil_primitive.c
M	source/blender/editors/gpencil/gpencil_utils.c

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

diff --git a/source/blender/blenkernel/BKE_brush.h b/source/blender/blenkernel/BKE_brush.h
index ca864479585..869f5d93d09 100644
--- a/source/blender/blenkernel/BKE_brush.h
+++ b/source/blender/blenkernel/BKE_brush.h
@@ -30,6 +30,7 @@
 enum eCurveMappingPreset;
 struct bContext;
 struct Brush;
+struct Paint;
 struct ImBuf;
 struct ImagePool;
 struct Main;
@@ -57,6 +58,7 @@ void BKE_brush_free(struct Brush *brush);
 void BKE_brush_sculpt_reset(struct Brush *brush);
 void BKE_brush_gpencil_presets(struct bContext *C);
 struct Brush *BKE_brush_getactive_gpencil(struct ToolSettings *ts);
+struct Paint *BKE_brush_get_gpencil_paint(struct ToolSettings *ts);
 
 /* image icon function */
 struct ImBuf *get_brush_icon(struct Brush *brush);
diff --git a/source/blender/blenkernel/intern/brush.c b/source/blender/blenkernel/intern/brush.c
index 31dde2e9d46..3c6166e0491 100644
--- a/source/blender/blenkernel/intern/brush.c
+++ b/source/blender/blenkernel/intern/brush.c
@@ -186,14 +186,7 @@ Brush *BKE_brush_add(Main *bmain, const char *name, const eObjectMode ob_mode)
 Brush *BKE_brush_add_gpencil(Main *bmain, ToolSettings *ts, const char *name)
 {
 	Brush *brush;
-
-	/* alloc paint session */
-	if (ts->gp_paint == NULL) {
-		ts->gp_paint = MEM_callocN(sizeof(GpPaint), "GpPaint");
-	}
-
-	Paint *paint = &ts->gp_paint->paint;
-
+	Paint *paint = BKE_brush_get_gpencil_paint(ts);
 	brush = BKE_brush_add(bmain, name, OB_MODE_GPENCIL_PAINT);
 
 	BKE_paint_brush_set(paint, brush);
@@ -201,6 +194,17 @@ Brush *BKE_brush_add_gpencil(Main *bmain, ToolSettings *ts, const char *name)
 	/* return brush */
 	return brush;
 }
+
+Paint *BKE_brush_get_gpencil_paint(ToolSettings *ts)
+{
+	/* alloc paint session */
+	if (ts->gp_paint == NULL) {
+		ts->gp_paint = MEM_callocN(sizeof(GpPaint), "GpPaint");
+	}
+
+	return &ts->gp_paint->paint;
+}
+
 /* grease pencil cumapping->preset */
 typedef enum eGPCurveMappingPreset {
 	GPCURVE_PRESET_PENCIL = 0,
@@ -256,12 +260,7 @@ void BKE_brush_gpencil_presets(bContext *C)
 #define LAZY_FACTOR 0.9f
 
 	ToolSettings *ts = CTX_data_tool_settings(C);
-	/* alloc paint session */
-	if (ts->gp_paint == NULL) {
-		ts->gp_paint = MEM_callocN(sizeof(GpPaint), "GpPaint");
-	}
-
-	Paint *paint = &ts->gp_paint->paint;
+	Paint *paint = BKE_brush_get_gpencil_paint(ts);
 	Main *bmain = CTX_data_main(C);
 
 	Brush *brush, *deft;
diff --git a/source/blender/editors/gpencil/gpencil_data.c b/source/blender/editors/gpencil/gpencil_data.c
index 092279c86c9..3141a840e4b 100644
--- a/source/blender/editors/gpencil/gpencil_data.c
+++ b/source/blender/editors/gpencil/gpencil_data.c
@@ -1449,12 +1449,7 @@ static int gp_brush_select_exec(bContext *C, wmOperator *op)
 
 	const int index = RNA_int_get(op->ptr, "index");
 	
-	/* alloc paint session */
-	if (ts->gp_paint == NULL) {
-		ts->gp_paint = MEM_callocN(sizeof(GpPaint), "GpPaint");
-	}
-
-	Paint *paint = &ts->gp_paint->paint;
+	Paint *paint = BKE_brush_get_gpencil_paint(ts);
 	int i = 0;
 	for (Brush *brush = bmain->brush.first; brush; brush = brush->id.next) {
 		if (brush->ob_mode == OB_MODE_GPENCIL_PAINT) {
diff --git a/source/blender/editors/gpencil/gpencil_edit.c b/source/blender/editors/gpencil/gpencil_edit.c
index 9c76aa94b9c..7d6735d2841 100644
--- a/source/blender/editors/gpencil/gpencil_edit.c
+++ b/source/blender/editors/gpencil/gpencil_edit.c
@@ -224,11 +224,7 @@ static int gpencil_paintmode_toggle_exec(bContext *C, wmOperator *op)
 	}
 
 	/* be sure we have brushes */
-	if (ts->gp_paint == NULL) {
-		ts->gp_paint = MEM_callocN(sizeof(GpPaint), "GpPaint");
-	}
-
-	Paint *paint = &ts->gp_paint->paint;
+	Paint *paint = BKE_brush_get_gpencil_paint(ts);
 	/* if not exist, create a new one */
 	if (paint->brush == NULL) {
 		BKE_brush_gpencil_presets(C);
diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c
index aa6b7f8df53..7975ebe3a9e 100644
--- a/source/blender/editors/gpencil/gpencil_paint.c
+++ b/source/blender/editors/gpencil/gpencil_paint.c
@@ -1475,12 +1475,7 @@ static void gp_session_validatebuffer(tGPsdata *p)
 static Brush *gp_get_default_eraser(Main *bmain, ToolSettings *ts)
 {
 	Brush *brush_dft = NULL;
-	/* alloc paint session */
-	if (ts->gp_paint == NULL) {
-		ts->gp_paint = MEM_callocN(sizeof(GpPaint), "GpPaint");
-	}
-
-	Paint *paint = &ts->gp_paint->paint;
+	Paint *paint = BKE_brush_get_gpencil_paint(ts);
 	Brush *brush_old = paint->brush;
 	for (Brush *brush = bmain->brush.first; brush; brush = brush->id.next) {
 		if ((brush->ob_mode == OB_MODE_GPENCIL_PAINT) && 
@@ -1523,12 +1518,7 @@ static void gp_init_drawing_brush(bContext *C, tGPsdata *p)
 	Brush *brush;
 	ToolSettings *ts = CTX_data_tool_settings(C);
 
-	/* alloc paint session */
-	if (ts->gp_paint == NULL) {
-		ts->gp_paint = MEM_callocN(sizeof(GpPaint), "GpPaint");
-	}
-
-	Paint *paint = &ts->gp_paint->paint;
+	Paint *paint = BKE_brush_get_gpencil_paint(ts);
 	Main *bmain = CTX_data_main(C);
 
 	/* if not exist, create a new one */
diff --git a/source/blender/editors/gpencil/gpencil_primitive.c b/source/blender/editors/gpencil/gpencil_primitive.c
index bcb203f93a4..cf3cee9074f 100644
--- a/source/blender/editors/gpencil/gpencil_primitive.c
+++ b/source/blender/editors/gpencil/gpencil_primitive.c
@@ -126,12 +126,7 @@ static void gp_primitive_set_initdata(bContext *C, tGPDprimitive *tgpi)
 	Brush *brush;
 
 	/* if brush doesn't exist, create a new one */
-	/* alloc paint session */
-	if (ts->gp_paint == NULL) {
-		ts->gp_paint = MEM_callocN(sizeof(GpPaint), "GpPaint");
-	}
-
-	Paint *paint = &ts->gp_paint->paint;
+	Paint *paint = BKE_brush_get_gpencil_paint(ts);
 	/* if not exist, create a new one */
 	if (paint->brush == NULL) {
 		/* create new brushes */
diff --git a/source/blender/editors/gpencil/gpencil_utils.c b/source/blender/editors/gpencil/gpencil_utils.c
index f0c8cde4332..e1ee41a2d48 100644
--- a/source/blender/editors/gpencil/gpencil_utils.c
+++ b/source/blender/editors/gpencil/gpencil_utils.c
@@ -1134,12 +1134,7 @@ void ED_gpencil_add_defaults(bContext *C)
 	/* ensure palettes, colors, and palette slots exist */
 	BKE_gpencil_paletteslot_validate(CTX_data_main(C), gpd);
 
-	/* alloc paint session */
-	if (ts->gp_paint == NULL) {
-		ts->gp_paint = MEM_callocN(sizeof(GpPaint), "GpPaint");
-	}
-
-	Paint *paint = &ts->gp_paint->paint;
+	Paint *paint = BKE_brush_get_gpencil_paint(ts);
 	/* if not exist, create a new one */
 	if (paint->brush == NULL) {
 		/* create new brushes */



More information about the Bf-blender-cvs mailing list