/// <summary> /// Fired after the node editor events /// </summary> public override void AfterEditorEvents() { CheckActivation(); if (!IsActivated) { return; } if (!Event.current.IsLeftClickEvent()) { return; } if (Event.current.modifiers != EventModifiers.None) { return; } Node clickedNode = NodeEditor.GetNodeUnderMouse(); Connector clickedConnector = NodeEditor.GetNodeConnectorUnderMouse(); if (clickedNode == null && clickedConnector == null) { NodeEditor.UnselectAll(); NodeEditor.RaiseSelectionChanged(); NodeEditor.FlagRepaint(); } }
/// <summary> /// Performs the drags before the other editor events /// /// This should be called after any node select modes /// </summary> public override void BeforeEditorEvents() { if (Event.current.button != 0) { return; } if (NodeEditor.GetPreUsedEventType() == EventType.MouseDown) { Node node = NodeEditor.GetNodeUnderMouse(); wasMouseDownInSelectedNode = node != null && node.IsSelected(); CheckActivation(); } if (!IsActivated) { return; } if (Event.current.type == EventType.MouseDrag) { HandleMouseMove(); } else if (Event.current.type == EventType.MouseUp || Event.current.type == EventType.MouseLeaveWindow) { Deactivate(); } }
/// <summary> /// Handles checking for clicked nodes /// </summary> public override void BeforeEditorEvents() { CheckActivation(); if (!IsActivated) { return; } if (Event.current.IsLeftClickEvent()) { Node selectedNode = NodeEditor.GetNodeUnderMouse(); if (selectedNode == null || !IsNodeValid(selectedNode)) { return; } MakeConnection(selectedNode); } else if (Event.current.IsRightClickEvent()) { if (startNode != null) { NodeEditor.RemoveConnector(connection); startNode = null; connection = null; } } }
/// <summary> /// Checks if the node is a valid context menu receiving node /// and displays its context menu /// </summary> /// <returns>True if context menu should be displayed, false if not</returns> protected override bool ShouldActivate() { if (!Event.current.IsRightClickEvent()) { return(false); } Node nodeUnderMouse = NodeEditor.GetNodeUnderMouse(); return(nodeUnderMouse != null && nodeUnderMouse.HasContextMenu); }
/// <summary> /// Shows the menu /// </summary> protected override void OnActivated() { Node nodeUnderMouse = NodeEditor.GetNodeUnderMouse(); if (nodeUnderMouse.IsSelectable && !nodeUnderMouse.IsSelected()) { NodeEditor.UnselectAll(); nodeUnderMouse.Select(); } UpdateActiveMenu(nodeUnderMouse.ContextMenu, nodeUnderMouse); Event.current.Use(); }
/// <summary> /// Checks for a destination node to attach the active connections to /// </summary> public override void BeforeEditorEvents() { if (!IsActivated) { return; } if (Event.current.IsRightClickEvent()) { Cancel(); return; } NodeEditor.FlagRepaint(); if (!Event.current.IsLeftClickEvent()) { return; } Node selectedNode = NodeEditor.GetNodeUnderMouse(); if (!IsNodeValid(selectedNode)) { return; } for (int i = 0; i < newConnections.Count; i++) { Connector connector = newConnections[i]; if (!IsConnectionValid(connector.GetStartNode(), selectedNode)) { NodeEditor.RemoveConnector(connector); newConnections.RemoveAt(i); continue; } connector.RemoveNode(NodeEditor.MouseNode); connector.AddNode(selectedNode); } if (newConnections.Count > 0) { RaiseOnConnectionsFinalized(newConnections); } Deactivate(); }
/// <summary> /// Checks for node selection before the editor processes the /// left-clicks /// </summary> public override void BeforeEditorEvents() { CheckActivation(); if (!IsActivated) { return; } if (Event.current.type != EventType.MouseDown || Event.current.button != 0) { return; } bool multiSelectActive = Event.current.modifiers == EventModifiers.Control || Event.current.modifiers == EventModifiers.Shift; Node clickedNode = NodeEditor.GetNodeUnderMouse(); if (clickedNode == null) { return; } if (!clickedNode.IsSelectable) { return; } bool isNodeSelected = clickedNode.IsSelected(); if (!multiSelectActive) { if (!isNodeSelected) { NodeEditor.UnselectAll(); clickedNode.Select(); } } else { clickedNode.ToggleSelected(); } NodeEditor.RaiseSelectionChanged(); NodeEditor.FlagRepaint(); Event.current.Use(); }