Added argument validation for GetState(index) and serializes access to GetState() implementation. Clarified GetState() documentation to explain that it returns combined device state.

This commit is contained in:
the_fiddler 2010-10-28 11:10:19 +00:00
parent bb1619161f
commit a7427707ef
2 changed files with 29 additions and 11 deletions

View file

@ -40,28 +40,38 @@ namespace OpenTK.Input
static readonly IKeyboardDriver driver =
Platform.Factory.Default.CreateKeyboardDriver();
static readonly object SyncRoot = new object();
#endregion
#region Public Members
/// <summary>
/// Retrieves the KeyboardState for the default keyboard device.
/// Retrieves the combined <see cref="OpenTK.Input.KeyboardState"/> for all keyboard devices.
/// </summary>
/// <returns>A <see cref="OpenTK.Input.KeyboardState"/> structure containing the state of the keyboard device.</returns>
/// <returns>A <see cref="OpenTK.Input.KeyboardState"/> structure containing the combined state for all keyboard devices.</returns>
public static KeyboardState GetState()
{
return driver.GetState();
lock (SyncRoot)
{
return driver.GetState();
}
}
/// <summary>
/// Retrieves the KeyboardState for the specified keyboard device.
/// Retrieves the <see cref="OpenTK.Input.KeyboardState"/> for the specified keyboard device.
/// </summary>
/// <param name="index">The index of the keyboard device.</param>
/// <returns>A <see cref="OpenTK.Input.KeyboardState"/> structure containing the state of the keyboard device.</returns>
public static KeyboardState GetState(int index)
{
return driver.GetState(index);
if (index < 0)
throw new ArgumentOutOfRangeException("index");
lock (SyncRoot)
{
return driver.GetState(index);
}
}
#endregion

View file

@ -40,30 +40,38 @@ namespace OpenTK.Input
static readonly IMouseDriver driver =
Platform.Factory.Default.CreateMouseDriver();
static readonly object SyncRoot = new object();
#endregion
#region Public Members
/// <summary>
/// Retrieves the MouseState for the specified mouse device.
/// Retrieves the combined <see cref="OpenTK.Input.MouseState"/> for all specified mouse devices.
/// </summary>
/// <returns>A <see cref="OpenTK.Input.MouseState"/> structure containing the state of the mouse device.</returns>
/// <returns>A <see cref="OpenTK.Input.MouseState"/> structure containing the combined state of all mouse devices.</returns>
public static MouseState GetState()
{
return driver.GetState();
lock (SyncRoot)
{
return driver.GetState();
}
}
/// <summary>
/// Retrieves the MouseState for the specified mouse device.
/// Retrieves the <see cref="OpenTK.Input.MouseState"/> for the specified mouse device.
/// </summary>
/// <param name="index">The index of the mouse device.</param>
/// <returns>A <see cref="OpenTK.Input.MouseState"/> structure containing the state of the mouse device.</returns>
/// <returns>A <see cref="OpenTK.Input.MouseState"/> structure containing the state for the specified mouse device.</returns>
public static MouseState GetState(int index)
{
if (index < 0)
throw new ArgumentOutOfRangeException("index");
return driver.GetState(index);
lock (SyncRoot)
{
return driver.GetState(index);
}
}
#endregion