示例#1
0
文件: AxisDrag.cs 项目: wwwK/XwPlot
        public override bool OnMouseMoved(MouseMovedEventArgs args, PlotCanvas pc)
        {
            Rectangle area = pc.PlotAreaBoundingBoxCache;

            if (dragging && physicalAxis != null)
            {
                pc.CacheAxes();

                double dX = args.X - lastPoint.X;
                double dY = args.Y - lastPoint.Y;
                lastPoint = new Point(args.X, args.Y);

                double length = physicalAxis.PhysicalLength;

                if (translateX)
                {
                    double xShift = -dX / length;
                    pc.TranslateXAxes(xShift);
                }
                if (translateY)
                {
                    double yShift = +dY / length;
                    pc.TranslateYAxes(yShift);
                }
                return(true);
            }
            return(false);
        }
示例#2
0
文件: PlotDrag.cs 项目: wwwK/XwPlot
        public override bool OnMouseMoved(MouseMovedEventArgs args, PlotCanvas pc)
        {
            Rectangle area = pc.PlotAreaBoundingBoxCache;

            if (dragging)
            {
                pc.CacheAxes();

                double dX = args.X - lastPoint.X;                               // distance mouse has moved
                double dY = args.Y - lastPoint.Y;
                lastPoint = new Point(args.X, args.Y);

                // Axis translation required
                double xShift = -dX / area.Width;
                double yShift = +dY / area.Height;

                if (Horizontal)
                {
                    pc.TranslateXAxes(xShift);
                }
                if (Vertical)
                {
                    pc.TranslateYAxes(yShift);
                }
                return(true);
            }
            return(false);
        }
示例#3
0
文件: PlotScale.cs 项目: wwwK/XwPlot
        public override bool OnMouseMoved(MouseMovedEventArgs args, PlotCanvas pc)
        {
            Rectangle area = pc.PlotAreaBoundingBoxCache;

            if (scaling)
            {
                pc.CacheAxes();

                double dX = args.X - lastPoint.X;                               // distance mouse has moved
                double dY = args.Y - lastPoint.Y;
                lastPoint = new Point(args.X, args.Y);

                // Alt key reduces sensitivity
                double factor = Sensitivity;
                if (key == Key.AltLeft || key == Key.AltRight)
                {
                    factor *= 0.25;                        // arbitrary change
                }

                double xProportion = +dX * factor / area.Width;
                double yProportion = -dY * factor / area.Height;
                if (Horizontal)
                {
                    pc.ZoomXAxes(xProportion, focusX);
                }
                if (Vertical)
                {
                    pc.ZoomYAxes(yProportion, focusY);
                }
                return(true);
            }
            return(false);
        }
示例#4
0
文件: PlotZoom.cs 项目: wwwK/XwPlot
        /// <summary>
        /// Mouse Scroll (wheel) method for PlotZoom interaction
        /// </summary>
        public override bool OnMouseScrolled(MouseScrolledEventArgs args, PlotCanvas pc)
        {
            double proportion = 0.1 * Sensitivity;              // use initial zoom of 10%
            double focusX = 0.5, focusY = 0.5;                  // default focus point

            double direction = 1;

            if (args.Direction == ScrollDirection.Down)
            {
                direction = -1;
            }

            // Zoom direction is +1 for Up/ZoomIn, or -1 for Down/ZoomOut
            proportion *= -direction;

            // delete previous focusPoint drawing
            pc.Canvas.QueueDraw(focusRect);

            Rectangle area = pc.PlotAreaBoundingBoxCache;

            if (area.Contains(args.X, args.Y))
            {
                focus.X = args.X;
                focus.Y = args.Y;
                focusX  = (double)(args.X - area.Left) / (double)area.Width;
                focusY  = (double)(area.Bottom - args.Y) / (double)area.Height;
            }

            // Zoom in/out for all defined axes
            pc.CacheAxes();
            pc.ZoomXAxes(proportion, focusX);
            pc.ZoomYAxes(proportion, focusY);

            double x = focus.X - 32;
            double y = focus.Y - 32;

            focusRect = new Rectangle(x, y, 64, 64);
            // draw new focusRect
            pc.Canvas.QueueDraw(focusRect);

            return(true);
        }
