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 5fd0340bb9
commit 415755a257
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 #endregion
#region Private Members #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 #endregion
#region Private Members #region Private Members

View file

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

View file

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

View file

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