Custom Names for Nodes

This commit makes it possible to add a custom name to a node. The feature can be
accessed either by using a menu or shortcut ctrl-r. It currently works only when
a single node is selected. Invoking the feature gives a popup menu in which a new
name can be entered. If the given name is not empty, it will be shown like
"(myCustomName) NodeName" in the node header.

This feature is particularly useful when documenting complex node setups.

I also fixed the size of blur node. It was too short before due to my previous
commit.

Thanks to David Millan Escriva for contribution!
This commit is contained in:
Juho Vepsalainen
2008-01-07 19:38:01 +00:00
parent 7da95822f0
commit aa1c0281c6
6 changed files with 110 additions and 9 deletions

View File

@@ -54,6 +54,8 @@ struct Material *editnode_get_active_material(struct Material *ma);
struct bNode *editnode_get_active_idnode(struct bNodeTree *ntree, short id_code);
struct bNode *editnode_get_active(struct bNodeTree *ntree);
void node_rename(struct SpaceNode *snode);
void snode_tag_dirty(struct SpaceNode *snode);
void snode_set_context(struct SpaceNode *snode);
@@ -97,6 +99,8 @@ struct SpaceNode;
struct bNodeLink;
void node_draw_link(struct SpaceNode *snode, struct bNodeLink *link);
void node_rename_but(char *s);
void init_node_butfuncs(void);
/* exported to CMP and SHD nodes */

View File

