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.
This commit is contained in:
Nicholas Bishop 2011-01-16 18:33:08 +00:00
parent 6ef1f23a33
commit c94eefd52b
3 changed files with 28 additions and 27 deletions

@ -48,6 +48,7 @@
#include "DNA_brush_types.h" #include "DNA_brush_types.h"
#include "DNA_object_types.h" #include "DNA_object_types.h"
#include "DNA_screen_types.h" #include "DNA_screen_types.h"
#include "DNA_space_types.h"
#include "RNA_access.h" #include "RNA_access.h"
#include "RNA_enum_types.h" #include "RNA_enum_types.h"
@ -1028,14 +1029,15 @@ static int ui_id_brush_get_icon(bContext *C, ID *id, int preview)
} }
else { else {
Object *ob = CTX_data_active_object(C); Object *ob = CTX_data_active_object(C);
EnumPropertyItem *items; SpaceImage *sima;
EnumPropertyItem *items = NULL;
int tool, mode = 0; int tool, mode = 0;
/* this is not nice, should probably make brushes be /* XXX: this is not nice, should probably make brushes
strictly in one paint mode only to avoid checking be strictly in one paint mode only to avoid
object mode here */ checking various context stuff here */
if(ob) { if(CTX_wm_view3d(C) && ob) {
if(ob->mode & OB_MODE_SCULPT) if(ob->mode & OB_MODE_SCULPT)
mode = OB_MODE_SCULPT; mode = OB_MODE_SCULPT;
else if(ob->mode & (OB_MODE_VERTEX_PAINT|OB_MODE_WEIGHT_PAINT)) 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) else if(ob->mode & OB_MODE_TEXTURE_PAINT)
mode = OB_MODE_TEXTURE_PAINT; mode = OB_MODE_TEXTURE_PAINT;
} }
else if((sima = CTX_wm_space_image(C)) &&
/* check if cached icon is OK */ (sima->flag & SI_DRAWTOOL)) {
if(!mode || (id->icon_id && mode == br->icon_mode)) mode = OB_MODE_TEXTURE_PAINT;
return id->icon_id; }
br->icon_mode = mode;
/* reset the icon */ /* reset the icon */
if(mode == OB_MODE_SCULPT) { 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; 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; id->icon_id = 0;
} }

@ -57,9 +57,6 @@ typedef struct Brush {
struct ImBuf *icon_imbuf; struct ImBuf *icon_imbuf;
PreviewImage *preview; PreviewImage *preview;
char icon_filepath[240]; char icon_filepath[240];
int icon_mode; /* store paint mode for which brush's icon was last generated */
int pad;
float normal_weight; float normal_weight;

@ -160,19 +160,23 @@ static int rna_ParticleEdit_hair_get(PointerRNA *ptr)
static int rna_Brush_mode_poll(PointerRNA *ptr, PointerRNA value) static int rna_Brush_mode_poll(PointerRNA *ptr, PointerRNA value)
{ {
Scene *scene= (Scene *)ptr->id.data; Scene *scene= (Scene *)ptr->id.data;
Object *ob = OBACT; ToolSettings *ts = scene->toolsettings;
Brush *brush= value.id.data; Brush *brush= value.id.data;
int mode = 0;
/* weak, for object painting we need to check against the object mode
* but for 2D view image painting we always want texture brushes /* check the origin of the Paint struct to see which paint
* this is not quite correct since you could be in object weightpaint mode to select from */
* mode at the same time as the 2D image view, but for now its *good enough* */
if(ob && ob->mode & OB_MODE_ALL_PAINT) { if(ptr->data == &ts->imapaint)
return ob->mode & brush->ob_mode; mode = OB_MODE_TEXTURE_PAINT;
} else if(ptr->data == ts->sculpt)
else { mode = OB_MODE_SCULPT;
return OB_MODE_TEXTURE_PAINT & brush->ob_mode; 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 #else