Пример #1
0
        private void OnMouseMove(object sender, MouseEventArgs e)
        {
            if (lmbPressed)
            {
                // panning:
                if (e.LeftButton == MouseButtonState.Released)
                {
                    lmbPressed = false;
                    RevertChanges();
                    return;
                }

                Point    screenMousePos = e.GetPosition(listeningPanel);
                Point    dataMousePos   = screenMousePos.ScreenToViewport(activePlotter.Transform);
                DataRect visible        = activePlotter.Viewport.Visible;
                double   delta;
                if (Placement.IsBottomOrTop())
                {
                    delta         = (dataMousePos - dragStartInViewport).X;
                    visible.XMin -= delta;
                }
                else
                {
                    delta         = (dataMousePos - dragStartInViewport).Y;
                    visible.YMin -= delta;
                }

                if (screenMousePos != lmbInitialPosition)
                {
                    listeningPanel.Cursor = Placement.IsBottomOrTop() ? Cursors.ScrollWE : Cursors.ScrollNS;
                }

                activePlotter.Viewport.SetChangeType(Placement.GetPanChangeType());
                activePlotter.Viewport.Visible = visible;
                activePlotter.Viewport.SetChangeType();

                e.Handled = true;
            }
            else if (rmbPressed)
            {
                // one direction zooming:
                if (e.RightButton == MouseButtonState.Released)
                {
                    rmbPressed = false;
                    RevertChanges();
                    return;
                }

                Point    screenMousePos = e.GetPosition(listeningPanel);
                DataRect visible        = activePlotter.Viewport.Visible;
                double   delta;

                bool isHorizontal = Placement.IsBottomOrTop();
                if (isHorizontal)
                {
                    delta = (screenMousePos - rmbInitialPosition).X;
                }
                else
                {
                    delta = (screenMousePos - rmbInitialPosition).Y;
                }

                if (delta < 0)
                {
                    delta = 1 / Math.Exp(-delta / RmbZoomScale);
                }
                else
                {
                    delta = Math.Exp(delta / RmbZoomScale);
                }

                Point center = dragStartInViewport;

                if (isHorizontal)
                {
                    visible = rmbDragStartRect.ZoomX(center, delta);
                }
                else
                {
                    visible = rmbDragStartRect.ZoomY(center, delta);
                }

                if (screenMousePos != lmbInitialPosition)
                {
                    listeningPanel.Cursor = Placement.IsBottomOrTop() ? Cursors.ScrollWE : Cursors.ScrollNS;
                }

                activePlotter.Viewport.SetChangeType(Placement.GetZoomChangeType());
                activePlotter.Viewport.Visible = visible;
                activePlotter.Viewport.SetChangeType();

                //e.Handled = true;
            }
        }