diff options
author | Campbell Barton <ideasman42@gmail.com> | 2018-11-14 03:52:17 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2018-11-14 03:55:02 +0300 |
commit | c279f879ab86e03dff0dbfd3a36b14bebb4956f9 (patch) | |
tree | 18d4dda46a3275267c8c17a2018c1c007c6ad26d /source/blender/editors/sculpt_paint/paint_ops.c | |
parent | 2b3b481c3d6553e7a4dd90efc25518fe8e1a5bc6 (diff) |
Paint: remove brush select paint_mode
Instead check which property has been set.
Diffstat (limited to 'source/blender/editors/sculpt_paint/paint_ops.c')
-rw-r--r-- | source/blender/editors/sculpt_paint/paint_ops.c | 50 |
1 files changed, 23 insertions, 27 deletions
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); |