diff --git a/source/blender/editors/sculpt_paint/sculpt.cc b/source/blender/editors/sculpt_paint/sculpt.cc index 63bf3d134e1..17b29aa5caa 100644 --- a/source/blender/editors/sculpt_paint/sculpt.cc +++ b/source/blender/editors/sculpt_paint/sculpt.cc @@ -70,6 +70,7 @@ #include "DEG_depsgraph.hh" #include "WM_api.hh" +#include "WM_toolsystem.hh" #include "WM_types.hh" #include "ED_gpencil_legacy.hh" @@ -4303,6 +4304,51 @@ bool SCULPT_poll(bContext *C) return SCULPT_mode_poll(C) && blender::ed::sculpt_paint::paint_brush_tool_poll(C); } +/** + * While most non-brush tools in sculpt mode do not use the brush cursor, the trim tools + * and the filter tools are expected to have the cursor visible so that some functionality is + * easier to visually estimate. + * + * See: #122856 + */ +static bool is_brush_related_tool(bContext *C) +{ + Paint *paint = BKE_paint_get_active_from_context(C); + Object *ob = CTX_data_active_object(C); + ScrArea *area = CTX_wm_area(C); + ARegion *region = CTX_wm_region(C); + + if (paint && ob && BKE_paint_brush(paint) && + (area && ELEM(area->spacetype, SPACE_VIEW3D, SPACE_IMAGE)) && + (region && region->regiontype == RGN_TYPE_WINDOW)) + { + bToolRef *tref = area->runtime.tool; + if (tref && tref->runtime && tref->runtime->keymap[0]) { + std::array trim_operators = { + WM_operatortype_find("SCULPT_OT_trim_box_gesture", false), + WM_operatortype_find("SCULPT_OT_trim_lasso_gesture", false), + WM_operatortype_find("SCULPT_OT_trim_line_gesture", false), + WM_operatortype_find("SCULPT_OT_trim_polyline_gesture", false), + WM_operatortype_find("SCULPT_OT_mesh_filter", false), + WM_operatortype_find("SCULPT_OT_cloth_filter", false), + WM_operatortype_find("SCULPT_OT_color_filter", false), + }; + + return std::any_of(trim_operators.begin(), trim_operators.end(), [tref](wmOperatorType *ot) { + PointerRNA ptr; + return WM_toolsystem_ref_properties_get_from_operator(tref, ot, &ptr); + }); + } + } + return false; +} + +bool SCULPT_brush_cursor_poll(bContext *C) +{ + using namespace blender::ed::sculpt_paint; + return SCULPT_mode_poll(C) && (paint_brush_tool_poll(C) || is_brush_related_tool(C)); +} + static const char *sculpt_tool_name(const Sculpt &sd) { const Brush &brush = *BKE_paint_brush_for_read(&sd.paint); diff --git a/source/blender/editors/sculpt_paint/sculpt_intern.hh b/source/blender/editors/sculpt_paint/sculpt_intern.hh index bf56f76f66f..cf3cb990d83 100644 --- a/source/blender/editors/sculpt_paint/sculpt_intern.hh +++ b/source/blender/editors/sculpt_paint/sculpt_intern.hh @@ -673,6 +673,11 @@ bool SCULPT_mode_poll_view3d(bContext *C); */ bool SCULPT_poll(bContext *C); +/** + * Determines whether or not the brush cursor should be shown in the viewport + */ +bool SCULPT_brush_cursor_poll(bContext *C); + /** * Returns true if sculpt session can handle color attributes * (BKE_pbvh_type(*ss->pbvh) == PBVH_FACES). If false an error diff --git a/source/blender/editors/sculpt_paint/sculpt_ops.cc b/source/blender/editors/sculpt_paint/sculpt_ops.cc index db0c79d12b2..20f81a51c8f 100644 --- a/source/blender/editors/sculpt_paint/sculpt_ops.cc +++ b/source/blender/editors/sculpt_paint/sculpt_ops.cc @@ -371,7 +371,7 @@ void ED_object_sculptmode_enter_ex(Main &bmain, Paint *paint = BKE_paint_get_active_from_paintmode(&scene, PaintMode::Sculpt); BKE_paint_init(&bmain, &scene, PaintMode::Sculpt, PAINT_CURSOR_SCULPT); - ED_paint_cursor_start(paint, SCULPT_poll); + ED_paint_cursor_start(paint, SCULPT_brush_cursor_poll); /* Check dynamic-topology flag; re-enter dynamic-topology mode when changing modes, * As long as no data was added that is not supported. */