Beispiel #1
0
        public void OnMouseDoubleClick(double X, double Y, GraphicsLayer.MouseButton button)
        {
            var x = X / _viewScale;
            var y = Y / _viewScale;

            var o = GetHit(x, y);

            var graphChanged = false;

            if (_state == States.Idle && !Canvas.IsControlKeyDown)
            {
                if (button == MouseButton.Left)
                {
                    if (o == null)
                    {
                        var v = new Vertex(x, y);
                        if (_graph.AddVertex(v))
                        {
                            graphChanged = true;
                        }
                    }
                    else if (o is Vertex)
                    {
                        var endVertex = (Vertex)o;
                        foreach (var v in _graph.SelectedVertices)
                        {
                            if (_graph.AddEdge(v, endVertex))
                            {
                                graphChanged = true;
                            }
                        }
                    }
                }
                else if (button == MouseButton.Right)
                {
                    if (o is Vertex)
                    {
                        if (_graph.RemoveVertex((Vertex)o))
                        {
                            graphChanged = true;
                        }
                    }
                }
            }

            Invalidate();

            if (graphChanged)
            {
                GraphChanged();
            }
        }
Beispiel #2
0
        public void OnMouseUp(double X, double Y, GraphicsLayer.MouseButton button)
        {
            var x = X / _viewScale;
            var y = Y / _viewScale;

            var o = GetHit(x, y);

            switch (_state)
            {
            case States.Idle:
            {
                break;
            }

            case States.DraggingVertex:
            {
                if (button == MouseButton.Left)
                {
                    _state = States.Idle;

                    if (SnapToGrid)
                    {
                        DoSnapToGrid();
                    }

                    GraphChanged();
                }
                break;
            }

            case States.DraggingSelectionRegion:
            {
                if (button == MouseButton.Left)
                {
                    _state = States.Idle;

                    List <Box> selectionPoints;
                    lock (_SelectionPointsToken)
                    {
                        selectionPoints = new List <Box>(_selectionPoints);

                        if (selectionPoints.Count > 2)
                        {
                            _graph.SelectObjects(selectionPoints, _controlWasDown);
                        }

                        Canvas.SelectedObjects = _graph.SelectedItems.Cast <object>();
                        Invalidate();
                    }
                }

                break;
            }

            case States.DraggingSelectedVertices:
            {
                if (button == MouseButton.Left)
                {
                    _state = States.Idle;
                    GraphChanged();
                }
                break;
            }
            }

            Invalidate();
        }
Beispiel #3
0
        public void OnMouseDown(double X, double Y, GraphicsLayer.MouseButton button)
        {
            _controlWasDown = Canvas.IsControlKeyDown;

            var x = X / _viewScale;
            var y = Y / _viewScale;

            var o = GetHit(x, y);

            switch (_state)
            {
            case States.Idle:
            {
                if (button == MouseButton.Left)
                {
                    if (o == null)
                    {
                        _selectionPoints.Clear();
                        _selectionPoints.Add(new Box(x, y));
                        _state = States.DraggingSelectionRegion;
                    }
                    else if (o is Vertex)
                    {
                        if (((Vertex)o).IsSelected)
                        {
                            foreach (Vertex v in _graph.SelectedVertices)
                            {
                                v.DragOffset = new Box(v.X - x, v.Y - y);
                            }

                            _state = States.DraggingSelectedVertices;
                        }
                        else
                        {
                            _DraggedVertex            = (Vertex)o;
                            _DraggedVertex.DragOffset = new Box(_DraggedVertex.X - x, _DraggedVertex.Y - y);
                            _state = States.DraggingVertex;
                        }
                    }
                    else if (o is Edge)
                    {
                    }
                }
                else if (button == MouseButton.Right)
                {
                    if (o == null)
                    {
                    }
                    else if (o is Vertex)
                    {
                    }
                    else if (o is Edge)
                    {
                    }
                }

                break;
            }

            case States.DraggingVertex:
                break;

            case States.DraggingSelectionRegion:
                break;
            }
        }