Fix [#36530] Texture tab refreshing problem

That was not really a bug (code working as expected), but the way tex context was handled was a bit raw, now it is much smarter:
* Default fallback context (when current one is no more valid) will now choose "most specific" ones first (i.e. material/lamp/particules before world and "others").
* When using that default fallback context, previous one is stored and we try to revive it later, if possible. Thus e.g. object[mat tex ctxt] -> empty[default world ctxt] -> object[mat tex ctxt] is now working as expected.
* However, when user explicitely or implicitely (through e.g. going to Material context...) sets a tex context, previous one is not stored, so that only default fallback context switch may later automatically revive a previous (presumably user-set) context.
This commit is contained in:
Bastien Montagne 2013-08-21 21:35:45 +00:00
parent 2a5b6d9c8f
commit c26a4be5c0
3 changed files with 38 additions and 15 deletions

View File

@ -150,20 +150,31 @@ static void set_texture_context(const bContext *C, SpaceButs *sbuts)
bool valid_particles = ED_texture_context_check_particles(C);
bool valid_others = ED_texture_context_check_others(C);
/* this is similar to direct user action, no need to keep "better" ctxt in _prev */
if ((sbuts->mainb == BCONTEXT_WORLD) && valid_world) {
sbuts->texture_context = SB_TEXC_WORLD;
sbuts->texture_context = sbuts->texture_context_prev = SB_TEXC_WORLD;
}
else if ((sbuts->mainb == BCONTEXT_MATERIAL) && valid_material) {
sbuts->texture_context = SB_TEXC_MATERIAL;
sbuts->texture_context = sbuts->texture_context_prev = SB_TEXC_MATERIAL;
}
else if ((sbuts->mainb == BCONTEXT_DATA) && valid_lamp) {
sbuts->texture_context = SB_TEXC_LAMP;
sbuts->texture_context = sbuts->texture_context_prev = SB_TEXC_LAMP;
}
else if ((sbuts->mainb == BCONTEXT_PARTICLE) && valid_particles) {
sbuts->texture_context = SB_TEXC_PARTICLES;
sbuts->texture_context = sbuts->texture_context_prev = SB_TEXC_PARTICLES;
}
else if ((ELEM(sbuts->mainb, BCONTEXT_MODIFIER, BCONTEXT_PHYSICS)) && valid_others) {
sbuts->texture_context = SB_TEXC_OTHER;
sbuts->texture_context = sbuts->texture_context_prev = SB_TEXC_OTHER;
}
/* Else, try to revive a previous "better" ctxt... */
else if ((sbuts->texture_context_prev != sbuts->texture_context) &&
(((sbuts->texture_context_prev == SB_TEXC_WORLD) && valid_world) ||
((sbuts->texture_context_prev == SB_TEXC_MATERIAL) && valid_material) ||
((sbuts->texture_context_prev == SB_TEXC_LAMP) && valid_lamp) ||
((sbuts->texture_context_prev == SB_TEXC_PARTICLES) && valid_particles) ||
((sbuts->texture_context_prev == SB_TEXC_OTHER) && valid_others)))
{
sbuts->texture_context = sbuts->texture_context_prev;
}
/* Else, just be sure that current context is valid! */
else if (((sbuts->texture_context == SB_TEXC_WORLD) && !valid_world) ||
@ -172,13 +183,9 @@ static void set_texture_context(const bContext *C, SpaceButs *sbuts)
((sbuts->texture_context == SB_TEXC_PARTICLES) && !valid_particles) ||
((sbuts->texture_context == SB_TEXC_OTHER) && !valid_others))
{
if (valid_others) {
sbuts->texture_context = SB_TEXC_OTHER;
}
else if (valid_world) {
sbuts->texture_context = SB_TEXC_WORLD;
}
else if (valid_material) {
/* this is default fallback, do keep "better" ctxt in _prev */
sbuts->texture_context_prev = sbuts->texture_context;
if (valid_material) {
sbuts->texture_context = SB_TEXC_MATERIAL;
}
else if (valid_lamp) {
@ -187,6 +194,12 @@ static void set_texture_context(const bContext *C, SpaceButs *sbuts)
else if (valid_particles) {
sbuts->texture_context = SB_TEXC_PARTICLES;
}
else if (valid_world) {
sbuts->texture_context = SB_TEXC_WORLD;
}
else if (valid_others) {
sbuts->texture_context = SB_TEXC_OTHER;
}
}
}
}

View File

@ -132,8 +132,9 @@ typedef struct SpaceButs {
short mainb, mainbo, mainbuser; /* context tabs */
short re_align, align; /* align for panels */
short preview; /* preview is signal to refresh */
short texture_context; /* texture context selector (material, world, brush)*/
char flag, pad;
/* texture context selector (material, lamp, particles, world, other)*/
short texture_context, texture_context_prev;
char flag, pad[7];
void *path; /* runtime */
int pathflag, dataicon; /* runtime */

View File

@ -959,6 +959,14 @@ static EnumPropertyItem *rna_SpaceProperties_texture_context_itemf(bContext *C,
return item;
}
static void rna_SpaceProperties_texture_context_set(PointerRNA *ptr, int value)
{
SpaceButs *sbuts = (SpaceButs *)(ptr->data);
/* User action, no need to keep "better" value in prev here! */
sbuts->texture_context = sbuts->texture_context_prev = value;
}
/* Space Console */
static void rna_ConsoleLine_body_get(PointerRNA *ptr, char *value)
{
@ -2194,7 +2202,8 @@ static void rna_def_space_buttons(BlenderRNA *brna)
prop = RNA_def_property(srna, "texture_context", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_items(prop, buttons_texture_context_items);
RNA_def_property_enum_funcs(prop, NULL, NULL, "rna_SpaceProperties_texture_context_itemf");
RNA_def_property_enum_funcs(prop, NULL, "rna_SpaceProperties_texture_context_set",
"rna_SpaceProperties_texture_context_itemf");
RNA_def_property_ui_text(prop, "Texture Context", "Type of texture data to display and edit");
RNA_def_property_update(prop, NC_TEXTURE, NULL);