From c9285f83abac4c8d0763d1a618647ce48d756382 Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Thu, 16 Feb 2023 13:47:13 +0100 Subject: [PATCH 1/2] Fix #104698: Assert and failure adding shortcuts to curves sculpt tools The keymap name in `WM_keymap_guess_from_context` didn't match the name of the keymap in the Blender default keymap (`km_sculpt_curves`). Fix by changing the utility function to match the keymap name. Before right clicking on any tool in curves sculpt mode gave an assert, now it shows a context menu. Pull Request #104791 --- source/blender/windowmanager/intern/wm_keymap_utils.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/blender/windowmanager/intern/wm_keymap_utils.c b/source/blender/windowmanager/intern/wm_keymap_utils.c index 0817b10f86e..cf8c0ebb859 100644 --- a/source/blender/windowmanager/intern/wm_keymap_utils.c +++ b/source/blender/windowmanager/intern/wm_keymap_utils.c @@ -141,7 +141,7 @@ wmKeyMap *WM_keymap_guess_from_context(const bContext *C) km_id = "Grease Pencil Stroke Vertex Mode"; break; case CTX_MODE_SCULPT_CURVES: - km_id = "Curves Sculpt"; + km_id = "Sculpt Curves"; break; } } From 9d15b3f4248dd965dbd26907f65f783f6845c17c Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Thu, 16 Feb 2023 13:48:39 +0100 Subject: [PATCH 2/2] Fix #104697: Curves Sculpt: Setting brush shortcuts does not work The active tools in `_defs_curves_sculpt` don't use names that are exactly the same as the corresponding brush name with "builtin_brush." at the beginning, instead they use more standard identifiers without capitals or spaces. The "brush_select" utility operator assumed the names matched though. That can be fixed by manually mapping the brushes to the active tools. Pull Request #104792 --- .../blender/editors/sculpt_paint/paint_ops.cc | 50 +++++++++++++++++-- 1 file changed, 46 insertions(+), 4 deletions(-) diff --git a/source/blender/editors/sculpt_paint/paint_ops.cc b/source/blender/editors/sculpt_paint/paint_ops.cc index c8216bda59d..ca102b5a0b8 100644 --- a/source/blender/editors/sculpt_paint/paint_ops.cc +++ b/source/blender/editors/sculpt_paint/paint_ops.cc @@ -832,6 +832,36 @@ static Brush *brush_tool_toggle(Main *bmain, Paint *paint, Brush *brush_orig, co return nullptr; } +/** The name of the active tool is "builtin_brush." concatenated with the returned string. */ +static blender::StringRefNull curves_active_tool_name_get(const eBrushCurvesSculptTool tool) +{ + switch (tool) { + case CURVES_SCULPT_TOOL_COMB: + return "comb"; + case CURVES_SCULPT_TOOL_DELETE: + return "delete"; + case CURVES_SCULPT_TOOL_SNAKE_HOOK: + return "snake_hook"; + case CURVES_SCULPT_TOOL_ADD: + return "add"; + case CURVES_SCULPT_TOOL_GROW_SHRINK: + return "grow_shrink"; + case CURVES_SCULPT_TOOL_SELECTION_PAINT: + return "selection_paint"; + case CURVES_SCULPT_TOOL_PINCH: + return "pinch"; + case CURVES_SCULPT_TOOL_SMOOTH: + return "smooth"; + case CURVES_SCULPT_TOOL_PUFF: + return "puff"; + case CURVES_SCULPT_TOOL_DENSITY: + return "density"; + case CURVES_SCULPT_TOOL_SLIDE: + return "slide"; + } + return ""; +} + static bool brush_generic_tool_set(bContext *C, Main *bmain, Paint *paint, @@ -869,8 +899,14 @@ static bool brush_generic_tool_set(bContext *C, * tool_name again. */ int tool_result = brush_tool(brush, paint->runtime.tool_offset); ePaintMode paint_mode = BKE_paintmode_get_active_from_context(C); - const EnumPropertyItem *items = BKE_paint_get_tool_enum_from_paintmode(paint_mode); - RNA_enum_name_from_value(items, tool_result, &tool_name); + + if (paint_mode == PAINT_MODE_SCULPT_CURVES) { + tool_name = curves_active_tool_name_get(eBrushCurvesSculptTool(tool)).c_str(); + } + else { + const EnumPropertyItem *items = BKE_paint_get_tool_enum_from_paintmode(paint_mode); + RNA_enum_name_from_value(items, tool_result, &tool_name); + } char tool_id[MAX_NAME]; SNPRINTF(tool_id, "builtin_brush.%s", tool_name); @@ -921,8 +957,14 @@ static int brush_select_exec(bContext *C, wmOperator *op) if (paint == nullptr) { return OPERATOR_CANCELLED; } - const EnumPropertyItem *items = BKE_paint_get_tool_enum_from_paintmode(paint_mode); - RNA_enum_name_from_value(items, tool, &tool_name); + + if (paint_mode == PAINT_MODE_SCULPT_CURVES) { + tool_name = curves_active_tool_name_get(eBrushCurvesSculptTool(tool)).c_str(); + } + else { + const EnumPropertyItem *items = BKE_paint_get_tool_enum_from_paintmode(paint_mode); + RNA_enum_name_from_value(items, tool, &tool_name); + } if (brush_generic_tool_set(C, bmain, paint, tool, tool_name, create_missing, toggle)) { return OPERATOR_FINISHED;