[Bf-blender-cvs] [c279f879ab8] blender2.8: Paint: remove brush select paint_mode

Campbell Barton noreply at git.blender.org
Wed Nov 14 01:55:15 CET 2018


Commit: c279f879ab86e03dff0dbfd3a36b14bebb4956f9
Author: Campbell Barton
Date:   Wed Nov 14 11:52:17 2018 +1100
Branches: blender2.8
https://developer.blender.org/rBc279f879ab86e03dff0dbfd3a36b14bebb4956f9

Paint: remove brush select paint_mode

Instead check which property has been set.

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

M	release/scripts/presets/keyconfig/keymap_data/blender_default.py
M	source/blender/editors/interface/interface_region_tooltip.c
M	source/blender/editors/sculpt_paint/paint_ops.c

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

diff --git a/release/scripts/presets/keyconfig/keymap_data/blender_default.py b/release/scripts/presets/keyconfig/keymap_data/blender_default.py
index ed22fb2ecb7..e501f4e91ab 100644
--- a/release/scripts/presets/keyconfig/keymap_data/blender_default.py
+++ b/release/scripts/presets/keyconfig/keymap_data/blender_default.py
@@ -3597,27 +3597,27 @@ def km_sculpt(_params):
          {"properties": [("mode", 'ROTATION'), ("texmode", 'SECONDARY')]}),
         # Tools
         ("paint.brush_select", {"type": 'X', "value": 'PRESS'},
-         {"properties": [("paint_mode", 'SCULPT'), ("sculpt_tool", 'DRAW')]}),
+         {"properties": [("sculpt_tool", 'DRAW')]}),
         ("paint.brush_select", {"type": 'S', "value": 'PRESS'},
-         {"properties": [("paint_mode", 'SCULPT'), ("sculpt_tool", 'SMOOTH')]}),
+         {"properties": [("sculpt_tool", 'SMOOTH')]}),
         ("paint.brush_select", {"type": 'P', "value": 'PRESS'},
-         {"properties": [("paint_mode", 'SCULPT'), ("sculpt_tool", 'PINCH')]}),
+         {"properties": [("sculpt_tool", 'PINCH')]}),
         ("paint.brush_select", {"type": 'I', "value": 'PRESS'},
-         {"properties": [("paint_mode", 'SCULPT'), ("sculpt_tool", 'INFLATE')]}),
+         {"properties": [("sculpt_tool", 'INFLATE')]}),
         ("paint.brush_select", {"type": 'G', "value": 'PRESS'},
-         {"properties": [("paint_mode", 'SCULPT'), ("sculpt_tool", 'GRAB')]}),
+         {"properties": [("sculpt_tool", 'GRAB')]}),
         ("paint.brush_select", {"type": 'L', "value": 'PRESS'},
-         {"properties": [("paint_mode", 'SCULPT'), ("sculpt_tool", 'LAYER')]}),
+         {"properties": [("sculpt_tool", 'LAYER')]}),
         ("paint.brush_select", {"type": 'T', "value": 'PRESS', "shift": True},
-         {"properties": [("paint_mode", 'SCULPT'), ("sculpt_tool", 'FLATTEN')]}),
+         {"properties": [("sculpt_tool", 'FLATTEN')]}),
         ("paint.brush_select", {"type": 'C', "value": 'PRESS'},
-         {"properties": [("paint_mode", 'SCULPT'), ("sculpt_tool", 'CLAY')]}),
+         {"properties": [("sculpt_tool", 'CLAY')]}),
         ("paint.brush_select", {"type": 'C', "value": 'PRESS', "shift": True},
-         {"properties": [("paint_mode", 'SCULPT'), ("sculpt_tool", 'CREASE')]}),
+         {"properties": [("sculpt_tool", 'CREASE')]}),
         ("paint.brush_select", {"type": 'K', "value": 'PRESS'},
-         {"properties": [("paint_mode", 'SCULPT'), ("sculpt_tool", 'SNAKE_HOOK')]}),
+         {"properties": [("sculpt_tool", 'SNAKE_HOOK')]}),
         ("paint.brush_select", {"type": 'M', "value": 'PRESS'},
-         {"properties": [("paint_mode", 'SCULPT'), ("sculpt_tool", 'MASK'), ("toggle", True), ("create_missing", True)]}),
+         {"properties": [("sculpt_tool", 'MASK'), ("toggle", True), ("create_missing", True)]}),
         # Menus
         ("wm.context_menu_enum", {"type": 'E', "value": 'PRESS'},
          {"properties": [("data_path", 'tool_settings.sculpt.brush.stroke_method')]}),
diff --git a/source/blender/editors/interface/interface_region_tooltip.c b/source/blender/editors/interface/interface_region_tooltip.c
index 8d7d67fb69f..6bdcdf57f47 100644
--- a/source/blender/editors/interface/interface_region_tooltip.c
+++ b/source/blender/editors/interface/interface_region_tooltip.c
@@ -476,7 +476,6 @@ static uiTooltipData *ui_tooltip_data_from_tool(bContext *C, uiBut *but, bool is
 					wmOperatorType *ot = WM_operatortype_find("paint.brush_select", true);
 					PointerRNA op_props;
 					WM_operator_properties_create_ptr(&op_props, ot);
-					RNA_enum_set(&op_props, "paint_mode", paint_mode);
 					RNA_enum_set(&op_props, tool_attr, items[i].value);
 
 					/* Check for direct access to the tool. */
diff --git a/source/blender/editors/sculpt_paint/paint_ops.c b/source/blender/editors/sculpt_paint/paint_ops.c
index a48541c990f..85dc37b9838 100644
--- a/source/blender/editors/sculpt_paint/paint_ops.c
+++ b/source/blender/editors/sculpt_paint/paint_ops.c
@@ -449,31 +449,40 @@ static int brush_generic_tool_set(
 	}
 }
 
