[Bf-blender-cvs] [c19dafd2a62] blender2.8: Paint: paint.brush_select now supports gpencil

Campbell Barton noreply at git.blender.org
Wed Nov 7 01:43:40 CET 2018


Commit: c19dafd2a62fe0bebe6f834017b108e77d133682
Author: Campbell Barton
Date:   Wed Nov 7 11:38:10 2018 +1100
Branches: blender2.8
https://developer.blender.org/rBc19dafd2a62fe0bebe6f834017b108e77d133682

Paint: paint.brush_select now supports gpencil

Replace grease pencil specific brush select operator.

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

M	release/scripts/startup/bl_ui/space_toolsystem_common.py
M	source/blender/blenkernel/BKE_paint.h
M	source/blender/blenkernel/intern/paint.c
M	source/blender/editors/gpencil/gpencil_data.c
M	source/blender/editors/gpencil/gpencil_intern.h
M	source/blender/editors/gpencil/gpencil_ops.c
M	source/blender/editors/interface/interface_region_tooltip.c
M	source/blender/editors/sculpt_paint/paint_ops.c
M	source/blender/makesrna/intern/rna_brush.c

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

diff --git a/release/scripts/startup/bl_ui/space_toolsystem_common.py b/release/scripts/startup/bl_ui/space_toolsystem_common.py
index f23b76c5911..6ddfcd97940 100644
--- a/release/scripts/startup/bl_ui/space_toolsystem_common.py
+++ b/release/scripts/startup/bl_ui/space_toolsystem_common.py
@@ -812,11 +812,13 @@ def keymap_from_context(context, space_type):
                     if item.data_block:
                         # PAINT_OT_brush_select
                         mode = context.active_object.mode
+                        # See: BKE_paint_get_tool_prop_id_from_paintmode
                         attr = {
                             'SCULPT': "sculpt_tool",
-                            'WEIGHT_PAINT': "weight_paint_tool",
-                            'VERTEX_PAINT': "vertex_paint_tool",
-                            'TEXTURE_PAINT': "texture_paint_tool",
+                            'VERTEX_PAINT': "vertex_tool",
+                            'WEIGHT_PAINT': "weight_tool",
+                            'TEXTURE_PAINT': "image_tool",
+                            'GPENCIL_PAINT': "gpencil_tool",
                         }.get(mode, (None, None))
                         if attr is not None:
                             kmi_hack_brush_select_properties.paint_mode = mode
@@ -826,10 +828,6 @@ def keymap_from_context(context, space_type):
                                 context='INVOKE_REGION_WIN',
                                 properties=kmi_hack_brush_select_properties,
                             )[1]
-                        elif mode == 'GPENCIL_PAINT':
-                            # TODO: gpencil.brush_select
-                            # By default no keys are mapped to this, pass.
-                            pass
                         else:
                             print("Unsupported mode:", mode)
                         del mode, attr
diff --git a/source/blender/blenkernel/BKE_paint.h b/source/blender/blenkernel/BKE_paint.h
index 3ebe041dd36..b4b667ecb6b 100644
--- a/source/blender/blenkernel/BKE_paint.h
+++ b/source/blender/blenkernel/BKE_paint.h
@@ -140,6 +140,7 @@ void BKE_paint_cavity_curve_preset(struct Paint *p, int preset);
 eObjectMode BKE_paint_object_mode_from_paintmode(ePaintMode mode);
 struct Paint *BKE_paint_get_active_from_paintmode(struct Scene *sce, ePaintMode mode);
 const struct EnumPropertyItem *BKE_paint_get_tool_enum_from_paintmode(ePaintMode mode);
+const char *BKE_paint_get_tool_prop_id_from_paintmode(ePaintMode mode);
 uint BKE_paint_get_brush_tool_offset_from_paintmode(const ePaintMode mode);
 struct Paint *BKE_paint_get_active(struct Scene *sce, struct ViewLayer *view_layer);
 struct Paint *BKE_paint_get_active_from_context(const struct bContext *C);
diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c
index 86af8604e70..db7cd513bf4 100644
--- a/source/blender/blenkernel/intern/paint.c
+++ b/source/blender/blenkernel/intern/paint.c
@@ -196,6 +196,21 @@ const EnumPropertyItem *BKE_paint_get_tool_enum_from_paintmode(ePaintMode mode)
 	return NULL;
 }
 
