[Bf-blender-cvs] [13c3c9b22fd] blender2.8: Cleanup: move brush query into utility function

Campbell Barton noreply at git.blender.org
Sat Nov 3 06:00:23 CET 2018


Commit: 13c3c9b22fd8453d4418577efbc2ccb93209e92e
Author: Campbell Barton
Date:   Sat Nov 3 15:44:16 2018 +1100
Branches: blender2.8
https://developer.blender.org/rB13c3c9b22fd8453d4418577efbc2ccb93209e92e

Cleanup: move brush query into utility function

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

M	source/blender/blenkernel/BKE_paint.h
M	source/blender/blenkernel/intern/paint.c
M	source/blender/blenkernel/intern/paint_toolslots.c
M	source/blender/makesrna/intern/rna_sculpt_paint.c

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

diff --git a/source/blender/blenkernel/BKE_paint.h b/source/blender/blenkernel/BKE_paint.h
index b8938c87275..c5fc6054812 100644
--- a/source/blender/blenkernel/BKE_paint.h
+++ b/source/blender/blenkernel/BKE_paint.h
@@ -136,6 +136,9 @@ struct Paint *BKE_paint_get_active(struct Scene *sce, struct ViewLayer *view_lay
 struct Paint *BKE_paint_get_active_from_context(const struct bContext *C);
 ePaintMode BKE_paintmode_get_active_from_context(const struct bContext *C);
 struct Brush *BKE_paint_brush(struct Paint *paint);
+bool BKE_paint_brush_tool_info(
+        const struct Scene *scene, const struct Paint *paint,
+        uint *r_tool_offset, eObjectMode *r_ob_mode);
 void BKE_paint_brush_set(struct Paint *paint, struct Brush *br);
 struct Palette *BKE_paint_palette(struct Paint *paint);
 void BKE_paint_palette_set(struct Paint *p, struct Palette *palette);
diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c
index 93b54fcb132..7838fb69f1a 100644
--- a/source/blender/blenkernel/intern/paint.c
+++ b/source/blender/blenkernel/intern/paint.c
@@ -302,6 +302,58 @@ void BKE_paint_brush_set(Paint *p, Brush *br)
 	}
 }
 
