I’m trying to make a sort of mouse wrap around feature in the GoToolPanning class. We have overriden the class in order to costumize the panning.
So basically, I have a method that checks if the mouse (while panning) is going out of the view, and if yes, changes the Cursor.Position to the other side of the view. That code is working great for other costum views.
Now, I’ve tried that on our implementation of GoToolPanning, without success. For example: I’m dragging toward the right side of the view, and when I leave the view, I teleport the mouse back to the left side of the view. What happens is that, when the mouse wraps at the other side, it thinks that the mouse moved from right to left. I tried changing the FirstInput.ViewPoint to the left side, but it doesn’t work.
Here’s the code I have:
public override void DoMouseMove()
// Take the mouse difference between the first input and last input
Point mouseDiff = new Point( this.FirstInput.ViewPoint.X - this.LastInput.MouseEventArgs.X, this.FirstInput.ViewPoint.Y - this.LastInput.MouseEventArgs.Y);
// If the difference is the same as last time, return
_LastMouseDiff.X = mouseDiff.X;
_LastMouseDiff.Y = mouseDiff.Y;
int x = LastInput.MouseEventArgs.X;
int y = LastInput.MouseEventArgs.Y;
// Check for wrap. x and y are mouse coordinates related to the view. If wrap occurs, they are changed to the other side of the view. Cursor.Position is also changed to move the mouse cursor at the right place
MiscUtils.WrapAround(this.View, ref x, ref y);
// If wrapping occured (coordinates x or y changed)
if (x != LastInput.MouseEventArgs.X || y != LastInput.MouseEventArgs.Y)
//Move the FirstInput to the other side
FirstInput.ViewPoint = new Point(FirstInput.ViewPoint.X + (x - LastInput.MouseEventArgs.X), FirstInput.ViewPoint.Y + (y - LastInput.MouseEventArgs.Y));
// Invert the mouse movement (to have the opposite direction of movement by default
this.LastInput.ViewPoint = new Point(this.FirstInput.ViewPoint.X + mouseDiff.X,this.FirstInput.ViewPoint.Y + mouseDiff.Y);
//Recreate the Mouse Event Args with new data
this.LastInput.MouseEventArgs = new MouseEventArgs(this.LastInput.MouseEventArgs.Button,this.LastInput.MouseEventArgs.Clicks,this.LastInput.ViewPoint.X,this.LastInput.ViewPoint.Y,this.LastInput.MouseEventArgs.Delta);
Any idea if that feature is possible? What data must I change with the values returned from my WrapAround method?