[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [32704] branches/particles-2010/source/ blender: bNodeSocketTypeInfo struct added to assemble all the socket type information in one place and make it easier to add new socket types .

Lukas Toenne lukas.toenne at googlemail.com
Mon Oct 25 17:36:49 CEST 2010


Revision: 32704
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=32704
Author:   lukastoenne
Date:     2010-10-25 17:36:48 +0200 (Mon, 25 Oct 2010)

Log Message:
-----------
bNodeSocketTypeInfo struct added to assemble all the socket type information in one place and make it easier to add new socket types. The list of type ids is still in the DNA file, this might be moved to individual tree definitions too.

Modified Paths:
--------------
    branches/particles-2010/source/blender/blenkernel/BKE_node.h
    branches/particles-2010/source/blender/editors/space_node/node_draw.c
    branches/particles-2010/source/blender/nodes/intern/composite/node_tree_composite.c
    branches/particles-2010/source/blender/nodes/intern/node_util.c
    branches/particles-2010/source/blender/nodes/intern/node_util.h
    branches/particles-2010/source/blender/nodes/intern/shader/node_tree_shader.c
    branches/particles-2010/source/blender/nodes/intern/simulation/node_tree_simulation.c
    branches/particles-2010/source/blender/nodes/intern/texture/node_tree_texture.c

Modified: branches/particles-2010/source/blender/blenkernel/BKE_node.h
===================================================================
--- branches/particles-2010/source/blender/blenkernel/BKE_node.h	2010-10-25 14:12:44 UTC (rev 32703)
+++ branches/particles-2010/source/blender/blenkernel/BKE_node.h	2010-10-25 15:36:48 UTC (rev 32704)
@@ -86,6 +86,14 @@
 	float min, max;					/* default range for inputs */
 } bNodeSocketDefinition;
 
+typedef struct bNodeSocketTypeInfo {
+	int type;
+	int color[4];
+	int icon;
+	char ui_name[64];
+	char ui_description[256];
+} bNodeSocketTypeInfo;
+
 typedef struct bNodeType {
 	void *next,*prev;
 	int type;
@@ -188,6 +196,7 @@
 	 * individual node update calls should be made internally if this function is defined! */
 	void (*updateNode)(struct bNodeTree *ntree, struct bNode *node);
 
+	struct bNodeSocketTypeInfo *(*getSocketTypeInfo)(int type);
 	int (*compatibleSocketTypes)(int type_a, int type_b);
 	int (*preferredSocketType)(int type_a, int type_b);
 } bNodeTreeTypeInfo;

Modified: branches/particles-2010/source/blender/editors/space_node/node_draw.c
===================================================================
--- branches/particles-2010/source/blender/editors/space_node/node_draw.c	2010-10-25 14:12:44 UTC (rev 32703)
+++ branches/particles-2010/source/blender/editors/space_node/node_draw.c	2010-10-25 15:36:48 UTC (rev 32704)
@@ -532,57 +532,12 @@
 	glDisable(GL_BLEND);
 }
 
