/// <summary> /// MouseUp method for RubberBand selection /// </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 DoMouseUp(int X, int Y, Modifier keys, InteractivePlotSurface2D ps) { bool modified = false; if (selectionActive_) { // erase current (clipped) rectangle ps.DrawOverlayRectangle(startPoint_, endPoint_, Color.White, false); endPoint_.X = X; endPoint_.Y = Y; Rectangle bounds = ps.PlotAreaBoundingBoxCache; if (!bounds.Contains(endPoint_)) { // MouseUp outside plotArea - cancel selection modified = false; } else { ps.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; ps.DefineAxis(ps.XAxis1, xMinProp, xMaxProp); ps.DefineAxis(ps.XAxis2, xMinProp, xMaxProp); ps.DefineAxis(ps.YAxis1, yMinProp, yMaxProp); ps.DefineAxis(ps.YAxis2, yMinProp, yMaxProp); modified = true; } selectionActive_ = false; startPoint_ = unset_; endPoint_ = unset_; } return modified; }
/// <summary> /// MouseMove method for AxisDrag 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) { if (((keys & Modifier.Button1) != 0) && dragging_&& physicalAxis_ != null ) { ps.CacheAxes(); float dX = (X - lastPoint_.X); float dY = (Y - lastPoint_.Y); lastPoint_ = new Point(X, 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; }
/// <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.ZoomAxis(ps.XAxis1, xProportion, focusX); ps.ZoomAxis(ps.XAxis2, xProportion, focusX); } if (vertical_) { ps.ZoomAxis(ps.YAxis1, yProportion, focusY); ps.ZoomAxis(ps.YAxis2, yProportion, focusY); } } else { // Axis translation required double xShift = -dX / area.Width; double yShift = +dY / area.Height; if (horizontal_) { ps.TranslateAxis(ps.XAxis1, xShift); ps.TranslateAxis(ps.XAxis2, xShift); } if (vertical_) { ps.TranslateAxis(ps.YAxis1, yShift); ps.TranslateAxis(ps.YAxis2, yShift); } } return true; } return false; }