forked from bartvdbraak/blender
Instead of requiring a const char* return from the (optional) node label callback function, let it write into a mutable string buffer. This will allow actual dynamic labels for nodes using the python
API.
This commit is contained in:
parent
ba7fd8cd5c
commit
8663b940ed
@ -175,7 +175,7 @@ typedef struct bNodeType {
|
||||
void (*draw_backdrop)(struct SpaceNode *snode, struct ImBuf *backdrop, struct bNode *node, int x, int y);
|
||||
|
||||
/// Optional custom label function for the node header.
|
||||
const char *(*labelfunc)(struct bNode *);
|
||||
void (*labelfunc)(struct bNode *node, char *label, int maxlen);
|
||||
/// Optional custom resize handle polling.
|
||||
int (*resize_area_func)(struct bNode *node, int x, int y);
|
||||
/// Optional selection area polling.
|
||||
@ -556,7 +556,7 @@ void BKE_node_preview_set_pixel(struct bNodePreview *preview, const f
|
||||
|
||||
/* ************** NODE TYPE ACCESS *************** */
|
||||
|
||||
const char *nodeLabel(struct bNode *node);
|
||||
void nodeLabel(struct bNode *node, char *label, int maxlen);
|
||||
|
||||
int nodeGroupPoll(struct bNodeTree *nodetree, struct bNodeTree *grouptree);
|
||||
|
||||
@ -571,7 +571,7 @@ void node_type_storage(struct bNodeType *ntype,
|
||||
const char *storagename,
|
||||
void (*freefunc)(struct bNode *node),
|
||||
void (*copyfunc)(struct bNodeTree *dest_ntree, struct bNode *dest_node, struct bNode *src_node));
|
||||
void node_type_label(struct bNodeType *ntype, const char *(*labelfunc)(struct bNode *));
|
||||
void node_type_label(struct bNodeType *ntype, void (*labelfunc)(struct bNode *, char *label, int maxlen));
|
||||
void node_type_update(struct bNodeType *ntype,
|
||||
void (*updatefunc)(struct bNodeTree *ntree, struct bNode *node),
|
||||
void (*verifyfunc)(struct bNodeTree *ntree, struct bNode *node, struct ID *id));
|
||||
|
@ -3089,14 +3089,14 @@ void nodeSynchronizeID(bNode *node, bool copy_to_id)
|
||||
|
||||
/* ************* node type access ********** */
|
||||
|
||||
const char *nodeLabel(bNode *node)
|
||||
void nodeLabel(bNode *node, char *label, int maxlen)
|
||||
{
|
||||
if (node->label[0] != '\0')
|
||||
return node->label;
|
||||
BLI_strncpy(label, node->label, maxlen);
|
||||
else if (node->typeinfo->labelfunc)
|
||||
return node->typeinfo->labelfunc(node);
|
||||
node->typeinfo->labelfunc(node, label, maxlen);
|
||||
else
|
||||
return IFACE_(node->typeinfo->ui_name);
|
||||
BLI_strncpy(label, IFACE_(node->typeinfo->ui_name), maxlen);
|
||||
}
|
||||
|
||||
static void node_type_base_defaults(bNodeType *ntype)
|
||||
@ -3267,7 +3267,7 @@ void node_type_storage(bNodeType *ntype,
|
||||
ntype->freefunc = freefunc;
|
||||
}
|
||||
|
||||
void node_type_label(struct bNodeType *ntype, const char *(*labelfunc)(struct bNode *))
|
||||
void node_type_label(struct bNodeType *ntype, void (*labelfunc)(struct bNode *, char *label, int maxlen))
|
||||
{
|
||||
ntype->labelfunc = labelfunc;
|
||||
}
|
||||
|
@ -391,12 +391,14 @@ static void node_draw_frame_label(bNode *node, const float aspect)
|
||||
NodeFrame *data = (NodeFrame *)node->storage;
|
||||
rctf *rct = &node->totr;
|
||||
int color_id = node_get_colorid(node);
|
||||
const char *label = nodeLabel(node);
|
||||
char label[MAX_NAME];
|
||||
/* XXX a bit hacky, should use separate align values for x and y */
|
||||
float width, ascender;
|
||||
float x, y;
|
||||
const int font_size = data->label_size / aspect;
|
||||
|
||||
nodeLabel(node, label, sizeof(label));
|
||||
|
||||
BLF_enable(fontid, BLF_ASPECT);
|
||||
BLF_aspect(fontid, aspect, aspect, 1.0f);
|
||||
BLF_size(fontid, MIN2(24, font_size), U.dpi); /* clamp otherwise it can suck up a LOT of memory */
|
||||
|
@ -868,7 +868,7 @@ static void node_draw_basis(const bContext *C, ARegion *ar, SpaceNode *snode, bN
|
||||
UI_ThemeColor(TH_TEXT);
|
||||
#endif
|
||||
|
||||
BLI_strncpy(showname, nodeLabel(node), sizeof(showname));
|
||||
nodeLabel(node, showname, sizeof(showname));
|
||||
|
||||
//if (node->flag & NODE_MUTED)
|
||||
// BLI_snprintf(showname, sizeof(showname), "[%s]", showname); /* XXX - don't print into self! */
|
||||
@ -1035,8 +1035,8 @@ static void node_draw_hidden(const bContext *C, ARegion *ar, SpaceNode *snode, b
|
||||
UI_ThemeColor(TH_TEXT);
|
||||
|
||||
if (node->miniwidth > 0.0f) {
|
||||
BLI_strncpy(showname, nodeLabel(node), sizeof(showname));
|
||||
|
||||
nodeLabel(node, showname, sizeof(showname));
|
||||
|
||||
//if (node->flag & NODE_MUTED)
|
||||
// BLI_snprintf(showname, sizeof(showname), "[%s]", showname); /* XXX - don't print into self! */
|
||||
|
||||
|
@ -48,12 +48,12 @@ static bNodeSocketTemplate cmp_node_moviedistortion_out[] = {
|
||||
{ -1, 0, "" }
|
||||
};
|
||||
|
||||
static const char *label(bNode *node)
|
||||
static void label(bNode *node, char *label, int maxlen)
|
||||
{
|
||||
if (node->custom1 == 0)
|
||||
return IFACE_("Undistortion");
|
||||
BLI_strncpy(label, IFACE_("Undistortion"), maxlen);
|
||||
else
|
||||
return IFACE_("Distortion");
|
||||
BLI_strncpy(label, IFACE_("Distortion"), maxlen);
|
||||
}
|
||||
|
||||
static void init(const bContext *C, PointerRNA *ptr)
|
||||
|
@ -82,9 +82,9 @@ bNodeSocket *node_group_find_output_socket(bNode *groupnode, const char *identif
|
||||
}
|
||||
|
||||
/* groups display their internal tree name as label */
|
||||
const char *node_group_label(bNode *node)
|
||||
void node_group_label(bNode *node, char *label, int maxlen)
|
||||
{
|
||||
return (node->id) ? node->id->name + 2 : IFACE_("Missing Datablock");
|
||||
BLI_strncpy(label, (node->id) ? node->id->name + 2 : IFACE_("Missing Datablock"), maxlen);
|
||||
}
|
||||
|
||||
int node_group_poll_instance(bNode *node, bNodeTree *nodetree)
|
||||
|
@ -37,7 +37,7 @@
|
||||
|
||||
struct bNodeTree;
|
||||
|
||||
const char *node_group_label(struct bNode *node);
|
||||
void node_group_label(struct bNode *node, char *label, int maxlen);
|
||||
int node_group_poll_instance(struct bNode *node, struct bNodeTree *nodetree);
|
||||
|
||||
void ntree_update_reroute_nodes(struct bNodeTree *ntree);
|
||||
|
@ -36,6 +36,7 @@
|
||||
#include "DNA_node_types.h"
|
||||
|
||||
#include "BLI_listbase.h"
|
||||
#include "BLI_string.h"
|
||||
#include "BLI_utildefines.h"
|
||||
|
||||
#include "BLF_translation.h"
|
||||
@ -82,32 +83,32 @@ void *node_initexec_curves(bNodeExecContext *UNUSED(context), bNode *node, bNode
|
||||
|
||||
/**** Labels ****/
|
||||
|
||||
const char *node_blend_label(bNode *node)
|
||||
void node_blend_label(bNode *node, char *label, int maxlen)
|
||||
{
|
||||
const char *name;
|
||||
RNA_enum_name(ramp_blend_items, node->custom1, &name);
|
||||
return IFACE_(name);
|
||||
BLI_strncpy(label, IFACE_(name), maxlen);
|
||||
}
|
||||
|
||||
const char *node_math_label(bNode *node)
|
||||
void node_math_label(bNode *node, char *label, int maxlen)
|
||||
{
|
||||
const char *name;
|
||||
RNA_enum_name(node_math_items, node->custom1, &name);
|
||||
return IFACE_(name);
|
||||
BLI_strncpy(label, IFACE_(name), maxlen);
|
||||
}
|
||||
|
||||
const char *node_vect_math_label(bNode *node)
|
||||
void node_vect_math_label(bNode *node, char *label, int maxlen)
|
||||
{
|
||||
const char *name;
|
||||
RNA_enum_name(node_vec_math_items, node->custom1, &name);
|
||||
return IFACE_(name);
|
||||
BLI_strncpy(label, IFACE_(name), maxlen);
|
||||
}
|
||||
|
||||
const char *node_filter_label(bNode *node)
|
||||
void node_filter_label(bNode *node, char *label, int maxlen)
|
||||
{
|
||||
const char *name;
|
||||
RNA_enum_name(node_filter_items, node->custom1, &name);
|
||||
return IFACE_(name);
|
||||
BLI_strncpy(label, IFACE_(name), maxlen);
|
||||
}
|
||||
|
||||
void node_update_internal_links_default(bNodeTree *ntree, bNode *node)
|
||||
|
@ -71,10 +71,10 @@ extern void *node_initexec_curves(struct bNodeExecContext *context, struct bNode
|
||||
|
||||
/**** Labels ****/
|
||||
|
||||
const char *node_blend_label(struct bNode *node);
|
||||
const char *node_math_label(struct bNode *node);
|
||||
const char *node_vect_math_label(struct bNode *node);
|
||||
const char *node_filter_label(struct bNode *node);
|
||||
void node_blend_label(struct bNode *node, char *label, int maxlen);
|
||||
void node_math_label(struct bNode *node, char *label, int maxlen);
|
||||
void node_vect_math_label(struct bNode *node, char *label, int maxlen);
|
||||
void node_filter_label(struct bNode *node, char *label, int maxlen);
|
||||
|
||||
void node_update_internal_links_default(struct bNodeTree *ntree, struct bNode *node);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user