Ejemplo n.º 1
0
    void MyDragLine()
    {
        if (startLineNode != null)
        {
            if (bDragingInputLine)
            {
                Vector2 lineEnd = startLineNode.getInputPortRect(startLinePort).center;
                drawBezier(Event.current.mousePosition, lineEnd, new Color(0.8f, 0.8f, 0.8f), true);
            }
            else if (bDragingOutputLine)
            {
                Vector2 lineStart = startLineNode.getOutputPortRect().center;
                drawBezier(lineStart, Event.current.mousePosition, new Color(0.8f, 0.8f, 0.8f), true);
            }
        }

        nodeManager.forEachNodes((n) => {
            for (int i = 0; i < n.getInputNum(); i++)
            {
                var inputNode = nodeManager.findNodeWindow(n.getInputGuid(i));
                if (inputNode != null)
                {
                    var endPos   = n.getInputPortRect(i).center;
                    var startPos = inputNode.getOutputPortRect().center;
                    drawBezier(startPos, endPos, new Color(0.8f, 0.8f, 0.8f), true);
                }
            }
        });

        if (Event.current.type == EventType.MouseDrag)
        {
            if (bDragingInputLine)
            {
            }
        }
        if (Event.current.type == EventType.MouseDown)
        {
            if (Event.current.button == 0)
            {
                nodeManager.forEachNodes((n) => {
                    for (int i = 0; i < n.getInputNum(); i++)
                    {
                        if (n.getInputPortRect(i).Contains(Event.current.mousePosition))
                        {
                            if (nodeManager.findNodeWindow(n.getInputGuid(i)) != null)
                            {
                                bDragingOutputLine = true;
                                startLineNode      = nodeManager.findNodeWindow(n.getInputGuid(i));
                                n.setInput(i, "");
                            }
                            else
                            {
                                bDragingInputLine = true;
                                startLineNode     = n;
                                startLinePort     = i;
                            }
                        }
                    }
                    if (n.hasOutput())
                    {
                        if (n.getOutputPortRect().Contains(Event.current.mousePosition))
                        {
                            bDragingOutputLine = true;
                            startLineNode      = n;
                        }
                    }
                });
            }
        }
        if (Event.current.type == EventType.MouseUp)
        {
            if (Event.current.button == 0)
            {
                if (bDragingInputLine)
                {
                    nodeManager.forEachNodes((n) => {
                        if (n != startLineNode)
                        {
                            if (n.hasOutput() && n.getOutputPortRect().Contains(Event.current.mousePosition))
                            {
                                startLineNode.setInput(startLinePort, n.getGuid());
                            }
                        }
                    });
                }
                else if (bDragingOutputLine)
                {
                    nodeManager.forEachNodes((n) => {
                        if (n != startLineNode)
                        {
                            for (int i = 0; i < n.getInputNum(); i++)
                            {
                                if (n.getInputPortRect(i).Contains(Event.current.mousePosition))
                                {
                                    n.setInput(i, startLineNode.getGuid());
                                }
                            }
                        }
                    });
                }
                bDragingInputLine  = false;
                bDragingOutputLine = false;
                this.Repaint();
            }
        }
    }