示例#1
0
        private void CanvasMouseDown(object sender, MouseEventArgs e)
        {
            if (!(e.OriginalSource is Canvas))
            {
                return;
            }
            if (mouseState != MouseState.Normal)
            {
                return;
            }

            Point mousePosition = e.GetPosition(canvas);

            mouseShiftDownPosition = mousePosition;
            if (Forms.Control.ModifierKeys == Forms.Keys.Shift || Forms.Control.ModifierKeys == (Forms.Keys.Shift | Forms.Keys.Control))
            {
                mouseShiftDown = true;
                canvas.CaptureMouse();

                Canvas.SetLeft(selectionBox, mouseShiftDownPosition.X);
                Canvas.SetTop(selectionBox, mouseShiftDownPosition.Y);
                selectionBox.Width  = 0;
                selectionBox.Height = 0;

                selectionBox.Visibility = Visibility.Visible;
            }

            if (GraphMode == GraphMode.DraggingMode)
            {
                if (!(Forms.Control.ModifierKeys == Forms.Keys.Control || Forms.Control.ModifierKeys == (Forms.Keys.Shift | Forms.Keys.Control)))
                {
                    CleanSelectedVertices();
                    CleanSelectedEdges();
                }
                previousMousePosition = mousePosition;
                mouseState            = MouseState.MovingGraph;
                ViewWindow.Static     = true;
            }
            else if (GraphMode == GraphMode.InsertingMode)
            {
                if (Forms.Control.ModifierKeys == Forms.Keys.Shift || Forms.Control.ModifierKeys == (Forms.Keys.Shift | Forms.Keys.Control))
                {
                    return;
                }
                Point corePos = ViewWindow.VisualToCorePosition(mousePosition);
                clickedVertex = Core.CreateVertex(corePos.X, corePos.Y);
                SelectionProcessing();
            }
        }
示例#2
0
        private void MouseZoom(object sender, MouseWheelEventArgs e)
        {
            Point position = ViewWindow.VisualToCorePosition(e.GetPosition(canvas));

            ViewWindow.SetZoom(e.Delta / 120.0, position);
        }
示例#3
0
        private void MouseMove(object sender, MouseEventArgs e)
        {
            Point mousePosition = e.GetPosition(canvas);

            if (mouseShiftDown && Forms.Control.ModifierKeys == Forms.Keys.Shift || Forms.Control.ModifierKeys == (Forms.Keys.Shift | Forms.Keys.Control))
            {
                if (mouseShiftDownPosition.X < mousePosition.X)
                {
                    Canvas.SetLeft(selectionBox, mouseShiftDownPosition.X);
                    selectionBox.Width = mousePosition.X - mouseShiftDownPosition.X;
                }
                else
                {
                    Canvas.SetLeft(selectionBox, mousePosition.X);
                    selectionBox.Width = mouseShiftDownPosition.X - mousePosition.X;
                }

                if (mouseShiftDownPosition.Y < mousePosition.Y)
                {
                    Canvas.SetTop(selectionBox, mouseShiftDownPosition.Y);
                    selectionBox.Height = mousePosition.Y - mouseShiftDownPosition.Y;
                }
                else
                {
                    Canvas.SetTop(selectionBox, mousePosition.Y);
                    selectionBox.Height = mouseShiftDownPosition.Y - mousePosition.Y;
                }

                previousMousePosition = mousePosition;
                return;
            }
            else if (mouseShiftDown)
            {
                mouseShiftDown = false;
                canvas.ReleaseMouseCapture();
                selectionBox.Visibility = Visibility.Collapsed;
            }

            if (GraphMode == GraphMode.DraggingMode)
            {
                if (mouseState == MouseState.Normal)
                {
                    return;
                }

                Vector coreShift = ViewWindow.VisualToCorePosition(mousePosition) -
                                   ViewWindow.VisualToCorePosition(previousMousePosition);
                previousMousePosition = mousePosition;

                if (mouseState == MouseState.MovingVertex && clickedVertex != null)
                {
                    clickedVertex.Shift(coreShift);
                }
                else if (mouseState == MouseState.MovingGraph)
                {
                    ViewWindow.Shift(coreShift);
                }
            }
            else
            {
                if (Mouse.LeftButton == MouseButtonState.Pressed)
                {
                    addedEdge.X2 = mousePosition.X - 1;
                    addedEdge.Y2 = mousePosition.Y - 1;
                    if (mousePosition.X < addedEdge.X1)
                    {
                        addedEdge.X2 += 2;
                    }

                    if (mousePosition.Y < addedEdge.Y1)
                    {
                        addedEdge.Y2 += 2;
                    }
                }
            }
        }