From c94eefd52b4174be3b98b3e921546a7a8486d691 Mon Sep 17 00:00:00 2001 From: Nicholas Bishop Date: Sun, 16 Jan 2011 18:33:08 +0000 Subject: [PATCH] Fixed bug [#25649] Image editor paint icon missing until enter weight paint A couple underlying issues: * Paint icon was looking only at the object mode to determine what the "current" mode is, but that gave problems when the object mode was anything other than texpaint, but 2D image paint was turned on. Fix was to also look at what space is being drawn, and only if it's in the 3D view does it look at the ob mode. * The brushes lists weren't getting filtered correctly in the same case where 2D image paint was on but a different object mode is enabled. Fixed by changing the brush rna poll to look at the paint source, rather than the object mode. --- .../editors/interface/interface_icons.c | 24 ++++++++-------- source/blender/makesdna/DNA_brush_types.h | 3 -- .../makesrna/intern/rna_sculpt_paint.c | 28 +++++++++++-------- 3 files changed, 28 insertions(+), 27 deletions(-) diff --git a/source/blender/editors/interface/interface_icons.c b/source/blender/editors/interface/interface_icons.c index ff041c18b00..bb6738cb8cd 100644 --- a/source/blender/editors/interface/interface_icons.c +++ b/source/blender/editors/interface/interface_icons.c @@ -48,6 +48,7 @@ #include "DNA_brush_types.h" #include "DNA_object_types.h" #include "DNA_screen_types.h" +#include "DNA_space_types.h" #include "RNA_access.h" #include "RNA_enum_types.h" @@ -1028,14 +1029,15 @@ static int ui_id_brush_get_icon(bContext *C, ID *id, int preview) } else { Object *ob = CTX_data_active_object(C); - EnumPropertyItem *items; + SpaceImage *sima; + EnumPropertyItem *items = NULL; 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 */ + /* XXX: this is not nice, should probably make brushes + be strictly in one paint mode only to avoid + checking various context stuff here */ - if(ob) { + if(CTX_wm_view3d(C) && ob) { if(ob->mode & OB_MODE_SCULPT) mode = OB_MODE_SCULPT; else if(ob->mode & (OB_MODE_VERTEX_PAINT|OB_MODE_WEIGHT_PAINT)) @@ -1043,12 +1045,10 @@ static int ui_id_brush_get_icon(bContext *C, ID *id, int preview) 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; + else if((sima = CTX_wm_space_image(C)) && + (sima->flag & SI_DRAWTOOL)) { + mode = OB_MODE_TEXTURE_PAINT; + } /* reset the icon */ if(mode == OB_MODE_SCULPT) { @@ -1064,7 +1064,7 @@ static int ui_id_brush_get_icon(bContext *C, ID *id, int preview) tool = br->imagepaint_tool; } - if(!RNA_enum_icon_from_value(items, tool, &id->icon_id)) + if(!items || !RNA_enum_icon_from_value(items, tool, &id->icon_id)) id->icon_id = 0; } diff --git a/source/blender/makesdna/DNA_brush_types.h b/source/blender/makesdna/DNA_brush_types.h index 37c6200b91f..6ddad214af4 100644 --- a/source/blender/makesdna/DNA_brush_types.h +++ b/source/blender/makesdna/DNA_brush_types.h @@ -57,9 +57,6 @@ 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; diff --git a/source/blender/makesrna/intern/rna_sculpt_paint.c b/source/blender/makesrna/intern/rna_sculpt_paint.c index ae13e5c68d9..040c2175d07 100644 --- a/source/blender/makesrna/intern/rna_sculpt_paint.c +++ b/source/blender/makesrna/intern/rna_sculpt_paint.c @@ -160,19 +160,23 @@ static int rna_ParticleEdit_hair_get(PointerRNA *ptr) static int rna_Brush_mode_poll(PointerRNA *ptr, PointerRNA value) { Scene *scene= (Scene *)ptr->id.data; - Object *ob = OBACT; + ToolSettings *ts = scene->toolsettings; Brush *brush= value.id.data; - - /* weak, for object painting we need to check against the object mode - * but for 2D view image painting we always want texture brushes - * this is not quite correct since you could be in object weightpaint - * mode at the same time as the 2D image view, but for now its *good enough* */ - if(ob && ob->mode & OB_MODE_ALL_PAINT) { - return ob->mode & brush->ob_mode; - } - else { - return OB_MODE_TEXTURE_PAINT & brush->ob_mode; - } + int mode = 0; + + /* check the origin of the Paint struct to see which paint + mode to select from */ + + if(ptr->data == &ts->imapaint) + mode = OB_MODE_TEXTURE_PAINT; + else if(ptr->data == ts->sculpt) + mode = OB_MODE_SCULPT; + else if(ptr->data == ts->vpaint) + mode = OB_MODE_VERTEX_PAINT; + else if(ptr->data == ts->wpaint) + mode = OB_MODE_WEIGHT_PAINT; + + return brush->ob_mode & mode; } #else