Brush Assets: Switch to a single "Brush" active tool #117491

Merged
Hans Goudey merged 11 commits from HooglyBoogly/blender:brush-assets-single-tool into brush-assets-project 2024-01-26 21:08:24 +01:00
5 changed files with 57 additions and 86 deletions
Showing only changes of commit bb4b56df4d - Show all commits

View File

@ -1383,17 +1383,24 @@ class _defs_particle:
class _defs_sculpt:
@staticmethod
def generate_from_brushes(context):
return generate_from_enum_ex(
context,
idname_prefix="builtin_brush.",
icon_prefix="brush.sculpt.",
type=bpy.types.Brush,
attr="sculpt_tool",
# TODO(@ideasman42): we may want to enable this,
# it causes awkward grouping with 2x column button layout.
use_separators=False,
)
def generate_brush_tool(context):
if not context:
return ()
brush = context.tool_settings.sculpt.brush
if not brush:
return ()
tool = brush.sculpt_tool
icon = "ops.sculpt_" + tool.lower()
return [
ToolDef.from_dict(
dict(
idname="builtin.brush",
label=brush.name,
icon=icon,
data_block=tool
)
)
]
@ToolDef.from_fn
def hide_border():
@ -2429,18 +2436,29 @@ class _defs_gpencil_weight:
class _defs_curves_sculpt:
@staticmethod
def generate_from_brushes(context):
return generate_from_enum_ex(
context,
idname_prefix="builtin_brush.",
icon_prefix="ops.curves.sculpt_",
type=bpy.types.Brush,
attr="curves_sculpt_tool",
icon_map={
# Use the generic icon for selection painting.
"ops.curves.sculpt_selection_paint": "ops.generic.select_paint",
},
)
def generate_brush_tool(context):
if not context:
return ()
brush = context.tool_settings.curves_sculpt.brush
if not brush:
return ()
tool = brush.curves_sculpt_tool
icon = "ops.curves.sculpt_" + tool.lower()
icon_map = {
# Use the generic icon for selection painting.
"ops.curves.sculpt_selection_paint": "ops.generic.select_paint",
}
icon = icon_map.get(icon, icon)
return [
ToolDef.from_dict(
dict(
idname="builtin.brush",
label=brush.name,
icon=icon,
data_block=tool
)
)
]
class _defs_gpencil_vertex:
@ -3076,7 +3094,9 @@ class VIEW3D_PT_tools_active(ToolSelectPanelHelper, Panel):
_defs_particle.generate_from_brushes,
],
'SCULPT': [
_defs_sculpt.generate_from_brushes,
lambda context: (
_defs_curves_sculpt.generate_brush_tool(context)
),
None,
(
_defs_sculpt.mask_border,
@ -3221,7 +3241,9 @@ class VIEW3D_PT_tools_active(ToolSelectPanelHelper, Panel):
),
],
'SCULPT_CURVES': [
_defs_curves_sculpt.generate_from_brushes,
lambda context: (
_defs_curves_sculpt.generate_brush_tool(context)
),
None,
*_tools_annotate,
],

View File

@ -496,8 +496,13 @@ class _draw_tool_settings_context_mode:
@staticmethod
def SCULPT_CURVES(context, layout, tool):
if (tool is None) or (not tool.has_datablock):
return False
# if tool is None:
# print("tool is None")
# return False
# if not tool.has_datablock:
# print("not tool.has_datablock")
# return False
tool_settings = context.tool_settings
paint = tool_settings.curves_sculpt

View File

@ -1188,6 +1188,7 @@ static int brush_asset_select_exec(bContext *C, wmOperator *op)
}
WM_main_add_notifier(NC_SCENE | ND_TOOLSETTINGS, nullptr);
WM_toolsystem_ref_set_by_id(C, "builtin.brush");
return OPERATOR_FINISHED;
}

View File

@ -850,36 +850,6 @@ 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,
@ -911,26 +881,7 @@ static bool brush_generic_tool_set(bContext *C,
BKE_paint_invalidate_overlay_all();
WM_main_add_notifier(NC_BRUSH | NA_EDITED, brush);
/* Tool System
* This is needed for when there is a non-sculpt tool active (transform for e.g.).
* In case we are toggling (and the brush changed to the toggle_brush), we need to get the
* tool_name again. */
int tool_result = brush_tool(brush, paint->runtime.tool_offset);
ePaintMode paint_mode = BKE_paintmode_get_active_from_context(C);
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);
WM_toolsystem_ref_set_by_id(C, tool_id);
WM_toolsystem_ref_set_by_id(C, "builtin.brush");
return true;
}
return false;
@ -977,14 +928,6 @@ static int brush_select_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
}
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;
}

View File

@ -726,7 +726,7 @@ static const char *toolsystem_default_tool(const bToolKey *tkey)
case CTX_MODE_VERTEX_GPENCIL_LEGACY:
return "builtin_brush.Draw";
case CTX_MODE_SCULPT_CURVES:
return "builtin_brush.Density";
return "builtin.brush";
/* end temporary hack. */
case CTX_MODE_PARTICLE: