Nodes: Add default socket value to tooltip of socket

Even if node is not used, socket value is still there.
This value can be placed in tooltip instead of evaluated one.

Pull Request: https://projects.blender.org/blender/blender/pulls/120497
This commit is contained in:
Iliya Katueshenock
2024-04-24 17:03:55 +02:00
committed by Hans Goudey
parent 15b9ae5436
commit 8e830a95de

View File

@@ -1583,6 +1583,31 @@ static void create_inspection_string_for_geometry_socket(std::stringstream &ss,
}
}
static void create_inspection_string_for_default_socket_value(const bNodeSocket &socket,
std::stringstream &ss)
{
if (!socket.is_input()) {
return;
}
if (socket.is_directly_linked()) {
return;
}
if (const nodes::SocketDeclaration *socket_decl = socket.runtime->declaration) {
if (socket_decl->input_field_type == nodes::InputSocketFieldType::Implicit) {
return;
}
}
if (socket.typeinfo->base_cpp_type == nullptr) {
return;
}
const CPPType &value_type = *socket.typeinfo->base_cpp_type;
BUFFER_FOR_CPP_TYPE_VALUE(value_type, socket_value);
socket.typeinfo->get_base_cpp_value(socket.default_value, socket_value);
create_inspection_string_for_generic_value(socket, GPointer(value_type, socket_value), ss);
value_type.destruct(socket_value);
}
static std::optional<std::string> create_description_inspection_string(const bNodeSocket &socket)
{
if (socket.runtime->declaration == nullptr) {
@@ -1732,6 +1757,18 @@ static std::optional<std::string> create_multi_input_log_inspection_string(
return str;
}
static std::optional<std::string> create_default_value_inspection_string(const bNodeSocket &socket)
{
std::stringstream ss;
create_inspection_string_for_default_socket_value(socket, ss);
std::string str = ss.str();
if (str.empty()) {
return std::nullopt;
}
return str;
}
static std::string node_socket_get_tooltip(const SpaceNode *snode,
const bNodeTree &ntree,
const bNodeSocket &socket)
@@ -1754,6 +1791,9 @@ static std::string node_socket_get_tooltip(const SpaceNode *snode,
if (std::optional<std::string> info = create_log_inspection_string(geo_tree_log, socket)) {
inspection_strings.append(std::move(*info));
}
else if (std::optional<std::string> info = create_default_value_inspection_string(socket)) {
inspection_strings.append(std::move(*info));
}
else if (std::optional<std::string> info = create_multi_input_log_inspection_string(
ntree, socket, tree_draw_ctx))
{