Fixed CursorVisible getter.

If necessary, re-grab the cursor whenever the window changes position/size.
This commit is contained in:
the_fiddler 2010-10-22 13:36:05 +00:00
parent 327941be33
commit b2ccc8f089

View file

@ -209,6 +209,10 @@ namespace OpenTK.Platform.Windows
if (suppress_resize <= 0 && Resize != null) if (suppress_resize <= 0 && Resize != null)
Resize(this, EventArgs.Empty); Resize(this, EventArgs.Empty);
} }
// Ensure cursor remains grabbed
if (!CursorVisible)
GrabCursor();
} }
} }
break; break;
@ -228,6 +232,10 @@ namespace OpenTK.Platform.Windows
} }
} }
// Ensure cursor remains grabbed
if (!CursorVisible)
GrabCursor();
break; break;
case WindowMessage.SIZE: case WindowMessage.SIZE:
@ -250,6 +258,10 @@ namespace OpenTK.Platform.Windows
WindowStateChanged(this, EventArgs.Empty); WindowStateChanged(this, EventArgs.Empty);
} }
// Ensure cursor remains grabbed
if (!CursorVisible)
GrabCursor();
break; break;
#endregion #endregion
@ -630,6 +642,24 @@ namespace OpenTK.Platform.Windows
suppress_resize--; suppress_resize--;
} }
void GrabCursor()
{
Win32Rectangle rect = Win32Rectangle.From(ClientRectangle);
Point pos = PointToScreen(new Point(rect.left, rect.top));
rect.left = pos.X;
rect.top = pos.Y;
if (!Functions.ClipCursor(ref rect))
Debug.WriteLine(String.Format("Failed to grab cursor. Error: {0}",
Marshal.GetLastWin32Error()));
}
static void UngrabCursor()
{
if (!Functions.ClipCursor(IntPtr.Zero))
Debug.WriteLine(String.Format("Failed to ungrab cursor. Error: {0}",
Marshal.GetLastWin32Error()));
}
#endregion #endregion
#region INativeWindow Members #region INativeWindow Members
@ -844,7 +874,7 @@ namespace OpenTK.Platform.Windows
public bool CursorVisible public bool CursorVisible
{ {
get { return cursor_visible_count > 0; } // Not used get { return cursor_visible_count >= 0; } // Not used
set set
{ {
if (value && cursor_visible_count < 0) if (value && cursor_visible_count < 0)
@ -855,9 +885,7 @@ namespace OpenTK.Platform.Windows
} }
while (cursor_visible_count < 0); while (cursor_visible_count < 0);
if (!Functions.ClipCursor(IntPtr.Zero)) UngrabCursor();
Debug.WriteLine(String.Format("Failed to ungrab cursor. Error: {0}",
Marshal.GetLastWin32Error()));
} }
else if (!value && cursor_visible_count >= 0) else if (!value && cursor_visible_count >= 0)
{ {
@ -867,13 +895,7 @@ namespace OpenTK.Platform.Windows
} }
while (cursor_visible_count >= 0); while (cursor_visible_count >= 0);
Win32Rectangle rect = Win32Rectangle.From(ClientRectangle); GrabCursor();
Point pos = PointToScreen(new Point(rect.left, rect.top));
rect.left = pos.X;
rect.top = pos.Y;
if (!Functions.ClipCursor(ref rect))
Debug.WriteLine(String.Format("Failed to grab cursor. Error: {0}",
Marshal.GetLastWin32Error()));
} }
} }
} }