Mouse wraparound

Hi,
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:

[code]
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
if (mouseDiff.Equals(_LastMouseDiff))
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);
base.DoMouseMove ();
}[/code]
Any idea if that feature is possible? What data must I change with the values returned from my WrapAround method?

I’m sorry, but I don’t understand what you are trying to do. Did you consider all of the properties that GoToolPanning has?
I tried your code, but of course it couldn’t compile.
You probably also want to set the LastInput.DocPoint, if you set the .ViewPoint. I don’t know if it would matter in this case, but it’s a good policy to keep those two properties in sync.

Hum,
There’s two things that I’m trying to do:
1- I’m panning in the opposite direction (that works great)
2- For the “WrapAround” feature, I’ll try to explain the behaviour. For example, if I’m panning and my cursor is going on the right side of the view. If the cursors gets out of the view (right side), I want it to flip on the other side (left side) and continue panning. So while I’m panning, I’ll never leave the view (so the cursor doesn’t get lost somewhere else when I stop panning). Leaving on the top side gets the cursor back down on the bottom side.
What my MiscUtils.WrapAround methods does, is that it checks if the cursor is in the given view. If not, it will flip the cursor on the other side of the view. (Changes the Cursor.Position, and also the mouse coordinates position related to the view - the ref x and ref y).
The tricky thing that must not happen is that when I flip on the other side (going toward the right side of the view, and flipping on the left side for example), I don’t want to have a panning action that equals moving from the right side to the left side, but always going on the same direction (right). And that is what I’m not able to do. GoToolPanning seems to notice that the cursor changed his position from right to left, and thus pans a great distance from right to left.
Geez, hard to explain by text… :(
So, I played with FirstInput.ViewPoint, FirstInput.DocPoint, LastInput.ViewPoint, LastInput.DocPoint, LastInput.MouseEventArgs.
Oh, one thing to add is that i’m panning manually (AutoPan = false and modal = false)

Ah, OK, so you are doing manual panning, and you want to be able to keep dragging the mouse towards the right forever, while keeping the cursor inside the view. But I guess you don’t want to do any autoscrolling, or do you? Autoscrolling would be an easy solution to your problem.
A disadvantage to the user of what I think you are trying to do is that the mouse will tend to migrate physically very far from the user/keyboard. Picking up the mouse while holding down a button is inconvenient. But I suppose that’s not a problem with some kinds of pointing devices.
Here’s a simplified version of what GoToolPanning normally does:
[Serializable]
public class CustomPanningTool : GoToolPanning {
public CustomPanningTool(GoView view) : base(view) {}
public override void Stop() {
if (this.AutoPan) {
base.Stop();
} else {
myActive = false;
}
this.View.CursorName = “default”;
}
public override void DoMouseDown() {
if (this.AutoPan) {
base.DoMouseDown();
} else {
myActive = true;
myLastViewPoint = this.LastInput.ViewPoint;
}
}
public override void DoMouseMove() {
if (this.AutoPan) {
base.DoMouseMove();
} else {
if (myActive) {
PointF pos = this.View.DocPosition;
Size viewdelta = new Size(this.LastInput.ViewPoint.X-myLastViewPoint.X, this.LastInput.ViewPoint.Y-myLastViewPoint.Y);
SizeF docdelta = this.View.ConvertViewToDoc(viewdelta);
myLastViewPoint = this.LastInput.ViewPoint;
this.View.DocPosition = new PointF(pos.X+docdelta.Width, pos.Y+docdelta.Height);
} else {
if (this.Modal) {
return;
} else {
myActive = true;
myLastViewPoint = this.LastInput.ViewPoint;
}
}
}
}
public override void DoMouseUp() {
if (this.AutoPan) {
base.DoMouseUp();
} else {
if (this.Modal) {
myActive = false;
} else {
StopTool();
}
}
}
[NonSerialized]
private bool myActive = false;
[NonSerialized]
private Point myLastViewPoint;
}
Simplifications involve not AutoPanning and not supporting GoWeb or GoPocket.
Now that you have the standard code, you can modify it for your own purposes.

Cool thx!
That’s what I thought, GoToolPanning was keeping his own mouse position in “myLastViewPoint”. Works perfectly now with that code! Had to add only a call to my method and things go on perfectly.
AutoScrolling is a nice idea, but our other tools all go with the “Wraparound” idea. Anyway, thanks for the comments.
Again, thank you!