forked from bartvdbraak/blender
Make dynamic node labels possible as a registerable function 'draw_label' (simple 'label' identifier is already in use, need to avoid API breakage). This should simply return a string. The dynamic label can still be overridden by the user-defined node.label string.
This commit is contained in:
parent
8663b940ed
commit
4d4ef0434b
@ -175,7 +175,7 @@ typedef struct bNodeType {
|
|||||||
void (*draw_backdrop)(struct SpaceNode *snode, struct ImBuf *backdrop, struct bNode *node, int x, int y);
|
void (*draw_backdrop)(struct SpaceNode *snode, struct ImBuf *backdrop, struct bNode *node, int x, int y);
|
||||||
|
|
||||||
/// Optional custom label function for the node header.
|
/// Optional custom label function for the node header.
|
||||||
void (*labelfunc)(struct bNode *node, char *label, int maxlen);
|
void (*labelfunc)(struct bNodeTree *ntree, struct bNode *node, char *label, int maxlen);
|
||||||
/// Optional custom resize handle polling.
|
/// Optional custom resize handle polling.
|
||||||
int (*resize_area_func)(struct bNode *node, int x, int y);
|
int (*resize_area_func)(struct bNode *node, int x, int y);
|
||||||
/// Optional selection area polling.
|
/// Optional selection area polling.
|
||||||
@ -556,7 +556,7 @@ void BKE_node_preview_set_pixel(struct bNodePreview *preview, const f
|
|||||||
|
|
||||||
/* ************** NODE TYPE ACCESS *************** */
|
/* ************** NODE TYPE ACCESS *************** */
|
||||||
|
|
||||||
void nodeLabel(struct bNode *node, char *label, int maxlen);
|
void nodeLabel(struct bNodeTree *ntree, struct bNode *node, char *label, int maxlen);
|
||||||
|
|
||||||
int nodeGroupPoll(struct bNodeTree *nodetree, struct bNodeTree *grouptree);
|
int nodeGroupPoll(struct bNodeTree *nodetree, struct bNodeTree *grouptree);
|
||||||
|
|
||||||
@ -571,7 +571,7 @@ void node_type_storage(struct bNodeType *ntype,
|
|||||||
const char *storagename,
|
const char *storagename,
|
||||||
void (*freefunc)(struct bNode *node),
|
void (*freefunc)(struct bNode *node),
|
||||||
void (*copyfunc)(struct bNodeTree *dest_ntree, struct bNode *dest_node, struct bNode *src_node));
|
void (*copyfunc)(struct bNodeTree *dest_ntree, struct bNode *dest_node, struct bNode *src_node));
|
||||||
void node_type_label(struct bNodeType *ntype, void (*labelfunc)(struct bNode *, char *label, int maxlen));
|
void node_type_label(struct bNodeType *ntype, void (*labelfunc)(struct bNodeTree *ntree, struct bNode *, char *label, int maxlen));
|
||||||
void node_type_update(struct bNodeType *ntype,
|
void node_type_update(struct bNodeType *ntype,
|
||||||
void (*updatefunc)(struct bNodeTree *ntree, struct bNode *node),
|
void (*updatefunc)(struct bNodeTree *ntree, struct bNode *node),
|
||||||
void (*verifyfunc)(struct bNodeTree *ntree, struct bNode *node, struct ID *id));
|
void (*verifyfunc)(struct bNodeTree *ntree, struct bNode *node, struct ID *id));
|
||||||
|
@ -3089,12 +3089,12 @@ void nodeSynchronizeID(bNode *node, bool copy_to_id)
|
|||||||
|
|
||||||
/* ************* node type access ********** */
|
/* ************* node type access ********** */
|
||||||
|
|
||||||
void nodeLabel(bNode *node, char *label, int maxlen)
|
void nodeLabel(bNodeTree *ntree, bNode *node, char *label, int maxlen)
|
||||||
{
|
{
|
||||||
if (node->label[0] != '\0')
|
if (node->label[0] != '\0')
|
||||||
BLI_strncpy(label, node->label, maxlen);
|
BLI_strncpy(label, node->label, maxlen);
|
||||||
else if (node->typeinfo->labelfunc)
|
else if (node->typeinfo->labelfunc)
|
||||||
node->typeinfo->labelfunc(node, label, maxlen);
|
node->typeinfo->labelfunc(ntree, node, label, maxlen);
|
||||||
else
|
else
|
||||||
BLI_strncpy(label, IFACE_(node->typeinfo->ui_name), maxlen);
|
BLI_strncpy(label, IFACE_(node->typeinfo->ui_name), maxlen);
|
||||||
}
|
}
|
||||||
@ -3267,7 +3267,7 @@ void node_type_storage(bNodeType *ntype,
|
|||||||
ntype->freefunc = freefunc;
|
ntype->freefunc = freefunc;
|
||||||
}
|
}
|
||||||
|
|
||||||
void node_type_label(struct bNodeType *ntype, void (*labelfunc)(struct bNode *, char *label, int maxlen))
|
void node_type_label(struct bNodeType *ntype, void (*labelfunc)(struct bNodeTree *ntree, struct bNode *node, char *label, int maxlen))
|
||||||
{
|
{
|
||||||
ntype->labelfunc = labelfunc;
|
ntype->labelfunc = labelfunc;
|
||||||
}
|
}
|
||||||
|
@ -384,7 +384,7 @@ static void node_draw_frame_prepare(const bContext *UNUSED(C), bNodeTree *ntree,
|
|||||||
node->totr = rect;
|
node->totr = rect;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void node_draw_frame_label(bNode *node, const float aspect)
|
static void node_draw_frame_label(bNodeTree *ntree, bNode *node, const float aspect)
|
||||||
{
|
{
|
||||||
/* XXX font id is crap design */
|
/* XXX font id is crap design */
|
||||||
const int fontid = UI_GetStyle()->widgetlabel.uifont_id;
|
const int fontid = UI_GetStyle()->widgetlabel.uifont_id;
|
||||||
@ -397,7 +397,7 @@ static void node_draw_frame_label(bNode *node, const float aspect)
|
|||||||
float x, y;
|
float x, y;
|
||||||
const int font_size = data->label_size / aspect;
|
const int font_size = data->label_size / aspect;
|
||||||
|
|
||||||
nodeLabel(node, label, sizeof(label));
|
nodeLabel(ntree, node, label, sizeof(label));
|
||||||
|
|
||||||
BLF_enable(fontid, BLF_ASPECT);
|
BLF_enable(fontid, BLF_ASPECT);
|
||||||
BLF_aspect(fontid, aspect, aspect, 1.0f);
|
BLF_aspect(fontid, aspect, aspect, 1.0f);
|
||||||
@ -420,7 +420,7 @@ static void node_draw_frame_label(bNode *node, const float aspect)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void node_draw_frame(const bContext *C, ARegion *ar, SpaceNode *snode,
|
static void node_draw_frame(const bContext *C, ARegion *ar, SpaceNode *snode,
|
||||||
bNodeTree *UNUSED(ntree), bNode *node, bNodeInstanceKey UNUSED(key))
|
bNodeTree *ntree, bNode *node, bNodeInstanceKey UNUSED(key))
|
||||||
{
|
{
|
||||||
rctf *rct = &node->totr;
|
rctf *rct = &node->totr;
|
||||||
int color_id = node_get_colorid(node);
|
int color_id = node_get_colorid(node);
|
||||||
@ -469,7 +469,7 @@ static void node_draw_frame(const bContext *C, ARegion *ar, SpaceNode *snode,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* label */
|
/* label */
|
||||||
node_draw_frame_label(node, snode->aspect);
|
node_draw_frame_label(ntree, node, snode->aspect);
|
||||||
|
|
||||||
UI_ThemeClearColor(color_id);
|
UI_ThemeClearColor(color_id);
|
||||||
|
|
||||||
|
@ -868,7 +868,7 @@ static void node_draw_basis(const bContext *C, ARegion *ar, SpaceNode *snode, bN
|
|||||||
UI_ThemeColor(TH_TEXT);
|
UI_ThemeColor(TH_TEXT);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
nodeLabel(node, showname, sizeof(showname));
|
nodeLabel(ntree, node, showname, sizeof(showname));
|
||||||
|
|
||||||
//if (node->flag & NODE_MUTED)
|
//if (node->flag & NODE_MUTED)
|
||||||
// BLI_snprintf(showname, sizeof(showname), "[%s]", showname); /* XXX - don't print into self! */
|
// BLI_snprintf(showname, sizeof(showname), "[%s]", showname); /* XXX - don't print into self! */
|
||||||
@ -1035,7 +1035,7 @@ static void node_draw_hidden(const bContext *C, ARegion *ar, SpaceNode *snode, b
|
|||||||
UI_ThemeColor(TH_TEXT);
|
UI_ThemeColor(TH_TEXT);
|
||||||
|
|
||||||
if (node->miniwidth > 0.0f) {
|
if (node->miniwidth > 0.0f) {
|
||||||
nodeLabel(node, showname, sizeof(showname));
|
nodeLabel(ntree, node, showname, sizeof(showname));
|
||||||
|
|
||||||
//if (node->flag & NODE_MUTED)
|
//if (node->flag & NODE_MUTED)
|
||||||
// BLI_snprintf(showname, sizeof(showname), "[%s]", showname); /* XXX - don't print into self! */
|
// BLI_snprintf(showname, sizeof(showname), "[%s]", showname); /* XXX - don't print into self! */
|
||||||
|
@ -1280,6 +1280,29 @@ static void rna_Node_draw_buttons_ext(struct uiLayout *layout, bContext *C, Poin
|
|||||||
RNA_parameter_list_free(&list);
|
RNA_parameter_list_free(&list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void rna_Node_draw_label(bNodeTree *ntree, bNode *node, char *label, int maxlen)
|
||||||
|
{
|
||||||
|
extern FunctionRNA rna_Node_draw_label_func;
|
||||||
|
|
||||||
|
PointerRNA ptr;
|
||||||
|
ParameterList list;
|
||||||
|
FunctionRNA *func;
|
||||||
|
void *ret;
|
||||||
|
char *rlabel;
|
||||||
|
|
||||||
|
func = &rna_Node_draw_label_func; /* RNA_struct_find_function(&ptr, "draw_label"); */
|
||||||
|
|
||||||
|
RNA_pointer_create(&ntree->id, &RNA_Node, node, &ptr);
|
||||||
|
RNA_parameter_list_create(&list, &ptr, func);
|
||||||
|
node->typeinfo->ext.call(NULL, &ptr, func, &list);
|
||||||
|
|
||||||
|
RNA_parameter_get_lookup(&list, "label", &ret);
|
||||||
|
rlabel = *(char **)ret;
|
||||||
|
BLI_strncpy(label, rlabel != NULL ? rlabel : "", maxlen);
|
||||||
|
|
||||||
|
RNA_parameter_list_free(&list);
|
||||||
|
}
|
||||||
|
|
||||||
static int rna_Node_is_registered_node_type(StructRNA *type)
|
static int rna_Node_is_registered_node_type(StructRNA *type)
|
||||||
{
|
{
|
||||||
return (RNA_struct_blender_type_get(type) != NULL);
|
return (RNA_struct_blender_type_get(type) != NULL);
|
||||||
@ -1321,7 +1344,7 @@ static bNodeType *rna_Node_register_base(Main *bmain, ReportList *reports, Struc
|
|||||||
PointerRNA dummyptr;
|
PointerRNA dummyptr;
|
||||||
FunctionRNA *func;
|
FunctionRNA *func;
|
||||||
PropertyRNA *parm;
|
PropertyRNA *parm;
|
||||||
int have_function[8];
|
int have_function[9];
|
||||||
|
|
||||||
/* setup dummy node & node type to store static properties in */
|
/* setup dummy node & node type to store static properties in */
|
||||||
memset(&dummynt, 0, sizeof(bNodeType));
|
memset(&dummynt, 0, sizeof(bNodeType));
|
||||||
@ -1379,6 +1402,7 @@ static bNodeType *rna_Node_register_base(Main *bmain, ReportList *reports, Struc
|
|||||||
nt->freefunc_api = (have_function[5]) ? rna_Node_free : NULL;
|
nt->freefunc_api = (have_function[5]) ? rna_Node_free : NULL;
|
||||||
nt->draw_buttons = (have_function[6]) ? rna_Node_draw_buttons : NULL;
|
nt->draw_buttons = (have_function[6]) ? rna_Node_draw_buttons : NULL;
|
||||||
nt->draw_buttons_ex = (have_function[7]) ? rna_Node_draw_buttons_ext : NULL;
|
nt->draw_buttons_ex = (have_function[7]) ? rna_Node_draw_buttons_ext : NULL;
|
||||||
|
nt->labelfunc = (have_function[8]) ? rna_Node_draw_label : NULL;
|
||||||
|
|
||||||
/* sanitize size values in case not all have been registered */
|
/* sanitize size values in case not all have been registered */
|
||||||
if (nt->maxwidth < nt->minwidth)
|
if (nt->maxwidth < nt->minwidth)
|
||||||
@ -7149,6 +7173,14 @@ static void rna_def_node(BlenderRNA *brna)
|
|||||||
RNA_def_property_struct_type(parm, "UILayout");
|
RNA_def_property_struct_type(parm, "UILayout");
|
||||||
RNA_def_property_ui_text(parm, "Layout", "Layout in the UI");
|
RNA_def_property_ui_text(parm, "Layout", "Layout in the UI");
|
||||||
RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL);
|
RNA_def_property_flag(parm, PROP_REQUIRED | PROP_NEVER_NULL);
|
||||||
|
|
||||||
|
/* dynamic label */
|
||||||
|
func = RNA_def_function(srna, "draw_label", NULL);
|
||||||
|
RNA_def_function_ui_description(func, "Returns a dynamic label string");
|
||||||
|
RNA_def_function_flag(func, FUNC_REGISTER_OPTIONAL);
|
||||||
|
parm = RNA_def_string(func, "label", "", MAX_NAME, "Label", "");
|
||||||
|
RNA_def_property_flag(parm, PROP_THICK_WRAP); /* needed for string return value */
|
||||||
|
RNA_def_function_output(func, parm);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void rna_def_node_link(BlenderRNA *brna)
|
static void rna_def_node_link(BlenderRNA *brna)
|
||||||
|
@ -48,7 +48,7 @@ static bNodeSocketTemplate cmp_node_moviedistortion_out[] = {
|
|||||||
{ -1, 0, "" }
|
{ -1, 0, "" }
|
||||||
};
|
};
|
||||||
|
|
||||||
static void label(bNode *node, char *label, int maxlen)
|
static void label(bNodeTree *UNUSED(ntree), bNode *node, char *label, int maxlen)
|
||||||
{
|
{
|
||||||
if (node->custom1 == 0)
|
if (node->custom1 == 0)
|
||||||
BLI_strncpy(label, IFACE_("Undistortion"), maxlen);
|
BLI_strncpy(label, IFACE_("Undistortion"), maxlen);
|
||||||
|
@ -82,7 +82,7 @@ bNodeSocket *node_group_find_output_socket(bNode *groupnode, const char *identif
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* groups display their internal tree name as label */
|
/* groups display their internal tree name as label */
|
||||||
void node_group_label(bNode *node, char *label, int maxlen)
|
void node_group_label(bNodeTree *UNUSED(ntree), bNode *node, char *label, int maxlen)
|
||||||
{
|
{
|
||||||
BLI_strncpy(label, (node->id) ? node->id->name + 2 : IFACE_("Missing Datablock"), maxlen);
|
BLI_strncpy(label, (node->id) ? node->id->name + 2 : IFACE_("Missing Datablock"), maxlen);
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@
|
|||||||
|
|
||||||
struct bNodeTree;
|
struct bNodeTree;
|
||||||
|
|
||||||
void node_group_label(struct bNode *node, char *label, int maxlen);
|
void node_group_label(struct bNodeTree *ntree, struct bNode *node, char *label, int maxlen);
|
||||||
int node_group_poll_instance(struct bNode *node, struct bNodeTree *nodetree);
|
int node_group_poll_instance(struct bNode *node, struct bNodeTree *nodetree);
|
||||||
|
|
||||||
void ntree_update_reroute_nodes(struct bNodeTree *ntree);
|
void ntree_update_reroute_nodes(struct bNodeTree *ntree);
|
||||||
|
@ -83,28 +83,28 @@ void *node_initexec_curves(bNodeExecContext *UNUSED(context), bNode *node, bNode
|
|||||||
|
|
||||||
/**** Labels ****/
|
/**** Labels ****/
|
||||||
|
|
||||||
void node_blend_label(bNode *node, char *label, int maxlen)
|
void node_blend_label(bNodeTree *UNUSED(ntree), bNode *node, char *label, int maxlen)
|
||||||
{
|
{
|
||||||
const char *name;
|
const char *name;
|
||||||
RNA_enum_name(ramp_blend_items, node->custom1, &name);
|
RNA_enum_name(ramp_blend_items, node->custom1, &name);
|
||||||
BLI_strncpy(label, IFACE_(name), maxlen);
|
BLI_strncpy(label, IFACE_(name), maxlen);
|
||||||
}
|
}
|
||||||
|
|
||||||
void node_math_label(bNode *node, char *label, int maxlen)
|
void node_math_label(bNodeTree *UNUSED(ntree), bNode *node, char *label, int maxlen)
|
||||||
{
|
{
|
||||||
const char *name;
|
const char *name;
|
||||||
RNA_enum_name(node_math_items, node->custom1, &name);
|
RNA_enum_name(node_math_items, node->custom1, &name);
|
||||||
BLI_strncpy(label, IFACE_(name), maxlen);
|
BLI_strncpy(label, IFACE_(name), maxlen);
|
||||||
}
|
}
|
||||||
|
|
||||||
void node_vect_math_label(bNode *node, char *label, int maxlen)
|
void node_vect_math_label(bNodeTree *UNUSED(ntree), bNode *node, char *label, int maxlen)
|
||||||
{
|
{
|
||||||
const char *name;
|
const char *name;
|
||||||
RNA_enum_name(node_vec_math_items, node->custom1, &name);
|
RNA_enum_name(node_vec_math_items, node->custom1, &name);
|
||||||
BLI_strncpy(label, IFACE_(name), maxlen);
|
BLI_strncpy(label, IFACE_(name), maxlen);
|
||||||
}
|
}
|
||||||
|
|
||||||
void node_filter_label(bNode *node, char *label, int maxlen)
|
void node_filter_label(bNodeTree *UNUSED(ntree), bNode *node, char *label, int maxlen)
|
||||||
{
|
{
|
||||||
const char *name;
|
const char *name;
|
||||||
RNA_enum_name(node_filter_items, node->custom1, &name);
|
RNA_enum_name(node_filter_items, node->custom1, &name);
|
||||||
|
@ -71,10 +71,10 @@ extern void *node_initexec_curves(struct bNodeExecContext *context, struct bNode
|
|||||||
|
|
||||||
/**** Labels ****/
|
/**** Labels ****/
|
||||||
|
|
||||||
void node_blend_label(struct bNode *node, char *label, int maxlen);
|
void node_blend_label(struct bNodeTree *ntree, struct bNode *node, char *label, int maxlen);
|
||||||
void node_math_label(struct bNode *node, char *label, int maxlen);
|
void node_math_label(struct bNodeTree *ntree, struct bNode *node, char *label, int maxlen);
|
||||||
void node_vect_math_label(struct bNode *node, char *label, int maxlen);
|
void node_vect_math_label(struct bNodeTree *ntree, struct bNode *node, char *label, int maxlen);
|
||||||
void node_filter_label(struct bNode *node, char *label, int maxlen);
|
void node_filter_label(struct bNodeTree *ntree, struct bNode *node, char *label, int maxlen);
|
||||||
|
|
||||||
void node_update_internal_links_default(struct bNodeTree *ntree, struct bNode *node);
|
void node_update_internal_links_default(struct bNodeTree *ntree, struct bNode *node);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user