Пример #1
0
static void do_buttons_buttons(bContext *C, void *UNUSED(arg), int event)
{
	SpaceButs *sbuts = CTX_wm_space_buts(C);

	if (!sbuts) /* editor type switch */
		return;

	switch (event) {
		case B_CONTEXT_SWITCH:
		case B_BUTSPREVIEW:
			ED_area_tag_redraw(CTX_wm_area(C));

			set_texture_context(C, sbuts);

			sbuts->preview = 1;
			break;
	}

	sbuts->mainbuser = sbuts->mainb;
}
Пример #2
0
void buttons_texture_context_compute(const bContext *C, SpaceButs *sbuts)
{
    /* gather available texture users in context. runs on every draw of
     * properties editor, before the buttons are created. */
    ButsContextTexture *ct = sbuts->texuser;
    Scene *scene = CTX_data_scene(C);
    ID *pinid = sbuts->pinid;

    set_texture_context(C, sbuts);

    if (!(BKE_scene_use_new_shading_nodes(scene) || (sbuts->texture_context == SB_TEXC_OTHER))) {
        if (ct) {
            BLI_freelistN(&ct->users);
            MEM_freeN(ct);
            sbuts->texuser = NULL;
        }

        return;
    }

    if (!ct) {
        ct = MEM_callocN(sizeof(ButsContextTexture), "ButsContextTexture");
        sbuts->texuser = ct;
    }
    else {
        BLI_freelistN(&ct->users);
    }

    buttons_texture_users_from_context(&ct->users, C, sbuts);

    if (pinid && GS(pinid->name) == ID_TE) {
        ct->user = NULL;
        ct->texture = (Tex *)pinid;
    }
    else {
        /* set one user as active based on active index */
        if (ct->index >= BLI_countlist(&ct->users))
            ct->index = 0;

        ct->user = BLI_findlink(&ct->users, ct->index);
        ct->texture = NULL;

        if (ct->user) {
            if (ct->user->ptr.data) {
                PointerRNA texptr;
                Tex *tex;

                /* get texture datablock pointer if it's a property */
                texptr = RNA_property_pointer_get(&ct->user->ptr, ct->user->prop);
                tex = (RNA_struct_is_a(texptr.type, &RNA_Texture)) ? texptr.data : NULL;

                ct->texture = tex;
            }
            else if (ct->user->node && !(ct->user->node->flag & NODE_ACTIVE_TEXTURE)) {
                ButsTextureUser *user;

                /* detect change of active texture node in same node tree, in that
                 * case we also automatically switch to the other node */
                for (user = ct->users.first; user; user = user->next) {
                    if (user->ntree == ct->user->ntree && user->node != ct->user->node) {
                        if (user->node->flag & NODE_ACTIVE_TEXTURE) {
                            ct->user = user;
                            ct->index = BLI_findindex(&ct->users, user);
                            break;
                        }
                    }
                }
            }
        }
    }
}