Added initial code for mouse grabbing. Modified GameWindowStates to test this.

This commit is contained in:
the_fiddler 2010-10-19 09:20:59 +00:00
parent a18825a062
commit 00311cdb13
3 changed files with 34 additions and 14 deletions

View file

@ -48,7 +48,12 @@ namespace Examples.Tests
{
switch (e.Key)
{
case OpenTK.Input.Key.Escape: this.Exit(); break;
case OpenTK.Input.Key.Escape:
if (!CursorVisible)
CursorVisible = true;
else
Exit();
break;
case Key.Number1: WindowState = WindowState.Normal; break;
case Key.Number2: WindowState = WindowState.Maximized; break;
@ -86,18 +91,9 @@ namespace Examples.Tests
{
refresh_text = true;
if (e.Button == MouseButton.Left)
{
if (e.IsPressed)
if (e.Button == MouseButton.Left && e.IsPressed)
{
CursorVisible = false;
move_window = true;
}
else
{
CursorVisible = true;
move_window = false;
}
}
}

View file

@ -957,6 +957,9 @@ namespace OpenTK.Platform.Windows
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
public static extern bool ClipCursor(ref RECT rcClip);
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
public static extern bool ClipCursor(IntPtr rcClip);
#region Async input
#region GetCursorPos

View file

@ -93,6 +93,8 @@ namespace OpenTK.Platform.Windows
KeyPressEventArgs key_press = new KeyPressEventArgs((char)0);
int cursor_visible_count = 0;
#endregion
#region Contructors
@ -842,8 +844,27 @@ namespace OpenTK.Platform.Windows
public bool CursorVisible
{
get { return true; }
set { Functions.ShowCursor(value); }
get { return cursor_visible_count > 0; }
set
{
if (value && cursor_visible_count < 0)
{
cursor_visible_count = Functions.ShowCursor(true);
if (!Functions.ClipCursor(IntPtr.Zero))
Debug.WriteLine(String.Format("Failed to grab cursor. Error: {0}",
Marshal.GetLastWin32Error()));
}
else if (!value && cursor_visible_count >= 0)
{
cursor_visible_count = Functions.ShowCursor(false);
Win32Rectangle rect = Win32Rectangle.From(ClientRectangle);
if (!Functions.ClipCursor(ref rect))
Debug.WriteLine(String.Format("Failed to grab cursor. Error: {0}",
Marshal.GetLastWin32Error()));
}
}
}
#endregion