Ejemplo n.º 1
0
 private void DrawConnection()
 {
     foreach (var rect in path)
     {
         GLUtils.DrawConnection(new Vector2(rect.x, rect.y), new Vector2(rect.x + rect.width, rect.y + rect.height), Color.red, 3f);
     }
 }
Ejemplo n.º 2
0
        public void DrawBlockNode()
        {
            // Draggable Block Node
            if (Position.Contains(Event.current.mousePosition) && Event.current.type == EventType.MouseDown && !(edgeNodeSelected || edgeNodeHovered))
            {
                blockSelected = true;
            }

            if (blockSelected && Event.current.type == EventType.MouseUp)
            {
                blockSelected = false;
                offsetPos     = null;
            }

            if (blockSelected)
            {
                guiDepth = 1;

                // Enables drag and drop from any section of the block clicked
                if (offsetPos == null)
                {
                    offsetPos = new Vector2(Mouse.screenPos.x - Position.x, Mouse.screenPos.y - Position.y);
                }

                // Utilize grid class for quantizing movement
                Position.x = Grid.SnapToGrid(Mouse.screenPos.x - offsetPos.Value.x);
                Position.y = Grid.SnapToGrid(Mouse.screenPos.y - offsetPos.Value.y);
                UpdateEdgeNodes();
            }
            else
            {
                guiDepth = 2;
            }

            // Render Block Node, followed by its connectors
            GUI.depth = guiDepth;
            if (GUI.Button(Position, Icon, GetBlockStyle(Icon)))
            {
                CommEngrUtils.Log(string.Format("Block with Rect({0}, {1}, {2}, {3}) clicked!",
                                                Position.x, Position.y, Position.width, Position.height));
            }

            // Selectable Edge Nodes
            GUI.depth = 0;
            foreach (var edgeNode in EdgeNodes)
            {
                if (edgeNode.Value.Position.Contains(Event.current.mousePosition))
                {
                    edgeNodeHovered = true;
                }
                else
                {
                    edgeNodeHovered = false;
                }

                if (edgeNodeHovered && Input.GetMouseButtonDown(0))
                {
                    screenPt1        = new Vector2(edgeNode.Value.Position.x, (float)Screen.height - edgeNode.Value.Position.y);
                    edgeNodeSelected = true;
                    callDrawEdge     = true;
                }

                if (edgeNodeSelected && Input.GetMouseButtonDown(1))
                {
                    callDrawEdge     = false;
                    edgeNodeHovered  = false;
                    edgeNodeSelected = false;
                }
                if (GUI.Button(edgeNode.Value.Position, "EN"))
                {
                }

                if (edgeNodeSelected)
                {
                }

                if (callDrawEdge)
                {
                    GLUtils.DrawConnection(screenPt1 + new Vector2(edgeNode.Value.Position.width / 2f, edgeNode.Value.Position.height / 2f), Mouse.screenPos, Color.red, 10f);
                }
            }
        }