Esempio n. 1
0
        private NodeSocket GetSocket(Type forType)
        {
            var socket = new NodeSocket();

            SetValidType(socket, forType);
            return(socket);
        }
Esempio n. 2
0
        private Point SnapIfPossible(Point rootRelativePoint)
        {
            snappedSocket = null;
            var nearestNode = root.GetNearestNode(rootRelativePoint);

            if (null == nearestNode)
            {
                return(rootRelativePoint);
            }

            var nearestConnector = dragType == DragEndPoint.Input
                ? nearestNode.GetNearestFreeOutputSocket(rootRelativePoint, null == outputSocket ? null : Node.GetValidType(outputSocket))
                : nearestNode.GetNearestFreeInputSocket(rootRelativePoint, null == inputSocket ? null : Node.GetValidType(inputSocket));

            if (null == nearestConnector)
            {
                return(rootRelativePoint);
            }

            var distance = (rootRelativePoint - nearestConnector.Position).Length;

            if (distance <= SnapDistance)
            {
                if (dragType == DragEndPoint.Input && !nearestNode.QueryCanConnectOutput(OutputNode) ||
                    dragType == DragEndPoint.Output && !nearestNode.QueryCanConnectInput(InputNode))
                {
                    return(rootRelativePoint);
                }

                snappedSocket = nearestConnector;
                return(nearestConnector.Position);
            }
            return(rootRelativePoint);
        }
Esempio n. 3
0
        protected override void OnMouseUp(MouseButtonEventArgs e)
        {
            base.OnMouseUp(e);
            var type = dragType;

            dragType = DragEndPoint.Unknown;
            ReleaseMouseCapture();
            if (null != snappedSocket)
            {
                if (DragEndPoint.Input == type)
                {
                    ConnectInputEndPoint(snappedSocket);
                }
                else
                {
                    ConnectOutputEndPoint(snappedSocket);
                }
            }
            if (null == inputSocket || null == outputSocket)
            {
                Delete();
            }
            snappedSocket = null;
            e.Handled     = true;
        }
Esempio n. 4
0
 private void Connect(NodeSocket from, IConnectable to)
 {
     if (!InputSockets.Contains(from) && !OutputSockets.Contains(from))
     {
         return;
     }
     from.Connect(to);
 }
Esempio n. 5
0
 public SocketType GetSocketType(NodeSocket socket)
 {
     if (InputSockets.Contains(socket))
     {
         return(SocketType.Input);
     }
     return(OutputSockets.Contains(socket) ? SocketType.Output : SocketType.Unknown);
 }
Esempio n. 6
0
 public void ConnectOutputEndPoint(NodeSocket to)
 {
     outputSocket = to;
     OutputNode   = to.Node;
     OnConnected(to);
     UpdateStopPoint();
     if (null == inputSocket)
     {
         StartPoint = StopPoint;
     }
     UpdateCentrePoints();
 }
Esempio n. 7
0
        private void AddInputSocket()
        {
            if (!CanAutoAddInputs || GetFreeInputSocket() != null)
            {
                return;
            }
            var socket = new NodeSocket();

            if (null != contentNode && contentNode.Inputs != null)
            {
                SetValidType(socket, contentNode.Inputs.LastOrDefault());
            }
            SubscribeInputSocket(socket);
            InputSockets.Add(socket);
        }
Esempio n. 8
0
        private Point SnapIfPossible(Point rootRelativePoint)
        {
            snappedSocket = null;
            var nearestNode = root.GetNearestNode(rootRelativePoint);
            if (null == nearestNode) return rootRelativePoint;

            var nearestConnector = dragType == DragEndPoint.Input
                ? nearestNode.GetNearestFreeOutputSocket(rootRelativePoint, null == outputSocket ? null : Node.GetValidType(outputSocket))
                : nearestNode.GetNearestFreeInputSocket(rootRelativePoint, null == inputSocket ? null : Node.GetValidType(inputSocket));
            if (null == nearestConnector) return rootRelativePoint;

            var distance = (rootRelativePoint - nearestConnector.Position).Length;
            if (distance <= SnapDistance)
            {
                if (dragType == DragEndPoint.Input && !nearestNode.QueryCanConnectOutput(OutputNode) ||
                    dragType == DragEndPoint.Output && !nearestNode.QueryCanConnectInput(InputNode))
                    return rootRelativePoint;

                snappedSocket = nearestConnector;
                return nearestConnector.Position;
            }
            return rootRelativePoint;
        }
Esempio n. 9
0
 protected override void OnMouseUp(MouseButtonEventArgs e)
 {
     base.OnMouseUp(e);
     var type = dragType;
     dragType = DragEndPoint.Unknown;
     ReleaseMouseCapture();
     if (null != snappedSocket)
     {
         if (DragEndPoint.Input == type)
             ConnectInputEndPoint(snappedSocket);
         else
             ConnectOutputEndPoint(snappedSocket);
     }
     if (null == inputSocket || null == outputSocket)
         Delete();
     snappedSocket = null;
     e.Handled = true;
 }
Esempio n. 10
0
 public SocketType GetSocketType(NodeSocket socket)
 {
     if (InputSockets.Contains(socket))
         return SocketType.Input;
     return OutputSockets.Contains(socket) ? SocketType.Output : SocketType.Unknown;
 }
Esempio n. 11
0
 private void AddInputSocket()
 {
     if (!CanAutoAddInputs || GetFreeInputSocket() != null) return;
     var socket = new NodeSocket();
     if (null != contentNode && contentNode.Inputs != null)
         SetValidType(socket, contentNode.Inputs.LastOrDefault());
     SubscribeInputSocket(socket);
     InputSockets.Add(socket);
 }
Esempio n. 12
0
 public static void SetValidType(NodeSocket element, Type value)
 {
     element.SetValue(ValidTypeProperty, value);
 }
Esempio n. 13
0
 public static Type GetValidType(NodeSocket element)
 {
     return((Type)element.GetValue(ValidTypeProperty));
 }
Esempio n. 14
0
 private static bool IsCompatible(NodeSocket socket, Type type)
 {
     return(null == type || GetValidType(socket) == type);
 }
Esempio n. 15
0
 private static bool IsSocketFree(NodeSocket socket)
 {
     return !socket.IsConnected;
 }
Esempio n. 16
0
 private static bool IsCompatible(NodeSocket socket, Type type)
 {
     return (null == type || GetValidType(socket) == type);
 }
Esempio n. 17
0
 private static bool IsSocketFree(NodeSocket socket)
 {
     return(!socket.IsConnected);
 }
Esempio n. 18
0
 private NodeSocket GetSocket(Type forType)
 {
     var socket = new NodeSocket();
     SetValidType(socket, forType);
     return socket;
 }
Esempio n. 19
0
 public void ConnectOutputEndPoint(NodeSocket to)
 {
     outputSocket = to;
     OutputNode = to.Node;
     OnConnected(to);
     UpdateStopPoint();
     if (null == inputSocket)
         StartPoint = StopPoint;
     UpdateCentrePoints();
 }
Esempio n. 20
0
 public static Type GetValidType(NodeSocket element)
 {
     return (Type)element.GetValue(ValidTypeProperty);
 }
Esempio n. 21
0
 public static void SetValidType(NodeSocket element, Type value)
 {
     element.SetValue(ValidTypeProperty, value);
 }
Esempio n. 22
0
 private void Connect(NodeSocket from, IConnectable to)
 {
     if (!InputSockets.Contains(from) && !OutputSockets.Contains(from)) return;
     from.Connect(to);
 }