Exemplo n.º 1
0
        private void DrawGraph()
        {
            var rect = TinyGUI.BeginZoom(_eventProcessor.Scale);

            TinyGUI.DrawGrid(Graph == null ? Vector2.zero : Graph.Offset, rect);
            DrawGraph(false);
            DrawGraph(true);
            TinyGUI.EndZoom();
            DrawMenu();
        }
Exemplo n.º 2
0
        private bool ProcessMouseUp(Event @event)
        {
            if (@event.button == 1)
            {
                //End of mouse right click
                if (Vector2.Distance(Zoomed(CurrentPosition), Zoomed(StartPosition)) < 1)
                {
                    ProcessContextMenu(Zoomed(CurrentPosition));
                }
                return(false);
            }

            if (@event.button != 0)
            {
                return(false);
            }

            //End of mouse left click
            if (NewEdge)
            {
                var @in = _graph.GetNodeUnder(Zoomed(CurrentPosition));
                if (@in != null && @in.Type == TinyNodeType.Regular)
                {
                    _graph.CreateEdge(_graph.GetNodeUnder(Zoomed(StartPosition)), @in);
                }
                else
                {
                    ProcessContextMenu(Zoomed(CurrentPosition));
                }
                return(true);
            }

            if (!MultiSelectionOn)
            {
                return(false);
            }

            var selection = GetSelectionRect(Zoomed(StartPosition), Zoomed(CurrentPosition));

            _selector.Add(_graph.Nodes.Where(x => selection.Overlaps(TinyGUI.GetNodeRect(x.Position))));
            return(true);
        }
Exemplo n.º 3
0
        private void OnGUI()
        {
            _buffer.OnUpdate(Graph);
            _eventProcessor.Process(Graph);

            DrawGraph();

            if (_eventProcessor.MultiSelectionOn)
            {
                TinyGUI.DrawMultiSelectionRect(_eventProcessor.StartPosition, _eventProcessor.CurrentPosition);
            }

            if (_eventProcessor.NewEdge)
            {
                TinyGUI.DrawEdge(_eventProcessor.StartPosition, _eventProcessor.CurrentPosition, true);
            }

            if (GUI.changed)
            {
                Repaint();
            }
        }
Exemplo n.º 4
0
        private void DrawGraph(bool selected)
        {
            if (Graph == null)
            {
                return;
            }

            foreach (var node in Graph.Nodes.Where(x => selected == Selector.IsSelected(x)))
            {
                TinyGUI.DrawNode(node, selected, Graph.HasInEdge(node), Graph.HasOutEdge(node));
            }

            foreach (var edge in Graph.Edges.Where(x => selected == Selector.IsSelected(x)))
            {
                var @out = TinyGUI.GetOutRect(Graph.GetNode(edge.Out));
                var @in  = TinyGUI.GetInRect(Graph.GetNode(edge.In));
                if (TinyGUI.DrawEdge(@out, @in, selected))
                {
                    Selector.AddSingle(edge);
                }
            }
        }
Exemplo n.º 5
0
        private bool ProcessMouseDown(Event @event)
        {
            if (@event.button == 1)
            {
                //Clean up selection on right mouse click
                _selector.Clean();
//                _newEdge = EditingEdge.Empty;
                return(true);
            }

            if (@event.button != 0)
            {
                return(false);
            }

            var node = _graph.GetNodeUnder(Zoomed(CurrentPosition), _selector);

            if (node == default)
            {
                _selector.Clean();
                MultiSelectionOn = true;
                return(false);
            }

            //Try Select node or edge on left mouse click
            var outRect = TinyGUI.GetOutRect(node);

            NewEdge = outRect.Contains(Zoomed(CurrentPosition));
            if (NewEdge)
            {
                StartPosition = outRect.center / ZoomOffset;
            }

            _selector.AddSingle(node);
            return(true);
        }
Exemplo n.º 6
0
        public static TinyNode GetNodeUnder(this TinyGraph graph, Vector2 point, TinySelector selector = null)
        {
            var nodes = graph.Nodes.Where(x => TinyGUI.GetNodeRect(x.Position).Contains(point));

            return(selector == null?nodes.FirstOrDefault() : nodes.OrderByDescending(selector.IsSelected).FirstOrDefault());
        }