2011-11-08 13:07:16 +00:00
|
|
|
/*
|
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
2018-06-01 18:19:39 +02:00
|
|
|
* of the License, or (at your option) any later version.
|
2011-11-08 13:07:16 +00:00
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
|
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
*
|
|
|
|
|
* The Original Code is Copyright (C) 2009 Blender Foundation.
|
|
|
|
|
* All rights reserved.
|
|
|
|
|
*/
|
|
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup spbuttons
|
2011-11-08 13:07:16 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
|
|
|
|
#include "BLI_listbase.h"
|
|
|
|
|
#include "BLI_string.h"
|
|
|
|
|
#include "BLI_utildefines.h"
|
|
|
|
|
|
2015-08-16 17:32:01 +10:00
|
|
|
#include "BLT_translation.h"
|
2013-02-24 15:40:28 +00:00
|
|
|
|
2011-11-08 13:07:16 +00:00
|
|
|
#include "DNA_ID.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "DNA_brush_types.h"
|
|
|
|
|
#include "DNA_linestyle_types.h"
|
2011-11-08 13:07:16 +00:00
|
|
|
#include "DNA_node_types.h"
|
2018-02-07 11:14:08 +11:00
|
|
|
#include "DNA_object_force_types.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "DNA_object_types.h"
|
2011-11-08 13:07:16 +00:00
|
|
|
#include "DNA_particle_types.h"
|
|
|
|
|
#include "DNA_scene_types.h"
|
|
|
|
|
#include "DNA_screen_types.h"
|
|
|
|
|
#include "DNA_space_types.h"
|
2018-07-04 13:00:46 +02:00
|
|
|
#include "DNA_windowmanager_types.h"
|
2014-05-03 18:51:53 +09:00
|
|
|
|
2011-11-08 13:07:16 +00:00
|
|
|
#include "BKE_context.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "BKE_gpencil_modifier.h"
|
2017-11-09 13:11:20 -02:00
|
|
|
#include "BKE_layer.h"
|
2014-07-16 13:36:39 +09:00
|
|
|
#include "BKE_linestyle.h"
|
2011-11-08 13:07:16 +00:00
|
|
|
#include "BKE_modifier.h"
|
|
|
|
|
#include "BKE_node.h"
|
|
|
|
|
#include "BKE_paint.h"
|
|
|
|
|
#include "BKE_particle.h"
|
|
|
|
|
#include "BKE_scene.h"
|
2018-04-24 15:20:17 +02:00
|
|
|
#include "BKE_workspace.h"
|
2014-11-28 15:50:43 +01:00
|
|
|
#ifdef WITH_FREESTYLE
|
|
|
|
|
# include "BKE_freestyle.h"
|
|
|
|
|
#endif
|
2011-11-08 13:07:16 +00:00
|
|
|
|
|
|
|
|
#include "RNA_access.h"
|
|
|
|
|
|
|
|
|
|
#include "UI_interface.h"
|
|
|
|
|
#include "UI_resources.h"
|
|
|
|
|
|
This commit addresses the somewhat weak handling of stackless textures in Blender with default (BI) renderer. To do so, it's defining an "other" texture context, and when in this one, it switches to using the "new shading" texture handling already known with Cycles engine.
So now, in the new "other" tex context, you can (depending on active data) have direct access to modifiers', force's or brushes' textures...
I also refactored a bit how texture contexts are handled (once again, we had some quite similar code in both space_buttons and RNA sources). This should also solve some harmless glitches like "no texture context selected in UI" sometimes when you remove data related to current texture (see e.g. after removing the material from default cube, in startup scene).
This usage of two different systems for textures, and the handling of switches between them, has been a bit tricky to get working right, but it is OK now I think. I also had to add a bool flag to buttons space, SB_TEX_USER_LIMITED (use_limited_texture_context in RNA), which indicates "new shading" texture code whether it has to ignore materials, lamps etc. (BI) or not (Cycles).
Btw, pinned textures from modifiers/force/etc. were also broken (showing nothing), now it should work too.
Thanks to Brecht for reviewing.
2013-05-17 07:10:10 +00:00
|
|
|
#include "ED_buttons.h"
|
2011-11-08 13:07:16 +00:00
|
|
|
#include "ED_node.h"
|
|
|
|
|
#include "ED_screen.h"
|
|
|
|
|
|
2018-07-04 13:00:46 +02:00
|
|
|
#include "WM_api.h"
|
|
|
|
|
|
2011-11-08 13:07:16 +00:00
|
|
|
#include "../interface/interface_intern.h"
|
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
#include "buttons_intern.h" // own include
|
2011-11-08 13:07:16 +00:00
|
|
|
|
|
|
|
|
/************************* Texture User **************************/
|
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
static void buttons_texture_user_property_add(ListBase *users,
|
|
|
|
|
ID *id,
|
|
|
|
|
PointerRNA ptr,
|
|
|
|
|
PropertyRNA *prop,
|
|
|
|
|
const char *category,
|
|
|
|
|
int icon,
|
|
|
|
|
const char *name)
|
2011-11-08 13:07:16 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
ButsTextureUser *user = MEM_callocN(sizeof(ButsTextureUser), "ButsTextureUser");
|
2011-11-08 13:07:16 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
user->id = id;
|
|
|
|
|
user->ptr = ptr;
|
|
|
|
|
user->prop = prop;
|
|
|
|
|
user->category = category;
|
|
|
|
|
user->icon = icon;
|
|
|
|
|
user->name = name;
|
|
|
|
|
user->index = BLI_listbase_count(users);
|
2011-11-08 13:07:16 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_addtail(users, user);
|
2011-11-08 13:07:16 +00:00
|
|
|
}
|
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
static void buttons_texture_user_node_add(ListBase *users,
|
|
|
|
|
ID *id,
|
|
|
|
|
bNodeTree *ntree,
|
|
|
|
|
bNode *node,
|
|
|
|
|
const char *category,
|
|
|
|
|
int icon,
|
|
|
|
|
const char *name)
|
2011-11-08 13:07:16 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
ButsTextureUser *user = MEM_callocN(sizeof(ButsTextureUser), "ButsTextureUser");
|
2011-11-08 13:07:16 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
user->id = id;
|
|
|
|
|
user->ntree = ntree;
|
|
|
|
|
user->node = node;
|
|
|
|
|
user->category = category;
|
|
|
|
|
user->icon = icon;
|
|
|
|
|
user->name = name;
|
|
|
|
|
user->index = BLI_listbase_count(users);
|
2011-11-08 13:07:16 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
BLI_addtail(users, user);
|
2011-11-08 13:07:16 +00:00
|
|
|
}
|
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
static void buttons_texture_users_find_nodetree(ListBase *users,
|
|
|
|
|
ID *id,
|
|
|
|
|
bNodeTree *ntree,
|
|
|
|
|
const char *category)
|
2011-11-08 13:07:16 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
bNode *node;
|
|
|
|
|
|
|
|
|
|
if (ntree) {
|
|
|
|
|
for (node = ntree->nodes.first; node; node = node->next) {
|
|
|
|
|
if (node->typeinfo->nclass == NODE_CLASS_TEXTURE) {
|
|
|
|
|
PointerRNA ptr;
|
|
|
|
|
/* PropertyRNA *prop; */ /* UNUSED */
|
|
|
|
|
|
|
|
|
|
RNA_pointer_create(&ntree->id, &RNA_Node, node, &ptr);
|
|
|
|
|
/* prop = RNA_struct_find_property(&ptr, "texture"); */ /* UNUSED */
|
|
|
|
|
|
|
|
|
|
buttons_texture_user_node_add(
|
|
|
|
|
users, id, ntree, node, category, RNA_struct_ui_icon(ptr.type), node->name);
|
|
|
|
|
}
|
|
|
|
|
else if (node->type == NODE_GROUP && node->id) {
|
|
|
|
|
buttons_texture_users_find_nodetree(users, id, (bNodeTree *)node->id, category);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-11-08 13:07:16 +00:00
|
|
|
}
|
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
static void buttons_texture_modifier_foreach(void *userData,
|
|
|
|
|
Object *ob,
|
|
|
|
|
ModifierData *md,
|
|
|
|
|
const char *propname)
|
2011-11-08 13:07:16 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
PointerRNA ptr;
|
|
|
|
|
PropertyRNA *prop;
|
|
|
|
|
ListBase *users = userData;
|
2011-11-08 13:07:16 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
RNA_pointer_create(&ob->id, &RNA_Modifier, md, &ptr);
|
|
|
|
|
prop = RNA_struct_find_property(&ptr, propname);
|
2011-11-08 13:07:16 +00:00
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
buttons_texture_user_property_add(
|
|
|
|
|
users, &ob->id, ptr, prop, N_("Modifiers"), RNA_struct_ui_icon(ptr.type), md->name);
|
2011-11-08 13:07:16 +00:00
|
|
|
}
|
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
static void buttons_texture_modifier_gpencil_foreach(void *userData,
|
|
|
|
|
Object *ob,
|
|
|
|
|
GpencilModifierData *md,
|
|
|
|
|
const char *propname)
|
2018-07-31 10:22:19 +02:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
PointerRNA ptr;
|
|
|
|
|
PropertyRNA *prop;
|
|
|
|
|
ListBase *users = userData;
|
|
|
|
|
|
|
|
|
|
RNA_pointer_create(&ob->id, &RNA_GpencilModifier, md, &ptr);
|
|
|
|
|
prop = RNA_struct_find_property(&ptr, propname);
|
|
|
|
|
|
|
|
|
|
buttons_texture_user_property_add(users,
|
|
|
|
|
&ob->id,
|
|
|
|
|
ptr,
|
|
|
|
|
prop,
|
|
|
|
|
N_("Grease Pencil Modifiers"),
|
|
|
|
|
RNA_struct_ui_icon(ptr.type),
|
|
|
|
|
md->name);
|
2018-07-31 10:22:19 +02:00
|
|
|
}
|
|
|
|
|
|
2019-04-17 06:17:24 +02:00
|
|
|
static void buttons_texture_users_from_context(ListBase *users,
|
|
|
|
|
const bContext *C,
|
|
|
|
|
SpaceProperties *sbuts)
|
2011-11-08 13:07:16 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
Scene *scene = NULL;
|
|
|
|
|
Object *ob = NULL;
|
|
|
|
|
FreestyleLineStyle *linestyle = NULL;
|
|
|
|
|
Brush *brush = NULL;
|
|
|
|
|
ID *pinid = sbuts->pinid;
|
|
|
|
|
bool limited_mode = (sbuts->flag & SB_TEX_USER_LIMITED) != 0;
|
|
|
|
|
|
|
|
|
|
/* get data from context */
|
|
|
|
|
if (pinid) {
|
|
|
|
|
if (GS(pinid->name) == ID_SCE) {
|
|
|
|
|
scene = (Scene *)pinid;
|
|
|
|
|
}
|
|
|
|
|
else if (GS(pinid->name) == ID_OB) {
|
|
|
|
|
ob = (Object *)pinid;
|
|
|
|
|
}
|
|
|
|
|
else if (GS(pinid->name) == ID_BR) {
|
|
|
|
|
brush = (Brush *)pinid;
|
|
|
|
|
}
|
|
|
|
|
else if (GS(pinid->name) == ID_LS) {
|
|
|
|
|
linestyle = (FreestyleLineStyle *)pinid;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!scene) {
|
|
|
|
|
scene = CTX_data_scene(C);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const ID_Type id_type = pinid != NULL ? GS(pinid->name) : -1;
|
|
|
|
|
if (!pinid || id_type == ID_SCE) {
|
|
|
|
|
wmWindow *win = CTX_wm_window(C);
|
|
|
|
|
ViewLayer *view_layer = (win->scene == scene) ? WM_window_get_active_view_layer(win) :
|
|
|
|
|
BKE_view_layer_default_view(scene);
|
|
|
|
|
|
|
|
|
|
brush = BKE_paint_brush(BKE_paint_get_active_from_context(C));
|
|
|
|
|
linestyle = BKE_linestyle_active_from_view_layer(view_layer);
|
|
|
|
|
ob = OBACT(view_layer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* fill users */
|
|
|
|
|
BLI_listbase_clear(users);
|
|
|
|
|
|
|
|
|
|
if (linestyle && !limited_mode) {
|
|
|
|
|
buttons_texture_users_find_nodetree(
|
|
|
|
|
users, &linestyle->id, linestyle->nodetree, N_("Line Style"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ob) {
|
|
|
|
|
ParticleSystem *psys = psys_get_current(ob);
|
|
|
|
|
MTex *mtex;
|
|
|
|
|
int a;
|
|
|
|
|
|
|
|
|
|
/* modifiers */
|
2020-05-08 10:14:02 +02:00
|
|
|
BKE_modifiers_foreach_tex_link(ob, buttons_texture_modifier_foreach, users);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
|
/* grease pencil modifiers */
|
2020-05-08 10:32:30 +02:00
|
|
|
BKE_gpencil_modifiers_foreach_tex_link(ob, buttons_texture_modifier_gpencil_foreach, users);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
|
|
|
|
/* particle systems */
|
|
|
|
|
if (psys && !limited_mode) {
|
|
|
|
|
for (a = 0; a < MAX_MTEX; a++) {
|
|
|
|
|
mtex = psys->part->mtex[a];
|
|
|
|
|
|
|
|
|
|
if (mtex) {
|
|
|
|
|
PointerRNA ptr;
|
|
|
|
|
PropertyRNA *prop;
|
|
|
|
|
|
|
|
|
|
RNA_pointer_create(&psys->part->id, &RNA_ParticleSettingsTextureSlot, mtex, &ptr);
|
|
|
|
|
prop = RNA_struct_find_property(&ptr, "texture");
|
|
|
|
|
|
|
|
|
|
buttons_texture_user_property_add(users,
|
|
|
|
|
&psys->part->id,
|
|
|
|
|
ptr,
|
|
|
|
|
prop,
|
|
|
|
|
N_("Particles"),
|
|
|
|
|
RNA_struct_ui_icon(&RNA_ParticleSettings),
|
|
|
|
|
psys->name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* field */
|
|
|
|
|
if (ob->pd && ob->pd->forcefield == PFIELD_TEXTURE) {
|
|
|
|
|
PointerRNA ptr;
|
|
|
|
|
PropertyRNA *prop;
|
|
|
|
|
|
|
|
|
|
RNA_pointer_create(&ob->id, &RNA_FieldSettings, ob->pd, &ptr);
|
|
|
|
|
prop = RNA_struct_find_property(&ptr, "texture");
|
|
|
|
|
|
|
|
|
|
buttons_texture_user_property_add(
|
|
|
|
|
users, &ob->id, ptr, prop, N_("Fields"), ICON_FORCE_TEXTURE, IFACE_("Texture Field"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* brush */
|
|
|
|
|
if (brush) {
|
|
|
|
|
PointerRNA ptr;
|
|
|
|
|
PropertyRNA *prop;
|
|
|
|
|
|
|
|
|
|
/* texture */
|
|
|
|
|
RNA_pointer_create(&brush->id, &RNA_BrushTextureSlot, &brush->mtex, &ptr);
|
|
|
|
|
prop = RNA_struct_find_property(&ptr, "texture");
|
|
|
|
|
|
|
|
|
|
buttons_texture_user_property_add(
|
|
|
|
|
users, &brush->id, ptr, prop, N_("Brush"), ICON_BRUSH_DATA, IFACE_("Brush"));
|
|
|
|
|
|
|
|
|
|
/* mask texture */
|
|
|
|
|
RNA_pointer_create(&brush->id, &RNA_BrushTextureSlot, &brush->mask_mtex, &ptr);
|
|
|
|
|
prop = RNA_struct_find_property(&ptr, "texture");
|
|
|
|
|
|
|
|
|
|
buttons_texture_user_property_add(
|
|
|
|
|
users, &brush->id, ptr, prop, N_("Brush"), ICON_BRUSH_DATA, IFACE_("Brush Mask"));
|
|
|
|
|
}
|
2011-11-08 13:07:16 +00:00
|
|
|
}
|
|
|
|
|
|
2019-02-16 10:44:15 +11:00
|
|
|
void buttons_texture_context_compute(const bContext *C, SpaceProperties *sbuts)
|
2011-11-08 13:07:16 +00:00
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* gather available texture users in context. runs on every draw of
|
|
|
|
|
* properties editor, before the buttons are created. */
|
|
|
|
|
ButsContextTexture *ct = sbuts->texuser;
|
|
|
|
|
ID *pinid = sbuts->pinid;
|
|
|
|
|
|
|
|
|
|
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_listbase_count_at_most(&ct->users, ct->index + 1)) {
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-11-08 13:07:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void template_texture_select(bContext *C, void *user_p, void *UNUSED(arg))
|
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* callback when selecting a texture user in the menu */
|
|
|
|
|
SpaceProperties *sbuts = CTX_wm_space_properties(C);
|
|
|
|
|
ButsContextTexture *ct = (sbuts) ? sbuts->texuser : NULL;
|
|
|
|
|
ButsTextureUser *user = (ButsTextureUser *)user_p;
|
|
|
|
|
PointerRNA texptr;
|
|
|
|
|
Tex *tex;
|
|
|
|
|
|
|
|
|
|
if (!ct) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* set user as active */
|
|
|
|
|
if (user->node) {
|
|
|
|
|
ED_node_set_active(CTX_data_main(C), user->ntree, user->node);
|
|
|
|
|
ct->texture = NULL;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
texptr = RNA_property_pointer_get(&user->ptr, user->prop);
|
|
|
|
|
tex = (RNA_struct_is_a(texptr.type, &RNA_Texture)) ? texptr.data : NULL;
|
|
|
|
|
|
|
|
|
|
ct->texture = tex;
|
|
|
|
|
|
|
|
|
|
if (user->ptr.type == &RNA_ParticleSettingsTextureSlot) {
|
|
|
|
|
/* stupid exception for particle systems which still uses influence
|
|
|
|
|
* from the old texture system, set the active texture slots as well */
|
2019-08-23 09:52:12 +02:00
|
|
|
ParticleSettings *part = (ParticleSettings *)user->ptr.owner_id;
|
2019-04-17 06:17:24 +02:00
|
|
|
int a;
|
|
|
|
|
|
|
|
|
|
for (a = 0; a < MAX_MTEX; a++) {
|
|
|
|
|
if (user->ptr.data == part->mtex[a]) {
|
|
|
|
|
part->texact = a;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (sbuts && tex) {
|
|
|
|
|
sbuts->preview = 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ct->user = user;
|
|
|
|
|
ct->index = user->index;
|
2011-11-08 13:07:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void template_texture_user_menu(bContext *C, uiLayout *layout, void *UNUSED(arg))
|
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* callback when opening texture user selection menu, to create buttons. */
|
|
|
|
|
SpaceProperties *sbuts = CTX_wm_space_properties(C);
|
|
|
|
|
ButsContextTexture *ct = sbuts->texuser;
|
|
|
|
|
ButsTextureUser *user;
|
|
|
|
|
uiBlock *block = uiLayoutGetBlock(layout);
|
|
|
|
|
const char *last_category = NULL;
|
|
|
|
|
|
|
|
|
|
for (user = ct->users.first; user; user = user->next) {
|
|
|
|
|
uiBut *but;
|
|
|
|
|
char name[UI_MAX_NAME_STR];
|
|
|
|
|
|
|
|
|
|
/* add label per category */
|
|
|
|
|
if (!last_category || !STREQ(last_category, user->category)) {
|
|
|
|
|
uiItemL(layout, IFACE_(user->category), ICON_NONE);
|
|
|
|
|
but = block->buttons.last;
|
|
|
|
|
but->drawflag = UI_BUT_TEXT_LEFT;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* create button */
|
|
|
|
|
if (user->prop) {
|
|
|
|
|
PointerRNA texptr = RNA_property_pointer_get(&user->ptr, user->prop);
|
|
|
|
|
Tex *tex = texptr.data;
|
|
|
|
|
|
|
|
|
|
if (tex) {
|
|
|
|
|
BLI_snprintf(name, UI_MAX_NAME_STR, " %s - %s", user->name, tex->id.name + 2);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
BLI_snprintf(name, UI_MAX_NAME_STR, " %s", user->name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
BLI_snprintf(name, UI_MAX_NAME_STR, " %s", user->name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
but = uiDefIconTextBut(block,
|
|
|
|
|
UI_BTYPE_BUT,
|
|
|
|
|
0,
|
|
|
|
|
user->icon,
|
|
|
|
|
name,
|
|
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
UI_UNIT_X * 4,
|
|
|
|
|
UI_UNIT_Y,
|
|
|
|
|
NULL,
|
|
|
|
|
0.0,
|
|
|
|
|
0.0,
|
|
|
|
|
0.0,
|
|
|
|
|
0.0,
|
|
|
|
|
"");
|
|
|
|
|
UI_but_funcN_set(but, template_texture_select, MEM_dupallocN(user), NULL);
|
|
|
|
|
|
|
|
|
|
last_category = user->category;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UI_block_flag_enable(block, UI_BLOCK_NO_FLIP);
|
2011-11-08 13:07:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void uiTemplateTextureUser(uiLayout *layout, bContext *C)
|
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* texture user selection dropdown menu. the available users have been
|
|
|
|
|
* gathered before drawing in ButsContextTexture, we merely need to
|
|
|
|
|
* display the current item. */
|
|
|
|
|
SpaceProperties *sbuts = CTX_wm_space_properties(C);
|
|
|
|
|
ButsContextTexture *ct = (sbuts) ? sbuts->texuser : NULL;
|
|
|
|
|
uiBlock *block = uiLayoutGetBlock(layout);
|
|
|
|
|
uiBut *but;
|
|
|
|
|
ButsTextureUser *user;
|
|
|
|
|
char name[UI_MAX_NAME_STR];
|
|
|
|
|
|
|
|
|
|
if (!ct) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* get current user */
|
|
|
|
|
user = ct->user;
|
|
|
|
|
|
|
|
|
|
if (!user) {
|
2019-06-11 22:25:01 +02:00
|
|
|
uiItemL(layout, TIP_("No textures in context"), ICON_NONE);
|
2019-04-17 06:17:24 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* create button */
|
|
|
|
|
BLI_strncpy(name, user->name, UI_MAX_NAME_STR);
|
|
|
|
|
|
|
|
|
|
if (user->icon) {
|
|
|
|
|
but = uiDefIconTextMenuBut(block,
|
|
|
|
|
template_texture_user_menu,
|
|
|
|
|
NULL,
|
|
|
|
|
user->icon,
|
|
|
|
|
name,
|
|
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
UI_UNIT_X * 4,
|
|
|
|
|
UI_UNIT_Y,
|
|
|
|
|
"");
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
but = uiDefMenuBut(
|
|
|
|
|
block, template_texture_user_menu, NULL, name, 0, 0, UI_UNIT_X * 4, UI_UNIT_Y, "");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* some cosmetic tweaks */
|
|
|
|
|
UI_but_type_set_menu_from_pulldown(but);
|
|
|
|
|
|
|
|
|
|
but->flag &= ~UI_BUT_ICON_SUBMENU;
|
2011-11-08 13:07:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/************************* Texture Show **************************/
|
|
|
|
|
|
|
|
|
|
static void template_texture_show(bContext *C, void *data_p, void *prop_p)
|
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
SpaceProperties *sbuts = CTX_wm_space_properties(C);
|
|
|
|
|
ButsContextTexture *ct = (sbuts) ? sbuts->texuser : NULL;
|
|
|
|
|
ButsTextureUser *user;
|
|
|
|
|
|
|
|
|
|
if (!ct) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (user = ct->users.first; user; user = user->next) {
|
|
|
|
|
if (user->ptr.data == data_p && user->prop == prop_p) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (user) {
|
|
|
|
|
/* select texture */
|
|
|
|
|
template_texture_select(C, user, NULL);
|
|
|
|
|
|
|
|
|
|
/* change context */
|
|
|
|
|
sbuts->mainb = BCONTEXT_TEXTURE;
|
|
|
|
|
sbuts->mainbuser = sbuts->mainb;
|
|
|
|
|
sbuts->preview = 1;
|
|
|
|
|
|
|
|
|
|
/* redraw editor */
|
|
|
|
|
ED_area_tag_redraw(CTX_wm_area(C));
|
|
|
|
|
}
|
2011-11-08 13:07:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void uiTemplateTextureShow(uiLayout *layout, bContext *C, PointerRNA *ptr, PropertyRNA *prop)
|
|
|
|
|
{
|
2019-04-17 06:17:24 +02:00
|
|
|
/* button to quickly show texture in texture tab */
|
|
|
|
|
SpaceProperties *sbuts = CTX_wm_space_properties(C);
|
|
|
|
|
ButsContextTexture *ct = (sbuts) ? sbuts->texuser : NULL;
|
|
|
|
|
ButsTextureUser *user;
|
|
|
|
|
|
|
|
|
|
/* only show button in other tabs in properties editor */
|
|
|
|
|
if (!ct || sbuts->mainb == BCONTEXT_TEXTURE) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* find corresponding texture user */
|
|
|
|
|
for (user = ct->users.first; user; user = user->next) {
|
|
|
|
|
if (user->ptr.data == ptr->data && user->prop == prop) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* draw button */
|
|
|
|
|
if (user) {
|
|
|
|
|
uiBlock *block = uiLayoutGetBlock(layout);
|
|
|
|
|
uiBut *but;
|
|
|
|
|
|
|
|
|
|
but = uiDefIconBut(block,
|
|
|
|
|
UI_BTYPE_BUT,
|
|
|
|
|
0,
|
|
|
|
|
ICON_PROPERTIES,
|
|
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
UI_UNIT_X,
|
|
|
|
|
UI_UNIT_Y,
|
|
|
|
|
NULL,
|
|
|
|
|
0.0,
|
|
|
|
|
0.0,
|
|
|
|
|
0.0,
|
|
|
|
|
0.0,
|
|
|
|
|
TIP_("Show texture in texture tab"));
|
|
|
|
|
UI_but_func_set(but, template_texture_show, user->ptr.data, user->prop);
|
|
|
|
|
}
|
2011-11-08 13:07:16 +00:00
|
|
|
}
|