+static const ePaintMode brush_select_paint_modes[] = {
+	PAINT_MODE_SCULPT,
+	PAINT_MODE_VERTEX,
+	PAINT_MODE_WEIGHT,
+	PAINT_MODE_TEXTURE_3D,
+	PAINT_MODE_GPENCIL,
+};
+
 static int brush_select_exec(bContext *C, wmOperator *op)
 {
 	Main *bmain = CTX_data_main(C);
 	Scene *scene = CTX_data_scene(C);
-	ePaintMode paint_mode = RNA_enum_get(op->ptr, "paint_mode");
 	const bool create_missing = RNA_boolean_get(op->ptr, "create_missing");
 	const bool toggle = RNA_boolean_get(op->ptr, "toggle");
 	const char *tool_name = "Brush";
-
-	if (paint_mode == PAINT_MODE_INVALID) {
-		paint_mode = BKE_paintmode_get_active_from_context(C);
-		if (paint_mode == PAINT_MODE_INVALID) {
-			return OPERATOR_CANCELLED;
+	int tool = 0;
+
+	ePaintMode paint_mode = PAINT_MODE_INVALID;
+	for (int i = 0; i < ARRAY_SIZE(brush_select_paint_modes); i++) {
+		paint_mode = brush_select_paint_modes[i];
+		const char *op_prop_id = BKE_paint_get_tool_prop_id_from_paintmode(paint_mode);
+		PropertyRNA *prop = RNA_struct_find_property(op->ptr, op_prop_id);
+		if (RNA_property_is_set(op->ptr, prop)) {
+			tool = RNA_property_enum_get(op->ptr, prop);
+			break;
 		}
 	}
 
-	Paint *paint = BKE_paint_get_active_from_paintmode(scene, paint_mode);
-	const EnumPropertyItem *items = BKE_paint_get_tool_enum_from_paintmode(paint_mode);
-	const char *op_prop_id = BKE_paint_get_tool_prop_id_from_paintmode(paint_mode);
-
-	if (op_prop_id == NULL) {
+	if (paint_mode == PAINT_MODE_INVALID) {
 		return OPERATOR_CANCELLED;
 	}
 
-	const int tool = RNA_enum_get(op->ptr, op_prop_id);
+	Paint *paint = BKE_paint_get_active_from_paintmode(scene, paint_mode);
+	const EnumPropertyItem *items = BKE_paint_get_tool_enum_from_paintmode(paint_mode);
 	RNA_enum_name_from_value(items, tool, &tool_name);
 	return brush_generic_tool_set(
 	        bmain, paint, tool,
@@ -483,16 +492,6 @@ static int brush_select_exec(bContext *C, wmOperator *op)
 
 static void PAINT_OT_brush_select(wmOperatorType *ot)
 {
-	/* Keep names matching 'rna_enum_object_mode_items' (besides active). */
-	static const EnumPropertyItem paint_mode_items[] = {
-		{PAINT_MODE_INVALID, "ACTIVE", 0, "Current", "Set brush for active paint mode"},
-		{PAINT_MODE_SCULPT, "SCULPT", ICON_SCULPTMODE_HLT, "Sculpt", ""},
-		{PAINT_MODE_VERTEX, "VERTEX_PAINT", ICON_VPAINT_HLT, "Vertex Paint", ""},
-		{PAINT_MODE_WEIGHT, "WEIGHT_PAINT", ICON_WPAINT_HLT, "Weight Paint", ""},
-		{PAINT_MODE_TEXTURE_3D, "TEXTURE_PAINT", ICON_TPAINT_HLT, "Texture Paint", ""},
-		{PAINT_MODE_GPENCIL, "GPENCIL_PAINT", ICON_GREASEPENCIL, "Grease Pencil Paint", ""},
-		{0, NULL, 0, NULL, NULL}
-	};
 	PropertyRNA *prop;
 
 	/* identifiers */
@@ -508,11 +507,8 @@ static void PAINT_OT_brush_select(wmOperatorType *ot)
 
 	/* props */
 	/* All properties are hidden, so as not to show the redo panel. */
-	prop = RNA_def_enum(ot->srna, "paint_mode", paint_mode_items, PAINT_MODE_INVALID, "Paint Mode", "");
-	RNA_def_property_flag(prop, PROP_HIDDEN);
-
-	for (const EnumPropertyItem *item = paint_mode_items + 1; item->identifier; item++) {
-		const ePaintMode paint_mode = item->value;
+	for (int i = 0; i < ARRAY_SIZE(brush_select_paint_modes); i++) {
+		const ePaintMode paint_mode = brush_select_paint_modes[i];
 		const char *prop_id = BKE_paint_get_tool_prop_id_from_paintmode(paint_mode);
 		prop = RNA_def_enum(ot->srna, prop_id, BKE_paint_get_tool_enum_from_paintmode(paint_mode), 0, prop_id, "");
 		RNA_def_property_flag(prop, PROP_HIDDEN);



More information about the Bf-blender-cvs mailing list