public GraphEvent(EventType eventType, BaseNodeGUI sourceNodeGUI, string message) { this.eventType = eventType; this.sourceNodeGUI = sourceNodeGUI; this.message = message; this.commandType = CommandType.NONE; }
public GraphEvent(EventType eventType, BaseNodeGUI sourceNodeGUI, Vector2 mousePosition) { this.eventType = eventType; this.sourceNodeGUI = sourceNodeGUI; this.mousePosition = mousePosition; this.commandType = CommandType.NONE; }
public GraphEvent(EventType eventType, BaseNodeGUI sourceNodeGUI, Socket sourceSocket, Vector2 mousePosition) { this.eventType = eventType; this.sourceNodeGUI = sourceNodeGUI; this.sourceSocket = sourceSocket; this.mousePosition = mousePosition; }
public GraphEvent(EventType eventType, BaseNodeGUI sourceNodeGUI, Socket sourceSocket, Vector2 eventPosition, Vector2 mousePosition, string message) { this.eventType = eventType; this.sourceNodeGUI = sourceNodeGUI; this.sourceSocket = sourceSocket; this.eventPosition = eventPosition; this.mousePosition = mousePosition; this.message = message; }
private void DrawNodes(Rect graphArea) { if (NodesGUIsDatabase == null || NodesGUIsDatabase.Keys.Count == 0) { return; //sanity check } BeginWindows(); foreach (string key in NodesGUIsDatabase.Keys) { BaseNodeGUI nodeGUI = NodesGUIsDatabase[key]; //get the nodeGUI var nodeGUIWorldRect = new Rect(nodeGUI.Node.GetPosition() + CurrentPanOffset / CurrentZoom, nodeGUI.Node.GetSize()); //calculate the world rect of the nodeGUI nodeGUI.IsVisible = m_scaledGraphArea.Overlaps(nodeGUIWorldRect); //check the the world rect is in view if (!nodeGUI.IsVisible) { continue; //if nodeGUI node in view -> do not draw it } //if the graph is too zoomed out it's pointless to process and draw the node contents as it is almost invisible and no relevant info can be read on the screen nodeGUI.ZoomedBeyondSocketDrawThreshold = CurrentZoom <= NodyWindowSettings.ZOOM_DRAW_THRESHOLD_FOR_SOCKETS; //let the NodeGUI know if it should draw its contents (we do this to optimize the viewing speed of the graph when there are a lot of nodes visible) nodeGUI.DrawNodeGUI(graphArea, CurrentPanOffset, CurrentZoom); //draw the node } EndWindows(); if (!m_altKeyPressed) { return; //if not in delete mode (Alt is not pressed) -> do not draw the delete buttons } if (CurrentZoom <= NodyWindowSettings.ZOOM_DRAW_THRESHOLD_FOR_CONNECTION_POINTS) { return; //if the graph is too zoomed out, beyond the connection points draw threshold -> do not draw the delete buttons } foreach (string key in NodesGUIsDatabase.Keys) { BaseNodeGUI nodeGUI = NodesGUIsDatabase[key]; //get the nodeGUI if (!nodeGUI.IsVisible) { continue; //if nodeGUI node in view -> do not draw it } DrawNodeDeleteButton(nodeGUI); //draw the delete button } }
private Socket GetSocketAtWorldPositionFromHoverRect(Vector2 worldPosition) { if (CurrentZoom <= NodyWindowSettings.ZOOM_DRAW_THRESHOLD_FOR_SOCKETS) { return(null); //if the graph is too zoomed out do not search for sockets } foreach (Socket socket in SocketsDatabase.Values) { BaseNodeGUI nodeParentGUI = NodesGUIsDatabase[socket.NodeId]; if (nodeParentGUI == null) { continue; } if (!nodeParentGUI.IsVisible) { continue; //the node, that the socket belongs to, is not visible -> do not process it } var socketWorldRect = new Rect(nodeParentGUI.Node.GetX() + (nodeParentGUI.Node.GetWidth() - socket.HoverRect.width) / 2, //(nodeParent.GetWidth() - socket.HoverRect.width) / 2 -> is the X offset of the hover rect nodeParentGUI.Node.GetY() + socket.GetY() + (socket.GetHeight() - socket.HoverRect.height) / 2, //(socket.GetHeight() - socket.HoverRect.height) / 2 -> is the Y offset of the hover rect socket.HoverRect.width, socket.HoverRect.height); var socketGridRect = new Rect(socketWorldRect.position * CurrentZoom + CurrentPanOffset, socketWorldRect.size * CurrentZoom); // GUI.color = Color.yellow; // GUI.Box(socketGridRect, GUIContent.none); // GUI.color = Color.white; if (socketGridRect.Contains(worldPosition)) { return(socket); } } return(null); }
private void DrawNodeDeleteButton(BaseNodeGUI nodeGUI) { if (!nodeGUI.Node.CanBeDeleted) { return; } switch (nodeGUI.Node.NodeType) { case NodeType.Start: case NodeType.Enter: case NodeType.Exit: return; } nodeGUI.SetDeleteButtonSizeScale(m_altKeyPressedAnimBool.faded * m_isDraggingAnimBool.faded); Vector2 gridPosition = nodeGUI.DeleteButtonRect.position + CurrentPanOffset / CurrentZoom; nodeGUI.DeleteButtonRectInGridSpace = new Rect(gridPosition, nodeGUI.DeleteButtonRect.size); GUI.color = Color.red; GUI.Box(nodeGUI.DeleteButtonRectInGridSpace, GUIContent.none, NodeButtonDelete); GUI.color = Color.white; }
public GraphEvent(EventType eventType, BaseNodeGUI sourceNodeGUI) { this.eventType = eventType; this.sourceNodeGUI = sourceNodeGUI; this.commandType = CommandType.NONE; }
public static void Send(EventType eventType, BaseNodeGUI sourceNodeGUI, Socket sourceSocket, Vector2 eventPosition, Vector2 mousePosition, string message) { Send(new GraphEvent(eventType, sourceNodeGUI, sourceSocket, eventPosition, mousePosition, message)); }
public static void Send(EventType eventType, BaseNodeGUI sourceNodeGUI, Socket sourceSocket, Vector2 mousePosition) { Send(new GraphEvent(eventType, sourceNodeGUI, sourceSocket, mousePosition)); }
public static void Send(EventType eventType, BaseNodeGUI sourceNodeGUI, string message) { Send(new GraphEvent(eventType, sourceNodeGUI, message)); }
public static void Send(EventType eventType, BaseNodeGUI sourceNodeGUI) { Send(new GraphEvent(eventType, sourceNodeGUI)); }
public GraphEvent(EventType eventType, BaseNodeGUI sourceNodeGUI) { this.eventType = eventType; this.sourceNodeGUI = sourceNodeGUI; }
private void HandleMouseLeftClicks() { Event current = Event.current; if (!current.isMouse) { return; } if (current.button != 0) { return; } if (current.type == EventType.MouseDown) { //left mouse button is down and the space key is down as well -> enter panning mode if (m_spaceKeyDown) { m_mode = GraphMode.Pan; current.Use(); return; } if (m_altKeyPressed) //delete mode { BaseNodeGUI nodeGUI = GetNodeGUIOfDeleteButtonAtWorldPosition(CurrentMousePosition); if (nodeGUI != null) { SoftDeleteNode(nodeGUI.Node, true, false); current.Use(); return; } } //pressed left mouse button over a socket point -> but we have at least two nodes selected -> do not allow starting any connections if (WindowSettings.SelectedNodes.Count < 2) { if (m_currentHoveredVirtualPoint != null) { // if (current.alt) if (m_altKeyPressed) { //pressed left mouse button over a socket virtual point while holding down Alt -> Disconnect Virtual Point DisconnectVirtualPoint(m_currentHoveredVirtualPoint, true); } else { //pressed left mouse button over a socket connection point -> it's a possible start of a connection m_activeSocket = m_currentHoveredVirtualPoint.Socket; //set the socket as the active socket m_mode = GraphMode.Connect; //set the graph in connection mode } current.Use(); return; } Socket socket = GetSocketAtWorldPositionFromHoverRect(CurrentMousePosition); if (socket != null) { // if (current.alt) if (m_altKeyPressed) { //pressed left mouse button over a socket while holding down Alt -> Remove Socket RemoveSocket(socket, true); } else { //pressed left mouse button over a socket -> it's a possible start of a connection m_activeSocket = socket; //set the socket as the active socket m_mode = GraphMode.Connect; //set the graph in connection mode } current.Use(); return; } } //pressed left mouse button over a node -> check to see if it's inside the header (if no node is currently selected) or it just over a node (if at least 2 nodes are selected) if (m_currentHoveredNode != null) { if (GetNodeGridRect(m_currentHoveredNode).Contains(CurrentMousePosition) || //if mouse is inside node -> allow dragging WindowSettings.SelectedNodes.Count > 1) //OR if there are at least 2 nodes selected -> allow dragging from any point on the node { //pressed left mouse button over a node -> select/deselect it if (current.shift || current.control || current.command) //if using modifiers -> create custom selection { SelectNodes(new List <Node> { m_currentHoveredNode }, true, true); //add/remove the node to/from selection } else if (!WindowSettings.SelectedNodes.Contains(m_currentHoveredNode)) //we may have a selection and we do not want to override it in order to be able to start dragging { SelectNodes(new List <Node> { m_currentHoveredNode }, false, true); //select this node only } //allow dragging ONLY IF the mouse is over a selected node //in the previous lines we only checked if it's over a node, but not if the node we are hovering over is currently selected if (WindowSettings.SelectedNodes.Contains(m_currentHoveredNode)) { if (Selection.activeObject != m_currentHoveredNode) { Selection.activeObject = m_currentHoveredNode; //select the node } //pressed left mouse button over a node -> it's a possible start drag PrepareToDragSelectedNodes(CurrentMousePosition); m_mode = GraphMode.Drag; } } current.Use(); return; } //pressed left mouse button over nothing -> it's a possible start selection PrepareToCreateSelectionBox(CurrentMousePosition); current.Use(); return; } if (current.type == EventType.MouseDrag) { //left mouse click is dragging and the graph is in panning mode if (m_mode == GraphMode.Pan) { //check that the space key is held down -> otherwise exit pan mode if (!m_spaceKeyDown) { m_mode = GraphMode.None; } else { DoPanning(current); } current.Use(); return; } //mouse left click is dragging a connection if (m_mode == GraphMode.Connect) { if (m_currentHoveredSocket != null) //mouse is over a socket -> color the line to green if connection is possible or red otherwise { m_createConnectionLineColor = m_activeSocket.CanConnect(m_currentHoveredSocket) ? Color.green : Color.red; } else if (m_currentHoveredVirtualPoint != null) //mouse is over a socket connection point -> color the line to green if connection is possible or red otherwise { m_createConnectionLineColor = m_activeSocket.CanConnect(m_currentHoveredVirtualPoint.Socket) ? Color.green : Color.red; } else //mouse is not over anything connectable -> show the connection point color to look for { m_createConnectionLineColor = m_activeSocket.IsInput ? DGUI.Colors.GetDColor(DGUI.Colors.NodyOutputColorName).Normal //source socket is input -> looking for an output socket -> color the line to the output color : DGUI.Colors.GetDColor(DGUI.Colors.NodyInputColorName).Normal; //source socket is output -> looking for an input socket -> color the line to the input color } current.Use(); return; } //mouse left click is dragging one or more nodes if (m_mode == GraphMode.Drag) // && GUIUtility.hotControl == dragNodesControlId) { m_isDraggingAnimBool.target = false; RecordUndo("Move Nodes"); UpdateSelectedNodesWhileDragging(); current.Use(); return; } //mouse left click is dragging and creating a selection box <- we know this because the the mouse is not over a point nor a node if (m_startSelectPoint != null) { m_mode = GraphMode.Select; } if (m_mode == GraphMode.Select) { UpdateSelectionBox(CurrentMousePosition); UpdateSelectBoxSelectedNodesWhileSelecting(current); UpdateNodesSelectedState(m_selectedNodesWhileSelecting); current.Use(); return; } } if (current.type == EventType.MouseUp) { if (RegisteredDoubleClick) { if (m_previousHoveredNode != null) { NodesGUIsDatabase[m_previousHoveredNode.Id].OnDoubleClick(this); } } //lifted left mouse button and was panning (space key was/is down) -> reset graph to idle if (m_mode == GraphMode.Pan) { m_mode = GraphMode.None; current.Use(); return; } //lifted left mouse button and was dragging -> reset graph to idle if (m_mode == GraphMode.Drag) { m_initialDragNodePositions.Clear(); m_isDraggingAnimBool.target = true; m_mode = GraphMode.None; current.Use(); return; } //lifted left mouse button and was selecting via selection box -> end selections and reset graph to idle mode if (m_mode == GraphMode.Select) { EndDragSelectedNodes(); m_mode = GraphMode.None; current.Use(); return; } //check if this happened over another socket or connection point if (m_currentHoveredSocket != null) { //lifted left mouse button over a socket if (m_activeSocket != null && //if there is an active socket m_activeSocket != m_currentHoveredSocket && //and it's not this one m_activeSocket.CanConnect(m_currentHoveredSocket)) //and the two sockets can get connected { ConnectSockets(m_activeSocket, m_currentHoveredSocket); //connect the two sockets } else //this was a failed connection attempt { GraphEvent.Send(GraphEvent.EventType.EVENT_CONNECTING_END); //send a graph event } m_activeSocket = null; //clear the active socket m_mode = GraphMode.None; //set the graph in idle mode current.Use(); return; } if (m_currentHoveredVirtualPoint != null) { //lifted left mouse button over a socket connection point if (m_activeSocket != null && //if there is an active socket m_activeSocket != m_currentHoveredVirtualPoint.Socket && //and it's not this one m_activeSocket.CanConnect(m_currentHoveredVirtualPoint.Socket)) //and the two sockets can get connected { ConnectSockets(m_activeSocket, m_currentHoveredVirtualPoint.Socket); //connect the two sockets } else //this was a failed connection attempt { GraphEvent.Send(GraphEvent.EventType.EVENT_CONNECTING_END); //send a graph event } m_activeSocket = null; //clear the active socket m_mode = GraphMode.None; //set the graph in idle mode current.Use(); return; } //it a connecting process was under way -> clear it //lifted left mouse button, but no virtual point was under the mouse position if (m_mode == GraphMode.Connect) { m_activeSocket = null; //clear the active socket m_mode = GraphMode.None; //set the graph in idle mode } Node node = GetNodeAtWorldPosition(CurrentMousePosition); if (node != null) { m_mode = GraphMode.None; //set the graph in idle mode current.Use(); return; } //lifted mouse left button over nothing -> deselect all and select the graph itself ExecuteGraphAction(GraphAction.DeselectAll); //deselect all nodes and select the graph itself m_mode = GraphMode.None; //set the graph in idle mode current.Use(); return; } //check if the developer released the left mouse button outside of the graph window if (current.rawType == EventType.MouseUp || current.rawType == EventType.MouseLeaveWindow) { switch (m_mode) { case GraphMode.Select: EndDragSelectedNodes(); m_mode = GraphMode.None; current.Use(); break; } } }