Beispiel #1
0
static void node_sockets_panel(const bContext *C, Panel *pa)
{
	SpaceNode *snode= CTX_wm_space_node(C);
	bNodeTree *ntree= (snode) ? snode->edittree : NULL;
	bNode *node = (ntree) ? nodeGetActive(ntree) : NULL;
	bNodeSocket *sock;
	uiLayout *layout= pa->layout, *split;
	char name[UI_MAX_NAME_STR];
	
	if(ELEM(NULL, ntree, node))
		return;
	
	for(sock=node->inputs.first; sock; sock=sock->next) {
		BLI_snprintf(name, sizeof(name), "%s:", sock->name);

		split = uiLayoutSplit(layout, 0.35f, 0);
		uiItemL(split, name, ICON_NONE);
		uiTemplateNodeLink(split, ntree, node, sock);
	}
}
static void ui_node_draw_input(uiLayout *layout, bContext *C, bNodeTree *ntree, bNode *node, bNodeSocket *input, int depth)
{
	PointerRNA inputptr, nodeptr;
	uiBlock *block = uiLayoutGetBlock(layout);
	uiBut *bt;
	uiLayout *split, *row, *col;
	bNode *lnode;
	char label[UI_MAX_NAME_STR];
	int indent = (depth > 1) ? 2 * (depth - 1) : 0;
	int dependency_loop;

	if (input->flag & SOCK_UNAVAIL)
		return;

	/* to avoid eternal loops on cyclic dependencies */
	node->flag |= NODE_TEST;
	lnode = (input->link) ? input->link->fromnode : NULL;

	dependency_loop = (lnode && (lnode->flag & NODE_TEST));
	if (dependency_loop)
		lnode = NULL;

	/* socket RNA pointer */
	RNA_pointer_create(&ntree->id, &RNA_NodeSocket, input, &inputptr);
	RNA_pointer_create(&ntree->id, &RNA_Node, node, &nodeptr);

	/* indented label */
	memset(label, ' ', indent);
	label[indent] = '\0';
	BLI_snprintf(label, UI_MAX_NAME_STR, "%s%s:", label, IFACE_(input->name));

	/* split in label and value */
	split = uiLayoutSplit(layout, 0.35f, false);

	row = uiLayoutRow(split, true);

	if (depth > 0) {
		UI_block_emboss_set(block, UI_EMBOSS_NONE);

		if (lnode && (lnode->inputs.first || (lnode->typeinfo->draw_buttons && lnode->type != NODE_GROUP))) {
			int icon = (input->flag & SOCK_COLLAPSED) ? ICON_DISCLOSURE_TRI_RIGHT : ICON_DISCLOSURE_TRI_DOWN;
			uiItemR(row, &inputptr, "show_expanded", UI_ITEM_R_ICON_ONLY, "", icon);
		}
		else
			uiItemL(row, "", ICON_BLANK1);

		bt = block->buttons.last;
		bt->rect.xmax = UI_UNIT_X / 2;

		UI_block_emboss_set(block, UI_EMBOSS);
	}

	uiItemL(row, label, ICON_NONE);
	bt = block->buttons.last;
	bt->drawflag = UI_BUT_TEXT_LEFT;

	if (dependency_loop) {
		row = uiLayoutRow(split, false);
		uiItemL(row, IFACE_("Dependency Loop"), ICON_ERROR);
	}
	else if (lnode) {
		/* input linked to a node */
		uiTemplateNodeLink(split, ntree, node, input);

		if (depth == 0 || !(input->flag & SOCK_COLLAPSED)) {
			if (depth == 0)
				uiItemS(layout);

			ui_node_draw_node(layout, C, ntree, lnode, depth);
		}
	}
	else {
		/* input not linked, show value */
		if (!(input->flag & SOCK_HIDE_VALUE)) {
			switch (input->type) {
				case SOCK_FLOAT:
				case SOCK_INT:
				case SOCK_BOOLEAN:
				case SOCK_RGBA:
				case SOCK_STRING:
					row = uiLayoutRow(split, true);
					uiItemR(row, &inputptr, "default_value", 0, "", ICON_NONE);
					break;
				case SOCK_VECTOR:
					row = uiLayoutRow(split, false);
					col = uiLayoutColumn(row, false);
					uiItemR(col, &inputptr, "default_value", 0, "", ICON_NONE);
					break;
					
				default:
					row = uiLayoutRow(split, false);
					break;
			}
		}
		else
			row = uiLayoutRow(split, false);

		uiTemplateNodeLink(row, ntree, node, input);
	}

	/* clear */
	node->flag &= ~NODE_TEST;
}