/// <summary> /// Handler for KeyPress events /// </summary> /// <param name="key">the NPlot key enumeration</param> /// <param name="ps">the InteractivePlotSurface2D</param> /// <returns></returns> public override bool DoKeyPress(Modifier keys, InteractivePlotSurface2D ps) { double factor = Sensitivity; if (((keys & Modifier.Alt) != 0)) { factor *= altFactor; } if ((keys & Modifier.Home) != 0) { ps.SetOriginalDimensions(); return(true); } if ((keys & Modifier.Left) != 0) { ps.CacheAxes(); ps.TranslateXAxes(left * factor); return(true); } if ((keys & Modifier.Right) != 0) { ps.CacheAxes(); ps.TranslateXAxes(right * factor); return(true); } if ((keys & Modifier.Up) != 0) { ps.CacheAxes(); ps.TranslateYAxes(up * factor); return(true); } if ((keys & Modifier.Down) != 0) { ps.CacheAxes(); ps.TranslateYAxes(down * factor); return(true); } if ((keys & Modifier.Plus) != 0) { ps.CacheAxes(); ps.ZoomXAxes(zoomIn * factor, symmetrical); ps.ZoomYAxes(zoomIn * factor, symmetrical); return(true); } if ((keys & Modifier.Minus) != 0) { ps.CacheAxes(); ps.ZoomXAxes(zoomOut * factor, symmetrical); ps.ZoomYAxes(zoomOut * factor, symmetrical); return(true); } return(false); }
/// <summary> /// MouseMove method for PlotDrag interaction /// </summary> /// <param name="X">mouse X position</param> /// <param name="Y"> mouse Y position</param> /// <param name="keys"> mouse and keyboard modifiers</param> /// <param name="ps">the InteractivePlotSurface2D</param> public override bool DoMouseMove(int X, int Y, Modifier keys, InteractivePlotSurface2D ps) { Rectangle area = ps.PlotAreaBoundingBoxCache; // Mouse Left-Button gives Plot Drag, Ctrl.Left-Button Zooms if (((keys & Modifier.Button1) != 0) && dragInitiated_) { ps.CacheAxes(); double dX = X - lastPoint_.X; // distance mouse has moved double dY = Y - lastPoint_.Y; lastPoint_ = new Point(X, Y); if ((keys & Modifier.Control) != 0) { // Axis re-ranging required double factor = Sensitivity; if ((keys & Modifier.Alt) != 0) { factor *= 0.25; // arbitrary change } double xProportion = +dX * factor / area.Width; double yProportion = -dY * factor / area.Height; if (horizontal_) { ps.ZoomXAxes(xProportion, focusX); } if (vertical_) { ps.ZoomYAxes(yProportion, focusY); } } else { // Axis translation required double xShift = -dX / area.Width; double yShift = +dY / area.Height; if (horizontal_) { ps.TranslateXAxes(xShift); } if (vertical_) { ps.TranslateYAxes(yShift); } } return(true); } return(false); }
/// <summary> /// Mouse Scroll (wheel) method for AxisZoom interaction /// </summary> public override bool DoMouseScroll(int X, int Y, int direction, Modifier keys, InteractivePlotSurface2D ps) { // Add timeout into Gtk loop when scroll starts - Omit for now // GLib.Timeout.Add (500, new GLib.TimeoutHandler (zoomTimeout) ); zoomActive = true; surface = ps; double proportion = 0.1 * sensitivity_; // use initial zoom of 10% double focusX = 0.5, focusY = 0.5; // default focus point // Zoom direction is +1 for Up/ZoomIn, or -1 for Down/ZoomOut proportion *= -direction; // delete previous focusPoint drawing - this is all a bit 'tentative' ps.QueueDraw(focusRect); Rectangle area = ps.PlotAreaBoundingBoxCache; if (area.Contains(X, Y)) { p.X = X; p.Y = Y; focusX = (double)(X - area.Left) / (double)area.Width; focusY = (double)(area.Bottom - Y) / (double)area.Height; } // Zoom in/out for all defined axes ps.CacheAxes(); ps.ZoomXAxes(proportion, focusX); ps.ZoomYAxes(proportion, focusY); // Note: r = 16, and Focus extents range from x-2*r-1 to x+2*r+1, y-2*r-1 to y+2*r+1 int x = p.X - 31; int y = p.Y - 31; focusRect = new Rectangle(x, y, 64, 64); // draw new focusRect ps.QueueDraw(focusRect); return(true); }
/// <summary> /// Handler for KeyPress events /// </summary> /// <param name="key">the NPlot key enumeration</param> /// <param name="ps">the InteractivePlotSurface2D</param> /// <returns></returns> public override bool DoKeyPress(Modifier keys, InteractivePlotSurface2D ps) { double factor = Sensitivity; if (((keys & Modifier.Alt) != 0)) { factor *= altFactor; } if ((keys & Modifier.Home) != 0) { ps.SetOriginalDimensions(); return true; } if ((keys & Modifier.Left) != 0) { ps.CacheAxes(); ps.TranslateXAxes(left * factor); return true; } if ((keys & Modifier.Right) != 0) { ps.CacheAxes(); ps.TranslateXAxes(right * factor); return true; } if ((keys & Modifier.Up) != 0) { ps.CacheAxes(); ps.TranslateYAxes(up * factor); return true; } if ((keys & Modifier.Down) != 0) { ps.CacheAxes(); ps.TranslateYAxes(down * factor); return true; } if ((keys & Modifier.Plus) != 0) { ps.CacheAxes(); ps.ZoomXAxes(zoomIn * factor, symmetrical); ps.ZoomYAxes(zoomIn * factor, symmetrical); return true; } if ((keys & Modifier.Minus) != 0) { ps.CacheAxes(); ps.ZoomXAxes(zoomOut * factor, symmetrical); ps.ZoomYAxes(zoomOut * factor, symmetrical); return true; } return false; }
/// <summary> /// MouseMove method for PlotDrag interaction /// </summary> /// <param name="X">mouse X position</param> /// <param name="Y"> mouse Y position</param> /// <param name="keys"> mouse and keyboard modifiers</param> /// <param name="ps">the InteractivePlotSurface2D</param> public override bool DoMouseMove(int X, int Y, Modifier keys, InteractivePlotSurface2D ps) { Rectangle area = ps.PlotAreaBoundingBoxCache; // Mouse Left-Button gives Plot Drag, Ctrl.Left-Button Zooms if (((keys & Modifier.Button1) != 0) && dragInitiated_) { ps.CacheAxes(); double dX = X - lastPoint_.X; // distance mouse has moved double dY = Y - lastPoint_.Y; lastPoint_ = new Point(X, Y); if ((keys & Modifier.Control) != 0) { // Axis re-ranging required double factor = Sensitivity; if ((keys & Modifier.Alt) != 0) { factor *= 0.25; // arbitrary change } double xProportion = +dX * factor / area.Width; double yProportion = -dY * factor / area.Height; if (horizontal_) { ps.ZoomXAxes(xProportion, focusX); } if (vertical_) { ps.ZoomYAxes(yProportion, focusY); } } else { // Axis translation required double xShift = -dX / area.Width; double yShift = +dY / area.Height; if (horizontal_) { ps.TranslateXAxes(xShift); } if (vertical_) { ps.TranslateYAxes(yShift); } } return true; } return false; }
/// <summary> /// Mouse Scroll (wheel) method for AxisZoom interaction /// </summary> public override bool DoMouseScroll(int X, int Y, int direction, Modifier keys, InteractivePlotSurface2D ps) { // Add timeout into Gtk loop when scroll starts - Omit for now // GLib.Timeout.Add (500, new GLib.TimeoutHandler (zoomTimeout) ); zoomActive = true; surface = ps; double proportion = 0.1 * sensitivity_; // use initial zoom of 10% double focusX = 0.5, focusY = 0.5; // default focus point // Zoom direction is +1 for Up/ZoomIn, or -1 for Down/ZoomOut proportion *= -direction; // delete previous focusPoint drawing - this is all a bit 'tentative' ps.QueueDraw(focusRect); Rectangle area = ps.PlotAreaBoundingBoxCache; if (area.Contains(X, Y)) { p.X = X; p.Y = Y; focusX = (double)(X - area.Left) / (double)area.Width; focusY = (double)(area.Bottom - Y) / (double)area.Height; } // Zoom in/out for all defined axes ps.CacheAxes(); ps.ZoomXAxes(proportion, focusX); ps.ZoomYAxes(proportion, focusY); // Note: r = 16, and Focus extents range from x-2*r-1 to x+2*r+1, y-2*r-1 to y+2*r+1 int x = p.X - 31; int y = p.Y - 31; focusRect = new Rectangle(x, y, 64, 64); // draw new focusRect ps.QueueDraw(focusRect); return (true); }