Ejemplo n.º 1
0
        private void ProductionGraphViewer_MouseMove(object sender, MouseEventArgs e)
        {
            var element = GetElementsAtPoint(ScreenToGraph(e.Location)).FirstOrDefault();

            if (element != null)
            {
                element.MouseMoved(Point.Add(ScreenToGraph(e.Location), new Size(-element.X, -element.Y)));
            }

            if (DraggedElement != null)
            {
                Point dragDiff = Point.Add(Control.MousePosition, new Size(-dragStartScreenPoint.X, -dragStartScreenPoint.Y));
                if (dragDiff.X * dragDiff.X + dragDiff.Y * dragDiff.Y > 9)                 //Only drag if the mouse has moved more than three pixels. This avoids dragging when the user is trying to click.
                {
                    clickHasBecomeDrag = true;
                    DraggedElement.Dragged(Point.Add(ScreenToGraph(e.Location), new Size(-DraggedElement.X, -DraggedElement.Y)));
                }
            }

            if ((Control.MouseButtons & MouseButtons.Middle) != 0 ||
                ((Control.MouseButtons & MouseButtons.Left) != 0 && DraggedElement == null))
            {
                ViewOffset = new Point(ViewOffset.X + (int)((e.X - lastMouseDragPoint.X) / ViewScale), ViewOffset.Y + (int)((e.Y - lastMouseDragPoint.Y) / ViewScale));
                LimitViewToBounds();
                lastMouseDragPoint = e.Location;
            }

            Invalidate();
        }
Ejemplo n.º 2
0
        private void StartDragging(object sender, MouseButtonEventArgs e)
        {
            HitTestResult hitResult = VisualTreeHelper.HitTest(this, e.GetPosition(this));

            if (!(GetParent(hitResult.VisualHit, 1) is Border element))
            {
                return;
            }
            mDragged = new DraggedElement()
            {
                Dragged          = element,
                DraggingPoint    = new Point(Canvas.GetLeft(element), Canvas.GetTop(element)),
                PickUpMousePoint = e.GetPosition(this),
                PickUpPoint      = new Point(Canvas.GetLeft(element), Canvas.GetTop(element))
            };
            Panel.SetZIndex(element, int.MaxValue);
            CaptureMouse();
        }