private void DrawNodes() { foreach (TerraNode node in Graph.Nodes) { TerraGUI.DrawNode(node); } }
private void DrawComments() { foreach (GraphComment comment in Graph.Comments) { TerraGUI.DrawComment(comment); } }
private void DrawActiveConnection() { if (HeldSocket == null) { return; } Vector2 output = HeldSocket.SocketType == SocketType.Output ? TerraUtility.GetSocketRect(HeldSocket).center : Event.current.mousePosition; Vector2 input = HeldSocket.SocketType == SocketType.Input ? TerraUtility.GetSocketRect(HeldSocket).center : Event.current.mousePosition; TerraGUI.DrawConnection(output, input, TerraUtility.TypeToColor(HeldSocket.FieldType)); }
public static void ProcessGraphEditorEvents(Event e, TerraGraphEditor window) { switch (e.type) { case EventType.KeyDown: if (e.keyCode == KeyCode.Delete) { foreach (TerraNode node in TerraGraphEditor.NodeSelection) { window.RemoveNode(node); } foreach (GraphComment comment in TerraGraphEditor.CommentSelection) { TerraGraphEditor.Graph.RemoveComment(comment); } TerraGraphEditor.NodeSelection.Clear(); TerraGraphEditor.CommentSelection.Clear(); TerraGraphEditor.Selecting = false; e.Use(); } if (e.keyCode == KeyCode.F) { if (TerraGraphEditor.NodeSelection.Count != 0 || TerraGraphEditor.CommentSelection.Count != 0) { Vector2 currentCenter = TerraGraphEditor.Window.position.size * 0.5f; Vector2 targetCenter = TerraGraphEditor.NodeSelection[0].Rect.center; Vector2 offset = currentCenter - targetCenter; foreach (TerraNode node in TerraGraphEditor.Graph.Nodes) { node.SetPosition(node.Rect.position + offset); } foreach (GraphComment comment in TerraGraphEditor.Graph.Comments) { comment.SetPosition(comment.Rect.position + offset); } TerraGUI.ApplyGridOffset(offset); e.Use(); } } break; case EventType.MouseDown: if (e.button == 0) { TerraGraphEditor.NodeSelection.Clear(); TerraGraphEditor.CommentSelection.Clear(); TerraGraphEditor.SelectionStart = e.mousePosition; TerraGraphEditor.Selecting = true; GUI.FocusControl(null); e.Use(); } if (e.button == 1) { TerraGraphEditor.NodeSelection.Clear(); TerraGraphEditor.CommentSelection.Clear(); GUI.FocusControl(null); GenericMenu contextMenu = TerraUtility.CreateNodeContextMenu((t) => window.CreateNode(t, e.mousePosition)); contextMenu.AddSeparator(""); contextMenu.AddItem(new GUIContent("Add Comment"), false, () => TerraGraphEditor.Window.CreateComment(e.mousePosition)); contextMenu.ShowAsContext(); e.Use(); } break; case EventType.MouseUp: if (e.button == 0) { TerraGraphEditor.HeldSocket = null; TerraGraphEditor.ResizingComment = null; TerraGraphEditor.Selecting = false; e.Use(); } break; case EventType.MouseDrag: if (e.button == 0) { if (!new Rect(new Vector2(0, 0), window.position.size).Contains(e.mousePosition)) { TerraGraphEditor.NodeSelection.Clear(); TerraGraphEditor.CommentSelection.Clear(); TerraGraphEditor.Selecting = false; TerraGraphEditor.ResizingComment = null; TerraGraphEditor.HeldSocket = null; GUI.FocusControl(null); e.Use(); } if (TerraGraphEditor.ResizingComment != null) { TerraGraphEditor.ResizingComment.SetSize(TerraGraphEditor.ResizingComment.Rect.size + e.delta); e.Use(); } else if (!TerraGraphEditor.Selecting) { foreach (TerraNode node in TerraGraphEditor.NodeSelection) { node.SetPosition(node.Rect.position + e.delta); } foreach (GraphComment comment in TerraGraphEditor.CommentSelection) { comment.SetPosition(comment.Rect.position + e.delta); } e.Use(); } } if (e.button == 2) { TerraGUI.ApplyGridOffset(e.delta); foreach (TerraNode node in TerraGraphEditor.Graph.Nodes) { node.SetPosition(node.Rect.position + e.delta); } foreach (GraphComment comment in TerraGraphEditor.Graph.Comments) { comment.SetPosition(comment.Rect.position + e.delta); } e.Use(); } break; } }
private void DrawWindow() { TerraGUI.DrawDefaultGrid(new Rect(new Vector2(0, Window.position.size.y), new Vector2(Window.position.size.x, -Window.position.size.y))); }