Esempio n. 1
0
        private async void Image_MouseUp(object sender, MouseButtonEventArgs e)
        {
            if (!DrawSelectionBox)
            {
                return;
            }
            // Release the mouse capture and stop tracking it.
            DrawSelectionBox = false;
            OuterGrid.ReleaseMouseCapture();

            // Hide the drag selection box.
            SelectionBox.Visibility = Visibility.Collapsed;
            var l          = RenderImage.TranslatePoint(new Point(0, 0), OuterGrid);
            var mouseUpPos = e.GetPosition(OuterGrid);

            if (mouseUpPos.X < l.X || mouseUpPos.X > l.X + RenderImage.ActualWidth)
            {
                return;
            }


            if (!(DataContext is MandelbrotViewModel dc) || !dc.CanRender())
            {
                return;
            }
            var topLeft   = SelectionBox.TranslatePoint(new Point(0, 0), RenderImage);
            var downRight = topLeft;

            downRight.X += SelectionBox.Width;
            downRight.Y += SelectionBox.Height;

            var oldL = dc.LeftEdge;
            var oldR = dc.RightEdge;
            var oldD = dc.BottomEdge;
            var oldU = dc.UpperEdge;

            var newL = oldL + (oldR - oldL) * topLeft.X / dc.CurrentBitmap.PixelWidth *
                       MandelbrotViewModel.DpiScale;
            var newR = oldL + (oldR - oldL) * downRight.X / dc.CurrentBitmap.PixelWidth *
                       MandelbrotViewModel.DpiScale;
            var newU = oldU - (oldU - oldD) * topLeft.Y / dc.CurrentBitmap.PixelHeight *
                       MandelbrotViewModel.DpiScale;
            var newD = oldU - (oldU - oldD) * downRight.Y / dc.CurrentBitmap.PixelHeight *
                       MandelbrotViewModel.DpiScale;

            dc.LeftEdge   = newL;
            dc.RightEdge  = newR;
            dc.UpperEdge  = newU;
            dc.BottomEdge = newD;

            await dc.ExecuteRender();
        }