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); UI_block_layout_set_current(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, UI_BTYPE_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, UI_BTYPE_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]; UI_but_funcN_set(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); } } } }