From 54e35e738817889122df1f2d612762d961ec552f Mon Sep 17 00:00:00 2001 From: Omar Emara Date: Mon, 6 Nov 2023 10:47:32 +0100 Subject: [PATCH] Nodes: Draw using draw_color_simple as a fallback If the draw_color method is not defined, try to use draw_color_simple as a fallback. If not defined either, fallback to a magenta color. The patch also updates the description of the method to clarify its use. Pull Request: https://projects.blender.org/blender/blender/pulls/114527 --- source/blender/editors/space_node/node_draw.cc | 8 +++++++- source/blender/makesrna/intern/rna_node_socket.cc | 6 +++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/source/blender/editors/space_node/node_draw.cc b/source/blender/editors/space_node/node_draw.cc index 4b43b1f613c..0337a15553c 100644 --- a/source/blender/editors/space_node/node_draw.cc +++ b/source/blender/editors/space_node/node_draw.cc @@ -1194,7 +1194,13 @@ void node_socket_color_get(const bContext &C, float r_color[4]) { if (!sock.typeinfo->draw_color) { - copy_v4_v4(r_color, float4(1.0f, 0.0f, 1.0f, 1.0f)); + /* Fallback to the simple variant. If not defined either, fallback to a magenta color. */ + if (sock.typeinfo->draw_color_simple) { + sock.typeinfo->draw_color_simple(sock.typeinfo, r_color); + } + else { + copy_v4_v4(r_color, float4(1.0f, 0.0f, 1.0f, 1.0f)); + } return; } diff --git a/source/blender/makesrna/intern/rna_node_socket.cc b/source/blender/makesrna/intern/rna_node_socket.cc index 53a74e22a4f..172b71860ac 100644 --- a/source/blender/makesrna/intern/rna_node_socket.cc +++ b/source/blender/makesrna/intern/rna_node_socket.cc @@ -589,7 +589,11 @@ static void rna_def_node_socket(BlenderRNA *brna) RNA_def_function_output(func, parm); func = RNA_def_function(srna, "draw_color_simple", nullptr); - RNA_def_function_ui_description(func, "Color of the socket icon"); + RNA_def_function_ui_description( + func, + "Color of the socket icon. Used to draw sockets in places where the socket does not belong " + "to a node, like the node interface panel. Also used to draw node sockets if draw_color is " + "not defined"); RNA_def_function_flag(func, FUNC_NO_SELF | FUNC_REGISTER_OPTIONAL); parm = RNA_def_float_array( func, "color", 4, default_draw_color, 0.0f, 1.0f, "Color", "", 0.0f, 1.0f);