Modified GetState() to return the combined state for all mouse/keyboard devices.

This commit is contained in:
the_fiddler 2010-10-28 11:10:57 +00:00
parent a7427707ef
commit 0044e4442d
5 changed files with 49 additions and 13 deletions

View file

@ -208,6 +208,19 @@ namespace OpenTK.Input
}
}
internal void MergeBits(KeyboardState other)
{
unsafe
{
int* k2 = other.Keys;
fixed (int* k1 = Keys)
{
for (int i = 0; i < NumInts; i++)
*(k1 + i) |= *(k2 + i);
}
}
}
#endregion
#region Private Members

View file

@ -300,6 +300,23 @@ namespace OpenTK.Input
}
}
internal void MergeBits(MouseState other)
{
unsafe
{
int* b2 = other.Buttons;
fixed (int* b1 = Buttons)
{
for (int i = 0; i < NumInts; i++)
*(b1 + i) |= *(b2 + i);
}
WheelPrecise += other.WheelPrecise;
X += other.X;
Y += other.Y;
}
}
#endregion
#region Private Members

View file

@ -68,7 +68,7 @@ namespace OpenTK.Platform.Windows
#endregion
#region internal static void UpdateKeyboardList()
#region UpdateKeyboardList
internal void UpdateKeyboardList()
{
@ -264,10 +264,12 @@ namespace OpenTK.Platform.Windows
public KeyboardState GetState()
{
if (keyboards.Count > 0)
return keyboards[0];
else
return new KeyboardState();
KeyboardState master = new KeyboardState();
foreach (KeyboardState ks in keyboards)
{
master.MergeBits(ks);
}
return master;
}
public KeyboardState GetState(int index)

View file

@ -65,10 +65,12 @@ namespace OpenTK.Platform.Windows
public MouseState GetState()
{
if (mice.Count > 0)
return mice[0];
else
return new MouseState();
MouseState master = new MouseState();
foreach (MouseState ms in mice)
{
master.MergeBits(ms);
}
return master;
}
public MouseState GetState(int index)

View file

@ -104,10 +104,12 @@ namespace OpenTK.Platform.X11
public MouseState GetState()
{
ProcessEvents();
if (mice.Count > 0)
return mice[0];
else
return new MouseState();
MouseState master = new MouseState();
foreach (MouseState ms in mice)
{
master.MergeBits(ms);
}
return master;
}
public MouseState GetState(int index)