Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/space_buttons/buttons_texture.cc
- This file was moved from source/blender/editors/space_buttons/buttons_texture.c.
| Show First 20 Lines • Show All 65 Lines • ▼ Show 20 Lines | static void buttons_texture_user_socket_property_add(ListBase *users, | ||||
| PropertyRNA *prop, | PropertyRNA *prop, | ||||
| bNodeTree *ntree, | bNodeTree *ntree, | ||||
| bNode *node, | bNode *node, | ||||
| bNodeSocket *socket, | bNodeSocket *socket, | ||||
| const char *category, | const char *category, | ||||
| int icon, | int icon, | ||||
| const char *name) | const char *name) | ||||
| { | { | ||||
| ButsTextureUser *user = MEM_callocN(sizeof(ButsTextureUser), "ButsTextureUser"); | ButsTextureUser *user = MEM_cnew<ButsTextureUser>("ButsTextureUser"); | ||||
| user->id = id; | user->id = id; | ||||
| user->ptr = ptr; | user->ptr = ptr; | ||||
| user->prop = prop; | user->prop = prop; | ||||
| user->ntree = ntree; | user->ntree = ntree; | ||||
| user->node = node; | user->node = node; | ||||
| user->socket = socket; | user->socket = socket; | ||||
| user->category = category; | user->category = category; | ||||
| user->icon = icon; | user->icon = icon; | ||||
| user->name = name; | user->name = name; | ||||
| user->index = BLI_listbase_count(users); | user->index = BLI_listbase_count(users); | ||||
| BLI_addtail(users, user); | BLI_addtail(users, user); | ||||
| } | } | ||||
| static void buttons_texture_user_property_add(ListBase *users, | static void buttons_texture_user_property_add(ListBase *users, | ||||
| ID *id, | ID *id, | ||||
| PointerRNA ptr, | PointerRNA ptr, | ||||
| PropertyRNA *prop, | PropertyRNA *prop, | ||||
| const char *category, | const char *category, | ||||
| int icon, | int icon, | ||||
| const char *name) | const char *name) | ||||
| { | { | ||||
| ButsTextureUser *user = MEM_callocN(sizeof(ButsTextureUser), "ButsTextureUser"); | ButsTextureUser *user = MEM_cnew<ButsTextureUser>("ButsTextureUser"); | ||||
| user->id = id; | user->id = id; | ||||
| user->ptr = ptr; | user->ptr = ptr; | ||||
| user->prop = prop; | user->prop = prop; | ||||
| user->category = category; | user->category = category; | ||||
| user->icon = icon; | user->icon = icon; | ||||
| user->name = name; | user->name = name; | ||||
| user->index = BLI_listbase_count(users); | user->index = BLI_listbase_count(users); | ||||
| BLI_addtail(users, user); | BLI_addtail(users, user); | ||||
| } | } | ||||
| static void buttons_texture_user_node_add(ListBase *users, | static void buttons_texture_user_node_add(ListBase *users, | ||||
| ID *id, | ID *id, | ||||
| bNodeTree *ntree, | bNodeTree *ntree, | ||||
| bNode *node, | bNode *node, | ||||
| const char *category, | const char *category, | ||||
| int icon, | int icon, | ||||
| const char *name) | const char *name) | ||||
| { | { | ||||
| ButsTextureUser *user = MEM_callocN(sizeof(ButsTextureUser), "ButsTextureUser"); | ButsTextureUser *user = MEM_cnew<ButsTextureUser>("ButsTextureUser"); | ||||
| user->id = id; | user->id = id; | ||||
| user->ntree = ntree; | user->ntree = ntree; | ||||
| user->node = node; | user->node = node; | ||||
| user->category = category; | user->category = category; | ||||
| user->icon = icon; | user->icon = icon; | ||||
| user->name = name; | user->name = name; | ||||
| user->index = BLI_listbase_count(users); | user->index = BLI_listbase_count(users); | ||||
| BLI_addtail(users, user); | BLI_addtail(users, user); | ||||
| } | } | ||||
| static void buttons_texture_users_find_nodetree(ListBase *users, | static void buttons_texture_users_find_nodetree(ListBase *users, | ||||
| ID *id, | ID *id, | ||||
| bNodeTree *ntree, | bNodeTree *ntree, | ||||
| const char *category) | const char *category) | ||||
| { | { | ||||
| bNode *node; | bNode *node; | ||||
| if (ntree) { | if (ntree) { | ||||
| for (node = ntree->nodes.first; node; node = node->next) { | for (node = static_cast<bNode *>(ntree->nodes.first); node; node = node->next) { | ||||
| if (node->typeinfo->nclass == NODE_CLASS_TEXTURE) { | if (node->typeinfo->nclass == NODE_CLASS_TEXTURE) { | ||||
| PointerRNA ptr; | PointerRNA ptr; | ||||
| // PropertyRNA *prop; /* UNUSED */ | // PropertyRNA *prop; /* UNUSED */ | ||||
| RNA_pointer_create(&ntree->id, &RNA_Node, node, &ptr); | RNA_pointer_create(&ntree->id, &RNA_Node, node, &ptr); | ||||
| // prop = RNA_struct_find_property(&ptr, "texture"); /* UNUSED */ | // prop = RNA_struct_find_property(&ptr, "texture"); /* UNUSED */ | ||||
| buttons_texture_user_node_add( | buttons_texture_user_node_add( | ||||
| Show All 25 Lines | LISTBASE_FOREACH (bNodeSocket *, socket, &node->inputs) { | ||||
| } | } | ||||
| if (socket->type != SOCK_TEXTURE) { | if (socket->type != SOCK_TEXTURE) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| RNA_pointer_create(&node_tree->id, &RNA_NodeSocket, socket, &ptr); | RNA_pointer_create(&node_tree->id, &RNA_NodeSocket, socket, &ptr); | ||||
| prop = RNA_struct_find_property(&ptr, "default_value"); | prop = RNA_struct_find_property(&ptr, "default_value"); | ||||
| PointerRNA texptr = RNA_property_pointer_get(&ptr, prop); | PointerRNA texptr = RNA_property_pointer_get(&ptr, prop); | ||||
| Tex *tex = RNA_struct_is_a(texptr.type, &RNA_Texture) ? (Tex *)texptr.data : NULL; | Tex *tex = RNA_struct_is_a(texptr.type, &RNA_Texture) ? (Tex *)texptr.data : nullptr; | ||||
| if (tex != NULL) { | if (tex != nullptr) { | ||||
| buttons_texture_user_socket_property_add(users, | buttons_texture_user_socket_property_add(users, | ||||
| &ob->id, | &ob->id, | ||||
| ptr, | ptr, | ||||
| prop, | prop, | ||||
| node_tree, | node_tree, | ||||
| node, | node, | ||||
| socket, | socket, | ||||
| N_("Geometry Nodes"), | N_("Geometry Nodes"), | ||||
| RNA_struct_ui_icon(ptr.type), | RNA_struct_ui_icon(ptr.type), | ||||
| nmd->modifier.name); | nmd->modifier.name); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| static void buttons_texture_modifier_foreach(void *userData, | static void buttons_texture_modifier_foreach(void *userData, | ||||
| Object *ob, | Object *ob, | ||||
| ModifierData *md, | ModifierData *md, | ||||
| const char *propname) | const char *propname) | ||||
| { | { | ||||
| ListBase *users = userData; | ListBase *users = static_cast<ListBase *>(userData); | ||||
| if (md->type == eModifierType_Nodes) { | if (md->type == eModifierType_Nodes) { | ||||
| NodesModifierData *nmd = (NodesModifierData *)md; | NodesModifierData *nmd = (NodesModifierData *)md; | ||||
| if (nmd->node_group != NULL) { | if (nmd->node_group != nullptr) { | ||||
| buttons_texture_modifier_geonodes_users_add(ob, nmd, nmd->node_group, users); | buttons_texture_modifier_geonodes_users_add(ob, nmd, nmd->node_group, users); | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| PointerRNA ptr; | PointerRNA ptr; | ||||
| PropertyRNA *prop; | PropertyRNA *prop; | ||||
| RNA_pointer_create(&ob->id, &RNA_Modifier, md, &ptr); | RNA_pointer_create(&ob->id, &RNA_Modifier, md, &ptr); | ||||
| prop = RNA_struct_find_property(&ptr, propname); | prop = RNA_struct_find_property(&ptr, propname); | ||||
| buttons_texture_user_property_add( | buttons_texture_user_property_add( | ||||
| users, &ob->id, ptr, prop, N_("Modifiers"), RNA_struct_ui_icon(ptr.type), md->name); | users, &ob->id, ptr, prop, N_("Modifiers"), RNA_struct_ui_icon(ptr.type), md->name); | ||||
| } | } | ||||
| } | } | ||||
| static void buttons_texture_modifier_gpencil_foreach(void *userData, | static void buttons_texture_modifier_gpencil_foreach(void *userData, | ||||
| Object *ob, | Object *ob, | ||||
| GpencilModifierData *md, | GpencilModifierData *md, | ||||
| const char *propname) | const char *propname) | ||||
| { | { | ||||
| PointerRNA ptr; | PointerRNA ptr; | ||||
| PropertyRNA *prop; | PropertyRNA *prop; | ||||
| ListBase *users = userData; | ListBase *users = static_cast<ListBase *>(userData); | ||||
| RNA_pointer_create(&ob->id, &RNA_GpencilModifier, md, &ptr); | RNA_pointer_create(&ob->id, &RNA_GpencilModifier, md, &ptr); | ||||
| prop = RNA_struct_find_property(&ptr, propname); | prop = RNA_struct_find_property(&ptr, propname); | ||||
| buttons_texture_user_property_add(users, | buttons_texture_user_property_add(users, | ||||
| &ob->id, | &ob->id, | ||||
| ptr, | ptr, | ||||
| prop, | prop, | ||||
| N_("Grease Pencil Modifiers"), | N_("Grease Pencil Modifiers"), | ||||
| RNA_struct_ui_icon(ptr.type), | RNA_struct_ui_icon(ptr.type), | ||||
| md->name); | md->name); | ||||
| } | } | ||||
| static void buttons_texture_users_from_context(ListBase *users, | static void buttons_texture_users_from_context(ListBase *users, | ||||
| const bContext *C, | const bContext *C, | ||||
| SpaceProperties *sbuts) | SpaceProperties *sbuts) | ||||
| { | { | ||||
| Scene *scene = NULL; | Scene *scene = nullptr; | ||||
| Object *ob = NULL; | Object *ob = nullptr; | ||||
| FreestyleLineStyle *linestyle = NULL; | FreestyleLineStyle *linestyle = nullptr; | ||||
| Brush *brush = NULL; | Brush *brush = nullptr; | ||||
| ID *pinid = sbuts->pinid; | ID *pinid = sbuts->pinid; | ||||
| bool limited_mode = (sbuts->flag & SB_TEX_USER_LIMITED) != 0; | bool limited_mode = (sbuts->flag & SB_TEX_USER_LIMITED) != 0; | ||||
| /* get data from context */ | /* get data from context */ | ||||
| if (pinid) { | if (pinid) { | ||||
| if (GS(pinid->name) == ID_SCE) { | if (GS(pinid->name) == ID_SCE) { | ||||
| scene = (Scene *)pinid; | scene = (Scene *)pinid; | ||||
| } | } | ||||
| else if (GS(pinid->name) == ID_OB) { | else if (GS(pinid->name) == ID_OB) { | ||||
| ob = (Object *)pinid; | ob = (Object *)pinid; | ||||
| } | } | ||||
| else if (GS(pinid->name) == ID_BR) { | else if (GS(pinid->name) == ID_BR) { | ||||
| brush = (Brush *)pinid; | brush = (Brush *)pinid; | ||||
| } | } | ||||
| else if (GS(pinid->name) == ID_LS) { | else if (GS(pinid->name) == ID_LS) { | ||||
| linestyle = (FreestyleLineStyle *)pinid; | linestyle = (FreestyleLineStyle *)pinid; | ||||
| } | } | ||||
| } | } | ||||
| if (!scene) { | if (!scene) { | ||||
| scene = CTX_data_scene(C); | scene = CTX_data_scene(C); | ||||
| } | } | ||||
| const ID_Type id_type = pinid != NULL ? GS(pinid->name) : -1; | const ID_Type id_type = ID_Type(pinid != nullptr ? GS(pinid->name) : -1); | ||||
| if (!pinid || id_type == ID_SCE) { | if (!pinid || id_type == ID_SCE) { | ||||
| wmWindow *win = CTX_wm_window(C); | wmWindow *win = CTX_wm_window(C); | ||||
| ViewLayer *view_layer = (win->scene == scene) ? WM_window_get_active_view_layer(win) : | ViewLayer *view_layer = (win->scene == scene) ? WM_window_get_active_view_layer(win) : | ||||
| BKE_view_layer_default_view(scene); | BKE_view_layer_default_view(scene); | ||||
| brush = BKE_paint_brush(BKE_paint_get_active_from_context(C)); | brush = BKE_paint_brush(BKE_paint_get_active_from_context(C)); | ||||
| linestyle = BKE_linestyle_active_from_view_layer(view_layer); | linestyle = BKE_linestyle_active_from_view_layer(view_layer); | ||||
| BKE_view_layer_synced_ensure(scene, view_layer); | BKE_view_layer_synced_ensure(scene, view_layer); | ||||
| ▲ Show 20 Lines • Show All 75 Lines • ▼ Show 20 Lines | buttons_texture_user_property_add( | ||||
| users, &brush->id, ptr, prop, N_("Brush"), ICON_BRUSH_DATA, IFACE_("Brush Mask")); | users, &brush->id, ptr, prop, N_("Brush"), ICON_BRUSH_DATA, IFACE_("Brush Mask")); | ||||
| } | } | ||||
| } | } | ||||
| void buttons_texture_context_compute(const bContext *C, SpaceProperties *sbuts) | void buttons_texture_context_compute(const bContext *C, SpaceProperties *sbuts) | ||||
| { | { | ||||
| /* gather available texture users in context. runs on every draw of | /* gather available texture users in context. runs on every draw of | ||||
| * properties editor, before the buttons are created. */ | * properties editor, before the buttons are created. */ | ||||
| ButsContextTexture *ct = sbuts->texuser; | ButsContextTexture *ct = static_cast<ButsContextTexture *>(sbuts->texuser); | ||||
| ID *pinid = sbuts->pinid; | ID *pinid = sbuts->pinid; | ||||
| if (!ct) { | if (!ct) { | ||||
| ct = MEM_callocN(sizeof(ButsContextTexture), "ButsContextTexture"); | ct = MEM_cnew<ButsContextTexture>("ButsContextTexture"); | ||||
| sbuts->texuser = ct; | sbuts->texuser = ct; | ||||
| } | } | ||||
| else { | else { | ||||
| BLI_freelistN(&ct->users); | BLI_freelistN(&ct->users); | ||||
| } | } | ||||
| buttons_texture_users_from_context(&ct->users, C, sbuts); | buttons_texture_users_from_context(&ct->users, C, sbuts); | ||||
| if (pinid && GS(pinid->name) == ID_TE) { | if (pinid && GS(pinid->name) == ID_TE) { | ||||
| ct->user = NULL; | ct->user = nullptr; | ||||
| ct->texture = (Tex *)pinid; | ct->texture = (Tex *)pinid; | ||||
| } | } | ||||
| else { | else { | ||||
| /* set one user as active based on active index */ | /* set one user as active based on active index */ | ||||
| if (ct->index >= BLI_listbase_count_at_most(&ct->users, ct->index + 1)) { | if (ct->index >= BLI_listbase_count_at_most(&ct->users, ct->index + 1)) { | ||||
| ct->index = 0; | ct->index = 0; | ||||
| } | } | ||||
| ct->user = BLI_findlink(&ct->users, ct->index); | ct->user = static_cast<ButsTextureUser *>(BLI_findlink(&ct->users, ct->index)); | ||||
| ct->texture = NULL; | ct->texture = nullptr; | ||||
| if (ct->user) { | if (ct->user) { | ||||
| if (ct->user->node != NULL) { | if (ct->user->node != nullptr) { | ||||
| /* Detect change of active texture node in same node tree, in that | /* Detect change of active texture node in same node tree, in that | ||||
| * case we also automatically switch to the other node. */ | * case we also automatically switch to the other node. */ | ||||
| if ((ct->user->node->flag & NODE_ACTIVE_TEXTURE) == 0) { | if ((ct->user->node->flag & NODE_ACTIVE_TEXTURE) == 0) { | ||||
| ButsTextureUser *user; | ButsTextureUser *user; | ||||
| for (user = ct->users.first; user; user = user->next) { | for (user = static_cast<ButsTextureUser *>(ct->users.first); user; user = user->next) { | ||||
| if (user->ntree == ct->user->ntree && user->node != ct->user->node) { | if (user->ntree == ct->user->ntree && user->node != ct->user->node) { | ||||
| if (user->node->flag & NODE_ACTIVE_TEXTURE) { | if (user->node->flag & NODE_ACTIVE_TEXTURE) { | ||||
| ct->user = user; | ct->user = user; | ||||
| ct->index = BLI_findindex(&ct->users, user); | ct->index = BLI_findindex(&ct->users, user); | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| if (ct->user->ptr.data) { | if (ct->user->ptr.data) { | ||||
| PointerRNA texptr; | PointerRNA texptr; | ||||
| Tex *tex; | Tex *tex; | ||||
| /* Get texture datablock pointer if it's a property. */ | /* Get texture datablock pointer if it's a property. */ | ||||
| texptr = RNA_property_pointer_get(&ct->user->ptr, ct->user->prop); | texptr = RNA_property_pointer_get(&ct->user->ptr, ct->user->prop); | ||||
| tex = RNA_struct_is_a(texptr.type, &RNA_Texture) ? texptr.data : NULL; | tex = RNA_struct_is_a(texptr.type, &RNA_Texture) ? static_cast<Tex *>(texptr.data) : | ||||
| nullptr; | |||||
| ct->texture = tex; | ct->texture = tex; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| static void template_texture_select(bContext *C, void *user_p, void *UNUSED(arg)) | static void template_texture_select(bContext *C, void *user_p, void *UNUSED(arg)) | ||||
| { | { | ||||
| /* callback when selecting a texture user in the menu */ | /* callback when selecting a texture user in the menu */ | ||||
| SpaceProperties *sbuts = find_space_properties(C); | SpaceProperties *sbuts = find_space_properties(C); | ||||
| ButsContextTexture *ct = (sbuts) ? sbuts->texuser : NULL; | ButsContextTexture *ct = (sbuts) ? static_cast<ButsContextTexture *>(sbuts->texuser) : nullptr; | ||||
| ButsTextureUser *user = (ButsTextureUser *)user_p; | ButsTextureUser *user = (ButsTextureUser *)user_p; | ||||
| PointerRNA texptr; | PointerRNA texptr; | ||||
| Tex *tex; | Tex *tex; | ||||
| if (!ct) { | if (!ct) { | ||||
| return; | return; | ||||
| } | } | ||||
| /* set user as active */ | /* set user as active */ | ||||
| if (user->node) { | if (user->node) { | ||||
| ED_node_set_active(CTX_data_main(C), NULL, user->ntree, user->node, NULL); | ED_node_set_active(CTX_data_main(C), nullptr, user->ntree, user->node, nullptr); | ||||
| ct->texture = NULL; | ct->texture = nullptr; | ||||
| /* Not totally sure if we should also change selection? */ | /* Not totally sure if we should also change selection? */ | ||||
| LISTBASE_FOREACH (bNode *, node, &user->ntree->nodes) { | LISTBASE_FOREACH (bNode *, node, &user->ntree->nodes) { | ||||
| nodeSetSelected(node, false); | nodeSetSelected(node, false); | ||||
| } | } | ||||
| nodeSetSelected(user->node, true); | nodeSetSelected(user->node, true); | ||||
| WM_event_add_notifier(C, NC_NODE | NA_SELECTED, NULL); | WM_event_add_notifier(C, NC_NODE | NA_SELECTED, nullptr); | ||||
| } | } | ||||
| if (user->ptr.data) { | if (user->ptr.data) { | ||||
| texptr = RNA_property_pointer_get(&user->ptr, user->prop); | texptr = RNA_property_pointer_get(&user->ptr, user->prop); | ||||
| tex = RNA_struct_is_a(texptr.type, &RNA_Texture) ? texptr.data : NULL; | tex = RNA_struct_is_a(texptr.type, &RNA_Texture) ? static_cast<Tex *>(texptr.data) : nullptr; | ||||
| ct->texture = tex; | ct->texture = tex; | ||||
| if (user->ptr.type == &RNA_ParticleSettingsTextureSlot) { | if (user->ptr.type == &RNA_ParticleSettingsTextureSlot) { | ||||
| /* stupid exception for particle systems which still uses influence | /* stupid exception for particle systems which still uses influence | ||||
| * from the old texture system, set the active texture slots as well */ | * from the old texture system, set the active texture slots as well */ | ||||
| ParticleSettings *part = (ParticleSettings *)user->ptr.owner_id; | ParticleSettings *part = (ParticleSettings *)user->ptr.owner_id; | ||||
| int a; | int a; | ||||
| Show All 13 Lines | static void template_texture_select(bContext *C, void *user_p, void *UNUSED(arg)) | ||||
| ct->user = user; | ct->user = user; | ||||
| ct->index = user->index; | ct->index = user->index; | ||||
| } | } | ||||
| static void template_texture_user_menu(bContext *C, uiLayout *layout, void *UNUSED(arg)) | static void template_texture_user_menu(bContext *C, uiLayout *layout, void *UNUSED(arg)) | ||||
| { | { | ||||
| /* callback when opening texture user selection menu, to create buttons. */ | /* callback when opening texture user selection menu, to create buttons. */ | ||||
| SpaceProperties *sbuts = CTX_wm_space_properties(C); | SpaceProperties *sbuts = CTX_wm_space_properties(C); | ||||
| ButsContextTexture *ct = sbuts->texuser; | ButsContextTexture *ct = static_cast<ButsContextTexture *>(sbuts->texuser); | ||||
| ButsTextureUser *user; | ButsTextureUser *user; | ||||
| uiBlock *block = uiLayoutGetBlock(layout); | uiBlock *block = uiLayoutGetBlock(layout); | ||||
| const char *last_category = NULL; | const char *last_category = nullptr; | ||||
| for (user = ct->users.first; user; user = user->next) { | for (user = static_cast<ButsTextureUser *>(ct->users.first); user; user = user->next) { | ||||
| uiBut *but; | uiBut *but; | ||||
| char name[UI_MAX_NAME_STR]; | char name[UI_MAX_NAME_STR]; | ||||
| /* add label per category */ | /* add label per category */ | ||||
| if (!last_category || !STREQ(last_category, user->category)) { | if (!last_category || !STREQ(last_category, user->category)) { | ||||
| uiItemL(layout, IFACE_(user->category), ICON_NONE); | uiItemL(layout, IFACE_(user->category), ICON_NONE); | ||||
| but = block->buttons.last; | but = static_cast<uiBut *>(block->buttons.last); | ||||
| but->drawflag = UI_BUT_TEXT_LEFT; | but->drawflag = UI_BUT_TEXT_LEFT; | ||||
| } | } | ||||
| /* create button */ | /* create button */ | ||||
| if (user->prop) { | if (user->prop) { | ||||
| PointerRNA texptr = RNA_property_pointer_get(&user->ptr, user->prop); | PointerRNA texptr = RNA_property_pointer_get(&user->ptr, user->prop); | ||||
| Tex *tex = texptr.data; | Tex *tex = static_cast<Tex *>(texptr.data); | ||||
| if (tex) { | if (tex) { | ||||
| BLI_snprintf(name, UI_MAX_NAME_STR, " %s - %s", user->name, tex->id.name + 2); | BLI_snprintf(name, UI_MAX_NAME_STR, " %s - %s", user->name, tex->id.name + 2); | ||||
| } | } | ||||
| else { | else { | ||||
| BLI_snprintf(name, UI_MAX_NAME_STR, " %s", user->name); | BLI_snprintf(name, UI_MAX_NAME_STR, " %s", user->name); | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| BLI_snprintf(name, UI_MAX_NAME_STR, " %s", user->name); | BLI_snprintf(name, UI_MAX_NAME_STR, " %s", user->name); | ||||
| } | } | ||||
| but = uiDefIconTextBut(block, | but = uiDefIconTextBut(block, | ||||
| UI_BTYPE_BUT, | UI_BTYPE_BUT, | ||||
| 0, | 0, | ||||
| user->icon, | user->icon, | ||||
| name, | name, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| UI_UNIT_X * 4, | UI_UNIT_X * 4, | ||||
| UI_UNIT_Y, | UI_UNIT_Y, | ||||
| NULL, | nullptr, | ||||
| 0.0, | 0.0, | ||||
| 0.0, | 0.0, | ||||
| 0.0, | 0.0, | ||||
| 0.0, | 0.0, | ||||
| ""); | ""); | ||||
| UI_but_funcN_set(but, template_texture_select, MEM_dupallocN(user), NULL); | UI_but_funcN_set(but, template_texture_select, MEM_dupallocN(user), nullptr); | ||||
| last_category = user->category; | last_category = user->category; | ||||
| } | } | ||||
| UI_block_flag_enable(block, UI_BLOCK_NO_FLIP); | UI_block_flag_enable(block, UI_BLOCK_NO_FLIP); | ||||
| } | } | ||||
| void uiTemplateTextureUser(uiLayout *layout, bContext *C) | void uiTemplateTextureUser(uiLayout *layout, bContext *C) | ||||
| { | { | ||||
| /* Texture user selection drop-down menu. the available users have been | /* Texture user selection drop-down menu. the available users have been | ||||
| * gathered before drawing in #ButsContextTexture, we merely need to | * gathered before drawing in #ButsContextTexture, we merely need to | ||||
| * display the current item. */ | * display the current item. */ | ||||
| SpaceProperties *sbuts = CTX_wm_space_properties(C); | SpaceProperties *sbuts = CTX_wm_space_properties(C); | ||||
| ButsContextTexture *ct = (sbuts) ? sbuts->texuser : NULL; | ButsContextTexture *ct = (sbuts) ? static_cast<ButsContextTexture *>(sbuts->texuser) : nullptr; | ||||
| uiBlock *block = uiLayoutGetBlock(layout); | uiBlock *block = uiLayoutGetBlock(layout); | ||||
| uiBut *but; | uiBut *but; | ||||
| ButsTextureUser *user; | ButsTextureUser *user; | ||||
| char name[UI_MAX_NAME_STR]; | char name[UI_MAX_NAME_STR]; | ||||
| if (!ct) { | if (!ct) { | ||||
| return; | return; | ||||
| } | } | ||||
| /* get current user */ | /* get current user */ | ||||
| user = ct->user; | user = ct->user; | ||||
| if (!user) { | if (!user) { | ||||
| uiItemL(layout, TIP_("No textures in context"), ICON_NONE); | uiItemL(layout, TIP_("No textures in context"), ICON_NONE); | ||||
| return; | return; | ||||
| } | } | ||||
| /* create button */ | /* create button */ | ||||
| BLI_strncpy(name, user->name, UI_MAX_NAME_STR); | BLI_strncpy(name, user->name, UI_MAX_NAME_STR); | ||||
| if (user->icon) { | if (user->icon) { | ||||
| but = uiDefIconTextMenuBut(block, | but = uiDefIconTextMenuBut(block, | ||||
| template_texture_user_menu, | template_texture_user_menu, | ||||
| NULL, | nullptr, | ||||
| user->icon, | user->icon, | ||||
| name, | name, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| UI_UNIT_X * 4, | UI_UNIT_X * 4, | ||||
| UI_UNIT_Y, | UI_UNIT_Y, | ||||
| ""); | ""); | ||||
| } | } | ||||
| else { | else { | ||||
| but = uiDefMenuBut( | but = uiDefMenuBut( | ||||
| block, template_texture_user_menu, NULL, name, 0, 0, UI_UNIT_X * 4, UI_UNIT_Y, ""); | block, template_texture_user_menu, nullptr, name, 0, 0, UI_UNIT_X * 4, UI_UNIT_Y, ""); | ||||
| } | } | ||||
| /* some cosmetic tweaks */ | /* some cosmetic tweaks */ | ||||
| UI_but_type_set_menu_from_pulldown(but); | UI_but_type_set_menu_from_pulldown(but); | ||||
| but->flag &= ~UI_BUT_ICON_SUBMENU; | but->flag &= ~UI_BUT_ICON_SUBMENU; | ||||
| } | } | ||||
| /************************* Texture Show **************************/ | /************************* Texture Show **************************/ | ||||
| static ScrArea *find_area_properties(const bContext *C) | static ScrArea *find_area_properties(const bContext *C) | ||||
| { | { | ||||
| bScreen *screen = CTX_wm_screen(C); | bScreen *screen = CTX_wm_screen(C); | ||||
| Object *ob = CTX_data_active_object(C); | Object *ob = CTX_data_active_object(C); | ||||
| LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) { | LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) { | ||||
| if (area->spacetype == SPACE_PROPERTIES) { | if (area->spacetype == SPACE_PROPERTIES) { | ||||
| /* Only if unpinned, or if pinned object matches. */ | /* Only if unpinned, or if pinned object matches. */ | ||||
| SpaceProperties *sbuts = area->spacedata.first; | SpaceProperties *sbuts = static_cast<SpaceProperties *>(area->spacedata.first); | ||||
| ID *pinid = sbuts->pinid; | ID *pinid = sbuts->pinid; | ||||
| if (pinid == NULL || ((GS(pinid->name) == ID_OB) && (Object *)pinid == ob)) { | if (pinid == nullptr || ((GS(pinid->name) == ID_OB) && (Object *)pinid == ob)) { | ||||
| return area; | return area; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| return NULL; | return nullptr; | ||||
| } | } | ||||
| static SpaceProperties *find_space_properties(const bContext *C) | static SpaceProperties *find_space_properties(const bContext *C) | ||||
| { | { | ||||
| ScrArea *area = find_area_properties(C); | ScrArea *area = find_area_properties(C); | ||||
| if (area != NULL) { | if (area != nullptr) { | ||||
| return area->spacedata.first; | return static_cast<SpaceProperties *>(area->spacedata.first); | ||||
| } | } | ||||
| return NULL; | return nullptr; | ||||
| } | } | ||||
| static void template_texture_show(bContext *C, void *data_p, void *prop_p) | static void template_texture_show(bContext *C, void *data_p, void *prop_p) | ||||
| { | { | ||||
| if (data_p == NULL || prop_p == NULL) { | if (data_p == nullptr || prop_p == nullptr) { | ||||
| return; | return; | ||||
| } | } | ||||
| ScrArea *area = find_area_properties(C); | ScrArea *area = find_area_properties(C); | ||||
| if (area == NULL) { | if (area == nullptr) { | ||||
| return; | return; | ||||
| } | } | ||||
| SpaceProperties *sbuts = (SpaceProperties *)area->spacedata.first; | SpaceProperties *sbuts = (SpaceProperties *)area->spacedata.first; | ||||
| ButsContextTexture *ct = (sbuts) ? sbuts->texuser : NULL; | ButsContextTexture *ct = (sbuts) ? static_cast<ButsContextTexture *>(sbuts->texuser) : nullptr; | ||||
| if (!ct) { | if (!ct) { | ||||
| return; | return; | ||||
| } | } | ||||
| ButsTextureUser *user; | ButsTextureUser *user; | ||||
| for (user = ct->users.first; user; user = user->next) { | for (user = static_cast<ButsTextureUser *>(ct->users.first); user; user = user->next) { | ||||
| if (user->ptr.data == data_p && user->prop == prop_p) { | if (user->ptr.data == data_p && user->prop == prop_p) { | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| if (user) { | if (user) { | ||||
| /* select texture */ | /* select texture */ | ||||
| template_texture_select(C, user, NULL); | template_texture_select(C, user, nullptr); | ||||
| /* change context */ | /* change context */ | ||||
| sbuts->mainb = BCONTEXT_TEXTURE; | sbuts->mainb = BCONTEXT_TEXTURE; | ||||
| sbuts->mainbuser = sbuts->mainb; | sbuts->mainbuser = sbuts->mainb; | ||||
| sbuts->preview = 1; | sbuts->preview = 1; | ||||
| /* redraw editor */ | /* redraw editor */ | ||||
| ED_area_tag_redraw(area); | ED_area_tag_redraw(area); | ||||
| } | } | ||||
| } | } | ||||
| void uiTemplateTextureShow(uiLayout *layout, const bContext *C, PointerRNA *ptr, PropertyRNA *prop) | void uiTemplateTextureShow(uiLayout *layout, const bContext *C, PointerRNA *ptr, PropertyRNA *prop) | ||||
| { | { | ||||
| /* Only show the button if there is actually a texture assigned. */ | /* Only show the button if there is actually a texture assigned. */ | ||||
| Tex *texture = RNA_property_pointer_get(ptr, prop).data; | Tex *texture = static_cast<Tex *>(RNA_property_pointer_get(ptr, prop).data); | ||||
| if (texture == NULL) { | if (texture == nullptr) { | ||||
| return; | return; | ||||
| } | } | ||||
| /* Only show the button if we are not in the Properties Editor's texture tab. */ | /* Only show the button if we are not in the Properties Editor's texture tab. */ | ||||
| SpaceProperties *sbuts_context = CTX_wm_space_properties(C); | SpaceProperties *sbuts_context = CTX_wm_space_properties(C); | ||||
| if (sbuts_context != NULL && sbuts_context->mainb == BCONTEXT_TEXTURE) { | if (sbuts_context != nullptr && sbuts_context->mainb == BCONTEXT_TEXTURE) { | ||||
| return; | return; | ||||
| } | } | ||||
| SpaceProperties *sbuts = find_space_properties(C); | SpaceProperties *sbuts = find_space_properties(C); | ||||
| ButsContextTexture *ct = (sbuts) ? sbuts->texuser : NULL; | ButsContextTexture *ct = (sbuts) ? static_cast<ButsContextTexture *>(sbuts->texuser) : nullptr; | ||||
| /* find corresponding texture user */ | /* find corresponding texture user */ | ||||
| ButsTextureUser *user; | ButsTextureUser *user; | ||||
| bool user_found = false; | bool user_found = false; | ||||
| if (ct != NULL) { | if (ct != nullptr) { | ||||
| for (user = ct->users.first; user; user = user->next) { | for (user = static_cast<ButsTextureUser *>(ct->users.first); user; user = user->next) { | ||||
| if (user->ptr.data == ptr->data && user->prop == prop) { | if (user->ptr.data == ptr->data && user->prop == prop) { | ||||
| user_found = true; | user_found = true; | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| /* Draw button (disabled if we cannot find a Properties Editor to display this in). */ | /* Draw button (disabled if we cannot find a Properties Editor to display this in). */ | ||||
| uiBlock *block = uiLayoutGetBlock(layout); | uiBlock *block = uiLayoutGetBlock(layout); | ||||
| uiBut *but; | uiBut *but; | ||||
| but = uiDefIconBut(block, | but = uiDefIconBut(block, | ||||
| UI_BTYPE_BUT, | UI_BTYPE_BUT, | ||||
| 0, | 0, | ||||
| ICON_PROPERTIES, | ICON_PROPERTIES, | ||||
| 0, | 0, | ||||
| 0, | 0, | ||||
| UI_UNIT_X, | UI_UNIT_X, | ||||
| UI_UNIT_Y, | UI_UNIT_Y, | ||||
| NULL, | nullptr, | ||||
| 0.0, | 0.0, | ||||
| 0.0, | 0.0, | ||||
| 0.0, | 0.0, | ||||
| 0.0, | 0.0, | ||||
| TIP_("Show texture in texture tab")); | TIP_("Show texture in texture tab")); | ||||
| UI_but_func_set(but, | UI_but_func_set(but, | ||||
| template_texture_show, | template_texture_show, | ||||
| user_found ? user->ptr.data : NULL, | user_found ? user->ptr.data : nullptr, | ||||
| user_found ? user->prop : NULL); | user_found ? user->prop : nullptr); | ||||
| if (ct == NULL) { | if (ct == nullptr) { | ||||
| UI_but_disable(but, TIP_("No (unpinned) Properties Editor found to display texture in")); | UI_but_disable(but, TIP_("No (unpinned) Properties Editor found to display texture in")); | ||||
| } | } | ||||
| else if (!user_found) { | else if (!user_found) { | ||||
| UI_but_disable(but, TIP_("No texture user found")); | UI_but_disable(but, TIP_("No texture user found")); | ||||
| } | } | ||||
| } | } | ||||