Cleanup: Make node editor functions private

These operations (sorting and selecting all nodes) should generally
be handled by the node editor and not outside code. They were not
called outside of the node editor, so they can be moved to the editor's
`intern` header.
This commit is contained in:
Hans Goudey 2022-01-18 13:07:18 -06:00
parent 09ecb089a5
commit 977baeaa26
6 changed files with 28 additions and 27 deletions

View File

@ -101,11 +101,6 @@ void ED_node_socket_draw(struct bNodeSocket *sock,
void ED_node_tree_update(const struct bContext *C);
void ED_node_tag_update_id(struct ID *id);
/**
* Sort nodes by selection: unselected nodes first, then selected,
* then the active node at the very end. Relative order is kept intact.
*/
void ED_node_sort(struct bNodeTree *ntree);
float ED_node_grid_size(void);
/* node_relationships.c */
@ -142,8 +137,6 @@ void ED_node_composit_default(const struct bContext *C, struct Scene *scene);
* Called from shading buttons or header.
*/
void ED_node_texture_default(const struct bContext *C, struct Tex *tex);
bool ED_node_select_check(const ListBase *lb);
void ED_node_select_all(ListBase *lb, int action);
void ED_node_post_apply_transform(struct bContext *C, struct bNodeTree *ntree);
void ED_node_set_active(struct Main *bmain,
struct SpaceNode *snode,

View File

@ -232,7 +232,7 @@ static bool compare_nodes(const bNode *a, const bNode *b)
return false;
}
void ED_node_sort(bNodeTree *ntree)
void node_sort(bNodeTree *ntree)
{
/* Merge sort is the algorithm of choice here. */
int totnodes = BLI_listbase_count(&ntree->nodes);

View File

@ -1381,7 +1381,7 @@ void NODE_OT_duplicate(wmOperatorType *ot)
ot->srna, "keep_inputs", false, "Keep Inputs", "Keep the input links to duplicated nodes");
}
bool ED_node_select_check(const ListBase *lb)
static bool node_select_check(const ListBase *lb)
{
LISTBASE_FOREACH (const bNode *, node, lb) {
if (node->flag & NODE_SELECT) {
@ -1392,10 +1392,10 @@ bool ED_node_select_check(const ListBase *lb)
return false;
}
void ED_node_select_all(ListBase *lb, int action)
void node_select_all(ListBase *lb, int action)
{
if (action == SEL_TOGGLE) {
if (ED_node_select_check(lb)) {
if (node_select_check(lb)) {
action = SEL_DESELECT;
}
else {
@ -2063,7 +2063,7 @@ static int node_copy_color_exec(bContext *C, wmOperator *UNUSED(op))
}
}
ED_node_sort(ntree);
node_sort(ntree);
WM_event_add_notifier(C, NC_NODE | ND_DISPLAY, nullptr);
return OPERATOR_FINISHED;

View File

@ -127,6 +127,12 @@ void node_socket_color_get(const bContext &C,
float r_color[4]);
void node_draw_space(const bContext &C, ARegion &region);
/**
* Sort nodes by selection: unselected nodes first, then selected,
* then the active node at the very end. Relative order is kept intact.
*/
void node_sort(bNodeTree *ntree);
void node_set_cursor(wmWindow &win, SpaceNode &snode, const blender::float2 &cursor);
/* DPI scaled coords */
blender::float2 node_to_view(const bNode &node, const blender::float2 &co);
@ -204,6 +210,8 @@ void draw_nodespace_back_pix(const bContext &C,
SpaceNode &snode,
bNodeInstanceKey parent_key);
void node_select_all(ListBase *lb, int action);
/**
* XXX Does some additional initialization on top of #nodeAddNode
* Can be used with both custom and static nodes,

View File

@ -1602,7 +1602,7 @@ static int node_parent_set_exec(bContext *C, wmOperator *UNUSED(op))
}
}
ED_node_sort(ntree);
node_sort(ntree);
WM_event_add_notifier(C, NC_NODE | ND_DISPLAY, nullptr);
return OPERATOR_FINISHED;
@ -1699,7 +1699,7 @@ static int node_join_exec(bContext *C, wmOperator *UNUSED(op))
}
}
ED_node_sort(&ntree);
node_sort(&ntree);
WM_event_add_notifier(C, NC_NODE | ND_DISPLAY, nullptr);
return OPERATOR_FINISHED;
@ -1785,7 +1785,7 @@ static int node_attach_invoke(bContext *C, wmOperator *UNUSED(op), const wmEvent
}
}
ED_node_sort(ntree);
node_sort(ntree);
WM_event_add_notifier(C, NC_NODE | ND_DISPLAY, nullptr);
return OPERATOR_FINISHED;
@ -1861,7 +1861,7 @@ static int node_detach_exec(bContext *C, wmOperator *UNUSED(op))
}
}
ED_node_sort(ntree);
node_sort(ntree);
WM_event_add_notifier(C, NC_NODE | ND_DISPLAY, nullptr);
return OPERATOR_FINISHED;

View File

@ -400,7 +400,7 @@ static int node_select_grouped_exec(bContext *C, wmOperator *op)
}
if (changed) {
ED_node_sort(snode->edittree);
node_sort(snode->edittree);
WM_event_add_notifier(C, NC_NODE | NA_SELECTED, nullptr);
return OPERATOR_FINISHED;
}
@ -468,7 +468,7 @@ void node_select_single(bContext &C, bNode &node)
ED_node_set_active(bmain, snode, snode->edittree, &node, &active_texture_changed);
ED_node_set_active_viewer_key(snode);
ED_node_sort(snode->edittree);
node_sort(snode->edittree);
if (active_texture_changed && has_workbench_in_texture_color(wm, scene, ob)) {
DEG_id_tag_update(&snode->edittree->id, ID_RECALC_COPY_ON_WRITE);
}
@ -611,7 +611,7 @@ static int node_mouse_select(bContext *C,
ED_spreadsheet_context_paths_set_geometry_node(&bmain, &snode, node);
}
ED_node_set_active_viewer_key(&snode);
ED_node_sort(snode.edittree);
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);
@ -688,7 +688,7 @@ static int node_box_select_exec(bContext *C, wmOperator *op)
const eSelectOp sel_op = (eSelectOp)RNA_enum_get(op->ptr, "mode");
const bool select = (sel_op != SEL_OP_SUB);
if (SEL_OP_USE_PRE_DESELECT(sel_op)) {
ED_node_select_all(&snode->edittree->nodes, SEL_DESELECT);
node_select_all(&snode->edittree->nodes, SEL_DESELECT);
}
LISTBASE_FOREACH (bNode *, node, &snode->edittree->nodes) {
@ -705,7 +705,7 @@ static int node_box_select_exec(bContext *C, wmOperator *op)
}
}
ED_node_sort(snode->edittree);
node_sort(snode->edittree);
WM_event_add_notifier(C, NC_NODE | NA_SELECTED, nullptr);
@ -775,7 +775,7 @@ static int node_circleselect_exec(bContext *C, wmOperator *op)
WM_gesture_is_modal_first((const wmGesture *)op->customdata));
const bool select = (sel_op != SEL_OP_SUB);
if (SEL_OP_USE_PRE_DESELECT(sel_op)) {
ED_node_select_all(&snode->edittree->nodes, SEL_DESELECT);
node_select_all(&snode->edittree->nodes, SEL_DESELECT);
}
/* get operator properties */
@ -850,7 +850,7 @@ static bool do_lasso_select_node(bContext *C,
const bool select = (sel_op != SEL_OP_SUB);
if (SEL_OP_USE_PRE_DESELECT(sel_op)) {
ED_node_select_all(&snode->edittree->nodes, SEL_DESELECT);
node_select_all(&snode->edittree->nodes, SEL_DESELECT);
changed = true;
}
@ -941,9 +941,9 @@ static int node_select_all_exec(bContext *C, wmOperator *op)
ListBase *node_lb = &snode->edittree->nodes;
int action = RNA_enum_get(op->ptr, "action");
ED_node_select_all(node_lb, action);
node_select_all(node_lb, action);
ED_node_sort(snode->edittree);
node_sort(snode->edittree);
WM_event_add_notifier(C, NC_NODE | NA_SELECTED, nullptr);
return OPERATOR_FINISHED;
@ -997,7 +997,7 @@ static int node_select_linked_to_exec(bContext *C, wmOperator *UNUSED(op))
}
}
ED_node_sort(snode->edittree);
node_sort(snode->edittree);
WM_event_add_notifier(C, NC_NODE | NA_SELECTED, nullptr);
return OPERATOR_FINISHED;
@ -1049,7 +1049,7 @@ static int node_select_linked_from_exec(bContext *C, wmOperator *UNUSED(op))
}
}
ED_node_sort(snode->edittree);
node_sort(snode->edittree);
WM_event_add_notifier(C, NC_NODE | NA_SELECTED, nullptr);
return OPERATOR_FINISHED;