public static void TransposeToAllignPoints(this IView2D view, Point2D world, Point screen, AxisSelection mode = AxisSelection.Both) { Point2D screenPosWS = view.ScreenSpace2WorldSpace(screen.X, screen.Y); //nudge the screen so the mouse is zooming in on a point; Point2D nudge = screenPosWS - world; nudge *= view.Zoom; switch (mode) { case AxisSelection.Both: view.TransformX += nudge.X; view.TransformY += nudge.Y; break; case AxisSelection.Vertical: view.TransformY += nudge.Y; break; case AxisSelection.Horizontal: view.TransformX += nudge.X; break; } }
protected void adjustZoomByWheel(int delta, int x, int y) { try { if (delta != 0) { if (view != null) { Point2D oldMousePosWS = view.ScreenSpace2WorldSpace(x, y); //double oldZoom = view.Zoom; //double newZoom = oldZoom + (delta / 1200.0); //double factor = Math.Pow(view.Zoom, Math.Log10(Math.Abs(delta))); double factor = Math.Abs((view.Zoom / 15) * (delta / 120)); factor = (delta > 0) ? factor : -factor; double newZoom = view.Zoom + factor; if (isValidZoomLevel(newZoom)) { view.Zoom = newZoom; view.TransposeToAllignPoints(oldMousePosWS, new Point(x, y)); } else { //WDAppLog.Debug("bad zoom: " + newZoom); view.Zoom = Math.Max(Math.Min(newZoom, MaxZoom), MinZoom); view.TransposeToAllignPoints(oldMousePosWS, new Point(x, y)); } DoViewChangeTasks(); picMain.Refresh(); } } } catch { } }
public MouseEventWorldSpace(int x, int y, MouseButtons button, IView2D view) { location = view.ScreenSpace2WorldSpace(new Point2D(x, y)); this.Button = button; }
public static Point2D ScreenSpace2WorldSpace(this IView2D view, Point screenSpace) { return(view.ScreenSpace2WorldSpace(screenSpace.X, screenSpace.Y)); }