示例#5
0
        /// <summary>
        /// OnMouseMoved method for AxisScale interaction
        /// </summary>
        public override bool OnMouseMoved(MouseMovedEventArgs args, PlotCanvas pc)
        {
            if (dragging && physicalAxis != null)
            {
                pc.CacheAxes();

                double dX = (args.X - lastPoint.X);
                double dY = (args.Y - lastPoint.Y);
                lastPoint = new Point(args.X, args.Y);

                // In case the physical axis is not horizontal/vertical, combine dX and dY
                // in a way which preserves their sign and intuitive axis zoom sense, ie
                // because the physical origin is top-left, expand with +ve dX, but -ve dY
                double distance   = dX - dY;
                double proportion = distance * Sensitivity / physicalAxis.PhysicalLength;
                axis.IncreaseRange(proportion, focusRatio);
                return(true);
            }
            return(false);
        }
示例#6
0
文件: KeyActions.cs 项目: wwwK/XwPlot
        /// <summary>
        /// Handler for KeyPressed events
        /// </summary>
        /// <param name="args">the Xwt.KeyEventArgs</param>
        /// <param name="pc">the PlotCanvas</param>
        /// <returns>
        /// true if the underlying (cached) plot requires redrawing, otherwise false
        /// </returns>
        public override bool OnKeyPressed(KeyEventArgs args, PlotCanvas pc)
        {
            double factor = Sensitivity;
            Key key = args.Key;
            ModifierKeys modifiers = args.Modifiers;

            if ((modifiers & ModifierKeys.Alt) != 0) {
                factor = Sensitivity * altFactor;
            }

            if (key == Key.Home || key == Key.NumPadHome) {
                pc.SetOriginalDimensions ();
                return true;
            }
            if (key == Key.Left || key == Key.NumPadLeft) {
                pc.CacheAxes();
                pc.TranslateXAxes (factor * left);
                return true;
            }
            if (key == Key.Right || key == Key.NumPadRight) {
                pc.CacheAxes();
                pc.TranslateXAxes (factor*right);
                return true;
            }
            if (key == Key.Up || key == Key.NumPadUp) {
                pc.CacheAxes ();
                pc.TranslateYAxes (factor*up);
                return true;
            }
            if (key == Key.Down || key == Key.NumPadDown) {
                pc.CacheAxes ();
                pc.TranslateYAxes (factor*down);
                return true;
            }
            if (key == Key.Plus || key == Key.NumPadAdd) {
                pc.CacheAxes ();
                pc.ZoomXAxes (zoomIn*factor, symmetrical);
                pc.ZoomYAxes (zoomIn*factor, symmetrical);
                return true;
            }
            if (key == Key.Minus || key == Key.NumPadSubtract) {
                pc.CacheAxes ();
                pc.ZoomXAxes (zoomOut*factor, symmetrical);
                pc.ZoomYAxes (zoomOut*factor, symmetrical);
                return true;
            }
            return false;
        }
示例#7
0
        public override bool OnButtonReleased(ButtonEventArgs args, PlotCanvas pc)
        {
            bool modified = false;

            // delete previous overlay rectangle
            pc.Canvas.QueueDraw(selection);

            if (selectionActive)
            {
                selectionActive = false;
                Rectangle bounds = pc.PlotAreaBoundingBoxCache;
                if (!bounds.Contains(endPoint))
                {
                    // MouseUp outside plotArea - cancel selection
                    modified = false;
                }
                else
                {
                    pc.CacheAxes();
                    // Redefine range based on selection. The proportions for
                    // Min and Max do not require Min < Max, since they will
                    // be re-ordered by Axis.DefineRange if necessary
                    double xMin = startPoint.X - bounds.Left;
                    double yMin = bounds.Bottom - startPoint.Y;

                    double xMax = endPoint.X - bounds.Left;
                    double yMax = bounds.Bottom - endPoint.Y;

                    double xMinProp = xMin / bounds.Width;
                    double xMaxProp = xMax / bounds.Width;
                    double yMinProp = yMin / bounds.Height;
                    double yMaxProp = yMax / bounds.Height;

                    pc.DefineXAxes(xMinProp, xMaxProp);
                    pc.DefineYAxes(yMinProp, yMaxProp);
                    modified = true;
                }
            }
            return(modified);
        }
