mono/MonoGame — pull request #2778 by LynxStar (2014-07-04 01:15:54+00:00)
Title: Implemented locking the cursor into the window for the Windows platform

I exposed the ability to restrict the mouse to the window.

On a somewhat related note I ended up doing this by running into some difference between MonoGame and XNA. If you have a windowed game and your cursor leaves the window it stops updating its relative coordinates.

Mouse state behaves different in MonoGame than XNA 4. I quickly checked that XNA it will happily provide you with relative coordinates that track your cursor outside of the window. After digging through the source I believe this is because of WinFormsGameForm's method of handling mouse events. The events delegated through the Form's control's event handlers. This leads to MouseMove not firing when the mouse is not over the control.

[WinFormsGameWindow.cs] (https://github.com/mono/MonoGame/blob/develop/MonoGame.Framework/Windows/WinFormsGameWindow.cs#L184)

This could be solved by updating the [Mouse.GetState] (https://github.com/mono/MonoGame/blob/develop/MonoGame.Framework/Input/Mouse.cs#L128) to grab the real mouse location and translate it back into the relative position.

I'll happily go create a separate feature branch to tackle that. Regardless being able to leverage the Form's cursor clip logic directly is heavily preferable than readjust the cursor back in bounds with a update loop's worth of delay.