diff options
author | Hans Goudey <h.goudey@me.com> | 2021-12-04 00:25:17 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2021-12-04 00:25:17 +0300 |
commit | 2d8606b36071dd14290aa8852451535a49d3096d (patch) | |
tree | 66674726756a859fa1a1e66e9b8eac84387ba2b8 | |
parent | ca0dbf8c26fb637ad06bd170e4e25d200d7ca0f0 (diff) |
Cleanup: Use references in node editor, other improvements
This helps to tell when a pointer is expected to be null, and avoid
overly verbose code when dereferencing. This commit also includes
a few other cleanups in this area:
- Use const in a few places
- Use `float2` instead of `float[2]`
- Remove some unnecessary includes and old code
The change can be continued further in the future.
-rw-r--r-- | source/blender/blenkernel/BKE_node.h | 4 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/node.cc | 2 | ||||
-rw-r--r-- | source/blender/editors/space_node/drawnode.cc | 296 | ||||
-rw-r--r-- | source/blender/editors/space_node/node_add.cc | 87 | ||||
-rw-r--r-- | source/blender/editors/space_node/node_draw.cc | 910 | ||||
-rw-r--r-- | source/blender/editors/space_node/node_edit.cc | 204 | ||||
-rw-r--r-- | source/blender/editors/space_node/node_geometry_attribute_search.cc | 16 | ||||
-rw-r--r-- | source/blender/editors/space_node/node_group.cc | 136 | ||||
-rw-r--r-- | source/blender/editors/space_node/node_intern.hh | 141 | ||||
-rw-r--r-- | source/blender/editors/space_node/node_relationships.cc | 550 | ||||
-rw-r--r-- | source/blender/editors/space_node/node_select.cc | 124 | ||||
-rw-r--r-- | source/blender/editors/space_node/node_templates.cc | 7 | ||||
-rw-r--r-- | source/blender/editors/space_node/node_view.cc | 80 | ||||
-rw-r--r-- | source/blender/editors/space_node/space_node.cc | 8 |
14 files changed, 1270 insertions, 1295 deletions
diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h index 776845b4c99..85699e4c28d 100644 --- a/source/blender/blenkernel/BKE_node.h +++ b/source/blender/blenkernel/BKE_node.h @@ -285,7 +285,7 @@ typedef struct bNodeType { */ void (*labelfunc)(struct bNodeTree *ntree, struct bNode *node, char *label, int maxlen); /** Optional custom resize handle polling. */ - NodeResizeDirection (*resize_area_func)(struct bNode *node, int x, int y); + NodeResizeDirection (*resize_area_func)(const struct bNode *node, int x, int y); /** Optional selection area polling. */ int (*select_area_func)(struct bNode *node, int x, int y); /** Optional tweak area polling (for grabbing). */ @@ -555,7 +555,7 @@ void ntreeInterfaceTypeUpdate(struct bNodeTree *ntree); struct bNodeType *nodeTypeFind(const char *idname); void nodeRegisterType(struct bNodeType *ntype); void nodeUnregisterType(struct bNodeType *ntype); -bool nodeTypeUndefined(struct bNode *node); +bool nodeTypeUndefined(const struct bNode *node); struct GHashIterator *nodeTypeGetIterator(void); /* Helper macros for iterating over node types. */ diff --git a/source/blender/blenkernel/intern/node.cc b/source/blender/blenkernel/intern/node.cc index 4178e7577d8..359dbaab12b 100644 --- a/source/blender/blenkernel/intern/node.cc +++ b/source/blender/blenkernel/intern/node.cc @@ -1455,7 +1455,7 @@ void nodeUnregisterType(bNodeType *nt) BLI_ghash_remove(nodetypes_hash, nt->idname, nullptr, node_free_type); } -bool nodeTypeUndefined(bNode *node) +bool nodeTypeUndefined(const bNode *node) { return (node->typeinfo == &NodeTypeUndefined) || ((ELEM(node->type, NODE_GROUP, NODE_CUSTOM_GROUP)) && node->id && diff --git a/source/blender/editors/space_node/drawnode.cc b/source/blender/editors/space_node/drawnode.cc index 0602bc7e124..cdce876f57a 100644 --- a/source/blender/editors/space_node/drawnode.cc +++ b/source/blender/editors/space_node/drawnode.cc @@ -22,8 +22,6 @@ * \brief lower level node drawing for nodes (boarders, headers etc), also node layout. */ -#include "BLI_blenlib.h" -#include "BLI_math.h" #include "BLI_system.h" #include "BLI_threads.h" @@ -79,6 +77,8 @@ #include "NOD_texture.h" #include "node_intern.hh" /* own include */ +using blender::float2; + /* Default flags for uiItemR(). Name is kept short since this is used a lot in this file. */ #define DEFAULT_FLAGS UI_ITEM_R_SPLIT_EMPTY_NAME @@ -250,7 +250,7 @@ static void node_buts_math(uiLayout *layout, bContext *UNUSED(C), PointerRNA *pt uiItemR(layout, ptr, "use_clamp", DEFAULT_FLAGS, nullptr, ICON_NONE); } -static NodeResizeDirection node_resize_area_default(bNode *node, const int x, const int y) +static NodeResizeDirection node_resize_area_default(const bNode *node, const int x, const int y) { if (node->flag & NODE_HIDDEN) { rctf totr = node->totr; @@ -264,7 +264,7 @@ static NodeResizeDirection node_resize_area_default(bNode *node, const int x, co } const float size = NODE_RESIZE_MARGIN; - rctf totr = node->totr; + const rctf &totr = node->totr; NodeResizeDirection dir = NODE_RESIZE_NONE; if (x >= totr.xmax - size && x < totr.xmax && y >= totr.ymin && y < totr.ymax) { @@ -295,9 +295,9 @@ static void node_draw_frame_prepare(const bContext *UNUSED(C), bNodeTree *ntree, /* init rect from current frame size */ rctf rect; - node_to_view(node, node->offsetx, node->offsety, &rect.xmin, &rect.ymax); + node_to_view(*node, node->offsetx, node->offsety, &rect.xmin, &rect.ymax); node_to_view( - node, node->offsetx + node->width, node->offsety - node->height, &rect.xmax, &rect.ymin); + *node, node->offsetx + node->width, node->offsety - node->height, &rect.xmax, &rect.ymin); /* frame can be resized manually only if shrinking is disabled or no children are attached */ data->flag |= NODE_FRAME_RESIZEABLE; @@ -328,25 +328,25 @@ static void node_draw_frame_prepare(const bContext *UNUSED(C), bNodeTree *ntree, } /* now adjust the frame size from view-space bounding box */ - node_from_view(node, rect.xmin, rect.ymax, &node->offsetx, &node->offsety); + node_from_view(*node, rect.xmin, rect.ymax, &node->offsetx, &node->offsety); float xmax, ymax; - node_from_view(node, rect.xmax, rect.ymin, &xmax, &ymax); + node_from_view(*node, rect.xmax, rect.ymin, &xmax, &ymax); node->width = xmax - node->offsetx; node->height = -ymax + node->offsety; node->totr = rect; } -static void node_draw_frame_label(bNodeTree *ntree, bNode *node, SpaceNode *snode) +static void node_draw_frame_label(bNodeTree &ntree, bNode &node, SpaceNode &snode) { - const float aspect = snode->runtime->aspect; + const float aspect = snode.runtime->aspect; /* XXX font id is crap design */ const int fontid = UI_style_get()->widgetlabel.uifont_id; - NodeFrame *data = (NodeFrame *)node->storage; + NodeFrame *data = (NodeFrame *)node.storage; const float font_size = data->label_size / aspect; char label[MAX_NAME]; - nodeLabel(ntree, node, label, sizeof(label)); + nodeLabel(&ntree, &node, label, sizeof(label)); BLF_enable(fontid, BLF_ASPECT); BLF_aspect(fontid, aspect, aspect, 1.0f); @@ -365,39 +365,39 @@ static void node_draw_frame_label(bNodeTree *ntree, bNode *node, SpaceNode *snod const int label_height = ((margin / aspect) + (ascender * aspect)); /* 'x' doesn't need aspect correction */ - rctf *rct = &node->totr; + const rctf &rct = node.totr; /* XXX a bit hacky, should use separate align values for x and y */ - float x = BLI_rctf_cent_x(rct) - (0.5f * width); - float y = rct->ymax - label_height; + float x = BLI_rctf_cent_x(&rct) - (0.5f * width); + float y = rct.ymax - label_height; /* label */ - const bool has_label = node->label[0] != '\0'; + const bool has_label = node.label[0] != '\0'; if (has_label) { BLF_position(fontid, x, y, 0); BLF_draw(fontid, label, BLF_DRAW_STR_DUMMY_MAX); } /* draw text body */ - if (node->id) { - Text *text = (Text *)node->id; + if (node.id) { + Text *text = (Text *)node.id; const int line_height_max = BLF_height_max(fontid); const float line_spacing = (line_height_max * aspect); - const float line_width = (BLI_rctf_size_x(rct) - margin) / aspect; + const float line_width = (BLI_rctf_size_x(&rct) - margin) / aspect; /* 'x' doesn't need aspect correction */ - x = rct->xmin + margin; - y = rct->ymax - label_height - (has_label ? line_spacing : 0); + x = rct.xmin + margin; + y = rct.ymax - label_height - (has_label ? line_spacing : 0); /* early exit */ - int y_min = y + ((margin * 2) - (y - rct->ymin)); + int y_min = y + ((margin * 2) - (y - rct.ymin)); BLF_enable(fontid, BLF_CLIPPING | BLF_WORD_WRAP); BLF_clipping(fontid, - rct->xmin, + rct.xmin, /* round to avoid clipping half-way through a line */ - y - (floorf(((y - rct->ymin) - (margin * 2)) / line_spacing) * line_spacing), - rct->xmin + line_width, - rct->ymax); + y - (floorf(((y - rct.ymin) - (margin * 2)) / line_spacing) * line_spacing), + rct.xmin + line_width, + rct.ymax); BLF_wordwrap(fontid, line_width); @@ -442,7 +442,7 @@ static void node_draw_frame(const bContext *C, const float alpha = color[3]; /* shadow */ - node_draw_shadow(snode, node, BASIS_RAD, alpha); + node_draw_shadow(*snode, *node, BASIS_RAD, alpha); /* body */ if (node->flag & NODE_CUSTOM_COLOR) { @@ -452,9 +452,9 @@ static void node_draw_frame(const bContext *C, UI_GetThemeColor4fv(TH_NODE_FRAME, color); } - const rctf *rct = &node->totr; + const rctf &rct = node->totr; UI_draw_roundbox_corner_set(UI_CNR_ALL); - UI_draw_roundbox_4fv(rct, true, BASIS_RAD, color); + UI_draw_roundbox_4fv(&rct, true, BASIS_RAD, color); /* outline active and selected emphasis */ if (node->flag & SELECT) { @@ -465,20 +465,20 @@ static void node_draw_frame(const bContext *C, UI_GetThemeColorShadeAlpha4fv(TH_SELECT, 0, -40, color); } - UI_draw_roundbox_aa(rct, false, BASIS_RAD, color); + UI_draw_roundbox_aa(&rct, false, BASIS_RAD, color); } /* label and text */ - node_draw_frame_label(ntree, node, snode); + node_draw_frame_label(*ntree, *node, *snode); - node_draw_extra_info_panel(snode, node); + node_draw_extra_info_panel(*snode, *node); UI_block_end(C, node->block); UI_block_draw(C, node->block); node->block = nullptr; } -static NodeResizeDirection node_resize_area_frame(bNode *node, const int x, const int y) +static NodeResizeDirection node_resize_area_frame(const bNode *node, const int x, const int y) { const float size = 10.0f; NodeFrame *data = (NodeFrame *)node->storage; @@ -522,7 +522,7 @@ static void node_draw_reroute_prepare(const bContext *UNUSED(C), { /* get "global" coords */ float locx, locy; - node_to_view(node, 0.0f, 0.0f, &locx, &locy); + node_to_view(*node, 0.0f, 0.0f, &locx, &locy); /* reroute node has exactly one input and one output, both in the same place */ bNodeSocket *nsock = (bNodeSocket *)node->outputs.first; @@ -549,46 +549,16 @@ static void node_draw_reroute(const bContext *C, bNodeInstanceKey UNUSED(key)) { char showname[128]; /* 128 used below */ - rctf *rct = &node->totr; + const rctf &rct = node->totr; /* skip if out of view */ - if (node->totr.xmax < region->v2d.cur.xmin || node->totr.xmin > region->v2d.cur.xmax || - node->totr.ymax < region->v2d.cur.ymin || node->totr.ymin > region->v2d.cur.ymax) { + if (rct.xmax < region->v2d.cur.xmin || rct.xmin > region->v2d.cur.xmax || + rct.ymax < region->v2d.cur.ymin || node->totr.ymin > region->v2d.cur.ymax) { UI_block_end(C, node->block); node->block = nullptr; return; } - /* XXX only kept for debugging - * selection state is indicated by socket outline below! - */ -#if 0 - float size = NODE_REROUTE_SIZE; - - /* body */ - float debug_color[4]; - UI_draw_roundbox_corner_set(UI_CNR_ALL); - UI_GetThemeColor4fv(TH_NODE, debug_color); - UI_draw_roundbox_aa(true, rct->xmin, rct->ymin, rct->xmax, rct->ymax, size, debug_color); - - /* outline active and selected emphasis */ - if (node->flag & SELECT) { - GPU_blend(GPU_BLEND_ALPHA); - GPU_line_smooth(true); - /* Using different shades of #TH_TEXT_HI for the emphasis, like triangle. */ - if (node->flag & NODE_ACTIVE) { - UI_GetThemeColorShadeAlpha4fv(TH_TEXT_HI, 0, -40, debug_color); - } - else { - UI_GetThemeColorShadeAlpha4fv(TH_TEXT_HI, -20, -120, debug_color); - } - UI_draw_roundbox_4fv(false, rct->xmin, rct->ymin, rct->xmax, rct->ymax, size, debug_color); - - GPU_line_smooth(false); - GPU_blend(GPU_BLEND_NONE); - } -#endif - if (node->label[0] != '\0') { /* draw title (node label) */ BLI_strncpy(showname, node->label, sizeof(showname)); @@ -596,8 +566,8 @@ static void node_draw_reroute(const bContext *C, UI_BTYPE_LABEL, 0, showname, - (int)(rct->xmin - NODE_DYS), - (int)(rct->ymax), + (int)(rct.xmin - NODE_DYS), + (int)(rct.ymax), (short)512, (short)NODE_DY, nullptr, @@ -611,7 +581,7 @@ static void node_draw_reroute(const bContext *C, /* only draw input socket. as they all are placed on the same position. * highlight also if node itself is selected, since we don't display the node body separately! */ - node_draw_sockets(®ion->v2d, C, ntree, node, false, node->flag & SELECT); + node_draw_sockets(region->v2d, *C, *ntree, *node, false, node->flag & SELECT); UI_block_end(C, node->block); UI_block_draw(C, node->block); @@ -3615,7 +3585,7 @@ static void std_node_socket_draw( if (socket_needs_attribute_search(*node, *sock)) { const bNodeTree *node_tree = (const bNodeTree *)node_ptr->owner_id; - node_geometry_add_attribute_search_button(C, node_tree, node, ptr, row); + node_geometry_add_attribute_search_button(*C, *node_tree, *node, *ptr, *row); } else { uiItemR(row, ptr, "default_value", DEFAULT_FLAGS, "", 0); @@ -3764,23 +3734,23 @@ void ED_init_node_socket_type_virtual(bNodeSocketType *stype) /* ************** Generic drawing ************** */ -void draw_nodespace_back_pix(const bContext *C, - ARegion *region, - SpaceNode *snode, +void draw_nodespace_back_pix(const bContext &C, + ARegion ®ion, + SpaceNode &snode, bNodeInstanceKey parent_key) { - Main *bmain = CTX_data_main(C); - bNodeInstanceKey active_viewer_key = (snode->nodetree ? snode->nodetree->active_viewer_key : - NODE_INSTANCE_KEY_NONE); + Main *bmain = CTX_data_main(&C); + bNodeInstanceKey active_viewer_key = (snode.nodetree ? snode.nodetree->active_viewer_key : + NODE_INSTANCE_KEY_NONE); GPU_matrix_push_projection(); GPU_matrix_push(); - wmOrtho2_region_pixelspace(region); + wmOrtho2_region_pixelspace(®ion); GPU_matrix_identity_set(); - ED_region_draw_cb_draw(C, region, REGION_DRAW_BACKDROP); + ED_region_draw_cb_draw(&C, ®ion, REGION_DRAW_BACKDROP); GPU_matrix_pop_projection(); GPU_matrix_pop(); - if (!(snode->flag & SNODE_BACKDRAW) || !ED_node_is_compositor(snode)) { + if (!(snode.flag & SNODE_BACKDRAW) || !ED_node_is_compositor(&snode)) { return; } @@ -3795,7 +3765,7 @@ void draw_nodespace_back_pix(const bContext *C, GPUFrameBuffer *old_fb = GPU_framebuffer_active_get(); GPU_framebuffer_restore(); BLI_thread_lock(LOCK_DRAW_IMAGE); - DRW_draw_view(C); + DRW_draw_view(&C); BLI_thread_unlock(LOCK_DRAW_IMAGE); GPU_framebuffer_bind_no_srgb(old_fb); /* Draw manager changes the depth state. Set it back to NONE. Without this the node preview @@ -3807,31 +3777,31 @@ void draw_nodespace_back_pix(const bContext *C, ImBuf *ibuf = BKE_image_acquire_ibuf(ima, nullptr, &lock); if (ibuf) { /* somehow the offset has to be calculated inverse */ - wmOrtho2_region_pixelspace(region); - const float x = (region->winx - snode->zoom * ibuf->x) / 2 + snode->xof; - const float y = (region->winy - snode->zoom * ibuf->y) / 2 + snode->yof; + wmOrtho2_region_pixelspace(®ion); + const float x = (region.winx - snode.zoom * ibuf->x) / 2 + snode.xof; + const float y = (region.winy - snode.zoom * ibuf->y) / 2 + snode.yof; /** \note draw selected info on backdrop */ - if (snode->edittree) { - bNode *node = (bNode *)snode->edittree->nodes.first; - rctf *viewer_border = &snode->nodetree->viewer_border; + if (snode.edittree) { + bNode *node = (bNode *)snode.edittree->nodes.first; + rctf *viewer_border = &snode.nodetree->viewer_border; while (node) { if (node->flag & NODE_SELECT) { if (node->typeinfo->draw_backdrop) { - node->typeinfo->draw_backdrop(snode, ibuf, node, x, y); + node->typeinfo->draw_backdrop(&snode, ibuf, node, x, y); } } node = node->next; } - if ((snode->nodetree->flag & NTREE_VIEWER_BORDER) && + if ((snode.nodetree->flag & NTREE_VIEWER_BORDER) && viewer_border->xmin < viewer_border->xmax && viewer_border->ymin < viewer_border->ymax) { rcti pixel_border; BLI_rcti_init(&pixel_border, - x + snode->zoom * viewer_border->xmin * ibuf->x, - x + snode->zoom * viewer_border->xmax * ibuf->x, - y + snode->zoom * viewer_border->ymin * ibuf->y, - y + snode->zoom * viewer_border->ymax * ibuf->y); + x + snode.zoom * viewer_border->xmin * ibuf->x, + x + snode.zoom * viewer_border->xmax * ibuf->x, + y + snode.zoom * viewer_border->ymin * ibuf->y, + y + snode.zoom * viewer_border->ymax * ibuf->y); uint pos = GPU_vertformat_attr_add( immVertexFormat(), "pos", GPU_COMP_F32, 2, GPU_FETCH_FLOAT); @@ -3853,7 +3823,7 @@ void draw_nodespace_back_pix(const bContext *C, /* return quadratic beziers points for a given nodelink and clip if v2d is not nullptr. */ bool node_link_bezier_handles(const View2D *v2d, const SpaceNode *snode, - const bNodeLink *link, + const bNodeLink &link, float vec[4][2]) { float cursor[2] = {0.0f, 0.0f}; @@ -3867,17 +3837,17 @@ bool node_link_bezier_handles(const View2D *v2d, /* in v0 and v3 we put begin/end points */ int toreroute, fromreroute; - if (link->fromsock) { - vec[0][0] = link->fromsock->locx; - vec[0][1] = link->fromsock->locy; - if (link->fromsock->flag & SOCK_MULTI_INPUT) { - node_link_calculate_multi_input_position(link->fromsock->locx, - link->fromsock->locy, - link->fromsock->total_inputs - 1, - link->fromsock->total_inputs, + if (link.fromsock) { + vec[0][0] = link.fromsock->locx; + vec[0][1] = link.fromsock->locy; + if (link.fromsock->flag & SOCK_MULTI_INPUT) { + node_link_calculate_multi_input_position(link.fromsock->locx, + link.fromsock->locy, + link.fromsock->total_inputs - 1, + link.fromsock->total_inputs, vec[0]); } - fromreroute = (link->fromnode && link->fromnode->type == NODE_REROUTE); + fromreroute = (link.fromnode && link.fromnode->type == NODE_REROUTE); } else { if (snode == nullptr) { @@ -3886,17 +3856,17 @@ bool node_link_bezier_handles(const View2D *v2d, copy_v2_v2(vec[0], cursor); fromreroute = 0; } - if (link->tosock) { - vec[3][0] = link->tosock->locx; - vec[3][1] = link->tosock->locy; - if (!(link->tonode->flag & NODE_HIDDEN) && link->tosock->flag & SOCK_MULTI_INPUT) { - node_link_calculate_multi_input_position(link->tosock->locx, - link->tosock->locy, - link->multi_input_socket_index, - link->tosock->total_inputs, + if (link.tosock) { + vec[3][0] = link.tosock->locx; + vec[3][1] = link.tosock->locy; + if (!(link.tonode->flag & NODE_HIDDEN) && link.tosock->flag & SOCK_MULTI_INPUT) { + node_link_calculate_multi_input_position(link.tosock->locx, + link.tosock->locy, + link.multi_input_socket_index, + link.tosock->total_inputs, vec[3]); } - toreroute = (link->tonode && link->tonode->type == NODE_REROUTE); + toreroute = (link.tonode && link.tonode->type == NODE_REROUTE); } else { if (snode == nullptr) { @@ -3962,7 +3932,7 @@ bool node_link_bezier_handles(const View2D *v2d, /* if v2d not nullptr, it clips and returns 0 if not visible */ bool node_link_bezier_points(const View2D *v2d, const SpaceNode *snode, - const bNodeLink *link, + const bNodeLink &link, float coord_array[][2], const int resol) { @@ -4190,7 +4160,7 @@ static char nodelink_get_color_id(int th_col) return 0; } -static void nodelink_batch_draw(const SpaceNode *snode) +static void nodelink_batch_draw(const SpaceNode &snode) { if (g_batch_link.count == 0) { return; @@ -4210,7 +4180,7 @@ static void nodelink_batch_draw(const SpaceNode *snode) GPU_batch_program_set_builtin(g_batch_link.batch, GPU_SHADER_2D_NODELINK_INST); GPU_batch_uniform_4fv_array(g_batch_link.batch, "colors", 6, colors); - GPU_batch_uniform_1f(g_batch_link.batch, "expandSize", snode->runtime->aspect * LINK_WIDTH); + GPU_batch_uniform_1f(g_batch_link.batch, "expandSize", snode.runtime->aspect * LINK_WIDTH); GPU_batch_uniform_1f(g_batch_link.batch, "arrowSize", ARROW_SIZE); GPU_batch_draw(g_batch_link.batch); @@ -4219,22 +4189,22 @@ static void nodelink_batch_draw(const SpaceNode *snode) GPU_blend(GPU_BLEND_NONE); } -void nodelink_batch_start(SpaceNode *UNUSED(snode)) +void nodelink_batch_start(SpaceNode &UNUSED(snode)) { g_batch_link.enabled = true; } -void nodelink_batch_end(SpaceNode *snode) +void nodelink_batch_end(SpaceNode &snode) { nodelink_batch_draw(snode); g_batch_link.enabled = false; } -static void nodelink_batch_add_link(const SpaceNode *snode, - const float p0[2], - const float p1[2], - const float p2[2], - const float p3[2], +static void nodelink_batch_add_link(const SpaceNode &snode, + const float2 &p0, + const float2 &p1, + const float2 &p2, + const float2 &p3, int th_col1, int th_col2, int th_col3, @@ -4277,13 +4247,13 @@ static void nodelink_batch_add_link(const SpaceNode *snode, } /* don't do shadows if th_col3 is -1. */ -void node_draw_link_bezier(const bContext *C, - const View2D *v2d, - const SpaceNode *snode, - const bNodeLink *link, - int th_col1, - int th_col2, - int th_col3) +void node_draw_link_bezier(const bContext &C, + const View2D &v2d, + const SpaceNode &snode, + const bNodeLink &link, + const int th_col1, + const int th_col2, + const int th_col3) { const float dim_factor = node_link_dim_factor(v2d, link); float thickness = 1.5f; @@ -4292,8 +4262,8 @@ void node_draw_link_bezier(const bContext *C, bTheme *btheme = UI_GetTheme(); const float dash_alpha = btheme->space_node.dash_alpha; - if (snode->edittree->type == NTREE_GEOMETRY) { - if (link->fromsock && link->fromsock->display_shape == SOCK_DISPLAY_SHAPE_DIAMOND) { + if (snode.edittree->type == NTREE_GEOMETRY) { + if (link.fromsock && link.fromsock->display_shape == SOCK_DISPLAY_SHAPE_DIAMOND) { /* Make field links a bit thinner. */ thickness = 1.0f; /* Draw field as dashes. */ @@ -4302,11 +4272,11 @@ void node_draw_link_bezier(const bContext *C, } float vec[4][2]; - const bool highlighted = link->flag & NODE_LINK_TEMP_HIGHLIGHT; - if (node_link_bezier_handles(v2d, snode, link, vec)) { - int drawarrow = ((link->tonode && (link->tonode->type == NODE_REROUTE)) && - (link->fromnode && (link->fromnode->type == NODE_REROUTE))); - int drawmuted = (link->flag & NODE_LINK_MUTED); + const bool highlighted = link.flag & NODE_LINK_TEMP_HIGHLIGHT; + if (node_link_bezier_handles(&v2d, &snode, link, vec)) { + int drawarrow = ((link.tonode && (link.tonode->type == NODE_REROUTE)) && + (link.fromnode && (link.fromnode->type == NODE_REROUTE))); + int drawmuted = (link.flag & NODE_LINK_MUTED); if (g_batch_link.batch == nullptr) { nodelink_batch_init(); } @@ -4316,23 +4286,23 @@ void node_draw_link_bezier(const bContext *C, UI_GetThemeColor4fv(th_col3, colors[0]); } - if (snode->overlay.flag & SN_OVERLAY_SHOW_OVERLAYS && - snode->overlay.flag & SN_OVERLAY_SHOW_WIRE_COLORS) { + 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 *)snode->edittree, &RNA_Node, link->fromnode, &from_node_ptr); - RNA_pointer_create((ID *)snode->edittree, &RNA_Node, link->tonode, &to_node_ptr); - if (link->fromsock) { - node_socket_color_get(C, snode->edittree, &from_node_ptr, link->fromsock, colors[1]); + RNA_pointer_create((ID *)snode.edittree, &RNA_Node, link.fromnode, &from_node_ptr); + RNA_pointer_create((ID *)snode.edittree, &RNA_Node, link.tonode, &to_node_ptr); + if (link.fromsock) { + node_socket_color_get(C, *snode.edittree, from_node_ptr, *link.fromsock, colors[1]); } else { - node_socket_color_get(C, snode->edittree, &to_node_ptr, link->tosock, colors[1]); + node_socket_color_get(C, *snode.edittree, to_node_ptr, *link.tosock, colors[1]); } - if (link->tosock) { - node_socket_color_get(C, snode->edittree, &to_node_ptr, link->tosock, colors[2]); + if (link.tosock) { + node_socket_color_get(C, *snode.edittree, to_node_ptr, *link.tosock, colors[2]); } else { - node_socket_color_get(C, snode->edittree, &from_node_ptr, link->fromsock, colors[2]); + node_socket_color_get(C, *snode.edittree, from_node_ptr, *link.fromsock, colors[2]); } } else { @@ -4341,8 +4311,8 @@ void node_draw_link_bezier(const bContext *C, } /* Highlight links connected to selected nodes. */ - const bool is_fromnode_selected = link->fromnode && link->fromnode->flag & SELECT; - const bool is_tonode_selected = link->tonode && link->tonode->flag & SELECT; + const bool is_fromnode_selected = link.fromnode && link.fromnode->flag & SELECT; + const bool is_tonode_selected = link.tonode && link.tonode->flag & SELECT; if (is_fromnode_selected || is_tonode_selected) { float color_selected[4]; UI_GetThemeColor4fv(TH_EDGE_SELECT, color_selected); @@ -4389,7 +4359,7 @@ void node_draw_link_bezier(const bContext *C, GPU_batch_program_set_builtin(batch, GPU_SHADER_2D_NODELINK); GPU_batch_uniform_2fv_array(batch, "bezierPts", 4, vec); GPU_batch_uniform_4fv_array(batch, "colors", 3, colors); - GPU_batch_uniform_1f(batch, "expandSize", snode->runtime->aspect * LINK_WIDTH); + GPU_batch_uniform_1f(batch, "expandSize", snode.runtime->aspect * LINK_WIDTH); GPU_batch_uniform_1f(batch, "arrowSize", ARROW_SIZE); GPU_batch_uniform_1i(batch, "doArrow", drawarrow); GPU_batch_uniform_1i(batch, "doMuted", drawmuted); @@ -4403,36 +4373,36 @@ void node_draw_link_bezier(const bContext *C, } /* NOTE: this is used for fake links in groups too. */ -void node_draw_link(const bContext *C, - const View2D *v2d, - const SpaceNode *snode, - const bNodeLink *link) +void node_draw_link(const bContext &C, + const View2D &v2d, + const SpaceNode &snode, + const bNodeLink &link) { int th_col1 = TH_WIRE_INNER, th_col2 = TH_WIRE_INNER, th_col3 = TH_WIRE; - if (link->fromsock == nullptr && link->tosock == nullptr) { + if (link.fromsock == nullptr && link.tosock == nullptr) { return; } /* new connection */ - if (!link->fromsock || !link->tosock) { + if (!link.fromsock || !link.tosock) { th_col1 = th_col2 = TH_ACTIVE; } else { /* going to give issues once... */ - if (link->tosock->flag & SOCK_UNAVAIL) { + if (link.tosock->flag & SOCK_UNAVAIL) { return; } - if (link->fromsock->flag & SOCK_UNAVAIL) { + if (link.fromsock->flag & SOCK_UNAVAIL) { return; } - if (link->flag & NODE_LINK_VALID) { + if (link.flag & NODE_LINK_VALID) { /* special indicated link, on drop-node */ - if (link->flag & NODE_LINKFLAG_HILITE) { + if (link.flag & NODE_LINKFLAG_HILITE) { th_col1 = th_col2 = TH_ACTIVE; } - else if (link->flag & NODE_LINK_MUTED) { + else if (link.flag & NODE_LINK_MUTED) { th_col1 = th_col2 = TH_REDALERT; } } @@ -4443,9 +4413,9 @@ void node_draw_link(const bContext *C, } } /* Links from field to non-field sockets are not allowed. */ - if (snode->edittree->type == NTREE_GEOMETRY && !(link->flag & NODE_LINK_DRAGGED)) { - if ((link->fromsock && link->fromsock->display_shape == SOCK_DISPLAY_SHAPE_DIAMOND) && - (link->tosock && link->tosock->display_shape == SOCK_DISPLAY_SHAPE_CIRCLE)) { + if (snode.edittree->type == NTREE_GEOMETRY && !(link.flag & NODE_LINK_DRAGGED)) { + if ((link.fromsock && link.fromsock->display_shape == SOCK_DISPLAY_SHAPE_DIAMOND) && + (link.tosock && link.tosock->display_shape == SOCK_DISPLAY_SHAPE_CIRCLE)) { th_col1 = th_col2 = th_col3 = TH_REDALERT; } } diff --git a/source/blender/editors/space_node/node_add.cc b/source/blender/editors/space_node/node_add.cc index 2e3579caaa1..5276cc39e83 100644 --- a/source/blender/editors/space_node/node_add.cc +++ b/source/blender/editors/space_node/node_add.cc @@ -67,19 +67,19 @@ * Can be used with both custom and static nodes, * if `idname == nullptr` the static int type will be used instead. */ -bNode *node_add_node(const bContext *C, const char *idname, int type, float locx, float locy) +bNode *node_add_node(const bContext &C, const char *idname, int type, float locx, float locy) { - SpaceNode *snode = CTX_wm_space_node(C); - Main *bmain = CTX_data_main(C); + SpaceNode &snode = *CTX_wm_space_node(&C); + Main &bmain = *CTX_data_main(&C); bNode *node = nullptr; node_deselect_all(snode); if (idname) { - node = nodeAddNode(C, snode->edittree, idname); + node = nodeAddNode(&C, snode.edittree, idname); } else { - node = nodeAddStaticNode(C, snode->edittree, type); + node = nodeAddStaticNode(&C, snode.edittree, type); } BLI_assert(node && node->typeinfo); @@ -89,13 +89,13 @@ bNode *node_add_node(const bContext *C, const char *idname, int type, float locx nodeSetSelected(node, true); - ntreeUpdateTree(bmain, snode->edittree); - ED_node_set_active(bmain, snode, snode->edittree, node, nullptr); + ntreeUpdateTree(&bmain, snode.edittree); + ED_node_set_active(&bmain, &snode, snode.edittree, node, nullptr); snode_update(snode, node); - if (snode->nodetree->type == NTREE_TEXTURE) { - ntreeTexCheckCyclics(snode->edittree); + if (snode.nodetree->type == NTREE_TEXTURE) { + ntreeTexCheckCyclics(snode.edittree); } return node; @@ -107,7 +107,7 @@ bNode *node_add_node(const bContext *C, const char *idname, int type, float locx /** \name Add Reroute Operator * \{ */ -static bool add_reroute_intersect_check(bNodeLink *link, +static bool add_reroute_intersect_check(const bNodeLink &link, float mcoords[][2], int tot, float result[2]) @@ -224,9 +224,9 @@ static bNodeSocketLink *add_reroute_do_socket_section(bContext *C, static int add_reroute_exec(bContext *C, wmOperator *op) { - SpaceNode *snode = CTX_wm_space_node(C); - ARegion *region = CTX_wm_region(C); - bNodeTree *ntree = snode->edittree; + SpaceNode &snode = *CTX_wm_space_node(C); + ARegion ®ion = *CTX_wm_region(C); + bNodeTree &ntree = *snode.edittree; float mcoords[256][2]; int i = 0; @@ -236,7 +236,7 @@ static int add_reroute_exec(bContext *C, wmOperator *op) RNA_float_get_array(&itemptr, "loc", loc); UI_view2d_region_to_view( - ®ion->v2d, (short)loc[0], (short)loc[1], &mcoords[i][0], &mcoords[i][1]); + ®ion.v2d, (short)loc[0], (short)loc[1], &mcoords[i][0], &mcoords[i][1]); i++; if (i >= 256) { break; @@ -246,7 +246,6 @@ static int add_reroute_exec(bContext *C, wmOperator *op) if (i > 1) { ListBase output_links, input_links; - bNodeLink *link; bNodeSocketLink *socklink; float insert_point[2]; @@ -259,11 +258,11 @@ static int add_reroute_exec(bContext *C, wmOperator *op) BLI_listbase_clear(&output_links); BLI_listbase_clear(&input_links); - for (link = (bNodeLink *)ntree->links.first; link; link = link->next) { - if (node_link_is_hidden_or_dimmed(®ion->v2d, link)) { + LISTBASE_FOREACH (bNodeLink *, link, &ntree.links) { + if (node_link_is_hidden_or_dimmed(region.v2d, *link)) { continue; } - if (add_reroute_intersect_check(link, mcoords, i, insert_point)) { + if (add_reroute_intersect_check(*link, mcoords, i, insert_point)) { add_reroute_insert_socket_link(&output_links, link->fromsock, link, insert_point); add_reroute_insert_socket_link(&input_links, link->tosock, link, insert_point); @@ -288,9 +287,9 @@ static int add_reroute_exec(bContext *C, wmOperator *op) BLI_freelistN(&input_links); /* always last */ - ntreeUpdateTree(CTX_data_main(C), ntree); - snode_notify(C, snode); - snode_dag_update(C, snode); + ntreeUpdateTree(CTX_data_main(C), &ntree); + snode_notify(*C, snode); + snode_dag_update(*C, snode); return OPERATOR_FINISHED; } @@ -377,7 +376,7 @@ static int node_add_group_exec(bContext *C, wmOperator *op) ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C)); - bNode *group_node = node_add_node(C, + bNode *group_node = node_add_node(*C, node_group_idname(C), (node_group->type == NTREE_CUSTOM) ? NODE_CUSTOM_GROUP : NODE_GROUP, @@ -395,8 +394,8 @@ static int node_add_group_exec(bContext *C, wmOperator *op) ntreeUpdateTree(bmain, node_group); ntreeUpdateTree(bmain, ntree); - snode_notify(C, snode); - snode_dag_update(C, snode); + snode_notify(*C, *snode); + snode_dag_update(*C, *snode); return OPERATOR_FINISHED; } @@ -469,7 +468,7 @@ static int node_add_object_exec(bContext *C, wmOperator *op) ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C)); bNode *object_node = node_add_node( - C, nullptr, GEO_NODE_OBJECT_INFO, snode->runtime->cursor[0], snode->runtime->cursor[1]); + *C, nullptr, GEO_NODE_OBJECT_INFO, snode->runtime->cursor[0], snode->runtime->cursor[1]); if (!object_node) { BKE_report(op->reports, RPT_WARNING, "Could not add node object"); return OPERATOR_CANCELLED; @@ -488,8 +487,8 @@ static int node_add_object_exec(bContext *C, wmOperator *op) nodeSetActive(ntree, object_node); ntreeUpdateTree(bmain, ntree); - snode_notify(C, snode); - snode_dag_update(C, snode); + snode_notify(*C, *snode); + snode_dag_update(*C, *snode); ED_node_tag_update_nodetree(bmain, ntree, object_node); DEG_relations_tag_update(bmain); @@ -580,7 +579,7 @@ static int node_add_texture_exec(bContext *C, wmOperator *op) ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C)); - bNode *texture_node = node_add_node(C, + bNode *texture_node = node_add_node(*C, nullptr, GEO_NODE_LEGACY_ATTRIBUTE_SAMPLE_TEXTURE, snode->runtime->cursor[0], @@ -596,8 +595,8 @@ static int node_add_texture_exec(bContext *C, wmOperator *op) nodeSetActive(ntree, texture_node); ntreeUpdateTree(bmain, ntree); - snode_notify(C, snode); - snode_dag_update(C, snode); + snode_notify(*C, *snode); + snode_dag_update(*C, *snode); DEG_relations_tag_update(bmain); ED_node_tag_update_nodetree(bmain, ntree, texture_node); @@ -680,8 +679,8 @@ static Collection *node_add_collection_get_and_poll_collection_node_tree(Main *b static int node_add_collection_exec(bContext *C, wmOperator *op) { Main *bmain = CTX_data_main(C); - SpaceNode *snode = CTX_wm_space_node(C); - bNodeTree *ntree = snode->edittree; + SpaceNode &snode = *CTX_wm_space_node(C); + bNodeTree *ntree = snode.edittree; Collection *collection; if (!(collection = node_add_collection_get_and_poll_collection_node_tree(bmain, op))) { @@ -691,7 +690,7 @@ static int node_add_collection_exec(bContext *C, wmOperator *op) ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C)); bNode *collection_node = node_add_node( - C, nullptr, GEO_NODE_COLLECTION_INFO, snode->runtime->cursor[0], snode->runtime->cursor[1]); + *C, nullptr, GEO_NODE_COLLECTION_INFO, snode.runtime->cursor[0], snode.runtime->cursor[1]); if (!collection_node) { BKE_report(op->reports, RPT_WARNING, "Could not add node collection"); return OPERATOR_CANCELLED; @@ -710,8 +709,8 @@ static int node_add_collection_exec(bContext *C, wmOperator *op) nodeSetActive(ntree, collection_node); ntreeUpdateTree(bmain, ntree); - snode_notify(C, snode); - snode_dag_update(C, snode); + snode_notify(*C, snode); + snode_dag_update(*C, snode); DEG_relations_tag_update(bmain); ED_node_tag_update_nodetree(bmain, ntree, collection_node); @@ -788,7 +787,7 @@ static bool node_add_file_poll(bContext *C) static int node_add_file_exec(bContext *C, wmOperator *op) { Main *bmain = CTX_data_main(C); - SpaceNode *snode = CTX_wm_space_node(C); + SpaceNode &snode = *CTX_wm_space_node(C); bNode *node; Image *ima; int type = 0; @@ -798,7 +797,7 @@ static int node_add_file_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; } - switch (snode->nodetree->type) { + switch (snode.nodetree->type) { case NTREE_SHADER: type = SH_NODE_TEX_IMAGE; break; @@ -817,7 +816,7 @@ static int node_add_file_exec(bContext *C, wmOperator *op) ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C)); - node = node_add_node(C, nullptr, type, snode->runtime->cursor[0], snode->runtime->cursor[1]); + node = node_add_node(*C, nullptr, type, snode.runtime->cursor[0], snode.runtime->cursor[1]); if (!node) { BKE_report(op->reports, RPT_WARNING, "Could not add an image node"); @@ -841,8 +840,8 @@ static int node_add_file_exec(bContext *C, wmOperator *op) WM_event_add_notifier(C, NC_IMAGE | NA_EDITED, ima); } - snode_notify(C, snode); - snode_dag_update(C, snode); + snode_notify(*C, snode); + snode_dag_update(*C, snode); DEG_relations_tag_update(bmain); return OPERATOR_FINISHED; @@ -923,7 +922,7 @@ static bool node_add_mask_poll(bContext *C) static int node_add_mask_exec(bContext *C, wmOperator *op) { Main *bmain = CTX_data_main(C); - SpaceNode *snode = CTX_wm_space_node(C); + SpaceNode &snode = *CTX_wm_space_node(C); bNode *node; ID *mask = node_add_mask_get_and_poll_mask(bmain, op); @@ -934,7 +933,7 @@ static int node_add_mask_exec(bContext *C, wmOperator *op) ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C)); node = node_add_node( - C, nullptr, CMP_NODE_MASK, snode->runtime->cursor[0], snode->runtime->cursor[1]); + *C, nullptr, CMP_NODE_MASK, snode.runtime->cursor[0], snode.runtime->cursor[1]); if (!node) { BKE_report(op->reports, RPT_WARNING, "Could not add a mask node"); @@ -944,8 +943,8 @@ static int node_add_mask_exec(bContext *C, wmOperator *op) node->id = mask; id_us_plus(mask); - snode_notify(C, snode); - snode_dag_update(C, snode); + snode_notify(*C, snode); + snode_dag_update(*C, snode); DEG_relations_tag_update(bmain); return OPERATOR_FINISHED; diff --git a/source/blender/editors/space_node/node_draw.cc b/source/blender/editors/space_node/node_draw.cc index 6452dc54544..fd07e6e0aba 100644 --- a/source/blender/editors/space_node/node_draw.cc +++ b/source/blender/editors/space_node/node_draw.cc @@ -93,6 +93,7 @@ # include "COM_compositor.h" #endif +using blender::float2; using blender::Map; using blender::Set; using blender::Span; @@ -120,7 +121,7 @@ void ED_node_tree_update(const bContext *C) { SpaceNode *snode = CTX_wm_space_node(C); if (snode) { - snode_set_context(C); + snode_set_context(*C); id_us_ensure_real(&snode->nodetree->id); } @@ -187,7 +188,7 @@ void ED_node_tag_update_nodetree(Main *bmain, bNodeTree *ntree, bNode *node) bool do_tag_update = true; if (node != nullptr) { - if (!node_connected_to_output(bmain, ntree, node)) { + if (!node_connected_to_output(*bmain, *ntree, *node)) { do_tag_update = false; } } @@ -323,52 +324,49 @@ void ED_node_sort(bNodeTree *ntree) } } -static void node_uiblocks_init(const bContext *C, bNodeTree *ntree) +static void node_uiblocks_init(const bContext &C, bNodeTree &ntree) { /* Add node uiBlocks in drawing order - prevents events going to overlapping nodes. */ - LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { + LISTBASE_FOREACH (bNode *, node, &ntree.nodes) { /* ui block */ char uiblockstr[32]; BLI_snprintf(uiblockstr, sizeof(uiblockstr), "node buttons %p", (void *)node); - node->block = UI_block_begin(C, CTX_wm_region(C), uiblockstr, UI_EMBOSS); + node->block = UI_block_begin(&C, CTX_wm_region(&C), uiblockstr, UI_EMBOSS); /* this cancels events for background nodes */ UI_block_flag_enable(node->block, UI_BLOCK_CLIP_EVENTS); } } -void node_to_view(const bNode *node, float x, float y, float *rx, float *ry) +void node_to_view(const bNode &node, float x, float y, float *rx, float *ry) { - nodeToView(node, x, y, rx, ry); + nodeToView(&node, x, y, rx, ry); *rx *= UI_DPI_FAC; *ry *= UI_DPI_FAC; } -void node_to_updated_rect(const bNode *node, rctf *r_rect) +void node_to_updated_rect(const bNode &node, rctf &r_rect) { - node_to_view(node, node->offsetx, node->offsety, &r_rect->xmin, &r_rect->ymax); - node_to_view(node, - node->offsetx + node->width, - node->offsety - node->height, - &r_rect->xmax, - &r_rect->ymin); + node_to_view(node, node.offsetx, node.offsety, &r_rect.xmin, &r_rect.ymax); + node_to_view( + node, node.offsetx + node.width, node.offsety - node.height, &r_rect.xmax, &r_rect.ymin); } -void node_from_view(const bNode *node, float x, float y, float *rx, float *ry) +void node_from_view(const bNode &node, float x, float y, float *rx, float *ry) { x /= UI_DPI_FAC; y /= UI_DPI_FAC; - nodeFromView(node, x, y, rx, ry); + nodeFromView(&node, x, y, rx, ry); } /** * Based on settings and sockets in node, set drawing rect info. */ -static void node_update_basis(const bContext *C, bNodeTree *ntree, bNode *node) +static void node_update_basis(const bContext &C, bNodeTree &ntree, bNode &node) { PointerRNA nodeptr; - RNA_pointer_create(&ntree->id, &RNA_Node, node, &nodeptr); + RNA_pointer_create(&ntree.id, &RNA_Node, &node, &nodeptr); /* Get "global" coordinates. */ float locx, locy; @@ -383,7 +381,7 @@ static void node_update_basis(const bContext *C, bNodeTree *ntree, bNode *node) dy -= NODE_DY; /* Add a little bit of padding above the top socket. */ - if (node->outputs.first || node->inputs.first) { + if (node.outputs.first || node.inputs.first) { dy -= NODE_DYS / 2; } @@ -391,15 +389,15 @@ static void node_update_basis(const bContext *C, bNodeTree *ntree, bNode *node) bool add_output_space = false; int buty; - LISTBASE_FOREACH (bNodeSocket *, nsock, &node->outputs) { + LISTBASE_FOREACH (bNodeSocket *, nsock, &node.outputs) { if (nodeSocketIsHidden(nsock)) { continue; } PointerRNA sockptr; - RNA_pointer_create(&ntree->id, &RNA_NodeSocket, nsock, &sockptr); + RNA_pointer_create(&ntree.id, &RNA_NodeSocket, nsock, &sockptr); - uiLayout *layout = UI_block_layout(node->block, + uiLayout *layout = UI_block_layout(node.block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, locx + NODE_DYS, @@ -409,7 +407,7 @@ static void node_update_basis(const bContext *C, bNodeTree *ntree, bNode *node) 0, UI_style_get_dpi()); - if (node->flag & NODE_MUTED) { + if (node.flag & NODE_MUTED) { uiLayoutSetActive(layout, false); } @@ -421,10 +419,10 @@ static void node_update_basis(const bContext *C, bNodeTree *ntree, bNode *node) uiLayout *row = uiLayoutRow(layout, true); uiLayoutSetAlignment(row, UI_LAYOUT_ALIGN_RIGHT); const char *socket_label = nodeSocketLabel(nsock); - nsock->typeinfo->draw((bContext *)C, row, &sockptr, &nodeptr, IFACE_(socket_label)); + nsock->typeinfo->draw((bContext *)&C, row, &sockptr, &nodeptr, IFACE_(socket_label)); - UI_block_align_end(node->block); - UI_block_layout_resolve(node->block, nullptr, &buty); + UI_block_align_end(node.block); + UI_block_layout_resolve(node.block, nullptr, &buty); /* Ensure minimum socket height in case layout is empty. */ buty = min_ii(buty, dy - NODE_DY); @@ -445,86 +443,86 @@ static void node_update_basis(const bContext *C, bNodeTree *ntree, bNode *node) dy -= NODE_DY / 4; } - node->prvr.xmin = locx + NODE_DYS; - node->prvr.xmax = locx + NODE_WIDTH(node) - NODE_DYS; + node.prvr.xmin = locx + NODE_DYS; + node.prvr.xmax = locx + NODE_WIDTH(node) - NODE_DYS; /* preview rect? */ - if (node->flag & NODE_PREVIEW) { + if (node.flag & NODE_PREVIEW) { float aspect = 1.0f; - if (node->preview_xsize && node->preview_ysize) { - aspect = (float)node->preview_ysize / (float)node->preview_xsize; + if (node.preview_xsize && node.preview_ysize) { + aspect = (float)node.preview_ysize / (float)node.preview_xsize; } dy -= NODE_DYS / 2; - node->prvr.ymax = dy; + node.prvr.ymax = dy; if (aspect <= 1.0f) { - node->prvr.ymin = dy - aspect * (NODE_WIDTH(node) - NODE_DY); + node.prvr.ymin = dy - aspect * (NODE_WIDTH(node) - NODE_DY); } else { /* Width correction of image. XXX huh? (ton) */ float dx = (NODE_WIDTH(node) - NODE_DYS) - (NODE_WIDTH(node) - NODE_DYS) / aspect; - node->prvr.ymin = dy - (NODE_WIDTH(node) - NODE_DY); + node.prvr.ymin = dy - (NODE_WIDTH(node) - NODE_DY); - node->prvr.xmin += 0.5f * dx; - node->prvr.xmax -= 0.5f * dx; + node.prvr.xmin += 0.5f * dx; + node.prvr.xmax -= 0.5f * dx; } - dy = node->prvr.ymin - NODE_DYS / 2; + dy = node.prvr.ymin - NODE_DYS / 2; /* Make sure that maximums are bigger or equal to minimums. */ - if (node->prvr.xmax < node->prvr.xmin) { - SWAP(float, node->prvr.xmax, node->prvr.xmin); + if (node.prvr.xmax < node.prvr.xmin) { + SWAP(float, node.prvr.xmax, node.prvr.xmin); } - if (node->prvr.ymax < node->prvr.ymin) { - SWAP(float, node->prvr.ymax, node->prvr.ymin); + if (node.prvr.ymax < node.prvr.ymin) { + SWAP(float, node.prvr.ymax, node.prvr.ymin); } } /* Buttons rect? */ - if (node->typeinfo->draw_buttons && (node->flag & NODE_OPTIONS)) { + if (node.typeinfo->draw_buttons && (node.flag & NODE_OPTIONS)) { dy -= NODE_DYS / 2; /* Set this for `uifunc()` that don't use layout engine yet. */ - node->butr.xmin = 0; - node->butr.xmax = NODE_WIDTH(node) - 2 * NODE_DYS; - node->butr.ymin = 0; - node->butr.ymax = 0; + node.butr.xmin = 0; + node.butr.xmax = NODE_WIDTH(node) - 2 * NODE_DYS; + node.butr.ymin = 0; + node.butr.ymax = 0; - uiLayout *layout = UI_block_layout(node->block, + uiLayout *layout = UI_block_layout(node.block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, locx + NODE_DYS, dy, - node->butr.xmax, + node.butr.xmax, 0, 0, UI_style_get_dpi()); - if (node->flag & NODE_MUTED) { + if (node.flag & NODE_MUTED) { uiLayoutSetActive(layout, false); } uiLayoutSetContextPointer(layout, "node", &nodeptr); - node->typeinfo->draw_buttons(layout, (bContext *)C, &nodeptr); + node.typeinfo->draw_buttons(layout, (bContext *)&C, &nodeptr); - UI_block_align_end(node->block); - UI_block_layout_resolve(node->block, nullptr, &buty); + UI_block_align_end(node.block); + UI_block_layout_resolve(node.block, nullptr, &buty); dy = buty - NODE_DYS / 2; } /* Input sockets. */ - LISTBASE_FOREACH (bNodeSocket *, nsock, &node->inputs) { + LISTBASE_FOREACH (bNodeSocket *, nsock, &node.inputs) { if (nodeSocketIsHidden(nsock)) { continue; } PointerRNA sockptr; - RNA_pointer_create(&ntree->id, &RNA_NodeSocket, nsock, &sockptr); + RNA_pointer_create(&ntree.id, &RNA_NodeSocket, nsock, &sockptr); /* Add the half the height of a multi-input socket to cursor Y * to account for the increased height of the taller sockets. */ @@ -536,7 +534,7 @@ static void node_update_basis(const bContext *C, bNodeTree *ntree, bNode *node) } dy -= multi_input_socket_offset * 0.5f; - uiLayout *layout = UI_block_layout(node->block, + uiLayout *layout = UI_block_layout(node.block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, locx + NODE_DYS, @@ -546,7 +544,7 @@ static void node_update_basis(const bContext *C, bNodeTree *ntree, bNode *node) 0, UI_style_get_dpi()); - if (node->flag & NODE_MUTED) { + if (node.flag & NODE_MUTED) { uiLayoutSetActive(layout, false); } @@ -557,10 +555,10 @@ static void node_update_basis(const bContext *C, bNodeTree *ntree, bNode *node) uiLayout *row = uiLayoutRow(layout, true); const char *socket_label = nodeSocketLabel(nsock); - nsock->typeinfo->draw((bContext *)C, row, &sockptr, &nodeptr, IFACE_(socket_label)); + nsock->typeinfo->draw((bContext *)&C, row, &sockptr, &nodeptr, IFACE_(socket_label)); - UI_block_align_end(node->block); - UI_block_layout_resolve(node->block, nullptr, &buty); + UI_block_align_end(node.block); + UI_block_layout_resolve(node.block, nullptr, &buty); /* Ensure minimum socket height in case layout is empty. */ buty = min_ii(buty, dy - NODE_DY); @@ -576,28 +574,28 @@ static void node_update_basis(const bContext *C, bNodeTree *ntree, bNode *node) } /* Little bit of space in end. */ - if (node->inputs.first || (node->flag & (NODE_OPTIONS | NODE_PREVIEW)) == 0) { + if (node.inputs.first || (node.flag & (NODE_OPTIONS | NODE_PREVIEW)) == 0) { dy -= NODE_DYS / 2; } - node->totr.xmin = locx; - node->totr.xmax = locx + NODE_WIDTH(node); - node->totr.ymax = locy; - node->totr.ymin = min_ff(dy, locy - 2 * NODE_DY); + node.totr.xmin = locx; + node.totr.xmax = locx + NODE_WIDTH(node); + node.totr.ymax = locy; + node.totr.ymin = min_ff(dy, locy - 2 * NODE_DY); /* Set the block bounds to clip mouse events from underlying nodes. * Add a margin for sockets on each side. */ - UI_block_bounds_set_explicit(node->block, - node->totr.xmin - NODE_SOCKSIZE, - node->totr.ymin, - node->totr.xmax + NODE_SOCKSIZE, - node->totr.ymax); + UI_block_bounds_set_explicit(node.block, + node.totr.xmin - NODE_SOCKSIZE, + node.totr.ymin, + node.totr.xmax + NODE_SOCKSIZE, + node.totr.ymax); } /** * Based on settings in node, sets drawing rect info. */ -static void node_update_hidden(bNode *node) +static void node_update_hidden(bNode &node) { int totin = 0, totout = 0; @@ -609,12 +607,12 @@ static void node_update_hidden(bNode *node) locy = round(locy); /* Calculate minimal radius. */ - LISTBASE_FOREACH (bNodeSocket *, nsock, &node->inputs) { + LISTBASE_FOREACH (bNodeSocket *, nsock, &node.inputs) { if (!nodeSocketIsHidden(nsock)) { totin++; } } - LISTBASE_FOREACH (bNodeSocket *, nsock, &node->outputs) { + LISTBASE_FOREACH (bNodeSocket *, nsock, &node.outputs) { if (!nodeSocketIsHidden(nsock)) { totout++; } @@ -626,20 +624,20 @@ static void node_update_hidden(bNode *node) hiddenrad += 5.0f * (float)(tot - 4); } - node->totr.xmin = locx; - node->totr.xmax = locx + max_ff(NODE_WIDTH(node), 2 * hiddenrad); - node->totr.ymax = locy + (hiddenrad - 0.5f * NODE_DY); - node->totr.ymin = node->totr.ymax - 2 * hiddenrad; + node.totr.xmin = locx; + node.totr.xmax = locx + max_ff(NODE_WIDTH(node), 2 * hiddenrad); + node.totr.ymax = locy + (hiddenrad - 0.5f * NODE_DY); + node.totr.ymin = node.totr.ymax - 2 * hiddenrad; /* Output sockets. */ float rad = (float)M_PI / (1.0f + (float)totout); float drad = rad; - LISTBASE_FOREACH (bNodeSocket *, nsock, &node->outputs) { + LISTBASE_FOREACH (bNodeSocket *, nsock, &node.outputs) { if (!nodeSocketIsHidden(nsock)) { /* Round the socket location to stop it from jiggling. */ - nsock->locx = round(node->totr.xmax - hiddenrad + sinf(rad) * hiddenrad); - nsock->locy = round(node->totr.ymin + hiddenrad + cosf(rad) * hiddenrad); + nsock->locx = round(node.totr.xmax - hiddenrad + sinf(rad) * hiddenrad); + nsock->locy = round(node.totr.ymin + hiddenrad + cosf(rad) * hiddenrad); rad += drad; } } @@ -647,31 +645,31 @@ static void node_update_hidden(bNode *node) /* Input sockets. */ rad = drad = -(float)M_PI / (1.0f + (float)totin); - LISTBASE_FOREACH (bNodeSocket *, nsock, &node->inputs) { + LISTBASE_FOREACH (bNodeSocket *, nsock, &node.inputs) { if (!nodeSocketIsHidden(nsock)) { /* Round the socket location to stop it from jiggling. */ - nsock->locx = round(node->totr.xmin + hiddenrad + sinf(rad) * hiddenrad); - nsock->locy = round(node->totr.ymin + hiddenrad + cosf(rad) * hiddenrad); + nsock->locx = round(node.totr.xmin + hiddenrad + sinf(rad) * hiddenrad); + nsock->locy = round(node.totr.ymin + hiddenrad + cosf(rad) * hiddenrad); rad += drad; } } /* Set the block bounds to clip mouse events from underlying nodes. * Add a margin for sockets on each side. */ - UI_block_bounds_set_explicit(node->block, - node->totr.xmin - NODE_SOCKSIZE, - node->totr.ymin, - node->totr.xmax + NODE_SOCKSIZE, - node->totr.ymax); + UI_block_bounds_set_explicit(node.block, + node.totr.xmin - NODE_SOCKSIZE, + node.totr.ymin, + node.totr.xmax + NODE_SOCKSIZE, + node.totr.ymax); } void node_update_default(const bContext *C, bNodeTree *ntree, bNode *node) { if (node->flag & NODE_HIDDEN) { - node_update_hidden(node); + node_update_hidden(*node); } else { - node_update_basis(C, ntree, node); + node_update_basis(*C, *ntree, *node); } } @@ -685,13 +683,13 @@ int node_tweak_area_default(bNode *node, int x, int y) return BLI_rctf_isect_pt(&node->totr, x, y); } -int node_get_colorid(bNode *node) +int node_get_colorid(bNode &node) { - switch (node->typeinfo->nclass) { + switch (node.typeinfo->nclass) { case NODE_CLASS_INPUT: return TH_NODE_INPUT; case NODE_CLASS_OUTPUT: - return (node->flag & NODE_DO_OUTPUT) ? TH_NODE_OUTPUT : TH_NODE; + return (node.flag & NODE_DO_OUTPUT) ? TH_NODE_OUTPUT : TH_NODE; case NODE_CLASS_CONVERTER: return TH_NODE_CONVERTER; case NODE_CLASS_OP_COLOR: @@ -727,21 +725,21 @@ int node_get_colorid(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 bContext &C, + const View2D &v2d, + const SpaceNode &snode, + const bNode &node) { GPU_blend(GPU_BLEND_ALPHA); - LISTBASE_FOREACH (const bNodeLink *, link, &node->internal_links) { - node_draw_link_bezier(C, v2d, snode, link, TH_WIRE_INNER, TH_WIRE_INNER, TH_WIRE); + LISTBASE_FOREACH (const bNodeLink *, link, &node.internal_links) { + node_draw_link_bezier(C, v2d, snode, *link, TH_WIRE_INNER, TH_WIRE_INNER, TH_WIRE); } GPU_blend(GPU_BLEND_NONE); } -static void node_socket_draw(const bNodeSocket *sock, +static void node_socket_draw(const bNodeSocket &sock, const float color[4], const float color_outline[4], float size, @@ -756,7 +754,7 @@ static void node_socket_draw(const bNodeSocket *sock, int flags; /* Set shape flags. */ - switch (sock->display_shape) { + switch (sock.display_shape) { case SOCK_DISPLAY_SHAPE_DIAMOND: case SOCK_DISPLAY_SHAPE_DIAMOND_DOT: flags = GPU_KEYFRAME_SHAPE_DIAMOND; @@ -772,7 +770,7 @@ static void node_socket_draw(const bNodeSocket *sock, break; } - if (ELEM(sock->display_shape, + if (ELEM(sock.display_shape, SOCK_DISPLAY_SHAPE_DIAMOND_DOT, SOCK_DISPLAY_SHAPE_SQUARE_DOT, SOCK_DISPLAY_SHAPE_CIRCLE_DOT)) { @@ -829,14 +827,17 @@ static void node_socket_outline_color_get(const bool selected, /* 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, bNodeTree *ntree, PointerRNA *node_ptr, bNodeSocket *sock, float r_color[4]) +void node_socket_color_get(const bContext &C, + const bNodeTree &ntree, + PointerRNA &node_ptr, + const bNodeSocket &sock, + float r_color[4]) { PointerRNA ptr; - BLI_assert(RNA_struct_is_a(node_ptr->type, &RNA_Node)); - RNA_pointer_create((ID *)ntree, &RNA_NodeSocket, sock, &ptr); + BLI_assert(RNA_struct_is_a(node_ptr.type, &RNA_Node)); + RNA_pointer_create((ID *)&ntree, &RNA_NodeSocket, &const_cast<bNodeSocket &>(sock), &ptr); - sock->typeinfo->draw_color((bContext *)C, &ptr, node_ptr, r_color); + sock.typeinfo->draw_color((bContext *)&C, &ptr, &node_ptr, r_color); } struct SocketTooltipData { @@ -1039,42 +1040,42 @@ static std::optional<std::string> create_socket_inspection_string(bContext *C, return ss.str(); } -static void node_socket_draw_nested(const bContext *C, - bNodeTree *ntree, - PointerRNA *node_ptr, - bNodeSocket *sock, - uint pos_id, - uint col_id, - uint shape_id, - uint size_id, - uint outline_col_id, - float size, - bool selected) +static void node_socket_draw_nested(const bContext &C, + bNodeTree &ntree, + PointerRNA &node_ptr, + bNodeSocket &sock, + const uint pos_id, + const uint col_id, + const uint shape_id, + const uint size_id, + const uint outline_col_id, + const float size, + const bool selected) { float color[4]; float outline_color[4]; node_socket_color_get(C, ntree, node_ptr, sock, color); - node_socket_outline_color_get(selected, sock->type, outline_color); + node_socket_outline_color_get(selected, sock.type, outline_color); node_socket_draw(sock, color, outline_color, size, - sock->locx, - sock->locy, + sock.locx, + sock.locy, pos_id, col_id, shape_id, size_id, outline_col_id); - if (ntree->type != NTREE_GEOMETRY) { + if (ntree.type != NTREE_GEOMETRY) { /* Only geometry nodes has socket value tooltips currently. */ return; } - bNode *node = (bNode *)node_ptr->data; + bNode *node = (bNode *)node_ptr.data; uiBlock *block = node->block; /* Ideally sockets themselves should be buttons, but they aren't currently. So add an invisible @@ -1085,8 +1086,8 @@ static void node_socket_draw_nested(const bContext *C, UI_BTYPE_BUT, 0, ICON_NONE, - sock->locx - size / 2, - sock->locy - size / 2, + sock.locx - size / 2, + sock.locy - size / 2, size, size, nullptr, @@ -1097,9 +1098,9 @@ static void node_socket_draw_nested(const bContext *C, nullptr); SocketTooltipData *data = (SocketTooltipData *)MEM_mallocN(sizeof(SocketTooltipData), __func__); - data->ntree = ntree; - data->node = (bNode *)node_ptr->data; - data->socket = sock; + data->ntree = &ntree; + data->node = (bNode *)node_ptr.data; + data->socket = &sock; UI_but_func_tooltip_set( but, @@ -1164,7 +1165,7 @@ void ED_node_socket_draw(bNodeSocket *sock, const rcti *rect, const float color[ /* Single point. */ immBegin(GPU_PRIM_POINTS, 1); - node_socket_draw(sock, + node_socket_draw(*sock, color, outline_color, BLI_rcti_size_y(&draw_rect), @@ -1262,34 +1263,37 @@ static void node_toggle_button_cb(struct bContext *C, void *node_argv, void *op_ const char *opname = (const char *)op_argv; /* Select & activate only the button's node. */ - node_select_single(C, node); + node_select_single(*C, *node); WM_operator_name_call(C, opname, WM_OP_INVOKE_DEFAULT, nullptr); } -void node_draw_shadow(const SpaceNode *snode, const bNode *node, float radius, float alpha) +void node_draw_shadow(const SpaceNode &snode, + const bNode &node, + const float radius, + const float alpha) { - const rctf *rct = &node->totr; + const rctf &rct = node.totr; UI_draw_roundbox_corner_set(UI_CNR_ALL); - ui_draw_dropshadow(rct, radius, snode->runtime->aspect, alpha, node->flag & SELECT); + ui_draw_dropshadow(&rct, radius, snode.runtime->aspect, alpha, node.flag & SELECT); } -void node_draw_sockets(const View2D *v2d, - const bContext *C, - bNodeTree *ntree, - bNode *node, - bool draw_outputs, - bool select_all) +void node_draw_sockets(const View2D &v2d, + const bContext &C, + bNodeTree &ntree, + bNode &node, + const bool draw_outputs, + const bool select_all) { - const uint total_input_len = BLI_listbase_count(&node->inputs); - const uint total_output_len = BLI_listbase_count(&node->outputs); + const uint total_input_len = BLI_listbase_count(&node.inputs); + const uint total_output_len = BLI_listbase_count(&node.outputs); if (total_input_len + total_output_len == 0) { return; } PointerRNA node_ptr; - RNA_pointer_create((ID *)ntree, &RNA_Node, node, &node_ptr); + RNA_pointer_create((ID *)&ntree, &RNA_Node, &node, &node_ptr); bool selected = false; @@ -1309,7 +1313,7 @@ void node_draw_sockets(const View2D *v2d, /* Set handle size. */ float scale; - UI_view2d_scale_get(v2d, &scale, nullptr); + UI_view2d_scale_get(&v2d, &scale, nullptr); scale *= 2.25f * NODE_SOCKSIZE; if (!select_all) { @@ -1318,7 +1322,7 @@ void node_draw_sockets(const View2D *v2d, /* Socket inputs. */ short selected_input_len = 0; - LISTBASE_FOREACH (bNodeSocket *, sock, &node->inputs) { + LISTBASE_FOREACH (bNodeSocket *, sock, &node.inputs) { if (nodeSocketIsHidden(sock)) { continue; } @@ -1333,8 +1337,8 @@ void node_draw_sockets(const View2D *v2d, node_socket_draw_nested(C, ntree, - &node_ptr, - sock, + node_ptr, + *sock, pos_id, col_id, shape_id, @@ -1347,7 +1351,7 @@ void node_draw_sockets(const View2D *v2d, /* Socket outputs. */ short selected_output_len = 0; if (draw_outputs) { - LISTBASE_FOREACH (bNodeSocket *, sock, &node->outputs) { + LISTBASE_FOREACH (bNodeSocket *, sock, &node.outputs) { if (nodeSocketIsHidden(sock)) { continue; } @@ -1358,8 +1362,8 @@ void node_draw_sockets(const View2D *v2d, node_socket_draw_nested(C, ntree, - &node_ptr, - sock, + node_ptr, + *sock, pos_id, col_id, shape_id, @@ -1384,15 +1388,15 @@ void node_draw_sockets(const View2D *v2d, if (selected_input_len) { /* Socket inputs. */ - LISTBASE_FOREACH (bNodeSocket *, sock, &node->inputs) { + LISTBASE_FOREACH (bNodeSocket *, sock, &node.inputs) { if (nodeSocketIsHidden(sock)) { continue; } if (select_all || (sock->flag & SELECT)) { node_socket_draw_nested(C, ntree, - &node_ptr, - sock, + node_ptr, + *sock, pos_id, col_id, shape_id, @@ -1409,15 +1413,15 @@ void node_draw_sockets(const View2D *v2d, if (selected_output_len) { /* Socket outputs. */ - LISTBASE_FOREACH (bNodeSocket *, sock, &node->outputs) { + LISTBASE_FOREACH (bNodeSocket *, sock, &node.outputs) { if (nodeSocketIsHidden(sock)) { continue; } if (select_all || (sock->flag & SELECT)) { node_socket_draw_nested(C, ntree, - &node_ptr, - sock, + node_ptr, + *sock, pos_id, col_id, shape_id, @@ -1442,7 +1446,7 @@ void node_draw_sockets(const View2D *v2d, /* Draw multi-input sockets after the others because they are drawn with `UI_draw_roundbox` * rather than with `GL_POINT`. */ - LISTBASE_FOREACH (bNodeSocket *, socket, &node->inputs) { + LISTBASE_FOREACH (bNodeSocket *, socket, &node.inputs) { if (nodeSocketIsHidden(socket)) { continue; } @@ -1450,13 +1454,13 @@ void node_draw_sockets(const View2D *v2d, continue; } - const bool is_node_hidden = (node->flag & NODE_HIDDEN); + const bool is_node_hidden = (node.flag & NODE_HIDDEN); const float width = NODE_SOCKSIZE; - float height = is_node_hidden ? width : node_socket_calculate_height(socket) - width; + float height = is_node_hidden ? width : node_socket_calculate_height(*socket) - width; float color[4]; float outline_color[4]; - node_socket_color_get(C, ntree, &node_ptr, socket, color); + node_socket_color_get(C, ntree, node_ptr, *socket, color); node_socket_outline_color_get(selected, socket->type, outline_color); node_socket_draw_multi_input(color, outline_color, width, height, socket->locx, socket->locy); @@ -1538,9 +1542,9 @@ static char *node_errors_tooltip_fn(bContext *UNUSED(C), void *argN, const char #define NODE_HEADER_ICON_SIZE (0.8f * U.widget_unit) static void node_add_error_message_button( - const bContext *C, bNodeTree &UNUSED(ntree), bNode &node, const rctf &rect, float &icon_offset) + const bContext &C, bNodeTree &UNUSED(ntree), bNode &node, const rctf &rect, float &icon_offset) { - SpaceNode *snode = CTX_wm_space_node(C); + SpaceNode *snode = CTX_wm_space_node(&C); const geo_log::NodeLog *node_log = geo_log::ModifierLog::find_node_by_node_editor_context(*snode, node); if (node_log == nullptr) { @@ -1579,18 +1583,18 @@ static void node_add_error_message_button( UI_block_emboss_set(node.block, UI_EMBOSS); } -static void get_exec_time_other_nodes(const bNode *node, - const SpaceNode *snode, +static void get_exec_time_other_nodes(const bNode &node, + const SpaceNode &snode, std::chrono::microseconds &exec_time, int &node_count) { - if (node->type == NODE_GROUP) { + if (node.type == NODE_GROUP) { const geo_log::TreeLog *root_tree_log = geo_log::ModifierLog::find_tree_by_node_editor_context( - *snode); + snode); if (root_tree_log == nullptr) { return; } - const geo_log::TreeLog *tree_log = root_tree_log->lookup_child_log(node->name); + const geo_log::TreeLog *tree_log = root_tree_log->lookup_child_log(node.name); if (tree_log == nullptr) { return; } @@ -1601,7 +1605,7 @@ static void get_exec_time_other_nodes(const bNode *node, } else { const geo_log::NodeLog *node_log = geo_log::ModifierLog::find_node_by_node_editor_context( - *snode, *node); + snode, node); if (node_log) { exec_time += node_log->execution_time(); node_count++; @@ -1609,15 +1613,15 @@ static void get_exec_time_other_nodes(const bNode *node, } } -static std::chrono::microseconds node_get_execution_time(const bNodeTree *ntree, - const bNode *node, - const SpaceNode *snode, +static std::chrono::microseconds node_get_execution_time(const bNodeTree &ntree, + const bNode &node, + const SpaceNode &snode, int &node_count) { std::chrono::microseconds exec_time = std::chrono::microseconds::zero(); - if (node->type == NODE_GROUP_OUTPUT) { + if (node.type == NODE_GROUP_OUTPUT) { const geo_log::TreeLog *tree_log = geo_log::ModifierLog::find_tree_by_node_editor_context( - *snode); + snode); if (tree_log == nullptr) { return exec_time; @@ -1627,18 +1631,18 @@ static std::chrono::microseconds node_get_execution_time(const bNodeTree *ntree, node_count++; }); } - else if (node->type == NODE_FRAME) { + else if (node.type == NODE_FRAME) { /* Could be cached in the future if this recursive code turns out to be slow. */ - LISTBASE_FOREACH (bNode *, tnode, &ntree->nodes) { - if (tnode->parent != node) { + LISTBASE_FOREACH (bNode *, tnode, &ntree.nodes) { + if (tnode->parent != &node) { continue; } if (tnode->type == NODE_FRAME) { - exec_time += node_get_execution_time(ntree, tnode, snode, node_count); + exec_time += node_get_execution_time(ntree, *tnode, snode, node_count); } else { - get_exec_time_other_nodes(tnode, snode, exec_time, node_count); + get_exec_time_other_nodes(*tnode, snode, exec_time, node_count); } } } @@ -1648,11 +1652,11 @@ static std::chrono::microseconds node_get_execution_time(const bNodeTree *ntree, return exec_time; } -static std::string node_get_execution_time_label(const SpaceNode *snode, const bNode *node) +static std::string node_get_execution_time_label(const SpaceNode &snode, const bNode &node) { int node_count = 0; std::chrono::microseconds exec_time = node_get_execution_time( - snode->nodetree, node, snode, node_count); + *snode.nodetree, node, snode, node_count); if (node_count == 0) { return std::string(""); @@ -1688,16 +1692,16 @@ struct NodeExtraInfoRow { int icon; }; -static Vector<NodeExtraInfoRow> node_get_extra_info(const SpaceNode *snode, const bNode *node) +static Vector<NodeExtraInfoRow> node_get_extra_info(const SpaceNode &snode, const bNode &node) { Vector<NodeExtraInfoRow> rows; - if (!(snode->overlay.flag & SN_OVERLAY_SHOW_OVERLAYS)) { + if (!(snode.overlay.flag & SN_OVERLAY_SHOW_OVERLAYS)) { return rows; } - if (snode->overlay.flag & SN_OVERLAY_SHOW_TIMINGS && snode->edittree->type == NTREE_GEOMETRY && - (ELEM(node->typeinfo->nclass, NODE_CLASS_GEOMETRY, NODE_CLASS_GROUP, NODE_CLASS_ATTRIBUTE) || - ELEM(node->type, NODE_FRAME, NODE_GROUP_OUTPUT))) { + if (snode.overlay.flag & SN_OVERLAY_SHOW_TIMINGS && snode.edittree->type == NTREE_GEOMETRY && + (ELEM(node.typeinfo->nclass, NODE_CLASS_GEOMETRY, NODE_CLASS_GROUP, NODE_CLASS_ATTRIBUTE) || + ELEM(node.type, NODE_FRAME, NODE_GROUP_OUTPUT))) { NodeExtraInfoRow row; row.text = node_get_execution_time_label(snode, node); if (!row.text.empty()) { @@ -1708,8 +1712,8 @@ static Vector<NodeExtraInfoRow> node_get_extra_info(const SpaceNode *snode, cons rows.append(std::move(row)); } } - const geo_log::NodeLog *node_log = geo_log::ModifierLog::find_node_by_node_editor_context(*snode, - *node); + const geo_log::NodeLog *node_log = geo_log::ModifierLog::find_node_by_node_editor_context(snode, + node); if (node_log != nullptr) { for (const std::string &message : node_log->debug_messages()) { NodeExtraInfoRow row; @@ -1721,18 +1725,18 @@ static Vector<NodeExtraInfoRow> node_get_extra_info(const SpaceNode *snode, cons return rows; } -static void node_draw_extra_info_row(const bNode *node, - const rctf *rect, +static void node_draw_extra_info_row(const bNode &node, + const rctf &rect, const int row, const NodeExtraInfoRow &extra_info_row) { - uiBut *but_timing = uiDefBut(node->block, + uiBut *but_timing = uiDefBut(node.block, UI_BTYPE_LABEL, 0, extra_info_row.text.c_str(), - (int)(rect->xmin + 4.0f * U.dpi_fac + NODE_MARGIN_X + 0.4f), - (int)(rect->ymin + row * (20.0f * U.dpi_fac)), - (short)(rect->xmax - rect->xmin), + (int)(rect.xmin + 4.0f * U.dpi_fac + NODE_MARGIN_X + 0.4f), + (int)(rect.ymin + row * (20.0f * U.dpi_fac)), + (short)(rect.xmax - rect.xmin), (short)NODE_DY, nullptr, 0, @@ -1740,13 +1744,13 @@ static void node_draw_extra_info_row(const bNode *node, 0, 0, ""); - UI_block_emboss_set(node->block, UI_EMBOSS_NONE); - uiBut *but_icon = uiDefIconBut(node->block, + UI_block_emboss_set(node.block, UI_EMBOSS_NONE); + uiBut *but_icon = uiDefIconBut(node.block, UI_BTYPE_BUT, 0, extra_info_row.icon, - (int)(rect->xmin + 6.0f * U.dpi_fac), - (int)(rect->ymin + row * (20.0f * U.dpi_fac)), + (int)(rect.xmin + 6.0f * U.dpi_fac), + (int)(rect.ymin + row * (20.0f * U.dpi_fac)), NODE_HEADER_ICON_SIZE * 0.8f, UI_UNIT_Y, nullptr, @@ -1755,14 +1759,14 @@ static void node_draw_extra_info_row(const bNode *node, 0, 0, extra_info_row.tooltip); - UI_block_emboss_set(node->block, UI_EMBOSS); - if (node->flag & NODE_MUTED) { + UI_block_emboss_set(node.block, UI_EMBOSS); + if (node.flag & NODE_MUTED) { UI_but_flag_enable(but_timing, UI_BUT_INACTIVE); UI_but_flag_enable(but_icon, UI_BUT_INACTIVE); } } -void node_draw_extra_info_panel(const SpaceNode *snode, const bNode *node) +void node_draw_extra_info_panel(const SpaceNode &snode, const bNode &node) { Vector<NodeExtraInfoRow> extra_info_rows = node_get_extra_info(snode, node); @@ -1770,23 +1774,23 @@ void node_draw_extra_info_panel(const SpaceNode *snode, const bNode *node) return; } - const rctf *rct = &node->totr; + const rctf &rct = node.totr; float color[4]; rctf extra_info_rect; - if (node->type == NODE_FRAME) { - extra_info_rect.xmin = rct->xmin; - extra_info_rect.xmax = rct->xmin + 95.0f * U.dpi_fac; - extra_info_rect.ymin = rct->ymin + 2.0f * U.dpi_fac; - extra_info_rect.ymax = rct->ymin + 2.0f * U.dpi_fac; + if (node.type == NODE_FRAME) { + extra_info_rect.xmin = rct.xmin; + extra_info_rect.xmax = rct.xmin + 95.0f * U.dpi_fac; + extra_info_rect.ymin = rct.ymin + 2.0f * U.dpi_fac; + extra_info_rect.ymax = rct.ymin + 2.0f * U.dpi_fac; } else { - extra_info_rect.xmin = rct->xmin + 3.0f * U.dpi_fac; - extra_info_rect.xmax = rct->xmin + 95.0f * U.dpi_fac; - extra_info_rect.ymin = rct->ymax; - extra_info_rect.ymax = rct->ymax + extra_info_rows.size() * (20.0f * U.dpi_fac); + extra_info_rect.xmin = rct.xmin + 3.0f * U.dpi_fac; + extra_info_rect.xmax = rct.xmin + 95.0f * U.dpi_fac; + extra_info_rect.ymin = rct.ymax; + extra_info_rect.ymax = rct.ymax + extra_info_rows.size() * (20.0f * U.dpi_fac); - if (node->flag & NODE_MUTED) { + if (node.flag & NODE_MUTED) { UI_GetThemeColorBlend4f(TH_BACK, TH_NODE, 0.2f, color); } else { @@ -1795,49 +1799,48 @@ void node_draw_extra_info_panel(const SpaceNode *snode, const bNode *node) color[3] -= 0.35f; UI_draw_roundbox_corner_set( UI_CNR_ALL & ~UI_CNR_BOTTOM_LEFT & - ((rct->xmax) > extra_info_rect.xmax ? ~UI_CNR_BOTTOM_RIGHT : UI_CNR_ALL)); + ((rct.xmax) > extra_info_rect.xmax ? ~UI_CNR_BOTTOM_RIGHT : UI_CNR_ALL)); UI_draw_roundbox_4fv(&extra_info_rect, true, BASIS_RAD, color); /* Draw outline. */ const float outline_width = 1.0f; - extra_info_rect.xmin = rct->xmin + 3.0f * U.dpi_fac - outline_width; - extra_info_rect.xmax = rct->xmin + 95.0f * U.dpi_fac + outline_width; - extra_info_rect.ymin = rct->ymax - outline_width; - extra_info_rect.ymax = rct->ymax + outline_width + - extra_info_rows.size() * (20.0f * U.dpi_fac); + extra_info_rect.xmin = rct.xmin + 3.0f * U.dpi_fac - outline_width; + extra_info_rect.xmax = rct.xmin + 95.0f * U.dpi_fac + outline_width; + extra_info_rect.ymin = rct.ymax - outline_width; + extra_info_rect.ymax = rct.ymax + outline_width + extra_info_rows.size() * (20.0f * U.dpi_fac); UI_GetThemeColorBlendShade4fv(TH_BACK, TH_NODE, 0.4f, -20, color); UI_draw_roundbox_corner_set( UI_CNR_ALL & ~UI_CNR_BOTTOM_LEFT & - ((rct->xmax) > extra_info_rect.xmax ? ~UI_CNR_BOTTOM_RIGHT : UI_CNR_ALL)); + ((rct.xmax) > extra_info_rect.xmax ? ~UI_CNR_BOTTOM_RIGHT : UI_CNR_ALL)); UI_draw_roundbox_4fv(&extra_info_rect, false, BASIS_RAD, color); } for (int row : extra_info_rows.index_range()) { - node_draw_extra_info_row(node, &extra_info_rect, row, extra_info_rows[row]); + node_draw_extra_info_row(node, extra_info_rect, row, extra_info_rows[row]); } } -static void node_draw_basis(const bContext *C, - const View2D *v2d, - const SpaceNode *snode, - bNodeTree *ntree, - bNode *node, +static void node_draw_basis(const bContext &C, + const View2D &v2d, + const SpaceNode &snode, + bNodeTree &ntree, + bNode &node, bNodeInstanceKey key) { const float iconbutw = NODE_HEADER_ICON_SIZE; /* Skip if out of view. */ - if (BLI_rctf_isect(&node->totr, &v2d->cur, nullptr) == false) { - UI_block_end(C, node->block); - node->block = nullptr; + if (BLI_rctf_isect(&node.totr, &v2d.cur, nullptr) == false) { + UI_block_end(&C, node.block); + node.block = nullptr; return; } /* Shadow. */ node_draw_shadow(snode, node, BASIS_RAD, 1.0f); - rctf *rct = &node->totr; + const rctf &rct = node.totr; float color[4]; int color_id = node_get_colorid(node); @@ -1848,16 +1851,16 @@ static void node_draw_basis(const bContext *C, /* Header. */ { const rctf rect = { - rct->xmin, - rct->xmax, - rct->ymax - NODE_DY, - rct->ymax, + rct.xmin, + rct.xmax, + rct.ymax - NODE_DY, + rct.ymax, }; float color_header[4]; /* Muted nodes get a mix of the background with the node color. */ - if (node->flag & NODE_MUTED) { + if (node.flag & NODE_MUTED) { UI_GetThemeColorBlend4f(TH_BACK, color_id, 0.1f, color_header); } else { @@ -1869,18 +1872,18 @@ static void node_draw_basis(const bContext *C, } /* Show/hide icons. */ - float iconofs = rct->xmax - 0.35f * U.widget_unit; + float iconofs = rct.xmax - 0.35f * U.widget_unit; /* Preview. */ - if (node->typeinfo->flag & NODE_PREVIEW) { + if (node.typeinfo->flag & NODE_PREVIEW) { iconofs -= iconbutw; - UI_block_emboss_set(node->block, UI_EMBOSS_NONE); - uiBut *but = uiDefIconBut(node->block, + UI_block_emboss_set(node.block, UI_EMBOSS_NONE); + uiBut *but = uiDefIconBut(node.block, UI_BTYPE_BUT_TOGGLE, 0, ICON_MATERIAL, iconofs, - rct->ymax - NODE_DY, + rct.ymax - NODE_DY, iconbutw, UI_UNIT_Y, nullptr, @@ -1889,24 +1892,24 @@ static void node_draw_basis(const bContext *C, 0, 0, ""); - UI_but_func_set(but, node_toggle_button_cb, node, (void *)"NODE_OT_preview_toggle"); + UI_but_func_set(but, node_toggle_button_cb, &node, (void *)"NODE_OT_preview_toggle"); /* XXX this does not work when node is activated and the operator called right afterwards, * since active ID is not updated yet (needs to process the notifier). * This can only work as visual indicator! */ - // if (!(node->flag & (NODE_ACTIVE_ID|NODE_DO_OUTPUT))) + // if (!(node.flag & (NODE_ACTIVE_ID|NODE_DO_OUTPUT))) // UI_but_flag_enable(but, UI_BUT_DISABLED); - UI_block_emboss_set(node->block, UI_EMBOSS); + UI_block_emboss_set(node.block, UI_EMBOSS); } /* Group edit. */ - if (node->type == NODE_GROUP) { + if (node.type == NODE_GROUP) { iconofs -= iconbutw; - UI_block_emboss_set(node->block, UI_EMBOSS_NONE); - uiBut *but = uiDefIconBut(node->block, + UI_block_emboss_set(node.block, UI_EMBOSS_NONE); + uiBut *but = uiDefIconBut(node.block, UI_BTYPE_BUT_TOGGLE, 0, ICON_NODETREE, iconofs, - rct->ymax - NODE_DY, + rct.ymax - NODE_DY, iconbutw, UI_UNIT_Y, nullptr, @@ -1915,18 +1918,18 @@ static void node_draw_basis(const bContext *C, 0, 0, ""); - UI_but_func_set(but, node_toggle_button_cb, node, (void *)"NODE_OT_group_edit"); - UI_block_emboss_set(node->block, UI_EMBOSS); + UI_but_func_set(but, node_toggle_button_cb, &node, (void *)"NODE_OT_group_edit"); + UI_block_emboss_set(node.block, UI_EMBOSS); } - if (node->type == NODE_CUSTOM && node->typeinfo->ui_icon != ICON_NONE) { + if (node.type == NODE_CUSTOM && node.typeinfo->ui_icon != ICON_NONE) { iconofs -= iconbutw; - UI_block_emboss_set(node->block, UI_EMBOSS_NONE); - uiDefIconBut(node->block, + UI_block_emboss_set(node.block, UI_EMBOSS_NONE); + uiDefIconBut(node.block, UI_BTYPE_BUT, 0, - node->typeinfo->ui_icon, + node.typeinfo->ui_icon, iconofs, - rct->ymax - NODE_DY, + rct.ymax - NODE_DY, iconbutw, UI_UNIT_Y, nullptr, @@ -1935,13 +1938,13 @@ static void node_draw_basis(const bContext *C, 0, 0, ""); - UI_block_emboss_set(node->block, UI_EMBOSS); + UI_block_emboss_set(node.block, UI_EMBOSS); } - node_add_error_message_button(C, *ntree, *node, *rct, iconofs); + node_add_error_message_button(C, ntree, node, rct, iconofs); /* Title. */ - if (node->flag & SELECT) { + if (node.flag & SELECT) { UI_GetThemeColor4fv(TH_SELECT, color); } else { @@ -1951,14 +1954,14 @@ static void node_draw_basis(const bContext *C, /* Collapse/expand icon. */ { const int but_size = U.widget_unit * 0.8f; - UI_block_emboss_set(node->block, UI_EMBOSS_NONE); + UI_block_emboss_set(node.block, UI_EMBOSS_NONE); - uiBut *but = uiDefIconBut(node->block, + uiBut *but = uiDefIconBut(node.block, UI_BTYPE_BUT_TOGGLE, 0, ICON_DOWNARROW_HLT, - rct->xmin + (NODE_MARGIN_X / 3), - rct->ymax - NODE_DY / 2.2f - but_size / 2, + rct.xmin + (NODE_MARGIN_X / 3), + rct.ymax - NODE_DY / 2.2f - but_size / 2, but_size, but_size, nullptr, @@ -1968,20 +1971,20 @@ static void node_draw_basis(const bContext *C, 0.0f, ""); - UI_but_func_set(but, node_toggle_button_cb, node, (void *)"NODE_OT_hide_toggle"); - UI_block_emboss_set(node->block, UI_EMBOSS); + UI_but_func_set(but, node_toggle_button_cb, &node, (void *)"NODE_OT_hide_toggle"); + UI_block_emboss_set(node.block, UI_EMBOSS); } char showname[128]; - nodeLabel(ntree, node, showname, sizeof(showname)); + nodeLabel(&ntree, &node, showname, sizeof(showname)); - uiBut *but = uiDefBut(node->block, + uiBut *but = uiDefBut(node.block, UI_BTYPE_LABEL, 0, showname, - (int)(rct->xmin + NODE_MARGIN_X + 0.4f), - (int)(rct->ymax - NODE_DY), - (short)(iconofs - rct->xmin - (18.0f * U.dpi_fac)), + (int)(rct.xmin + NODE_MARGIN_X + 0.4f), + (int)(rct.ymax - NODE_DY), + (short)(iconofs - rct.xmin - (18.0f * U.dpi_fac)), (short)NODE_DY, nullptr, 0, @@ -1989,12 +1992,12 @@ static void node_draw_basis(const bContext *C, 0, 0, ""); - if (node->flag & NODE_MUTED) { + if (node.flag & NODE_MUTED) { UI_but_flag_enable(but, UI_BUT_INACTIVE); } /* Wire across the node when muted/disabled. */ - if (node->flag & NODE_MUTED) { + if (node.flag & NODE_MUTED) { node_draw_mute_line(C, v2d, snode, node); } @@ -2002,35 +2005,35 @@ static void node_draw_basis(const bContext *C, const float outline_width = 1.0f; { /* Use warning color to indicate undefined types. */ - if (nodeTypeUndefined(node)) { + if (nodeTypeUndefined(&node)) { UI_GetThemeColorBlend4f(TH_REDALERT, TH_NODE, 0.4f, color); } /* Muted nodes get a mix of the background with the node color. */ - else if (node->flag & NODE_MUTED) { + else if (node.flag & NODE_MUTED) { UI_GetThemeColorBlend4f(TH_BACK, TH_NODE, 0.2f, color); } - else if (node->flag & NODE_CUSTOM_COLOR) { - rgba_float_args_set(color, node->color[0], node->color[1], node->color[2], 1.0f); + else if (node.flag & NODE_CUSTOM_COLOR) { + rgba_float_args_set(color, node.color[0], node.color[1], node.color[2], 1.0f); } else { UI_GetThemeColor4fv(TH_NODE, color); } /* Draw selected nodes fully opaque. */ - if (node->flag & SELECT) { + if (node.flag & SELECT) { color[3] = 1.0f; } /* Draw muted nodes slightly transparent so the wires inside are visible. */ - if (node->flag & NODE_MUTED) { + if (node.flag & NODE_MUTED) { color[3] -= 0.2f; } const rctf rect = { - rct->xmin, - rct->xmax, - rct->ymin, - rct->ymax - (NODE_DY + outline_width), + rct.xmin, + rct.xmax, + rct.ymin, + rct.ymax - (NODE_DY + outline_width), }; UI_draw_roundbox_corner_set(UI_CNR_BOTTOM_LEFT | UI_CNR_BOTTOM_RIGHT); @@ -2041,7 +2044,7 @@ static void node_draw_basis(const bContext *C, { float color_underline[4]; - if (node->flag & NODE_MUTED) { + if (node.flag & NODE_MUTED) { UI_GetThemeColor4fv(TH_WIRE, color_underline); } else { @@ -2049,10 +2052,10 @@ static void node_draw_basis(const bContext *C, } const rctf rect = { - rct->xmin, - rct->xmax, - rct->ymax - (NODE_DY + outline_width), - rct->ymax - NODE_DY, + rct.xmin, + rct.xmax, + rct.ymax - (NODE_DY + outline_width), + rct.ymax - NODE_DY, }; UI_draw_roundbox_corner_set(UI_CNR_NONE); @@ -2062,19 +2065,19 @@ static void node_draw_basis(const bContext *C, /* Outline. */ { const rctf rect = { - rct->xmin - outline_width, - rct->xmax + outline_width, - rct->ymin - outline_width, - rct->ymax + outline_width, + rct.xmin - outline_width, + rct.xmax + outline_width, + rct.ymin - outline_width, + rct.ymax + outline_width, }; /* Color the outline according to active, selected, or undefined status. */ float color_outline[4]; - if (node->flag & SELECT) { - UI_GetThemeColor4fv((node->flag & NODE_ACTIVE) ? TH_ACTIVE : TH_SELECT, color_outline); + if (node.flag & SELECT) { + UI_GetThemeColor4fv((node.flag & NODE_ACTIVE) ? TH_ACTIVE : TH_SELECT, color_outline); } - else if (nodeTypeUndefined(node)) { + else if (nodeTypeUndefined(&node)) { UI_GetThemeColor4fv(TH_REDALERT, color_outline); } else { @@ -2086,7 +2089,7 @@ static void node_draw_basis(const bContext *C, } float scale; - UI_view2d_scale_get(v2d, &scale, nullptr); + UI_view2d_scale_get(&v2d, &scale, nullptr); /* Skip slow socket drawing if zoom is small. */ if (scale > 0.2f) { @@ -2094,34 +2097,31 @@ static void node_draw_basis(const bContext *C, } /* Preview. */ - bNodeInstanceHash *previews = (bNodeInstanceHash *)CTX_data_pointer_get(C, "node_previews").data; - if (node->flag & NODE_PREVIEW && previews) { + bNodeInstanceHash *previews = + (bNodeInstanceHash *)CTX_data_pointer_get(&C, "node_previews").data; + if (node.flag & NODE_PREVIEW && previews) { bNodePreview *preview = (bNodePreview *)BKE_node_instance_hash_lookup(previews, key); if (preview && (preview->xsize && preview->ysize)) { - if (preview->rect && !BLI_rctf_is_empty(&node->prvr)) { - node_draw_preview(preview, &node->prvr); + if (preview->rect && !BLI_rctf_is_empty(&node.prvr)) { + node_draw_preview(preview, &node.prvr); } } } - UI_block_end(C, node->block); - UI_block_draw(C, node->block); - node->block = nullptr; + UI_block_end(&C, node.block); + UI_block_draw(&C, node.block); + node.block = nullptr; } -static void node_draw_hidden(const bContext *C, - const View2D *v2d, - const SpaceNode *snode, - bNodeTree *ntree, - bNode *node, - bNodeInstanceKey UNUSED(key)) +static void node_draw_hidden( + const bContext &C, const View2D &v2d, const SpaceNode &snode, bNodeTree &ntree, bNode &node) { - rctf *rct = &node->totr; - float centy = BLI_rctf_cent_y(rct); - float hiddenrad = BLI_rctf_size_y(rct) / 2.0f; + const rctf &rct = node.totr; + float centy = BLI_rctf_cent_y(&rct); + float hiddenrad = BLI_rctf_size_y(&rct) / 2.0f; float scale; - UI_view2d_scale_get(v2d, &scale, nullptr); + UI_view2d_scale_get(&v2d, &scale, nullptr); const int color_id = node_get_colorid(node); @@ -2129,43 +2129,43 @@ static void node_draw_hidden(const bContext *C, node_draw_shadow(snode, node, hiddenrad, 1.0f); /* Wire across the node when muted/disabled. */ - if (node->flag & NODE_MUTED) { + if (node.flag & NODE_MUTED) { node_draw_mute_line(C, v2d, snode, node); } /* Body. */ float color[4]; { - if (nodeTypeUndefined(node)) { + if (nodeTypeUndefined(&node)) { /* Use warning color to indicate undefined types. */ UI_GetThemeColorBlend4f(TH_REDALERT, TH_NODE, 0.4f, color); } - else if (node->flag & NODE_MUTED) { + else if (node.flag & NODE_MUTED) { /* Muted nodes get a mix of the background with the node color. */ UI_GetThemeColorBlendShade4fv(TH_BACK, color_id, 0.1f, 0, color); } - else if (node->flag & NODE_CUSTOM_COLOR) { - rgba_float_args_set(color, node->color[0], node->color[1], node->color[2], 1.0f); + else if (node.flag & NODE_CUSTOM_COLOR) { + rgba_float_args_set(color, node.color[0], node.color[1], node.color[2], 1.0f); } else { UI_GetThemeColorBlend4f(TH_NODE, color_id, 0.4f, color); } /* Draw selected nodes fully opaque. */ - if (node->flag & SELECT) { + if (node.flag & SELECT) { color[3] = 1.0f; } /* Draw muted nodes slightly transparent so the wires inside are visible. */ - if (node->flag & NODE_MUTED) { + if (node.flag & NODE_MUTED) { color[3] -= 0.2f; } - UI_draw_roundbox_4fv(rct, true, hiddenrad, color); + UI_draw_roundbox_4fv(&rct, true, hiddenrad, color); } /* Title. */ - if (node->flag & SELECT) { + if (node.flag & SELECT) { UI_GetThemeColor4fv(TH_SELECT, color); } else { @@ -2175,13 +2175,13 @@ static void node_draw_hidden(const bContext *C, /* Collapse/expand icon. */ { const int but_size = U.widget_unit * 1.0f; - UI_block_emboss_set(node->block, UI_EMBOSS_NONE); + UI_block_emboss_set(node.block, UI_EMBOSS_NONE); - uiBut *but = uiDefIconBut(node->block, + uiBut *but = uiDefIconBut(node.block, UI_BTYPE_BUT_TOGGLE, 0, ICON_RIGHTARROW, - rct->xmin + (NODE_MARGIN_X / 3), + rct.xmin + (NODE_MARGIN_X / 3), centy - but_size / 2, but_size, but_size, @@ -2192,20 +2192,20 @@ static void node_draw_hidden(const bContext *C, 0.0f, ""); - UI_but_func_set(but, node_toggle_button_cb, node, (void *)"NODE_OT_hide_toggle"); - UI_block_emboss_set(node->block, UI_EMBOSS); + UI_but_func_set(but, node_toggle_button_cb, &node, (void *)"NODE_OT_hide_toggle"); + UI_block_emboss_set(node.block, UI_EMBOSS); } char showname[128]; - nodeLabel(ntree, node, showname, sizeof(showname)); + nodeLabel(&ntree, &node, showname, sizeof(showname)); - uiBut *but = uiDefBut(node->block, + uiBut *but = uiDefBut(node.block, UI_BTYPE_LABEL, 0, showname, - round_fl_to_int(rct->xmin + NODE_MARGIN_X), + round_fl_to_int(rct.xmin + NODE_MARGIN_X), round_fl_to_int(centy - NODE_DY * 0.5f), - (short)(BLI_rctf_size_x(rct) - ((18.0f + 12.0f) * U.dpi_fac)), + (short)(BLI_rctf_size_x(&rct) - ((18.0f + 12.0f) * U.dpi_fac)), (short)NODE_DY, nullptr, 0, @@ -2218,19 +2218,19 @@ static void node_draw_hidden(const bContext *C, { const float outline_width = 1.0f; const rctf rect = { - rct->xmin - outline_width, - rct->xmax + outline_width, - rct->ymin - outline_width, - rct->ymax + outline_width, + rct.xmin - outline_width, + rct.xmax + outline_width, + rct.ymin - outline_width, + rct.ymax + outline_width, }; /* Color the outline according to active, selected, or undefined status. */ float color_outline[4]; - if (node->flag & SELECT) { - UI_GetThemeColor4fv((node->flag & NODE_ACTIVE) ? TH_ACTIVE : TH_SELECT, color_outline); + if (node.flag & SELECT) { + UI_GetThemeColor4fv((node.flag & NODE_ACTIVE) ? TH_ACTIVE : TH_SELECT, color_outline); } - else if (nodeTypeUndefined(node)) { + else if (nodeTypeUndefined(&node)) { UI_GetThemeColor4fv(TH_REDALERT, color_outline); } else { @@ -2241,7 +2241,7 @@ static void node_draw_hidden(const bContext *C, UI_draw_roundbox_4fv(&rect, false, hiddenrad, color_outline); } - if (node->flag & NODE_MUTED) { + if (node.flag & NODE_MUTED) { UI_but_flag_enable(but, UI_BUT_INACTIVE); } @@ -2252,26 +2252,26 @@ static void node_draw_hidden(const bContext *C, immUniformThemeColorShadeAlpha(TH_TEXT, -40, -180); float dx = 0.5f * U.widget_unit; - const float dx2 = 0.15f * U.widget_unit * snode->runtime->aspect; + const float dx2 = 0.15f * U.widget_unit * snode.runtime->aspect; const float dy = 0.2f * U.widget_unit; immBegin(GPU_PRIM_LINES, 4); - immVertex2f(pos, rct->xmax - dx, centy - dy); - immVertex2f(pos, rct->xmax - dx, centy + dy); + immVertex2f(pos, rct.xmax - dx, centy - dy); + immVertex2f(pos, rct.xmax - dx, centy + dy); - immVertex2f(pos, rct->xmax - dx - dx2, centy - dy); - immVertex2f(pos, rct->xmax - dx - dx2, centy + dy); + immVertex2f(pos, rct.xmax - dx - dx2, centy - dy); + immVertex2f(pos, rct.xmax - dx - dx2, centy + dy); immEnd(); immUniformThemeColorShadeAlpha(TH_TEXT, 0, -180); - dx -= snode->runtime->aspect; + dx -= snode.runtime->aspect; immBegin(GPU_PRIM_LINES, 4); - immVertex2f(pos, rct->xmax - dx, centy - dy); - immVertex2f(pos, rct->xmax - dx, centy + dy); + immVertex2f(pos, rct.xmax - dx, centy - dy); + immVertex2f(pos, rct.xmax - dx, centy + dy); - immVertex2f(pos, rct->xmax - dx - dx2, centy - dy); - immVertex2f(pos, rct->xmax - dx - dx2, centy + dy); + immVertex2f(pos, rct.xmax - dx - dx2, centy - dy); + immVertex2f(pos, rct.xmax - dx - dx2, centy + dy); immEnd(); immUnbindProgram(); @@ -2279,9 +2279,9 @@ static void node_draw_hidden(const bContext *C, node_draw_sockets(v2d, C, ntree, node, true, false); - UI_block_end(C, node->block); - UI_block_draw(C, node->block); - node->block = nullptr; + UI_block_end(&C, node.block); + UI_block_draw(&C, node.block); + node.block = nullptr; } int node_get_resize_cursor(NodeResizeDirection directions) @@ -2298,32 +2298,36 @@ int node_get_resize_cursor(NodeResizeDirection directions) return WM_CURSOR_EDIT; } -void node_set_cursor(wmWindow *win, SpaceNode *snode, float cursor[2]) +void node_set_cursor(wmWindow &win, SpaceNode &snode, const float2 &cursor) { - bNodeTree *ntree = snode->edittree; + const bNodeTree *ntree = snode.edittree; + if (ntree == nullptr) { + WM_cursor_set(&win, WM_CURSOR_DEFAULT); + return; + } + bNode *node; bNodeSocket *sock; int wmcursor = WM_CURSOR_DEFAULT; - if (ntree) { - if (node_find_indicated_socket(snode, &node, &sock, cursor, SOCK_IN | SOCK_OUT)) { - /* Pass. */ - } - else { - /* Check nodes front to back. */ - for (node = (bNode *)ntree->nodes.last; node; node = node->prev) { - if (BLI_rctf_isect_pt(&node->totr, cursor[0], cursor[1])) { - break; /* First hit on node stops. */ - } - } - if (node) { - NodeResizeDirection dir = node->typeinfo->resize_area_func(node, cursor[0], cursor[1]); - wmcursor = node_get_resize_cursor(dir); - } + if (node_find_indicated_socket( + snode, &node, &sock, cursor, (eNodeSocketInOut)(SOCK_IN | SOCK_OUT))) { + WM_cursor_set(&win, WM_CURSOR_DEFAULT); + return; + } + + /* Check nodes front to back. */ + for (node = (bNode *)ntree->nodes.last; node; node = node->prev) { + if (BLI_rctf_isect_pt(&node->totr, cursor[0], cursor[1])) { + break; /* First hit on node stops. */ } } + if (node) { + NodeResizeDirection dir = node->typeinfo->resize_area_func(node, cursor[0], cursor[1]); + wmcursor = node_get_resize_cursor(dir); + } - WM_cursor_set(win, wmcursor); + WM_cursor_set(&win, wmcursor); } void node_draw_default(const bContext *C, @@ -2335,32 +2339,32 @@ void node_draw_default(const bContext *C, { const View2D *v2d = ®ion->v2d; if (node->flag & NODE_HIDDEN) { - node_draw_hidden(C, v2d, snode, ntree, node, key); + node_draw_hidden(*C, *v2d, *snode, *ntree, *node); } else { - node_draw_basis(C, v2d, snode, ntree, node, key); + node_draw_basis(*C, *v2d, *snode, *ntree, *node, key); } } -static void node_update(const bContext *C, bNodeTree *ntree, bNode *node) +static void node_update(const bContext &C, bNodeTree &ntree, bNode &node) { - if (node->typeinfo->draw_nodetype_prepare) { - node->typeinfo->draw_nodetype_prepare(C, ntree, node); + if (node.typeinfo->draw_nodetype_prepare) { + node.typeinfo->draw_nodetype_prepare(&C, &ntree, &node); } } -static void count_multi_input_socket_links(bNodeTree *ntree, SpaceNode *snode) +static void count_multi_input_socket_links(bNodeTree &ntree, SpaceNode &snode) { Map<bNodeSocket *, int> counts; - LISTBASE_FOREACH (bNodeLink *, link, &ntree->links) { + LISTBASE_FOREACH (bNodeLink *, link, &ntree.links) { if (link->tosock->flag & SOCK_MULTI_INPUT) { int &count = counts.lookup_or_add(link->tosock, 0); count++; } } /* Count temporary links going into this socket. */ - if (snode->runtime->linkdrag) { - for (const bNodeLink *link : snode->runtime->linkdrag->links) { + if (snode.runtime->linkdrag) { + for (const bNodeLink *link : snode.runtime->linkdrag->links) { if (link->tosock && (link->tosock->flag & SOCK_MULTI_INPUT)) { int &count = counts.lookup_or_add(link->tosock, 0); count++; @@ -2368,7 +2372,7 @@ static void count_multi_input_socket_links(bNodeTree *ntree, SpaceNode *snode) } } - LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { + LISTBASE_FOREACH (bNode *, node, &ntree.nodes) { LISTBASE_FOREACH (bNodeSocket *, socket, &node->inputs) { if (socket->flag & SOCK_MULTI_INPUT) { socket->total_inputs = counts.lookup_default(socket, 0); @@ -2377,86 +2381,82 @@ static void count_multi_input_socket_links(bNodeTree *ntree, SpaceNode *snode) } } -void node_update_nodetree(const bContext *C, bNodeTree *ntree) +void node_update_nodetree(const bContext &C, bNodeTree &ntree) { /* Make sure socket "used" tags are correct, for displaying value buttons. */ - SpaceNode *snode = CTX_wm_space_node(C); - ntreeTagUsedSockets(ntree); + SpaceNode *snode = CTX_wm_space_node(&C); + ntreeTagUsedSockets(&ntree); - count_multi_input_socket_links(ntree, snode); + count_multi_input_socket_links(ntree, *snode); /* Update nodes front to back, so children sizes get updated before parents. */ - LISTBASE_FOREACH_BACKWARD (bNode *, node, &ntree->nodes) { - node_update(C, ntree, node); + LISTBASE_FOREACH_BACKWARD (bNode *, node, &ntree.nodes) { + node_update(C, ntree, *node); } } -static void node_draw(const bContext *C, - ARegion *region, - SpaceNode *snode, - bNodeTree *ntree, - bNode *node, +static void node_draw(const bContext &C, + ARegion ®ion, + SpaceNode &snode, + bNodeTree &ntree, + bNode &node, bNodeInstanceKey key) { - if (node->typeinfo->draw_nodetype) { - node->typeinfo->draw_nodetype(C, region, snode, ntree, node, key); + if (node.typeinfo->draw_nodetype) { + node.typeinfo->draw_nodetype(&C, ®ion, &snode, &ntree, &node, key); } } #define USE_DRAW_TOT_UPDATE -void node_draw_nodetree(const bContext *C, - ARegion *region, - SpaceNode *snode, - bNodeTree *ntree, +void node_draw_nodetree(const bContext &C, + ARegion ®ion, + SpaceNode &snode, + bNodeTree &ntree, bNodeInstanceKey parent_key) { - if (ntree == nullptr) { - return; /* Groups. */ - } - #ifdef USE_DRAW_TOT_UPDATE - if (ntree->nodes.first) { - BLI_rctf_init_minmax(®ion->v2d.tot); + if (ntree.nodes.first) { + BLI_rctf_init_minmax(®ion.v2d.tot); } #endif /* Draw background nodes, last nodes in front. */ - LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { + LISTBASE_FOREACH (bNode *, node, &ntree.nodes) { #ifdef USE_DRAW_TOT_UPDATE /* Unrelated to background nodes, update the v2d->tot, * can be anywhere before we draw the scroll bars. */ - BLI_rctf_union(®ion->v2d.tot, &node->totr); + BLI_rctf_union(®ion.v2d.tot, &node->totr); #endif if (!(node->flag & NODE_BACKGROUND)) { continue; } - bNodeInstanceKey key = BKE_node_instance_key(parent_key, ntree, node); - node_draw(C, region, snode, ntree, node, key); + bNodeInstanceKey key = BKE_node_instance_key(parent_key, &ntree, node); + node_draw(C, region, snode, ntree, *node, key); } /* Node lines. */ GPU_blend(GPU_BLEND_ALPHA); nodelink_batch_start(snode); - LISTBASE_FOREACH (bNodeLink *, link, &ntree->links) { + LISTBASE_FOREACH (bNodeLink *, link, &ntree.links) { if (!nodeLinkIsHidden(link)) { - node_draw_link(C, ®ion->v2d, snode, link); + node_draw_link(C, region.v2d, snode, *link); } } nodelink_batch_end(snode); GPU_blend(GPU_BLEND_NONE); /* Draw foreground nodes, last nodes in front. */ - LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { + LISTBASE_FOREACH (bNode *, node, &ntree.nodes) { if (node->flag & NODE_BACKGROUND) { continue; } - bNodeInstanceKey key = BKE_node_instance_key(parent_key, ntree, node); - node_draw(C, region, snode, ntree, node, key); + bNodeInstanceKey key = BKE_node_instance_key(parent_key, &ntree, node); + node_draw(C, region, snode, ntree, *node, key); } } @@ -2490,36 +2490,36 @@ static void draw_tree_path(const bContext &C, ARegion ®ion) GPU_matrix_pop_projection(); } -static void snode_setup_v2d(SpaceNode *snode, ARegion *region, const float center[2]) +static void snode_setup_v2d(SpaceNode &snode, ARegion ®ion, const float2 ¢er) { - View2D *v2d = ®ion->v2d; + View2D &v2d = region.v2d; /* Shift view to node tree center. */ - UI_view2d_center_set(v2d, center[0], center[1]); - UI_view2d_view_ortho(v2d); + UI_view2d_center_set(&v2d, center[0], center[1]); + UI_view2d_view_ortho(&v2d); /* Aspect + font, set each time. */ - snode->runtime->aspect = BLI_rctf_size_x(&v2d->cur) / (float)region->winx; + snode.runtime->aspect = BLI_rctf_size_x(&v2d.cur) / (float)region.winx; // XXX snode->curfont = uiSetCurFont_ext(snode->aspect); } -static void draw_nodetree(const bContext *C, - ARegion *region, - bNodeTree *ntree, +static void draw_nodetree(const bContext &C, + ARegion ®ion, + bNodeTree &ntree, bNodeInstanceKey parent_key) { - SpaceNode *snode = CTX_wm_space_node(C); + SpaceNode *snode = CTX_wm_space_node(&C); node_uiblocks_init(C, ntree); node_update_nodetree(C, ntree); - node_draw_nodetree(C, region, snode, ntree, parent_key); + node_draw_nodetree(C, region, *snode, ntree, parent_key); } /** * Make the background slightly brighter to indicate that users are inside a node-group. */ -static void draw_background_color(const SpaceNode *snode) +static void draw_background_color(const SpaceNode &snode) { const int max_tree_length = 3; const float bright_factor = 0.25f; @@ -2527,7 +2527,7 @@ static void draw_background_color(const SpaceNode *snode) /* We ignore the first element of the path since it is the top-most tree and it doesn't need to * be brighter. We also set a cap to how many levels we want to set apart, to avoid the * background from getting too bright. */ - const int clamped_tree_path_length = BLI_listbase_count_at_most(&snode->treepath, + const int clamped_tree_path_length = BLI_listbase_count_at_most(&snode.treepath, max_tree_length); const int depth = max_ii(0, clamped_tree_path_length - 1); @@ -2537,34 +2537,34 @@ static void draw_background_color(const SpaceNode *snode) GPU_clear_color(color[0], color[1], color[2], 1.0); } -void node_draw_space(const bContext *C, ARegion *region) +void node_draw_space(const bContext &C, ARegion ®ion) { - wmWindow *win = CTX_wm_window(C); - SpaceNode *snode = CTX_wm_space_node(C); - View2D *v2d = ®ion->v2d; + wmWindow *win = CTX_wm_window(&C); + SpaceNode &snode = *CTX_wm_space_node(&C); + View2D &v2d = region.v2d; /* Setup off-screen buffers. */ - GPUViewport *viewport = WM_draw_region_get_viewport(region); + GPUViewport *viewport = WM_draw_region_get_viewport(®ion); GPUFrameBuffer *framebuffer_overlay = GPU_viewport_framebuffer_overlay_get(viewport); GPU_framebuffer_bind_no_srgb(framebuffer_overlay); - UI_view2d_view_ortho(v2d); + UI_view2d_view_ortho(&v2d); draw_background_color(snode); GPU_depth_test(GPU_DEPTH_NONE); GPU_scissor_test(true); /* XXX `snode->runtime->cursor` set in coordinate-space for placing new nodes, * used for drawing noodles too. */ - UI_view2d_region_to_view(®ion->v2d, - win->eventstate->xy[0] - region->winrct.xmin, - win->eventstate->xy[1] - region->winrct.ymin, - &snode->runtime->cursor[0], - &snode->runtime->cursor[1]); - snode->runtime->cursor[0] /= UI_DPI_FAC; - snode->runtime->cursor[1] /= UI_DPI_FAC; + UI_view2d_region_to_view(®ion.v2d, + win->eventstate->xy[0] - region.winrct.xmin, + win->eventstate->xy[1] - region.winrct.ymin, + &snode.runtime->cursor[0], + &snode.runtime->cursor[1]); + snode.runtime->cursor[0] /= UI_DPI_FAC; + snode.runtime->cursor[1] /= UI_DPI_FAC; - ED_region_draw_cb_draw(C, region, REGION_DRAW_PRE_VIEW); + ED_region_draw_cb_draw(&C, ®ion, REGION_DRAW_PRE_VIEW); /* Only set once. */ GPU_blend(GPU_BLEND_ALPHA); @@ -2573,15 +2573,15 @@ void node_draw_space(const bContext *C, ARegion *region) snode_set_context(C); const int grid_levels = UI_GetThemeValueType(TH_NODE_GRID_LEVELS, SPACE_NODE); - UI_view2d_dot_grid_draw(v2d, TH_GRID, NODE_GRID_STEP_SIZE, grid_levels); + UI_view2d_dot_grid_draw(&v2d, TH_GRID, NODE_GRID_STEP_SIZE, grid_levels); /* Draw parent node trees. */ - if (snode->treepath.last) { - bNodeTreePath *path = (bNodeTreePath *)snode->treepath.last; + if (snode.treepath.last) { + bNodeTreePath *path = (bNodeTreePath *)snode.treepath.last; /* Update tree path name (drawn in the bottom left). */ - ID *name_id = (path->nodetree && path->nodetree != snode->nodetree) ? &path->nodetree->id : - snode->id; + ID *name_id = (path->nodetree && path->nodetree != snode.nodetree) ? &path->nodetree->id : + snode.id; if (name_id && UNLIKELY(!STREQ(path->display_name, name_id->name + 2))) { BLI_strncpy(path->display_name, name_id->name + 2, sizeof(path->display_name)); @@ -2589,12 +2589,12 @@ void node_draw_space(const bContext *C, ARegion *region) /* Current View2D center, will be set temporarily for parent node trees. */ float center[2]; - UI_view2d_center_get(v2d, ¢er[0], ¢er[1]); + UI_view2d_center_get(&v2d, ¢er[0], ¢er[1]); /* Store new view center in path and current edit tree. */ copy_v2_v2(path->view_center, center); - if (snode->edittree) { - copy_v2_v2(snode->edittree->view_center, center); + if (snode.edittree) { + copy_v2_v2(snode.edittree->view_center, center); } /* Top-level edit tree. */ @@ -2612,31 +2612,31 @@ void node_draw_space(const bContext *C, ARegion *region) GPU_matrix_push(); GPU_matrix_identity_set(); - wmOrtho2_pixelspace(region->winx, region->winy); + wmOrtho2_pixelspace(region.winx, region.winy); - WM_gizmomap_draw(region->gizmo_map, C, WM_GIZMOMAP_DRAWSTEP_2D); + WM_gizmomap_draw(region.gizmo_map, &C, WM_GIZMOMAP_DRAWSTEP_2D); GPU_matrix_pop(); GPU_matrix_projection_set(original_proj); } - draw_nodetree(C, region, ntree, path->parent_key); + draw_nodetree(C, region, *ntree, path->parent_key); } /* Temporary links. */ GPU_blend(GPU_BLEND_ALPHA); GPU_line_smooth(true); - if (snode->runtime->linkdrag) { - for (const bNodeLink *link : snode->runtime->linkdrag->links) { - node_draw_link(C, v2d, snode, link); + if (snode.runtime->linkdrag) { + for (const bNodeLink *link : snode.runtime->linkdrag->links) { + node_draw_link(C, v2d, snode, *link); } } GPU_line_smooth(false); GPU_blend(GPU_BLEND_NONE); - if (snode->overlay.flag & SN_OVERLAY_SHOW_OVERLAYS && snode->flag & SNODE_SHOW_GPENCIL) { + if (snode.overlay.flag & SN_OVERLAY_SHOW_OVERLAYS && snode.flag & SNODE_SHOW_GPENCIL) { /* Draw grease-pencil annotations. */ - ED_annotation_draw_view2d(C, true); + ED_annotation_draw_view2d(&C, true); } } else { @@ -2645,23 +2645,23 @@ void node_draw_space(const bContext *C, ARegion *region) draw_nodespace_back_pix(C, region, snode, NODE_INSTANCE_KEY_NONE); } - ED_region_draw_cb_draw(C, region, REGION_DRAW_POST_VIEW); + ED_region_draw_cb_draw(&C, ®ion, REGION_DRAW_POST_VIEW); /* Reset view matrix. */ - UI_view2d_view_restore(C); + UI_view2d_view_restore(&C); - if (snode->overlay.flag & SN_OVERLAY_SHOW_OVERLAYS) { - if (snode->flag & SNODE_SHOW_GPENCIL && snode->treepath.last) { + if (snode.overlay.flag & SN_OVERLAY_SHOW_OVERLAYS) { + if (snode.flag & SNODE_SHOW_GPENCIL && snode.treepath.last) { /* Draw grease-pencil (screen strokes, and also paint-buffer). */ - ED_annotation_draw_view2d(C, false); + ED_annotation_draw_view2d(&C, false); } /* Draw context path. */ - if (snode->overlay.flag & SN_OVERLAY_SHOW_PATH && snode->edittree) { - draw_tree_path(*C, *region); + if (snode.overlay.flag & SN_OVERLAY_SHOW_PATH && snode.edittree) { + draw_tree_path(C, region); } } /* Scrollers. */ - UI_view2d_scrollers_draw(v2d, nullptr); + UI_view2d_scrollers_draw(&v2d, nullptr); } diff --git a/source/blender/editors/space_node/node_edit.cc b/source/blender/editors/space_node/node_edit.cc index e6dae26e174..f856347e09a 100644 --- a/source/blender/editors/space_node/node_edit.cc +++ b/source/blender/editors/space_node/node_edit.cc @@ -31,9 +31,6 @@ #include "DNA_text_types.h" #include "DNA_world_types.h" -#include "BLI_blenlib.h" -#include "BLI_math.h" - #include "BKE_context.h" #include "BKE_global.h" #include "BKE_image.h" @@ -80,6 +77,8 @@ #define USE_ESC_COMPO +using blender::float2; + /* ***************** composite job manager ********************** */ enum { @@ -103,11 +102,11 @@ struct CompoJob { float *progress; }; -float node_socket_calculate_height(const bNodeSocket *socket) +float node_socket_calculate_height(const bNodeSocket &socket) { float sock_height = NODE_SOCKSIZE * 2.0f; - if (socket->flag & SOCK_MULTI_INPUT) { - sock_height += max_ii(NODE_MULTI_INPUT_LINK_GAP * 0.5f * socket->total_inputs, NODE_SOCKSIZE); + if (socket.flag & SOCK_MULTI_INPUT) { + sock_height += max_ii(NODE_MULTI_INPUT_LINK_GAP * 0.5f * socket.total_inputs, NODE_SOCKSIZE); } return sock_height; } @@ -394,31 +393,31 @@ bool composite_node_editable(bContext *C) return false; } -void snode_dag_update(bContext *C, SpaceNode *snode) +void snode_dag_update(bContext &C, SpaceNode &snode) { - Main *bmain = CTX_data_main(C); + Main *bmain = CTX_data_main(&C); /* for groups, update all ID's using this */ - if ((snode->edittree->id.flag & LIB_EMBEDDED_DATA) == 0) { + if ((snode.edittree->id.flag & LIB_EMBEDDED_DATA) == 0) { FOREACH_NODETREE_BEGIN (bmain, tntree, id) { - if (ntreeHasTree(tntree, snode->edittree)) { + if (ntreeHasTree(tntree, snode.edittree)) { DEG_id_tag_update(id, 0); } } FOREACH_NODETREE_END; } - DEG_id_tag_update(snode->id, 0); - DEG_id_tag_update(&snode->nodetree->id, 0); + DEG_id_tag_update(snode.id, 0); + DEG_id_tag_update(&snode.nodetree->id, 0); } -void snode_notify(bContext *C, SpaceNode *snode) +void snode_notify(bContext &C, SpaceNode &snode) { - ID *id = snode->id; + ID *id = snode.id; - WM_event_add_notifier(C, NC_NODE | NA_EDITED, nullptr); + WM_event_add_notifier(&C, NC_NODE | NA_EDITED, nullptr); - if (ED_node_is_shader(snode)) { + if (ED_node_is_shader(&snode)) { if (GS(id->name) == ID_MA) { WM_main_add_notifier(NC_MATERIAL | ND_SHADING, id); } @@ -429,13 +428,13 @@ void snode_notify(bContext *C, SpaceNode *snode) WM_main_add_notifier(NC_WORLD | ND_WORLD, id); } } - else if (ED_node_is_compositor(snode)) { - WM_event_add_notifier(C, NC_SCENE | ND_NODES, id); + else if (ED_node_is_compositor(&snode)) { + WM_event_add_notifier(&C, NC_SCENE | ND_NODES, id); } - else if (ED_node_is_texture(snode)) { - WM_event_add_notifier(C, NC_TEXTURE | ND_NODES, id); + else if (ED_node_is_texture(&snode)) { + WM_event_add_notifier(&C, NC_TEXTURE | ND_NODES, id); } - else if (ED_node_is_geometry(snode)) { + else if (ED_node_is_geometry(&snode)) { WM_main_add_notifier(NC_OBJECT | ND_MODIFIER, id); } } @@ -604,15 +603,15 @@ void ED_node_texture_default(const bContext *C, Tex *tex) } /* Here we set the active tree(s), even called for each redraw now, so keep it fast :) */ -void snode_set_context(const bContext *C) +void snode_set_context(const bContext &C) { - SpaceNode *snode = CTX_wm_space_node(C); + SpaceNode *snode = CTX_wm_space_node(&C); bNodeTreeType *treetype = ntreeTypeFind(snode->tree_idname); bNodeTree *ntree = snode->nodetree; ID *id = snode->id, *from = snode->from; /* check the tree type */ - if (!treetype || (treetype->poll && !treetype->poll(C, treetype))) { + if (!treetype || (treetype->poll && !treetype->poll(&C, treetype))) { /* invalid tree type, skip * NOTE: not resetting the node path here, invalid #bNodeTreeType * may still be registered at a later point. */ @@ -633,7 +632,7 @@ void snode_set_context(const bContext *C) id = nullptr; from = nullptr; - treetype->get_from_context(C, treetype, &ntree, &id, &from); + treetype->get_from_context(&C, treetype, &ntree, &id, &from); } } @@ -643,7 +642,7 @@ void snode_set_context(const bContext *C) } } -void snode_update(SpaceNode *snode, bNode *node) +void snode_update(SpaceNode &snode, bNode *node) { /* XXX this only updates nodes in the current node space tree path. * The function supposedly should update any potential group node linking to changed tree, @@ -651,7 +650,7 @@ void snode_update(SpaceNode *snode, bNode *node) */ /* update all edited group nodes */ - bNodeTreePath *path = (bNodeTreePath *)snode->treepath.last; + bNodeTreePath *path = (bNodeTreePath *)snode.treepath.last; if (path) { bNodeTree *ngroup = path->nodetree; for (path = path->prev; path; path = path->prev) { @@ -661,7 +660,7 @@ void snode_update(SpaceNode *snode, bNode *node) } if (node) { - nodeUpdate(snode->edittree, node); + nodeUpdate(snode.edittree, node); } } @@ -918,10 +917,10 @@ static void edit_node_properties_get( /* ************************** Node generic ************** */ /* is rct in visible part of node? */ -static bNode *visible_node(SpaceNode *snode, const rctf *rct) +static bNode *visible_node(SpaceNode &snode, const rctf &rct) { - LISTBASE_FOREACH_BACKWARD (bNode *, node, &snode->edittree->nodes) { - if (BLI_rctf_isect(&node->totr, rct, nullptr)) { + LISTBASE_FOREACH_BACKWARD (bNode *, node, &snode.edittree->nodes) { + if (BLI_rctf_isect(&node->totr, &rct, nullptr)) { return node; } } @@ -941,7 +940,7 @@ struct NodeSizeWidget { static void node_resize_init(bContext *C, wmOperator *op, const wmEvent *UNUSED(event), - bNode *node, + const bNode *node, NodeResizeDirection dir) { SpaceNode *snode = CTX_wm_space_node(C); @@ -1091,20 +1090,22 @@ static int node_resize_invoke(bContext *C, wmOperator *op, const wmEvent *event) { SpaceNode *snode = CTX_wm_space_node(C); ARegion *region = CTX_wm_region(C); - bNode *node = nodeGetActive(snode->edittree); + const bNode *node = nodeGetActive(snode->edittree); - if (node) { - float cursor[2]; + if (node == nullptr) { + return OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH; + } - /* convert mouse coordinates to v2d space */ - UI_view2d_region_to_view(®ion->v2d, event->mval[0], event->mval[1], &cursor[0], &cursor[1]); - const NodeResizeDirection dir = node->typeinfo->resize_area_func(node, cursor[0], cursor[1]); - if (dir != NODE_RESIZE_NONE) { - node_resize_init(C, op, event, node, dir); - return OPERATOR_RUNNING_MODAL; - } + /* convert mouse coordinates to v2d space */ + float cursor[2]; + UI_view2d_region_to_view(®ion->v2d, event->mval[0], event->mval[1], &cursor[0], &cursor[1]); + const NodeResizeDirection dir = node->typeinfo->resize_area_func(node, cursor[0], cursor[1]); + if (dir == NODE_RESIZE_NONE) { + return OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH; } - return OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH; + + node_resize_init(C, op, event, node, dir); + return OPERATOR_RUNNING_MODAL; } static void node_resize_cancel(bContext *C, wmOperator *op) @@ -1172,7 +1173,7 @@ void node_set_hidden_sockets(SpaceNode *snode, bNode *node, int set) } /* checks snode->mouse position, and returns found node/socket */ -static bool cursor_isect_multi_input_socket(const float cursor[2], const bNodeSocket *socket) +static bool cursor_isect_multi_input_socket(const float cursor[2], const bNodeSocket &socket) { const float node_socket_height = node_socket_calculate_height(socket); rctf multi_socket_rect; @@ -1182,10 +1183,10 @@ static bool cursor_isect_multi_input_socket(const float cursor[2], const bNodeSo * sometimes want to drag the link to the other side, if you may * accidentally pick the wrong link otherwise. */ BLI_rctf_init(&multi_socket_rect, - socket->locx - NODE_SOCKSIZE * 4.0f, - socket->locx + NODE_SOCKSIZE * 2.0f, - socket->locy - node_socket_height, - socket->locy + node_socket_height); + socket.locx - NODE_SOCKSIZE * 4.0f, + socket.locx + NODE_SOCKSIZE * 2.0f, + socket.locy - node_socket_height, + socket.locy + node_socket_height); if (BLI_rctf_isect_pt(&multi_socket_rect, cursor[0], cursor[1])) { return true; } @@ -1193,8 +1194,11 @@ static bool cursor_isect_multi_input_socket(const float cursor[2], const bNodeSo } /* type is SOCK_IN and/or SOCK_OUT */ -bool node_find_indicated_socket( - SpaceNode *snode, bNode **nodep, bNodeSocket **sockp, const float cursor[2], int in_out) +bool node_find_indicated_socket(SpaceNode &snode, + bNode **nodep, + bNodeSocket **sockp, + const float2 &cursor, + const eNodeSocketInOut in_out) { rctf rect; @@ -1202,7 +1206,7 @@ bool node_find_indicated_socket( *sockp = nullptr; /* check if we click in a socket */ - LISTBASE_FOREACH (bNode *, node, &snode->edittree->nodes) { + LISTBASE_FOREACH (bNode *, node, &snode.edittree->nodes) { BLI_rctf_init_pt_radius(&rect, cursor, NODE_SOCKSIZE + 4); if (!(node->flag & NODE_HIDDEN)) { @@ -1221,8 +1225,8 @@ bool node_find_indicated_socket( LISTBASE_FOREACH (bNodeSocket *, sock, &node->inputs) { if (!nodeSocketIsHidden(sock)) { if (sock->flag & SOCK_MULTI_INPUT && !(node->flag & NODE_HIDDEN)) { - if (cursor_isect_multi_input_socket(cursor, sock)) { - if (node == visible_node(snode, &rect)) { + if (cursor_isect_multi_input_socket(cursor, *sock)) { + if (node == visible_node(snode, rect)) { *nodep = node; *sockp = sock; return true; @@ -1230,7 +1234,7 @@ bool node_find_indicated_socket( } } else if (BLI_rctf_isect_pt(&rect, sock->locx, sock->locy)) { - if (node == visible_node(snode, &rect)) { + if (node == visible_node(snode, rect)) { *nodep = node; *sockp = sock; return true; @@ -1243,7 +1247,7 @@ bool node_find_indicated_socket( LISTBASE_FOREACH (bNodeSocket *, sock, &node->outputs) { if (!nodeSocketIsHidden(sock)) { if (BLI_rctf_isect_pt(&rect, sock->locx, sock->locy)) { - if (node == visible_node(snode, &rect)) { + if (node == visible_node(snode, rect)) { *nodep = node; *sockp = sock; return true; @@ -1259,28 +1263,28 @@ bool node_find_indicated_socket( /* ****************** Link Dimming *********************** */ -float node_link_dim_factor(const View2D *v2d, const bNodeLink *link) +float node_link_dim_factor(const View2D &v2d, const bNodeLink &link) { - if (link->fromsock == nullptr || link->tosock == nullptr) { + if (link.fromsock == nullptr || link.tosock == nullptr) { return 1.0f; } const float min_endpoint_distance = std::min( - std::max(BLI_rctf_length_x(&v2d->cur, link->fromsock->locx), - BLI_rctf_length_y(&v2d->cur, link->fromsock->locy)), - std::max(BLI_rctf_length_x(&v2d->cur, link->tosock->locx), - BLI_rctf_length_y(&v2d->cur, link->tosock->locy))); + std::max(BLI_rctf_length_x(&v2d.cur, link.fromsock->locx), + BLI_rctf_length_y(&v2d.cur, link.fromsock->locy)), + std::max(BLI_rctf_length_x(&v2d.cur, link.tosock->locx), + BLI_rctf_length_y(&v2d.cur, link.tosock->locy))); if (min_endpoint_distance == 0.0f) { return 1.0f; } - const float viewport_width = BLI_rctf_size_x(&v2d->cur); + const float viewport_width = BLI_rctf_size_x(&v2d.cur); return std::clamp(1.0f - min_endpoint_distance / viewport_width * 10.0f, 0.05f, 1.0f); } -bool node_link_is_hidden_or_dimmed(const View2D *v2d, const bNodeLink *link) +bool node_link_is_hidden_or_dimmed(const View2D &v2d, const bNodeLink &link) { - return nodeLinkIsHidden(link) || node_link_dim_factor(v2d, link) < 0.5f; + return nodeLinkIsHidden(&link) || node_link_dim_factor(v2d, link) < 0.5f; } /* ****************** Duplicate *********************** */ @@ -1390,7 +1394,7 @@ static int node_duplicate_exec(bContext *C, wmOperator *op) node->flag &= ~(NODE_ACTIVE | NODE_ACTIVE_TEXTURE); nodeSetSelected(newnode, true); - do_tag_update |= (do_tag_update || node_connected_to_output(bmain, ntree, newnode)); + do_tag_update |= (do_tag_update || node_connected_to_output(*bmain, *ntree, *newnode)); } /* make sure we don't copy new nodes again! */ @@ -1401,9 +1405,9 @@ static int node_duplicate_exec(bContext *C, wmOperator *op) ntreeUpdateTree(CTX_data_main(C), snode->edittree); - snode_notify(C, snode); + snode_notify(*C, *snode); if (do_tag_update) { - snode_dag_update(C, snode); + snode_dag_update(*C, *snode); } return OPERATOR_FINISHED; @@ -1496,8 +1500,8 @@ static int node_read_viewlayers_exec(bContext *C, wmOperator *UNUSED(op)) } } - snode_notify(C, snode); - snode_dag_update(C, snode); + snode_notify(*C, *snode); + snode_dag_update(*C, *snode); return OPERATOR_FINISHED; } @@ -1664,7 +1668,7 @@ static int node_preview_toggle_exec(bContext *C, wmOperator *UNUSED(op)) node_flag_toggle_exec(snode, NODE_PREVIEW); - snode_notify(C, snode); + snode_notify(*C, *snode); return OPERATOR_FINISHED; } @@ -1778,14 +1782,15 @@ static int node_mute_exec(bContext *C, wmOperator *UNUSED(op)) LISTBASE_FOREACH (bNode *, node, &snode->edittree->nodes) { if ((node->flag & SELECT) && !node->typeinfo->no_muting) { node->flag ^= NODE_MUTED; - snode_update(snode, node); - do_tag_update |= (do_tag_update || node_connected_to_output(bmain, snode->edittree, node)); + snode_update(*snode, node); + do_tag_update |= (do_tag_update || + node_connected_to_output(*bmain, *snode->edittree, *node)); } } - snode_notify(C, snode); + snode_notify(*C, *snode); if (do_tag_update) { - snode_dag_update(C, snode); + snode_dag_update(*C, *snode); } return OPERATOR_FINISHED; @@ -1818,16 +1823,17 @@ static int node_delete_exec(bContext *C, wmOperator *UNUSED(op)) LISTBASE_FOREACH_MUTABLE (bNode *, node, &snode->edittree->nodes) { if (node->flag & SELECT) { - do_tag_update |= (do_tag_update || node_connected_to_output(bmain, snode->edittree, node)); + do_tag_update |= (do_tag_update || + node_connected_to_output(*bmain, *snode->edittree, *node)); nodeRemoveNode(bmain, snode->edittree, node, true); } } ntreeUpdateTree(CTX_data_main(C), snode->edittree); - snode_notify(C, snode); + snode_notify(*C, *snode); if (do_tag_update) { - snode_dag_update(C, snode); + snode_dag_update(*C, *snode); } return OPERATOR_FINISHED; @@ -1874,8 +1880,8 @@ static int node_switch_view_exec(bContext *C, wmOperator *UNUSED(op)) ntreeUpdateTree(CTX_data_main(C), snode->edittree); - snode_notify(C, snode); - snode_dag_update(C, snode); + snode_notify(*C, *snode); + snode_dag_update(*C, *snode); return OPERATOR_FINISHED; } @@ -1912,8 +1918,8 @@ static int node_delete_reconnect_exec(bContext *C, wmOperator *UNUSED(op)) ntreeUpdateTree(CTX_data_main(C), snode->edittree); - snode_notify(C, snode); - snode_dag_update(C, snode); + snode_notify(*C, *snode); + snode_dag_update(*C, *snode); return OPERATOR_FINISHED; } @@ -1960,7 +1966,7 @@ static int node_output_file_add_socket_exec(bContext *C, wmOperator *op) RNA_string_get(op->ptr, "file_path", file_path); ntreeCompositOutputFileAddSocket(ntree, node, file_path, &scene->r.im_format); - snode_notify(C, snode); + snode_notify(*C, *snode); return OPERATOR_FINISHED; } @@ -2009,7 +2015,7 @@ static int node_output_file_remove_active_socket_exec(bContext *C, wmOperator *U return OPERATOR_CANCELLED; } - snode_notify(C, snode); + snode_notify(*C, *snode); return OPERATOR_FINISHED; } @@ -2076,7 +2082,7 @@ static int node_output_file_move_active_socket_exec(bContext *C, wmOperator *op) nimf->active_input++; } - snode_notify(C, snode); + snode_notify(*C, *snode); return OPERATOR_FINISHED; } @@ -2286,7 +2292,7 @@ static int node_clipboard_paste_exec(bContext *C, wmOperator *op) ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C)); /* deselect old nodes */ - node_deselect_all(snode); + node_deselect_all(*snode); /* calculate "barycenter" for placing on mouse cursor */ float center[2] = {0.0f, 0.0f}; @@ -2324,8 +2330,8 @@ static int node_clipboard_paste_exec(bContext *C, wmOperator *op) Main *bmain = CTX_data_main(C); ntreeUpdateTree(bmain, snode->edittree); - snode_notify(C, snode); - snode_dag_update(C, snode); + snode_notify(*C, *snode); + snode_dag_update(*C, *snode); /* Pasting nodes can create arbitrary new relations, because nodes can reference IDs. */ DEG_relations_tag_update(bmain); @@ -2395,8 +2401,8 @@ static int ntree_socket_add_exec(bContext *C, wmOperator *op) ntreeUpdateTree(CTX_data_main(C), ntree); - snode_notify(C, snode); - snode_dag_update(C, snode); + snode_notify(*C, *snode); + snode_dag_update(*C, *snode); WM_event_add_notifier(C, NC_NODE | ND_DISPLAY, nullptr); @@ -2445,8 +2451,8 @@ static int ntree_socket_remove_exec(bContext *C, wmOperator *op) ntreeUpdateTree(CTX_data_main(C), ntree); - snode_notify(C, snode); - snode_dag_update(C, snode); + snode_notify(*C, *snode); + snode_dag_update(*C, *snode); WM_event_add_notifier(C, NC_NODE | ND_DISPLAY, nullptr); @@ -2508,8 +2514,8 @@ static int ntree_socket_change_type_exec(bContext *C, wmOperator *op) ntreeUpdateTree(main, ntree); - snode_notify(C, snode); - snode_dag_update(C, snode); + snode_notify(*C, *snode); + snode_dag_update(*C, *snode); WM_event_add_notifier(C, NC_NODE | ND_DISPLAY, nullptr); @@ -2623,8 +2629,8 @@ static int ntree_socket_move_exec(bContext *C, wmOperator *op) ntree->update |= NTREE_UPDATE_GROUP; ntreeUpdateTree(CTX_data_main(C), ntree); - snode_notify(C, snode); - snode_dag_update(C, snode); + snode_notify(*C, *snode); + snode_dag_update(*C, *snode); WM_event_add_notifier(C, NC_NODE | ND_DISPLAY, nullptr); @@ -2855,7 +2861,7 @@ static int viewer_border_exec(bContext *C, wmOperator *op) btree->flag |= NTREE_VIEWER_BORDER; } - snode_notify(C, snode); + snode_notify(*C, *snode); WM_event_add_notifier(C, NC_NODE | ND_DISPLAY, nullptr); } else { @@ -2895,7 +2901,7 @@ static int clear_viewer_border_exec(bContext *C, wmOperator *UNUSED(op)) bNodeTree *btree = snode->nodetree; btree->flag &= ~NTREE_VIEWER_BORDER; - snode_notify(C, snode); + snode_notify(*C, *snode); WM_event_add_notifier(C, NC_NODE | ND_DISPLAY, nullptr); return OPERATOR_FINISHED; @@ -2940,7 +2946,7 @@ static int node_cryptomatte_add_socket_exec(bContext *C, wmOperator *UNUSED(op)) ntreeCompositCryptomatteAddSocket(ntree, node); - snode_notify(C, snode); + snode_notify(*C, *snode); return OPERATOR_FINISHED; } @@ -2986,7 +2992,7 @@ static int node_cryptomatte_remove_socket_exec(bContext *C, wmOperator *UNUSED(o return OPERATOR_CANCELLED; } - snode_notify(C, snode); + snode_notify(*C, *snode); return OPERATOR_FINISHED; } diff --git a/source/blender/editors/space_node/node_geometry_attribute_search.cc b/source/blender/editors/space_node/node_geometry_attribute_search.cc index 79ba9b8d2d9..4890c3e39cf 100644 --- a/source/blender/editors/space_node/node_geometry_attribute_search.cc +++ b/source/blender/editors/space_node/node_geometry_attribute_search.cc @@ -100,13 +100,13 @@ static void attribute_search_exec_fn(bContext *C, void *data_v, void *item_v) ED_undo_push(C, "Assign Attribute Name"); } -void node_geometry_add_attribute_search_button(const bContext *UNUSED(C), - const bNodeTree *node_tree, - const bNode *node, - PointerRNA *socket_ptr, - uiLayout *layout) +void node_geometry_add_attribute_search_button(const bContext &UNUSED(C), + const bNodeTree &node_tree, + const bNode &node, + PointerRNA &socket_ptr, + uiLayout &layout) { - uiBlock *block = uiLayoutGetBlock(layout); + uiBlock *block = uiLayoutGetBlock(&layout); uiBut *but = uiDefIconTextButR(block, UI_BTYPE_SEARCH_MENU, 0, @@ -116,7 +116,7 @@ void node_geometry_add_attribute_search_button(const bContext *UNUSED(C), 0, 10 * UI_UNIT_X, /* Dummy value, replaced by layout system. */ UI_UNIT_Y, - socket_ptr, + &socket_ptr, "default_value", 0, 0.0f, @@ -126,7 +126,7 @@ void node_geometry_add_attribute_search_button(const bContext *UNUSED(C), ""); AttributeSearchData *data = OBJECT_GUARDED_NEW( - AttributeSearchData, {node_tree, node, (bNodeSocket *)socket_ptr->data}); + AttributeSearchData, {&node_tree, &node, (bNodeSocket *)socket_ptr.data}); UI_but_func_search_set_results_are_suggestions(but, true); UI_but_func_search_set_sep_string(but, UI_MENU_ARROW_SEP); diff --git a/source/blender/editors/space_node/node_group.cc b/source/blender/editors/space_node/node_group.cc index 60cd0fc0f59..704ffe1e478 100644 --- a/source/blender/editors/space_node/node_group.cc +++ b/source/blender/editors/space_node/node_group.cc @@ -419,8 +419,8 @@ static int node_group_ungroup_exec(bContext *C, wmOperator *op) return OPERATOR_CANCELLED; } - snode_notify(C, snode); - snode_dag_update(C, snode); + snode_notify(*C, *snode); + snode_dag_update(*C, *snode); return OPERATOR_FINISHED; } @@ -616,8 +616,8 @@ static int node_group_separate_exec(bContext *C, wmOperator *op) ntreeUpdateTree(CTX_data_main(C), snode->nodetree); - snode_notify(C, snode); - snode_dag_update(C, snode); + snode_notify(*C, *snode); + snode_dag_update(*C, *snode); return OPERATOR_FINISHED; } @@ -663,16 +663,16 @@ void NODE_OT_group_separate(wmOperatorType *ot) /** \name Make Group Operator * \{ */ -static bool node_group_make_use_node(bNode *node, bNode *gnode) +static bool node_group_make_use_node(bNode &node, bNode *gnode) { - return (node != gnode && !ELEM(node->type, NODE_GROUP_INPUT, NODE_GROUP_OUTPUT) && - (node->flag & NODE_SELECT)); + return (&node != gnode && !ELEM(node.type, NODE_GROUP_INPUT, NODE_GROUP_OUTPUT) && + (node.flag & NODE_SELECT)); } -static bool node_group_make_test_selected(bNodeTree *ntree, +static bool node_group_make_test_selected(bNodeTree &ntree, bNode *gnode, const char *ntree_idname, - struct ReportList *reports) + struct ReportList &reports) { int ok = true; @@ -680,20 +680,20 @@ static bool node_group_make_test_selected(bNodeTree *ntree, bNodeTree *ngroup = ntreeAddTree(nullptr, "Pseudo Node Group", ntree_idname); /* check poll functions for selected nodes */ - LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { - if (node_group_make_use_node(node, gnode)) { + LISTBASE_FOREACH (bNode *, node, &ntree.nodes) { + if (node_group_make_use_node(*node, gnode)) { const char *disabled_hint = nullptr; if (node->typeinfo->poll_instance && !node->typeinfo->poll_instance(node, ngroup, &disabled_hint)) { if (disabled_hint) { - BKE_reportf(reports, + BKE_reportf(&reports, RPT_WARNING, "Can not add node '%s' in a group:\n %s", node->name, disabled_hint); } else { - BKE_reportf(reports, RPT_WARNING, "Can not add node '%s' in a group", node->name); + BKE_reportf(&reports, RPT_WARNING, "Can not add node '%s' in a group", node->name); } ok = false; break; @@ -712,15 +712,15 @@ static bool node_group_make_test_selected(bNodeTree *ntree, /* check if all connections are OK, no unselected node has both * inputs and outputs to a selection */ - LISTBASE_FOREACH (bNodeLink *, link, &ntree->links) { - if (node_group_make_use_node(link->fromnode, gnode)) { + LISTBASE_FOREACH (bNodeLink *, link, &ntree.links) { + if (node_group_make_use_node(*link->fromnode, gnode)) { link->tonode->done |= 1; } - if (node_group_make_use_node(link->tonode, gnode)) { + if (node_group_make_use_node(*link->tonode, gnode)) { link->fromnode->done |= 2; } } - LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { + LISTBASE_FOREACH (bNode *, node, &ntree.nodes) { if (!(node->flag & NODE_SELECT) && node != gnode && node->done == 3) { return false; } @@ -729,13 +729,13 @@ static bool node_group_make_test_selected(bNodeTree *ntree, } static int node_get_selected_minmax( - bNodeTree *ntree, bNode *gnode, float *min, float *max, bool use_size) + bNodeTree &ntree, bNode *gnode, float2 &min, float2 &max, bool use_size) { int totselect = 0; INIT_MINMAX2(min, max); - LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { - if (node_group_make_use_node(node, gnode)) { + LISTBASE_FOREACH (bNode *, node, &ntree.nodes) { + if (node_group_make_use_node(*node, gnode)) { float loc[2]; nodeToView(node, node->offsetx, node->offsety, &loc[0], &loc[1]); minmax_v2v2_v2(min, max, loc); @@ -756,9 +756,9 @@ static int node_get_selected_minmax( return totselect; } -static void node_group_make_insert_selected(const bContext *C, bNodeTree *ntree, bNode *gnode) +static void node_group_make_insert_selected(const bContext &C, bNodeTree &ntree, bNode *gnode) { - Main *bmain = CTX_data_main(C); + Main *bmain = CTX_data_main(&C); bNodeTree *ngroup = (bNodeTree *)gnode->id; bool expose_visible = false; @@ -771,12 +771,12 @@ static void node_group_make_insert_selected(const bContext *C, bNodeTree *ntree, nodeSetSelected(node, false); } - float center[2], min[2], max[2]; + float2 center, min, max; const int totselect = node_get_selected_minmax(ntree, gnode, min, max, false); add_v2_v2v2(center, min, max); mul_v2_fl(center, 0.5f); - float real_min[2], real_max[2]; + float2 real_min, real_max; node_get_selected_minmax(ntree, gnode, real_min, real_max, true); /* auto-add interface for "solo" nodes */ @@ -787,16 +787,16 @@ static void node_group_make_insert_selected(const bContext *C, bNodeTree *ntree, ListBase anim_basepaths = {nullptr, nullptr}; /* move nodes over */ - LISTBASE_FOREACH_MUTABLE (bNode *, node, &ntree->nodes) { - if (node_group_make_use_node(node, gnode)) { + LISTBASE_FOREACH_MUTABLE (bNode *, node, &ntree.nodes) { + if (node_group_make_use_node(*node, gnode)) { /* keep track of this node's RNA "base" path (the part of the pat identifying the node) * if the old nodetree has animation data which potentially covers this node */ - if (ntree->adt) { + if (ntree.adt) { PointerRNA ptr; char *path; - RNA_pointer_create(&ntree->id, &RNA_Node, node, &ptr); + RNA_pointer_create(&ntree.id, &RNA_Node, node, &ptr); path = RNA_path_from_ID_to_struct(&ptr); if (path) { @@ -810,7 +810,7 @@ static void node_group_make_insert_selected(const bContext *C, bNodeTree *ntree, } /* change node-collection membership */ - BLI_remlink(&ntree->nodes, node); + BLI_remlink(&ntree.nodes, node); BLI_addtail(&ngroup->nodes, node); /* ensure unique node name in the ngroup */ @@ -819,8 +819,8 @@ static void node_group_make_insert_selected(const bContext *C, bNodeTree *ntree, } /* move animation data over */ - if (ntree->adt) { - BKE_animdata_transfer_by_basepath(bmain, &ntree->id, &ngroup->id, &anim_basepaths); + if (ntree.adt) { + BKE_animdata_transfer_by_basepath(bmain, &ntree.id, &ngroup->id, &anim_basepaths); /* paths + their wrappers need to be freed */ LISTBASE_FOREACH_MUTABLE (AnimationBasePathChange *, basepath_change, &anim_basepaths) { @@ -832,36 +832,36 @@ static void node_group_make_insert_selected(const bContext *C, bNodeTree *ntree, ntreeFreeCache(ngroup); /* create input node */ - bNode *input_node = nodeAddStaticNode(C, ngroup, NODE_GROUP_INPUT); + bNode *input_node = nodeAddStaticNode(&C, ngroup, NODE_GROUP_INPUT); input_node->locx = real_min[0] - center[0] - offsetx; input_node->locy = -offsety; /* create output node */ - bNode *output_node = nodeAddStaticNode(C, ngroup, NODE_GROUP_OUTPUT); + bNode *output_node = nodeAddStaticNode(&C, ngroup, NODE_GROUP_OUTPUT); output_node->locx = real_max[0] - center[0] + offsetx * 0.25f; output_node->locy = -offsety; /* relink external sockets */ - LISTBASE_FOREACH_MUTABLE (bNodeLink *, link, &ntree->links) { - int fromselect = node_group_make_use_node(link->fromnode, gnode); - int toselect = node_group_make_use_node(link->tonode, gnode); + LISTBASE_FOREACH_MUTABLE (bNodeLink *, link, &ntree.links) { + int fromselect = node_group_make_use_node(*link->fromnode, gnode); + int toselect = node_group_make_use_node(*link->tonode, gnode); if ((fromselect && link->tonode == gnode) || (toselect && link->fromnode == gnode)) { /* remove all links to/from the gnode. * this can remove link information, but there's no general way to preserve it. */ - nodeRemLink(ntree, link); + nodeRemLink(&ntree, link); } else if (toselect && !fromselect) { bNodeSocket *link_sock; bNode *link_node; - node_socket_skip_reroutes(&ntree->links, link->tonode, link->tosock, &link_node, &link_sock); + node_socket_skip_reroutes(&ntree.links, link->tonode, link->tosock, &link_node, &link_sock); bNodeSocket *iosock = ntreeAddSocketInterfaceFromSocket(ngroup, link_node, link_sock); /* update the group node and interface node sockets, * so the new interface socket can be linked. */ - node_group_update(ntree, gnode); + node_group_update(&ntree, gnode); node_group_input_update(ngroup, input_node); /* create new internal link */ @@ -890,13 +890,13 @@ static void node_group_make_insert_selected(const bContext *C, bNodeTree *ntree, bNodeSocket *link_sock; bNode *link_node; node_socket_skip_reroutes( - &ntree->links, link->fromnode, link->fromsock, &link_node, &link_sock); + &ntree.links, link->fromnode, link->fromsock, &link_node, &link_sock); bNodeSocket *iosock = ntreeAddSocketInterfaceFromSocket(ngroup, link_node, link_sock); /* update the group node and interface node sockets, * so the new interface socket can be linked. */ - node_group_update(ntree, gnode); + node_group_update(&ntree, gnode); node_group_output_update(ngroup, output_node); /* create new internal link */ @@ -911,19 +911,19 @@ static void node_group_make_insert_selected(const bContext *C, bNodeTree *ntree, } /* move internal links */ - LISTBASE_FOREACH_MUTABLE (bNodeLink *, link, &ntree->links) { - int fromselect = node_group_make_use_node(link->fromnode, gnode); - int toselect = node_group_make_use_node(link->tonode, gnode); + LISTBASE_FOREACH_MUTABLE (bNodeLink *, link, &ntree.links) { + int fromselect = node_group_make_use_node(*link->fromnode, gnode); + int toselect = node_group_make_use_node(*link->tonode, gnode); if (fromselect && toselect) { - BLI_remlink(&ntree->links, link); + BLI_remlink(&ntree.links, link); BLI_addtail(&ngroup->links, link); } } /* move nodes in the group to the center */ LISTBASE_FOREACH (bNode *, node, &ngroup->nodes) { - if (node_group_make_use_node(node, gnode) && !node->parent) { + if (node_group_make_use_node(*node, gnode) && !node->parent) { node->locx -= center[0]; node->locy -= center[1]; } @@ -932,7 +932,7 @@ static void node_group_make_insert_selected(const bContext *C, bNodeTree *ntree, /* Expose all unlinked sockets too but only the visible ones. */ if (expose_visible) { LISTBASE_FOREACH (bNode *, node, &ngroup->nodes) { - if (node_group_make_use_node(node, gnode)) { + if (node_group_make_use_node(*node, gnode)) { LISTBASE_FOREACH (bNodeSocket *, sock, &node->inputs) { bool skip = false; LISTBASE_FOREACH (bNodeLink *, link, &ngroup->links) { @@ -987,17 +987,17 @@ static void node_group_make_insert_selected(const bContext *C, bNodeTree *ntree, /* update of the group tree */ ngroup->update |= NTREE_UPDATE | NTREE_UPDATE_LINKS; /* update of the tree containing the group instance node */ - ntree->update |= NTREE_UPDATE_NODES | NTREE_UPDATE_LINKS; + ntree.update |= NTREE_UPDATE_NODES | NTREE_UPDATE_LINKS; } -static bNode *node_group_make_from_selected(const bContext *C, - bNodeTree *ntree, +static bNode *node_group_make_from_selected(const bContext &C, + bNodeTree &ntree, const char *ntype, const char *ntreetype) { - Main *bmain = CTX_data_main(C); + Main *bmain = CTX_data_main(&C); - float min[2], max[2]; + float2 min, max; const int totselect = node_get_selected_minmax(ntree, nullptr, min, max, false); /* don't make empty group */ if (totselect == 0) { @@ -1008,7 +1008,7 @@ static bNode *node_group_make_from_selected(const bContext *C, bNodeTree *ngroup = ntreeAddTree(bmain, "NodeGroup", ntreetype); /* make group node */ - bNode *gnode = nodeAddNode(C, ntree, ntype); + bNode *gnode = nodeAddNode(&C, &ntree, ntype); gnode->id = (ID *)ngroup; gnode->locx = 0.5f * (min[0] + max[0]); @@ -1017,44 +1017,44 @@ static bNode *node_group_make_from_selected(const bContext *C, node_group_make_insert_selected(C, ntree, gnode); /* update of the tree containing the group instance node */ - ntree->update |= NTREE_UPDATE_NODES; + ntree.update |= NTREE_UPDATE_NODES; return gnode; } static int node_group_make_exec(bContext *C, wmOperator *op) { - SpaceNode *snode = CTX_wm_space_node(C); - bNodeTree *ntree = snode->edittree; + SpaceNode &snode = *CTX_wm_space_node(C); + bNodeTree &ntree = *snode.edittree; const char *ntree_idname = group_ntree_idname(C); const char *node_idname = node_group_idname(C); Main *bmain = CTX_data_main(C); ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C)); - if (!node_group_make_test_selected(ntree, nullptr, ntree_idname, op->reports)) { + if (!node_group_make_test_selected(ntree, nullptr, ntree_idname, *op->reports)) { return OPERATOR_CANCELLED; } - bNode *gnode = node_group_make_from_selected(C, ntree, node_idname, ntree_idname); + bNode *gnode = node_group_make_from_selected(*C, ntree, node_idname, ntree_idname); if (gnode) { bNodeTree *ngroup = (bNodeTree *)gnode->id; - nodeSetActive(ntree, gnode); + nodeSetActive(&ntree, gnode); if (ngroup) { - ED_node_tree_push(snode, ngroup, gnode); + ED_node_tree_push(&snode, ngroup, gnode); LISTBASE_FOREACH (bNode *, node, &ngroup->nodes) { - sort_multi_input_socket_links(snode, node, nullptr, nullptr); + sort_multi_input_socket_links(snode, *node, nullptr, nullptr); } ntreeUpdateTree(bmain, ngroup); } } - ntreeUpdateTree(bmain, ntree); + ntreeUpdateTree(bmain, &ntree); - snode_notify(C, snode); - snode_dag_update(C, snode); + snode_notify(*C, snode); + snode_dag_update(*C, snode); /* We broke relations in node tree, need to rebuild them in the graphs. */ DEG_relations_tag_update(bmain); @@ -1099,11 +1099,11 @@ static int node_group_insert_exec(bContext *C, wmOperator *op) } bNodeTree *ngroup = (bNodeTree *)gnode->id; - if (!node_group_make_test_selected(ntree, gnode, ngroup->idname, op->reports)) { + if (!node_group_make_test_selected(*ntree, gnode, ngroup->idname, *op->reports)) { return OPERATOR_CANCELLED; } - node_group_make_insert_selected(C, ntree, gnode); + node_group_make_insert_selected(*C, *ntree, gnode); nodeSetActive(ntree, gnode); ED_node_tree_push(snode, ngroup, gnode); @@ -1111,8 +1111,8 @@ static int node_group_insert_exec(bContext *C, wmOperator *op) ntreeUpdateTree(bmain, ntree); - snode_notify(C, snode); - snode_dag_update(C, snode); + snode_notify(*C, *snode); + snode_dag_update(*C, *snode); return OPERATOR_FINISHED; } diff --git a/source/blender/editors/space_node/node_intern.hh b/source/blender/editors/space_node/node_intern.hh index adfc68d270d..91cf2fb33a5 100644 --- a/source/blender/editors/space_node/node_intern.hh +++ b/source/blender/editors/space_node/node_intern.hh @@ -67,7 +67,7 @@ struct SpaceNode_Runtime { float aspect; /** Mouse position for drawing socket-less links and adding nodes. */ - float cursor[2]; + blender::float2 cursor; /** For auto compositing. */ bool recalc; @@ -83,62 +83,62 @@ struct SpaceNode_Runtime { /* Transform between View2Ds in the tree path. */ blender::float2 space_node_group_offset(const SpaceNode &snode); -float node_socket_calculate_height(const bNodeSocket *socket); +float node_socket_calculate_height(const bNodeSocket &socket); void node_link_calculate_multi_input_position(const float socket_x, const float socket_y, const int index, const int total_inputs, float r[2]); -int node_get_colorid(bNode *node); -void node_draw_extra_info_panel(const SpaceNode *snode, const bNode *node); +int node_get_colorid(bNode &node); +void node_draw_extra_info_panel(const SpaceNode &snode, const bNode &node); int node_get_resize_cursor(NodeResizeDirection directions); -void node_draw_shadow(const SpaceNode *snode, const bNode *node, float radius, float alpha); +void node_draw_shadow(const SpaceNode &snode, const bNode &node, float radius, float alpha); void node_draw_default(const bContext *C, ARegion *region, SpaceNode *snode, bNodeTree *ntree, bNode *node, bNodeInstanceKey key); -void node_draw_sockets(const View2D *v2d, - const bContext *C, - bNodeTree *ntree, - bNode *node, - bool draw_outputs, - bool select_all); +void node_draw_sockets(const View2D &v2d, + const bContext &C, + bNodeTree &ntree, + bNode &node, + const bool draw_outputs, + const bool select_all); void node_update_default(const bContext *C, bNodeTree *ntree, bNode *node); int node_select_area_default(bNode *node, int x, int y); int node_tweak_area_default(bNode *node, int x, int y); -void node_socket_color_get(const bContext *C, - bNodeTree *ntree, - PointerRNA *node_ptr, - bNodeSocket *sock, +void node_socket_color_get(const bContext &C, + const bNodeTree &ntree, + PointerRNA &node_ptr, + const bNodeSocket &sock, float r_color[4]); -void node_update_nodetree(const bContext *C, bNodeTree *ntree); -void node_draw_nodetree(const bContext *C, - ARegion *region, - SpaceNode *snode, - bNodeTree *ntree, +void node_update_nodetree(const bContext &C, bNodeTree &ntree); +void node_draw_nodetree(const bContext &C, + ARegion ®ion, + SpaceNode &snode, + bNodeTree &ntree, bNodeInstanceKey parent_key); -void node_draw_space(const bContext *C, ARegion *region); +void node_draw_space(const bContext &C, ARegion ®ion); -void node_set_cursor(wmWindow *win, SpaceNode *snode, float cursor[2]); +void node_set_cursor(wmWindow &win, SpaceNode &snode, const blender::float2 &cursor); /* DPI scaled coords */ -void node_to_view(const bNode *node, float x, float y, float *rx, float *ry); -void node_to_updated_rect(const bNode *node, rctf *r_rect); -void node_from_view(const bNode *node, float x, float y, float *rx, float *ry); +void node_to_view(const bNode &node, float x, float y, float *rx, float *ry); +void node_to_updated_rect(const bNode &node, rctf &r_rect); +void node_from_view(const bNode &node, float x, float y, float *rx, float *ry); void node_toolbar_register(ARegionType *art); void node_operatortypes(void); void node_keymap(wmKeyConfig *keyconf); -void node_deselect_all(SpaceNode *snode); -void node_socket_select(bNode *node, bNodeSocket *sock); -void node_socket_deselect(bNode *node, bNodeSocket *sock, const bool deselect_node); -void node_deselect_all_input_sockets(SpaceNode *snode, const bool deselect_nodes); -void node_deselect_all_output_sockets(SpaceNode *snode, const bool deselect_nodes); -void node_select_single(bContext *C, bNode *node); +void node_deselect_all(SpaceNode &snode); +void node_socket_select(bNode *node, bNodeSocket &sock); +void node_socket_deselect(bNode *node, bNodeSocket &sock, const bool deselect_node); +void node_deselect_all_input_sockets(SpaceNode &snode, const bool deselect_nodes); +void node_deselect_all_output_sockets(SpaceNode &snode, const bool deselect_nodes); +void node_select_single(bContext &C, bNode &node); void NODE_OT_select(wmOperatorType *ot); void NODE_OT_select_all(wmOperatorType *ot); @@ -151,8 +151,8 @@ void NODE_OT_select_grouped(wmOperatorType *ot); void NODE_OT_select_same_type_step(wmOperatorType *ot); void NODE_OT_find_node(wmOperatorType *ot); -int space_node_view_flag( - bContext *C, SpaceNode *snode, ARegion *region, const int node_flag, const int smooth_viewtx); +bool space_node_view_flag( + bContext &C, SpaceNode &snode, ARegion ®ion, int node_flag, int smooth_viewtx); void NODE_OT_view_all(wmOperatorType *ot); void NODE_OT_view_selected(wmOperatorType *ot); @@ -163,35 +163,35 @@ void NODE_OT_backimage_zoom(wmOperatorType *ot); void NODE_OT_backimage_fit(wmOperatorType *ot); void NODE_OT_backimage_sample(wmOperatorType *ot); -void nodelink_batch_start(SpaceNode *snode); -void nodelink_batch_end(SpaceNode *snode); - -void node_draw_link(const bContext *C, - const View2D *v2d, - const SpaceNode *snode, - const bNodeLink *link); -void node_draw_link_bezier(const bContext *C, - const View2D *v2d, - const SpaceNode *snode, - const bNodeLink *link, +void nodelink_batch_start(SpaceNode &snode); +void nodelink_batch_end(SpaceNode &snode); + +void node_draw_link(const bContext &C, + const View2D &v2d, + const SpaceNode &snode, + const bNodeLink &link); +void node_draw_link_bezier(const bContext &C, + const View2D &v2d, + const SpaceNode &snode, + const bNodeLink &link, int th_col1, int th_col2, int th_col3); bool node_link_bezier_points(const View2D *v2d, const SpaceNode *snode, - const bNodeLink *link, + const bNodeLink &link, float coord_array[][2], const int resol); bool node_link_bezier_handles(const View2D *v2d, const SpaceNode *snode, - const bNodeLink *link, + const bNodeLink &ink, float vec[4][2]); -void draw_nodespace_back_pix(const bContext *C, - ARegion *region, - SpaceNode *snode, +void draw_nodespace_back_pix(const bContext &C, + ARegion ®ion, + SpaceNode &snode, bNodeInstanceKey parent_key); -bNode *node_add_node(const bContext *C, const char *idname, int type, float locx, float locy); +bNode *node_add_node(const bContext &C, const char *idname, int type, float locx, float locy); void NODE_OT_add_reroute(wmOperatorType *ot); void NODE_OT_add_group(wmOperatorType *ot); void NODE_OT_add_object(wmOperatorType *ot); @@ -208,11 +208,11 @@ void NODE_OT_group_ungroup(wmOperatorType *ot); void NODE_OT_group_separate(wmOperatorType *ot); void NODE_OT_group_edit(wmOperatorType *ot); -void sort_multi_input_socket_links(SpaceNode *snode, - bNode *node, +void sort_multi_input_socket_links(SpaceNode &snode, + bNode &node, bNodeLink *drag_link, - float cursor[2]); -bool node_connected_to_output(Main *bmain, bNodeTree *ntree, bNode *node); + const blender::float2 *cursor); +bool node_connected_to_output(Main &bmain, bNodeTree &ntree, bNode &node); void NODE_OT_link(wmOperatorType *ot); void NODE_OT_link_make(wmOperatorType *ot); @@ -229,21 +229,24 @@ void NODE_OT_link_viewer(wmOperatorType *ot); void NODE_OT_insert_offset(wmOperatorType *ot); -void snode_notify(bContext *C, SpaceNode *snode); -void snode_dag_update(bContext *C, SpaceNode *snode); -void snode_set_context(const bContext *C); +void snode_notify(bContext &C, SpaceNode &snode); +void snode_dag_update(bContext &C, SpaceNode &snode); +void snode_set_context(const bContext &C); -void snode_update(SpaceNode *snode, bNode *node); +void snode_update(SpaceNode &snode, bNode *node); bool composite_node_active(bContext *C); bool composite_node_editable(bContext *C); bool node_has_hidden_sockets(bNode *node); void node_set_hidden_sockets(SpaceNode *snode, bNode *node, int set); int node_render_changed_exec(bContext *, wmOperator *); -bool node_find_indicated_socket( - SpaceNode *snode, bNode **nodep, bNodeSocket **sockp, const float cursor[2], int in_out); -float node_link_dim_factor(const View2D *v2d, const bNodeLink *link); -bool node_link_is_hidden_or_dimmed(const View2D *v2d, const bNodeLink *link); +bool node_find_indicated_socket(SpaceNode &snode, + bNode **nodep, + bNodeSocket **sockp, + const blender::float2 &cursor, + eNodeSocketInOut in_out); +float node_link_dim_factor(const View2D &v2d, const bNodeLink &link); +bool node_link_is_hidden_or_dimmed(const View2D &v2d, const bNodeLink &link); void NODE_OT_duplicate(wmOperatorType *ot); void NODE_OT_delete(wmOperatorType *ot); @@ -288,11 +291,11 @@ void NODE_GGT_backdrop_corner_pin(wmGizmoGroupType *gzgt); void NODE_OT_cryptomatte_layer_add(wmOperatorType *ot); void NODE_OT_cryptomatte_layer_remove(wmOperatorType *ot); -void node_geometry_add_attribute_search_button(const bContext *C, - const bNodeTree *node_tree, - const bNode *node, - PointerRNA *socket_ptr, - uiLayout *layout); +void node_geometry_add_attribute_search_button(const bContext &C, + const bNodeTree &node_tree, + const bNode &node, + PointerRNA &socket_ptr, + uiLayout &layout); extern const char *node_context_dir[]; @@ -302,8 +305,8 @@ extern const char *node_context_dir[]; #define NODE_DYS (U.widget_unit / 2) #define NODE_DY U.widget_unit #define NODE_SOCKDY (0.1f * U.widget_unit) -#define NODE_WIDTH(node) (node->width * UI_DPI_FAC) -#define NODE_HEIGHT(node) (node->height * UI_DPI_FAC) +#define NODE_WIDTH(node) (node.width * UI_DPI_FAC) +#define NODE_HEIGHT(node) (node.height * UI_DPI_FAC) #define NODE_MARGIN_X (1.2f * U.widget_unit) #define NODE_SOCKSIZE (0.25f * U.widget_unit) #define NODE_MULTI_INPUT_LINK_GAP (0.25f * U.widget_unit) diff --git a/source/blender/editors/space_node/node_relationships.cc b/source/blender/editors/space_node/node_relationships.cc index fa84ada0af0..fa147f56345 100644 --- a/source/blender/editors/space_node/node_relationships.cc +++ b/source/blender/editors/space_node/node_relationships.cc @@ -63,34 +63,35 @@ #include "node_intern.hh" /* own include */ using namespace blender::nodes::node_tree_ref_types; +using blender::float2; using blender::Vector; /* -------------------------------------------------------------------- */ /** \name Relations Helpers * \{ */ -static bool ntree_has_drivers(bNodeTree *ntree) +static bool ntree_has_drivers(bNodeTree &ntree) { - const AnimData *adt = BKE_animdata_from_id(&ntree->id); + const AnimData *adt = BKE_animdata_from_id(&ntree.id); if (adt == nullptr) { return false; } return !BLI_listbase_is_empty(&adt->drivers); } -static bool ntree_check_nodes_connected_dfs(bNodeTree *ntree, bNode *from, bNode *to) +static bool ntree_check_nodes_connected_dfs(bNodeTree &ntree, bNode &from, bNode &to) { - if (from->flag & NODE_TEST) { + if (from.flag & NODE_TEST) { return false; } - from->flag |= NODE_TEST; - LISTBASE_FOREACH (bNodeLink *, link, &ntree->links) { - if (link->fromnode == from) { - if (link->tonode == to) { + from.flag |= NODE_TEST; + LISTBASE_FOREACH (bNodeLink *, link, &ntree.links) { + if (link->fromnode == &from) { + if (link->tonode == &to) { return true; } - if (ntree_check_nodes_connected_dfs(ntree, link->tonode, to)) { + if (ntree_check_nodes_connected_dfs(ntree, *link->tonode, to)) { return true; } } @@ -98,26 +99,25 @@ static bool ntree_check_nodes_connected_dfs(bNodeTree *ntree, bNode *from, bNode return false; } -static bool ntree_check_nodes_connected(bNodeTree *ntree, bNode *from, bNode *to) +static bool ntree_check_nodes_connected(bNodeTree &ntree, bNode &from, bNode &to) { - if (from == to) { + if (&from == &to) { return true; } - ntreeNodeFlagSet(ntree, NODE_TEST, false); + ntreeNodeFlagSet(&ntree, NODE_TEST, false); return ntree_check_nodes_connected_dfs(ntree, from, to); } -static bool node_group_has_output_dfs(bNode *node) +static bool node_group_has_output_dfs(bNode &node) { - bNodeTree *ntree = (bNodeTree *)node->id; + bNodeTree *ntree = (bNodeTree *)node.id; if (ntree->id.tag & LIB_TAG_DOIT) { return false; } ntree->id.tag |= LIB_TAG_DOIT; - for (bNode *current_node = (bNode *)ntree->nodes.first; current_node != nullptr; - current_node = current_node->next) { + LISTBASE_FOREACH (bNode *, current_node, &ntree->nodes) { if (current_node->type == NODE_GROUP) { - if (current_node->id && node_group_has_output_dfs(current_node)) { + if (current_node->id && node_group_has_output_dfs(*current_node)) { return true; } } @@ -128,18 +128,18 @@ static bool node_group_has_output_dfs(bNode *node) return false; } -static bool node_group_has_output(Main *bmain, bNode *node) +static bool node_group_has_output(Main &bmain, bNode &node) { - BLI_assert(ELEM(node->type, NODE_GROUP, NODE_CUSTOM_GROUP)); - bNodeTree *ntree = (bNodeTree *)node->id; + BLI_assert(ELEM(node.type, NODE_GROUP, NODE_CUSTOM_GROUP)); + bNodeTree *ntree = (bNodeTree *)node.id; if (ntree == nullptr) { return false; } - BKE_main_id_tag_listbase(&bmain->nodetrees, LIB_TAG_DOIT, false); + BKE_main_id_tag_listbase(&bmain.nodetrees, LIB_TAG_DOIT, false); return node_group_has_output_dfs(node); } -bool node_connected_to_output(Main *bmain, bNodeTree *ntree, bNode *node) +bool node_connected_to_output(Main &bmain, bNodeTree &ntree, bNode &node) { /* Special case for drivers: if node tree has any drivers we assume it is * always to be tagged for update when node changes. Otherwise we will be @@ -149,7 +149,7 @@ bool node_connected_to_output(Main *bmain, bNodeTree *ntree, bNode *node) if (ntree_has_drivers(ntree)) { return true; } - LISTBASE_FOREACH (bNode *, current_node, &ntree->nodes) { + LISTBASE_FOREACH (bNode *, current_node, &ntree.nodes) { /* Special case for group nodes -- if modified node connected to a group * with active output inside we consider refresh is needed. * @@ -157,21 +157,21 @@ bool node_connected_to_output(Main *bmain, bNodeTree *ntree, bNode *node) * is connected to and so eventually. */ if (ELEM(current_node->type, NODE_GROUP, NODE_CUSTOM_GROUP)) { - if (current_node->id != nullptr && ntree_has_drivers((bNodeTree *)current_node->id)) { + if (current_node->id != nullptr && ntree_has_drivers((bNodeTree &)current_node->id)) { return true; } - if (ntree_check_nodes_connected(ntree, node, current_node) && - node_group_has_output(bmain, current_node)) { + if (ntree_check_nodes_connected(ntree, node, *current_node) && + node_group_has_output(bmain, *current_node)) { return true; } } if (current_node->flag & NODE_DO_OUTPUT) { - if (ntree_check_nodes_connected(ntree, node, current_node)) { + if (ntree_check_nodes_connected(ntree, node, *current_node)) { return true; } } if (current_node->type == GEO_NODE_VIEWER) { - if (ntree_check_nodes_connected(ntree, node, current_node)) { + if (ntree_check_nodes_connected(ntree, node, *current_node)) { return true; } } @@ -208,46 +208,47 @@ static void clear_picking_highlight(ListBase *links) } } -static bNodeLink *create_drag_link(Main *bmain, SpaceNode *snode, bNode *node, bNodeSocket *sock) +static bNodeLink *create_drag_link(Main &bmain, SpaceNode &snode, bNode &node, bNodeSocket &sock) { - bNodeLink *oplink = (bNodeLink *)MEM_callocN(sizeof(bNodeLink), "drag link op link"); - if (sock->in_out == SOCK_OUT) { - oplink->fromnode = node; - oplink->fromsock = sock; + bNodeLink *oplink = (bNodeLink *)MEM_callocN(sizeof(bNodeLink), __func__); + if (sock.in_out == SOCK_OUT) { + oplink->fromnode = &node; + oplink->fromsock = &sock; } else { - oplink->tonode = node; - oplink->tosock = sock; + oplink->tonode = &node; + oplink->tosock = &sock; } oplink->flag |= NODE_LINK_VALID; oplink->flag &= ~NODE_LINK_TEST; - if (node_connected_to_output(bmain, snode->edittree, node)) { + if (node_connected_to_output(bmain, *snode.edittree, node)) { oplink->flag |= NODE_LINK_TEST; } oplink->flag |= NODE_LINK_DRAGGED; return oplink; } -static void pick_link(const bContext *C, - wmOperator *op, - bNodeLinkDrag *nldrag, - SpaceNode *snode, +static void pick_link(const bContext &C, + wmOperator &op, + bNodeLinkDrag &nldrag, + SpaceNode &snode, bNode *node, - bNodeLink *link_to_pick) + bNodeLink &link_to_pick) { - clear_picking_highlight(&snode->edittree->links); - RNA_boolean_set(op->ptr, "has_link_picked", true); + clear_picking_highlight(&snode.edittree->links); + RNA_boolean_set(op.ptr, "has_link_picked", true); - Main *bmain = CTX_data_main(C); - bNodeLink *link = create_drag_link(bmain, snode, link_to_pick->fromnode, link_to_pick->fromsock); + Main *bmain = CTX_data_main(&C); + bNodeLink *link = create_drag_link( + *bmain, snode, *link_to_pick.fromnode, *link_to_pick.fromsock); - nldrag->links.append(link); - nodeRemLink(snode->edittree, link_to_pick); + nldrag.links.append(link); + nodeRemLink(snode.edittree, &link_to_pick); - BLI_assert(nldrag->last_node_hovered_while_dragging_a_link != nullptr); + BLI_assert(nldrag.last_node_hovered_while_dragging_a_link != nullptr); sort_multi_input_socket_links( - snode, nldrag->last_node_hovered_while_dragging_a_link, nullptr, nullptr); + snode, *nldrag.last_node_hovered_while_dragging_a_link, nullptr, nullptr); /* Send changed event to original link->tonode. */ if (node) { @@ -255,20 +256,20 @@ static void pick_link(const bContext *C, } } -static void pick_input_link_by_link_intersect(const bContext *C, - wmOperator *op, - bNodeLinkDrag *nldrag, - const float *cursor) +static void pick_input_link_by_link_intersect(const bContext &C, + wmOperator &op, + bNodeLinkDrag &nldrag, + const float2 &cursor) { - SpaceNode *snode = CTX_wm_space_node(C); - const ARegion *region = CTX_wm_region(C); + SpaceNode *snode = CTX_wm_space_node(&C); + const ARegion *region = CTX_wm_region(&C); const View2D *v2d = ®ion->v2d; float drag_start[2]; - RNA_float_get_array(op->ptr, "drag_start", drag_start); + RNA_float_get_array(op.ptr, "drag_start", drag_start); bNode *node; bNodeSocket *socket; - node_find_indicated_socket(snode, &node, &socket, drag_start, SOCK_IN); + node_find_indicated_socket(*snode, &node, &socket, drag_start, SOCK_IN); /* Distance to test overlapping of cursor on link. */ const float cursor_link_touch_distance = 12.5f * UI_DPI_FAC; @@ -281,7 +282,7 @@ static void pick_input_link_by_link_intersect(const bContext *C, if (link->tosock == socket) { /* Test if the cursor is near a link. */ float vec[4][2]; - node_link_bezier_handles(v2d, snode, link, vec); + node_link_bezier_handles(v2d, snode, *link, vec); float data[NODE_LINK_RESOL * 2 + 2]; BKE_curve_forward_diff_bezier( @@ -295,7 +296,7 @@ static void pick_input_link_by_link_intersect(const bContext *C, float distance = dist_squared_to_line_segment_v2(cursor, l1, l2); if (distance < cursor_link_touch_distance) { link_to_pick = link; - nldrag->last_picked_multi_input_socket_link = link_to_pick; + nldrag.last_picked_multi_input_socket_link = link_to_pick; } } } @@ -305,7 +306,7 @@ static void pick_input_link_by_link_intersect(const bContext *C, * Not essential for the basic behavior, but can make interaction feel a bit better if * the mouse moves to the right and loses the "selection." */ if (!link_to_pick) { - bNodeLink *last_picked_link = nldrag->last_picked_multi_input_socket_link; + bNodeLink *last_picked_link = nldrag.last_picked_multi_input_socket_link; if (last_picked_link) { link_to_pick = last_picked_link; } @@ -314,10 +315,10 @@ static void pick_input_link_by_link_intersect(const bContext *C, if (link_to_pick) { /* Highlight is set here and cleared in the next iteration or if the operation finishes. */ link_to_pick->flag |= NODE_LINK_TEMP_HIGHLIGHT; - ED_area_tag_redraw(CTX_wm_area(C)); + ED_area_tag_redraw(CTX_wm_area(&C)); - if (!node_find_indicated_socket(snode, &node, &socket, cursor, SOCK_IN)) { - pick_link(C, op, nldrag, snode, node, link_to_pick); + if (!node_find_indicated_socket(*snode, &node, &socket, cursor, SOCK_IN)) { + pick_link(C, op, nldrag, *snode, node, *link_to_pick); } } } @@ -418,14 +419,14 @@ static bNodeSocket *best_socket_input(bNodeTree *ntree, bNode *node, int num, in return nullptr; } -static bool snode_autoconnect_input(SpaceNode *snode, +static bool snode_autoconnect_input(SpaceNode &snode, bNode *node_fr, bNodeSocket *sock_fr, bNode *node_to, bNodeSocket *sock_to, int replace) { - bNodeTree *ntree = snode->edittree; + bNodeTree *ntree = snode.edittree; /* then we can connect */ if (replace) { @@ -437,8 +438,8 @@ static bool snode_autoconnect_input(SpaceNode *snode, } struct LinkAndPosition { - struct bNodeLink *link; - float multi_socket_position[2]; + bNodeLink *link; + float2 multi_socket_position; }; static int compare_link_by_y_position(const void *a, const void *b) @@ -452,12 +453,12 @@ static int compare_link_by_y_position(const void *a, const void *b) return link_a_y > link_b_y ? 1 : -1; } -void sort_multi_input_socket_links(SpaceNode *snode, - bNode *node, +void sort_multi_input_socket_links(SpaceNode &snode, + bNode &node, bNodeLink *drag_link, - float cursor[2]) + const float2 *cursor) { - LISTBASE_FOREACH (bNodeSocket *, socket, &node->inputs) { + LISTBASE_FOREACH (bNodeSocket *, socket, &node.inputs) { if (!(socket->flag & SOCK_MULTI_INPUT)) { continue; } @@ -467,7 +468,7 @@ void sort_multi_input_socket_links(SpaceNode *snode, total_inputs, sizeof(LinkAndPosition *), __func__); int index = 0; - LISTBASE_FOREACH (bNodeLink *, link, &snode->edittree->links) { + LISTBASE_FOREACH (bNodeLink *, link, &snode.edittree->links) { if (link->tosock == socket) { struct LinkAndPosition *link_and_position = (LinkAndPosition *)MEM_callocN( sizeof(struct LinkAndPosition), __func__); @@ -486,7 +487,9 @@ void sort_multi_input_socket_links(SpaceNode *snode, LinkAndPosition *link_and_position = (LinkAndPosition *)MEM_callocN(sizeof(LinkAndPosition), __func__); link_and_position->link = drag_link; - copy_v2_v2(link_and_position->multi_socket_position, cursor); + if (cursor) { + link_and_position->multi_socket_position = *cursor; + } input_links[index] = link_and_position; index++; } @@ -506,12 +509,12 @@ void sort_multi_input_socket_links(SpaceNode *snode, } } -static void snode_autoconnect(Main *bmain, - SpaceNode *snode, +static void snode_autoconnect(Main &bmain, + SpaceNode &snode, const bool allow_multiple, const bool replace) { - bNodeTree *ntree = snode->edittree; + bNodeTree *ntree = snode.edittree; Vector<bNode *> sorted_nodes; LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { @@ -584,7 +587,7 @@ static void snode_autoconnect(Main *bmain, } if (numlinks > 0) { - ntreeUpdateTree(bmain, ntree); + ntreeUpdateTree(&bmain, ntree); } } @@ -639,26 +642,26 @@ static CustomDataType socket_type_to_custom_data_type(const eNodeSocketDatatype /** * Find the socket to link to in a viewer node. */ -static bNodeSocket *node_link_viewer_get_socket(bNodeTree *ntree, - bNode *viewer_node, - bNodeSocket *src_socket) +static bNodeSocket *node_link_viewer_get_socket(bNodeTree &ntree, + bNode &viewer_node, + bNodeSocket &src_socket) { - if (viewer_node->type != GEO_NODE_VIEWER) { + if (viewer_node.type != GEO_NODE_VIEWER) { /* In viewer nodes in the compositor, only the first input should be linked to. */ - return (bNodeSocket *)viewer_node->inputs.first; + return (bNodeSocket *)viewer_node.inputs.first; } /* For the geometry nodes viewer, find the socket with the correct type. */ - LISTBASE_FOREACH (bNodeSocket *, viewer_socket, &viewer_node->inputs) { - if (viewer_socket->type == src_socket->type) { + LISTBASE_FOREACH (bNodeSocket *, viewer_socket, &viewer_node.inputs) { + if (viewer_socket->type == src_socket.type) { if (viewer_socket->type == SOCK_GEOMETRY) { return viewer_socket; } - NodeGeometryViewer *storage = (NodeGeometryViewer *)viewer_node->storage; + NodeGeometryViewer *storage = (NodeGeometryViewer *)viewer_node.storage; const CustomDataType data_type = socket_type_to_custom_data_type( - (eNodeSocketDatatype)src_socket->type); + (eNodeSocketDatatype)src_socket.type); BLI_assert(data_type != CD_AUTO_FROM_NAME); storage->data_type = data_type; - nodeUpdate(ntree, viewer_node); + nodeUpdate(&ntree, &viewer_node); return viewer_socket; } } @@ -791,31 +794,31 @@ static const OutputSocketRef *find_output_socket_to_be_viewed(const NodeRef *act return nullptr; } -static int link_socket_to_viewer(const bContext *C, +static int link_socket_to_viewer(const bContext &C, bNode *viewer_bnode, - bNode *bnode_to_view, - bNodeSocket *bsocket_to_view) + bNode &bnode_to_view, + bNodeSocket &bsocket_to_view) { - SpaceNode *snode = CTX_wm_space_node(C); - bNodeTree *btree = snode->edittree; + SpaceNode &snode = *CTX_wm_space_node(&C); + bNodeTree &btree = *snode.edittree; if (viewer_bnode == nullptr) { /* Create a new viewer node if none exists. */ - const int viewer_type = get_default_viewer_type(C); + const int viewer_type = get_default_viewer_type(&C); viewer_bnode = node_add_node( - C, nullptr, viewer_type, bsocket_to_view->locx + 100, bsocket_to_view->locy); + C, nullptr, viewer_type, bsocket_to_view.locx + 100, bsocket_to_view.locy); if (viewer_bnode == nullptr) { return OPERATOR_CANCELLED; } } - bNodeSocket *viewer_bsocket = node_link_viewer_get_socket(btree, viewer_bnode, bsocket_to_view); + bNodeSocket *viewer_bsocket = node_link_viewer_get_socket(btree, *viewer_bnode, bsocket_to_view); if (viewer_bsocket == nullptr) { return OPERATOR_CANCELLED; } bNodeLink *link_to_change = nullptr; - LISTBASE_FOREACH (bNodeLink *, link, &btree->links) { + LISTBASE_FOREACH (bNodeLink *, link, &btree.links) { if (link->tosock == viewer_bsocket) { link_to_change = link; break; @@ -823,38 +826,34 @@ static int link_socket_to_viewer(const bContext *C, } if (link_to_change == nullptr) { - nodeAddLink(btree, bnode_to_view, bsocket_to_view, viewer_bnode, viewer_bsocket); + nodeAddLink(&btree, &bnode_to_view, &bsocket_to_view, viewer_bnode, viewer_bsocket); } else { - link_to_change->fromnode = bnode_to_view; - link_to_change->fromsock = bsocket_to_view; - btree->update |= NTREE_UPDATE_LINKS; + link_to_change->fromnode = &bnode_to_view; + link_to_change->fromsock = &bsocket_to_view; + btree.update |= NTREE_UPDATE_LINKS; } - remove_links_to_unavailable_viewer_sockets(*btree, *viewer_bnode); + remove_links_to_unavailable_viewer_sockets(btree, *viewer_bnode); - if (btree->type == NTREE_GEOMETRY) { - ED_spreadsheet_context_paths_set_geometry_node(CTX_data_main(C), snode, viewer_bnode); + if (btree.type == NTREE_GEOMETRY) { + ED_spreadsheet_context_paths_set_geometry_node(CTX_data_main(&C), &snode, viewer_bnode); } - ntreeUpdateTree(CTX_data_main(C), btree); + ntreeUpdateTree(CTX_data_main(&C), &btree); snode_update(snode, viewer_bnode); - DEG_id_tag_update(&btree->id, 0); + DEG_id_tag_update(&btree.id, 0); return OPERATOR_FINISHED; } -static int node_link_viewer(const bContext *C, bNode *bnode_to_view) +static int node_link_viewer(const bContext &C, bNode &bnode_to_view) { - if (bnode_to_view == nullptr) { - return OPERATOR_CANCELLED; - } - - SpaceNode *snode = CTX_wm_space_node(C); - bNodeTree *btree = snode->edittree; + SpaceNode &snode = *CTX_wm_space_node(&C); + bNodeTree *btree = snode.edittree; const NodeTreeRef tree{btree}; - const NodeRef &node_to_view = *tree.find_node(*bnode_to_view); + const NodeRef &node_to_view = *tree.find_node(bnode_to_view); const NodeRef *active_viewer_node = get_existing_viewer(tree); const OutputSocketRef *socket_to_view = find_output_socket_to_be_viewed(active_viewer_node, @@ -863,7 +862,7 @@ static int node_link_viewer(const bContext *C, bNode *bnode_to_view) return OPERATOR_FINISHED; } - bNodeSocket *bsocket_to_view = socket_to_view->bsocket(); + bNodeSocket &bsocket_to_view = *socket_to_view->bsocket(); bNode *viewer_bnode = active_viewer_node ? active_viewer_node->bnode() : nullptr; return link_socket_to_viewer(C, viewer_bnode, bnode_to_view, bsocket_to_view); } @@ -872,8 +871,8 @@ static int node_link_viewer(const bContext *C, bNode *bnode_to_view) static int node_active_link_viewer_exec(bContext *C, wmOperator *UNUSED(op)) { - SpaceNode *snode = CTX_wm_space_node(C); - bNode *node = nodeGetActive(snode->edittree); + SpaceNode &snode = *CTX_wm_space_node(C); + bNode *node = nodeGetActive(snode.edittree); if (!node) { return OPERATOR_CANCELLED; @@ -881,11 +880,11 @@ static int node_active_link_viewer_exec(bContext *C, wmOperator *UNUSED(op)) ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C)); - if (blender::ed::nodes::viewer_linking::node_link_viewer(C, node) == OPERATOR_CANCELLED) { + if (blender::ed::nodes::viewer_linking::node_link_viewer(*C, *node) == OPERATOR_CANCELLED) { return OPERATOR_CANCELLED; } - snode_notify(C, snode); + snode_notify(*C, snode); return OPERATOR_FINISHED; } @@ -928,48 +927,49 @@ static void node_link_update_header(bContext *C, bNodeLinkDrag *UNUSED(nldrag)) ED_workspace_status_text(C, header); } -static int node_count_links(const bNodeTree *ntree, const bNodeSocket *socket) +static int node_count_links(const bNodeTree &ntree, const bNodeSocket &socket) { int count = 0; - LISTBASE_FOREACH (bNodeLink *, link, &ntree->links) { - if (ELEM(socket, link->fromsock, link->tosock)) { + LISTBASE_FOREACH (bNodeLink *, link, &ntree.links) { + if (ELEM(&socket, link->fromsock, link->tosock)) { count++; } } return count; } -static void node_remove_extra_links(SpaceNode *snode, bNodeLink *link) +static void node_remove_extra_links(SpaceNode &snode, bNodeLink &link) { - bNodeTree *ntree = snode->edittree; - bNodeSocket *from = link->fromsock, *to = link->tosock; + bNodeTree &ntree = *snode.edittree; + bNodeSocket &from = *link.fromsock; + bNodeSocket &to = *link.tosock; int to_count = node_count_links(ntree, to); int from_count = node_count_links(ntree, from); - int to_link_limit = nodeSocketLinkLimit(to); - int from_link_limit = nodeSocketLinkLimit(from); + int to_link_limit = nodeSocketLinkLimit(&to); + int from_link_limit = nodeSocketLinkLimit(&from); - LISTBASE_FOREACH_MUTABLE (bNodeLink *, tlink, &ntree->links) { - if (tlink == link) { + LISTBASE_FOREACH_MUTABLE (bNodeLink *, tlink, &ntree.links) { + if (tlink == &link) { continue; } - if (tlink && tlink->fromsock == from) { + if (tlink && tlink->fromsock == &from) { if (from_count > from_link_limit) { - nodeRemLink(ntree, tlink); + nodeRemLink(&ntree, tlink); tlink = nullptr; from_count--; } } - if (tlink && tlink->tosock == to) { + if (tlink && tlink->tosock == &to) { if (to_count > to_link_limit) { - nodeRemLink(ntree, tlink); + nodeRemLink(&ntree, tlink); tlink = nullptr; to_count--; } - else if (tlink->fromsock == from) { + else if (tlink->fromsock == &from) { /* Also remove link if it comes from the same output. */ - nodeRemLink(ntree, tlink); + nodeRemLink(&ntree, tlink); tlink = nullptr; to_count--; from_count--; @@ -978,18 +978,18 @@ static void node_remove_extra_links(SpaceNode *snode, bNodeLink *link) } } -static void node_link_exit(bContext *C, wmOperator *op, bool apply_links) +static void node_link_exit(bContext &C, wmOperator &op, const bool apply_links) { - Main *bmain = CTX_data_main(C); - SpaceNode *snode = CTX_wm_space_node(C); - bNodeTree *ntree = snode->edittree; - bNodeLinkDrag *nldrag = (bNodeLinkDrag *)op->customdata; + Main *bmain = CTX_data_main(&C); + SpaceNode &snode = *CTX_wm_space_node(&C); + bNodeTree &ntree = *snode.edittree; + bNodeLinkDrag *nldrag = (bNodeLinkDrag *)op.customdata; bool do_tag_update = false; /* View will be reset if no links connect. */ bool reset_view = true; /* avoid updates while applying links */ - ntree->is_updating = true; + ntree.is_updating = true; for (bNodeLink *link : nldrag->links) { /* See note below, but basically TEST flag means that the link * was connected to output (or to a node which affects the @@ -1004,52 +1004,52 @@ static void node_link_exit(bContext *C, wmOperator *op, bool apply_links) * let nodes perform special link insertion handling */ if (link->fromnode->typeinfo->insert_link) { - link->fromnode->typeinfo->insert_link(ntree, link->fromnode, link); + link->fromnode->typeinfo->insert_link(&ntree, link->fromnode, link); } if (link->tonode->typeinfo->insert_link) { - link->tonode->typeinfo->insert_link(ntree, link->tonode, link); + link->tonode->typeinfo->insert_link(&ntree, link->tonode, link); } /* add link to the node tree */ - BLI_addtail(&ntree->links, link); + BLI_addtail(&ntree.links, link); - ntree->update |= NTREE_UPDATE_LINKS; + ntree.update |= NTREE_UPDATE_LINKS; /* tag tonode for update */ link->tonode->update |= NODE_UPDATE; /* we might need to remove a link */ - node_remove_extra_links(snode, link); + node_remove_extra_links(snode, *link); if (link->tonode) { - do_tag_update |= (do_tag_update || node_connected_to_output(bmain, ntree, link->tonode)); + do_tag_update |= (do_tag_update || node_connected_to_output(*bmain, ntree, *link->tonode)); } reset_view = false; } else { - nodeRemLink(ntree, link); + nodeRemLink(&ntree, link); } } - ntree->is_updating = false; + ntree.is_updating = false; - ntreeUpdateTree(bmain, ntree); + ntreeUpdateTree(bmain, &ntree); snode_notify(C, snode); if (do_tag_update) { snode_dag_update(C, snode); } if (reset_view) { - UI_view2d_edge_pan_cancel(C, &nldrag->pan_data); + UI_view2d_edge_pan_cancel(&C, &nldrag->pan_data); } - snode->runtime->linkdrag.reset(); + snode.runtime->linkdrag.reset(); } -static void node_link_find_socket(bContext *C, wmOperator *op, float cursor[2]) +static void node_link_find_socket(bContext &C, wmOperator &op, const float2 &cursor) { - SpaceNode *snode = CTX_wm_space_node(C); - bNodeLinkDrag *nldrag = (bNodeLinkDrag *)op->customdata; + SpaceNode &snode = *CTX_wm_space_node(&C); + bNodeLinkDrag *nldrag = (bNodeLinkDrag *)op.customdata; if (nldrag->in_out == SOCK_OUT) { bNode *tnode; @@ -1063,7 +1063,7 @@ static void node_link_find_socket(bContext *C, wmOperator *op, float cursor[2]) /* Skip if tsock is already linked with this output. */ bNodeLink *existing_link_connected_to_fromsock = nullptr; - LISTBASE_FOREACH (bNodeLink *, existing_link, &snode->edittree->links) { + LISTBASE_FOREACH (bNodeLink *, existing_link, &snode.edittree->links) { if (existing_link->fromsock == link->fromsock && existing_link->tosock == tsock) { existing_link_connected_to_fromsock = existing_link; break; @@ -1080,7 +1080,7 @@ static void node_link_find_socket(bContext *C, wmOperator *op, float cursor[2]) continue; } if (link->tosock && link->tosock->flag & SOCK_MULTI_INPUT) { - sort_multi_input_socket_links(snode, tnode, link, cursor); + sort_multi_input_socket_links(snode, *tnode, link, &cursor); } } } @@ -1088,7 +1088,7 @@ static void node_link_find_socket(bContext *C, wmOperator *op, float cursor[2]) for (bNodeLink *link : nldrag->links) { if (nldrag->last_node_hovered_while_dragging_a_link) { sort_multi_input_socket_links( - snode, nldrag->last_node_hovered_while_dragging_a_link, nullptr, cursor); + snode, *nldrag->last_node_hovered_while_dragging_a_link, nullptr, &cursor); } link->tonode = nullptr; link->tosock = nullptr; @@ -1129,19 +1129,19 @@ static int node_link_modal(bContext *C, wmOperator *op, const wmEvent *event) { bNodeLinkDrag *nldrag = (bNodeLinkDrag *)op->customdata; ARegion *region = CTX_wm_region(C); - float cursor[2]; UI_view2d_edge_pan_apply_event(C, &nldrag->pan_data, event); - UI_view2d_region_to_view(®ion->v2d, event->mval[0], event->mval[1], &cursor[0], &cursor[1]); + float2 cursor; + UI_view2d_region_to_view(®ion->v2d, event->mval[0], event->mval[1], &cursor.x, &cursor.y); switch (event->type) { case MOUSEMOVE: if (nldrag->from_multi_input_socket && !RNA_boolean_get(op->ptr, "has_link_picked")) { - pick_input_link_by_link_intersect(C, op, nldrag, cursor); + pick_input_link_by_link_intersect(*C, *op, *nldrag, cursor); } else { - node_link_find_socket(C, op, cursor); + node_link_find_socket(*C, *op, cursor); node_link_update_header(C, nldrag); ED_region_tag_redraw(region); @@ -1152,12 +1152,12 @@ static int node_link_modal(bContext *C, wmOperator *op, const wmEvent *event) case RIGHTMOUSE: case MIDDLEMOUSE: { if (event->val == KM_RELEASE) { - node_link_exit(C, op, true); + node_link_exit(*C, *op, true); ED_workspace_status_text(C, nullptr); ED_region_tag_redraw(region); - SpaceNode *snode = CTX_wm_space_node(C); - clear_picking_highlight(&snode->edittree->links); + SpaceNode &snode = *CTX_wm_space_node(C); + clear_picking_highlight(&snode.edittree->links); return OPERATOR_FINISHED; } break; @@ -1167,10 +1167,10 @@ static int node_link_modal(bContext *C, wmOperator *op, const wmEvent *event) return OPERATOR_RUNNING_MODAL; } -static std::unique_ptr<bNodeLinkDrag> node_link_init(Main *bmain, - SpaceNode *snode, - float cursor[2], - bool detach) +static std::unique_ptr<bNodeLinkDrag> node_link_init(Main &bmain, + SpaceNode &snode, + float2 cursor, + const bool detach) { /* output indicated? */ bNode *node; @@ -1178,13 +1178,13 @@ static std::unique_ptr<bNodeLinkDrag> node_link_init(Main *bmain, if (node_find_indicated_socket(snode, &node, &sock, cursor, SOCK_OUT)) { std::unique_ptr<bNodeLinkDrag> nldrag = std::make_unique<bNodeLinkDrag>(); - const int num_links = nodeCountSocketLinks(snode->edittree, sock); + const int num_links = nodeCountSocketLinks(snode.edittree, sock); int link_limit = nodeSocketLinkLimit(sock); if (num_links > 0 && (num_links >= link_limit || detach)) { /* dragged links are fixed on input side */ nldrag->in_out = SOCK_IN; /* detach current links and store them in the operator data */ - LISTBASE_FOREACH_MUTABLE (bNodeLink *, link, &snode->edittree->links) { + LISTBASE_FOREACH_MUTABLE (bNodeLink *, link, &snode.edittree->links) { if (link->fromsock == sock) { bNodeLink *oplink = (bNodeLink *)MEM_callocN(sizeof(bNodeLink), "drag link op link"); *oplink = *link; @@ -1199,12 +1199,12 @@ static std::unique_ptr<bNodeLinkDrag> node_link_init(Main *bmain, * using TEST flag. */ oplink->flag &= ~NODE_LINK_TEST; - if (node_connected_to_output(bmain, snode->edittree, link->tonode)) { + if (node_connected_to_output(bmain, *snode.edittree, *link->tonode)) { oplink->flag |= NODE_LINK_TEST; } nldrag->links.append(oplink); - nodeRemLink(snode->edittree, link); + nodeRemLink(snode.edittree, link); } } } @@ -1212,7 +1212,7 @@ static std::unique_ptr<bNodeLinkDrag> node_link_init(Main *bmain, /* dragged links are fixed on output side */ nldrag->in_out = SOCK_OUT; /* create a new link */ - nldrag->links.append(create_drag_link(bmain, snode, node, sock)); + nldrag->links.append(create_drag_link(bmain, snode, *node, *sock)); } return nldrag; } @@ -1222,13 +1222,13 @@ static std::unique_ptr<bNodeLinkDrag> node_link_init(Main *bmain, std::unique_ptr<bNodeLinkDrag> nldrag = std::make_unique<bNodeLinkDrag>(); nldrag->last_node_hovered_while_dragging_a_link = node; - const int num_links = nodeCountSocketLinks(snode->edittree, sock); + const int num_links = nodeCountSocketLinks(snode.edittree, sock); if (num_links > 0) { /* dragged links are fixed on output side */ nldrag->in_out = SOCK_OUT; /* detach current links and store them in the operator data */ bNodeLink *link_to_pick; - LISTBASE_FOREACH_MUTABLE (bNodeLink *, link, &snode->edittree->links) { + LISTBASE_FOREACH_MUTABLE (bNodeLink *, link, &snode.edittree->links) { if (link->tosock == sock) { if (sock->flag & SOCK_MULTI_INPUT) { nldrag->from_multi_input_socket = true; @@ -1244,12 +1244,12 @@ static std::unique_ptr<bNodeLinkDrag> node_link_init(Main *bmain, oplink->flag |= NODE_LINK_VALID; oplink->flag |= NODE_LINK_DRAGGED; oplink->flag &= ~NODE_LINK_TEST; - if (node_connected_to_output(bmain, snode->edittree, link_to_pick->tonode)) { + if (node_connected_to_output(bmain, *snode.edittree, *link_to_pick->tonode)) { oplink->flag |= NODE_LINK_TEST; } nldrag->links.append(oplink); - nodeRemLink(snode->edittree, link_to_pick); + nodeRemLink(snode.edittree, link_to_pick); /* send changed event to original link->tonode */ if (node) { @@ -1261,7 +1261,7 @@ static std::unique_ptr<bNodeLinkDrag> node_link_init(Main *bmain, /* dragged links are fixed on input side */ nldrag->in_out = SOCK_IN; /* create a new link */ - nldrag->links.append(create_drag_link(bmain, snode, node, sock)); + nldrag->links.append(create_drag_link(bmain, snode, *node, *sock)); } return nldrag; } @@ -1271,26 +1271,26 @@ static std::unique_ptr<bNodeLinkDrag> node_link_init(Main *bmain, static int node_link_invoke(bContext *C, wmOperator *op, const wmEvent *event) { - Main *bmain = CTX_data_main(C); - SpaceNode *snode = CTX_wm_space_node(C); - ARegion *region = CTX_wm_region(C); + Main &bmain = *CTX_data_main(C); + SpaceNode &snode = *CTX_wm_space_node(C); + ARegion ®ion = *CTX_wm_region(C); bool detach = RNA_boolean_get(op->ptr, "detach"); - float cursor[2]; - UI_view2d_region_to_view(®ion->v2d, event->mval[0], event->mval[1], &cursor[0], &cursor[1]); + float2 cursor; + UI_view2d_region_to_view(®ion.v2d, event->mval[0], event->mval[1], &cursor[0], &cursor[1]); RNA_float_set_array(op->ptr, "drag_start", cursor); RNA_boolean_set(op->ptr, "has_link_picked", false); - ED_preview_kill_jobs(CTX_wm_manager(C), bmain); + ED_preview_kill_jobs(CTX_wm_manager(C), &bmain); std::unique_ptr<bNodeLinkDrag> nldrag = node_link_init(bmain, snode, cursor, detach); if (nldrag) { UI_view2d_edge_pan_operator_init(C, &nldrag->pan_data, op); - snode->runtime->linkdrag = std::move(nldrag); - op->customdata = snode->runtime->linkdrag.get(); + snode.runtime->linkdrag = std::move(nldrag); + op->customdata = snode.runtime->linkdrag.get(); /* add modal handler */ WM_event_add_modal_handler(C, op); @@ -1371,11 +1371,11 @@ void NODE_OT_link(wmOperatorType *ot) /* makes a link between selected output and input sockets */ static int node_make_link_exec(bContext *C, wmOperator *op) { - Main *bmain = CTX_data_main(C); - SpaceNode *snode = CTX_wm_space_node(C); + Main &bmain = *CTX_data_main(C); + SpaceNode &snode = *CTX_wm_space_node(C); const bool replace = RNA_boolean_get(op->ptr, "replace"); - ED_preview_kill_jobs(CTX_wm_manager(C), bmain); + ED_preview_kill_jobs(CTX_wm_manager(C), &bmain); snode_autoconnect(bmain, snode, true, replace); @@ -1383,9 +1383,9 @@ static int node_make_link_exec(bContext *C, wmOperator *op) node_deselect_all_input_sockets(snode, false); node_deselect_all_output_sockets(snode, false); - ntreeUpdateTree(CTX_data_main(C), snode->edittree); - snode_notify(C, snode); - snode_dag_update(C, snode); + ntreeUpdateTree(CTX_data_main(C), snode.edittree); + snode_notify(*C, snode); + snode_dag_update(*C, snode); return OPERATOR_FINISHED; } @@ -1415,7 +1415,7 @@ void NODE_OT_link_make(wmOperatorType *ot) /** \name Node Link Intersect * \{ */ -static bool node_links_intersect(bNodeLink *link, const float mcoords[][2], int tot) +static bool node_links_intersect(bNodeLink &link, const float mcoords[][2], int tot) { float coord_array[NODE_LINK_RESOL + 1][2]; @@ -1439,9 +1439,9 @@ static bool node_links_intersect(bNodeLink *link, const float mcoords[][2], int static int cut_links_exec(bContext *C, wmOperator *op) { - Main *bmain = CTX_data_main(C); - SpaceNode *snode = CTX_wm_space_node(C); - ARegion *region = CTX_wm_region(C); + Main &bmain = *CTX_data_main(C); + SpaceNode &snode = *CTX_wm_space_node(C); + ARegion ®ion = *CTX_wm_region(C); bool do_tag_update = false; int i = 0; @@ -1451,7 +1451,7 @@ static int cut_links_exec(bContext *C, wmOperator *op) RNA_float_get_array(&itemptr, "loc", loc); UI_view2d_region_to_view( - ®ion->v2d, (int)loc[0], (int)loc[1], &mcoords[i][0], &mcoords[i][1]); + ®ion.v2d, (int)loc[0], (int)loc[1], &mcoords[i][0], &mcoords[i][1]); i++; if (i >= 256) { break; @@ -1462,36 +1462,36 @@ static int cut_links_exec(bContext *C, wmOperator *op) if (i > 1) { bool found = false; - ED_preview_kill_jobs(CTX_wm_manager(C), bmain); + ED_preview_kill_jobs(CTX_wm_manager(C), &bmain); - LISTBASE_FOREACH_MUTABLE (bNodeLink *, link, &snode->edittree->links) { - if (node_link_is_hidden_or_dimmed(®ion->v2d, link)) { + LISTBASE_FOREACH_MUTABLE (bNodeLink *, link, &snode.edittree->links) { + if (node_link_is_hidden_or_dimmed(region.v2d, *link)) { continue; } - if (node_links_intersect(link, mcoords, i)) { + if (node_links_intersect(*link, mcoords, i)) { if (found == false) { /* TODO(sergey): Why did we kill jobs twice? */ - ED_preview_kill_jobs(CTX_wm_manager(C), bmain); + ED_preview_kill_jobs(CTX_wm_manager(C), &bmain); found = true; } do_tag_update |= (do_tag_update || - node_connected_to_output(bmain, snode->edittree, link->tonode)); + node_connected_to_output(bmain, *snode.edittree, *link->tonode)); snode_update(snode, link->tonode); bNode *to_node = link->tonode; - nodeRemLink(snode->edittree, link); - sort_multi_input_socket_links(snode, to_node, nullptr, nullptr); + nodeRemLink(snode.edittree, link); + sort_multi_input_socket_links(snode, *to_node, nullptr, nullptr); } } if (found) { - ntreeUpdateTree(CTX_data_main(C), snode->edittree); - snode_notify(C, snode); + ntreeUpdateTree(CTX_data_main(C), snode.edittree); + snode_notify(*C, snode); if (do_tag_update) { - snode_dag_update(C, snode); + snode_dag_update(*C, snode); } return OPERATOR_FINISHED; @@ -1536,9 +1536,9 @@ void NODE_OT_links_cut(wmOperatorType *ot) static int mute_links_exec(bContext *C, wmOperator *op) { - Main *bmain = CTX_data_main(C); - SpaceNode *snode = CTX_wm_space_node(C); - ARegion *region = CTX_wm_region(C); + Main &bmain = *CTX_data_main(C); + SpaceNode &snode = *CTX_wm_space_node(C); + ARegion ®ion = *CTX_wm_region(C); bool do_tag_update = false; int i = 0; @@ -1548,7 +1548,7 @@ static int mute_links_exec(bContext *C, wmOperator *op) RNA_float_get_array(&itemptr, "loc", loc); UI_view2d_region_to_view( - ®ion->v2d, (int)loc[0], (int)loc[1], &mcoords[i][0], &mcoords[i][1]); + ®ion.v2d, (int)loc[0], (int)loc[1], &mcoords[i][0], &mcoords[i][1]); i++; if (i >= 256) { break; @@ -1557,16 +1557,16 @@ static int mute_links_exec(bContext *C, wmOperator *op) RNA_END; if (i > 1) { - ED_preview_kill_jobs(CTX_wm_manager(C), bmain); + ED_preview_kill_jobs(CTX_wm_manager(C), &bmain); /* Count intersected links and clear test flag. */ int tot = 0; - LISTBASE_FOREACH (bNodeLink *, link, &snode->edittree->links) { - if (node_link_is_hidden_or_dimmed(®ion->v2d, link)) { + LISTBASE_FOREACH (bNodeLink *, link, &snode.edittree->links) { + if (node_link_is_hidden_or_dimmed(region.v2d, *link)) { continue; } link->flag &= ~NODE_LINK_TEST; - if (node_links_intersect(link, mcoords, i)) { + if (node_links_intersect(*link, mcoords, i)) { tot++; } } @@ -1575,32 +1575,32 @@ static int mute_links_exec(bContext *C, wmOperator *op) } /* Mute links. */ - LISTBASE_FOREACH (bNodeLink *, link, &snode->edittree->links) { - if (node_link_is_hidden_or_dimmed(®ion->v2d, link) || (link->flag & NODE_LINK_TEST)) { + LISTBASE_FOREACH (bNodeLink *, link, &snode.edittree->links) { + if (node_link_is_hidden_or_dimmed(region.v2d, *link) || (link->flag & NODE_LINK_TEST)) { continue; } - if (node_links_intersect(link, mcoords, i)) { + if (node_links_intersect(*link, mcoords, i)) { do_tag_update |= (do_tag_update || - node_connected_to_output(bmain, snode->edittree, link->tonode)); + node_connected_to_output(bmain, *snode.edittree, *link->tonode)); snode_update(snode, link->tonode); - nodeMuteLinkToggle(snode->edittree, link); + nodeMuteLinkToggle(snode.edittree, link); } } /* Clear remaining test flags. */ - LISTBASE_FOREACH (bNodeLink *, link, &snode->edittree->links) { - if (node_link_is_hidden_or_dimmed(®ion->v2d, link)) { + LISTBASE_FOREACH (bNodeLink *, link, &snode.edittree->links) { + if (node_link_is_hidden_or_dimmed(region.v2d, *link)) { continue; } link->flag &= ~NODE_LINK_TEST; } - ntreeUpdateTree(CTX_data_main(C), snode->edittree); - snode_notify(C, snode); + ntreeUpdateTree(CTX_data_main(C), snode.edittree); + snode_notify(*C, snode); if (do_tag_update) { - snode_dag_update(C, snode); + snode_dag_update(*C, snode); } return OPERATOR_FINISHED; @@ -1642,21 +1642,21 @@ void NODE_OT_links_mute(wmOperatorType *ot) static int detach_links_exec(bContext *C, wmOperator *UNUSED(op)) { - SpaceNode *snode = CTX_wm_space_node(C); - bNodeTree *ntree = snode->edittree; + SpaceNode &snode = *CTX_wm_space_node(C); + bNodeTree &ntree = *snode.edittree; ED_preview_kill_jobs(CTX_wm_manager(C), CTX_data_main(C)); - LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { + LISTBASE_FOREACH (bNode *, node, &ntree.nodes) { if (node->flag & SELECT) { - nodeInternalRelink(ntree, node); + nodeInternalRelink(&ntree, node); } } - ntreeUpdateTree(CTX_data_main(C), ntree); + ntreeUpdateTree(CTX_data_main(C), &ntree); - snode_notify(C, snode); - snode_dag_update(C, snode); + snode_notify(*C, snode); + snode_dag_update(*C, snode); return OPERATOR_FINISHED; } @@ -1763,12 +1763,12 @@ static void node_join_attach_recursive(bNode *node, bNode *frame) static int node_join_exec(bContext *C, wmOperator *UNUSED(op)) { - SpaceNode *snode = CTX_wm_space_node(C); - bNodeTree *ntree = snode->edittree; + SpaceNode &snode = *CTX_wm_space_node(C); + bNodeTree &ntree = *snode.edittree; /* XXX save selection: node_add_node call below sets the new frame as single * active+selected node */ - LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { + LISTBASE_FOREACH (bNode *, node, &ntree.nodes) { if (node->flag & NODE_SELECT) { node->flag |= NODE_TEST; } @@ -1777,27 +1777,27 @@ static int node_join_exec(bContext *C, wmOperator *UNUSED(op)) } } - bNode *frame = node_add_node(C, nullptr, NODE_FRAME, 0.0f, 0.0f); + bNode *frame = node_add_node(*C, nullptr, NODE_FRAME, 0.0f, 0.0f); /* reset tags */ - LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { + LISTBASE_FOREACH (bNode *, node, &ntree.nodes) { node->done = 0; } - LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { + LISTBASE_FOREACH (bNode *, node, &ntree.nodes) { if (!(node->done & NODE_JOIN_DONE)) { node_join_attach_recursive(node, frame); } } /* restore selection */ - LISTBASE_FOREACH (bNode *, node, &ntree->nodes) { + LISTBASE_FOREACH (bNode *, node, &ntree.nodes) { if (node->flag & NODE_TEST) { node->flag |= NODE_SELECT; } } - ED_node_sort(ntree); + ED_node_sort(&ntree); WM_event_add_notifier(C, NC_NODE | ND_DISPLAY, nullptr); return OPERATOR_FINISHED; @@ -2031,7 +2031,7 @@ static bool ed_node_link_conditions(ScrArea *area, /* test node for links */ LISTBASE_FOREACH (bNodeLink *, link, &snode->edittree->links) { - if (node_link_is_hidden_or_dimmed(®ion->v2d, link)) { + if (node_link_is_hidden_or_dimmed(region->v2d, *link)) { continue; } @@ -2070,11 +2070,11 @@ void ED_node_link_intersect_test(ScrArea *area, int test) LISTBASE_FOREACH (bNodeLink *, link, &snode->edittree->links) { float coord_array[NODE_LINK_RESOL + 1][2]; - if (node_link_is_hidden_or_dimmed(®ion->v2d, link)) { + if (node_link_is_hidden_or_dimmed(region->v2d, *link)) { continue; } - if (node_link_bezier_points(nullptr, nullptr, link, coord_array, NODE_LINK_RESOL)) { + if (node_link_bezier_points(nullptr, nullptr, *link, coord_array, NODE_LINK_RESOL)) { float dist = FLT_MAX; /* loop over link coords to find shortest dist to @@ -2210,19 +2210,19 @@ static bool node_parents_offset_flag_enable_cb(bNode *parent, void *UNUSED(userd return true; } -static void node_offset_apply(bNode *node, const float offset_x) +static void node_offset_apply(bNode &node, const float offset_x) { /* NODE_TEST is used to flag nodes that shouldn't be offset (again) */ - if ((node->flag & NODE_TEST) == 0) { - node->anim_init_locx = node->locx; - node->anim_ofsx = (offset_x / UI_DPI_FAC); - node->flag |= NODE_TEST; + if ((node.flag & NODE_TEST) == 0) { + node.anim_init_locx = node.locx; + node.anim_ofsx = (offset_x / UI_DPI_FAC); + node.flag |= NODE_TEST; } } static void node_parent_offset_apply(NodeInsertOfsData *data, bNode *parent, const float offset_x) { - node_offset_apply(parent, offset_x); + node_offset_apply(*parent, offset_x); /* Flag all children as offset to prevent them from being offset * separately (they've already moved with the parent). */ @@ -2249,10 +2249,10 @@ static bool node_link_insert_offset_frame_chain_cb(bNode *fromnode, bNode *ofs_node = reversed ? fromnode : tonode; if (ofs_node->parent && ofs_node->parent != data->insert_parent) { - node_offset_apply(ofs_node->parent, data->offset_x); + node_offset_apply(*ofs_node->parent, data->offset_x); } else { - node_offset_apply(ofs_node, data->offset_x); + node_offset_apply(*ofs_node, data->offset_x); } return true; @@ -2291,7 +2291,7 @@ static bool node_link_insert_offset_chain_cb(bNode *fromnode, node_link_insert_offset_frame_chains(data->ntree, ofs_node->parent, data, reversed); } else { - node_offset_apply(ofs_node, data->offset_x); + node_offset_apply(*ofs_node, data->offset_x); } if (nodeIsChildOf(data->insert_parent, ofs_node) == false) { @@ -2300,10 +2300,10 @@ static bool node_link_insert_offset_chain_cb(bNode *fromnode, } else if (ofs_node->parent) { bNode *node = nodeFindRootParent(ofs_node); - node_offset_apply(node, data->offset_x); + node_offset_apply(*node, data->offset_x); } else { - node_offset_apply(ofs_node, data->offset_x); + node_offset_apply(*ofs_node, data->offset_x); } return true; @@ -2315,9 +2315,9 @@ static void node_link_insert_offset_ntree(NodeInsertOfsData *iofsd, const bool right_alignment) { bNodeTree *ntree = iofsd->ntree; - bNode *insert = iofsd->insert; + bNode &insert = *iofsd->insert; bNode *prev = iofsd->prev, *next = iofsd->next; - bNode *init_parent = insert->parent; /* store old insert->parent for restoring later */ + bNode *init_parent = insert.parent; /* store old insert.parent for restoring later */ const float min_margin = U.node_margin * UI_DPI_FAC; const float width = NODE_WIDTH(insert); @@ -2328,20 +2328,20 @@ static void node_link_insert_offset_ntree(NodeInsertOfsData *iofsd, /* NODE_TEST will be used later, so disable for all nodes */ ntreeNodeFlagSet(ntree, NODE_TEST, false); - /* `insert->totr` isn't updated yet, + /* `insert.totr` isn't updated yet, * so `totr_insert` is used to get the correct world-space coords. */ rctf totr_insert; - node_to_updated_rect(insert, &totr_insert); + node_to_updated_rect(insert, totr_insert); /* frame attachment wasn't handled yet * so we search the frame that the node will be attached to later */ - insert->parent = node_find_frame_to_attach(region, ntree, mouse_xy); + insert.parent = node_find_frame_to_attach(region, ntree, mouse_xy); /* this makes sure nodes are also correctly offset when inserting a node on top of a frame * without actually making it a part of the frame (because mouse isn't intersecting it) * - logic here is similar to node_find_frame_to_attach */ - if (!insert->parent || - (prev->parent && (prev->parent == next->parent) && (prev->parent != insert->parent))) { + if (!insert.parent || + (prev->parent && (prev->parent == next->parent) && (prev->parent != insert.parent))) { bNode *frame; rctf totr_frame; @@ -2353,15 +2353,15 @@ static void node_link_insert_offset_ntree(NodeInsertOfsData *iofsd, } /* for some reason frame y coords aren't correct yet */ - node_to_updated_rect(frame, &totr_frame); + node_to_updated_rect(*frame, totr_frame); if (BLI_rctf_isect_x(&totr_frame, totr_insert.xmin) && BLI_rctf_isect_x(&totr_frame, totr_insert.xmax)) { if (BLI_rctf_isect_y(&totr_frame, totr_insert.ymin) || BLI_rctf_isect_y(&totr_frame, totr_insert.ymax)) { - /* frame isn't insert->parent actually, but this is needed to make offsetting + /* frame isn't insert.parent actually, but this is needed to make offsetting * nodes work correctly for above checked cases (it is restored later) */ - insert->parent = frame; + insert.parent = frame; break; } } @@ -2391,12 +2391,12 @@ static void node_link_insert_offset_ntree(NodeInsertOfsData *iofsd, const float addval = (min_margin - dist) * (right_alignment ? 1.0f : -1.0f); if (needs_alignment) { bNode *offs_node = right_alignment ? next : prev; - if (!offs_node->parent || offs_node->parent == insert->parent || - nodeIsChildOf(offs_node->parent, insert)) { - node_offset_apply(offs_node, addval); + if (!offs_node->parent || offs_node->parent == insert.parent || + nodeIsChildOf(offs_node->parent, &insert)) { + node_offset_apply(*offs_node, addval); } - else if (!insert->parent && offs_node->parent) { - node_offset_apply(nodeFindRootParent(offs_node), addval); + else if (!insert.parent && offs_node->parent) { + node_offset_apply(*nodeFindRootParent(offs_node), addval); } margin = addval; } @@ -2408,11 +2408,11 @@ static void node_link_insert_offset_ntree(NodeInsertOfsData *iofsd, } if (needs_alignment) { - iofsd->insert_parent = insert->parent; + iofsd->insert_parent = insert.parent; iofsd->offset_x = margin; /* flag all parents of insert as offset to prevent them from being offset */ - nodeParentsIter(insert, node_parents_offset_flag_enable_cb, nullptr); + nodeParentsIter(&insert, node_parents_offset_flag_enable_cb, nullptr); /* iterate over entire chain and apply offsets */ nodeChainIter(ntree, right_alignment ? next : prev, @@ -2421,7 +2421,7 @@ static void node_link_insert_offset_ntree(NodeInsertOfsData *iofsd, !right_alignment); } - insert->parent = init_parent; + insert.parent = init_parent; } /** @@ -2553,7 +2553,7 @@ void ED_node_link_insert(Main *bmain, ScrArea *area) link->tonode = select; link->tosock = best_input; - node_remove_extra_links(snode, link); + node_remove_extra_links(*snode, *link); link->flag &= ~NODE_LINKFLAG_HILITE; bNodeLink *new_link = nodeAddLink(snode->edittree, select, best_output, node, sockto); @@ -2576,7 +2576,7 @@ void ED_node_link_insert(Main *bmain, ScrArea *area) } ntreeUpdateTree(bmain, snode->edittree); /* needed for pointers */ - snode_update(snode, select); + snode_update(*snode, select); ED_node_tag_update_id((ID *)snode->edittree); ED_node_tag_update_id(snode->id); } diff --git a/source/blender/editors/space_node/node_select.cc b/source/blender/editors/space_node/node_select.cc index 3c7b404547b..6a566fa45d5 100644 --- a/source/blender/editors/space_node/node_select.cc +++ b/source/blender/editors/space_node/node_select.cc @@ -63,6 +63,8 @@ #include "node_intern.hh" /* own include */ +using blender::float2; + /** * Function to detect if there is a visible view3d that uses workbench in texture mode. * This function is for fixing T76970 for Blender 2.83. The actual fix should add a mechanism in @@ -98,11 +100,11 @@ static bool has_workbench_in_texture_color(const wmWindowManager *wm, /** \name Public Node Selection API * \{ */ -static bNode *node_under_mouse_select(bNodeTree *ntree, int mx, int my) +static bNode *node_under_mouse_select(bNodeTree &ntree, int mx, int my) { bNode *node; - for (node = (bNode *)ntree->nodes.last; node; node = node->prev) { + for (node = (bNode *)ntree.nodes.last; node; node = node->prev) { if (node->typeinfo->select_area_func) { if (node->typeinfo->select_area_func(node, mx, my)) { return node; @@ -112,13 +114,13 @@ static bNode *node_under_mouse_select(bNodeTree *ntree, int mx, int my) return nullptr; } -static bNode *node_under_mouse_tweak(bNodeTree *ntree, int mx, int my) +static bNode *node_under_mouse_tweak(bNodeTree &ntree, const float2 &mouse) { bNode *node; - for (node = (bNode *)ntree->nodes.last; node; node = node->prev) { + for (node = (bNode *)ntree.nodes.last; node; node = node->prev) { if (node->typeinfo->tweak_area_func) { - if (node->typeinfo->tweak_area_func(node, mx, my)) { + if (node->typeinfo->tweak_area_func(node, (int)mouse.x, (int)mouse.y)) { return node; } } @@ -126,15 +128,16 @@ static bNode *node_under_mouse_tweak(bNodeTree *ntree, int mx, int my) return nullptr; } -static bool is_position_over_node_or_socket(SpaceNode *snode, float mouse[2]) +static bool is_position_over_node_or_socket(SpaceNode &snode, const float2 &mouse) { - if (node_under_mouse_tweak(snode->edittree, mouse[0], mouse[1])) { + if (node_under_mouse_tweak(*snode.edittree, mouse)) { return true; } bNode *node; bNodeSocket *sock; - if (node_find_indicated_socket(snode, &node, &sock, mouse, SOCK_IN | SOCK_OUT)) { + if (node_find_indicated_socket( + snode, &node, &sock, mouse, (eNodeSocketInOut)(SOCK_IN | SOCK_OUT))) { return true; } @@ -145,9 +148,9 @@ static bool is_event_over_node_or_socket(bContext *C, const wmEvent *event) { SpaceNode *snode = CTX_wm_space_node(C); ARegion *region = CTX_wm_region(C); - float mouse[2]; - UI_view2d_region_to_view(®ion->v2d, event->mval[0], event->mval[1], &mouse[0], &mouse[1]); - return is_position_over_node_or_socket(snode, mouse); + float2 mouse; + UI_view2d_region_to_view(®ion->v2d, event->mval[0], event->mval[1], &mouse.x, &mouse.y); + return is_position_over_node_or_socket(*snode, mouse); } static void node_toggle(bNode *node) @@ -155,9 +158,9 @@ static void node_toggle(bNode *node) nodeSetSelected(node, !(node->flag & SELECT)); } -void node_socket_select(bNode *node, bNodeSocket *sock) +void node_socket_select(bNode *node, bNodeSocket &sock) { - sock->flag |= SELECT; + sock.flag |= SELECT; /* select node too */ if (node) { @@ -165,22 +168,22 @@ void node_socket_select(bNode *node, bNodeSocket *sock) } } -void node_socket_deselect(bNode *node, bNodeSocket *sock, const bool deselect_node) +void node_socket_deselect(bNode *node, bNodeSocket &sock, const bool deselect_node) { - sock->flag &= ~SELECT; + sock.flag &= ~SELECT; if (node && deselect_node) { bool sel = false; /* if no selected sockets remain, also deselect the node */ - for (sock = (bNodeSocket *)node->inputs.first; sock; sock = sock->next) { - if (sock->flag & SELECT) { + LISTBASE_FOREACH (bNodeSocket *, input, &node->inputs) { + if (input->flag & SELECT) { sel = true; break; } } - for (sock = (bNodeSocket *)node->outputs.first; sock; sock = sock->next) { - if (sock->flag & SELECT) { + LISTBASE_FOREACH (bNodeSocket *, output, &node->outputs) { + if (output->flag & SELECT) { sel = true; break; } @@ -192,9 +195,9 @@ void node_socket_deselect(bNode *node, bNodeSocket *sock, const bool deselect_no } } -static void node_socket_toggle(bNode *node, bNodeSocket *sock, int deselect_node) +static void node_socket_toggle(bNode *node, bNodeSocket &sock, bool deselect_node) { - if (sock->flag & SELECT) { + if (sock.flag & SELECT) { node_socket_deselect(node, sock, deselect_node); } else { @@ -202,17 +205,14 @@ static void node_socket_toggle(bNode *node, bNodeSocket *sock, int deselect_node } } -/* no undo here! */ -void node_deselect_all(SpaceNode *snode) +void node_deselect_all(SpaceNode &snode) { - bNode *node; - - for (node = (bNode *)snode->edittree->nodes.first; node; node = node->next) { + LISTBASE_FOREACH (bNode *, node, &snode.edittree->nodes) { nodeSetSelected(node, false); } } -void node_deselect_all_input_sockets(SpaceNode *snode, const bool deselect_nodes) +void node_deselect_all_input_sockets(SpaceNode &snode, const bool deselect_nodes) { bNode *node; bNodeSocket *sock; @@ -222,7 +222,7 @@ void node_deselect_all_input_sockets(SpaceNode *snode, const bool deselect_nodes * We can do that more efficiently here. */ - for (node = (bNode *)snode->edittree->nodes.first; node; node = node->next) { + for (node = (bNode *)snode.edittree->nodes.first; node; node = node->next) { int sel = 0; for (sock = (bNodeSocket *)node->inputs.first; sock; sock = sock->next) { @@ -245,7 +245,7 @@ void node_deselect_all_input_sockets(SpaceNode *snode, const bool deselect_nodes } } -void node_deselect_all_output_sockets(SpaceNode *snode, const bool deselect_nodes) +void node_deselect_all_output_sockets(SpaceNode &snode, const bool deselect_nodes) { bNode *node; bNodeSocket *sock; @@ -255,7 +255,7 @@ void node_deselect_all_output_sockets(SpaceNode *snode, const bool deselect_node * We can do that more efficiently here. */ - for (node = (bNode *)snode->edittree->nodes.first; node; node = node->next) { + for (node = (bNode *)snode.edittree->nodes.first; node; node = node->next) { bool sel = false; for (sock = (bNodeSocket *)node->outputs.first; sock; sock = sock->next) { @@ -455,24 +455,24 @@ void NODE_OT_select_grouped(wmOperatorType *ot) /** \name Select (Cursor Pick) Operator * \{ */ -void node_select_single(bContext *C, bNode *node) +void node_select_single(bContext &C, bNode &node) { - Main *bmain = CTX_data_main(C); - SpaceNode *snode = CTX_wm_space_node(C); - const Object *ob = CTX_data_active_object(C); - const Scene *scene = CTX_data_scene(C); - const wmWindowManager *wm = CTX_wm_manager(C); + Main *bmain = CTX_data_main(&C); + SpaceNode *snode = CTX_wm_space_node(&C); + const Object *ob = CTX_data_active_object(&C); + const Scene *scene = CTX_data_scene(&C); + const wmWindowManager *wm = CTX_wm_manager(&C); bool active_texture_changed = false; bNode *tnode; for (tnode = (bNode *)snode->edittree->nodes.first; tnode; tnode = tnode->next) { - if (tnode != node) { + if (tnode != &node) { nodeSetSelected(tnode, false); } } - nodeSetSelected(node, true); + nodeSetSelected(&node, true); - ED_node_set_active(bmain, snode, snode->edittree, node, &active_texture_changed); + ED_node_set_active(bmain, snode, snode->edittree, &node, &active_texture_changed); ED_node_set_active_viewer_key(snode); ED_node_sort(snode->edittree); @@ -480,7 +480,7 @@ void node_select_single(bContext *C, bNode *node) DEG_id_tag_update(&snode->edittree->id, ID_RECALC_COPY_ON_WRITE); } - WM_event_add_notifier(C, NC_NODE | NA_SELECTED, nullptr); + WM_event_add_notifier(&C, NC_NODE | NA_SELECTED, nullptr); } static int node_mouse_select(bContext *C, @@ -488,9 +488,9 @@ static int node_mouse_select(bContext *C, const int mval[2], bool wait_to_deselect_others) { - Main *bmain = CTX_data_main(C); - SpaceNode *snode = CTX_wm_space_node(C); - ARegion *region = CTX_wm_region(C); + Main &bmain = *CTX_data_main(C); + SpaceNode &snode = *CTX_wm_space_node(C); + ARegion ®ion = *CTX_wm_region(C); const Object *ob = CTX_data_active_object(C); const Scene *scene = CTX_data_scene(C); const wmWindowManager *wm = CTX_wm_manager(C); @@ -511,20 +511,20 @@ static int node_mouse_select(bContext *C, } /* get mouse coordinates in view2d space */ - UI_view2d_region_to_view(®ion->v2d, mval[0], mval[1], &cursor[0], &cursor[1]); + UI_view2d_region_to_view(®ion.v2d, mval[0], mval[1], &cursor[0], &cursor[1]); /* first do socket selection, these generally overlap with nodes. */ if (socket_select) { if (node_find_indicated_socket(snode, &node, &sock, cursor, SOCK_IN)) { /* NOTE: SOCK_IN does not take into account the extend case... * This feature is not really used anyway currently? */ - node_socket_toggle(node, sock, true); + node_socket_toggle(node, *sock, true); ret_value = OPERATOR_FINISHED; } else if (node_find_indicated_socket(snode, &node, &sock, cursor, SOCK_OUT)) { if (sock->flag & SELECT) { if (extend) { - node_socket_deselect(node, sock, true); + node_socket_deselect(node, *sock, true); } else { ret_value = OPERATOR_FINISHED; @@ -538,20 +538,20 @@ static int node_mouse_select(bContext *C, if (tsock == sock) { continue; } - node_socket_deselect(node, tsock, true); + node_socket_deselect(node, *tsock, true); } } if (!extend) { - for (tnode = (bNode *)snode->edittree->nodes.first; tnode; tnode = tnode->next) { + for (tnode = (bNode *)snode.edittree->nodes.first; tnode; tnode = tnode->next) { if (tnode == node) { continue; } for (tsock = (bNodeSocket *)tnode->outputs.first; tsock; tsock = tsock->next) { - node_socket_deselect(tnode, tsock, true); + node_socket_deselect(tnode, *tsock, true); } } } - node_socket_select(node, sock); + node_socket_select(node, *sock); ret_value = OPERATOR_FINISHED; } } @@ -559,7 +559,7 @@ static int node_mouse_select(bContext *C, if (!sock) { /* find the closest visible node */ - node = node_under_mouse_select(snode->edittree, (int)cursor[0], (int)cursor[1]); + node = node_under_mouse_select(*snode.edittree, (int)cursor[0], (int)cursor[1]); if (extend) { if (node != nullptr) { @@ -580,7 +580,7 @@ static int node_mouse_select(bContext *C, } else { /* Deselect in empty space. */ - for (tnode = (bNode *)snode->edittree->nodes.first; tnode; tnode = tnode->next) { + for (tnode = (bNode *)snode.edittree->nodes.first; tnode; tnode = tnode->next) { nodeSetSelected(tnode, false); } ret_value = OPERATOR_FINISHED; @@ -595,7 +595,7 @@ static int node_mouse_select(bContext *C, else { nodeSetSelected(node, true); - for (tnode = (bNode *)snode->edittree->nodes.first; tnode; tnode = tnode->next) { + for (tnode = (bNode *)snode.edittree->nodes.first; tnode; tnode = tnode->next) { if (tnode != node) { nodeSetSelected(tnode, false); } @@ -612,16 +612,16 @@ static int node_mouse_select(bContext *C, bool viewer_node_changed = false; if (node != nullptr && ret_value != OPERATOR_RUNNING_MODAL) { viewer_node_changed = (node->flag & NODE_DO_OUTPUT) == 0 && node->type == GEO_NODE_VIEWER; - ED_node_set_active(bmain, snode, snode->edittree, node, &active_texture_changed); + ED_node_set_active(&bmain, &snode, snode.edittree, node, &active_texture_changed); } else if (node != nullptr && node->type == GEO_NODE_VIEWER) { - ED_spreadsheet_context_paths_set_geometry_node(bmain, snode, node); + ED_spreadsheet_context_paths_set_geometry_node(&bmain, &snode, node); } - ED_node_set_active_viewer_key(snode); - ED_node_sort(snode->edittree); + ED_node_set_active_viewer_key(&snode); + ED_node_sort(snode.edittree); if ((active_texture_changed && has_workbench_in_texture_color(wm, scene, ob)) || viewer_node_changed) { - DEG_id_tag_update(&snode->edittree->id, ID_RECALC_COPY_ON_WRITE); + DEG_id_tag_update(&snode.edittree->id, ID_RECALC_COPY_ON_WRITE); } WM_event_add_notifier(C, NC_NODE | NA_SELECTED, nullptr); @@ -1149,13 +1149,13 @@ static int node_select_same_type_step_exec(bContext *C, wmOperator *op) } } - node_select_single(C, active); + node_select_single(*C, *active); /* is note outside view? */ if (active->totr.xmax < region->v2d.cur.xmin || active->totr.xmin > region->v2d.cur.xmax || active->totr.ymax < region->v2d.cur.ymin || active->totr.ymin > region->v2d.cur.ymax) { const int smooth_viewtx = WM_operator_smooth_viewtx_get(op); - space_node_view_flag(C, snode, region, NODE_SELECT, smooth_viewtx); + space_node_view_flag(*C, *snode, *region, NODE_SELECT, smooth_viewtx); } } @@ -1239,12 +1239,12 @@ static void node_find_exec_fn(struct bContext *C, void *UNUSED(arg1), void *arg2 if (active) { ARegion *region = CTX_wm_region(C); - node_select_single(C, active); + node_select_single(*C, *active); /* is note outside view? */ if (active->totr.xmax < region->v2d.cur.xmin || active->totr.xmin > region->v2d.cur.xmax || active->totr.ymax < region->v2d.cur.ymin || active->totr.ymin > region->v2d.cur.ymax) { - space_node_view_flag(C, snode, region, NODE_SELECT, U.smooth_viewtx); + space_node_view_flag(*C, *snode, *region, NODE_SELECT, U.smooth_viewtx); } } } diff --git a/source/blender/editors/space_node/node_templates.cc b/source/blender/editors/space_node/node_templates.cc index b2a7c1753fb..3a43386c6bf 100644 --- a/source/blender/editors/space_node/node_templates.cc +++ b/source/blender/editors/space_node/node_templates.cc @@ -709,7 +709,7 @@ void uiTemplateNodeLink( 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(*C, *ntree, node_ptr, *input, socket_col); UI_block_layout_set_current(block, layout); @@ -769,7 +769,6 @@ static void ui_node_draw_input( PointerRNA inputptr, nodeptr; uiBlock *block = uiLayoutGetBlock(layout); uiLayout *row = nullptr; - bNode *lnode; bool dependency_loop; if (input->flag & SOCK_UNAVAIL) { @@ -778,7 +777,7 @@ static void ui_node_draw_input( /* to avoid eternal loops on cyclic dependencies */ node->flag |= NODE_TEST; - lnode = (input->link) ? input->link->fromnode : nullptr; + bNode *lnode = (input->link) ? input->link->fromnode : nullptr; dependency_loop = (lnode && (lnode->flag & NODE_TEST)); if (dependency_loop) { @@ -868,7 +867,7 @@ static void ui_node_draw_input( 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. */ - node_geometry_add_attribute_search_button(C, node_tree, node, &inputptr, row); + node_geometry_add_attribute_search_button(*C, *node_tree, *node, inputptr, *row); } else { uiItemR(sub, &inputptr, "default_value", 0, "", ICON_NONE); diff --git a/source/blender/editors/space_node/node_view.cc b/source/blender/editors/space_node/node_view.cc index 36b84bec7eb..1153b28bd82 100644 --- a/source/blender/editors/space_node/node_view.cc +++ b/source/blender/editors/space_node/node_view.cc @@ -62,25 +62,21 @@ using blender::StringRef; /** \name View All Operator * \{ */ -int space_node_view_flag( - bContext *C, SpaceNode *snode, ARegion *region, const int node_flag, const int smooth_viewtx) +bool space_node_view_flag( + bContext &C, SpaceNode &snode, ARegion ®ion, const int node_flag, const int smooth_viewtx) { - bNode *node; - rctf cur_new; - float oldwidth, oldheight, width, height; - float oldasp, asp; - int tot = 0; - bool has_frame = false; + const float oldwidth = BLI_rctf_size_x(®ion.v2d.cur); + const float oldheight = BLI_rctf_size_y(®ion.v2d.cur); - oldwidth = BLI_rctf_size_x(®ion->v2d.cur); - oldheight = BLI_rctf_size_y(®ion->v2d.cur); - - oldasp = oldwidth / oldheight; + const float old_aspect = oldwidth / oldheight; + rctf cur_new; BLI_rctf_init_minmax(&cur_new); - if (snode->edittree) { - for (node = (bNode *)snode->edittree->nodes.first; node; node = node->next) { + int tot = 0; + bool has_frame = false; + if (snode.edittree) { + LISTBASE_FOREACH (const bNode *, node, &snode.edittree->nodes) { if ((node->flag & node_flag) == node_flag) { BLI_rctf_union(&cur_new, &node->totr); tot++; @@ -92,37 +88,39 @@ int space_node_view_flag( } } - if (tot) { - width = BLI_rctf_size_x(&cur_new); - height = BLI_rctf_size_y(&cur_new); - asp = width / height; + if (tot == 0) { + return false; + } - /* for single non-frame nodes, don't zoom in, just pan view, - * but do allow zooming out, this allows for big nodes to be zoomed out */ - if ((tot == 1) && (has_frame == false) && ((oldwidth * oldheight) > (width * height))) { - /* center, don't zoom */ - BLI_rctf_resize(&cur_new, oldwidth, oldheight); + const float width = BLI_rctf_size_x(&cur_new); + const float height = BLI_rctf_size_y(&cur_new); + const float new_aspect = width / height; + + /* for single non-frame nodes, don't zoom in, just pan view, + * but do allow zooming out, this allows for big nodes to be zoomed out */ + if ((tot == 1) && (has_frame == false) && ((oldwidth * oldheight) > (width * height))) { + /* center, don't zoom */ + BLI_rctf_resize(&cur_new, oldwidth, oldheight); + } + else { + if (old_aspect < new_aspect) { + const float height_new = width / old_aspect; + cur_new.ymin = cur_new.ymin - height_new / 2.0f; + cur_new.ymax = cur_new.ymax + height_new / 2.0f; } else { - if (oldasp < asp) { - const float height_new = width / oldasp; - cur_new.ymin = cur_new.ymin - height_new / 2.0f; - cur_new.ymax = cur_new.ymax + height_new / 2.0f; - } - else { - const float width_new = height * oldasp; - cur_new.xmin = cur_new.xmin - width_new / 2.0f; - cur_new.xmax = cur_new.xmax + width_new / 2.0f; - } - - /* add some padding */ - BLI_rctf_scale(&cur_new, 1.1f); + const float width_new = height * old_aspect; + cur_new.xmin = cur_new.xmin - width_new / 2.0f; + cur_new.xmax = cur_new.xmax + width_new / 2.0f; } - UI_view2d_smooth_view(C, region, &cur_new, smooth_viewtx); + /* add some padding */ + BLI_rctf_scale(&cur_new, 1.1f); } - return (tot != 0); + UI_view2d_smooth_view(&C, ®ion, &cur_new, smooth_viewtx); + + return true; } static int node_view_all_exec(bContext *C, wmOperator *op) @@ -135,7 +133,7 @@ static int node_view_all_exec(bContext *C, wmOperator *op) snode->xof = 0; snode->yof = 0; - if (space_node_view_flag(C, snode, region, 0, smooth_viewtx)) { + if (space_node_view_flag(*C, *snode, *region, 0, smooth_viewtx)) { return OPERATOR_FINISHED; } return OPERATOR_CANCELLED; @@ -168,7 +166,7 @@ static int node_view_selected_exec(bContext *C, wmOperator *op) SpaceNode *snode = CTX_wm_space_node(C); const int smooth_viewtx = WM_operator_smooth_viewtx_get(op); - if (space_node_view_flag(C, snode, region, NODE_SELECT, smooth_viewtx)) { + if (space_node_view_flag(*C, *snode, *region, NODE_SELECT, smooth_viewtx)) { return OPERATOR_FINISHED; } return OPERATOR_CANCELLED; @@ -738,7 +736,7 @@ static int space_node_view_geometry_nodes_legacy(bContext *C, SpaceNode *snode, } const int smooth_viewtx = WM_operator_smooth_viewtx_get(op); - if (space_node_view_flag(C, snode, region, NODE_SELECT, smooth_viewtx)) { + if (space_node_view_flag(*C, *snode, *region, NODE_SELECT, smooth_viewtx)) { return OPERATOR_FINISHED; } return OPERATOR_CANCELLED; diff --git a/source/blender/editors/space_node/space_node.cc b/source/blender/editors/space_node/space_node.cc index ffca26946bc..b57f091b1d7 100644 --- a/source/blender/editors/space_node/space_node.cc +++ b/source/blender/editors/space_node/space_node.cc @@ -479,7 +479,7 @@ static void node_area_refresh(const struct bContext *C, ScrArea *area) /* default now: refresh node is starting preview */ SpaceNode *snode = (SpaceNode *)area->spacedata.first; - snode_set_context(C); + snode_set_context(*C); if (snode->nodetree) { if (snode->nodetree->type == NTREE_SHADER) { @@ -595,7 +595,7 @@ static void node_cursor(wmWindow *win, ScrArea *area, ARegion *region) &snode->runtime->cursor[1]); /* here snode->runtime->cursor is used to detect the node edge for sizing */ - node_set_cursor(win, snode, snode->runtime->cursor); + node_set_cursor(*win, *snode, snode->runtime->cursor); /* XXX snode->runtime->cursor is in placing new nodes space */ snode->runtime->cursor[0] /= UI_DPI_FAC; @@ -629,7 +629,7 @@ static void node_main_region_init(wmWindowManager *wm, ARegion *region) static void node_main_region_draw(const bContext *C, ARegion *region) { - node_draw_space(C, region); + node_draw_space(*C, *region); } /* ************* dropboxes ************* */ @@ -752,7 +752,7 @@ static void node_header_region_init(wmWindowManager *UNUSED(wm), ARegion *region static void node_header_region_draw(const bContext *C, ARegion *region) { /* find and set the context */ - snode_set_context(C); + snode_set_context(*C); ED_region_header(C, region); } |