Skip to content

Commit

Permalink
SADXLVL2: Fixed mouse wrapping in the scene panel and fixed a small u…
Browse files Browse the repository at this point in the history
…nrelated bug.
  • Loading branch information
michael-fadely committed Feb 24, 2015
1 parent 9bbec47 commit d0395e3
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions SADXLVL2/MainForm.cs
Expand Up @@ -53,7 +53,7 @@ void Application_ThreadException(object sender, System.Threading.ThreadException
bool zoomKeyDown;

// TODO: Make these both configurable.
bool mouseWrapScreen = true;
bool mouseWrapScreen = false;
ushort mouseWrapThreshold = 2;

// helpers / ui stuff
Expand Down Expand Up @@ -1663,32 +1663,35 @@ private void Panel1_MouseMove(object sender, MouseEventArgs e)
}

Point mouseDelta = mouseEvent - (Size)mouseLast;
bool performedWrap = false;

if (e.Button != MouseButtons.None)
{
// TODO: Figure out why RectangleToScreen gets offset values for panel1
Rectangle mouseBounds = (mouseWrapScreen) ? Screen.GetBounds(ClientRectangle) : RectangleToScreen(ClientRectangle);
Console.WriteLine(mouseBounds);
Rectangle mouseBounds = (mouseWrapScreen) ? Screen.GetBounds(ClientRectangle) : panel1.RectangleToScreen(panel1.Bounds);

if (Cursor.Position.X < (mouseBounds.Left + mouseWrapThreshold))
{
Cursor.Position = new Point(mouseBounds.Right - mouseWrapThreshold, Cursor.Position.Y);
mouseEvent = new Point(mouseEvent.X + mouseBounds.Width - mouseWrapThreshold, mouseEvent.Y);
performedWrap = true;
}
else if (Cursor.Position.X > (mouseBounds.Right - mouseWrapThreshold))
{
Cursor.Position = new Point(mouseBounds.Left + mouseWrapThreshold, Cursor.Position.Y);
mouseEvent = new Point(mouseEvent.X - mouseBounds.Width + mouseWrapThreshold, mouseEvent.Y);
performedWrap = true;
}
if (Cursor.Position.Y < (mouseBounds.Top + mouseWrapThreshold))
{
Cursor.Position = new Point(Cursor.Position.X, mouseBounds.Bottom - mouseWrapThreshold);
mouseEvent = new Point(mouseEvent.X, mouseEvent.Y + mouseBounds.Height - mouseWrapThreshold);
performedWrap = true;
}
else if (Cursor.Position.Y > (mouseBounds.Bottom - mouseWrapThreshold))
{
Cursor.Position = new Point(Cursor.Position.X, mouseBounds.Top + mouseWrapThreshold);
mouseEvent = new Point(mouseEvent.X, mouseEvent.Y - mouseBounds.Height + mouseWrapThreshold);
performedWrap = true;
}
}

Expand Down Expand Up @@ -1784,7 +1787,7 @@ private void Panel1_MouseMove(object sender, MouseEventArgs e)
break;
}

if (Math.Abs(mouseDelta.X / 2) * cam.MoveSpeed > 0 || Math.Abs(mouseDelta.Y / 2) * cam.MoveSpeed > 0)
if (performedWrap || Math.Abs(mouseDelta.X / 2) * cam.MoveSpeed > 0 || Math.Abs(mouseDelta.Y / 2) * cam.MoveSpeed > 0)
mouseLast = mouseEvent;
}

Expand Down

0 comments on commit d0395e3

Please sign in to comment.