2023-08-16 00:20:26 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2023 Blender Authors
|
2023-05-31 16:19:06 +02:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2011-11-07 22:28:49 +00:00
|
|
|
|
2019-02-18 08:08:12 +11:00
|
|
|
/** \file
|
|
|
|
|
* \ingroup edinterface
|
2011-11-07 22:28:49 +00:00
|
|
|
*/
|
|
|
|
|
|
2021-06-02 17:19:36 +02:00
|
|
|
#include <cstdlib>
|
|
|
|
|
#include <cstring>
|
2021-10-15 12:12:36 +02:00
|
|
|
#include <optional>
|
2011-11-07 22:28:49 +00:00
|
|
|
|
2025-03-06 10:38:47 +01:00
|
|
|
#include <fmt/format.h>
|
|
|
|
|
|
2011-11-07 22:28:49 +00:00
|
|
|
#include "MEM_guardedalloc.h"
|
|
|
|
|
|
|
|
|
|
#include "DNA_node_types.h"
|
|
|
|
|
#include "DNA_screen_types.h"
|
|
|
|
|
|
|
|
|
|
#include "BLI_listbase.h"
|
|
|
|
|
#include "BLI_string.h"
|
2023-05-13 17:38:48 +10:00
|
|
|
#include "BLI_string_utf8.h"
|
2021-06-02 17:19:36 +02:00
|
|
|
#include "BLI_vector.hh"
|
2011-11-07 22:28:49 +00:00
|
|
|
|
2024-02-09 18:59:42 +01:00
|
|
|
#include "BLT_translation.hh"
|
2011-11-09 14:13:17 +00:00
|
|
|
|
2023-11-16 11:41:55 +01:00
|
|
|
#include "BKE_context.hh"
|
2024-01-15 12:44:04 -05:00
|
|
|
#include "BKE_lib_id.hh"
|
2023-12-01 19:43:16 +01:00
|
|
|
#include "BKE_main.hh"
|
2025-01-14 16:26:54 +01:00
|
|
|
#include "BKE_main_invariants.hh"
|
2023-08-30 12:37:21 +02:00
|
|
|
#include "BKE_node_runtime.hh"
|
2023-11-16 11:41:55 +01:00
|
|
|
#include "BKE_node_tree_update.hh"
|
2011-11-07 22:28:49 +00:00
|
|
|
|
2023-08-10 22:40:27 +02:00
|
|
|
#include "RNA_access.hh"
|
2024-07-10 18:30:02 +02:00
|
|
|
#include "RNA_prototypes.hh"
|
2011-11-07 22:28:49 +00:00
|
|
|
|
2021-10-15 12:12:36 +02:00
|
|
|
#include "NOD_node_declaration.hh"
|
2023-07-02 21:01:57 +02:00
|
|
|
#include "NOD_socket.hh"
|
2012-01-20 13:27:54 +00:00
|
|
|
|
2022-11-26 00:21:17 -06:00
|
|
|
#include "../interface/interface_intern.hh" /* XXX bad level */
|
2023-08-05 02:57:52 +02:00
|
|
|
#include "UI_interface.hh"
|
2012-08-02 23:03:16 +00:00
|
|
|
|
2023-08-05 02:57:52 +02:00
|
|
|
#include "ED_node.hh" /* own include */
|
2021-11-12 12:12:27 -06:00
|
|
|
#include "node_intern.hh"
|
2011-11-07 22:28:49 +00:00
|
|
|
|
2023-08-05 02:57:52 +02:00
|
|
|
#include "ED_undo.hh"
|
2011-11-07 22:28:49 +00:00
|
|
|
|
2023-09-29 13:17:52 +02:00
|
|
|
#include "WM_api.hh"
|
|
|
|
|
|
2021-10-15 12:12:36 +02:00
|
|
|
using blender::nodes::NodeDeclaration;
|
|
|
|
|
|
2022-01-20 10:36:56 -06:00
|
|
|
namespace blender::ed::space_node {
|
|
|
|
|
|
2011-11-07 22:28:49 +00:00
|
|
|
/************************* Node Socket Manipulation **************************/
|
|
|
|
|
|
2013-04-18 11:36:11 +00:00
|
|
|
/* describes an instance of a node type and a specific socket to link */
|
2021-06-02 17:19:36 +02:00
|
|
|
struct NodeLinkItem {
|
2024-07-04 11:44:06 +02:00
|
|
|
int socket_index; /* index for linking */
|
|
|
|
|
int socket_type; /* socket type for compatibility check */
|
|
|
|
|
const char *socket_name; /* ui label of the socket */
|
|
|
|
|
const char *node_name; /* ui label of the node */
|
2018-06-04 09:31:30 +02:00
|
|
|
|
2013-04-18 11:36:11 +00:00
|
|
|
/* extra settings */
|
2024-07-04 11:44:06 +02:00
|
|
|
bNodeTree *ngroup; /* group node tree */
|
2021-06-02 17:19:36 +02:00
|
|
|
};
|
2013-04-18 11:36:11 +00:00
|
|
|
|
2024-07-04 11:44:06 +02:00
|
|
|
static void node_link_item_init(NodeLinkItem &item)
|
|
|
|
|
{
|
|
|
|
|
item.socket_index = -1;
|
|
|
|
|
item.socket_type = SOCK_CUSTOM;
|
|
|
|
|
item.socket_name = nullptr;
|
|
|
|
|
item.node_name = nullptr;
|
|
|
|
|
item.ngroup = nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-18 11:36:11 +00:00
|
|
|
/* Compare an existing node to a link item to see if it can be reused.
|
|
|
|
|
* item must be for the same node type!
|
|
|
|
|
* XXX should become a node type callback
|
|
|
|
|
*/
|
|
|
|
|
static bool node_link_item_compare(bNode *node, NodeLinkItem *item)
|
|
|
|
|
{
|
2025-01-17 12:17:49 +01:00
|
|
|
if (node->is_group()) {
|
2013-04-18 11:36:11 +00:00
|
|
|
return (node->id == (ID *)item->ngroup);
|
|
|
|
|
}
|
2020-07-03 17:20:08 +02:00
|
|
|
return true;
|
2013-04-18 11:36:11 +00:00
|
|
|
}
|
|
|
|
|
|
2022-03-16 11:23:45 +01:00
|
|
|
static void node_link_item_apply(bNodeTree *ntree, bNode *node, NodeLinkItem *item)
|
2013-04-18 11:36:11 +00:00
|
|
|
{
|
2025-01-17 12:17:49 +01:00
|
|
|
if (node->is_group()) {
|
2013-04-18 11:36:11 +00:00
|
|
|
node->id = (ID *)item->ngroup;
|
2022-03-16 11:23:45 +01:00
|
|
|
BKE_ntree_update_tag_node_property(ntree, node);
|
2013-04-18 11:36:11 +00:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
/* nothing to do for now */
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-03-26 21:16:47 +11:00
|
|
|
if (node->id) {
|
2013-04-18 11:36:11 +00:00
|
|
|
id_us_plus(node->id);
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2013-04-18 11:36:11 +00:00
|
|
|
}
|
|
|
|
|
|
2011-11-07 22:28:49 +00:00
|
|
|
static void node_tag_recursive(bNode *node)
|
|
|
|
|
{
|
2019-03-26 21:16:47 +11:00
|
|
|
if (!node || (node->flag & NODE_TEST)) {
|
2012-07-01 09:54:44 +00:00
|
|
|
return; /* in case of cycles */
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2012-07-01 09:54:44 +00:00
|
|
|
|
2011-11-07 22:28:49 +00:00
|
|
|
node->flag |= NODE_TEST;
|
|
|
|
|
|
2023-08-04 08:51:13 +10:00
|
|
|
LISTBASE_FOREACH (bNodeSocket *, input, &node->inputs) {
|
2019-03-26 21:16:47 +11:00
|
|
|
if (input->link) {
|
2011-11-07 22:28:49 +00:00
|
|
|
node_tag_recursive(input->link->fromnode);
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
|
|
|
|
}
|
2011-11-07 22:28:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void node_clear_recursive(bNode *node)
|
|
|
|
|
{
|
2019-03-26 21:16:47 +11:00
|
|
|
if (!node || !(node->flag & NODE_TEST)) {
|
2012-07-01 09:54:44 +00:00
|
|
|
return; /* in case of cycles */
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2012-07-01 09:54:44 +00:00
|
|
|
|
2011-11-07 22:28:49 +00:00
|
|
|
node->flag &= ~NODE_TEST;
|
|
|
|
|
|
2023-08-04 08:51:13 +10:00
|
|
|
LISTBASE_FOREACH (bNodeSocket *, input, &node->inputs) {
|
2019-03-26 21:16:47 +11:00
|
|
|
if (input->link) {
|
2011-11-07 22:28:49 +00:00
|
|
|
node_clear_recursive(input->link->fromnode);
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
|
|
|
|
}
|
2011-11-07 22:28:49 +00:00
|
|
|
}
|
|
|
|
|
|
2018-11-23 17:02:55 +01:00
|
|
|
static void node_remove_linked(Main *bmain, bNodeTree *ntree, bNode *rem_node)
|
2011-11-07 22:28:49 +00:00
|
|
|
{
|
|
|
|
|
bNode *node, *next;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-03-26 21:16:47 +11:00
|
|
|
if (!rem_node) {
|
2011-11-07 22:28:49 +00:00
|
|
|
return;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-11-07 22:28:49 +00:00
|
|
|
/* tag linked nodes to be removed */
|
2025-02-28 22:12:34 +01:00
|
|
|
for (bNode *node : ntree->all_nodes()) {
|
2011-11-07 22:28:49 +00:00
|
|
|
node->flag &= ~NODE_TEST;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-11-07 22:28:49 +00:00
|
|
|
node_tag_recursive(rem_node);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-11-07 22:28:49 +00:00
|
|
|
/* clear tags on nodes that are still used by other nodes */
|
2025-02-28 22:12:34 +01:00
|
|
|
for (bNode *node : ntree->all_nodes()) {
|
2019-03-26 21:16:47 +11:00
|
|
|
if (!(node->flag & NODE_TEST)) {
|
2023-08-04 08:51:13 +10:00
|
|
|
LISTBASE_FOREACH (bNodeSocket *, sock, &node->inputs) {
|
2019-03-26 21:16:47 +11:00
|
|
|
if (sock->link && sock->link->fromnode != rem_node) {
|
2011-11-07 22:28:49 +00:00
|
|
|
node_clear_recursive(sock->link->fromnode);
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-11-07 22:28:49 +00:00
|
|
|
/* remove nodes */
|
2021-06-02 17:19:36 +02:00
|
|
|
for (node = (bNode *)ntree->nodes.first; node; node = next) {
|
2011-11-07 22:28:49 +00:00
|
|
|
next = node->next;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (node->flag & NODE_TEST) {
|
2025-02-19 13:44:11 +01:00
|
|
|
bke::node_remove_node(bmain, *ntree, *node, true);
|
2011-11-07 22:28:49 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* disconnect socket from the node it is connected to */
|
|
|
|
|
static void node_socket_disconnect(Main *bmain,
|
|
|
|
|
bNodeTree *ntree,
|
|
|
|
|
bNode *node_to,
|
|
|
|
|
bNodeSocket *sock_to)
|
|
|
|
|
{
|
2019-03-26 21:16:47 +11:00
|
|
|
if (!sock_to->link) {
|
2011-11-07 22:28:49 +00:00
|
|
|
return;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2011-11-07 22:28:49 +00:00
|
|
|
|
2025-02-19 13:44:11 +01:00
|
|
|
bke::node_remove_link(ntree, *sock_to->link);
|
2012-10-24 21:57:16 +00:00
|
|
|
sock_to->flag |= SOCK_COLLAPSED;
|
2011-11-07 22:28:49 +00:00
|
|
|
|
2021-12-21 15:18:56 +01:00
|
|
|
BKE_ntree_update_tag_node_property(ntree, node_to);
|
2025-01-14 16:26:54 +01:00
|
|
|
BKE_main_ensure_invariants(*bmain, ntree->id);
|
2011-11-07 22:28:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* remove all nodes connected to this socket, if they aren't connected to other nodes */
|
|
|
|
|
static void node_socket_remove(Main *bmain, bNodeTree *ntree, bNode *node_to, bNodeSocket *sock_to)
|
|
|
|
|
{
|
2019-03-26 21:16:47 +11:00
|
|
|
if (!sock_to->link) {
|
2011-11-07 22:28:49 +00:00
|
|
|
return;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2011-11-07 22:28:49 +00:00
|
|
|
|
2018-11-23 17:02:55 +01:00
|
|
|
node_remove_linked(bmain, ntree, sock_to->link->fromnode);
|
2012-10-24 21:57:16 +00:00
|
|
|
sock_to->flag |= SOCK_COLLAPSED;
|
2011-11-07 22:28:49 +00:00
|
|
|
|
2021-12-21 15:18:56 +01:00
|
|
|
BKE_ntree_update_tag_node_property(ntree, node_to);
|
2025-01-14 16:26:54 +01:00
|
|
|
BKE_main_ensure_invariants(*bmain, ntree->id);
|
2011-11-07 22:28:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* add new node connected to this socket, or replace an existing one */
|
2013-04-18 11:36:11 +00:00
|
|
|
static void node_socket_add_replace(const bContext *C,
|
|
|
|
|
bNodeTree *ntree,
|
|
|
|
|
bNode *node_to,
|
|
|
|
|
bNodeSocket *sock_to,
|
|
|
|
|
int type,
|
|
|
|
|
NodeLinkItem *item)
|
2011-11-07 22:28:49 +00:00
|
|
|
{
|
2018-06-09 15:16:44 +02:00
|
|
|
Main *bmain = CTX_data_main(C);
|
2011-11-07 22:28:49 +00:00
|
|
|
bNode *node_from;
|
2012-10-12 14:35:10 +00:00
|
|
|
bNodeSocket *sock_from_tmp;
|
2021-06-02 17:19:36 +02:00
|
|
|
bNode *node_prev = nullptr;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-11-07 22:28:49 +00:00
|
|
|
/* unlink existing node */
|
2012-03-24 06:38:07 +00:00
|
|
|
if (sock_to->link) {
|
2011-11-07 22:28:49 +00:00
|
|
|
node_prev = sock_to->link->fromnode;
|
2025-02-19 13:44:11 +01:00
|
|
|
bke::node_remove_link(ntree, *sock_to->link);
|
2011-11-07 22:28:49 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-11-07 22:28:49 +00:00
|
|
|
/* find existing node that we can use */
|
2021-06-02 17:19:36 +02:00
|
|
|
for (node_from = (bNode *)ntree->nodes.first; node_from; node_from = node_from->next) {
|
2025-01-09 15:28:57 +01:00
|
|
|
if (node_from->type_legacy == type) {
|
2011-11-07 22:28:49 +00:00
|
|
|
break;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-03-26 21:16:47 +11:00
|
|
|
if (node_from) {
|
|
|
|
|
if (node_from->inputs.first || node_from->typeinfo->draw_buttons ||
|
|
|
|
|
node_from->typeinfo->draw_buttons_ex)
|
|
|
|
|
{
|
2021-06-02 17:19:36 +02:00
|
|
|
node_from = nullptr;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
2025-01-09 15:28:57 +01:00
|
|
|
if (node_prev && node_prev->type_legacy == type && node_link_item_compare(node_prev, item)) {
|
2011-11-07 22:28:49 +00:00
|
|
|
/* keep the previous node if it's the same type */
|
|
|
|
|
node_from = node_prev;
|
|
|
|
|
}
|
2012-03-24 06:38:07 +00:00
|
|
|
else if (!node_from) {
|
2025-02-19 13:44:11 +01:00
|
|
|
node_from = bke::node_add_static_node(C, *ntree, type);
|
2021-06-02 17:19:36 +02:00
|
|
|
if (node_prev != nullptr) {
|
2018-09-20 19:53:16 +02:00
|
|
|
/* If we're replacing existing node, use its location. */
|
2024-12-11 21:06:41 +01:00
|
|
|
node_from->location[0] = node_prev->location[0];
|
|
|
|
|
node_from->location[1] = node_prev->location[1];
|
2015-06-02 12:32:43 +05:00
|
|
|
}
|
|
|
|
|
else {
|
2021-06-02 17:19:36 +02:00
|
|
|
sock_from_tmp = (bNodeSocket *)BLI_findlink(&node_from->outputs, item->socket_index);
|
2025-02-19 13:44:11 +01:00
|
|
|
bke::node_position_relative(*node_from, *node_to, *sock_from_tmp, *sock_to);
|
2015-06-02 12:32:43 +05:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-03-16 11:23:45 +01:00
|
|
|
node_link_item_apply(ntree, node_from, item);
|
2025-01-14 16:26:54 +01:00
|
|
|
BKE_main_ensure_invariants(*bmain, ntree->id);
|
2011-11-07 22:28:49 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2025-02-19 13:44:11 +01:00
|
|
|
bke::node_set_active(*ntree, *node_from);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-11-07 22:28:49 +00:00
|
|
|
/* add link */
|
2021-06-02 17:19:36 +02:00
|
|
|
sock_from_tmp = (bNodeSocket *)BLI_findlink(&node_from->outputs, item->socket_index);
|
2025-02-19 13:44:11 +01:00
|
|
|
bke::node_add_link(*ntree, *node_from, *sock_from_tmp, *node_to, *sock_to);
|
2012-10-24 21:57:16 +00:00
|
|
|
sock_to->flag &= ~SOCK_COLLAPSED;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-11-07 22:28:49 +00:00
|
|
|
/* copy input sockets from previous node */
|
2012-03-24 06:38:07 +00:00
|
|
|
if (node_prev && node_from != node_prev) {
|
2023-08-04 08:51:13 +10:00
|
|
|
LISTBASE_FOREACH (bNodeSocket *, sock_prev, &node_prev->inputs) {
|
|
|
|
|
LISTBASE_FOREACH (bNodeSocket *, sock_from, &node_from->inputs) {
|
2025-02-19 13:44:11 +01:00
|
|
|
if (bke::node_count_socket_links(*ntree, *sock_from) >=
|
|
|
|
|
bke::node_socket_link_limit(*sock_from))
|
2024-08-19 20:27:37 +02:00
|
|
|
{
|
2012-03-20 17:56:12 +00:00
|
|
|
continue;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-08-04 16:32:33 +02:00
|
|
|
if (STREQ(sock_prev->identifier, sock_from->identifier) &&
|
2024-01-02 18:12:54 +01:00
|
|
|
sock_prev->type == sock_from->type)
|
|
|
|
|
{
|
2011-11-07 22:28:49 +00:00
|
|
|
bNodeLink *link = sock_prev->link;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (link && link->fromnode) {
|
2025-02-19 13:44:11 +01:00
|
|
|
bke::node_add_link(*ntree, *link->fromnode, *link->fromsock, *node_from, *sock_from);
|
|
|
|
|
bke::node_remove_link(ntree, *link);
|
2011-11-07 22:28:49 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-04-18 13:16:38 +00:00
|
|
|
node_socket_copy_default_value(sock_from, sock_prev);
|
2011-11-07 22:28:49 +00:00
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
2011-11-08 13:07:16 +00:00
|
|
|
/* also preserve mapping for texture nodes */
|
2012-03-24 06:38:07 +00:00
|
|
|
if (node_from->typeinfo->nclass == NODE_CLASS_TEXTURE &&
|
2020-08-25 11:23:35 +02:00
|
|
|
node_prev->typeinfo->nclass == NODE_CLASS_TEXTURE &&
|
|
|
|
|
/* White noise texture node does not have NodeTexBase. */
|
2021-06-02 17:19:36 +02:00
|
|
|
node_from->storage != nullptr && node_prev->storage != nullptr)
|
|
|
|
|
{
|
2011-11-08 13:07:16 +00:00
|
|
|
memcpy(node_from->storage, node_prev->storage, sizeof(NodeTexBase));
|
2012-04-28 06:31:57 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-11-07 22:28:49 +00:00
|
|
|
/* remove node */
|
2018-11-23 17:02:55 +01:00
|
|
|
node_remove_linked(bmain, ntree, node_prev);
|
2011-11-07 22:28:49 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-12-21 15:18:56 +01:00
|
|
|
BKE_ntree_update_tag_node_property(ntree, node_from);
|
|
|
|
|
BKE_ntree_update_tag_node_property(ntree, node_to);
|
2025-01-14 16:26:54 +01:00
|
|
|
BKE_main_ensure_invariants(*bmain, ntree->id);
|
2011-11-07 22:28:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/****************************** Node Link Menu *******************************/
|
|
|
|
|
|
2012-09-20 01:02:39 +00:00
|
|
|
// #define UI_NODE_LINK_ADD 0
|
2012-07-01 09:54:44 +00:00
|
|
|
#define UI_NODE_LINK_DISCONNECT -1
|
|
|
|
|
#define UI_NODE_LINK_REMOVE -2
|
2011-11-07 22:28:49 +00:00
|
|
|
|
2021-06-02 17:19:36 +02:00
|
|
|
struct NodeLinkArg {
|
2011-11-07 22:28:49 +00:00
|
|
|
Main *bmain;
|
|
|
|
|
Scene *scene;
|
|
|
|
|
bNodeTree *ntree;
|
|
|
|
|
bNode *node;
|
|
|
|
|
bNodeSocket *sock;
|
|
|
|
|
|
2024-05-13 16:07:12 +02:00
|
|
|
bke::bNodeType *node_type;
|
2013-04-18 11:36:11 +00:00
|
|
|
NodeLinkItem item;
|
2011-11-07 22:28:49 +00:00
|
|
|
|
|
|
|
|
uiLayout *layout;
|
2021-06-02 17:19:36 +02:00
|
|
|
};
|
2011-11-07 22:28:49 +00:00
|
|
|
|
2021-10-15 12:12:36 +02:00
|
|
|
static Vector<NodeLinkItem> ui_node_link_items(NodeLinkArg *arg,
|
|
|
|
|
int in_out,
|
|
|
|
|
std::optional<NodeDeclaration> &r_node_decl)
|
2013-04-18 11:36:11 +00:00
|
|
|
{
|
2021-10-15 12:12:36 +02:00
|
|
|
Vector<NodeLinkItem> items;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2025-01-09 15:28:57 +01:00
|
|
|
if (arg->node_type->type_legacy == NODE_GROUP) {
|
2024-12-19 15:00:31 -05:00
|
|
|
LISTBASE_FOREACH (bNodeTree *, ngroup, &arg->bmain->nodetrees) {
|
2024-12-19 15:04:03 -05:00
|
|
|
if (BKE_id_name(ngroup->id)[0] == '.') {
|
|
|
|
|
/* Don't display hidden node groups, just like the add menu. */
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-12 18:43:23 +02:00
|
|
|
const char *disabled_hint;
|
2024-05-13 16:07:12 +02:00
|
|
|
if ((ngroup->type != arg->ntree->type) ||
|
2024-08-19 20:27:37 +02:00
|
|
|
!bke::node_group_poll(arg->ntree, ngroup, &disabled_hint))
|
2021-10-15 12:12:36 +02:00
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2021-03-09 18:23:02 +01:00
|
|
|
|
2023-09-14 14:13:07 +02:00
|
|
|
ngroup->ensure_interface_cache();
|
2023-08-30 12:37:21 +02:00
|
|
|
Span<bNodeTreeInterfaceSocket *> iosockets = (in_out == SOCK_IN ?
|
|
|
|
|
ngroup->interface_inputs() :
|
|
|
|
|
ngroup->interface_outputs());
|
|
|
|
|
for (const int index : iosockets.index_range()) {
|
|
|
|
|
bNodeTreeInterfaceSocket *iosock = iosockets[index];
|
2021-10-15 12:12:36 +02:00
|
|
|
NodeLinkItem item;
|
2024-07-04 11:44:06 +02:00
|
|
|
node_link_item_init(item);
|
2021-10-15 12:12:36 +02:00
|
|
|
item.socket_index = index;
|
|
|
|
|
/* NOTE: int stemp->type is not fully reliable, not used for node group
|
|
|
|
|
* interface sockets. use the typeinfo->type instead.
|
|
|
|
|
*/
|
2024-05-13 16:07:12 +02:00
|
|
|
const bke::bNodeSocketType *typeinfo = iosock->socket_typeinfo();
|
2023-08-30 12:37:21 +02:00
|
|
|
item.socket_type = typeinfo->type;
|
|
|
|
|
item.socket_name = iosock->name;
|
2021-10-15 12:12:36 +02:00
|
|
|
item.node_name = ngroup->id.name + 2;
|
|
|
|
|
item.ngroup = ngroup;
|
|
|
|
|
|
|
|
|
|
items.append(item);
|
2013-04-18 11:36:11 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-10-15 12:12:36 +02:00
|
|
|
else if (arg->node_type->declare != nullptr) {
|
|
|
|
|
using namespace blender;
|
|
|
|
|
using namespace blender::nodes;
|
|
|
|
|
|
|
|
|
|
r_node_decl.emplace(NodeDeclaration());
|
2023-10-15 20:28:23 +02:00
|
|
|
blender::nodes::build_node_declaration(*arg->node_type, *r_node_decl, nullptr, nullptr);
|
2023-08-30 12:37:21 +02:00
|
|
|
Span<SocketDeclaration *> socket_decls = (in_out == SOCK_IN) ? r_node_decl->inputs :
|
|
|
|
|
r_node_decl->outputs;
|
2021-10-15 12:12:36 +02:00
|
|
|
int index = 0;
|
2023-08-30 12:37:21 +02:00
|
|
|
for (const SocketDeclaration *socket_decl_ptr : socket_decls) {
|
2021-10-15 12:12:36 +02:00
|
|
|
const SocketDeclaration &socket_decl = *socket_decl_ptr;
|
|
|
|
|
NodeLinkItem item;
|
2024-07-04 11:44:06 +02:00
|
|
|
node_link_item_init(item);
|
2021-10-15 12:12:36 +02:00
|
|
|
item.socket_index = index++;
|
2024-03-20 12:37:37 +01:00
|
|
|
item.socket_type = socket_decl.socket_type;
|
2022-12-29 14:55:27 -05:00
|
|
|
item.socket_name = socket_decl.name.c_str();
|
2025-01-08 16:34:41 +01:00
|
|
|
item.node_name = arg->node_type->ui_name.c_str();
|
2021-10-15 12:12:36 +02:00
|
|
|
items.append(item);
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-04-18 11:36:11 +00:00
|
|
|
else {
|
2024-05-13 16:07:12 +02:00
|
|
|
bke::bNodeSocketTemplate *socket_templates = (in_out == SOCK_IN ? arg->node_type->inputs :
|
|
|
|
|
arg->node_type->outputs);
|
|
|
|
|
bke::bNodeSocketTemplate *stemp;
|
2013-04-18 11:36:11 +00:00
|
|
|
int i;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-10-15 12:12:36 +02:00
|
|
|
i = 0;
|
|
|
|
|
for (stemp = socket_templates; stemp && stemp->type != -1; stemp++, i++) {
|
|
|
|
|
NodeLinkItem item;
|
2024-07-04 11:44:06 +02:00
|
|
|
node_link_item_init(item);
|
2021-10-15 12:12:36 +02:00
|
|
|
item.socket_index = i;
|
|
|
|
|
item.socket_type = stemp->type;
|
|
|
|
|
item.socket_name = stemp->name;
|
2025-01-08 16:34:41 +01:00
|
|
|
item.node_name = arg->node_type->ui_name.c_str();
|
2021-10-15 12:12:36 +02:00
|
|
|
items.append(item);
|
2013-04-18 11:36:11 +00:00
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-10-15 12:12:36 +02:00
|
|
|
return items;
|
2013-04-18 11:36:11 +00:00
|
|
|
}
|
|
|
|
|
|
2012-03-20 19:56:45 +00:00
|
|
|
static void ui_node_link(bContext *C, void *arg_p, void *event_p)
|
2011-11-07 22:28:49 +00:00
|
|
|
{
|
2012-07-01 09:54:44 +00:00
|
|
|
NodeLinkArg *arg = (NodeLinkArg *)arg_p;
|
2011-11-07 22:28:49 +00:00
|
|
|
Main *bmain = arg->bmain;
|
|
|
|
|
bNode *node_to = arg->node;
|
|
|
|
|
bNodeSocket *sock_to = arg->sock;
|
|
|
|
|
bNodeTree *ntree = arg->ntree;
|
2018-09-19 12:05:58 +10:00
|
|
|
int event = POINTER_AS_INT(event_p);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-03-26 21:16:47 +11:00
|
|
|
if (event == UI_NODE_LINK_DISCONNECT) {
|
2011-11-07 22:28:49 +00:00
|
|
|
node_socket_disconnect(bmain, ntree, node_to, sock_to);
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
|
|
|
|
else if (event == UI_NODE_LINK_REMOVE) {
|
2011-11-07 22:28:49 +00:00
|
|
|
node_socket_remove(bmain, ntree, node_to, sock_to);
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
|
|
|
|
else {
|
2025-01-09 15:28:57 +01:00
|
|
|
node_socket_add_replace(C, ntree, node_to, sock_to, arg->node_type->type_legacy, &arg->item);
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-20 19:56:45 +00:00
|
|
|
ED_undo_push(C, "Node input modify");
|
2011-11-07 22:28:49 +00:00
|
|
|
}
|
|
|
|
|
|
2021-12-13 16:22:21 +11:00
|
|
|
static void ui_node_sock_name(const bNodeTree *ntree,
|
|
|
|
|
bNodeSocket *sock,
|
|
|
|
|
char name[UI_MAX_NAME_STR])
|
2011-11-07 22:28:49 +00:00
|
|
|
{
|
2012-03-24 06:38:07 +00:00
|
|
|
if (sock->link && sock->link->fromnode) {
|
2011-11-07 22:28:49 +00:00
|
|
|
bNode *node = sock->link->fromnode;
|
2025-03-05 11:17:50 +01:00
|
|
|
const std::string node_name = bke::node_label(*ntree, *node);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-02-08 06:07:10 +11:00
|
|
|
if (BLI_listbase_is_empty(&node->inputs) && node->outputs.first != node->outputs.last) {
|
2025-03-05 11:17:50 +01:00
|
|
|
BLI_snprintf(name,
|
|
|
|
|
UI_MAX_NAME_STR,
|
|
|
|
|
"%s | %s",
|
|
|
|
|
IFACE_(node_name.c_str()),
|
|
|
|
|
IFACE_(sock->link->fromsock->name));
|
2012-04-28 06:31:57 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2025-03-05 11:17:50 +01:00
|
|
|
BLI_strncpy_utf8(name, IFACE_(node_name.c_str()), UI_MAX_NAME_STR);
|
2012-04-28 06:31:57 +00:00
|
|
|
}
|
2011-11-07 22:28:49 +00:00
|
|
|
}
|
2019-03-26 21:16:47 +11:00
|
|
|
else if (sock->type == SOCK_SHADER) {
|
2023-05-13 17:38:48 +10:00
|
|
|
BLI_strncpy_utf8(name, IFACE_("None"), UI_MAX_NAME_STR);
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
|
|
|
|
else {
|
2023-05-13 17:38:48 +10:00
|
|
|
BLI_strncpy_utf8(name, IFACE_("Default"), UI_MAX_NAME_STR);
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2011-11-07 22:28:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int ui_compatible_sockets(int typeA, int typeB)
|
|
|
|
|
{
|
|
|
|
|
return (typeA == typeB);
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-27 00:58:25 +02:00
|
|
|
static int ui_node_item_name_compare(const void *a, const void *b)
|
|
|
|
|
{
|
2024-05-13 16:07:12 +02:00
|
|
|
const bke::bNodeType *type_a = *(const bke::bNodeType **)a;
|
|
|
|
|
const bke::bNodeType *type_b = *(const bke::bNodeType **)b;
|
2025-01-08 16:34:41 +01:00
|
|
|
return BLI_strcasecmp_natural(type_a->ui_name.c_str(), type_b->ui_name.c_str());
|
2016-04-27 00:58:25 +02:00
|
|
|
}
|
|
|
|
|
|
2024-05-13 16:07:12 +02:00
|
|
|
static bool ui_node_item_special_poll(const bNodeTree * /*ntree*/, const bke::bNodeType *ntype)
|
2016-08-17 14:51:25 +02:00
|
|
|
{
|
2025-01-08 16:34:41 +01:00
|
|
|
if (ntype->idname == "ShaderNodeUVAlongStroke") {
|
2016-08-17 14:51:25 +02:00
|
|
|
/* TODO(sergey): Currently we don't have Freestyle nodes edited from
|
|
|
|
|
* the buttons context, so can ignore its nodes completely.
|
|
|
|
|
*
|
|
|
|
|
* However, we might want to do some extra checks here later.
|
|
|
|
|
*/
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-07 22:28:49 +00:00
|
|
|
static void ui_node_menu_column(NodeLinkArg *arg, int nclass, const char *cname)
|
|
|
|
|
{
|
|
|
|
|
bNodeTree *ntree = arg->ntree;
|
|
|
|
|
bNodeSocket *sock = arg->sock;
|
|
|
|
|
uiLayout *layout = arg->layout;
|
2021-06-02 17:19:36 +02:00
|
|
|
uiLayout *column = nullptr;
|
2011-11-07 22:28:49 +00:00
|
|
|
uiBlock *block = uiLayoutGetBlock(layout);
|
|
|
|
|
uiBut *but;
|
|
|
|
|
NodeLinkArg *argN;
|
|
|
|
|
int first = 1;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-04-27 00:58:25 +02:00
|
|
|
/* generate array of node types sorted by UI name */
|
2024-05-13 16:07:12 +02:00
|
|
|
blender::Vector<bke::bNodeType *> sorted_ntypes;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2024-12-23 17:45:15 +01:00
|
|
|
for (blender::bke::bNodeType *ntype : blender::bke::node_types_get()) {
|
2021-04-12 18:43:23 +02:00
|
|
|
const char *disabled_hint;
|
|
|
|
|
if (!(ntype->poll && ntype->poll(ntype, ntree, &disabled_hint))) {
|
2018-07-10 11:39:57 +02:00
|
|
|
continue;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-08-17 14:51:25 +02:00
|
|
|
if (ntype->nclass != nclass) {
|
2016-04-27 00:58:25 +02:00
|
|
|
continue;
|
2016-08-17 14:51:25 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-08-17 14:51:25 +02:00
|
|
|
if (!ui_node_item_special_poll(ntree, ntype)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-06-02 17:19:36 +02:00
|
|
|
sorted_ntypes.append(ntype);
|
2018-11-30 15:35:15 +11:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2024-05-13 16:07:12 +02:00
|
|
|
qsort(sorted_ntypes.data(),
|
|
|
|
|
sorted_ntypes.size(),
|
|
|
|
|
sizeof(bke::bNodeType *),
|
|
|
|
|
ui_node_item_name_compare);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-04-27 00:58:25 +02:00
|
|
|
/* generate UI */
|
2021-06-02 17:19:36 +02:00
|
|
|
for (int j = 0; j < sorted_ntypes.size(); j++) {
|
2024-05-13 16:07:12 +02:00
|
|
|
bke::bNodeType *ntype = sorted_ntypes[j];
|
2013-03-18 16:34:57 +00:00
|
|
|
char name[UI_MAX_NAME_STR];
|
2021-06-02 17:19:36 +02:00
|
|
|
const char *cur_node_name = nullptr;
|
2020-09-09 18:41:07 +02:00
|
|
|
int num = 0;
|
2013-12-04 00:00:09 +01:00
|
|
|
int icon = ICON_NONE;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-04-18 11:36:11 +00:00
|
|
|
arg->node_type = ntype;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-10-15 12:12:36 +02:00
|
|
|
std::optional<blender::nodes::NodeDeclaration> node_decl;
|
|
|
|
|
Vector<NodeLinkItem> items = ui_node_link_items(arg, SOCK_OUT, node_decl);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-10-15 12:12:36 +02:00
|
|
|
for (const NodeLinkItem &item : items) {
|
|
|
|
|
if (ui_compatible_sockets(item.socket_type, sock->type)) {
|
2013-03-18 16:34:57 +00:00
|
|
|
num++;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-10-15 12:12:36 +02:00
|
|
|
for (const NodeLinkItem &item : items) {
|
|
|
|
|
if (!ui_compatible_sockets(item.socket_type, sock->type)) {
|
2011-11-07 22:28:49 +00:00
|
|
|
continue;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
if (first) {
|
2021-06-02 17:19:36 +02:00
|
|
|
column = uiLayoutColumn(layout, false);
|
2013-03-18 16:34:57 +00:00
|
|
|
UI_block_layout_set_current(block, column);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-11-09 21:20:40 +01:00
|
|
|
uiItemL(column, IFACE_(cname), ICON_NODE);
|
2025-02-14 15:29:26 +01:00
|
|
|
but = block->buttons.last().get();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
first = 0;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
2013-03-18 16:34:57 +00:00
|
|
|
if (num > 1) {
|
2021-10-15 12:12:36 +02:00
|
|
|
if (!cur_node_name || !STREQ(cur_node_name, item.node_name)) {
|
|
|
|
|
cur_node_name = item.node_name;
|
2013-03-18 16:34:57 +00:00
|
|
|
/* XXX Do not use uiItemL here,
|
|
|
|
|
* it would add an empty icon as we are in a menu! */
|
|
|
|
|
uiDefBut(block,
|
|
|
|
|
UI_BTYPE_LABEL,
|
|
|
|
|
0,
|
2013-04-23 17:49:26 +00:00
|
|
|
IFACE_(cur_node_name),
|
2019-01-15 23:24:20 +11:00
|
|
|
0,
|
2014-11-09 21:20:40 +01:00
|
|
|
0,
|
|
|
|
|
UI_UNIT_X * 4,
|
|
|
|
|
UI_UNIT_Y,
|
2021-06-02 17:19:36 +02:00
|
|
|
nullptr,
|
2013-12-04 00:00:09 +01:00
|
|
|
0.0,
|
|
|
|
|
0.0,
|
|
|
|
|
"");
|
2011-11-07 22:28:49 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2023-05-09 12:50:37 +10:00
|
|
|
SNPRINTF(name, "%s", IFACE_(item.socket_name));
|
2013-12-04 00:00:09 +01:00
|
|
|
icon = ICON_BLANK1;
|
2011-11-07 22:28:49 +00:00
|
|
|
}
|
2013-12-04 00:00:09 +01:00
|
|
|
else {
|
2023-05-13 17:38:48 +10:00
|
|
|
STRNCPY_UTF8(name, IFACE_(item.node_name));
|
2013-12-04 00:00:09 +01:00
|
|
|
icon = ICON_NONE;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-11-09 21:20:40 +01:00
|
|
|
but = uiDefIconTextBut(block,
|
|
|
|
|
UI_BTYPE_BUT,
|
|
|
|
|
0,
|
|
|
|
|
icon,
|
|
|
|
|
name,
|
|
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
UI_UNIT_X * 4,
|
|
|
|
|
UI_UNIT_Y,
|
2021-06-02 17:19:36 +02:00
|
|
|
nullptr,
|
2013-12-04 00:00:09 +01:00
|
|
|
0.0,
|
|
|
|
|
0.0,
|
|
|
|
|
TIP_("Add node to input"));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-06-02 17:19:36 +02:00
|
|
|
argN = (NodeLinkArg *)MEM_dupallocN(arg);
|
2021-10-15 12:12:36 +02:00
|
|
|
argN->item = item;
|
2021-06-02 17:19:36 +02:00
|
|
|
UI_but_funcN_set(but, ui_node_link, argN, nullptr);
|
2011-11-07 22:28:49 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2011-11-07 22:28:49 +00:00
|
|
|
}
|
|
|
|
|
|
2024-12-02 19:24:07 +01:00
|
|
|
static void node_menu_column_foreach_cb(void *calldata, int nclass, const StringRefNull name)
|
2011-11-07 22:28:49 +00:00
|
|
|
{
|
2012-07-01 09:54:44 +00:00
|
|
|
NodeLinkArg *arg = (NodeLinkArg *)calldata;
|
2011-11-07 22:28:49 +00:00
|
|
|
|
2019-03-26 21:16:47 +11:00
|
|
|
if (!ELEM(nclass, NODE_CLASS_GROUP, NODE_CLASS_LAYOUT)) {
|
2024-12-02 19:24:07 +01:00
|
|
|
ui_node_menu_column(arg, nclass, name.c_str());
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2011-11-07 22:28:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void ui_template_node_link_menu(bContext *C, uiLayout *layout, void *but_p)
|
|
|
|
|
{
|
2012-07-01 09:54:44 +00:00
|
|
|
Main *bmain = CTX_data_main(C);
|
|
|
|
|
Scene *scene = CTX_data_scene(C);
|
2011-11-07 22:28:49 +00:00
|
|
|
uiBlock *block = uiLayoutGetBlock(layout);
|
2012-07-01 09:54:44 +00:00
|
|
|
uiBut *but = (uiBut *)but_p;
|
2011-11-07 22:28:49 +00:00
|
|
|
uiLayout *split, *column;
|
2012-07-01 09:54:44 +00:00
|
|
|
NodeLinkArg *arg = (NodeLinkArg *)but->func_argN;
|
2011-11-07 22:28:49 +00:00
|
|
|
bNodeSocket *sock = arg->sock;
|
2024-05-13 16:07:12 +02:00
|
|
|
bke::bNodeTreeType *ntreetype = arg->ntree->typeinfo;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-11-09 21:20:40 +01:00
|
|
|
UI_block_layout_set_current(block, layout);
|
2014-04-01 11:34:00 +11:00
|
|
|
split = uiLayoutSplit(layout, 0.0f, false);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-07-01 09:54:44 +00:00
|
|
|
arg->bmain = bmain;
|
|
|
|
|
arg->scene = scene;
|
|
|
|
|
arg->layout = split;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-03-26 21:16:47 +11:00
|
|
|
if (ntreetype && ntreetype->foreach_nodeclass) {
|
2024-05-10 19:20:03 +02:00
|
|
|
ntreetype->foreach_nodeclass(arg, node_menu_column_foreach_cb);
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-04-01 11:34:00 +11:00
|
|
|
column = uiLayoutColumn(split, false);
|
2014-11-09 21:20:40 +01:00
|
|
|
UI_block_layout_set_current(block, column);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (sock->link) {
|
2012-06-02 19:58:12 +00:00
|
|
|
uiItemL(column, IFACE_("Link"), ICON_NONE);
|
2025-02-14 15:29:26 +01:00
|
|
|
but = block->buttons.last().get();
|
2018-06-08 23:56:28 +02:00
|
|
|
but->drawflag = UI_BUT_TEXT_LEFT;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-11-21 14:43:08 +01:00
|
|
|
but = uiDefBut(block,
|
|
|
|
|
UI_BTYPE_BUT,
|
2014-11-09 21:20:40 +01:00
|
|
|
0,
|
2024-06-13 12:15:55 +02:00
|
|
|
CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Remove"),
|
2014-11-09 21:20:40 +01:00
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
UI_UNIT_X * 4,
|
|
|
|
|
UI_UNIT_Y,
|
2021-06-02 17:19:36 +02:00
|
|
|
nullptr,
|
2012-07-01 09:54:44 +00:00
|
|
|
0.0,
|
|
|
|
|
0.0,
|
|
|
|
|
TIP_("Remove nodes connected to the input"));
|
2018-09-19 12:05:58 +10:00
|
|
|
UI_but_funcN_set(but, ui_node_link, MEM_dupallocN(arg), POINTER_FROM_INT(UI_NODE_LINK_REMOVE));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-11-09 21:20:40 +01:00
|
|
|
but = uiDefBut(block,
|
|
|
|
|
UI_BTYPE_BUT,
|
|
|
|
|
0,
|
|
|
|
|
IFACE_("Disconnect"),
|
|
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
UI_UNIT_X * 4,
|
|
|
|
|
UI_UNIT_Y,
|
2021-06-02 17:19:36 +02:00
|
|
|
nullptr,
|
2012-07-01 09:54:44 +00:00
|
|
|
0.0,
|
|
|
|
|
0.0,
|
|
|
|
|
TIP_("Disconnect nodes connected to the input"));
|
2018-09-19 12:05:58 +10:00
|
|
|
UI_but_funcN_set(
|
|
|
|
|
but, ui_node_link, MEM_dupallocN(arg), POINTER_FROM_INT(UI_NODE_LINK_DISCONNECT));
|
2011-11-07 22:28:49 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-05-22 08:36:06 +00:00
|
|
|
ui_node_menu_column(arg, NODE_CLASS_GROUP, N_("Group"));
|
2011-11-07 22:28:49 +00:00
|
|
|
}
|
|
|
|
|
|
2022-01-20 10:36:56 -06:00
|
|
|
} // namespace blender::ed::space_node
|
|
|
|
|
|
2020-04-16 15:09:49 +02:00
|
|
|
void uiTemplateNodeLink(
|
2023-11-01 09:29:56 +01:00
|
|
|
uiLayout *layout, bContext *C, bNodeTree *ntree, bNode *node, bNodeSocket *input)
|
2011-11-07 22:28:49 +00:00
|
|
|
{
|
2022-01-20 10:36:56 -06:00
|
|
|
using namespace blender::ed::space_node;
|
|
|
|
|
|
2011-11-07 22:28:49 +00:00
|
|
|
uiBlock *block = uiLayoutGetBlock(layout);
|
|
|
|
|
NodeLinkArg *arg;
|
|
|
|
|
uiBut *but;
|
2020-04-16 15:09:49 +02:00
|
|
|
float socket_col[4];
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2025-03-05 16:35:09 +01:00
|
|
|
arg = MEM_callocN<NodeLinkArg>("NodeLinkArg");
|
2011-11-07 22:28:49 +00:00
|
|
|
arg->ntree = ntree;
|
|
|
|
|
arg->node = node;
|
2020-09-04 20:59:13 +02:00
|
|
|
arg->sock = input;
|
2024-07-04 11:44:06 +02:00
|
|
|
node_link_item_init(arg->item);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2025-01-24 16:45:32 +01:00
|
|
|
PointerRNA node_ptr = RNA_pointer_create_discrete(&ntree->id, &RNA_Node, node);
|
2023-11-01 09:29:56 +01:00
|
|
|
node_socket_color_get(*C, *ntree, node_ptr, *input, socket_col);
|
2020-04-16 15:09:49 +02:00
|
|
|
|
2014-11-09 21:20:40 +01:00
|
|
|
UI_block_layout_set_current(block, layout);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-09-04 20:59:13 +02:00
|
|
|
if (input->link || input->type == SOCK_SHADER || (input->flag & SOCK_HIDE_VALUE)) {
|
2011-11-07 22:28:49 +00:00
|
|
|
char name[UI_MAX_NAME_STR];
|
2020-09-04 20:59:13 +02:00
|
|
|
ui_node_sock_name(ntree, input, name);
|
2012-07-01 09:54:44 +00:00
|
|
|
but = uiDefMenuBut(
|
2021-06-02 17:19:36 +02:00
|
|
|
block, ui_template_node_link_menu, nullptr, name, 0, 0, UI_UNIT_X * 4, UI_UNIT_Y, "");
|
2011-11-07 22:28:49 +00:00
|
|
|
}
|
2019-03-26 21:16:47 +11:00
|
|
|
else {
|
2012-03-24 02:51:46 +00:00
|
|
|
but = uiDefIconMenuBut(
|
2021-06-02 17:19:36 +02:00
|
|
|
block, ui_template_node_link_menu, nullptr, ICON_NONE, 0, 0, UI_UNIT_X, UI_UNIT_Y, "");
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-11-09 21:20:40 +01:00
|
|
|
UI_but_type_set_menu_from_pulldown(but);
|
2020-09-04 20:59:13 +02:00
|
|
|
UI_but_node_link_set(but, input, socket_col);
|
2020-04-16 15:21:06 +02:00
|
|
|
UI_but_drawflag_enable(but, UI_BUT_ICON_LEFT);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-07-01 09:54:44 +00:00
|
|
|
but->poin = (char *)but;
|
2011-11-07 22:28:49 +00:00
|
|
|
but->func_argN = arg;
|
2024-07-05 17:09:40 +02:00
|
|
|
but->func_argN_free_fn = MEM_freeN;
|
|
|
|
|
but->func_argN_copy_fn = MEM_dupallocN;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-09-04 20:59:13 +02:00
|
|
|
if (input->link && input->link->fromnode) {
|
|
|
|
|
if (input->link->fromnode->flag & NODE_ACTIVE_TEXTURE) {
|
2011-11-08 13:07:16 +00:00
|
|
|
but->flag |= UI_BUT_NODE_ACTIVE;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
|
|
|
|
}
|
2011-11-07 22:28:49 +00:00
|
|
|
}
|
|
|
|
|
|
2022-01-20 10:36:56 -06:00
|
|
|
namespace blender::ed::space_node {
|
|
|
|
|
|
2011-11-07 22:28:49 +00:00
|
|
|
/**************************** Node Tree Layout *******************************/
|
|
|
|
|
|
2023-09-20 17:43:19 +02:00
|
|
|
static void ui_node_draw_input(uiLayout &layout,
|
|
|
|
|
bContext &C,
|
|
|
|
|
bNodeTree &ntree,
|
|
|
|
|
bNode &node,
|
|
|
|
|
bNodeSocket &input,
|
|
|
|
|
int depth,
|
|
|
|
|
const char *panel_label);
|
|
|
|
|
|
2024-10-11 12:20:58 +02:00
|
|
|
static void ui_node_draw_recursive(uiLayout &layout,
|
|
|
|
|
bContext &C,
|
|
|
|
|
bNodeTree &ntree,
|
|
|
|
|
bNode &node,
|
|
|
|
|
const nodes::PanelDeclaration &panel_decl,
|
|
|
|
|
const int depth)
|
|
|
|
|
{
|
2025-02-28 20:06:28 +01:00
|
|
|
const nodes::SocketDeclaration *panel_toggle_decl = panel_decl.panel_input_decl();
|
2025-03-06 10:38:47 +01:00
|
|
|
const std::string panel_id = fmt::format(
|
|
|
|
|
"{}_{}_{}", ntree.id.name, node.identifier, panel_decl.identifier);
|
2025-02-28 20:06:28 +01:00
|
|
|
PanelLayout panel_layout = uiLayoutPanel(
|
2025-03-06 10:38:47 +01:00
|
|
|
&C, &layout, panel_id.c_str(), panel_decl.default_collapsed);
|
2025-02-28 20:06:28 +01:00
|
|
|
if (panel_toggle_decl) {
|
|
|
|
|
uiLayoutSetPropSep(panel_layout.header, false);
|
|
|
|
|
uiLayoutSetPropDecorate(panel_layout.header, false);
|
|
|
|
|
PointerRNA toggle_ptr = RNA_pointer_create_discrete(
|
|
|
|
|
&ntree.id, &RNA_NodeSocket, &node.socket_by_decl(*panel_toggle_decl));
|
|
|
|
|
uiItemR(panel_layout.header,
|
|
|
|
|
&toggle_ptr,
|
|
|
|
|
"default_value",
|
|
|
|
|
UI_ITEM_NONE,
|
|
|
|
|
panel_decl.name,
|
|
|
|
|
ICON_NONE);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
uiItemL(panel_layout.header, panel_decl.name, ICON_NONE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!panel_layout.body) {
|
2024-10-11 12:20:58 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
for (const nodes::ItemDeclaration *item_decl : panel_decl.items) {
|
2025-02-28 20:06:28 +01:00
|
|
|
if (item_decl == panel_toggle_decl) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2024-10-11 12:20:58 +02:00
|
|
|
if (const auto *socket_decl = dynamic_cast<const nodes::SocketDeclaration *>(item_decl)) {
|
|
|
|
|
if (socket_decl->in_out == SOCK_IN) {
|
2025-02-28 20:06:28 +01:00
|
|
|
ui_node_draw_input(*panel_layout.body,
|
2024-10-11 12:20:58 +02:00
|
|
|
C,
|
|
|
|
|
ntree,
|
|
|
|
|
node,
|
|
|
|
|
node.socket_by_decl(*socket_decl),
|
|
|
|
|
depth,
|
|
|
|
|
panel_decl.name.c_str());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (const auto *sub_panel_decl = dynamic_cast<const nodes::PanelDeclaration *>(item_decl))
|
|
|
|
|
{
|
2025-02-28 20:06:28 +01:00
|
|
|
ui_node_draw_recursive(*panel_layout.body, C, ntree, node, *sub_panel_decl, depth + 1);
|
2024-10-11 12:20:58 +02:00
|
|
|
}
|
|
|
|
|
else if (const auto *layout_decl = dynamic_cast<const nodes::LayoutDeclaration *>(item_decl)) {
|
2025-01-24 16:45:32 +01:00
|
|
|
PointerRNA nodeptr = RNA_pointer_create_discrete(&ntree.id, &RNA_Node, &node);
|
2025-02-28 20:06:28 +01:00
|
|
|
layout_decl->draw(panel_layout.body, &C, &nodeptr);
|
2024-10-11 12:20:58 +02:00
|
|
|
}
|
2023-09-20 17:54:18 +02:00
|
|
|
}
|
2023-09-20 17:43:19 +02:00
|
|
|
}
|
2011-11-07 22:28:49 +00:00
|
|
|
|
|
|
|
|
static void ui_node_draw_node(
|
2022-09-02 16:38:08 -05:00
|
|
|
uiLayout &layout, bContext &C, bNodeTree &ntree, bNode &node, int depth)
|
2011-11-07 22:28:49 +00:00
|
|
|
{
|
2025-01-24 16:45:32 +01:00
|
|
|
PointerRNA nodeptr = RNA_pointer_create_discrete(&ntree.id, &RNA_Node, &node);
|
2011-11-07 22:28:49 +00:00
|
|
|
|
2023-09-20 17:43:19 +02:00
|
|
|
if (node.declaration() && node.declaration()->use_custom_socket_order) {
|
2024-10-11 12:20:58 +02:00
|
|
|
const nodes::NodeDeclaration &node_decl = *node.declaration();
|
|
|
|
|
for (const nodes::ItemDeclaration *item_decl : node_decl.root_items) {
|
|
|
|
|
if (const auto *panel_decl = dynamic_cast<const nodes::PanelDeclaration *>(item_decl)) {
|
|
|
|
|
ui_node_draw_recursive(layout, C, ntree, node, *panel_decl, depth + 1);
|
|
|
|
|
}
|
|
|
|
|
else if (const auto *socket_decl = dynamic_cast<const nodes::SocketDeclaration *>(item_decl))
|
2023-09-20 17:43:19 +02:00
|
|
|
{
|
|
|
|
|
if (socket_decl->in_out == SOCK_IN) {
|
2024-10-11 12:20:58 +02:00
|
|
|
ui_node_draw_input(
|
2025-02-26 00:27:03 +01:00
|
|
|
layout, C, ntree, node, node.socket_by_decl(*socket_decl), depth + 1, nullptr);
|
2023-09-20 17:43:19 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
2024-10-11 12:20:58 +02:00
|
|
|
if (node.typeinfo->draw_buttons) {
|
2025-01-09 15:28:57 +01:00
|
|
|
if (node.type_legacy != NODE_GROUP) {
|
2024-10-11 12:20:58 +02:00
|
|
|
uiLayoutSetPropSep(&layout, true);
|
|
|
|
|
node.typeinfo->draw_buttons(&layout, &C, &nodeptr);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-20 17:43:19 +02:00
|
|
|
LISTBASE_FOREACH (bNodeSocket *, input, &node.inputs) {
|
|
|
|
|
ui_node_draw_input(layout, C, ntree, node, *input, depth + 1, nullptr);
|
|
|
|
|
}
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2011-11-07 22:28:49 +00:00
|
|
|
}
|
|
|
|
|
|
2023-09-20 17:43:19 +02:00
|
|
|
static void ui_node_draw_input(uiLayout &layout,
|
|
|
|
|
bContext &C,
|
|
|
|
|
bNodeTree &ntree,
|
|
|
|
|
bNode &node,
|
|
|
|
|
bNodeSocket &input,
|
|
|
|
|
int depth,
|
|
|
|
|
const char *panel_label)
|
2011-11-07 22:28:49 +00:00
|
|
|
{
|
2022-09-02 16:38:08 -05:00
|
|
|
uiBlock *block = uiLayoutGetBlock(&layout);
|
2021-06-02 17:19:36 +02:00
|
|
|
uiLayout *row = nullptr;
|
2020-05-01 15:21:41 +02:00
|
|
|
bool dependency_loop;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-09-02 16:38:08 -05:00
|
|
|
if (input.flag & SOCK_UNAVAIL) {
|
2011-11-07 22:28:49 +00:00
|
|
|
return;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-11-07 22:28:49 +00:00
|
|
|
/* to avoid eternal loops on cyclic dependencies */
|
2022-09-02 16:38:08 -05:00
|
|
|
node.flag |= NODE_TEST;
|
|
|
|
|
bNode *lnode = (input.link) ? input.link->fromnode : nullptr;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-11-14 20:26:23 +00:00
|
|
|
dependency_loop = (lnode && (lnode->flag & NODE_TEST));
|
2019-03-26 21:16:47 +11:00
|
|
|
if (dependency_loop) {
|
2021-06-02 17:19:36 +02:00
|
|
|
lnode = nullptr;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-11-07 22:28:49 +00:00
|
|
|
/* socket RNA pointer */
|
2025-01-24 16:45:32 +01:00
|
|
|
PointerRNA inputptr = RNA_pointer_create_discrete(&ntree.id, &RNA_NodeSocket, &input);
|
|
|
|
|
PointerRNA nodeptr = RNA_pointer_create_discrete(&ntree.id, &RNA_Node, &node);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-09-02 16:38:08 -05:00
|
|
|
row = uiLayoutRow(&layout, true);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-05-01 15:21:41 +02:00
|
|
|
uiPropertySplitWrapper split_wrapper = uiItemPropertySplitWrapperCreate(row);
|
2024-09-20 13:03:35 +02:00
|
|
|
/* Decorations are added manually here. */
|
|
|
|
|
uiLayoutSetPropDecorate(row, false);
|
2020-05-01 15:21:41 +02:00
|
|
|
/* Empty decorator item for alignment. */
|
|
|
|
|
bool add_dummy_decorator = false;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-05-01 15:21:41 +02:00
|
|
|
{
|
|
|
|
|
uiLayout *sub = uiLayoutRow(split_wrapper.label_column, true);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-05-01 15:21:41 +02:00
|
|
|
if (depth > 0) {
|
2025-03-31 00:36:46 +02:00
|
|
|
UI_block_emboss_set(block, blender::ui::EmbossType::None);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2025-01-09 15:28:57 +01:00
|
|
|
if (lnode && (lnode->inputs.first ||
|
|
|
|
|
(lnode->typeinfo->draw_buttons && lnode->type_legacy != NODE_GROUP)))
|
2024-01-02 18:12:54 +01:00
|
|
|
{
|
2024-01-30 22:35:15 +01:00
|
|
|
int icon = (input.flag & SOCK_COLLAPSED) ? ICON_RIGHTARROW : ICON_DOWNARROW_HLT;
|
2020-05-01 15:21:41 +02:00
|
|
|
uiItemR(sub, &inputptr, "show_expanded", UI_ITEM_R_ICON_ONLY, "", icon);
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2025-03-31 00:36:46 +02:00
|
|
|
UI_block_emboss_set(block, blender::ui::EmbossType::Emboss);
|
2020-05-01 15:21:41 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-05-01 15:21:41 +02:00
|
|
|
sub = uiLayoutRow(sub, true);
|
|
|
|
|
uiLayoutSetAlignment(sub, UI_LAYOUT_ALIGN_RIGHT);
|
2023-09-20 17:43:19 +02:00
|
|
|
uiItemL(sub, node_socket_get_label(&input, panel_label), ICON_NONE);
|
2011-11-07 22:28:49 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-03-24 06:38:07 +00:00
|
|
|
if (dependency_loop) {
|
2024-01-11 19:49:03 +01:00
|
|
|
uiItemL(row, RPT_("Dependency Loop"), ICON_ERROR);
|
2020-05-01 15:21:41 +02:00
|
|
|
add_dummy_decorator = true;
|
2011-11-14 20:26:23 +00:00
|
|
|
}
|
2012-03-24 06:38:07 +00:00
|
|
|
else if (lnode) {
|
2011-11-07 22:28:49 +00:00
|
|
|
/* input linked to a node */
|
2022-09-02 16:38:08 -05:00
|
|
|
uiTemplateNodeLink(row, &C, &ntree, &node, &input);
|
2020-05-01 15:21:41 +02:00
|
|
|
add_dummy_decorator = true;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-09-02 16:38:08 -05:00
|
|
|
if (depth == 0 || !(input.flag & SOCK_COLLAPSED)) {
|
2019-03-26 21:16:47 +11:00
|
|
|
if (depth == 0) {
|
2022-09-02 16:38:08 -05:00
|
|
|
uiItemS(&layout);
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2022-09-02 16:38:08 -05:00
|
|
|
ui_node_draw_node(layout, C, ntree, *lnode, depth);
|
2011-11-07 22:28:49 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2011-11-07 22:28:49 +00:00
|
|
|
else {
|
UI: Add support for showing socket descriptions in tooltips
Currently, hovering over a socket itself shows no tooltip at all, while
hovering over its value field shows "Default value", which is not helpful.
This patch therefore implements socket tooltips following the proposal at
https://blender.community/c/rightclickselect/2Qgbbc/.
A lot of the basic functionality was already implemented for Geometry Nodes,
where hovering over the socket itself shows introspection info.
This patch extends this by:
- Supporting dynamic tooltips on labels, which is important for good tooltip
coverage in a socket's region of the node.
- Adding a function to setting a dynamic tooltip for an entire uiLayout, which
avoids needing to set it manually for a wide variety of socket types.
- Hiding the property label field in a tooltip when dynamic tooltip is also
provided. If really needed, this label can be restored through the dynamic
tooltip, but in all current cases the label is actually pointless anyways
since the dynamic tooltip gives more accurate and specific information.
- Adding dynamic tooltips to a socket's UI layout row if it has a description
configured, both in the Node Editor as well as in the Material Properties.
Note that the patch does not add any actual tooltip content yet, just the
infrastructure to show them. By default, sockets without a description still
show the old "Default value" tooltip.
For an example of how to add socket descriptions, check the Cylinder node
in the Geometry Nodes.
Differential Revision: https://developer.blender.org/D9967
2022-04-11 02:02:12 +02:00
|
|
|
uiLayout *sub = uiLayoutRow(row, true);
|
2020-04-16 15:21:06 +02:00
|
|
|
|
2022-09-02 16:38:08 -05:00
|
|
|
uiTemplateNodeLink(sub, &C, &ntree, &node, &input);
|
2020-04-16 15:21:06 +02:00
|
|
|
|
2022-09-02 16:38:08 -05:00
|
|
|
if (input.flag & SOCK_HIDE_VALUE) {
|
2020-05-01 15:21:41 +02:00
|
|
|
add_dummy_decorator = true;
|
|
|
|
|
}
|
2011-11-07 22:28:49 +00:00
|
|
|
/* input not linked, show value */
|
2020-05-01 15:21:41 +02:00
|
|
|
else {
|
2022-09-02 16:38:08 -05:00
|
|
|
switch (input.type) {
|
2020-05-01 15:21:41 +02:00
|
|
|
case SOCK_VECTOR:
|
UI: Add support for showing socket descriptions in tooltips
Currently, hovering over a socket itself shows no tooltip at all, while
hovering over its value field shows "Default value", which is not helpful.
This patch therefore implements socket tooltips following the proposal at
https://blender.community/c/rightclickselect/2Qgbbc/.
A lot of the basic functionality was already implemented for Geometry Nodes,
where hovering over the socket itself shows introspection info.
This patch extends this by:
- Supporting dynamic tooltips on labels, which is important for good tooltip
coverage in a socket's region of the node.
- Adding a function to setting a dynamic tooltip for an entire uiLayout, which
avoids needing to set it manually for a wide variety of socket types.
- Hiding the property label field in a tooltip when dynamic tooltip is also
provided. If really needed, this label can be restored through the dynamic
tooltip, but in all current cases the label is actually pointless anyways
since the dynamic tooltip gives more accurate and specific information.
- Adding dynamic tooltips to a socket's UI layout row if it has a description
configured, both in the Node Editor as well as in the Material Properties.
Note that the patch does not add any actual tooltip content yet, just the
infrastructure to show them. By default, sockets without a description still
show the old "Default value" tooltip.
For an example of how to add socket descriptions, check the Cylinder node
in the Geometry Nodes.
Differential Revision: https://developer.blender.org/D9967
2022-04-11 02:02:12 +02:00
|
|
|
uiItemS(sub);
|
|
|
|
|
sub = uiLayoutColumn(sub, true);
|
2020-05-01 15:21:41 +02:00
|
|
|
ATTR_FALLTHROUGH;
|
2013-07-19 15:23:42 +00:00
|
|
|
case SOCK_FLOAT:
|
|
|
|
|
case SOCK_INT:
|
2023-06-14 20:30:10 +02:00
|
|
|
case SOCK_ROTATION:
|
2013-07-19 15:23:42 +00:00
|
|
|
case SOCK_BOOLEAN:
|
|
|
|
|
case SOCK_RGBA:
|
2023-07-29 15:06:33 +10:00
|
|
|
uiItemR(sub, &inputptr, "default_value", UI_ITEM_NONE, "", ICON_NONE);
|
2024-09-20 13:03:35 +02:00
|
|
|
if (split_wrapper.decorate_column) {
|
|
|
|
|
uiItemDecoratorR(
|
|
|
|
|
split_wrapper.decorate_column, &inputptr, "default_value", RNA_NO_INDEX);
|
|
|
|
|
}
|
2013-07-19 15:23:42 +00:00
|
|
|
break;
|
2021-03-09 19:09:53 +01:00
|
|
|
case SOCK_STRING: {
|
|
|
|
|
const bNodeTree *node_tree = (const bNodeTree *)nodeptr.owner_id;
|
2022-09-02 16:38:08 -05:00
|
|
|
SpaceNode *snode = CTX_wm_space_node(&C);
|
2021-07-23 16:13:04 +02:00
|
|
|
if (node_tree->type == NTREE_GEOMETRY && snode != nullptr) {
|
|
|
|
|
/* Only add the attribute search in the node editor, in other places there is not
|
|
|
|
|
* enough context. */
|
2022-09-02 16:38:08 -05:00
|
|
|
node_geometry_add_attribute_search_button(C, node, inputptr, *sub);
|
2021-03-09 19:09:53 +01:00
|
|
|
}
|
|
|
|
|
else {
|
2023-07-29 15:06:33 +10:00
|
|
|
uiItemR(sub, &inputptr, "default_value", UI_ITEM_NONE, "", ICON_NONE);
|
2021-03-09 19:09:53 +01:00
|
|
|
}
|
2024-09-20 13:03:35 +02:00
|
|
|
if (split_wrapper.decorate_column) {
|
|
|
|
|
uiItemDecoratorR(
|
|
|
|
|
split_wrapper.decorate_column, &inputptr, "default_value", RNA_NO_INDEX);
|
|
|
|
|
}
|
2021-03-09 19:09:53 +01:00
|
|
|
break;
|
|
|
|
|
}
|
2024-01-26 12:40:01 +01:00
|
|
|
case SOCK_MENU:
|
|
|
|
|
uiItemL(sub, RPT_("Unsupported Menu Socket"), ICON_NONE);
|
|
|
|
|
break;
|
2023-07-10 18:22:01 +02:00
|
|
|
case SOCK_CUSTOM:
|
|
|
|
|
input.typeinfo->draw(&C, sub, &inputptr, &nodeptr, input.name);
|
|
|
|
|
break;
|
2020-05-01 15:21:41 +02:00
|
|
|
default:
|
|
|
|
|
add_dummy_decorator = true;
|
2011-11-07 22:28:49 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2024-09-20 13:03:35 +02:00
|
|
|
if (add_dummy_decorator && split_wrapper.decorate_column) {
|
2024-12-06 14:08:10 +01:00
|
|
|
uiItemDecoratorR(split_wrapper.decorate_column, nullptr, std::nullopt, 0);
|
2020-05-01 15:21:41 +02:00
|
|
|
}
|
|
|
|
|
|
2023-01-02 16:45:49 -05:00
|
|
|
node_socket_add_tooltip(ntree, input, *row);
|
UI: Add support for showing socket descriptions in tooltips
Currently, hovering over a socket itself shows no tooltip at all, while
hovering over its value field shows "Default value", which is not helpful.
This patch therefore implements socket tooltips following the proposal at
https://blender.community/c/rightclickselect/2Qgbbc/.
A lot of the basic functionality was already implemented for Geometry Nodes,
where hovering over the socket itself shows introspection info.
This patch extends this by:
- Supporting dynamic tooltips on labels, which is important for good tooltip
coverage in a socket's region of the node.
- Adding a function to setting a dynamic tooltip for an entire uiLayout, which
avoids needing to set it manually for a wide variety of socket types.
- Hiding the property label field in a tooltip when dynamic tooltip is also
provided. If really needed, this label can be restored through the dynamic
tooltip, but in all current cases the label is actually pointless anyways
since the dynamic tooltip gives more accurate and specific information.
- Adding dynamic tooltips to a socket's UI layout row if it has a description
configured, both in the Node Editor as well as in the Material Properties.
Note that the patch does not add any actual tooltip content yet, just the
infrastructure to show them. By default, sockets without a description still
show the old "Default value" tooltip.
For an example of how to add socket descriptions, check the Cylinder node
in the Geometry Nodes.
Differential Revision: https://developer.blender.org/D9967
2022-04-11 02:02:12 +02:00
|
|
|
|
2011-11-07 22:28:49 +00:00
|
|
|
/* clear */
|
2022-09-02 16:38:08 -05:00
|
|
|
node.flag &= ~NODE_TEST;
|
2011-11-07 22:28:49 +00:00
|
|
|
}
|
|
|
|
|
|
2022-01-20 10:36:56 -06:00
|
|
|
} // namespace blender::ed::space_node
|
|
|
|
|
|
2011-11-07 22:28:49 +00:00
|
|
|
void uiTemplateNodeView(
|
|
|
|
|
uiLayout *layout, bContext *C, bNodeTree *ntree, bNode *node, bNodeSocket *input)
|
|
|
|
|
{
|
2022-01-20 10:36:56 -06:00
|
|
|
using namespace blender::ed::space_node;
|
|
|
|
|
|
2019-03-26 21:16:47 +11:00
|
|
|
if (!ntree) {
|
2011-11-07 22:28:49 +00:00
|
|
|
return;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2023-09-26 12:12:10 +02:00
|
|
|
ntree->ensure_topology_cache();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-11-07 22:28:49 +00:00
|
|
|
/* clear for cycle check */
|
2025-02-28 22:12:34 +01:00
|
|
|
for (bNode *tnode : ntree->all_nodes()) {
|
2011-11-07 22:28:49 +00:00
|
|
|
tnode->flag &= ~NODE_TEST;
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-03-26 21:16:47 +11:00
|
|
|
if (input) {
|
2023-09-20 17:43:19 +02:00
|
|
|
ui_node_draw_input(*layout, *C, *ntree, *node, *input, 0, nullptr);
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
|
|
|
|
else {
|
2022-09-02 16:38:08 -05:00
|
|
|
ui_node_draw_node(*layout, *C, *ntree, *node, 0);
|
2019-03-26 21:16:47 +11:00
|
|
|
}
|
2011-11-07 22:28:49 +00:00
|
|
|
}
|