Beispiel #1
0
        public void UpdatePosition()
        {
            if (Math.Abs(mouseWheelDelta) > 60)
            {
                zoom = Math.Max(Math.Min(zoom + mouseWheelDelta * zoomSensitivity, maxZoom), minZoom);

                fieldLayer.SetZoom(zoom);
                gridLayer.canvasImage.RenderTransform = fieldLayer.canvasImage.RenderTransform;
                pathLayer.canvasImage.RenderTransform = fieldLayer.canvasImage.RenderTransform;

                mouseWheelDelta = 0;
            }

            Point mousePositionCurrent = Mouse.GetPosition(canvasWindowUI.canvas);

            // if(Math.Abs((mousePositionCurrent.X - mousePositionPrevious.X) + (mousePositionCurrent.Y - mousePositionPrevious.Y)) > 80) return;
            if (Mouse.MiddleButton == MouseButtonState.Pressed)
            {
                mouseMoveDelta = (Point)(mousePositionCurrent - mousePositionPrevious);
            }
            else
            {
                mouseMoveDelta = new Point(0, 0);
            }

            mousePositionPrevious = mousePositionCurrent;

            // if (Mouse.MiddleButton == MouseButtonState.Pressed) {
            fieldLayer.SetPosition(fieldLayer.GetPosition() + (System.Windows.Vector)mouseMoveDelta);
            Point position = fieldLayer.GetPosition();

            gridLayer.SetPosition(grid.x * zoom + position.X, grid.y * zoom + position.Y);
            pathLayer.SetPosition(grid.x * zoom + position.X, grid.y * zoom + position.Y);
            // }
        }