Skip to content

Commit

Permalink
Merge pull request #79311 from Geometror/rework-graphnode
Browse files Browse the repository at this point in the history
Clean up/refactor GraphNode and make it more flexible
  • Loading branch information
akien-mga committed Sep 8, 2023
2 parents 0bca424 + 5afe78b commit 2167694
Show file tree
Hide file tree
Showing 26 changed files with 1,548 additions and 1,485 deletions.
18 changes: 9 additions & 9 deletions doc/classes/GraphEdit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@
<param index="2" name="mouse_position" type="Vector2" />
<description>
Returns whether the [param mouse_position] is in the input hot zone.
By default, a hot zone is a [Rect2] positioned such that its center is at [param in_node].[method GraphNode.get_connection_input_position]([param in_port]) (For output's case, call [method GraphNode.get_connection_output_position] instead). The hot zone's width is twice the Theme Property [code]port_grab_distance_horizontal[/code], and its height is twice the [code]port_grab_distance_vertical[/code].
By default, a hot zone is a [Rect2] positioned such that its center is at [param in_node].[method GraphNode.get_input_port_position]([param in_port]) (For output's case, call [method GraphNode.get_output_port_position] instead). The hot zone's width is twice the Theme Property [code]port_grab_distance_horizontal[/code], and its height is twice the [code]port_grab_distance_vertical[/code].
Below is a sample code to help get started:
[codeblock]
func _is_in_input_hotzone(in_node, in_port, mouse_position):
var port_size: Vector2 = Vector2(get_theme_constant("port_grab_distance_horizontal"), get_theme_constant("port_grab_distance_vertical"))
var port_pos: Vector2 = in_node.get_position() + in_node.get_connection_input_position(in_port) - port_size / 2
var port_pos: Vector2 = in_node.get_position() + in_node.get_input_port_position(in_port) - port_size / 2
var rect = Rect2(port_pos, port_size)

return rect.has_point(mouse_position)
Expand All @@ -49,7 +49,7 @@
[codeblock]
func _is_in_output_hotzone(in_node, in_port, mouse_position):
var port_size: Vector2 = Vector2(get_theme_constant("port_grab_distance_horizontal"), get_theme_constant("port_grab_distance_vertical"))
var port_pos: Vector2 = in_node.get_position() + in_node.get_connection_output_position(in_port) - port_size / 2
var port_pos: Vector2 = in_node.get_position() + in_node.get_output_port_position(in_port) - port_size / 2
var rect = Rect2(port_pos, port_size)

return rect.has_point(mouse_position)
Expand Down Expand Up @@ -289,6 +289,12 @@
Emitted at the beginning of a GraphNode movement.
</description>
</signal>
<signal name="close_nodes_request">
<param index="0" name="nodes" type="StringName[]" />
<description>
Emitted when attempting to remove a GraphNode from the GraphEdit. Provides a list of node names to be removed (all selected nodes, excluding nodes without closing button).
</description>
</signal>
<signal name="connection_drag_ended">
<description>
Emitted at the end of a connection drag.
Expand Down Expand Up @@ -332,12 +338,6 @@
Emitted when the user presses [kbd]Ctrl + C[/kbd].
</description>
</signal>
<signal name="delete_nodes_request">
<param index="0" name="nodes" type="StringName[]" />
<description>
Emitted when a GraphNode is attempted to be removed from the GraphEdit. Provides a list of node names to be removed (all selected nodes, excluding nodes without closing button).
</description>
</signal>
<signal name="disconnection_request">
<param index="0" name="from_node" type="StringName" />
<param index="1" name="from_port" type="int" />
Expand Down
69 changes: 69 additions & 0 deletions doc/classes/GraphElement.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="GraphElement" inherits="Container" is_experimental="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
<brief_description>
A container that represents a basic element that can be placed inside a [GraphEdit] control.
</brief_description>
<description>
[GraphElement] allows to create custom elements for a [GraphEdit] graph. By default such elements can be selected, resized, and repositioned, but they cannot be connected. For a graph element that allows for connections see [GraphNode].
</description>
<tutorials>
</tutorials>
<members>
<member name="draggable" type="bool" setter="set_draggable" getter="is_draggable" default="true">
If [code]true[/code], the user can drag the GraphElement.
</member>
<member name="position_offset" type="Vector2" setter="set_position_offset" getter="get_position_offset" default="Vector2(0, 0)">
The offset of the GraphElement, relative to the scroll offset of the [GraphEdit].
</member>
<member name="resizable" type="bool" setter="set_resizable" getter="is_resizable" default="false">
If [code]true[/code], the user can resize the GraphElement.
[b]Note:[/b] Dragging the handle will only emit the [signal resize_request] signal, the GraphElement needs to be resized manually.
</member>
<member name="selectable" type="bool" setter="set_selectable" getter="is_selectable" default="true">
If [code]true[/code], the user can select the GraphElement.
</member>
<member name="selected" type="bool" setter="set_selected" getter="is_selected" default="false">
If [code]true[/code], the GraphElement is selected.
</member>
</members>
<signals>
<signal name="close_request">
<description>
Emitted when closing the GraphElement is requested.
</description>
</signal>
<signal name="dragged">
<param index="0" name="from" type="Vector2" />
<param index="1" name="to" type="Vector2" />
<description>
Emitted when the GraphElement is dragged.
</description>
</signal>
<signal name="node_deselected">
<description>
Emitted when the GraphElement is deselected.
</description>
</signal>
<signal name="node_selected">
<description>
Emitted when the GraphElement is selected.
</description>
</signal>
<signal name="position_offset_changed">
<description>
Emitted when the GraphElement is moved.
</description>
</signal>
<signal name="raise_request">
<description>
Emitted when displaying the GraphElement over other ones is requested. Happens on focusing (clicking into) the GraphElement.
</description>
</signal>
<signal name="resize_request">
<param index="0" name="new_minsize" type="Vector2" />
<description>
Emitted when resizing the GraphElement is requested. Happens on dragging the resizer handle (see [member resizable]).
</description>
</signal>
</signals>
</class>
Loading

0 comments on commit 2167694

Please sign in to comment.