Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r--source/blender/blenkernel/BKE_node.h24
-rw-r--r--source/blender/blenkernel/intern/node.cc15
2 files changed, 29 insertions, 10 deletions
diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h
index 30c76dc894c..d6c4ad037e2 100644
--- a/source/blender/blenkernel/BKE_node.h
+++ b/source/blender/blenkernel/BKE_node.h
@@ -289,10 +289,22 @@ typedef struct bNodeType {
void (*freefunc_api)(struct PointerRNA *ptr);
void (*copyfunc_api)(struct PointerRNA *ptr, const struct bNode *src_node);
- /* can this node type be added to a node tree */
- bool (*poll)(struct bNodeType *ntype, struct bNodeTree *nodetree);
- /* can this node be added to a node tree */
- bool (*poll_instance)(struct bNode *node, struct bNodeTree *nodetree);
+ /**
+ * Can this node type be added to a node tree?
+ * \param r_disabled_hint: Optional hint to display in the UI when the poll fails.
+ * The callback can set this to a static string without having to
+ * null-check it (or without setting it to null if it's not used).
+ * The caller must pass a valid `const char **` and null-initialize it
+ * when it's not just a dummy, that is, if it actually wants to access
+ * the returned disabled-hint (null-check needed!).
+ */
+ bool (*poll)(struct bNodeType *ntype, struct bNodeTree *nodetree, const char **r_disabled_hint);
+ /** Can this node be added to a node tree?
+ * \param r_disabled_hint: See `poll()`.
+ */
+ bool (*poll_instance)(struct bNode *node,
+ struct bNodeTree *nodetree,
+ const char **r_disabled_hint);
/* optional handling of link insertion */
void (*insert_link)(struct bNodeTree *ntree, struct bNode *node, struct bNodeLink *link);
@@ -804,7 +816,9 @@ void BKE_node_preview_set_pixel(
void nodeLabel(struct bNodeTree *ntree, struct bNode *node, char *label, int maxlen);
const char *nodeSocketLabel(const struct bNodeSocket *sock);
-int nodeGroupPoll(struct bNodeTree *nodetree, struct bNodeTree *grouptree);
+bool nodeGroupPoll(struct bNodeTree *nodetree,
+ struct bNodeTree *grouptree,
+ const char **r_disabled_hint);
/* Init a new node type struct with default values and callbacks */
void node_type_base(struct bNodeType *ntype, int type, const char *name, short nclass, short flag);
diff --git a/source/blender/blenkernel/intern/node.cc b/source/blender/blenkernel/intern/node.cc
index 52f6c4f93ad..02195e0d60f 100644
--- a/source/blender/blenkernel/intern/node.cc
+++ b/source/blender/blenkernel/intern/node.cc
@@ -2007,7 +2007,8 @@ bNode *nodeAddStaticNode(const struct bContext *C, bNodeTree *ntree, int type)
/* do an extra poll here, because some int types are used
* for multiple node types, this helps find the desired type
*/
- if (ntype->type == type && (!ntype->poll || ntype->poll(ntype, ntree))) {
+ const char *disabled_hint;
+ if (ntype->type == type && (!ntype->poll || ntype->poll(ntype, ntree, &disabled_hint))) {
idname = ntype->idname;
break;
}
@@ -4407,15 +4408,17 @@ static void node_type_base_defaults(bNodeType *ntype)
}
/* allow this node for any tree type */
-static bool node_poll_default(bNodeType *UNUSED(ntype), bNodeTree *UNUSED(ntree))
+static bool node_poll_default(bNodeType *UNUSED(ntype),
+ bNodeTree *UNUSED(ntree),
+ const char **UNUSED(disabled_hint))
{
return true;
}
/* use the basic poll function */
-static bool node_poll_instance_default(bNode *node, bNodeTree *ntree)
+static bool node_poll_instance_default(bNode *node, bNodeTree *ntree, const char **disabled_hint)
{
- return node->typeinfo->poll(node->typeinfo, ntree);
+ return node->typeinfo->poll(node->typeinfo, ntree, disabled_hint);
}
/* NOLINTNEXTLINE: readability-function-size */
@@ -4634,7 +4637,9 @@ void node_type_internal_links(bNodeType *ntype,
/* callbacks for undefined types */
-static bool node_undefined_poll(bNodeType *UNUSED(ntype), bNodeTree *UNUSED(nodetree))
+static bool node_undefined_poll(bNodeType *UNUSED(ntype),
+ bNodeTree *UNUSED(nodetree),
+ const char **UNUSED(r_disabled_hint))
{
/* this type can not be added deliberately, it's just a placeholder */
return false;