@@ -107,6 +107,7 @@ typedef struct bNode {
struct bNode *next, *prev, *new_node;
char name[32];
char username[32]; /* custom name defined by user */
short type, flag;
short done, level; /* both for dependency and sorting */
short lasty, menunr; /* lasty: check preview render status, menunr: browse ID blocks */

View File

@@ -1129,7 +1129,7 @@ static int node_composit_buts_blur(uiBlock *block, bNodeTree *ntree, bNode *node
}
uiBlockEndAlign(block);
}
return 57;
return 77;
}
static int node_composit_buts_dblur(uiBlock *block, bNodeTree *ntree, bNode *node, rctf *butr)
@@ -2043,6 +2043,45 @@ void init_node_butfuncs(void)
/* ************** Generic drawing ************** */
void node_rename_but(char *s)
{
uiBlock *block;
ListBase listb={0, 0};
int dy, x1, y1, sizex=80, sizey=30;
short pivot[2], mval[2], ret=0;
getmouseco_sc(mval);
pivot[0]= CLAMPIS(mval[0], (sizex+10), G.curscreen->sizex-30);
pivot[1]= CLAMPIS(mval[1], (sizey/2)+10, G.curscreen->sizey-(sizey/2)-10);
if (pivot[0]!=mval[0] || pivot[1]!=mval[1])
warp_pointer(pivot[0], pivot[1]);
mywinset(G.curscreen->mainwin);
x1= pivot[0]-sizex+10;
y1= pivot[1]-sizey/2;
dy= sizey/2;
block= uiNewBlock(&listb, "button", UI_EMBOSS, UI_HELV, G.curscreen->mainwin);
uiBlockSetFlag(block, UI_BLOCK_LOOP|UI_BLOCK_REDRAW|UI_BLOCK_NUMSELECT|UI_BLOCK_ENTER_OK);
/* buttons have 0 as return event, to prevent menu to close on hotkeys */
uiBlockBeginAlign(block);
uiDefBut(block, TEX, B_NOP, "Name: ", (short)(x1),(short)(y1+dy), 150, 19, s, 0.0, 19.0, 0, 0, "Node user name");
uiBlockEndAlign(block);
uiDefBut(block, BUT, 32767, "OK", (short)(x1+150), (short)(y1+dy), 29, 19, NULL, 0, 0, 0, 0, "");
uiBoundsBlock(block, 2);
ret= uiDoBlocks(&listb, 0, 0);
}
static void draw_nodespace_grid(SpaceNode *snode)
{
float start, step= 25.0f;
@@ -2486,6 +2525,7 @@ static void node_draw_basis(ScrArea *sa, SpaceNode *snode, bNode *node)
rctf *rct= &node->totr;
float slen, iconofs;
int ofs, color_id= node_get_colorid(node);
char showname[64];
uiSetRoundBox(15-4);
ui_dropshadow(rct, BASIS_RAD, snode->aspect, node->flag & SELECT);
@@ -2564,8 +2604,18 @@ static void node_draw_basis(ScrArea *sa, SpaceNode *snode, bNode *node)
BIF_ThemeColor(TH_TEXT);
ui_rasterpos_safe(rct->xmin+19.0f, rct->ymax-NODE_DY+5.0f, snode->aspect);
snode_drawstring(snode, node->name, (int)(iconofs - rct->xmin-18.0f));
if(node->username[0]) {
strcpy(showname,"(");
strcat(showname, node->username);
strcat(showname,") ");
strcat(showname, node->name);
}
else
strcpy(showname, node->name);
snode_drawstring(snode, showname, (int)(iconofs - rct->xmin-18.0f));
/* body */
BIF_ThemeColor4(TH_NODE);
glEnable(GL_BLEND);
@@ -2680,13 +2730,14 @@ static void node_draw_basis(ScrArea *sa, SpaceNode *snode, bNode *node)
}
void node_draw_hidden(SpaceNode *snode, bNode *node)
static void node_draw_hidden(SpaceNode *snode, bNode *node)
{
bNodeSocket *sock;
rctf *rct= &node->totr;
float dx, centy= 0.5f*(rct->ymax+rct->ymin);
float hiddenrad= 0.5f*(rct->ymax-rct->ymin);
int color_id= node_get_colorid(node);
char showname[64];
/* shadow */
uiSetRoundBox(15);
@@ -2720,7 +2771,17 @@ void node_draw_hidden(SpaceNode *snode, bNode *node)
if(node->miniwidth>0.0f) {
ui_rasterpos_safe(rct->xmin+21.0f, centy-4.0f, snode->aspect);
snode_drawstring(snode, node->name, (int)(rct->xmax - rct->xmin-18.0f -12.0f));
if(node->username[0]) {
strcpy(showname,"(");
strcat(showname, node->username);
strcat(showname,") ");
strcat(showname, node->name);
}
else
strcpy(showname, node->name);
snode_drawstring(snode, showname, (int)(rct->xmax - rct->xmin-18.0f -12.0f));
}
/* scale widget thing */

View File

@@ -22,7 +22,7 @@
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
* Contributor(s): David Millan Escriva, Juho Vepsäläinen
*
* ***** END GPL LICENSE BLOCK *****
*/
@@ -1083,7 +1083,33 @@ static void scale_node(SpaceNode *snode, bNode *node)
allqueue(REDRAWNODE, 1);
}
/* ******************** rename ******************* */
void node_rename(SpaceNode *snode)
{
bNode *node, *rename_node;
short found_node= 0;
/* don't rename if more than one node is selected */
/* a nice alternative for this would be to rename last selected node */
for(node= snode->edittree->nodes.first; node; node= node->next) {
if(node->flag & SELECT) {
if(found_node) {
error("Can rename only one selected node at time");
return;
}
rename_node= node;
found_node= 1;
}
}
if(found_node) {
node_rename_but((char *)rename_node->username);
BIF_undo_push("Rename Node");
allqueue(REDRAWNODE, 1);
}
}
/* ********************** select ******************** */
@@ -2305,8 +2331,12 @@ void winqreadnodespace(ScrArea *sa, void *spacedata, BWinEvent *evt)
node_select_linked(snode, G.qual==LR_SHIFTKEY);
break;
case RKEY:
if(okee("Read saved Render Layers"))
node_read_renderlayers(snode);
if(G.qual==LR_CTRLKEY) {
node_rename(snode);
} else{
if(okee("Read saved Render Layers"))
node_read_renderlayers(snode);
}
break;
case DELKEY:
case XKEY:

View File

@@ -23,7 +23,7 @@
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
* Contributor(s): David Millan Escriva, Juho Vepsäläinen
*
* ***** END GPL LICENSE BLOCK *****
*/
@@ -516,6 +516,9 @@ static void do_node_nodemenu(void *arg, int event)
case 11: /* make link */
node_make_link(snode);
break;
case 12: /* rename */
node_rename(snode);
break;
}
if(fromlib==-1) error_libdata();
@@ -552,6 +555,7 @@ static uiBlock *node_nodemenu(void *arg_unused)
uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Hide/Unhide|H", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 7, "");
uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Rename|Ctrl R", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 12, "");
uiDefBut(block, SEPR, 0, "", 0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");

View File

@@ -1659,6 +1659,7 @@ static TBitem tb_node_node[]= {
{ 0, "Edit Group|Tab", TB_TAB, NULL},
{ 0, "SEPR", 0, NULL},
{ 0, "Hide/Unhide|H", 'h', NULL},
{ 0, "Rename|Ctrl R", TB_CTRL|'r', NULL},
{ 0, "SEPR", 0, NULL},
{ 0, "Read Saved Render Results|R", 'r', NULL},
{ 0, "Show Cyclic Dependencies|C", 'c', NULL},