-void node_socket_get_color(int type, int r_col[4])
+static void socket_circle_draw(bNodeTree *ntree, bNodeSocket *sock, float size)
 {
-	switch (type) {
-	case -1:
-		r_col[0]= 0;	r_col[1]= 0;	r_col[2]= 0;	r_col[3]= 0;
-		break;
-	case SOCK_VALUE:
-		r_col[0]= 160;	r_col[1]= 160;	r_col[2]= 160;	r_col[3]= 255;
-		break;
-	case SOCK_VECTOR:
-		r_col[0]= 100;	r_col[1]= 100;	r_col[2]= 200;	r_col[3]= 255;
-		break;
-	case SOCK_RGBA:
-		r_col[0]= 200;	r_col[1]= 200;	r_col[2]= 40;	r_col[3]= 255;
-		break;
-	case SOCK_OP:
-		r_col[0]= 174;	r_col[1]= 58;	r_col[2]= 5;	r_col[3]= 255;
-		break;
-	case SOCK_ANY:
-		r_col[0]= 30;	r_col[1]= 30;	r_col[2]= 30;	r_col[3]= 255;
-		break;
-	case SOCK_INT:
-		r_col[0]= 86;	r_col[1]= 185;	r_col[2]= 86;	r_col[3]= 255;
-		break;
-	case SOCK_FLOAT:
-		r_col[0]= 124;	r_col[1]= 242;	r_col[2]= 154;	r_col[3]= 255;
-		break;
-	case SOCK_BOOL:
-		r_col[0]= 200;	r_col[1]= 137;	r_col[2]= 52;	r_col[3]= 255;
-		break;
-	case SOCK_QUAT:
-		r_col[0]= 0;	r_col[1]= 209;	r_col[2]= 225;	r_col[3]= 255;
-		break;
-	case SOCK_MATRIX:
-		r_col[0]= 131;	r_col[1]= 39;	r_col[2]= 248;	r_col[3]= 255;
-		break;
-	case SOCK_STRING:
-		r_col[0]= 180;	r_col[1]= 180;	r_col[2]= 180;	r_col[3]= 255;
-		break;
-	default:
-		r_col[0]= 100;	r_col[1]= 200;	r_col[2]= 100;	r_col[3]= 255;
-	}
+	bNodeTreeTypeInfo *tti= ntreeGetTypeInfo(ntree->type);
+	node_circle_draw(sock->locx, sock->locy, size, tti->getSocketTypeInfo(sock->type)->color);
 }
 
