static void ui_imageuser_layer_menu(bContext *UNUSED(C), uiLayout *layout, void *rnd_pt) { void **rnd_data = rnd_pt; uiBlock *block = uiLayoutGetBlock(layout); RenderResult *rr = rnd_data[0]; ImageUser *iuser = rnd_data[1]; RenderLayer *rl; RenderLayer rl_fake = {NULL}; const char *fake_name; int nr; uiBlockSetCurLayout(block, layout); uiLayoutColumn(layout, false); uiDefBut(block, LABEL, 0, IFACE_("Layer"), 0, 0, UI_UNIT_X * 5, UI_UNIT_Y, NULL, 0.0, 0.0, 0, 0, ""); uiItemS(layout); nr = BLI_countlist(&rr->layers) - 1; fake_name = ui_imageuser_layer_fake_name(rr); if (fake_name) { BLI_strncpy(rl_fake.name, fake_name, sizeof(rl_fake.name)); nr += 1; } for (rl = rr->layers.last; rl; rl = rl->prev, nr--) { final: uiDefButS(block, BUTM, B_NOP, IFACE_(rl->name), 0, 0, UI_UNIT_X * 5, UI_UNIT_X, &iuser->layer, (float) nr, 0.0, 0, -1, ""); }
void uiTemplateNodeLink(uiLayout *layout, bNodeTree *ntree, bNode *node, bNodeSocket *sock) { uiBlock *block = uiLayoutGetBlock(layout); NodeLinkArg *arg; uiBut *but; arg = MEM_callocN(sizeof(NodeLinkArg), "NodeLinkArg"); arg->ntree = ntree; arg->node = node; arg->sock = sock; uiBlockSetCurLayout(block, layout); if (sock->link || sock->type == SOCK_SHADER || (sock->flag & SOCK_HIDE_VALUE)) { char name[UI_MAX_NAME_STR]; ui_node_sock_name(sock, name); but = uiDefMenuBut(block, ui_template_node_link_menu, NULL, name, 0, 0, UI_UNIT_X * 4, UI_UNIT_Y, ""); } else but = uiDefIconMenuBut(block, ui_template_node_link_menu, NULL, ICON_NONE, 0, 0, UI_UNIT_X, UI_UNIT_Y, ""); uiButSetMenuFromPulldown(but); but->flag |= UI_BUT_NODE_LINK; but->poin = (char *)but; but->func_argN = arg; if (sock->link && sock->link->fromnode) if (sock->link->fromnode->flag & NODE_ACTIVE_TEXTURE) but->flag |= UI_BUT_NODE_ACTIVE; }
static void ui_template_node_link_menu(bContext *C, uiLayout *layout, void *but_p) { Main *bmain = CTX_data_main(C); Scene *scene = CTX_data_scene(C); uiBlock *block = uiLayoutGetBlock(layout); uiBut *but = (uiBut *)but_p; uiLayout *split, *column; NodeLinkArg *arg = (NodeLinkArg *)but->func_argN; bNodeSocket *sock = arg->sock; bNodeTreeType *ntreetype = arg->ntree->typeinfo; uiBlockSetFlag(block, UI_BLOCK_NO_FLIP); uiBlockSetCurLayout(block, layout); split = uiLayoutSplit(layout, 0.0f, false); arg->bmain = bmain; arg->scene = scene; arg->layout = split; if (ntreetype && ntreetype->foreach_nodeclass) ntreetype->foreach_nodeclass(scene, arg, node_menu_column_foreach_cb); column = uiLayoutColumn(split, false); uiBlockSetCurLayout(block, column); if (sock->link) { uiItemL(column, IFACE_("Link"), ICON_NONE); but = block->buttons.last; but->drawflag = UI_BUT_TEXT_LEFT; but = uiDefBut(block, BUT, 0, IFACE_("Remove"), 0, 0, UI_UNIT_X * 4, UI_UNIT_Y, NULL, 0.0, 0.0, 0.0, 0.0, TIP_("Remove nodes connected to the input")); uiButSetNFunc(but, ui_node_link, MEM_dupallocN(arg), SET_INT_IN_POINTER(UI_NODE_LINK_REMOVE)); but = uiDefBut(block, BUT, 0, IFACE_("Disconnect"), 0, 0, UI_UNIT_X * 4, UI_UNIT_Y, NULL, 0.0, 0.0, 0.0, 0.0, TIP_("Disconnect nodes connected to the input")); uiButSetNFunc(but, ui_node_link, MEM_dupallocN(arg), SET_INT_IN_POINTER(UI_NODE_LINK_DISCONNECT)); } ui_node_menu_column(arg, NODE_CLASS_GROUP, N_("Group")); }
static void ui_node_menu_column(NodeLinkArg *arg, int nclass, const char *cname) { bNodeTree *ntree = arg->ntree; bNodeSocket *sock = arg->sock; uiLayout *layout = arg->layout; uiLayout *column = NULL; uiBlock *block = uiLayoutGetBlock(layout); uiBut *but; NodeLinkArg *argN; int first = 1; int compatibility = 0; if (ntree->type == NTREE_SHADER) { if (BKE_scene_use_new_shading_nodes(arg->scene)) compatibility = NODE_NEW_SHADING; else compatibility = NODE_OLD_SHADING; } NODE_TYPES_BEGIN(ntype) { NodeLinkItem *items; int totitems; char name[UI_MAX_NAME_STR]; const char *cur_node_name = NULL; int i, num = 0; int icon = ICON_NONE; if (compatibility && !(ntype->compatibility & compatibility)) continue; if (ntype->nclass != nclass) continue; arg->node_type = ntype; ui_node_link_items(arg, SOCK_OUT, &items, &totitems); for (i = 0; i < totitems; ++i) if (ui_compatible_sockets(items[i].socket_type, sock->type)) num++; for (i = 0; i < totitems; ++i) { if (!ui_compatible_sockets(items[i].socket_type, sock->type)) continue; if (first) { column = uiLayoutColumn(layout, 0); uiBlockSetCurLayout(block, column); uiItemL(column, IFACE_(cname), ICON_NODE); but = block->buttons.last; first = 0; } if (num > 1) { if (!cur_node_name || !STREQ(cur_node_name, items[i].node_name)) { cur_node_name = items[i].node_name; /* XXX Do not use uiItemL here, it would add an empty icon as we are in a menu! */ uiDefBut(block, LABEL, 0, IFACE_(cur_node_name), 0, 0, UI_UNIT_X * 4, UI_UNIT_Y, NULL, 0.0, 0.0, 0.0, 0.0, ""); } BLI_snprintf(name, UI_MAX_NAME_STR, "%s", IFACE_(items[i].socket_name)); icon = ICON_BLANK1; } else { BLI_strncpy(name, IFACE_(items[i].node_name), UI_MAX_NAME_STR); icon = ICON_NONE; } but = uiDefIconTextBut(block, BUT, 0, icon, name, 0, 0, UI_UNIT_X * 4, UI_UNIT_Y, NULL, 0.0, 0.0, 0.0, 0.0, TIP_("Add node to input")); argN = MEM_dupallocN(arg); argN->item = items[i]; uiButSetNFunc(but, ui_node_link, argN, NULL); } if (items) MEM_freeN(items); } NODE_TYPES_END }
static void ui_node_menu_column(NodeLinkArg *arg, int nclass, const char *cname) { Main *bmain = arg->bmain; bNodeTree *ntree = arg->ntree; bNodeSocket *sock = arg->sock; uiLayout *layout = arg->layout; uiLayout *column = NULL; uiBlock *block = uiLayoutGetBlock(layout); uiBut *but; bNodeType *ntype; bNodeTree *ngroup; NodeLinkArg *argN; int first = 1; int compatibility= 0; if (ntree->type == NTREE_SHADER) { if (BKE_scene_use_new_shading_nodes(arg->scene)) compatibility= NODE_NEW_SHADING; else compatibility= NODE_OLD_SHADING; } if (nclass == NODE_CLASS_GROUP) { for (ngroup=bmain->nodetree.first; ngroup; ngroup=ngroup->id.next) { bNodeSocket *gsock; char name[UI_MAX_NAME_STR]; int i, j, num = 0; if (ngroup->type != ntree->type) continue; for (gsock=ngroup->inputs.first; gsock; gsock=gsock->next) if (ui_compatible_sockets(gsock->type, sock->type)) num++; for (i=0, j=0, gsock=ngroup->outputs.first; gsock; gsock=gsock->next, i++) { if (!ui_compatible_sockets(gsock->type, sock->type)) continue; if (first) { column= uiLayoutColumn(layout, 0); uiBlockSetCurLayout(block, column); uiItemL(column, cname, ICON_NODE); but= block->buttons.last; but->flag= UI_TEXT_LEFT; first = 0; } if (num > 1) { if (j == 0) { uiItemL(column, ngroup->id.name+2, ICON_NODE); but= block->buttons.last; but->flag= UI_TEXT_LEFT; } BLI_snprintf(name, UI_MAX_NAME_STR, " %s", gsock->name); j++; } else BLI_strncpy(name, ngroup->id.name+2, UI_MAX_NAME_STR); but = uiDefBut(block, BUT, 0, ngroup->id.name+2, 0, 0, UI_UNIT_X*4, UI_UNIT_Y, NULL, 0.0, 0.0, 0.0, 0.0, "Add node to input"); argN = MEM_dupallocN(arg); argN->type = NODE_GROUP; argN->ngroup = ngroup; argN->output = i; uiButSetNFunc(but, ui_node_link, argN, NULL); } } } else { bNodeTreeType *ttype= ntreeGetType(ntree->type); for (ntype=ttype->node_types.first; ntype; ntype=ntype->next) { bNodeSocketTemplate *stemp; char name[UI_MAX_NAME_STR]; int i, j, num = 0; if (compatibility && !(ntype->compatibility & compatibility)) continue; if (ntype->nclass != nclass) continue; for (i=0, stemp=ntype->outputs; stemp && stemp->type != -1; stemp++, i++) if (ui_compatible_sockets(stemp->type, sock->type)) num++; for (i=0, j=0, stemp=ntype->outputs; stemp && stemp->type != -1; stemp++, i++) { if (!ui_compatible_sockets(stemp->type, sock->type)) continue; if (first) { column= uiLayoutColumn(layout, 0); uiBlockSetCurLayout(block, column); uiItemL(column, cname, ICON_NODE); but= block->buttons.last; but->flag= UI_TEXT_LEFT; first = 0; } if (num > 1) { if (j == 0) { uiItemL(column, ntype->name, ICON_NODE); but= block->buttons.last; but->flag= UI_TEXT_LEFT; } BLI_snprintf(name, UI_MAX_NAME_STR, " %s", stemp->name); j++; } else BLI_strncpy(name, ntype->name, UI_MAX_NAME_STR); but = uiDefBut(block, BUT, 0, name, 0, 0, UI_UNIT_X*4, UI_UNIT_Y, NULL, 0.0, 0.0, 0.0, 0.0, "Add node to input"); argN = MEM_dupallocN(arg); argN->type = ntype->type; argN->output = i; uiButSetNFunc(but, ui_node_link, argN, NULL); } } } }