From 0044e4442df61269193e957612899e55e0f1b6a3 Mon Sep 17 00:00:00 2001 From: the_fiddler Date: Thu, 28 Oct 2010 11:10:57 +0000 Subject: [PATCH] Modified GetState() to return the combined state for all mouse/keyboard devices. --- Source/OpenTK/Input/KeyboardState.cs | 13 +++++++++++++ Source/OpenTK/Input/MouseState.cs | 17 +++++++++++++++++ .../OpenTK/Platform/Windows/WinRawKeyboard.cs | 12 +++++++----- Source/OpenTK/Platform/Windows/WinRawMouse.cs | 10 ++++++---- Source/OpenTK/Platform/X11/XI2Mouse.cs | 10 ++++++---- 5 files changed, 49 insertions(+), 13 deletions(-) diff --git a/Source/OpenTK/Input/KeyboardState.cs b/Source/OpenTK/Input/KeyboardState.cs index 99dea373..2d5c2e68 100644 --- a/Source/OpenTK/Input/KeyboardState.cs +++ b/Source/OpenTK/Input/KeyboardState.cs @@ -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 diff --git a/Source/OpenTK/Input/MouseState.cs b/Source/OpenTK/Input/MouseState.cs index 19c74451..5338d133 100644 --- a/Source/OpenTK/Input/MouseState.cs +++ b/Source/OpenTK/Input/MouseState.cs @@ -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 diff --git a/Source/OpenTK/Platform/Windows/WinRawKeyboard.cs b/Source/OpenTK/Platform/Windows/WinRawKeyboard.cs index c5c0b8b2..01bba01a 100644 --- a/Source/OpenTK/Platform/Windows/WinRawKeyboard.cs +++ b/Source/OpenTK/Platform/Windows/WinRawKeyboard.cs @@ -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) diff --git a/Source/OpenTK/Platform/Windows/WinRawMouse.cs b/Source/OpenTK/Platform/Windows/WinRawMouse.cs index ed614dfe..9d1676e3 100644 --- a/Source/OpenTK/Platform/Windows/WinRawMouse.cs +++ b/Source/OpenTK/Platform/Windows/WinRawMouse.cs @@ -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) diff --git a/Source/OpenTK/Platform/X11/XI2Mouse.cs b/Source/OpenTK/Platform/X11/XI2Mouse.cs index 6eb902f4..5290e2de 100644 --- a/Source/OpenTK/Platform/X11/XI2Mouse.cs +++ b/Source/OpenTK/Platform/X11/XI2Mouse.cs @@ -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)