From a90bcdf93d82bf5d9964b12bb20af696ca66654e Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 6 Nov 2018 12:08:39 +1100 Subject: Tool System: use tool type enum to access brushes Previously the brush names were used which had the limit that: - Brush names that were deleted wouldn't show up in the toolbar. - Naming collisions between user defined brushes and existing tools broke tool selection. Now brushes are created as needed when tools are selected. Note, vertex/weight paint combine tool and blend modes, this should be split out into a separate enum. --- source/blender/makesrna/intern/rna_workspace_api.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'source/blender/makesrna/intern/rna_workspace_api.c') diff --git a/source/blender/makesrna/intern/rna_workspace_api.c b/source/blender/makesrna/intern/rna_workspace_api.c index 83ee5195fd8..4cb74ac1479 100644 --- a/source/blender/makesrna/intern/rna_workspace_api.c +++ b/source/blender/makesrna/intern/rna_workspace_api.c @@ -116,13 +116,20 @@ static void rna_WorkspaceTool_refresh_from_context( } } else { - Paint *paint = BKE_paint_get_active(scene, view_layer); - if (paint) { + const ePaintMode paint_mode = BKE_paintmode_get_from_tool(tref); + Paint *paint = BKE_paint_get_active_from_paintmode(scene, paint_mode); + const EnumPropertyItem *items = BKE_paint_get_tool_enum_from_paintmode(paint_mode); + if (paint && paint->brush && items) { const ID *brush = (ID *)paint->brush; - if (brush) { - if (!STREQ(tref_rt->data_block, brush->name + 2)) { - STRNCPY(tref_rt->data_block, brush->name + 2); - STRNCPY(tref->idname, brush->name + 2); + const char tool_type = *(char *)POINTER_OFFSET(brush, paint->runtime.tool_offset); + const int i = RNA_enum_from_value(items, tool_type); + /* Possible when loading files from the future. */ + if (i != -1) { + const char *name = items[i].name; + const char *identifier = items[i].identifier; + if (!STREQ(tref_rt->data_block, identifier)) { + STRNCPY(tref_rt->data_block, identifier); + STRNCPY(tref->idname, name); } } } -- cgit v1.2.3