[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [59599] branches/hive/source/blender: Applied patch https://codereview.appspot.com/12437043/: customizing the order of socket display in Node Editor nodes

Sjoerd de Vries sjdv1982 at gmail.com
Wed Aug 28 13:35:25 CEST 2013


Revision: 59599
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=59599
Author:   sjoerddevries
Date:     2013-08-28 11:35:25 +0000 (Wed, 28 Aug 2013)
Log Message:
-----------
Applied patch https://codereview.appspot.com/12437043/: customizing the order of socket display in Node Editor nodes

Modified Paths:
--------------
    branches/hive/source/blender/editors/space_node/node_draw.c
    branches/hive/source/blender/makesdna/DNA_node_types.h
    branches/hive/source/blender/makesrna/intern/rna_nodetree.c

Modified: branches/hive/source/blender/editors/space_node/node_draw.c
===================================================================
--- branches/hive/source/blender/editors/space_node/node_draw.c	2013-08-28 11:26:13 UTC (rev 59598)
+++ branches/hive/source/blender/editors/space_node/node_draw.c	2013-08-28 11:35:25 UTC (rev 59599)
@@ -310,18 +310,98 @@
 	nodeFromView(node, x, y, rx, ry);
 }
 
+inline void nodesocket_update(const bContext *C, bNodeTree *ntree, bNode *node, PointerRNA nodeptr, bNodeSocket *nsock,
+		float locx, bool is_output, float *p_dy)
+{
+	uiLayout *layout, *row;
+	PointerRNA sockptr;
+	int buty;
+	float dy_old = *p_dy;
 
+    if (nodeSocketIsHidden(nsock))
+            return;
+
+    RNA_pointer_create(&ntree->id, &RNA_NodeSocket, nsock, &sockptr);
+
+    layout = uiBlockLayout(node->block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL,
+                           locx + NODE_DYS, *p_dy, NODE_WIDTH(node) - NODE_DY, NODE_DY, UI_GetStyle());
+    /* context pointers for current node and socket */
+    uiLayoutSetContextPointer(layout, "node", &nodeptr);
+    uiLayoutSetContextPointer(layout, "socket", &sockptr);
+
+    if (is_output) {
+        /* align output buttons to the right */
+        row = uiLayoutRow(layout, 1);
+        uiLayoutSetAlignment(row, UI_LAYOUT_ALIGN_RIGHT);
+
+        node->typeinfo->drawoutputfunc((bContext *)C, row, &sockptr, &nodeptr);
+    }
+    else {
+    	node->typeinfo->drawinputfunc((bContext *)C, layout, &sockptr, &nodeptr);
+    }
+
+    uiBlockEndAlign(node->block);
+    uiBlockLayoutResolve(node->block, NULL, &buty);
+
+    /* ensure minimum socket height in case layout is empty */
+    buty = min_ii(buty, *p_dy - NODE_DY);
+
+    if (is_output) {
+    	nsock->locx = locx + NODE_WIDTH(node);
+    }
+    else {
+    	nsock->locx = locx;
+    }
+    /* place the socket circle in the middle of the layout */
+    nsock->locy = 0.5f * (*p_dy + buty);
+
+    *p_dy = buty;
+
+    if (nsock->next)
+    	*p_dy -= NODE_SOCKDY;
+
+/* XXX Staying on the same row will only work if the "generic socket" patch is applied as well
+ * This #ifdef is so that the current patch can be tested independently
+ * Remove this #ifdef magic after that patch has been accepted, making the following code unconditional
+*/
+#ifdef NODETYPE_SOCKETS_GENERIC
+    /* if the node uses generic sockets, and the socket has shared row enabled, undo the row increment */
+    if ((node->typeinfo->flag & NODETYPE_SOCKETS_GENERIC) && (nsock->typeinfo->flag & SOCKTYPE_SHARED_ROW))
+    	*p_dy = dy_old;
+#endif
+}
+
+inline void node_get_socketrow_range(bNode *node, short *p_min_socketrow, short *p_max_socketrow) {
+	bNodeSocket *nsock;
+	*p_min_socketrow = 0;
+	*p_max_socketrow = 0;
+
+	/* Determine minimum and maximum socket row */
+	for (nsock = node->outputs.first; nsock; nsock = nsock->next) {
+		BLI_assert(nsock->row >= -127 && nsock->row < 128);
+		if (nsock->row < *p_min_socketrow) *p_min_socketrow = nsock->row;
+		if (nsock->row > *p_max_socketrow) *p_max_socketrow = nsock->row;
+	}
+	for (nsock = node->inputs.first; nsock; nsock = nsock->next) {
+		BLI_assert(nsock->row >= -127 && nsock->row < 128);
+		if (nsock->row < *p_min_socketrow) *p_min_socketrow = nsock->row;
+		if (nsock->row > *p_max_socketrow) *p_max_socketrow = nsock->row;
+	}
+}
+
 /* based on settings in node, sets drawing rect info. each redraw! */
 static void node_update_basis(const bContext *C, bNodeTree *ntree, bNode *node)
 {
-	uiLayout *layout, *row;
-	PointerRNA nodeptr, sockptr;
+	uiLayout *layout;
+	PointerRNA nodeptr;
 	bNodeSocket *nsock;
 	float locx, locy;
 	float dy;
 	int buty;
-	
+	short socketrow, min_socketrow, max_socketrow;
+
 	RNA_pointer_create(&ntree->id, &RNA_Node, node, &nodeptr);
+	node_get_socketrow_range(node, &min_socketrow, &max_socketrow);
 	
 	/* get "global" coords */
 	node_to_view(node, 0.0f, 0.0f, &locx, &locy);
@@ -333,39 +413,22 @@
 	/* little bit space in top */
 	if (node->outputs.first)
 		dy -= NODE_DYS / 2;
+
+	/* 1. Drawing output and input sockets with row < 0, in order */
+	for (socketrow = min_socketrow; socketrow < 0; socketrow++) {
+		for (nsock = node->outputs.first; nsock; nsock = nsock->next) {
+			if (nsock->row == socketrow) nodesocket_update(C, ntree, node, nodeptr, nsock, locx, 1, &dy);
+		}
+		for (nsock = node->inputs.first; nsock; nsock = nsock->next) {
+			if (nsock->row == socketrow) nodesocket_update(C, ntree, node, nodeptr, nsock, locx, 0, &dy);
+		}
+	}
 	
+	/* 2. Standard drawing: outputs with row == 0, preview rect, buttons rect, and inputs with row == 0 */
+
 	/* output sockets */
 	for (nsock = node->outputs.first; nsock; nsock = nsock->next) {
-		if (nodeSocketIsHidden(nsock))
-			continue;
-		
-		RNA_pointer_create(&ntree->id, &RNA_NodeSocket, nsock, &sockptr);
-		
-		layout = uiBlockLayout(node->block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL,
-		                       locx + NODE_DYS, dy, NODE_WIDTH(node) - NODE_DY, NODE_DY, UI_GetStyle());
-		/* context pointers for current node and socket */
-		uiLayoutSetContextPointer(layout, "node", &nodeptr);
-		uiLayoutSetContextPointer(layout, "socket", &sockptr);
-		
-		/* align output buttons to the right */
-		row = uiLayoutRow(layout, 1);
-		uiLayoutSetAlignment(row, UI_LAYOUT_ALIGN_RIGHT);
-		
-		node->typeinfo->drawoutputfunc((bContext *)C, row, &sockptr, &nodeptr);
-		
-		uiBlockEndAlign(node->block);
-		uiBlockLayoutResolve(node->block, NULL, &buty);
-		
-		/* ensure minimum socket height in case layout is empty */
-		buty = min_ii(buty, dy - NODE_DY);
-		
-		nsock->locx = locx + NODE_WIDTH(node);
-		/* place the socket circle in the middle of the layout */
-		nsock->locy = 0.5f * (dy + buty);
-		
-		dy = buty;
-		if (nsock->next)
-			dy -= NODE_SOCKDY;
+		if (!nsock->row) nodesocket_update(C, ntree, node, nodeptr, nsock, locx, 1, &dy);
 	}
 
 	node->prvr.xmin = locx + NODE_DYS;
@@ -426,34 +489,19 @@
 
 	/* input sockets */
 	for (nsock = node->inputs.first; nsock; nsock = nsock->next) {
-		if (nodeSocketIsHidden(nsock))
-			continue;
-		
-		RNA_pointer_create(&ntree->id, &RNA_NodeSocket, nsock, &sockptr);
-		
-		layout = uiBlockLayout(node->block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL,
-		                       locx + NODE_DYS, dy, NODE_WIDTH(node) - NODE_DY, NODE_DY, UI_GetStyle());
-		/* context pointers for current node and socket */
-		uiLayoutSetContextPointer(layout, "node", &nodeptr);
-		uiLayoutSetContextPointer(layout, "socket", &sockptr);
-		
-		node->typeinfo->drawinputfunc((bContext *)C, layout, &sockptr, &nodeptr);
-		
-		uiBlockEndAlign(node->block);
-		uiBlockLayoutResolve(node->block, NULL, &buty);
-		
-		/* ensure minimum socket height in case layout is empty */
-		buty = min_ii(buty, dy - NODE_DY);
-		
-		nsock->locx = locx;
-		/* place the socket circle in the middle of the layout */
-		nsock->locy = 0.5f * (dy + buty);
-		
-		dy = buty;
-		if (nsock->next)
-			dy -= NODE_SOCKDY;
+		if (!nsock->row) nodesocket_update(C, ntree, node, nodeptr, nsock, locx, 0, &dy);
 	}
-	
+
+	/* 3. Adding output and input sockets with row > 0, in order */
+	for (socketrow = 1; socketrow <= max_socketrow; socketrow++) {
+		for (nsock = node->outputs.first; nsock; nsock = nsock->next) {
+			if (nsock->row == socketrow) nodesocket_update(C, ntree, node, nodeptr, nsock, locx, 1, &dy);
+		}
+		for (nsock = node->inputs.first; nsock; nsock = nsock->next) {
+			if (nsock->row == socketrow) nodesocket_update(C, ntree, node, nodeptr, nsock, locx, 0, &dy);
+		}
+	}
+
 	/* little bit space in end */
 	if (node->inputs.first || (node->flag & (NODE_OPTIONS | NODE_PREVIEW)) == 0)
 		dy -= NODE_DYS / 2;
@@ -480,6 +528,9 @@
 	float locx, locy;
 	float rad, drad, hiddenrad = HIDDEN_RAD;
 	int totin = 0, totout = 0, tot;
+	short socketrow, min_socketrow, max_socketrow;
+
+	node_get_socketrow_range(node, &min_socketrow, &max_socketrow);
 	
 	/* get "global" coords */
 	node_to_view(node, 0.0f, 0.0f, &locx, &locy);
@@ -501,26 +552,31 @@
 	node->totr.xmax = locx + 3 * hiddenrad + node->miniwidth;
 	node->totr.ymax = locy + (hiddenrad - 0.5f * NODE_DY);
 	node->totr.ymin = node->totr.ymax - 2 * hiddenrad;
-	
+
 	/* output sockets */
 	rad = drad = (float)M_PI / (1.0f + (float)totout);
 	
-	for (nsock = node->outputs.first; nsock; nsock = nsock->next) {
-		if (!nodeSocketIsHidden(nsock)) {
-			nsock->locx = node->totr.xmax - hiddenrad + sinf(rad) * hiddenrad;
-			nsock->locy = node->totr.ymin + hiddenrad + cosf(rad) * hiddenrad;
-			rad += drad;
+	for (socketrow = min_socketrow; socketrow <= max_socketrow; socketrow++) {
+		for (nsock = node->outputs.first; nsock; nsock = nsock->next) {
+			if (!nodeSocketIsHidden(nsock) && nsock->row == socketrow) {
+				nsock->locx = node->totr.xmax - hiddenrad + sinf(rad) * hiddenrad;
+				nsock->locy = node->totr.ymin + hiddenrad + cosf(rad) * hiddenrad;
+				rad += drad;
+			}
 		}
 	}
+
 	
 	/* input sockets */
 	rad = drad = -(float)M_PI / (1.0f + (float)totin);
 	
-	for (nsock = node->inputs.first; nsock; nsock = nsock->next) {
-		if (!nodeSocketIsHidden(nsock)) {
-			nsock->locx = node->totr.xmin + hiddenrad + sinf(rad) * hiddenrad;
-			nsock->locy = node->totr.ymin + hiddenrad + cosf(rad) * hiddenrad;
-			rad += drad;
+	for (socketrow = min_socketrow; socketrow <= max_socketrow; socketrow++) {
+		for (nsock = node->inputs.first; nsock; nsock = nsock->next) {
+			if (!nodeSocketIsHidden(nsock) && nsock->row == socketrow) {
+				nsock->locx = node->totr.xmin + hiddenrad + sinf(rad) * hiddenrad;
+				nsock->locy = node->totr.ymin + hiddenrad + cosf(rad) * hiddenrad;
+				rad += drad;
+			}
 		}
 	}
 

Modified: branches/hive/source/blender/makesdna/DNA_node_types.h
===================================================================
--- branches/hive/source/blender/makesdna/DNA_node_types.h	2013-08-28 11:26:13 UTC (rev 59598)
+++ branches/hive/source/blender/makesdna/DNA_node_types.h	2013-08-28 11:35:25 UTC (rev 59599)
@@ -105,6 +105,8 @@
 	char idname[64];			/* runtime type identifier */
 	
 	float locx, locy;
+	short row; char pad[6];		/* which socket row does the socket belong to:
+	 	 	 	 	 	 	 	 				default = 0, many sockets can be on the same row  */
 	
 	void *default_value;		/* default input value used for unlinked sockets */
 	

Modified: branches/hive/source/blender/makesrna/intern/rna_nodetree.c
===================================================================
--- branches/hive/source/blender/makesrna/intern/rna_nodetree.c	2013-08-28 11:26:13 UTC (rev 59598)

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list