From 17bd906de3ba02c8d7bf848b1f61465f09fc631c Mon Sep 17 00:00:00 2001 From: Nicholas Bishop Date: Tue, 14 Dec 2010 01:19:51 +0000 Subject: [PATCH] Fixed bug #23826, Other kind of brushes appear in sculpt mode Was another problem caused by each brush being allowed in more than one paint mode. Added a new field to the brush struct to indicate what mode the icon was last set for; if it's changed then reset it. Not sure if it's really worth it to cache this, could remove it for simplicity. --- .../editors/interface/interface_icons.c | 40 +++++++++++++------ source/blender/makesdna/DNA_brush_types.h | 3 ++ 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/source/blender/editors/interface/interface_icons.c b/source/blender/editors/interface/interface_icons.c index cf1a90137af..566400e98d6 100644 --- a/source/blender/editors/interface/interface_icons.c +++ b/source/blender/editors/interface/interface_icons.c @@ -1026,30 +1026,46 @@ static int ui_id_brush_get_icon(bContext *C, ID *id, int preview) BKE_icon_getid(id); ui_id_icon_render(C, id, preview); } - else if(!id->icon_id) { - /* no icon found, reset it */ - - /* this is not nice, should probably make - brushes be strictly in one paint mode only - to avoid this kind of thing */ + else { Object *ob = CTX_data_active_object(C); EnumPropertyItem *items; - int tool; - - if(ob && (ob->mode & OB_MODE_SCULPT)) { + int tool, mode = 0; + + /* this is not nice, should probably make brushes be + strictly in one paint mode only to avoid checking + object mode here */ + + if(ob) { + if(ob->mode & OB_MODE_SCULPT) + mode = OB_MODE_SCULPT; + else if(ob->mode & (OB_MODE_VERTEX_PAINT|OB_MODE_WEIGHT_PAINT)) + mode = OB_MODE_VERTEX_PAINT; + else if(ob->mode & OB_MODE_TEXTURE_PAINT) + mode = OB_MODE_TEXTURE_PAINT; + } + + /* check if cached icon is OK */ + if(!mode || (id->icon_id && mode == br->icon_mode)) + return id->icon_id; + + br->icon_mode = mode; + + /* reset the icon */ + if(mode == OB_MODE_SCULPT) { items = brush_sculpt_tool_items; tool = br->sculpt_tool; } - else if(ob && (ob->mode & (OB_MODE_VERTEX_PAINT|OB_MODE_WEIGHT_PAINT))) { + else if(mode == OB_MODE_VERTEX_PAINT) { items = brush_vertexpaint_tool_items; tool = br->vertexpaint_tool; } - else { + else if(mode == OB_MODE_TEXTURE_PAINT) { items = brush_imagepaint_tool_items; tool = br->imagepaint_tool; } - RNA_enum_icon_from_value(items, tool, &id->icon_id); + if(!RNA_enum_icon_from_value(items, tool, &id->icon_id)) + id->icon_id = 0; } return id->icon_id; diff --git a/source/blender/makesdna/DNA_brush_types.h b/source/blender/makesdna/DNA_brush_types.h index 1492319fe22..8fca829101b 100644 --- a/source/blender/makesdna/DNA_brush_types.h +++ b/source/blender/makesdna/DNA_brush_types.h @@ -57,6 +57,9 @@ typedef struct Brush { struct ImBuf *icon_imbuf; PreviewImage *preview; char icon_filepath[240]; + int icon_mode; /* store paint mode for which brush's icon was last generated */ + int pad; + float normal_weight;