Cleanup: Comment formatting in node editor

Also remove an accidentally committed timing print.
This commit is contained in:
Hans Goudey 2023-01-03 20:02:01 -05:00
parent 8b1edff6b5
commit 1d636f5e05
8 changed files with 176 additions and 224 deletions

View File

@ -78,15 +78,6 @@ void ED_node_draw_snap(
/* node_draw.cc */
/**
* Draw a single node socket at default size.
* \note this is only called from external code, internally #node_socket_draw_nested() is used for
* optimized drawing of multiple/all sockets of a node.
*/
void ED_node_socket_draw(struct bNodeSocket *sock,
const struct rcti *rect,
const float color[4],
float scale);
void ED_node_tree_update(const struct bContext *C);
void ED_node_tag_update_id(struct ID *id);

View File

@ -9,6 +9,7 @@ struct SpaceNode;
struct ARegion;
struct Main;
struct bNodeTree;
struct rcti;
namespace blender::ed::space_node {
@ -22,4 +23,11 @@ void node_insert_on_link_flags_set(SpaceNode &snode, const ARegion &region);
void node_insert_on_link_flags(Main &bmain, SpaceNode &snode);
void node_insert_on_link_flags_clear(bNodeTree &node_tree);
/**
* Draw a single node socket at default size.
* \note this is only called from external code, internally #node_socket_draw_nested() is used for
* optimized drawing of multiple/all sockets of a node.
*/
void node_socket_draw(bNodeSocket *sock, const rcti *rect, const float color[4], float scale);
} // namespace blender::ed::space_node

View File

@ -26,7 +26,7 @@
#include "BLF_api.h"
#include "ED_node.h"
#include "ED_node.hh"
#include "UI_interface.h"
#include "UI_interface_icons.h"
@ -2213,7 +2213,8 @@ static void widget_draw_node_link_socket(const uiWidgetColors *wcol,
UI_widgetbase_draw_cache_flush();
GPU_blend(GPU_BLEND_NONE);
ED_node_socket_draw(static_cast<bNodeSocket *>(but->custom_data), rect, col, scale);
blender::ed::space_node::node_socket_draw(
static_cast<bNodeSocket *>(but->custom_data), rect, col, scale);
}
else {
widget_draw_icon(but, ICON_LAYER_USED, alpha, rect, wcol->text);

View File

@ -699,8 +699,7 @@ static int node_add_file_exec(bContext *C, wmOperator *op)
}
/* When adding new image file via drag-drop we need to load imbuf in order
* to get proper image source.
*/
* to get proper image source. */
if (RNA_struct_property_is_set(op->ptr, "filepath")) {
BKE_image_signal(bmain, ima, nullptr, IMA_SIGNAL_RELOAD);
WM_event_add_notifier(C, NC_IMAGE | NA_EDITED, ima);
@ -717,7 +716,7 @@ static int node_add_file_invoke(bContext *C, wmOperator *op, const wmEvent *even
ARegion *region = CTX_wm_region(C);
SpaceNode *snode = CTX_wm_space_node(C);
/* convert mouse coordinates to v2d space */
/* Convert mouse coordinates to `v2d` space. */
UI_view2d_region_to_view(&region->v2d,
event->mval[0],
event->mval[1],
@ -860,13 +859,12 @@ static int new_node_tree_exec(bContext *C, wmOperator *op)
ntree = ntreeAddTree(bmain, treename, idname);
/* hook into UI */
/* Hook into UI. */
UI_context_active_but_prop_get_templateID(C, &ptr, &prop);
if (prop) {
/* RNA_property_pointer_set increases the user count,
* fixed here as the editor is the initial user.
*/
/* #RNA_property_pointer_set increases the user count, fixed here as the editor is the initial
* user. */
id_us_min(&ntree->id);
RNA_id_pointer_create(&ntree->id, &idptr);

View File

@ -59,6 +59,7 @@
#include "ED_gpencil.h"
#include "ED_node.h"
#include "ED_node.hh"
#include "ED_screen.h"
#include "ED_space_api.h"
#include "ED_viewer_path.hh"
@ -84,9 +85,6 @@
namespace geo_log = blender::nodes::geo_eval_log;
using blender::GPointer;
using blender::Vector;
/**
* This is passed to many functions which draw the node editor.
*/
@ -278,7 +276,7 @@ static Array<uiBlock *> node_uiblocks_init(const bContext &C, const Span<bNode *
for (const int i : nodes.index_range()) {
const std::string block_name = "node_" + std::string(nodes[i]->name);
blocks[i] = UI_block_begin(&C, CTX_wm_region(&C), block_name.c_str(), UI_EMBOSS);
/* this cancels events for background nodes */
/* This cancels events for background nodes. */
UI_block_flag_enable(blocks[i], UI_BLOCK_CLIP_EVENTS);
}
@ -1240,12 +1238,8 @@ static void node_socket_draw_nested(const bContext &C,
UI_block_emboss_set(&block, old_emboss);
}
} // namespace blender::ed::space_node
void ED_node_socket_draw(bNodeSocket *sock, const rcti *rect, const float color[4], float scale)
void node_socket_draw(bNodeSocket *sock, const rcti *rect, const float color[4], float scale)
{
using namespace blender::ed::space_node;
const float size = NODE_SOCKSIZE_DRAW_MULIPLIER * NODE_SOCKSIZE * scale;
rcti draw_rect = *rect;
float outline_color[4] = {0};
@ -1292,10 +1286,6 @@ void ED_node_socket_draw(bNodeSocket *sock, const rcti *rect, const float color[
GPU_blend(state);
}
namespace blender::ed::space_node {
/* ************** Socket callbacks *********** */
static void node_draw_preview_background(rctf *rect)
{
GPUVertFormat *format = immVertexFormat();
@ -1526,7 +1516,8 @@ static void node_draw_sockets(const View2D &v2d,
scale,
selected);
if (--selected_input_len == 0) {
break; /* Stop as soon as last one is drawn. */
/* Stop as soon as last one is drawn. */
break;
}
}
}
@ -1552,7 +1543,8 @@ static void node_draw_sockets(const View2D &v2d,
scale,
selected);
if (--selected_output_len == 0) {
break; /* Stop as soon as last one is drawn. */
/* Stop as soon as last one is drawn. */
break;
}
}
}
@ -2163,11 +2155,6 @@ static void node_draw_basis(const bContext &C,
node_toggle_button_cb,
POINTER_FROM_INT(node.identifier),
(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)))
// UI_but_flag_enable(but, UI_BUT_DISABLED);
UI_block_emboss_set(&block, UI_EMBOSS);
}
/* Group edit. */
@ -2680,28 +2667,28 @@ static void frame_node_prepare_for_draw(bNode &node, Span<bNode *> nodes)
const float margin = 1.5f * U.widget_unit;
NodeFrame *data = (NodeFrame *)node.storage;
/* init rect from current frame size */
/* Initialize rect from current frame size. */
rctf rect;
node_to_updated_rect(node, rect);
/* frame can be resized manually only if shrinking is disabled or no children are attached */
/* Frame can be resized manually only if shrinking is disabled or no children are attached. */
data->flag |= NODE_FRAME_RESIZEABLE;
/* for shrinking bbox, initialize the rect from first child node */
/* For shrinking bounding box, initialize the rect from first child node. */
bool bbinit = (data->flag & NODE_FRAME_SHRINK);
/* fit bounding box to all children */
/* Fit bounding box to all children. */
for (const bNode *tnode : nodes) {
if (tnode->parent != &node) {
continue;
}
/* add margin to node rect */
/* Add margin to node rect. */
rctf noderect = tnode->runtime->totr;
noderect.xmin -= margin;
noderect.xmax += margin;
noderect.ymin -= margin;
noderect.ymax += margin;
/* first child initializes frame */
/* First child initializes frame. */
if (bbinit) {
bbinit = false;
rect = noderect;
@ -2712,7 +2699,7 @@ static void frame_node_prepare_for_draw(bNode &node, Span<bNode *> nodes)
}
}
/* now adjust the frame size from view-space bounding box */
/* Now adjust the frame size from view-space bounding box. */
const float2 offset = node_from_view(node, {rect.xmin, rect.ymax});
node.offsetx = offset.x;
node.offsety = offset.y;
@ -2725,10 +2712,9 @@ static void frame_node_prepare_for_draw(bNode &node, Span<bNode *> nodes)
static void reroute_node_prepare_for_draw(bNode &node)
{
/* get "global" coords */
const float2 loc = node_to_view(node, float2(0));
/* reroute node has exactly one input and one output, both in the same place */
/* Reroute node has exactly one input and one output, both in the same place. */
bNodeSocket *socket = (bNodeSocket *)node.outputs.first;
socket->runtime->locx = loc.x;
socket->runtime->locy = loc.y;
@ -2802,10 +2788,10 @@ static void frame_node_draw_label(TreeDrawContext &tree_draw_ctx,
BLF_enable(fontid, BLF_ASPECT);
BLF_aspect(fontid, aspect, aspect, 1.0f);
/* clamp otherwise it can suck up a LOT of memory */
/* Clamp. Otherwise it can suck up a LOT of memory. */
BLF_size(fontid, MIN2(24.0f, font_size) * U.dpi_fac);
/* title color */
/* Title color. */
int color_id = node_get_colorid(tree_draw_ctx, node);
uchar color[3];
UI_GetThemeColorBlendShade3ubv(TH_TEXT, color_id, 0.4f, 10, color);
@ -2818,7 +2804,7 @@ static void frame_node_draw_label(TreeDrawContext &tree_draw_ctx,
/* 'x' doesn't need aspect correction */
const rctf &rct = node.runtime->totr;
/* XXX a bit hacky, should use separate align values for x and y */
/* 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;
@ -2829,24 +2815,23 @@ static void frame_node_draw_label(TreeDrawContext &tree_draw_ctx,
BLF_draw(fontid, label, sizeof(label));
}
/* draw text body */
/* Draw text body. */
if (node.id) {
const Text *text = (const 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;
/* 'x' doesn't need aspect correction */
/* 'x' doesn't need aspect correction. */
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));
BLF_enable(fontid, BLF_CLIPPING | BLF_WORD_WRAP);
BLF_clipping(fontid,
rct.xmin,
/* round to avoid clipping half-way through a line */
/* 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);
@ -2882,7 +2867,7 @@ static void frame_node_draw(const bContext &C,
bNode &node,
uiBlock &block)
{
/* skip if out of view */
/* Skip if out of view. */
if (BLI_rctf_isect(&node.runtime->totr, &region.v2d.cur, nullptr) == false) {
UI_block_end(&C, &block);
return;
@ -2892,10 +2877,8 @@ static void frame_node_draw(const bContext &C,
UI_GetThemeColor4fv(TH_NODE_FRAME, color);
const float alpha = color[3];
/* shadow */
node_draw_shadow(snode, node, BASIS_RAD, alpha);
/* body */
if (node.flag & NODE_CUSTOM_COLOR) {
rgba_float_args_set(color, node.color[0], node.color[1], node.color[2], alpha);
}
@ -2907,7 +2890,7 @@ static void frame_node_draw(const bContext &C,
UI_draw_roundbox_corner_set(UI_CNR_ALL);
UI_draw_roundbox_4fv(&rct, true, BASIS_RAD, color);
/* outline active and selected emphasis */
/* Outline active and selected emphasis. */
if (node.flag & SELECT) {
if (node.flag & NODE_ACTIVE) {
UI_GetThemeColorShadeAlpha4fv(TH_ACTIVE, 0, -40, color);
@ -2919,7 +2902,7 @@ static void frame_node_draw(const bContext &C,
UI_draw_roundbox_aa(&rct, false, BASIS_RAD, color);
}
/* label and text */
/* Label and text. */
frame_node_draw_label(tree_draw_ctx, ntree, node, snode);
node_draw_extra_info_panel(tree_draw_ctx, snode, node, block);
@ -2931,7 +2914,7 @@ static void frame_node_draw(const bContext &C,
static void reroute_node_draw(
const bContext &C, ARegion &region, bNodeTree &ntree, bNode &node, uiBlock &block)
{
/* skip if out of view */
/* Skip if out of view. */
const rctf &rct = node.runtime->totr;
if (rct.xmax < region.v2d.cur.xmin || rct.xmin > region.v2d.cur.xmax ||
rct.ymax < region.v2d.cur.ymin || node.runtime->totr.ymin > region.v2d.cur.ymax) {
@ -2940,7 +2923,7 @@ static void reroute_node_draw(
}
if (node.label[0] != '\0') {
/* draw title (node label) */
/* Draw title (node label). */
char showname[128]; /* 128 used below */
BLI_strncpy(showname, node.label, sizeof(showname));
const short width = 512;
@ -2965,9 +2948,8 @@ static void reroute_node_draw(
UI_but_drawflag_disable(label_but, UI_BUT_TEXT_LEFT);
}
/* 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!
*/
/* Only draw input socket as they all are placed on the same position highlight
* if node itself is selected, since we don't display the node body separately. */
node_draw_sockets(region.v2d, C, ntree, node, block, false, node.flag & SELECT);
UI_block_end(&C, &block);
@ -3098,9 +3080,7 @@ static void snode_setup_v2d(SpaceNode &snode, ARegion &region, const float2 &cen
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);
// XXX snode->curfont = uiSetCurFont_ext(snode->aspect);
}
/* Similar to is_compositor_enabled() in draw_manager.c but checks all 3D views. */
@ -3199,7 +3179,6 @@ static void draw_background_color(const SpaceNode &snode)
void node_draw_space(const bContext &C, ARegion &region)
{
SCOPED_TIMER_AVERAGED(__func__);
wmWindow *win = CTX_wm_window(&C);
SpaceNode &snode = *CTX_wm_space_node(&C);
View2D &v2d = region.v2d;

View File

@ -168,12 +168,12 @@ static int compo_get_recalc_flags(const bContext *C)
return recalc_flags;
}
/* called by compo, only to check job 'stop' value */
/* Called by compositor, only to check job 'stop' value. */
static bool compo_breakjob(void *cjv)
{
CompoJob *cj = (CompoJob *)cjv;
/* without G.is_break 'ESC' won't quit - which annoys users */
/* Without G.is_break 'ESC' won't quit - which annoys users. */
return (*(cj->stop)
#ifdef USE_ESC_COMPO
|| G.is_break
@ -181,7 +181,7 @@ static bool compo_breakjob(void *cjv)
);
}
/* called by compo, wmJob sends notifier */
/* Called by compositor, #wmJob sends notifier. */
static void compo_statsdrawjob(void *cjv, const char * /*str*/)
{
CompoJob *cj = (CompoJob *)cjv;
@ -189,7 +189,7 @@ static void compo_statsdrawjob(void *cjv, const char * /*str*/)
*(cj->do_update) = true;
}
/* called by compo, wmJob sends notifier */
/* Called by compositor, wmJob sends notifier. */
static void compo_redrawjob(void *cjv)
{
CompoJob *cj = (CompoJob *)cjv;
@ -210,8 +210,8 @@ static void compo_freejob(void *cjv)
MEM_freeN(cj);
}
/* only now we copy the nodetree, so adding many jobs while
* sliding buttons doesn't frustrate */
/* Only now we copy the nodetree, so adding many jobs while
* sliding buttons doesn't frustrate. */
static void compo_initjob(void *cjv)
{
CompoJob *cj = (CompoJob *)cjv;
@ -236,7 +236,7 @@ static void compo_initjob(void *cjv)
}
}
/* called before redraw notifiers, it moves finished previews over */
/* Called before redraw notifiers, it moves finished previews over. */
static void compo_updatejob(void * /*cjv*/)
{
WM_main_add_notifier(NC_SCENE | ND_COMPO_RESULT, nullptr);
@ -249,7 +249,7 @@ static void compo_progressjob(void *cjv, float progress)
*(cj->progress) = progress;
}
/* only this runs inside thread */
/* Only this runs inside thread. */
static void compo_startjob(void *cjv,
/* Cannot be const, this function implements wm_jobs_start_callback.
* NOLINTNEXTLINE: readability-non-const-parameter. */
@ -278,8 +278,6 @@ static void compo_startjob(void *cjv,
ntree->runtime->update_draw = compo_redrawjob;
ntree->runtime->udh = cj;
// XXX BIF_store_spare();
/* 1 is do_previews */
BKE_callback_exec_id(cj->bmain, &scene->id, BKE_CB_EVT_COMPOSITE_PRE);
if ((cj->scene->r.scemode & R_MULTIVIEW) == 0) {
@ -331,7 +329,7 @@ void ED_node_composite_job(const bContext *C, bNodeTree *nodetree, Scene *scene_
Scene *scene = CTX_data_scene(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
/* to fix bug: T32272. */
/* See T32272. */
if (G.is_rendering) {
return;
}
@ -351,14 +349,14 @@ void ED_node_composite_job(const bContext *C, bNodeTree *nodetree, Scene *scene_
WM_JOB_TYPE_COMPOSITE);
CompoJob *cj = MEM_cnew<CompoJob>("compo job");
/* customdata for preview thread */
/* Custom data for preview thread. */
cj->bmain = bmain;
cj->scene = scene;
cj->view_layer = view_layer;
cj->ntree = nodetree;
cj->recalc_flags = compo_get_recalc_flags(C);
/* setup job */
/* Set up job. */
WM_jobs_customdata_set(wm_job, cj, compo_freejob);
WM_jobs_timer(wm_job, 0.1, NC_SCENE | ND_COMPO_RESULT, NC_SCENE | ND_COMPO_RESULT);
WM_jobs_callbacks_ex(wm_job,
@ -582,7 +580,7 @@ void ED_node_composit_default(const bContext *C, Scene *sce)
in->locy = 400.0f;
nodeSetActive(sce->nodetree, in);
/* links from color to color */
/* Links from color to color. */
bNodeSocket *fromsock = (bNodeSocket *)in->outputs.first;
bNodeSocket *tosock = (bNodeSocket *)out->inputs.first;
nodeAddLink(sce->nodetree, in, fromsock, out, tosock);
@ -592,7 +590,6 @@ void ED_node_composit_default(const bContext *C, Scene *sce)
void ED_node_texture_default(const bContext *C, Tex *tex)
{
/* but lets check it anyway */
if (tex->nodetree) {
if (G.debug & G_DEBUG) {
printf("error in texture initialize\n");
@ -631,16 +628,16 @@ void snode_set_context(const bContext &C)
bNodeTree *ntree = snode->nodetree;
ID *id = snode->id, *from = snode->from;
/* check the tree type */
/* Check the tree type. */
if (!treetype || (treetype->poll && !treetype->poll(&C, treetype))) {
/* invalid tree type, skip
/* Invalid tree type, skip.
* NOTE: not resetting the node path here, invalid #bNodeTreeType
* may still be registered at a later point. */
return;
}
if (snode->nodetree && !STREQ(snode->nodetree->idname, snode->tree_idname)) {
/* current tree does not match selected type, clear tree path */
/* Current tree does not match selected type, clear tree path. */
ntree = nullptr;
id = nullptr;
from = nullptr;
@ -648,7 +645,7 @@ void snode_set_context(const bContext &C)
if (!(snode->flag & SNODE_PIN) || ntree == nullptr) {
if (treetype->get_from_context) {
/* reset and update from context */
/* Reset and update from context. */
ntree = nullptr;
id = nullptr;
from = nullptr;
@ -681,7 +678,7 @@ void ED_node_set_active(
const bool was_output = (node->flag & NODE_DO_OUTPUT) != 0;
bool do_update = false;
/* generic node group output: set node as active output */
/* Generic node group output: set node as active output. */
if (node->type == NODE_GROUP_OUTPUT) {
for (bNode *node_iter : ntree->all_nodes()) {
if (node_iter->type == NODE_GROUP_OUTPUT) {
@ -696,7 +693,7 @@ void ED_node_set_active(
}
}
/* tree specific activate calls */
/* Tree specific activate calls. */
if (ntree->type == NTREE_SHADER) {
if (ELEM(node->type,
SH_NODE_OUTPUT_MATERIAL,
@ -760,7 +757,7 @@ void ED_node_set_active(
WM_main_add_notifier(NC_MATERIAL | ND_NODES, node->id);
}
else if (ntree->type == NTREE_COMPOSIT) {
/* make active viewer, currently only 1 supported... */
/* Make active viewer, currently only one is supported. */
if (ELEM(node->type, CMP_NODE_VIEWER, CMP_NODE_SPLITVIEWER)) {
for (bNode *node_iter : ntree->all_nodes()) {
if (ELEM(node_iter->type, CMP_NODE_VIEWER, CMP_NODE_SPLITVIEWER)) {
@ -1022,7 +1019,7 @@ static int node_resize_modal(bContext *C, wmOperator *op, const wmEvent *event)
}
}
/* height works the other way round ... */
/* Height works the other way round. */
{
float heightmin = UI_DPI_FAC * node->typeinfo->minheight;
float heightmax = UI_DPI_FAC * node->typeinfo->maxheight;
@ -1039,9 +1036,8 @@ static int node_resize_modal(bContext *C, wmOperator *op, const wmEvent *event)
}
}
/* XXX make callback? */
if (node->type == NODE_FRAME) {
/* keep the offset symmetric around center point */
/* Keep the offset symmetric around center point. */
if (nsw->directions & NODE_RESIZE_LEFT) {
node->locx = nsw->oldlocx + 0.5f * dx;
node->offsetx = nsw->oldoffsetx + 0.5f * dx;
@ -1101,7 +1097,7 @@ static int node_resize_invoke(bContext *C, wmOperator *op, const wmEvent *event)
return OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH;
}
/* convert mouse coordinates to v2d space */
/* Convert mouse coordinates to `v2d` space. */
float2 cursor;
int2 mval;
WM_event_drag_start_mval(event, region, mval);
@ -1169,7 +1165,7 @@ void node_set_hidden_sockets(SpaceNode *snode, bNode *node, int set)
}
}
else {
/* hide unused sockets */
/* Hide unused sockets. */
LISTBASE_FOREACH (bNodeSocket *, sock, &node->inputs) {
if (sock->link == nullptr) {
sock->flag |= SOCK_HIDDEN;
@ -1183,7 +1179,6 @@ 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 float2 &cursor, const bNodeSocket &socket)
{
const float node_socket_height = node_socket_calculate_height(socket);
@ -1220,7 +1215,7 @@ bNodeSocket *node_find_indicated_socket(SpaceNode &snode,
BLI_rctf_init_pt_radius(&rect, cursor, size_sock_padded);
if (!(node.flag & NODE_HIDDEN)) {
/* extra padding inside and out - allow dragging on the text areas too */
/* Extra padding inside and out - allow dragging on the text areas too. */
if (in_out == SOCK_IN) {
rect.xmax += NODE_SOCKSIZE;
rect.xmin -= NODE_SOCKSIZE * 4;
@ -1312,7 +1307,7 @@ static void node_duplicate_reparent_recursive(bNodeTree *ntree,
node->flag |= NODE_TEST;
/* find first selected parent */
/* Find first selected parent. */
for (parent = node->parent; parent; parent = parent->parent) {
if (parent->flag & SELECT) {
if (!(parent->flag & NODE_TEST)) {
@ -1321,7 +1316,7 @@ static void node_duplicate_reparent_recursive(bNodeTree *ntree,
break;
}
}
/* reparent node copy to parent copy */
/* Reparent node copy to parent copy. */
if (parent) {
nodeDetachNode(ntree, node_map.lookup(node));
nodeAttachNode(ntree, node_map.lookup(node), node_map.lookup(parent));
@ -1368,9 +1363,8 @@ static int node_duplicate_exec(bContext *C, wmOperator *op)
/* Copy links between selected nodes. */
bNodeLink *lastlink = (bNodeLink *)ntree->links.last;
LISTBASE_FOREACH (bNodeLink *, link, &ntree->links) {
/* This creates new links between copied nodes.
* If keep_inputs is set, also copies input links from unselected (when fromnode==nullptr)!
*/
/* This creates new links between copied nodes. If keep_inputs is set, also copies input links
* from unselected (when fromnode is null)! */
if (link->tonode && (link->tonode->flag & NODE_SELECT) &&
(keep_inputs || (link->fromnode && (link->fromnode->flag & NODE_SELECT)))) {
bNodeLink *newlink = MEM_cnew<bNodeLink>("bNodeLink");
@ -1387,7 +1381,7 @@ static int node_duplicate_exec(bContext *C, wmOperator *op)
newlink->fromsock = socket_map.lookup(link->fromsock);
}
else {
/* input node not copied, this keeps the original input linked */
/* Input node not copied, this keeps the original input linked. */
newlink->fromnode = link->fromnode;
newlink->fromsock = link->fromsock;
}
@ -1395,24 +1389,24 @@ static int node_duplicate_exec(bContext *C, wmOperator *op)
BLI_addtail(&ntree->links, newlink);
}
/* make sure we don't copy new links again! */
/* Make sure we don't copy new links again. */
if (link == lastlink) {
break;
}
}
/* clear flags for recursive depth-first iteration */
/* Clear flags for recursive depth-first iteration. */
for (bNode *node : ntree->all_nodes()) {
node->flag &= ~NODE_TEST;
}
/* reparent copied nodes */
/* Reparent copied nodes. */
for (bNode *node : node_map.keys()) {
if (!(node->flag & NODE_TEST)) {
node_duplicate_reparent_recursive(ntree, node_map, node);
}
}
/* deselect old nodes, select the copies instead */
/* Deselect old nodes, select the copies instead. */
for (const auto item : node_map.items()) {
bNode *src_node = item.key;
bNode *dst_node = item.value;
@ -1453,9 +1447,7 @@ void NODE_OT_duplicate(wmOperatorType *ot)
RNA_def_property_flag(prop, PROP_SKIP_SAVE);
}
/* XXX: some code needing updating to operators. */
/* goes over all scenes, reads render layers */
/* Goes over all scenes, reads render layers. */
static int node_read_viewlayers_exec(bContext *C, wmOperator * /*op*/)
{
Main *bmain = CTX_data_main(C);
@ -1492,7 +1484,6 @@ static int node_read_viewlayers_exec(bContext *C, wmOperator * /*op*/)
void NODE_OT_read_viewlayers(wmOperatorType *ot)
{
ot->name = "Read View Layers";
ot->idname = "NODE_OT_read_viewlayers";
ot->description = "Read all render layers of all used scenes";
@ -1500,9 +1491,6 @@ void NODE_OT_read_viewlayers(wmOperatorType *ot)
ot->exec = node_read_viewlayers_exec;
ot->poll = composite_node_active;
/* flags */
ot->flag = 0;
}
int node_render_changed_exec(bContext *C, wmOperator * /*op*/)
@ -1563,15 +1551,14 @@ void NODE_OT_render_changed(wmOperatorType *ot)
/** \name Node Hide Operator
* \{ */
/**
* Toggles the flag on all selected nodes. If the flag is set on all nodes it is unset.
* If the flag is not set on all nodes, it is set.
*/
static void node_flag_toggle_exec(SpaceNode *snode, int toggle_flag)
{
int tot_eq = 0, tot_neq = 0;
/* Toggles the flag on all selected nodes.
* If the flag is set on all nodes it is unset.
* If the flag is not set on all nodes, it is set.
*/
for (bNode *node : snode->edittree->all_nodes()) {
if (node->flag & SELECT) {
@ -1616,7 +1603,7 @@ static int node_hide_toggle_exec(bContext *C, wmOperator * /*op*/)
{
SpaceNode *snode = CTX_wm_space_node(C);
/* sanity checking (poll callback checks this already) */
/* Sanity checking (poll callback checks this already). */
if ((snode == nullptr) || (snode->edittree == nullptr)) {
return OPERATOR_CANCELLED;
}
@ -1647,7 +1634,7 @@ static int node_preview_toggle_exec(bContext *C, wmOperator * /*op*/)
{
SpaceNode *snode = CTX_wm_space_node(C);
/* sanity checking (poll callback checks this already) */
/* Sanity checking (poll callback checks this already). */
if ((snode == nullptr) || (snode->edittree == nullptr)) {
return OPERATOR_CANCELLED;
}
@ -1720,7 +1707,7 @@ static int node_options_toggle_exec(bContext *C, wmOperator * /*op*/)
{
SpaceNode *snode = CTX_wm_space_node(C);
/* sanity checking (poll callback checks this already) */
/* Sanity checking (poll callback checks this already). */
if ((snode == nullptr) || (snode->edittree == nullptr)) {
return OPERATOR_CANCELLED;
}
@ -1751,7 +1738,7 @@ static int node_socket_toggle_exec(bContext *C, wmOperator * /*op*/)
{
SpaceNode *snode = CTX_wm_space_node(C);
/* sanity checking (poll callback checks this already) */
/* Sanity checking (poll callback checks this already). */
if ((snode == nullptr) || (snode->edittree == nullptr)) {
return OPERATOR_CANCELLED;
}
@ -1899,7 +1886,7 @@ static int node_switch_view_exec(bContext *C, wmOperator * /*op*/)
LISTBASE_FOREACH_MUTABLE (bNode *, node, &snode->edittree->nodes) {
if (node->flag & SELECT) {
/* call the update function from the Switch View node */
/* Call the update function from the Switch View node. */
node->runtime->update = NODE_UPDATE_OPERATOR;
}
}
@ -2224,7 +2211,7 @@ static int ntree_socket_add_exec(bContext *C, wmOperator *op)
bNodeSocket *sock;
if (active_sock) {
/* insert a copy of the active socket right after it */
/* Insert a copy of the active socket right after it. */
sock = ntreeInsertSocketInterface(
ntree, in_out, active_sock->idname, active_sock->next, active_sock->name);
/* XXX this only works for actual sockets, not interface templates! */
@ -2239,7 +2226,7 @@ static int ntree_socket_add_exec(bContext *C, wmOperator *op)
LISTBASE_FOREACH (bNodeSocket *, socket_iter, sockets) {
socket_iter->flag &= ~SELECT;
}
/* make the new socket active */
/* Make the new socket selected. */
sock->flag |= SELECT;
ED_node_tree_propagate_change(C, CTX_data_main(C), snode->edittree);
@ -2284,11 +2271,11 @@ static int ntree_socket_remove_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
}
/* preferably next socket becomes active, otherwise try previous socket */
/* Preferably next socket becomes active, otherwise try previous socket. */
bNodeSocket *active_sock = (iosock->next ? iosock->next : iosock->prev);
ntreeRemoveSocketInterface(ntree, iosock);
/* set active socket */
/* Set active socket. */
if (active_sock) {
active_sock->flag |= SELECT;
}
@ -2510,12 +2497,12 @@ static bool node_shader_script_update_poll(bContext *C)
const RenderEngineType *type = RE_engines_find(scene->r.engine);
SpaceNode *snode = CTX_wm_space_node(C);
/* test if we have a render engine that supports shaders scripts */
/* Test if we have a render engine that supports shaders scripts. */
if (!(type && type->update_script_node)) {
return false;
}
/* see if we have a shader script node in context */
/* See if we have a shader script node in context. */
bNode *node = (bNode *)CTX_data_pointer_get_type(C, "node", &RNA_ShaderNodeScript).data;
if (!node && snode && snode->edittree) {
@ -2530,13 +2517,13 @@ static bool node_shader_script_update_poll(bContext *C)
}
}
/* see if we have a text datablock in context */
/* See if we have a text datablock in context. */
Text *text = (Text *)CTX_data_pointer_get_type(C, "edit_text", &RNA_Text).data;
if (text) {
return true;
}
/* we don't check if text datablock is actually in use, too slow for poll */
/* We don't check if text datablock is actually in use, too slow for poll. */
return false;
}
@ -2552,7 +2539,7 @@ static bool node_shader_script_update_text_recursive(RenderEngine *engine,
done_trees.add_new(ntree);
/* update each script that is using this text datablock */
/* Update each script that is using this text datablock. */
for (bNode *node : ntree->all_nodes()) {
if (node->type == NODE_GROUP) {
bNodeTree *ngroup = (bNodeTree *)node->id;
@ -2582,7 +2569,6 @@ static int node_shader_script_update_exec(bContext *C, wmOperator *op)
RenderEngine *engine = RE_engine_create(type);
engine->reports = op->reports;
/* get node */
bNodeTree *ntree_base = nullptr;
bNode *node = nullptr;
if (nodeptr.data) {
@ -2595,13 +2581,13 @@ static int node_shader_script_update_exec(bContext *C, wmOperator *op)
}
if (node) {
/* update single node */
/* Update single node. */
type->update_script_node(engine, ntree_base, node);
found = true;
}
else {
/* update all nodes using text datablock */
/* Update all nodes using text datablock. */
Text *text = (Text *)CTX_data_pointer_get_type(C, "edit_text", &RNA_Text).data;
if (text) {
@ -2683,17 +2669,17 @@ static int viewer_border_exec(bContext *C, wmOperator *op)
rcti rect;
rctf rectf;
/* get border from operator */
/* Get border from operator. */
WM_operator_properties_border_to_rcti(op, &rect);
/* convert border to unified space within backdrop image */
/* Convert border to unified space within backdrop image. */
viewer_border_corner_to_backdrop(
snode, region, rect.xmin, rect.ymin, ibuf->x, ibuf->y, &rectf.xmin, &rectf.ymin);
viewer_border_corner_to_backdrop(
snode, region, rect.xmax, rect.ymax, ibuf->x, ibuf->y, &rectf.xmax, &rectf.ymax);
/* clamp coordinates */
/* Clamp coordinates. */
rectf.xmin = max_ff(rectf.xmin, 0.0f);
rectf.ymin = max_ff(rectf.ymin, 0.0f);
rectf.xmax = min_ff(rectf.xmax, 1.0f);

View File

@ -55,13 +55,13 @@
struct NodeInsertOfsData {
bNodeTree *ntree;
bNode *insert; /* inserted node */
bNode *prev, *next; /* prev/next node in the chain */
bNode *insert; /* Inserted node. */
bNode *prev, *next; /* Prev/next node in the chain. */
bNode *insert_parent;
wmTimer *anim_timer;
float offset_x; /* offset to apply to node chain */
float offset_x; /* Offset to apply to node chain. */
};
namespace blender::ed::space_node {
@ -188,7 +188,7 @@ static bNodeSocket *best_socket_output(bNodeTree *ntree,
bNodeSocket *sock_target,
const bool allow_multiple)
{
/* first look for selected output */
/* First look for selected output. */
LISTBASE_FOREACH (bNodeSocket *, sock, &node->outputs) {
if (!socket_is_available(ntree, sock, allow_multiple)) {
continue;
@ -199,13 +199,13 @@ static bNodeSocket *best_socket_output(bNodeTree *ntree,
}
}
/* try to find a socket with a matching name */
/* Try to find a socket with a matching name. */
LISTBASE_FOREACH (bNodeSocket *, sock, &node->outputs) {
if (!socket_is_available(ntree, sock, allow_multiple)) {
continue;
}
/* check for same types */
/* Check for same types. */
if (sock->type == sock_target->type) {
if (STREQ(sock->name, sock_target->name)) {
return sock;
@ -213,13 +213,13 @@ static bNodeSocket *best_socket_output(bNodeTree *ntree,
}
}
/* otherwise settle for the first available socket of the right type */
/* Otherwise settle for the first available socket of the right type. */
LISTBASE_FOREACH (bNodeSocket *, sock, &node->outputs) {
if (!socket_is_available(ntree, sock, allow_multiple)) {
continue;
}
/* check for same types */
/* Check for same types. */
if (sock->type == sock_target->type) {
return sock;
}
@ -234,8 +234,8 @@ static bNodeSocket *best_socket_output(bNodeTree *ntree,
return nullptr;
}
/* this is a bit complicated, but designed to prioritize finding
* sockets of higher types, such as image, first */
/* This is a bit complicated, but designed to prioritize finding
* sockets of higher types, such as image, first. */
static bNodeSocket *best_socket_input(bNodeTree *ntree, bNode *node, int num, int replace)
{
int maxtype = 0;
@ -243,7 +243,7 @@ static bNodeSocket *best_socket_input(bNodeTree *ntree, bNode *node, int num, in
maxtype = max_ii(sock->type, maxtype);
}
/* find sockets of higher 'types' first (i.e. image) */
/* Find sockets of higher 'types' first (i.e. image). */
int a = 0;
for (int socktype = maxtype; socktype >= 0; socktype--) {
LISTBASE_FOREACH (bNodeSocket *, sock, &node->inputs) {
@ -253,8 +253,8 @@ static bNodeSocket *best_socket_input(bNodeTree *ntree, bNode *node, int num, in
}
if (sock->type == socktype) {
/* increment to make sure we don't keep finding
* the same socket on every attempt running this function */
/* Increment to make sure we don't keep finding the same socket on every attempt running
* this function. */
a++;
if (a > num) {
return sock;
@ -275,7 +275,6 @@ static bool snode_autoconnect_input(SpaceNode &snode,
{
bNodeTree *ntree = snode.edittree;
/* then we can connect */
if (replace) {
nodeRemSocketLinks(ntree, sock_to);
}
@ -357,12 +356,12 @@ static void snode_autoconnect(SpaceNode &snode, const bool allow_multiple, const
bNode *node_fr = sorted_nodes[i];
bNode *node_to = sorted_nodes[i + 1];
/* corner case: input/output node aligned the wrong way around (T47729) */
/* Corner case: input/output node aligned the wrong way around (T47729). */
if (BLI_listbase_is_empty(&node_to->inputs) || BLI_listbase_is_empty(&node_fr->outputs)) {
SWAP(bNode *, node_fr, node_to);
}
/* if there are selected sockets, connect those */
/* If there are selected sockets, connect those. */
LISTBASE_FOREACH (bNodeSocket *, sock_to, &node_to->inputs) {
if (sock_to->flag & SELECT) {
has_selected_inputs = true;
@ -371,7 +370,7 @@ static void snode_autoconnect(SpaceNode &snode, const bool allow_multiple, const
continue;
}
/* check for an appropriate output socket to connect from */
/* Check for an appropriate output socket to connect from. */
bNodeSocket *sock_fr = best_socket_output(ntree, node_fr, sock_to, allow_multiple);
if (!sock_fr) {
continue;
@ -384,18 +383,18 @@ static void snode_autoconnect(SpaceNode &snode, const bool allow_multiple, const
}
if (!has_selected_inputs) {
/* no selected inputs, connect by finding suitable match */
/* No selected inputs, connect by finding suitable match. */
int num_inputs = BLI_listbase_count(&node_to->inputs);
for (int i = 0; i < num_inputs; i++) {
/* find the best guess input socket */
/* Find the best guess input socket. */
bNodeSocket *sock_to = best_socket_input(ntree, node_to, i, replace);
if (!sock_to) {
continue;
}
/* check for an appropriate output socket to connect from */
/* Check for an appropriate output socket to connect from. */
bNodeSocket *sock_fr = best_socket_output(ntree, node_fr, sock_to, allow_multiple);
if (!sock_fr) {
continue;
@ -902,9 +901,7 @@ static void add_dragged_links_to_tree(bContext &C, bNodeLinkDrag &nldrag)
if (!link.tosock || !link.fromsock) {
continue;
}
/* before actually adding the link,
* let nodes perform special link insertion handling
*/
/* Before actually adding the link let nodes perform special link insertion handling. */
bNodeLink *new_link = MEM_new<bNodeLink>(__func__, link);
if (link.fromnode->typeinfo->insert_link) {
link.fromnode->typeinfo->insert_link(&ntree, link.fromnode, new_link);
@ -913,11 +910,11 @@ static void add_dragged_links_to_tree(bContext &C, bNodeLinkDrag &nldrag)
link.tonode->typeinfo->insert_link(&ntree, link.tonode, new_link);
}
/* add link to the node tree */
/* Add link to the node tree. */
BLI_addtail(&ntree.links, new_link);
BKE_ntree_update_tag_link_added(&ntree, new_link);
/* we might need to remove a link */
/* We might need to remove a link. */
node_remove_extra_links(snode, *new_link);
}
@ -952,7 +949,7 @@ static void node_link_find_socket(bContext &C, wmOperator &op, const float2 &cur
if (bNodeSocket *tsock = node_find_indicated_socket(snode, cursor, SOCK_IN)) {
bNode &tnode = tsock->owner_node();
for (bNodeLink &link : nldrag.links) {
/* skip if socket is on the same node as the fromsock */
/* Skip if socket is on the same node as the fromsock. */
if (link.fromnode == &tnode) {
continue;
}
@ -966,7 +963,7 @@ static void node_link_find_socket(bContext &C, wmOperator &op, const float2 &cur
}
}
/* attach links to the socket */
/* Attach links to the socket. */
link.tonode = &tnode;
link.tosock = tsock;
nldrag.last_node_hovered_while_dragging_a_link = &tnode;
@ -995,16 +992,16 @@ static void node_link_find_socket(bContext &C, wmOperator &op, const float2 &cur
if (bNodeSocket *tsock = node_find_indicated_socket(snode, cursor, SOCK_OUT)) {
bNode &node = tsock->owner_node();
for (bNodeLink &link : nldrag.links) {
/* skip if this is already the target socket */
/* Skip if this is already the target socket. */
if (link.fromsock == tsock) {
continue;
}
/* skip if socket is on the same node as the fromsock */
/* Skip if socket is on the same node as the `fromsock`. */
if (link.tonode == &node) {
continue;
}
/* attach links to the socket */
/* Attach links to the socket. */
link.fromnode = &node;
link.fromsock = tsock;
}
@ -1097,9 +1094,9 @@ static std::unique_ptr<bNodeLinkDrag> node_link_init(SpaceNode &snode,
nldrag->start_link_count = nodeCountSocketLinks(snode.edittree, sock);
int link_limit = nodeSocketLinkLimit(sock);
if (nldrag->start_link_count > 0 && (nldrag->start_link_count >= link_limit || detach)) {
/* dragged links are fixed on input side */
/* Dragged links are fixed on input side. */
nldrag->in_out = SOCK_IN;
/* detach current links and store them in the operator data */
/* Detach current links and store them in the operator data. */
LISTBASE_FOREACH_MUTABLE (bNodeLink *, link, &snode.edittree->links) {
if (link->fromsock == sock) {
bNodeLink oplink = *link;
@ -1112,7 +1109,7 @@ static std::unique_ptr<bNodeLinkDrag> node_link_init(SpaceNode &snode,
}
}
else {
/* dragged links are fixed on output side */
/* Dragged links are fixed on output side. */
nldrag->in_out = SOCK_OUT;
nldrag->links.append(create_drag_link(node, *sock));
}
@ -1128,9 +1125,9 @@ static std::unique_ptr<bNodeLinkDrag> node_link_init(SpaceNode &snode,
nldrag->start_link_count = nodeCountSocketLinks(snode.edittree, sock);
if (nldrag->start_link_count > 0) {
/* dragged links are fixed on output side */
/* Dragged links are fixed on output side. */
nldrag->in_out = SOCK_OUT;
/* detach current links and store them in the operator data */
/* Detach current links and store them in the operator data. */
bNodeLink *link_to_pick;
LISTBASE_FOREACH_MUTABLE (bNodeLink *, link, &snode.edittree->links) {
if (link->tosock == sock) {
@ -1146,12 +1143,12 @@ static std::unique_ptr<bNodeLinkDrag> node_link_init(SpaceNode &snode,
nldrag->links.append(oplink);
nodeRemLink(snode.edittree, link_to_pick);
/* send changed event to original link->tonode */
/* Send changed event to original link->tonode. */
BKE_ntree_update_tag_node_property(snode.edittree, &node);
}
}
else {
/* dragged links are fixed on input side */
/* Dragged links are fixed on input side. */
nldrag->in_out = SOCK_IN;
nldrag->links.append(create_drag_link(node, *sock));
}
@ -1207,7 +1204,6 @@ void NODE_OT_link(wmOperatorType *ot)
/* api callbacks */
ot->invoke = node_link_invoke;
ot->modal = node_link_modal;
// ot->exec = node_link_exec;
ot->poll = ED_operator_node_editable;
ot->cancel = node_link_cancel;
@ -1241,7 +1237,7 @@ void NODE_OT_link(wmOperatorType *ot)
/** \name Make Link Operator
* \{ */
/* makes a link between selected output and input sockets */
/* 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);
@ -1253,7 +1249,7 @@ static int node_make_link_exec(bContext *C, wmOperator *op)
snode_autoconnect(snode, true, replace);
/* deselect sockets after linking */
/* Deselect sockets after linking. */
node_deselect_all_input_sockets(node_tree, false);
node_deselect_all_output_sockets(node_tree, false);
@ -1716,14 +1712,14 @@ static int node_attach_invoke(bContext *C, wmOperator * /*op*/, const wmEvent *e
}
if (node->parent == nullptr) {
/* disallow moving a parent into its child */
/* Disallow moving a parent into its child. */
if (nodeAttachNodeCheck(frame, node) == false) {
/* attach all unparented nodes */
/* Attach all unparented nodes. */
nodeAttachNode(&ntree, node, frame);
}
}
else {
/* attach nodes which share parent with the frame */
/* Attach nodes which share parent with the frame. */
bNode *parent;
for (parent = frame->parent; parent; parent = parent->parent) {
if (parent == node->parent) {
@ -1732,7 +1728,7 @@ static int node_attach_invoke(bContext *C, wmOperator * /*op*/, const wmEvent *e
}
if (parent) {
/* disallow moving a parent into its child */
/* Disallow moving a parent into its child. */
if (nodeAttachNodeCheck(frame, node) == false) {
nodeDetachNode(&ntree, node);
nodeAttachNode(&ntree, node, frame);
@ -1781,17 +1777,17 @@ static void node_detach_recursive(bNodeTree &ntree,
detach_states[node->index()].done = true;
if (node->parent) {
/* call recursively */
/* Call recursively. */
if (!detach_states[node->parent->index()].done) {
node_detach_recursive(ntree, detach_states, node->parent);
}
/* in any case: if the parent is a descendant, so is the child */
/* In any case: if the parent is a descendant, so is the child. */
if (detach_states[node->parent->index()].descendent) {
detach_states[node->index()].descendent = true;
}
else if (node->flag & NODE_SELECT) {
/* if parent is not a descendant of a selected node, detach */
/* If parent is not a descendant of a selected node, detach. */
nodeDetachNode(&ntree, node);
detach_states[node->index()].descendent = true;
}
@ -1801,7 +1797,7 @@ static void node_detach_recursive(bNodeTree &ntree,
}
}
/* detach the root nodes in the current selection */
/* Detach the root nodes in the current selection. */
static int node_detach_exec(bContext *C, wmOperator * /*op*/)
{
SpaceNode &snode = *CTX_wm_space_node(C);
@ -1809,9 +1805,7 @@ static int node_detach_exec(bContext *C, wmOperator * /*op*/)
Array<NodeDetachstate> detach_states(ntree.all_nodes().size(), NodeDetachstate{false, false});
/* detach nodes recursively
* relative order is preserved here!
*/
/* Detach nodes recursively. Relative order is preserved here. */
for (bNode *node : ntree.all_nodes()) {
if (!detach_states[node->index()].done) {
node_detach_recursive(ntree, detach_states, node);
@ -1889,7 +1883,7 @@ void node_insert_on_link_flags_set(SpaceNode &snode, const ARegion &region)
return;
}
/* find link to select/highlight */
/* Find link to select/highlight. */
bNodeLink *selink = nullptr;
float dist_best = FLT_MAX;
LISTBASE_FOREACH (bNodeLink *, link, &node_tree.links) {
@ -1901,23 +1895,22 @@ void node_insert_on_link_flags_set(SpaceNode &snode, const ARegion &region)
node_link_bezier_points_evaluated(*link, coords);
float dist = FLT_MAX;
/* loop over link coords to find shortest dist to
* upper left node edge of a intersected line segment */
/* Loop over link coords to find shortest dist to upper left node edge of a intersected line
* segment. */
for (int i = 0; i < NODE_LINK_RESOL; i++) {
/* Check if the node rectangle intersects the line from this point to next one. */
if (BLI_rctf_isect_segment(&node_to_insert->runtime->totr, coords[i], coords[i + 1])) {
/* store the shortest distance to the upper left edge
* of all intersections found so far */
/* Store the shortest distance to the upper left edge of all intersections found so far. */
const float node_xy[] = {node_to_insert->runtime->totr.xmin,
node_to_insert->runtime->totr.ymax};
/* to be precise coords should be clipped by select->totr,
* but not done since there's no real noticeable difference */
/* To be precise coords should be clipped by `select->totr`, but not done since there's no
* real noticeable difference. */
dist = min_ff(dist_squared_to_line_segment_v2(node_xy, coords[i], coords[i + 1]), dist);
}
}
/* we want the link with the shortest distance to node center */
/* We want the link with the shortest distance to node center. */
if (dist < dist_best) {
dist_best = dist;
selink = link;
@ -2070,7 +2063,7 @@ bNodeSocket *get_main_socket(bNodeTree &ntree, bNode &node, eNodeSocketInOut in_
}
}
/* find priority range */
/* Find priority range. */
int maxpriority = -1;
LISTBASE_FOREACH (bNodeSocket *, sock, sockets) {
if (sock->flag & SOCK_UNAVAIL) {
@ -2079,7 +2072,7 @@ bNodeSocket *get_main_socket(bNodeTree &ntree, bNode &node, eNodeSocketInOut in_
maxpriority = max_ii(get_main_socket_priority(sock), maxpriority);
}
/* try all priorities, starting from 'highest' */
/* Try all priorities, starting from 'highest'. */
for (int priority = maxpriority; priority >= 0; priority--) {
LISTBASE_FOREACH (bNodeSocket *, sock, sockets) {
if (!!sock->is_visible() && priority == get_main_socket_priority(sock)) {
@ -2088,7 +2081,7 @@ bNodeSocket *get_main_socket(bNodeTree &ntree, bNode &node, eNodeSocketInOut in_
}
}
/* no visible sockets, unhide first of highest priority */
/* No visible sockets, unhide first of highest priority. */
for (int priority = maxpriority; priority >= 0; priority--) {
LISTBASE_FOREACH (bNodeSocket *, sock, sockets) {
if (sock->flag & SOCK_UNAVAIL) {
@ -2236,13 +2229,13 @@ static void node_link_insert_offset_ntree(NodeInsertOfsData *iofsd,
rctf 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 */
/* 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);
/* this makes sure nodes are also correctly offset when inserting a node on top of a frame
/* 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 */
* - logic here is similar to node_find_frame_to_attach. */
if (!insert.parent ||
(prev->parent && (prev->parent == next->parent) && (prev->parent != insert.parent))) {
bNode *frame;

View File

@ -262,7 +262,7 @@ void node_deselect_all_input_sockets(bNodeTree &node_tree, const bool deselect_n
socket->flag &= ~SELECT;
}
/* if no selected sockets remain, also deselect the node */
/* If no selected sockets remain, also deselect the node. */
if (deselect_nodes) {
LISTBASE_FOREACH (bNodeSocket *, socket, &node->outputs) {
if (socket->flag & SELECT) {
@ -530,18 +530,18 @@ static bool node_mouse_select(bContext *C,
bNode *node = nullptr;
bNodeSocket *sock = nullptr;
/* always do socket_select when extending selection. */
/* Always do socket_select when extending selection. */
const bool socket_select = (params->sel_op == SEL_OP_XOR) ||
RNA_boolean_get(op->ptr, "socket_select");
bool changed = false;
bool found = false;
bool node_was_selected = false;
/* get mouse coordinates in view2d space */
/* Get mouse coordinates in view2d space. */
float2 cursor;
UI_view2d_region_to_view(&region.v2d, mval.x, mval.y, &cursor.x, &cursor.y);
/* first do socket selection, these generally overlap with nodes. */
/* First do socket selection, these generally overlap with nodes. */
if (socket_select) {
/* NOTE: unlike nodes #SelectPick_Params isn't fully supported. */
const bool extend = (params->sel_op == SEL_OP_XOR);
@ -599,7 +599,7 @@ static bool node_mouse_select(bContext *C,
if (!sock) {
/* find the closest visible node */
/* Find the closest visible node. */
node = node_under_mouse_select(node_tree, cursor);
found = (node != nullptr);
node_was_selected = node && (node->flag & SELECT);
@ -617,28 +617,25 @@ static bool node_mouse_select(bContext *C,
if (found) {
switch (params->sel_op) {
case SEL_OP_ADD: {
case SEL_OP_ADD:
nodeSetSelected(node, true);
break;
}
case SEL_OP_SUB: {
case SEL_OP_SUB:
nodeSetSelected(node, false);
break;
}
case SEL_OP_XOR: {
/* Check active so clicking on an inactive node activates it. */
bool is_selected = (node->flag & NODE_SELECT) && (node->flag & NODE_ACTIVE);
nodeSetSelected(node, !is_selected);
break;
}
case SEL_OP_SET: {
case SEL_OP_SET:
nodeSetSelected(node, true);
break;
}
case SEL_OP_AND: {
BLI_assert_unreachable(); /* Doesn't make sense for picking. */
case SEL_OP_AND:
/* Doesn't make sense for picking. */
BLI_assert_unreachable();
break;
}
}
changed = true;
@ -681,20 +678,20 @@ static bool node_mouse_select(bContext *C,
static int node_select_exec(bContext *C, wmOperator *op)
{
/* get settings from RNA properties for operator */
/* Get settings from RNA properties for operator. */
int2 mval;
RNA_int_get_array(op->ptr, "location", mval);
SelectPick_Params params = {};
ED_select_pick_params_from_operator(op->ptr, &params);
/* perform the select */
/* Perform the selection. */
const bool changed = node_mouse_select(C, op, mval, &params);
if (changed) {
return OPERATOR_PASS_THROUGH | OPERATOR_FINISHED;
}
/* Nothing selected, just passthrough. */
/* Nothing selected, just pass through. */
return OPERATOR_PASS_THROUGH | OPERATOR_CANCELLED;
}
@ -962,10 +959,9 @@ static bool do_lasso_select_node(bContext *C,
changed = true;
}
/* get rectangle from operator */
/* Get rectangle from operator. */
BLI_lasso_boundbox(&rect, mcoords, mcoords_len);
/* do actual selection */
for (bNode *node : node_tree.all_nodes()) {
if (select && (node->flag & NODE_SELECT)) {
continue;
@ -1389,7 +1385,7 @@ static uiBlock *node_find_menu(bContext *C, ARegion *region, void *arg_op)
but, nullptr, node_find_update_fn, op->type, false, nullptr, node_find_exec_fn, nullptr);
UI_but_flag_enable(but, UI_BUT_ACTIVATE_ON_INIT);
/* fake button, it holds space for search items */
/* Fake button holds space for search items. */
uiDefBut(block,
UI_BTYPE_LABEL,
0,