Added an optional label string to nodes. As pointed out by Sebastian Koenig, some nodes (in particular render layer nodes) need custom labels, but it is not possible to make any useful generic abbreviation. The label string can be used as a custom user-defined label in this case, without the ugly .xxx extensions needed for unique node names. When the label string is empty, the default type label will be used.

This commit is contained in:
Lukas Toenne 2011-03-17 10:11:12 +00:00
parent e3842d1ca4
commit afd8865181
4 changed files with 14 additions and 52 deletions

View File

@ -113,6 +113,7 @@ static void active_node_panel(const bContext *C, Panel *pa)
/* draw this node's name, etc. */
uiItemR(layout, &ptr, "name", 0, NULL, ICON_NODE);
uiItemR(layout, &ptr, "label", 0, NULL, ICON_NODE);
// TODO: a separator would be nice...
/* draw this node's settings */

View File

@ -804,7 +804,9 @@ static void node_draw_basis(const bContext *C, ARegion *ar, SpaceNode *snode, bN
else
UI_ThemeColor(TH_TEXT); */
if (node->typeinfo->labelfunc)
if (node->label[0]!='\0')
BLI_strncpy(showname, node->label, sizeof(showname));
else if (node->typeinfo->labelfunc)
BLI_strncpy(showname, node->typeinfo->labelfunc(node), sizeof(showname));
else
BLI_strncpy(showname, node->typeinfo->name, sizeof(showname));
@ -948,7 +950,9 @@ static void node_draw_hidden(const bContext *C, ARegion *ar, SpaceNode *snode, b
UI_ThemeColor(TH_TEXT);
if(node->miniwidth>0.0f) {
if (node->typeinfo->labelfunc)
if (node->label[0]!='\0')
BLI_strncpy(showname, node->label, sizeof(showname));
else if (node->typeinfo->labelfunc)
BLI_strncpy(showname, node->typeinfo->labelfunc(node), sizeof(showname));
else
BLI_strncpy(showname, node->typeinfo->name, sizeof(showname));

View File

@ -136,7 +136,8 @@ typedef struct bNode {
void *storage; /* custom data, must be struct, for storage in file */
float locx, locy; /* root offset for drawing */
float width, miniwidth;
float width, miniwidth;
char label[32]; /* custom user-defined label */
short custom1, custom2; /* to be abused for buttons */
float custom3, custom4;

View File

@ -317,55 +317,6 @@ static void rna_Node_name_set(PointerRNA *ptr, const char *value)
BKE_all_animdata_fix_paths_rename("nodes", oldname, node->name);
}
/* this should be done at display time! if no custom names are set */
#if 0
static void rna_Node_update_username(Main *bmain, Scene *scene, PointerRNA *ptr)
{
bNode *node= (bNode*)ptr->data;
const char *name;
/*
if (!node->username[0]) {
if(node->id) {
BLI_strncpy(node->username, node->id->name+2, NODE_MAXSTR);
}
else {
switch(node->typeinfo->type) {
case SH_NODE_MIX_RGB:
case CMP_NODE_MIX_RGB:
case TEX_NODE_MIX_RGB:
if(RNA_enum_name(node_blend_type_items, node->custom1, &name))
BLI_strncpy(node->username, name, NODE_MAXSTR);
break;
case CMP_NODE_FILTER:
if(RNA_enum_name(node_filter_items, node->custom1, &name))
BLI_strncpy(node->username, name, NODE_MAXSTR);
break;
case CMP_NODE_FLIP:
if(RNA_enum_name(node_flip_items, node->custom1, &name))
BLI_strncpy(node->username, name, NODE_MAXSTR);
break;
case SH_NODE_MATH:
case CMP_NODE_MATH:
case TEX_NODE_MATH:
if(RNA_enum_name(node_math_items, node->custom1, &name))
BLI_strncpy(node->username, name, NODE_MAXSTR);
break;
case SH_NODE_VECT_MATH:
if(RNA_enum_name(node_vec_math_items, node->custom1, &name))
BLI_strncpy(node->username, name, NODE_MAXSTR);
break;
}
*/
}
}
rna_Node_update(bmain, scene, ptr);
}
#endif
static void rna_NodeSocket_update(Main *bmain, Scene *scene, PointerRNA *ptr)
{
bNodeTree *ntree= (bNodeTree*)ptr->id.data;
@ -2698,6 +2649,11 @@ static void rna_def_node(BlenderRNA *brna)
RNA_def_property_collection_sdna(prop, NULL, "outputs", NULL);
RNA_def_property_struct_type(prop, "NodeSocket");
RNA_def_property_ui_text(prop, "Outputs", "");
prop = RNA_def_property(srna, "label", PROP_STRING, PROP_NONE);
RNA_def_property_string_sdna(prop, NULL, "label");
RNA_def_property_ui_text(prop, "Label", "Optional custom node label");
RNA_def_property_update(prop, NC_NODE, "rna_Node_update");
}
static void rna_def_node_link(BlenderRNA *brna)