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) 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.Number1: WindowState = WindowState.Normal; break;
case Key.Number2: WindowState = WindowState.Maximized; break; case Key.Number2: WindowState = WindowState.Maximized; break;
@ -86,18 +91,9 @@ namespace Examples.Tests
{ {
refresh_text = true; refresh_text = true;
if (e.Button == MouseButton.Left) if (e.Button == MouseButton.Left && e.IsPressed)
{
if (e.IsPressed)
{ {
CursorVisible = false; 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)] [DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
public static extern bool ClipCursor(ref RECT rcClip); 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 Async input
#region GetCursorPos #region GetCursorPos

View file

@ -93,6 +93,8 @@ namespace OpenTK.Platform.Windows
KeyPressEventArgs key_press = new KeyPressEventArgs((char)0); KeyPressEventArgs key_press = new KeyPressEventArgs((char)0);
int cursor_visible_count = 0;
#endregion #endregion
#region Contructors #region Contructors
@ -842,8 +844,27 @@ namespace OpenTK.Platform.Windows
public bool CursorVisible public bool CursorVisible
{ {
get { return true; } get { return cursor_visible_count > 0; }
set { Functions.ShowCursor(value); } 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 #endregion