Complete fix for [#35769] The “show texture in texture tab” button in a modifier does not show up until the user manually shows the texture in the Texture tab (and better fix for [#35741] Material shows WORLD texture_context by default).

Simply recompute texture context on every redraw, like already done for sbuts->texuser (also called texture context :/ ).

Also allows simplification, buttons_check_texture_context can be merged back into set_texture_context...
This commit is contained in:
Bastien Montagne 2013-06-16 13:13:42 +00:00
parent 29be979758
commit a691487ed4
3 changed files with 23 additions and 58 deletions

@ -59,53 +59,6 @@
#define B_CONTEXT_SWITCH 101
static void set_texture_context(const bContext *C, SpaceButs *sbuts)
{
Scene *scene = CTX_data_scene(C);
if (BKE_scene_use_new_shading_nodes(scene)) {
return; /* No texture context in new shading mode */
}
if ((sbuts->mainb == BCONTEXT_WORLD) && ED_texture_context_check_world(C)) {
sbuts->texture_context = SB_TEXC_WORLD;
}
else if ((sbuts->mainb == BCONTEXT_MATERIAL) && ED_texture_context_check_material(C)) {
sbuts->texture_context = SB_TEXC_MATERIAL;
}
else if ((sbuts->mainb == BCONTEXT_DATA) && ED_texture_context_check_lamp(C)) {
sbuts->texture_context = SB_TEXC_LAMP;
}
else if ((sbuts->mainb == BCONTEXT_PARTICLE) && ED_texture_context_check_particles(C)) {
sbuts->texture_context = SB_TEXC_PARTICLES;
}
else if ((ELEM(sbuts->mainb, BCONTEXT_MODIFIER, BCONTEXT_PHYSICS)) && ED_texture_context_check_others(C)) {
sbuts->texture_context = SB_TEXC_OTHER;
}
/* Second pass: sbuts->mainbuser still contains the previous button context.
* Useful e.g. when we switch to material, no material present, add a material, switch to texture.
* See #35741. */
else if ((sbuts->mainbuser == BCONTEXT_WORLD) && ED_texture_context_check_world(C)) {
sbuts->texture_context = SB_TEXC_WORLD;
}
else if ((sbuts->mainbuser == BCONTEXT_MATERIAL) && ED_texture_context_check_material(C)) {
sbuts->texture_context = SB_TEXC_MATERIAL;
}
else if ((sbuts->mainbuser == BCONTEXT_DATA) && ED_texture_context_check_lamp(C)) {
sbuts->texture_context = SB_TEXC_LAMP;
}
else if ((sbuts->mainbuser == BCONTEXT_PARTICLE) && ED_texture_context_check_particles(C)) {
sbuts->texture_context = SB_TEXC_PARTICLES;
}
else if ((ELEM(sbuts->mainbuser, BCONTEXT_MODIFIER, BCONTEXT_PHYSICS)) && ED_texture_context_check_others(C)) {
sbuts->texture_context = SB_TEXC_OTHER;
}
/* Else, just be sure that current context is valid! */
else {
buttons_check_texture_context(C, sbuts);
}
}
static void do_buttons_buttons(bContext *C, void *UNUSED(arg), int event)
{
SpaceButs *sbuts = CTX_wm_space_buts(C);
@ -117,8 +70,6 @@ static void do_buttons_buttons(bContext *C, void *UNUSED(arg), int event)
case B_CONTEXT_SWITCH:
ED_area_tag_redraw(CTX_wm_area(C));
set_texture_context(C, sbuts);
sbuts->preview = 1;
break;
}

@ -111,7 +111,6 @@ extern const char *buttons_context_dir[]; /* doc access */
/* buttons_texture.c */
void buttons_texture_context_compute(const struct bContext *C, struct SpaceButs *sbuts);
void buttons_check_texture_context(const struct bContext *C, struct SpaceButs *sbuts);
/* buttons_ops.c */
void BUTTONS_OT_file_browse(struct wmOperatorType *ot);

@ -135,8 +135,7 @@ bool ED_texture_context_check_others(const bContext *C)
return false;
}
/* Only change texture context if current one is invalid! */
void buttons_check_texture_context(const bContext *C, SpaceButs *sbuts)
static void set_texture_context(const bContext *C, SpaceButs *sbuts)
{
Scene *scene = CTX_data_scene(C);
@ -151,11 +150,27 @@ void buttons_check_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);
if (((sbuts->texture_context == SB_TEXC_WORLD) && !valid_world) ||
((sbuts->texture_context == SB_TEXC_MATERIAL) && !valid_material) ||
((sbuts->texture_context == SB_TEXC_LAMP) && !valid_lamp) ||
((sbuts->texture_context == SB_TEXC_PARTICLES) && !valid_particles) ||
((sbuts->texture_context == SB_TEXC_OTHER) && !valid_others))
if ((sbuts->mainb == BCONTEXT_WORLD) && valid_world) {
sbuts->texture_context = SB_TEXC_WORLD;
}
else if ((sbuts->mainb == BCONTEXT_MATERIAL) && valid_material) {
sbuts->texture_context = SB_TEXC_MATERIAL;
}
else if ((sbuts->mainb == BCONTEXT_DATA) && valid_lamp) {
sbuts->texture_context = SB_TEXC_LAMP;
}
else if ((sbuts->mainb == BCONTEXT_PARTICLE) && valid_particles) {
sbuts->texture_context = SB_TEXC_PARTICLES;
}
else if ((ELEM(sbuts->mainb, BCONTEXT_MODIFIER, BCONTEXT_PHYSICS)) && valid_others) {
sbuts->texture_context = SB_TEXC_OTHER;
}
/* Else, just be sure that current context is valid! */
else if (((sbuts->texture_context == SB_TEXC_WORLD) && !valid_world) ||
((sbuts->texture_context == SB_TEXC_MATERIAL) && !valid_material) ||
((sbuts->texture_context == SB_TEXC_LAMP) && !valid_lamp) ||
((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;
@ -368,7 +383,7 @@ void buttons_texture_context_compute(const bContext *C, SpaceButs *sbuts)
Scene *scene = CTX_data_scene(C);
ID *pinid = sbuts->pinid;
buttons_check_texture_context(C, sbuts);
set_texture_context(C, sbuts);
if (!(BKE_scene_use_new_shading_nodes(scene) || (sbuts->texture_context == SB_TEXC_OTHER))) {
if (ct) {