Nodes: Panels integration with blend files and UI #111348

Merged
Lukas Tönne merged 96 commits from LukasTonne/blender:node-panels-final into main 2023-08-30 12:37:28 +02:00
7 changed files with 112 additions and 110 deletions
Showing only changes of commit ca82f437fc - Show all commits

View File

@ -169,6 +169,7 @@ typedef struct bNodeSocketType {
struct PointerRNA *ptr,
struct PointerRNA *node_ptr,
float *r_color);
void (*draw_color_simple)(const bNodeSocketType *socket_type, float *r_color);
void (*interface_draw)(struct ID *id,
struct bNodeTreeInterfaceSocket *socket,

View File

@ -648,12 +648,14 @@ bNodeSocketType *bNodeTreeInterfaceSocket::socket_typeinfo() const
blender::ColorGeometry4f bNodeTreeInterfaceSocket::socket_color() const
{
bNodeSocketType *typeinfo = this->socket_typeinfo();
if (!typeinfo || !typeinfo->draw_color) {
if (!typeinfo || !typeinfo->draw_color_simple) {
return blender::ColorGeometry4f(1.0f, 0.0f, 1.0f, 1.0f);
}
float color[4];
typeinfo->draw_color(nullptr, nullptr, nullptr, color);
if (typeinfo->draw_color_simple) {
typeinfo->draw_color_simple(typeinfo, color);
}
return blender::ColorGeometry4f(color);
}

View File

@ -1124,6 +1124,15 @@ static void node_socket_undefined_draw_color(bContext * /*C*/,
r_color[3] = 1.0f;
}
static void node_socket_undefined_draw_color_simple(const bNodeSocketType * /*type*/,
float *r_color)
{
r_color[0] = 1.0f;
r_color[1] = 0.0f;
r_color[2] = 0.0f;
r_color[3] = 1.0f;
}
static void node_socket_undefined_interface_draw(ID * /*id*/,
bNodeTreeInterfaceSocket * /*interface_socket*/,
bContext * /*C*/,
@ -1152,6 +1161,7 @@ void ED_node_init_butfuncs()
NodeSocketTypeUndefined.draw = node_socket_undefined_draw;
NodeSocketTypeUndefined.draw_color = node_socket_undefined_draw_color;
NodeSocketTypeUndefined.draw_color_simple = node_socket_undefined_draw_color_simple;
NodeSocketTypeUndefined.interface_draw = node_socket_undefined_interface_draw;
/* node type ui functions */
@ -1207,11 +1217,12 @@ void std_node_socket_color_fn(bContext * /*C*/,
{
copy_v4_v4(r_color, std_node_socket_colors[socket_type]);
};
static void std_node_socket_color_simple_fn(const bNodeSocketType *type, float *r_color)
{
copy_v4_v4(r_color, std_node_socket_colors[type->type]);
};
using SocketColorFn = void (*)(bContext * /*C*/,
PointerRNA * /*ptr*/,
PointerRNA * /*node_ptr*/,
float *r_color);
using SocketColorFn = void (*)(bContext *C, PointerRNA *ptr, PointerRNA *node_ptr, float *r_color);
/* Callbacks for all built-in socket types. */
static const SocketColorFn std_node_socket_color_funcs[] = {
std_node_socket_color_fn<SOCK_FLOAT>,
@ -1515,6 +1526,11 @@ static void node_socket_virtual_draw_color(bContext * /*C*/,
copy_v4_v4(r_color, virtual_node_socket_color);
}
static void node_socket_virtual_draw_color_simple(const bNodeSocketType * /*type*/, float *r_color)
{
copy_v4_v4(r_color, virtual_node_socket_color);
}
} // namespace blender::ed::space_node
void ED_init_standard_node_socket_type(bNodeSocketType *stype)
@ -1522,6 +1538,7 @@ void ED_init_standard_node_socket_type(bNodeSocketType *stype)
using namespace blender::ed::space_node;
stype->draw = std_node_socket_draw;
stype->draw_color = std_node_socket_color_funcs[stype->type];
stype->draw_color_simple = std_node_socket_color_simple_fn;
stype->interface_draw = std_node_socket_interface_draw;
}
@ -1530,6 +1547,7 @@ void ED_init_node_socket_type_virtual(bNodeSocketType *stype)
using namespace blender::ed::space_node;
stype->draw = node_socket_button_label;
stype->draw_color = node_socket_virtual_draw_color;
stype->draw_color_simple = node_socket_virtual_draw_color_simple;
}
void ED_node_type_draw_color(const char *idname, float *r_color)
@ -2069,8 +2087,7 @@ static bool node_link_is_field_link(const SpaceNode &snode, const bNodeLink &lin
return false;
}
static NodeLinkDrawConfig nodelink_get_draw_config(const bContext &C,
const View2D &v2d,
static NodeLinkDrawConfig nodelink_get_draw_config(const View2D &v2d,
const SpaceNode &snode,
const bNodeLink &link,
const int th_col1,
@ -2084,8 +2101,6 @@ static NodeLinkDrawConfig nodelink_get_draw_config(const bContext &C,
draw_config.th_col2 = th_col2;
draw_config.th_col3 = th_col3;
const bNodeTree &node_tree = *snode.edittree;
draw_config.dim_factor = selected ? 1.0f : node_link_dim_factor(v2d, link);
bTheme *btheme = UI_GetTheme();
@ -2110,22 +2125,18 @@ static NodeLinkDrawConfig nodelink_get_draw_config(const bContext &C,
if (snode.overlay.flag & SN_OVERLAY_SHOW_OVERLAYS &&
snode.overlay.flag & SN_OVERLAY_SHOW_WIRE_COLORS)
{
PointerRNA from_node_ptr, to_node_ptr;
RNA_pointer_create((ID *)&node_tree, &RNA_Node, link.fromnode, &from_node_ptr);
RNA_pointer_create((ID *)&node_tree, &RNA_Node, link.tonode, &to_node_ptr);
if (link.fromsock) {
node_socket_color_get(C, node_tree, from_node_ptr, *link.fromsock, draw_config.start_color);
node_socket_color_get(*link.fromsock->typeinfo, draw_config.start_color);
}
else {
node_socket_color_get(C, node_tree, to_node_ptr, *link.tosock, draw_config.start_color);
node_socket_color_get(*link.tosock->typeinfo, draw_config.start_color);
}
if (link.tosock) {
node_socket_color_get(C, node_tree, to_node_ptr, *link.tosock, draw_config.end_color);
node_socket_color_get(*link.tosock->typeinfo, draw_config.end_color);
}
else {
node_socket_color_get(C, node_tree, from_node_ptr, *link.fromsock, draw_config.end_color);
node_socket_color_get(*link.fromsock->typeinfo, draw_config.end_color);
}
}
else {
@ -2204,8 +2215,7 @@ static void node_draw_link_bezier_ex(const SpaceNode &snode,
}
}
void node_draw_link_bezier(const bContext &C,
const View2D &v2d,
void node_draw_link_bezier(const View2D &v2d,
const SpaceNode &snode,
const bNodeLink &link,
const int th_col1,
@ -2218,13 +2228,12 @@ void node_draw_link_bezier(const bContext &C,
return;
}
const NodeLinkDrawConfig draw_config = nodelink_get_draw_config(
C, v2d, snode, link, th_col1, th_col2, th_col3, selected);
v2d, snode, link, th_col1, th_col2, th_col3, selected);
node_draw_link_bezier_ex(snode, draw_config, points);
}
void node_draw_link(const bContext &C,
const View2D &v2d,
void node_draw_link(const View2D &v2d,
const SpaceNode &snode,
const bNodeLink &link,
const bool selected)
@ -2267,7 +2276,7 @@ void node_draw_link(const bContext &C,
}
}
node_draw_link_bezier(C, v2d, snode, link, th_col1, th_col2, th_col3, selected);
node_draw_link_bezier(v2d, snode, link, th_col1, th_col2, th_col3, selected);
}
std::array<float2, 4> node_link_bezier_points_dragged(const SpaceNode &snode,
@ -2284,10 +2293,7 @@ std::array<float2, 4> node_link_bezier_points_dragged(const SpaceNode &snode,
return points;
}
void node_draw_link_dragged(const bContext &C,
const View2D &v2d,
const SpaceNode &snode,
const bNodeLink &link)
void node_draw_link_dragged(const View2D &v2d, const SpaceNode &snode, const bNodeLink &link)
{
if (link.fromsock == nullptr && link.tosock == nullptr) {
return;
@ -2296,7 +2302,7 @@ void node_draw_link_dragged(const bContext &C,
const std::array<float2, 4> points = node_link_bezier_points_dragged(snode, link);
const NodeLinkDrawConfig draw_config = nodelink_get_draw_config(
C, v2d, snode, link, TH_ACTIVE, TH_ACTIVE, TH_WIRE, true);
v2d, snode, link, TH_ACTIVE, TH_ACTIVE, TH_WIRE, true);
/* End marker outline. */
node_draw_link_end_markers(link, draw_config, points, true);
/* Link. */

View File

@ -800,16 +800,13 @@ static int node_get_colorid(TreeDrawContext &tree_draw_ctx, const bNode &node)
}
}
static void node_draw_mute_line(const bContext &C,
const View2D &v2d,
const SpaceNode &snode,
const bNode &node)
static void node_draw_mute_line(const View2D &v2d, const SpaceNode &snode, const bNode &node)
{
GPU_blend(GPU_BLEND_ALPHA);
for (const bNodeLink &link : node.internal_links()) {
if (!nodeLinkIsHidden(&link)) {
node_draw_link_bezier(C, v2d, snode, link, TH_WIRE_INNER, TH_WIRE_INNER, TH_WIRE, false);
node_draw_link_bezier(v2d, snode, link, TH_WIRE_INNER, TH_WIRE_INNER, TH_WIRE, false);
}
}
@ -907,18 +904,9 @@ static void node_socket_outline_color_get(const bool selected,
}
}
void node_socket_color_get(const bContext &C,
const bNodeTree &ntree,
PointerRNA &node_ptr,
const bNodeSocket &sock,
float r_color[4])
void node_socket_color_get(const bNodeSocketType &type, float r_color[4])
{
PointerRNA ptr;
BLI_assert(RNA_struct_is_a(node_ptr.type, &RNA_Node));
RNA_pointer_create(
&const_cast<ID &>(ntree.id), &RNA_NodeSocket, &const_cast<bNodeSocket &>(sock), &ptr);
sock.typeinfo->draw_color((bContext *)&C, &ptr, &node_ptr, r_color);
type.draw_color_simple(&type, r_color);
}
static void create_inspection_string_for_generic_value(const bNodeSocket &socket,
@ -1343,9 +1331,7 @@ void node_socket_add_tooltip(const bNodeTree &ntree, const bNodeSocket &sock, ui
MEM_freeN);
}
static void node_socket_draw_nested(const bContext &C,
const bNodeTree &ntree,
PointerRNA &node_ptr,
static void node_socket_draw_nested(const bNodeTree &ntree,
uiBlock &block,
const bNodeSocket &sock,
const uint pos_id,
@ -1360,7 +1346,7 @@ static void node_socket_draw_nested(const bContext &C,
float color[4];
float outline_color[4];
node_socket_color_get(C, ntree, node_ptr, sock, color);
node_socket_color_get(*sock.typeinfo, color);
node_socket_outline_color_get(selected, sock.type, outline_color);
node_socket_draw(sock,
@ -1555,7 +1541,6 @@ static void node_draw_shadow(const SpaceNode &snode,
}
static void node_draw_sockets(const View2D &v2d,
const bContext &C,
const bNodeTree &ntree,
const bNode &node,
uiBlock &block,
@ -1614,18 +1599,8 @@ static void node_draw_sockets(const View2D &v2d,
continue;
}
node_socket_draw_nested(C,
ntree,
node_ptr,
block,
*sock,
pos_id,
col_id,
shape_id,
size_id,
outline_col_id,
scale,
selected);
node_socket_draw_nested(
ntree, block, *sock, pos_id, col_id, shape_id, size_id, outline_col_id, scale, selected);
}
/* Socket outputs. */
@ -1640,18 +1615,8 @@ static void node_draw_sockets(const View2D &v2d,
continue;
}
node_socket_draw_nested(C,
ntree,
node_ptr,
block,
*sock,
pos_id,
col_id,
shape_id,
size_id,
outline_col_id,
scale,
selected);
node_socket_draw_nested(
ntree, block, *sock, pos_id, col_id, shape_id, size_id, outline_col_id, scale, selected);
}
}
@ -1678,9 +1643,7 @@ static void node_draw_sockets(const View2D &v2d,
continue;
}
if (select_all || (sock->flag & SELECT)) {
node_socket_draw_nested(C,
ntree,
node_ptr,
node_socket_draw_nested(ntree,
block,
*sock,
pos_id,
@ -1705,9 +1668,7 @@ static void node_draw_sockets(const View2D &v2d,
continue;
}
if (select_all || (sock->flag & SELECT)) {
node_socket_draw_nested(C,
ntree,
node_ptr,
node_socket_draw_nested(ntree,
block,
*sock,
pos_id,
@ -1749,7 +1710,7 @@ static void node_draw_sockets(const View2D &v2d,
float color[4];
float outline_color[4];
node_socket_color_get(C, ntree, node_ptr, *socket, color);
node_socket_color_get(*socket->typeinfo, color);
node_socket_outline_color_get(socket->flag & SELECT, socket->type, outline_color);
const float2 location = socket->runtime->location;
@ -1769,7 +1730,6 @@ static void node_panel_toggle_button_cb(bContext *C, void *panel_state_argv, voi
}
static void node_draw_panels(const View2D & /*v2d*/,
const bContext & /*C*/,
TreeDrawContext &tree_draw_ctx,
bNodeTree &ntree,
const bNode &node,
@ -2710,7 +2670,7 @@ static void node_draw_basis(const bContext &C,
/* Wire across the node when muted/disabled. */
if (node.flag & NODE_MUTED) {
node_draw_mute_line(C, v2d, snode, node);
node_draw_mute_line(v2d, snode, node);
}
/* Body. */
@ -2814,11 +2774,11 @@ static void node_draw_basis(const bContext &C,
/* Skip slow socket drawing if zoom is small. */
if (scale > 0.2f) {
node_draw_sockets(v2d, C, ntree, node, block, true, false);
node_draw_sockets(v2d, ntree, node, block, true, false);
}
if (node.declaration() != nullptr) {
node_draw_panels(v2d, C, tree_draw_ctx, ntree, node, block);
node_draw_panels(v2d, tree_draw_ctx, ntree, node, block);
}
UI_block_end(&C, &block);
@ -2849,7 +2809,7 @@ static void node_draw_hidden(const bContext &C,
/* Wire across the node when muted/disabled. */
if (node.flag & NODE_MUTED) {
node_draw_mute_line(C, v2d, snode, node);
node_draw_mute_line(v2d, snode, node);
}
/* Body. */
@ -2999,7 +2959,7 @@ static void node_draw_hidden(const bContext &C,
immUnbindProgram();
GPU_blend(GPU_BLEND_NONE);
node_draw_sockets(v2d, C, ntree, node, block, true, false);
node_draw_sockets(v2d, ntree, node, block, true, false);
UI_block_end(&C, &block);
UI_block_draw(&C, &block);
@ -3374,7 +3334,7 @@ static void reroute_node_draw(
/* Only draw input socket as they all are placed on the same position highlight
* if node itself is selected, since we don't display the node body separately. */
node_draw_sockets(region.v2d, C, ntree, node, block, false, node.flag & SELECT);
node_draw_sockets(region.v2d, ntree, node, block, false, node.flag & SELECT);
UI_block_end(&C, &block);
UI_block_draw(&C, &block);
@ -3634,14 +3594,14 @@ static void node_draw_nodetree(const bContext &C,
for (const bNodeLink *link : ntree.all_links()) {
if (!nodeLinkIsHidden(link) && !bke::nodeLinkIsSelected(link)) {
node_draw_link(C, region.v2d, snode, *link, false);
node_draw_link(region.v2d, snode, *link, false);
}
}
/* Draw selected node links after the unselected ones, so they are shown on top. */
for (const bNodeLink *link : ntree.all_links()) {
if (!nodeLinkIsHidden(link) && bke::nodeLinkIsSelected(link)) {
node_draw_link(C, region.v2d, snode, *link, true);
node_draw_link(region.v2d, snode, *link, true);
}
}
@ -3892,7 +3852,7 @@ void node_draw_space(const bContext &C, ARegion &region)
GPU_line_smooth(true);
if (snode.runtime->linkdrag) {
for (const bNodeLink &link : snode.runtime->linkdrag->links) {
node_draw_link_dragged(C, v2d, snode, link);
node_draw_link_dragged(v2d, snode, link);
}
}
GPU_line_smooth(false);

View File

@ -162,11 +162,7 @@ int node_get_resize_cursor(NodeResizeDirection directions);
* Usual convention here would be #node_socket_get_color(),
* but that's already used (for setting a color property socket).
*/
void node_socket_color_get(const bContext &C,
const bNodeTree &ntree,
PointerRNA &node_ptr,
const bNodeSocket &sock,
float r_color[4]);
void node_socket_color_get(const bNodeSocketType &type, float r_color[4]);
/* `node_draw.cc` */
@ -244,20 +240,15 @@ void nodelink_batch_end(SpaceNode &snode);
/**
* \note this is used for fake links in groups too.
*/
void node_draw_link(const bContext &C,
const View2D &v2d,
void node_draw_link(const View2D &v2d,
const SpaceNode &snode,
const bNodeLink &link,
bool selected);
void node_draw_link_dragged(const bContext &C,
const View2D &v2d,
const SpaceNode &snode,
const bNodeLink &link);
void node_draw_link_dragged(const View2D &v2d, const SpaceNode &snode, const bNodeLink &link);
/**
* Don't do shadows if th_col3 is -1.
*/
void node_draw_link_bezier(const bContext &C,
const View2D &v2d,
void node_draw_link_bezier(const View2D &v2d,
const SpaceNode &snode,
const bNodeLink &link,
int th_col1,

View File

@ -711,7 +711,7 @@ static void ui_template_node_link_menu(bContext *C, uiLayout *layout, void *but_
} // namespace blender::ed::space_node
void uiTemplateNodeLink(
uiLayout *layout, bContext *C, bNodeTree *ntree, bNode *node, bNodeSocket *input)
uiLayout *layout, bContext * /*C*/, bNodeTree *ntree, bNode *node, bNodeSocket *input)
{
using namespace blender::ed::space_node;
@ -725,9 +725,7 @@ void uiTemplateNodeLink(
arg->node = node;
arg->sock = input;
PointerRNA node_ptr;
RNA_pointer_create((ID *)ntree, &RNA_Node, node, &node_ptr);
node_socket_color_get(*C, *ntree, node_ptr, *input, socket_col);
node_socket_color_get(*input->typeinfo, socket_col);
UI_block_layout_set_current(block, layout);

View File

@ -50,6 +50,7 @@ const EnumPropertyItem rna_enum_node_socket_type_items[] = {
extern FunctionRNA rna_NodeSocket_draw_func;
extern FunctionRNA rna_NodeSocket_draw_color_func;
extern FunctionRNA rna_NodeSocket_draw_color_simple_func;
/* ******** Node Socket ******** */
@ -95,6 +96,27 @@ static void rna_NodeSocket_draw_color(bContext *C,
RNA_parameter_list_free(&list);
}
static void rna_NodeSocket_draw_color_simple(const bNodeSocketType *socket_type, float *r_color)
{
ParameterList list;
FunctionRNA *func;
void *ret;
func = &rna_NodeSocket_draw_color_simple_func; /* RNA_struct_find_function(&ptr,
"draw_color_simple"); */
PointerRNA ptr;
RNA_pointer_create(nullptr, socket_type->ext_socket.srna, nullptr, &ptr);
RNA_parameter_list_create(&list, &ptr, func);
RNA_parameter_set_lookup(&list, "type", socket_type);
socket_type->ext_socket.call(nullptr, &ptr, func, &list);
RNA_parameter_get_lookup(&list, "color", &ret);
copy_v4_v4(r_color, static_cast<float *>(ret));
RNA_parameter_list_free(&list);
}
static bool rna_NodeSocket_unregister(Main * /*bmain*/, StructRNA *type)
{
bNodeSocketType *st = static_cast<bNodeSocketType *>(RNA_struct_blender_type_get(type));
@ -123,7 +145,7 @@ static StructRNA *rna_NodeSocket_register(Main * /*bmain*/,
bNodeSocketType *st, dummy_st;
bNodeSocket dummy_sock;
PointerRNA dummy_sock_ptr;
bool have_function[2];
bool have_function[3];
/* setup dummy socket & socket type to store static properties in */
memset(&dummy_st, 0, sizeof(bNodeSocketType));
@ -176,6 +198,7 @@ static StructRNA *rna_NodeSocket_register(Main * /*bmain*/,
st->draw = (have_function[0]) ? rna_NodeSocket_draw : nullptr;
st->draw_color = (have_function[1]) ? rna_NodeSocket_draw_color : nullptr;
st->draw_color_simple = (have_function[2]) ? rna_NodeSocket_draw_color_simple : nullptr;
/* update while blender is running */
WM_main_add_notifier(NC_NODE | NA_EDITED, nullptr);
@ -303,6 +326,13 @@ static void rna_NodeSocketStandard_draw_color(
sock->typeinfo->draw_color(C, &ptr, nodeptr, r_color);
}
static void rna_NodeSocketStandard_draw_color_simple(struct StructRNA *type, float r_color[4])
{
const bNodeSocketType *typeinfo = static_cast<const bNodeSocketType *>(
RNA_struct_blender_type_get(type));
typeinfo->draw_color_simple(typeinfo, r_color);
}
/* ******** Node Socket Subtypes ******** */
void rna_NodeSocketStandard_float_range(
@ -542,7 +572,7 @@ static void rna_def_node_socket(BlenderRNA *brna)
func = RNA_def_function(srna, "draw_color", nullptr);
RNA_def_function_ui_description(func, "Color of the socket icon");
RNA_def_function_flag(func, FUNC_REGISTER);
RNA_def_function_flag(func, FUNC_REGISTER_OPTIONAL);
parm = RNA_def_pointer(func, "context", "Context", "", "");
RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED);
parm = RNA_def_property(func, "node", PROP_POINTER, PROP_NONE);
@ -552,6 +582,13 @@ static void rna_def_node_socket(BlenderRNA *brna)
parm = RNA_def_float_array(
func, "color", 4, default_draw_color, 0.0f, 1.0f, "Color", "", 0.0f, 1.0f);
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_flag(func, FUNC_NO_SELF | FUNC_USE_SELF_TYPE | FUNC_REGISTER_OPTIONAL);
parm = RNA_def_float_array(
func, "color", 4, default_draw_color, 0.0f, 1.0f, "Color", "", 0.0f, 1.0f);
RNA_def_function_output(func, parm);
}
static void rna_def_node_socket_standard(BlenderRNA *brna)
@ -604,6 +641,13 @@ static void rna_def_node_socket_standard(BlenderRNA *brna)
parm = RNA_def_float_array(
func, "color", 4, default_draw_color, 0.0f, 1.0f, "Color", "", 0.0f, 1.0f);
RNA_def_function_output(func, parm);
func = RNA_def_function(srna, "draw_color_simple", "rna_NodeSocketStandard_draw_color_simple");
RNA_def_function_ui_description(func, "Color of the socket icon");
RNA_def_function_flag(func, FUNC_NO_SELF | FUNC_USE_SELF_TYPE | FUNC_REGISTER_OPTIONAL);
parm = RNA_def_float_array(
func, "color", 4, default_draw_color, 0.0f, 1.0f, "Color", "", 0.0f, 1.0f);
RNA_def_function_output(func, parm);
}
/* Common functions for all builtin socket interface types. */