-static void socket_circle_draw(bNodeSocket *sock, float size)
-{
-	int col[4];
-	node_socket_get_color(sock->type, col);
-	node_circle_draw(sock->locx, sock->locy, size, col);
-}
-
 static void node_sync_cb(bContext *C, void *snode_v, void *node_v)
 {
 	SpaceNode *snode= snode_v;
@@ -834,7 +789,7 @@
 			if (sock->panel && sock->panel->collapsed)
 				continue;
 			
-			socket_circle_draw(sock, NODE_SOCKSIZE);
+			socket_circle_draw(ntree, sock, NODE_SOCKSIZE);
 			
 			if(sock->link==NULL) {
 			
@@ -975,7 +930,7 @@
 			if (sock->panel && sock->panel->collapsed)
 				continue;
 			
-			socket_circle_draw(sock, NODE_SOCKSIZE);
+			socket_circle_draw(ntree, sock, NODE_SOCKSIZE);
 			
 			ofs= 0;
 			UI_ThemeColor(TH_TEXT);
@@ -1027,6 +982,7 @@
 
 static void node_draw_hidden(const bContext *C, ARegion *ar, SpaceNode *snode, bNode *node)
 {
+	bNodeTree *ntree = snode->nodetree;
 	bNodeSocket *sock;
 	rctf *rct= &node->totr;
 	float dx, centy= 0.5f*(rct->ymax+rct->ymin);
@@ -1098,12 +1054,12 @@
 	/* sockets */
 	for(sock= node->inputs.first; sock; sock= sock->next) {
 		if(!(sock->flag & (SOCK_HIDDEN|SOCK_UNAVAIL)))
-			socket_circle_draw(sock, NODE_SOCKSIZE);
+			socket_circle_draw(ntree, sock, NODE_SOCKSIZE);
 	}
 	
 	for(sock= node->outputs.first; sock; sock= sock->next) {
 		if(!(sock->flag & (SOCK_HIDDEN|SOCK_UNAVAIL)))
-			socket_circle_draw(sock, NODE_SOCKSIZE);
+			socket_circle_draw(ntree, sock, NODE_SOCKSIZE);
 	}
 	
 	uiEndBlock(C, node->block);
@@ -1210,6 +1166,7 @@
 /* groups are, on creation, centered around 0,0 */
 static void node_draw_group(const bContext *C, ARegion *ar, SpaceNode *snode, bNode *gnode)
 {
+	bNodeTree *ntree = snode->nodetree;
 	bNodeTree *ngroup= (bNodeTree *)gnode->id;
 	bNodeSocket *sock;
 	rctf rect= gnode->totr;
@@ -1256,10 +1213,10 @@
 	/* group sockets */
 	for(sock= gnode->inputs.first; sock; sock= sock->next)
 		if(!(sock->flag & (SOCK_HIDDEN|SOCK_UNAVAIL)))
-			socket_circle_draw(sock, NODE_SOCKSIZE);
+			socket_circle_draw(ntree, sock, NODE_SOCKSIZE);
 	for(sock= gnode->outputs.first; sock; sock= sock->next)
 		if(!(sock->flag & (SOCK_HIDDEN|SOCK_UNAVAIL)))
-			socket_circle_draw(sock, NODE_SOCKSIZE);
+			socket_circle_draw(ntree, sock, NODE_SOCKSIZE);
 
 
 	

Modified: branches/particles-2010/source/blender/nodes/intern/composite/node_tree_composite.c
===================================================================
--- branches/particles-2010/source/blender/nodes/intern/composite/node_tree_composite.c	2010-10-25 14:12:44 UTC (rev 32703)
+++ branches/particles-2010/source/blender/nodes/intern/composite/node_tree_composite.c	2010-10-25 15:36:48 UTC (rev 32704)
@@ -289,7 +289,8 @@
 	/* endExec */			endExec,
 	/* exec */				exec,
 	/* update */			NULL,
-	/* updateNode */		updateNode
+	/* updateNode */		updateNode,
+	/* getSocketTypeInfo */	getSocketTypeInfoDefault
 };
 
 

Modified: branches/particles-2010/source/blender/nodes/intern/node_util.c
===================================================================
--- branches/particles-2010/source/blender/nodes/intern/node_util.c	2010-10-25 14:12:44 UTC (rev 32703)
+++ branches/particles-2010/source/blender/nodes/intern/node_util.c	2010-10-25 15:36:48 UTC (rev 32704)
@@ -232,3 +232,35 @@
 		}
 	}
 }
+
+bNodeSocketTypeInfo *getSocketTypeInfoDefault(int type)
+{
+	static bNodeSocketTypeInfo sockettype_value = {
+		/* type */				SOCK_VALUE,
+		/* color */				{160,160,160,255},
+		/* icon */				0,
+		/* ui_name */			"Value",
+		/* ui_description */	"Scalar value socket"
+	};
+	static bNodeSocketTypeInfo sockettype_vector = {
+		/* type */				SOCK_VECTOR,
+		/* color */				{100,100,200,255},
+		/* icon */				0,
+		/* ui_name */			"Vector",
+		/* ui_description */	"Vector socket"
+	};
+	static bNodeSocketTypeInfo sockettype_rgba = {
+		/* type */				SOCK_RGBA,
+		/* color */				{200,200,40,255},
+		/* icon */				0,
+		/* ui_name */			"Color",
+		/* ui_description */	"Color socket"
+	};
+	static bNodeSocketTypeInfo *types[] = {
+		/* SOCK_VALUE */	&sockettype_value,
+		/* SOCK_VECTOR */	&sockettype_vector,
+		/* SOCK_RGBA */		&sockettype_rgba
+	};
+	
+	return types[type];
+}

Modified: branches/particles-2010/source/blender/nodes/intern/node_util.h
===================================================================
--- branches/particles-2010/source/blender/nodes/intern/node_util.h	2010-10-25 14:12:44 UTC (rev 32703)
+++ branches/particles-2010/source/blender/nodes/intern/node_util.h	2010-10-25 15:36:48 UTC (rev 32704)
@@ -70,6 +70,8 @@
 void group_node_get_stack(struct bNode *node, struct bNodeStack *stack, struct bNodeStack **in, struct bNodeStack **out, struct bNodeStack **gin, struct bNodeStack **gout);
 void node_group_execute(struct bNodeStack *stack, void *data, struct bNode *gnode, struct bNodeStack **in, struct bNodeStack **out);
 
