/// <summary> /// Selects the specified node. /// </summary> /// <param name="layout">Layout.</param> /// <param name="additive">If set to <c>true</c> additive.</param> public void Select(NodeLayout layout, bool additive) { if (IsSelected(layout)) { if (additive) { Remove(layout); } else { return; } } if (!additive || layout == null) { Clear(); } if (layout != null) { SelectionList.Add(layout); layout.Selected = true; } }
public void Draw() { // Iterate through nodes foreach (var node in _graph.Nodes.GetAll) { NodeLayout nodelayout = _editor.GetLayout(node) as NodeLayout; if (nodelayout == null) { continue; } // Iterate through the node pins foreach (var pin in node.PinCollection.Get()) { // If the pin is output or transition input continue // We are using inputs and transition outputs only becouse those can // have only a single wire. if (pin.PinType == PinType.Output || pin.PinType == PinType.TransIn) { continue; } // Continue if the pin doesn't have any active connection if (pin.Connections.Count == 0) { continue; } var connection = pin.Connections[0]; var otherLayout = _editor.GetLayout(connection.NodeID); // If the other layout doesn't exist the pin should be fixed. if (otherLayout == null) { _editor.FixConnectionIssue(node, pin); return; } // If the layout exists... else { //... check if the layout has connection to this node (validate) bool isValid = false; var otherPin = otherLayout.Node.PinCollection.Get(connection.PinName); foreach (var otherConn in otherPin.Connections) { if (otherConn.NodeID == node.ID && otherConn.PinName == pin.Name) { isValid = true; } } if (isValid) { if (pin.VariableType != otherPin.VariableType) { Disconnect(pin); } } // If the connection is valid, connect. if (isValid) { var pinFrom = nodelayout.GetPin(pin.Name); var pinTo = otherLayout.GetPin(otherPin.Name); DrawWire(pinFrom.WireRect, pinTo.WireRect, pinFrom.Color, pinFrom.Direction); } else { _editor.FixConnectionIssue(node, pin); return; } } } } if (IsPinSelected) { Event e = Event.current; Rect r = new Rect(0, 0, 16, 16); r.x = e.mousePosition.x; r.y = e.mousePosition.y; DrawWire(_selectedPin.WireRect, r, _selectedPin.Color, _selectedPin.Direction); _editor.Repaint(); } }
/// <summary> /// Determines whether this node is selected or not. /// </summary> /// <returns><c>true</c> if this instance is selected the specified layout; otherwise, <c>false</c>.</returns> /// <param name="layout">Layout.</param> public bool IsSelected(NodeLayout layout) { return(layout != null && SelectionList.Contains(layout)); }
/// <summary> /// Sets a node that which have the mouse cursor over it. /// </summary> /// <param name="window">Window.</param> public void onMouseOver(NodeLayout window) { _mouseOver = window; }
/// <summary> /// Removes the specified node from the selection. /// </summary> /// <param name="layout">Layout.</param> public void Remove(NodeLayout layout) { layout.Selected = false; SelectionList.Remove(layout); }