Skip to content

Commit

Permalink
GH-738 Fix Select Group to include Knots and Nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
Naros committed Aug 25, 2024
1 parent 0fd2856 commit 48fa31d
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 13 deletions.
17 changes: 17 additions & 0 deletions src/editor/graph/graph_edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,23 @@ void OrchestratorGraphEdit::for_each_graph_node(std::function<void(OrchestratorG
}
}

void OrchestratorGraphEdit::for_each_graph_element(const std::function<void(GraphElement*)>& p_func, bool p_nodes, bool p_knots)
{
const int child_count = get_child_count();
for (int index = 0; index < child_count; index++)
{
GraphElement* element = Object::cast_to<GraphElement>(get_child(index));
if (!element)
continue;

const OrchestratorGraphNode* node = Object::cast_to<OrchestratorGraphNode>(element);
const OrchestratorGraphKnot* knot = Object::cast_to<OrchestratorGraphKnot>(element);

if ((p_nodes && node) || (p_knots && knot))
p_func(element);
}
}

void OrchestratorGraphEdit::execute_action(const String& p_action_name)
{
Ref<InputEventAction> action = memnew(InputEventAction);
Expand Down
6 changes: 6 additions & 0 deletions src/editor/graph/graph_edit.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,12 @@ class OrchestratorGraphEdit : public GraphEdit
/// @param p_func the lambda to be applied
void for_each_graph_node(std::function<void(OrchestratorGraphNode*)> p_func);

/// Perform an action for each <code>GraphNode</code> object type
/// @param p_func the function to call for each graph element
/// @param p_nodes whether <code>OrchestratorGraphNode</code> objects are included, defaults to <code>true</code>
/// @param p_knots whether <code>OrchestratorGraphKnot</code> objects are included, defaults to <code>true</code>
void for_each_graph_element(const std::function<void(GraphElement*)>& p_func, bool p_nodes = true, bool p_knots = true);

/// Execute the specified action
/// @param p_action_name the action to execute
void execute_action(const String& p_action_name);
Expand Down
6 changes: 3 additions & 3 deletions src/editor/graph/graph_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -618,12 +618,12 @@ void OrchestratorGraphNode::_add_option_pin()
function_call_node->add_dynamic_pin();
}

List<OrchestratorGraphNode*> OrchestratorGraphNode::get_nodes_within_global_rect()
List<GraphElement*> OrchestratorGraphNode::get_elements_within_global_rect()
{
Rect2 rect = get_global_rect();

List<OrchestratorGraphNode*> results;
_graph->for_each_graph_node([&](OrchestratorGraphNode* other) {
List<GraphElement*> results;
_graph->for_each_graph_element([&](GraphElement* other) {
if (other && other != this)
{
Rect2 other_rect = other->get_global_rect();
Expand Down
4 changes: 2 additions & 2 deletions src/editor/graph/graph_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ class OrchestratorGraphNode : public GraphNode
/// Set whether node icons are shown
virtual void show_icons(bool p_show_icons) { }

/// Get a list of nodes within this node's global rect.
List<OrchestratorGraphNode*> get_nodes_within_global_rect();
/// Get a list of elements within this node's global rect.
List<GraphElement*> get_elements_within_global_rect();

/// Get the specified point index at the given position and direction
/// @param p_position the position
Expand Down
16 changes: 8 additions & 8 deletions src/editor/graph/nodes/graph_node_comment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ void OrchestratorGraphNodeComment::_on_raise_request()

bool OrchestratorGraphNodeComment::is_group_selected()
{
List<OrchestratorGraphNode*> intersections = get_nodes_within_global_rect();
for (OrchestratorGraphNode* child : intersections)
List<GraphElement*> intersections = get_elements_within_global_rect();
for (GraphElement* child : intersections)
if (!child->is_selected())
return false;
return true;
Expand All @@ -131,24 +131,24 @@ bool OrchestratorGraphNodeComment::is_group_selected()
void OrchestratorGraphNodeComment::select_group()
{
// Select all child nodes
List<OrchestratorGraphNode*> intersections = get_nodes_within_global_rect();
for (OrchestratorGraphNode* child : intersections)
List<GraphElement*> intersections = get_elements_within_global_rect();
for (GraphElement* child : intersections)
child->set_selected(true);
}

void OrchestratorGraphNodeComment::deselect_group()
{
// Deselects all child nodes
List<OrchestratorGraphNode*> intersections = get_nodes_within_global_rect();
for (OrchestratorGraphNode* child : intersections)
List<GraphElement*> intersections = get_elements_within_global_rect();
for (GraphElement* child : intersections)
child->set_selected(false);
}

void OrchestratorGraphNodeComment::raise_request_node_reorder()
{
// This guarantees that any node that intersects with a comment node will be repositioned
// in the scene after the comment, so that the rendering order appears correct.
List<OrchestratorGraphNode*> intersections = get_nodes_within_global_rect();
for (OrchestratorGraphNode* node : intersections)
List<GraphElement*> intersections = get_elements_within_global_rect();
for (GraphElement* node : intersections)
get_parent()->move_child(node, -1);
}

0 comments on commit 48fa31d

Please sign in to comment.