Fix #122856: Sculpt trim and filter tools do not show brush cursor
This commit adds a new poll function specifically for determining if the sculpt cursor should be drawn. This function whitelists a hardcoded set of non-brush operators to display the cursor for. In testing, this extra check has negligable performance impact. On average it takes 0.012ms per execution. Pull Request: https://projects.blender.org/blender/blender/pulls/123570
This commit is contained in:
@@ -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<wmOperatorType *, 7> 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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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. */
|
||||
|
||||
Reference in New Issue
Block a user