+const char *BKE_paint_get_tool_prop_id_from_paintmode(ePaintMode mode)
+{
+	switch (mode) {
+		case ePaintSculpt: return "sculpt_tool";
+		case ePaintVertex: return "vertex_tool";
+		case ePaintWeight: return "weight_tool";
+		case ePaintTexture2D:
+		case ePaintTextureProjective: return "image_tool";
+		case ePaintGpencil: return "gpencil_tool";
+		default:
+			/* invalid paint mode */
+			return NULL;
+	}
+}
+
 Paint *BKE_paint_get_active(Scene *sce, ViewLayer *view_layer)
 {
 	if (sce && view_layer) {
diff --git a/source/blender/editors/gpencil/gpencil_data.c b/source/blender/editors/gpencil/gpencil_data.c
index 8c7068c0a7c..458e9d0eb41 100644
--- a/source/blender/editors/gpencil/gpencil_data.c
+++ b/source/blender/editors/gpencil/gpencil_data.c
@@ -1546,57 +1546,6 @@ void GPENCIL_OT_brush_presets_create(wmOperatorType *ot)
 
 }
 
-/* ***************** Select Brush ************************ */
-
-static int gp_brush_select_exec(bContext *C, wmOperator *op)
-{
-	ToolSettings *ts = CTX_data_tool_settings(C);
-	Main *bmain = CTX_data_main(C);
-
-	/* if there's no existing container */
-	if (ts == NULL) {
-		BKE_report(op->reports, RPT_ERROR, "Nowhere to go");
-		return OPERATOR_CANCELLED;
-	}
-
-	const int index = RNA_int_get(op->ptr, "index");
-
-	Paint *paint = &ts->gp_paint->paint;
-	int i = 0;
-	for (Brush *brush = bmain->brush.first; brush; brush = brush->id.next) {
-		if (brush->ob_mode == OB_MODE_GPENCIL_PAINT) {
-			if (i == index) {
-				BKE_paint_brush_set(paint, brush);
-
-				/* notifiers */
-				WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL);
-				return OPERATOR_FINISHED;
-			}
-			i++;
-		}
-	}
-
-	return OPERATOR_CANCELLED;
-}
-
-void GPENCIL_OT_brush_select(wmOperatorType *ot)
-{
-	/* identifiers */
-	ot->name = "Select Brush";
-	ot->idname = "GPENCIL_OT_brush_select";
-	ot->description = "Select a Grease Pencil drawing brush";
-
-	/* callbacks */
-	ot->exec = gp_brush_select_exec;
-	ot->poll = gp_active_brush_poll;
-
-	/* flags */
-	ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
-
-	/* properties */
-	RNA_def_int(ot->srna, "index", 0, 0, INT_MAX, "Index", "Index of Drawing Brush", 0, INT_MAX);
-}
-
 /* ***************** Select Sculpt Brush ************************ */
 
 static int gp_sculpt_select_exec(bContext *C, wmOperator *op)
diff --git a/source/blender/editors/gpencil/gpencil_intern.h b/source/blender/editors/gpencil/gpencil_intern.h
index f7117189c32..bed4811d7bb 100644
--- a/source/blender/editors/gpencil/gpencil_intern.h
+++ b/source/blender/editors/gpencil/gpencil_intern.h
@@ -386,7 +386,6 @@ void GPENCIL_OT_stroke_separate(struct wmOperatorType *ot);
 void GPENCIL_OT_stroke_split(struct wmOperatorType *ot);
 
 void GPENCIL_OT_brush_presets_create(struct wmOperatorType *ot);
-void GPENCIL_OT_brush_select(struct wmOperatorType *ot);
 
 void GPENCIL_OT_sculpt_select(struct wmOperatorType *ot);
 
diff --git a/source/blender/editors/gpencil/gpencil_ops.c b/source/blender/editors/gpencil/gpencil_ops.c
index d9a233b78d8..968233866f6 100644
--- a/source/blender/editors/gpencil/gpencil_ops.c
+++ b/source/blender/editors/gpencil/gpencil_ops.c
@@ -763,7 +763,6 @@ void ED_operatortypes_gpencil(void)
 	WM_operatortype_append(GPENCIL_OT_stroke_split);
 
 	WM_operatortype_append(GPENCIL_OT_brush_presets_create);
-	WM_operatortype_append(GPENCIL_OT_brush_select);
 
 	WM_operatortype_append(GPENCIL_OT_sculpt_select);
 