示例#8
0
        public override bool OnMouseMoved(MouseMovedEventArgs args, PlotCanvas pc)
        {
            Rectangle area = pc.PlotAreaBoundingBoxCache;

            if (dragging) {
                pc.CacheAxes();

                double dX = args.X - lastPoint.X;		// distance mouse has moved
                double dY = args.Y - lastPoint.Y;
                lastPoint = new Point (args.X, args.Y);

                // Axis translation required
                double xShift = -dX / area.Width;
                double yShift = +dY / area.Height;

                if (Horizontal) {
                    pc.TranslateXAxes (xShift);
                }
                if (Vertical) {
                    pc.TranslateYAxes (yShift);
                }
                return true;
            }
            return false;
        }
示例#9
0
        /// <summary>
        /// OnMouseMoved method for AxisScale interaction
        /// </summary>
        public override bool OnMouseMoved(MouseMovedEventArgs args, PlotCanvas pc)
        {
            if (dragging && physicalAxis != null) {
                pc.CacheAxes();

                double dX = (args.X - lastPoint.X);
                double dY = (args.Y - lastPoint.Y);
                lastPoint = new Point (args.X, args.Y);

                // In case the physical axis is not horizontal/vertical, combine dX and dY
                // in a way which preserves their sign and intuitive axis zoom sense, ie
                // because the physical origin is top-left, expand with +ve dX, but -ve dY
                double distance = dX - dY;
                double proportion = distance*Sensitivity /physicalAxis.PhysicalLength;
                axis.IncreaseRange (proportion, focusRatio);
                return true;
            }
            return false;
        }
示例#10
0
        /// <summary>
        /// Mouse Scroll (wheel) method for PlotZoom interaction
        /// </summary>
        public override bool OnMouseScrolled(MouseScrolledEventArgs args, PlotCanvas pc)
        {
            double proportion = 0.1*Sensitivity;	// use initial zoom of 10%
            double focusX = 0.5, focusY = 0.5;		// default focus point

            double direction = 1;
            if (args.Direction == ScrollDirection.Down) {
                direction = -1;
            }

            // Zoom direction is +1 for Up/ZoomIn, or -1 for Down/ZoomOut
            proportion *= -direction;

            // delete previous focusPoint drawing
            pc.Canvas.QueueDraw (focusRect);

            Rectangle area = pc.PlotAreaBoundingBoxCache;
            if (area.Contains(args.X, args.Y)) {
                focus.X = args.X;
                focus.Y = args.Y;
                focusX = (double)(args.X - area.Left)/(double)area.Width;
                focusY = (double)(area.Bottom - args.Y)/(double)area.Height;
            }

            // Zoom in/out for all defined axes
            pc.CacheAxes();
            pc.ZoomXAxes (proportion,focusX);
            pc.ZoomYAxes (proportion,focusY);

            double x = focus.X-32;
            double y = focus.Y-32;

            focusRect = new Rectangle (x, y, 64, 64);
            // draw new focusRect
            pc.Canvas.QueueDraw (focusRect);

            return (true);
        }
示例#11
0
        public override bool OnMouseMoved(MouseMovedEventArgs args, PlotCanvas pc)
        {
            Rectangle area = pc.PlotAreaBoundingBoxCache;

            if (scaling) {
                pc.CacheAxes();

                double dX = args.X - lastPoint.X;		// distance mouse has moved
                double dY = args.Y - lastPoint.Y;
                lastPoint = new Point (args.X, args.Y);

                // Alt key reduces sensitivity
                double factor = Sensitivity;
                if (key == Key.AltLeft || key == Key.AltRight) {
                    factor *= 0.25;	   // arbitrary change
                }

                double xProportion = +dX*factor/area.Width;
                double yProportion = -dY*factor/area.Height;
                if (Horizontal) {
                    pc.ZoomXAxes (xProportion, focusX);
                }
                if (Vertical) {
                    pc.ZoomYAxes (yProportion, focusY);
                }
                return true;
            }
            return false;
        }
