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
This commit is contained in:
Omar Emara
2023-11-06 10:47:32 +01:00
committed by Omar Emara
parent 0ca1e70de1
commit 54e35e7388
2 changed files with 12 additions and 2 deletions

View File

@@ -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;
}

View File

@@ -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);