diff --git a/source/blender/editors/interface/interface_region_tooltip.c b/source/blender/editors/interface/interface_region_tooltip.c
index 6d3ba95fda5..e8a73eaf56d 100644
--- a/source/blender/editors/interface/interface_region_tooltip.c
+++ b/source/blender/editors/interface/interface_region_tooltip.c
@@ -459,27 +459,7 @@ static uiTooltipData *ui_tooltip_data_from_tool(bContext *C, uiBut *but, bool is
 
 		if (shortcut == NULL) {
 			ePaintMode paint_mode = BKE_paintmode_get_active_from_context(C);
-			const char *tool_attr = NULL;
-
-			switch (paint_mode) {
-				case ePaintSculpt:
-					tool_attr = "sculpt_tool";
-					break;
-				case ePaintVertex:
-					tool_attr = "vertex_paint_tool";
-					break;
-				case ePaintWeight:
-					tool_attr = "weight_paint_tool";
-					break;
-				case ePaintTexture2D:
-				case ePaintTextureProjective:
-					tool_attr = "texture_paint_tool";
-					paint_mode = ePaintTextureProjective;
-					break;
-				default:
-					break;
-			}
-
+			const char *tool_attr = BKE_paint_get_tool_prop_id_from_paintmode(paint_mode);
 			if (tool_attr != NULL) {
 				const EnumPropertyItem *items = BKE_paint_get_tool_enum_from_paintmode(paint_mode);
 				const int i = RNA_enum_from_name(items, tool_name);
diff --git a/source/blender/editors/sculpt_paint/paint_ops.c b/source/blender/editors/sculpt_paint/paint_ops.c
index be59d8e2c71..9bad1324aa6 100644
--- a/source/blender/editors/sculpt_paint/paint_ops.c
+++ b/source/blender/editors/sculpt_paint/paint_ops.c
@@ -466,18 +466,10 @@ static int brush_select_exec(bContext *C, wmOperator *op)
 
 	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 = NULL;
-
-	switch (paint_mode) {
-		case ePaintSculpt: op_prop_id = "sculpt_tool"; break;
-		case ePaintVertex: op_prop_id = "vertex_paint_tool"; break;
-		case ePaintWeight: op_prop_id = "weight_paint_tool"; break;
-		case ePaintTexture2D:
-		case ePaintTextureProjective: op_prop_id = "texture_paint_tool"; break;
-		default:
-			/* invalid paint mode */
-			BLI_assert(0);
-			return OPERATOR_CANCELLED;
+	const char *op_prop_id = BKE_paint_get_tool_prop_id_from_paintmode(paint_mode);
+
+	if (op_prop_id == NULL) {
+		return OPERATOR_CANCELLED;
 	}
 
 	const int tool = RNA_enum_get(op->ptr, op_prop_id);
@@ -490,12 +482,14 @@ 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[] = {
 		{ePaintInvalid, "ACTIVE", 0, "Current", "Set brush for active paint mode"},
 		{ePaintSculpt, "SCULPT", ICON_SCULPTMODE_HLT, "Sculpt", ""},
 		{ePaintVertex, "VERTEX_PAINT", ICON_VPAINT_HLT, "Vertex Paint", ""},
 		{ePaintWeight, "WEIGHT_PAINT", ICON_WPAINT_HLT, "Weight Paint", ""},
 		{ePaintTextureProjective, "TEXTURE_PAINT", ICON_TPAINT_HLT, "Texture Paint", ""},
+		{ePaintGpencil, "GPENCIL_PAINT", ICON_GREASEPENCIL, "Grease Pencil Paint", ""},
 		{0, NULL, 0, NULL, NULL}
 	};
 	PropertyRNA *prop;
@@ -515,14 +509,13 @@ static void PAINT_OT_brush_select(wmOperatorType *ot)
 	/* All properties are hidden, so as not to show the redo panel. */
 	prop = RNA_def_enum(ot->srna, "paint_mode", paint_mode_items, ePaintInvalid, "Paint Mode", "");
 	RNA_def_property_flag(prop, PROP_HIDDEN);
-	prop = RNA_def_enum(ot->srna, "sculpt_tool", rna_enum_brush_sculpt_tool_items, 0, "Sculpt Tool", "");
-	RNA_def_property_flag(prop, PROP_HIDDEN);
-	prop = RNA_def_enum(ot->srna, "vertex_paint_tool", rna_enum_brush_vertex_tool_items, 0, "Vertex Paint Tool", "");
-	RNA_def_property_flag(prop, PR

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list