Exemplo n.º 1
0
        /// <summary>
        /// Handles sending the motion data to the selected nodes
        /// </summary>
        private void HandleMouseMove()
        {
            IEnumerable <Node> selectedNodes = NodeEditor.GetSelectedNodes();

            int used  = 0;
            int count = 0;

            Vector2 zoomedDrag = NodeEditor.ApplyZoomToVector(Event.current.delta);

            foreach (Node node in selectedNodes)
            {
                if (node.HandleDrag(zoomedDrag))
                {
                    used++;
                }
                count++;
            }

            if (used > 0)
            {
                NodeEditor.FlagRepaint();
                Event.current.Use();
            }
            else if (count == 0)
            {
                Deactivate();
            }
        }
        /// <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>
        /// 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();
        }
Exemplo n.º 5
0
        public override void BeforeEditorEvents()
        {
            CheckActivation();

            if (!IsActivated)
            {
                return;
            }

            if (!Event.current.IsLeftClickEvent())
            {
                return;
            }

            bool multiSelectActive = Event.current.modifiers == EventModifiers.Control ||
                                     Event.current.modifiers == EventModifiers.Shift;

            Connector clickedConnector = NodeEditor.GetNodeConnectorUnderMouse();

            if (clickedConnector == null)
            {
                return;
            }

            if (!clickedConnector.IsSelectable)
            {
                return;
            }

            bool isSelected = clickedConnector.IsSelected();

            if (!multiSelectActive)
            {
                if (!isSelected)
                {
                    NodeEditor.UnselectAll();
                    clickedConnector.Select();
                }
            }
            else
            {
                clickedConnector.ToggleSelected();
            }

            NodeEditor.RaiseSelectionChanged();
            NodeEditor.FlagRepaint();
            Event.current.Use();
        }
        /// <summary>
        /// Configures the rectangle used for selection
        /// </summary>
        public override void AfterEditorEvents()
        {
            CheckActivation();

            if (!IsActivated)
            {
                return;
            }

            if (Event.current.button != 0)
            {
                Cancel();
                Event.current.Use();
                return;
            }

            if (Event.current.type == EventType.MouseDrag)
            {
                Vector2 startPoint = NodeEditor.ApplyZoomToVector(dragStartPos);
                Vector2 endPoint   = NodeEditor.GetZoomedMousePosition();

                selectionRect = RectExtensions.FromPoints(startPoint, endPoint);

                NodeEditor.FlagRepaint();
                Event.current.Use();
            }
            else if (Event.current.type == EventType.MouseUp)
            {
                SelectNodes();
                SelectConnectors();

                NodeEditor.RaiseSelectionChanged();

                selectionRect = Rect.zero;
                Deactivate();

                Event.current.Use();
            }
            else if (Event.current.type == EventType.MouseLeaveWindow)
            {
                Cancel();
            }
        }