Пример #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();
        }
Пример #2
0
        private void Image_MouseMove(object sender, MouseEventArgs e)
        {
            if (DrawSelectionBox)
            {
                var mousePos = e.GetPosition(OuterGrid);
                var l        = RenderImage.TranslatePoint(new Point(0, 0), OuterGrid);

                if (mousePos.X < l.X || mousePos.X > l.X + RenderImage.ActualWidth)
                {
                    DrawSelectionBox = false;
                    OuterGrid.ReleaseMouseCapture();
                    SelectionBox.Visibility = Visibility.Collapsed;
                    return;
                }

                if (MouseDownPos.X < mousePos.X)
                {
                    Canvas.SetLeft(SelectionBox, MouseDownPos.X);
                    SelectionBox.Width = mousePos.X - MouseDownPos.X;
                }
                else
                {
                    Canvas.SetLeft(SelectionBox, mousePos.X);
                    SelectionBox.Width = MouseDownPos.X - mousePos.X;
                }

                if (MouseDownPos.Y < mousePos.Y)
                {
                    Canvas.SetTop(SelectionBox, MouseDownPos.Y);
                    SelectionBox.Height = mousePos.Y - MouseDownPos.Y;
                }
                else
                {
                    Canvas.SetTop(SelectionBox, mousePos.Y);
                    SelectionBox.Height = MouseDownPos.Y - mousePos.Y;
                }
            }
        }