Added an optional label string to nodes. As pointed out by Sebastian Koenig, some...
authorLukas Toenne <lukas.toenne@googlemail.com>
Thu, 17 Mar 2011 10:11:12 +0000 (10:11 +0000)
committerLukas Toenne <lukas.toenne@googlemail.com>
Thu, 17 Mar 2011 10:11:12 +0000 (10:11 +0000)
source/blender/editors/space_node/node_buttons.c
source/blender/editors/space_node/node_draw.c
source/blender/makesdna/DNA_node_types.h
source/blender/makesrna/intern/rna_nodetree.c

index b1191b616dcf55b1ab20f9346b551e74767dd587..f8ea6e881f73165eece669be524f8dd3eba862a7 100644 (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 */
index c5221d4583750312568e0c4a4017eb31dfc7db26..920e670573d29c364e9acfc79b060a181b915c3c 100644 (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));
index 803e5418bcc3cd8804aec9d3b3940c79561159da..03387c3a63afa82ea64c49f6800c3c6c83fc6f5a 100644 (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;
        
index 4926c695d21d4642d509c7afdec21b48fac4febb..e39b71c2786f7aa1e7d06c9ae95b777a06d70d8e 100644 (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)