mirror of
https://github.com/Ryujinx/Opentk.git
synced 2025-01-26 22:11:11 +00:00
Merge pull request #199 from Frassle/anydown
[Input] Add IsAnyKey/ButtonDown to Keyboard/MouseState.
This commit is contained in:
commit
f0de8333a6
|
@ -140,6 +140,19 @@ namespace OpenTK.Input
|
||||||
get { return GetButton(Buttons.Start); }
|
get { return GetButton(Buttons.Start); }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a value indicating whether any button is pressed.
|
||||||
|
/// </summary>
|
||||||
|
/// <value><c>true</c> if any button is pressed; otherwise, <c>false</c>.</value>
|
||||||
|
public bool IsAnyButtonPressed
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
// If any bit is set then a button is down.
|
||||||
|
return buttons != 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <param name="left">A <see cref="GamePadButtons"/> instance to test for equality.</param>
|
/// <param name="left">A <see cref="GamePadButtons"/> instance to test for equality.</param>
|
||||||
/// <param name="right">A <see cref="GamePadButtons"/> instance to test for equality.</param>
|
/// <param name="right">A <see cref="GamePadButtons"/> instance to test for equality.</param>
|
||||||
public static bool operator ==(GamePadButtons left, GamePadButtons right)
|
public static bool operator ==(GamePadButtons left, GamePadButtons right)
|
||||||
|
|
|
@ -123,6 +123,19 @@ namespace OpenTK.Input
|
||||||
return (buttons & (1 << (int)button)) == 0;
|
return (buttons & (1 << (int)button)) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a value indicating whether any button is down.
|
||||||
|
/// </summary>
|
||||||
|
/// <value><c>true</c> if any button is down; otherwise, <c>false</c>.</value>
|
||||||
|
public bool IsAnyButtonDown
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
// If any bit is set then a button is down.
|
||||||
|
return buttons != 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a value indicating whether this instance is connected.
|
/// Gets a value indicating whether this instance is connected.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -39,7 +39,7 @@ namespace OpenTK.Input
|
||||||
#region Fields
|
#region Fields
|
||||||
|
|
||||||
// Allocate enough ints to store all keyboard keys
|
// Allocate enough ints to store all keyboard keys
|
||||||
const int IntSize = sizeof(int);
|
const int IntSize = sizeof(int) * 8;
|
||||||
const int NumInts = ((int)Key.LastKey + IntSize - 1) / IntSize;
|
const int NumInts = ((int)Key.LastKey + IntSize - 1) / IntSize;
|
||||||
// The following line triggers bogus CS0214 in gmcs 2.0.1, sigh...
|
// The following line triggers bogus CS0214 in gmcs 2.0.1, sigh...
|
||||||
unsafe fixed int Keys[NumInts];
|
unsafe fixed int Keys[NumInts];
|
||||||
|
@ -108,6 +108,33 @@ namespace OpenTK.Input
|
||||||
return !IsKeyDown(code);
|
return !IsKeyDown(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a value indicating whether any key is down.
|
||||||
|
/// </summary>
|
||||||
|
/// <value><c>true</c> if any key is down; otherwise, <c>false</c>.</value>
|
||||||
|
public bool IsAnyKeyDown
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
// If any bit is set then a key is down.
|
||||||
|
unsafe
|
||||||
|
{
|
||||||
|
fixed (int* k = Keys)
|
||||||
|
{
|
||||||
|
for(int i = 0; i < NumInts; ++i)
|
||||||
|
{
|
||||||
|
if (k[i] != 0)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a <see cref="System.Boolean"/> indicating whether this keyboard
|
/// Gets a <see cref="System.Boolean"/> indicating whether this keyboard
|
||||||
/// is connected.
|
/// is connected.
|
||||||
|
@ -226,8 +253,8 @@ namespace OpenTK.Input
|
||||||
{
|
{
|
||||||
ValidateOffset(offset);
|
ValidateOffset(offset);
|
||||||
|
|
||||||
int int_offset = offset / 32;
|
int int_offset = offset / IntSize;
|
||||||
int bit_offset = offset % 32;
|
int bit_offset = offset % IntSize;
|
||||||
unsafe
|
unsafe
|
||||||
{
|
{
|
||||||
fixed (int* k = Keys) { return (*(k + int_offset) & (1 << bit_offset)) != 0u; }
|
fixed (int* k = Keys) { return (*(k + int_offset) & (1 << bit_offset)) != 0u; }
|
||||||
|
@ -238,8 +265,8 @@ namespace OpenTK.Input
|
||||||
{
|
{
|
||||||
ValidateOffset(offset);
|
ValidateOffset(offset);
|
||||||
|
|
||||||
int int_offset = offset / 32;
|
int int_offset = offset / IntSize;
|
||||||
int bit_offset = offset % 32;
|
int bit_offset = offset % IntSize;
|
||||||
unsafe
|
unsafe
|
||||||
{
|
{
|
||||||
fixed (int* k = Keys) { *(k + int_offset) |= 1 << bit_offset; }
|
fixed (int* k = Keys) { *(k + int_offset) |= 1 << bit_offset; }
|
||||||
|
@ -250,8 +277,8 @@ namespace OpenTK.Input
|
||||||
{
|
{
|
||||||
ValidateOffset(offset);
|
ValidateOffset(offset);
|
||||||
|
|
||||||
int int_offset = offset / 32;
|
int int_offset = offset / IntSize;
|
||||||
int bit_offset = offset % 32;
|
int bit_offset = offset % IntSize;
|
||||||
unsafe
|
unsafe
|
||||||
{
|
{
|
||||||
fixed (int* k = Keys) { *(k + int_offset) &= ~(1 << bit_offset); }
|
fixed (int* k = Keys) { *(k + int_offset) &= ~(1 << bit_offset); }
|
||||||
|
|
|
@ -173,6 +173,19 @@ namespace OpenTK.Input
|
||||||
get { return IsButtonDown(MouseButton.Button2) ? ButtonState.Pressed : ButtonState.Released; }
|
get { return IsButtonDown(MouseButton.Button2) ? ButtonState.Pressed : ButtonState.Released; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a value indicating whether any button is down.
|
||||||
|
/// </summary>
|
||||||
|
/// <value><c>true</c> if any button is down; otherwise, <c>false</c>.</value>
|
||||||
|
public bool IsAnyButtonDown
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
// If any bit is set then a button is down.
|
||||||
|
return buttons != 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the absolute wheel position in integer units. This property is intended for XNA compatibility.
|
/// Gets the absolute wheel position in integer units. This property is intended for XNA compatibility.
|
||||||
/// To support high-precision mice, it is recommended to use <see cref="WheelPrecise"/> instead.
|
/// To support high-precision mice, it is recommended to use <see cref="WheelPrecise"/> instead.
|
||||||
|
|
Loading…
Reference in a new issue