+struct bNodeSocketTypeInfo *getSocketTypeInfoDefault(int type);
+
 #endif
 
 // this is needed for inlining behaviour

Modified: branches/particles-2010/source/blender/nodes/intern/shader/node_tree_shader.c
===================================================================
--- branches/particles-2010/source/blender/nodes/intern/shader/node_tree_shader.c	2010-10-25 14:12:44 UTC (rev 32703)
+++ branches/particles-2010/source/blender/nodes/intern/shader/node_tree_shader.c	2010-10-25 15:36:48 UTC (rev 32704)
@@ -181,7 +181,8 @@
 	/* endExec */			endExec,
 	/* exec */				exec,
 	/* update */			NULL,
-	/* updateNode */		NULL
+	/* updateNode */		NULL,
+	/* getSocketTypeInfo */	getSocketTypeInfoDefault
 };
 
 /* GPU material from shader nodes */

Modified: branches/particles-2010/source/blender/nodes/intern/simulation/node_tree_simulation.c
===================================================================
--- branches/particles-2010/source/blender/nodes/intern/simulation/node_tree_simulation.c	2010-10-25 14:12:44 UTC (rev 32703)
+++ branches/particles-2010/source/blender/nodes/intern/simulation/node_tree_simulation.c	2010-10-25 15:36:48 UTC (rev 32704)
@@ -394,6 +394,96 @@
 		node->typeinfo->updatefunc(ntree, node);
 }
 
+static bNodeSocketTypeInfo *getSocketTypeInfo(int type)
+{
+	static bNodeSocketTypeInfo sockettype_vector = {
+		/* type */				SOCK_VECTOR,
+		/* color */				{100,100,200,255},
+		/* icon */				0,
+		/* ui_name */			"Vector",
+		/* ui_description */	"Vector socket"
+	};
+	static bNodeSocketTypeInfo sockettype_rgba = {
+		/* type */				SOCK_RGBA,
+		/* color */				{200,200,40,255},
+		/* icon */				0,
+		/* ui_name */			"Color",
+		/* ui_description */	"Color socket"
+	};
+	static bNodeSocketTypeInfo sockettype_any = {
+		/* type */				SOCK_ANY,
+		/* color */				{30,30,30,255},
+		/* icon */				0,
+		/* ui_name */			"Any",
+		/* ui_description */	"Adapting socket"
+	};
+	static bNodeSocketTypeInfo sockettype_op = {
+		/* type */				SOCK_OP,
+		/* color */				{174,58,5,255},
+		/* icon */				0,
+		/* ui_name */			"Execution",
+		/* ui_description */	"Execution control socket"
+	};
+	static bNodeSocketTypeInfo sockettype_bool = {
+		/* type */				SOCK_BOOL,
+		/* color */				{200,137,52,255},
+		/* icon */				0,
+		/* ui_name */			"Boolean",
+		/* ui_description */	"Boolean socket"
+	};
+	static bNodeSocketTypeInfo sockettype_int = {
+		/* type */				SOCK_INT,
+		/* color */				{86,185,86,255},
+		/* icon */				0,
+		/* ui_name */			"Integer",
+		/* ui_description */	"Integer socket"
+	};
+	static bNodeSocketTypeInfo sockettype_float = {
+		/* type */				SOCK_FLOAT,
+		/* color */				{124,242,154,255},
+		/* icon */				0,
+		/* ui_name */			"Float",
+		/* ui_description */	"Floating point socket"
+	};
+	static bNodeSocketTypeInfo sockettype_quat = {

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list