+bool BKE_paint_brush_tool_info(
+        const Scene *scene, const struct Paint *paint,
+        uint *r_tool_offset, eObjectMode *r_ob_mode)
+{
+	ToolSettings *ts = scene->toolsettings;
+	if (paint == &ts->imapaint.paint) {
+		if (r_tool_offset != NULL) {
+			*r_tool_offset = offsetof(Brush, imagepaint_tool);
+		}
+		if (r_ob_mode != NULL) {
+			*r_ob_mode = OB_MODE_TEXTURE_PAINT;
+		}
+	}
+	else if (paint == &ts->sculpt->paint) {
+		if (r_tool_offset != NULL) {
+			*r_tool_offset = offsetof(Brush, sculpt_tool);
+		}
+		if (r_ob_mode != NULL) {
+			*r_ob_mode = OB_MODE_SCULPT;
+		}
+	}
+	else if (paint == &ts->vpaint->paint) {
+		if (r_tool_offset != NULL) {
+			*r_tool_offset = offsetof(Brush, vertexpaint_tool);
+		}
+		if (r_ob_mode != NULL) {
+			*r_ob_mode = OB_MODE_VERTEX_PAINT;
+		}
+	}
+	else if (paint == &ts->wpaint->paint) {
+		if (r_tool_offset != NULL) {
+			*r_tool_offset = offsetof(Brush, vertexpaint_tool);
+		}
+		if (r_ob_mode != NULL) {
+			*r_ob_mode = OB_MODE_WEIGHT_PAINT;
+		}
+	}
+	else if (paint == &ts->gp_paint->paint) {
+		if (r_tool_offset != NULL) {
+			*r_tool_offset = offsetof(Brush, gpencil_tool);
+		}
+		if (r_ob_mode != NULL) {
+			*r_ob_mode = OB_MODE_GPENCIL_PAINT;
+		}
+	}
+	else {
+		return false;
+	}
+	return true;
+}
+
+
 /** Free (or release) any data used by this paint curve (does not free the pcurve itself). */
 void BKE_paint_curve_free(PaintCurve *pc)
 {
diff --git a/source/blender/blenkernel/intern/paint_toolslots.c b/source/blender/blenkernel/intern/paint_toolslots.c
index bdafe217276..19c461d1777 100644
--- a/source/blender/blenkernel/intern/paint_toolslots.c
+++ b/source/blender/blenkernel/intern/paint_toolslots.c
@@ -93,23 +93,10 @@ void BKE_paint_toolslots_init_from_main(struct Main *bmain)
 
 void BKE_paint_toolslots_brush_update_ex(Scene *scene, Paint *paint, Brush *brush)
 {
-	ToolSettings *ts = scene->toolsettings;
-	int slot_index;
-	if (paint == &ts->imapaint.paint) {
-		slot_index = brush->imagepaint_tool;
-	}
-	else if (paint == &ts->sculpt->paint) {
-		slot_index = brush->sculpt_tool;
-	}
-	else if (paint == &ts->vpaint->paint) {
-		slot_index = brush->vertexpaint_tool;
-	}
-	else if (paint == &ts->wpaint->paint) {
-		slot_index = brush->vertexpaint_tool;
-	}
-	else if (paint == &ts->gp_paint->paint) {
-		slot_index = brush->gpencil_tool;
-	}
+	uint tool_offset = 0;
+	bool ok = BKE_paint_brush_tool_info(scene, paint, &tool_offset, NULL);
+	BLI_assert(ok);
+	int slot_index = *(char *)POINTER_OFFSET(brush, tool_offset);
 	BKE_paint_toolslots_len_ensure(paint, slot_index + 1);
 	PaintToolSlot *tslot = &paint->tool_slots[slot_index];
 	id_us_plus(&brush->id);
diff --git a/source/blender/makesrna/intern/rna_sculpt_paint.c b/source/blender/makesrna/intern/rna_sculpt_paint.c
index dcddf77b963..86c860ef6a5 100644
--- a/source/blender/makesrna/intern/rna_sculpt_paint.c
+++ b/source/blender/makesrna/intern/rna_sculpt_paint.c
@@ -274,36 +274,17 @@ static bool rna_Brush_mode_poll(PointerRNA *ptr, PointerRNA value)
 {
 	Scene *scene = (Scene *)ptr->id.data;
 	const Paint *paint = ptr->data;
-	ToolSettings *ts = scene->toolsettings;
 	Brush *brush = value.id.data;
-	int mode = 0;
+	eObjectMode ob_mode = 0;
 	uint brush_tool_offset = 0;
 
 	/* check the origin of the Paint struct to see which paint
 	 * mode to select from */
 
-	if (paint == &ts->imapaint.paint) {
-		mode = OB_MODE_TEXTURE_PAINT;
-		brush_tool_offset = offsetof(Brush, imagepaint_tool);
-	}
-	else if (paint == &ts->sculpt->paint) {
-		mode = OB_MODE_SCULPT;
-		brush_tool_offset = offsetof(Brush, sculpt_tool);
-	}
-	else if (paint == &ts->vpaint->paint) {
-		mode = OB_MODE_VERTEX_PAINT;
-		brush_tool_offset = offsetof(Brush, vertexpaint_tool);
-	}
-	else if (paint == &ts->wpaint->paint) {
-		mode = OB_MODE_WEIGHT_PAINT;
-		brush_tool_offset = offsetof(Brush, vertexpaint_tool);
-	}
-	else if (paint == &ts->gp_paint->paint) {
-		mode = OB_MODE_GPENCIL_PAINT;
-		brush_tool_offset = offsetof(Brush, gpencil_tool);
-	}
+	bool ok = BKE_paint_brush_tool_info(scene, paint, &brush_tool_offset, &ob_mode);
+	BLI_assert(ok);
 
-	if (brush->ob_mode & mode) {
+	if (brush->ob_mode & ob_mode) {
 		if (paint->brush) {
 			const char *tool_a = (const char *)POINTER_OFFSET(paint->brush, brush_tool_offset);
 			const char *tool_b = (const char *)POINTER_OFFSET(brush,        brush_tool_offset);



More information about the Bf-blender-cvs mailing list