goldenpockets's picture

Capture mouse on GameWindow

Im planning to make a RTS game and I need my GameWindow to capture the mouse so it cant get out of the client rectangle.
This lets the user to play in windowed mode: he can move in the scenario when the mouse reaches the edge of the window.

I managed to do this on windows forms. Quick example:

namespace WindowsFormsApplication1
{
	public partial class Form1 : Form
	{
		public Form1()
		{
			InitializeComponent();
		}
 
		private void Form1_Activated(object sender, EventArgs e)
		{
			Rectangle rc = RectangleToScreen(ClientRectangle);
			Cursor.Position = new Point(rc.Left + rc.Width / 2, rc.Top + rc.Height / 2);
			Cursor.Clip = rc;
			Capture = true;
			Cursor = Cursors.Cross;
		}
	}
}

Any way to do this with OpenTK?