示例#12
0
        public override bool OnMouseMoved(MouseMovedEventArgs args, PlotCanvas pc)
        {
            Rectangle area = pc.PlotAreaBoundingBoxCache;

            if (dragging && physicalAxis != null) {
                pc.CacheAxes();

                double dX = args.X - lastPoint.X;
                double dY = args.Y - lastPoint.Y;
                lastPoint = new Point (args.X, args.Y);

                double length = physicalAxis.PhysicalLength;

                if (translateX) {
                    double xShift = -dX / length;
                    pc.TranslateXAxes (xShift);
                }
                if (translateY) {
                    double yShift = +dY / length;
                    pc.TranslateYAxes (yShift);
                }
                return true;
            }
            return false;
        }
示例#13
0
        public override bool OnButtonReleased(ButtonEventArgs args, PlotCanvas pc)
        {
            bool modified = false;

            // delete previous overlay rectangle
            pc.Canvas.QueueDraw (selection);

            if (selectionActive) {
                selectionActive = false;
                Rectangle bounds = pc.PlotAreaBoundingBoxCache;
                if (!bounds.Contains(endPoint)) {
                    // MouseUp outside plotArea - cancel selection
                    modified = false;
                }
                else {
                    pc.CacheAxes();
                    // Redefine range based on selection. The proportions for
                    // Min and Max do not require Min < Max, since they will
                    // be re-ordered by Axis.DefineRange if necessary
                    double xMin = startPoint.X - bounds.Left;
                    double yMin = bounds.Bottom - startPoint.Y;

                    double xMax = endPoint.X - bounds.Left;
                    double yMax = bounds.Bottom - endPoint.Y;

                    double xMinProp = xMin/bounds.Width;
                    double xMaxProp = xMax/bounds.Width;
                    double yMinProp = yMin/bounds.Height;
                    double yMaxProp = yMax/bounds.Height;

                    pc.DefineXAxes (xMinProp, xMaxProp);
                    pc.DefineYAxes (yMinProp, yMaxProp);
                    modified = true;
                }
            }
            return modified;
        }
示例#14
0
        /// <summary>
        /// Handler for KeyPressed events
        /// </summary>
        /// <param name="args">the Xwt.KeyEventArgs</param>
        /// <param name="pc">the PlotCanvas</param>
        /// <returns>
        /// true if the underlying (cached) plot requires redrawing, otherwise false
        /// </returns>
        public override bool OnKeyPressed(KeyEventArgs args, PlotCanvas pc)
        {
            double factor = Sensitivity;
            Key key = args.Key;
            ModifierKeys modifiers = args.Modifiers;

            if ((modifiers & ModifierKeys.Alt) != 0) {
                factor = Sensitivity * altFactor;
            }

            if (key == Key.Home || key == Key.NumPadHome) {
                pc.SetOriginalDimensions ();
                return true;
            }
            if (key == Key.Left || key == Key.NumPadLeft) {
                pc.CacheAxes();
                pc.TranslateXAxes (factor * left);
                return true;
            }
            if (key == Key.Right || key == Key.NumPadRight) {
                pc.CacheAxes();
                pc.TranslateXAxes (factor*right);
                return true;
            }
            if (key == Key.Up || key == Key.NumPadUp) {
                pc.CacheAxes ();
                pc.TranslateYAxes (factor*up);
                return true;
            }
            if (key == Key.Down || key == Key.NumPadDown) {
                pc.CacheAxes ();
                pc.TranslateYAxes (factor*down);
                return true;
            }
            if (key == Key.Plus || key == Key.NumPadAdd) {
                pc.CacheAxes ();
                pc.ZoomXAxes (zoomIn*factor, symmetrical);
                pc.ZoomYAxes (zoomIn*factor, symmetrical);
                return true;
            }
            if (key == Key.Minus || key == Key.NumPadSubtract) {
                pc.CacheAxes ();
                pc.ZoomXAxes (zoomOut*factor, symmetrical);
                pc.ZoomYAxes (zoomOut*factor, symmetrical);
                return true;
            }
            return false;
        }