aboutsummaryrefslogtreecommitdiffstatsci
path: root/src
diff options
context:
space:
mode:
authorjpbruyere <jp.bruyere@hotmail.com>2016-02-13 18:10:23 +0100
committerjpbruyere <jp.bruyere@hotmail.com>2016-03-01 05:01:44 +0100
commitfa6dd3d807f7c7c9292b5f4d5cc10406d10e173d (patch)
tree27146a232022554983c8fa92f7be757554774e78 /src
parentc7a9d36bd679f827b649e2b792465b127fd577d1 (diff)
base changed done, need mouse state to be updated
Diffstat (limited to 'src')
-rw-r--r--src/BubblingMouseButtonEventArgs.cs1
-rw-r--r--src/GraphicObjects/Button.cs1
-rw-r--r--src/GraphicObjects/CheckBox.cs1
-rw-r--r--src/GraphicObjects/Container.cs1
-rw-r--r--src/GraphicObjects/Expandable.cs1
-rw-r--r--src/GraphicObjects/FileDialog.cs1
-rw-r--r--src/GraphicObjects/GraphicObject.cs8
-rw-r--r--src/GraphicObjects/Image.cs6
-rw-r--r--src/GraphicObjects/Label.cs1
-rw-r--r--src/GraphicObjects/ListBox.cs2
-rw-r--r--src/GraphicObjects/PrivateContainer.cs1
-rw-r--r--src/GraphicObjects/RadioButton.cs1
-rw-r--r--src/GraphicObjects/Scroller.cs11
-rw-r--r--src/GraphicObjects/Slider.cs6
-rw-r--r--src/GraphicObjects/Spinner.cs1
-rw-r--r--src/GraphicObjects/Splitter.cs6
-rw-r--r--src/GraphicObjects/TabItem.cs8
-rw-r--r--src/GraphicObjects/TabView.cs4
-rw-r--r--src/GraphicObjects/TemplatedControl.cs2
-rw-r--r--src/GraphicObjects/TextBox.cs1
-rw-r--r--src/GraphicObjects/TextRun.cs1
-rw-r--r--src/GraphicObjects/Window.cs1
-rw-r--r--src/Input/ButtonState.cs45
-rw-r--r--src/Input/Buttons.cs166
-rw-r--r--src/Input/Key.cs380
-rw-r--r--src/Input/KeyModifiers.cs57
-rw-r--r--src/Input/KeyboardKeyEventArgs.cs168
-rw-r--r--src/Input/KeyboardState.cs316
-rw-r--r--src/Input/MouseButton.cs92
-rw-r--r--src/Input/MouseEventArgs.cs369
-rw-r--r--src/Input/MouseScroll.cs118
-rw-r--r--src/Input/MouseState.cs360
-rw-r--r--src/OpenTKGameWindow.cs62
33 files changed, 2128 insertions, 71 deletions
diff --git a/src/BubblingMouseButtonEventArgs.cs b/src/BubblingMouseButtonEventArgs.cs
index 863d265e..515a7e07 100644
--- a/src/BubblingMouseButtonEventArgs.cs
+++ b/src/BubblingMouseButtonEventArgs.cs
@@ -1,5 +1,4 @@
using System;
-using OpenTK.Input;
namespace Crow
{
diff --git a/src/GraphicObjects/Button.cs b/src/GraphicObjects/Button.cs
index 92d19af6..0b37118c 100644
--- a/src/GraphicObjects/Button.cs
+++ b/src/GraphicObjects/Button.cs
@@ -8,7 +8,6 @@ using System.Diagnostics;
using System.Xml.Serialization;
using Cairo;
-using OpenTK.Input;
using System.ComponentModel;
namespace Crow
diff --git a/src/GraphicObjects/CheckBox.cs b/src/GraphicObjects/CheckBox.cs
index edf6650b..71e686f9 100644
--- a/src/GraphicObjects/CheckBox.cs
+++ b/src/GraphicObjects/CheckBox.cs
@@ -1,5 +1,4 @@
using System;
-using OpenTK.Input;
using System.ComponentModel;
using System.Xml.Serialization;
diff --git a/src/GraphicObjects/Container.cs b/src/GraphicObjects/Container.cs
index 360eee51..cb6145a8 100644
--- a/src/GraphicObjects/Container.cs
+++ b/src/GraphicObjects/Container.cs
@@ -1,7 +1,6 @@
using System;
using System.Xml.Serialization;
using System.Reflection;
-using OpenTK.Input;
using System.ComponentModel;
using System.Linq;
diff --git a/src/GraphicObjects/Expandable.cs b/src/GraphicObjects/Expandable.cs
index 16b3e974..af8b5640 100644
--- a/src/GraphicObjects/Expandable.cs
+++ b/src/GraphicObjects/Expandable.cs
@@ -1,5 +1,4 @@
using System;
-using OpenTK.Input;
using System.ComponentModel;
using System.Xml.Serialization;
diff --git a/src/GraphicObjects/FileDialog.cs b/src/GraphicObjects/FileDialog.cs
index bed42a05..b1c93119 100644
--- a/src/GraphicObjects/FileDialog.cs
+++ b/src/GraphicObjects/FileDialog.cs
@@ -24,7 +24,6 @@ using System.ComponentModel;
using System.IO;
using System.Collections.Generic;
using System.Diagnostics;
-using OpenTK.Input;
using System.Linq;
using System.Text.RegularExpressions;
diff --git a/src/GraphicObjects/GraphicObject.cs b/src/GraphicObjects/GraphicObject.cs
index 2ddcecca..9f1bf811 100644
--- a/src/GraphicObjects/GraphicObject.cs
+++ b/src/GraphicObjects/GraphicObject.cs
@@ -1,15 +1,13 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
-using System.Diagnostics;
-using System.Linq;
+using System.Xml.Serialization;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
-using System.Xml.Serialization;
using Cairo;
-using OpenTK.Input;
-using System.IO;
+using System.Linq;
+using System.Diagnostics;
namespace Crow
{
diff --git a/src/GraphicObjects/Image.cs b/src/GraphicObjects/Image.cs
index 46d081eb..8f02a19e 100644
--- a/src/GraphicObjects/Image.cs
+++ b/src/GraphicObjects/Image.cs
@@ -1,14 +1,10 @@
using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
using Cairo;
-using System.IO;
-using System.Runtime.InteropServices;
using System.Xml.Serialization;
using System.ComponentModel;
using System.Diagnostics;
+
namespace Crow
{
public class Image : GraphicObject
diff --git a/src/GraphicObjects/Label.cs b/src/GraphicObjects/Label.cs
index 6782e259..fa2d5828 100644
--- a/src/GraphicObjects/Label.cs
+++ b/src/GraphicObjects/Label.cs
@@ -7,7 +7,6 @@ using Cairo;
using System.Text.RegularExpressions;
using System.Xml.Serialization;
using System.ComponentModel;
-using OpenTK.Input;
namespace Crow
{
diff --git a/src/GraphicObjects/ListBox.cs b/src/GraphicObjects/ListBox.cs
index 69e71784..31555306 100644
--- a/src/GraphicObjects/ListBox.cs
+++ b/src/GraphicObjects/ListBox.cs
@@ -1,4 +1,4 @@
-//
+ //
// ListBox.cs
//
// Author:
diff --git a/src/GraphicObjects/PrivateContainer.cs b/src/GraphicObjects/PrivateContainer.cs
index 640e8d0b..3a3d9067 100644
--- a/src/GraphicObjects/PrivateContainer.cs
+++ b/src/GraphicObjects/PrivateContainer.cs
@@ -21,7 +21,6 @@
using System;
using System.Xml.Serialization;
using System.ComponentModel;
-using OpenTK.Input;
using Cairo;
namespace Crow
diff --git a/src/GraphicObjects/RadioButton.cs b/src/GraphicObjects/RadioButton.cs
index 4370d157..a6248706 100644
--- a/src/GraphicObjects/RadioButton.cs
+++ b/src/GraphicObjects/RadioButton.cs
@@ -1,5 +1,4 @@
using System;
-using OpenTK.Input;
using System.ComponentModel;
using System.Xml.Serialization;
diff --git a/src/GraphicObjects/Scroller.cs b/src/GraphicObjects/Scroller.cs
index 459205fe..58a0f245 100644
--- a/src/GraphicObjects/Scroller.cs
+++ b/src/GraphicObjects/Scroller.cs
@@ -24,7 +24,6 @@ using System.Xml.Serialization;
using System.ComponentModel;
using System.Diagnostics;
using Cairo;
-using OpenTK.Input;
namespace Crow
{
@@ -166,10 +165,6 @@ namespace Crow
internal Point savedMousePos;
public override bool MouseIsIn (Point m)
{
-// Debug.WriteLine ("Mouse in scroller: {0} scr coord:{1} mouse:{2}",
-// base.ScreenCoordinates (Slot).ContainsOrIsEqual (m),
-// base.ScreenCoordinates (Slot), m);
-
return Visible ? base.ScreenCoordinates(Slot).ContainsOrIsEqual (m) : false;
}
public override void checkHoverWidget (MouseMoveEventArgs e)
@@ -180,10 +175,6 @@ namespace Crow
}
public override void onMouseWheel (object sender, MouseWheelEventArgs e)
{
- //base.onMouseWheel (sender, e); base event buble to the top
-// if (MouseWheelChanged!=null)
-// MouseWheelChanged (this, e);
-
if (Child == null)
return;
@@ -218,7 +209,7 @@ namespace Crow
gr.Save ();
//clip to scrolled client zone
- CairoHelpers.CairoRectangle (gr, ClientRectangle, CornerRadius);//+ new Point((int)ScrollX,(int)ScrollY)
+ CairoHelpers.CairoRectangle (gr, ClientRectangle, CornerRadius);
gr.Clip ();
gr.Translate (-ScrollX, -ScrollY);
diff --git a/src/GraphicObjects/Slider.cs b/src/GraphicObjects/Slider.cs
index faaacd78..a96f2a40 100644
--- a/src/GraphicObjects/Slider.cs
+++ b/src/GraphicObjects/Slider.cs
@@ -172,7 +172,7 @@ namespace Crow
}
#region mouse handling
- public override void onMouseDown (object sender, OpenTK.Input.MouseButtonEventArgs e)
+ public override void onMouseDown (object sender, MouseButtonEventArgs e)
{
base.onMouseDown (sender, e);
@@ -191,13 +191,13 @@ namespace Crow
Value += LargeIncrement;
}
}
- public override void onMouseUp (object sender, OpenTK.Input.MouseButtonEventArgs e)
+ public override void onMouseUp (object sender,MouseButtonEventArgs e)
{
base.onMouseUp (sender, e);
holdCursor = false;
}
- public override void onMouseMove (object sender, OpenTK.Input.MouseMoveEventArgs e)
+ public override void onMouseMove (object sender, MouseMoveEventArgs e)
{
if (holdCursor) {
if (_orientation == Orientation.Horizontal)
diff --git a/src/GraphicObjects/Spinner.cs b/src/GraphicObjects/Spinner.cs
index ffc9472b..9447f205 100644
--- a/src/GraphicObjects/Spinner.cs
+++ b/src/GraphicObjects/Spinner.cs
@@ -19,7 +19,6 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
using System;
-using OpenTK.Input;
namespace Crow
{
diff --git a/src/GraphicObjects/Splitter.cs b/src/GraphicObjects/Splitter.cs
index 97cce52c..dbda87af 100644
--- a/src/GraphicObjects/Splitter.cs
+++ b/src/GraphicObjects/Splitter.cs
@@ -58,7 +58,7 @@ namespace Crow
base.Parent = value;
}
}
- public override void onMouseEnter (object sender, OpenTK.Input.MouseMoveEventArgs e)
+ public override void onMouseEnter (object sender, MouseMoveEventArgs e)
{
base.onMouseEnter (sender, e);
if ((Parent as GenericStack).Orientation == Orientation.Horizontal)
@@ -66,12 +66,12 @@ namespace Crow
else
this.HostContainer.MouseCursor = XCursor.V;
}
- public override void onMouseLeave (object sender, OpenTK.Input.MouseMoveEventArgs e)
+ public override void onMouseLeave (object sender, MouseMoveEventArgs e)
{
base.onMouseLeave (sender, e);
this.HostContainer.MouseCursor = XCursor.Default;
}
- public override void onMouseMove (object sender, OpenTK.Input.MouseMoveEventArgs e)
+ public override void onMouseMove (object sender, MouseMoveEventArgs e)
{
base.onMouseMove (sender, e);
diff --git a/src/GraphicObjects/TabItem.cs b/src/GraphicObjects/TabItem.cs
index b0e733fb..c2d863af 100644
--- a/src/GraphicObjects/TabItem.cs
+++ b/src/GraphicObjects/TabItem.cs
@@ -158,18 +158,18 @@ namespace Crow
|| mouseIsInTitle;
}
bool holdCursor = false;
- public override void onMouseDown (object sender, OpenTK.Input.MouseButtonEventArgs e)
+ public override void onMouseDown (object sender, MouseButtonEventArgs e)
{
base.onMouseDown (sender, e);
holdCursor = true;
}
- public override void onMouseUp (object sender, OpenTK.Input.MouseButtonEventArgs e)
+ public override void onMouseUp (object sender, MouseButtonEventArgs e)
{
base.onMouseUp (sender, e);
holdCursor = false;
(Parent as TabView).UpdateLayout (LayoutingType.ArrangeChildren);
}
- public override void onMouseMove (object sender, OpenTK.Input.MouseMoveEventArgs e)
+ public override void onMouseMove (object sender, MouseMoveEventArgs e)
{
base.onMouseMove (sender, e);
@@ -206,7 +206,7 @@ namespace Crow
TabOffset = tmp;
}
}
- public void butCloseTabClick (object sender, OpenTK.Input.MouseButtonEventArgs e){
+ public void butCloseTabClick (object sender, MouseButtonEventArgs e){
(Parent as TabView).RemoveChild(this);
}
#endregion
diff --git a/src/GraphicObjects/TabView.cs b/src/GraphicObjects/TabView.cs
index a480ae09..7bf827d6 100644
--- a/src/GraphicObjects/TabView.cs
+++ b/src/GraphicObjects/TabView.cs
@@ -23,7 +23,6 @@ using System.Xml.Serialization;
using System.ComponentModel;
using Cairo;
using System.Diagnostics;
-using OpenTK.Input;
namespace Crow
{
@@ -207,7 +206,8 @@ namespace Crow
}
}
#endregion
- void Ti_MouseDown (object sender, OpenTK.Input.MouseButtonEventArgs e)
+
+ void Ti_MouseDown (object sender, MouseButtonEventArgs e)
{
SelectedTab = Children.IndexOf (sender as GraphicObject);
}
diff --git a/src/GraphicObjects/TemplatedControl.cs b/src/GraphicObjects/TemplatedControl.cs
index bb2fbd28..c8ec2d9e 100644
--- a/src/GraphicObjects/TemplatedControl.cs
+++ b/src/GraphicObjects/TemplatedControl.cs
@@ -23,8 +23,8 @@ using System.Xml.Serialization;
using System.ComponentModel;
using System.IO;
using System.Xml;
-using System.Linq;
using System.Diagnostics;
+using System.Linq;
namespace Crow
{
diff --git a/src/GraphicObjects/TextBox.cs b/src/GraphicObjects/TextBox.cs
index 91122523..7907eb42 100644
--- a/src/GraphicObjects/TextBox.cs
+++ b/src/GraphicObjects/TextBox.cs
@@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
-using OpenTK.Input;
using Cairo;
using System.Diagnostics;
using System.Xml.Serialization;
diff --git a/src/GraphicObjects/TextRun.cs b/src/GraphicObjects/TextRun.cs
index bb308eb6..0fa463af 100644
--- a/src/GraphicObjects/TextRun.cs
+++ b/src/GraphicObjects/TextRun.cs
@@ -7,7 +7,6 @@ using Cairo;
using System.Text.RegularExpressions;
using System.Xml.Serialization;
using System.ComponentModel;
-using OpenTK.Input;
namespace Crow
{
diff --git a/src/GraphicObjects/Window.cs b/src/GraphicObjects/Window.cs
index 5e1bd681..757ee080 100644
--- a/src/GraphicObjects/Window.cs
+++ b/src/GraphicObjects/Window.cs
@@ -2,7 +2,6 @@
using System.Xml.Serialization;
using System.ComponentModel;
using System.Diagnostics;
-using OpenTK.Input;
namespace Crow
{
diff --git a/src/Input/ButtonState.cs b/src/Input/ButtonState.cs
new file mode 100644
index 00000000..17849ca8
--- /dev/null
+++ b/src/Input/ButtonState.cs
@@ -0,0 +1,45 @@
+ #region License
+ //
+ // The Open Toolkit Library License
+ //
+ // Copyright (c) 2006 - 2010 the Open Toolkit library.
+ //
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
+ // of this software and associated documentation files (the "Software"), to deal
+ // in the Software without restriction, including without limitation the rights to
+ // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+ // the Software, and to permit persons to whom the Software is furnished to do
+ // so, subject to the following conditions:
+ //
+ // The above copyright notice and this permission notice shall be included in all
+ // copies or substantial portions of the Software.
+ //
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ // OTHER DEALINGS IN THE SOFTWARE.
+ //
+ #endregion
+
+namespace Crow
+{
+ /// <summary>
+ /// Enumerates possible mouse button states.
+ /// </summary>
+ public enum ButtonState
+ {
+ /// <summary>
+ /// Indicates that a mouse button is released.
+ /// </summary>
+ Released = 0,
+
+ /// <summary>
+ /// Indicates that a mouse button is pressed.
+ /// </summary>
+ Pressed = 1
+ }
+}
diff --git a/src/Input/Buttons.cs b/src/Input/Buttons.cs
new file mode 100644
index 00000000..a80f5040
--- /dev/null
+++ b/src/Input/Buttons.cs
@@ -0,0 +1,166 @@
+//
+// GamePadButton.cs
+//
+// Author:
+// robert <${AuthorEmail}>
+//
+// Copyright (c) 2012 robert
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+using System;
+
+namespace OpenTK.Input
+{
+ /// <summary>
+ /// Enumerates available buttons for a <c>GamePad</c> device.
+ /// </summary>
+ [Flags]
+ public enum Buttons
+ {
+ /// <summary>
+ /// DPad up direction button
+ /// </summary>
+ DPadUp = 1 << 0,
+
+ /// <summary>
+ /// DPad down direction button
+ /// </summary>
+ DPadDown = 1 << 1,
+
+ /// <summary>
+ /// DPad left direction button
+ /// </summary>
+ DPadLeft = 1 << 2,
+
+ /// <summary>
+ /// DPad right direction button
+ /// </summary>
+ DPadRight = 1 << 3,
+
+ /// <summary>
+ /// Start button
+ /// </summary>
+ Start = 1 << 4,
+
+ /// <summary>
+ /// Back button
+ /// </summary>
+ Back = 1 << 5,
+
+ /// <summary>
+ /// Left stick button
+ /// </summary>
+ LeftStick = 1 << 6,
+
+ /// <summary>
+ /// Right stick button
+ /// </summary>
+ RightStick = 1 << 7,
+
+ /// <summary>
+ /// Left shoulder button
+ /// </summary>
+ LeftShoulder = 1 << 8,
+
+ /// <summary>
+ /// Right shoulder button
+ /// </summary>
+ RightShoulder = 1 << 9,
+
+ /// <summary>
+ /// Home button
+ /// </summary>
+ Home = 1 << 11,
+
+ /// <summary>
+ /// Home button
+ /// </summary>
+ BigButton = Home,
+
+ /// <summary>
+ /// A button
+ /// </summary>
+ A = 1 << 12,
+
+ /// <summary>
+ /// B button
+ /// </summary>
+ B = 1 << 13,
+
+ /// <summary>
+ /// X button
+ /// </summary>
+ X = 1 << 14,
+
+ /// <summary>
+ /// Y button
+ /// </summary>
+ Y = 1 << 15,
+
+ /// <summary>
+ /// Left thumbstick left direction button
+ /// </summary>
+ LeftThumbstickLeft = 1 << 21,
+
+ /// <summary>
+ /// Right trigger button
+ /// </summary>
+ RightTrigger = 1 << 22,
+
+ /// <summary>
+ /// Left trigger button
+ /// </summary>
+ LeftTrigger = 1 << 23,
+
+ /// <summary>
+ /// Right thumbstick up direction button
+ /// </summary>
+ RightThumbstickUp = 1 << 24,
+
+ /// <summary>
+ /// Right thumbstick down direction button
+ /// </summary>
+ RightThumbstickDown = 1 << 25,
+
+ /// <summary>
+ /// Right stick right direction button
+ /// </summary>
+ RightThumbstickRight = 1 << 26,
+
+ /// <summary>
+ /// Right stick left direction button
+ /// </summary>
+ RightThumbstickLeft = 1 << 27,
+
+ /// <summary>
+ /// Left stick up direction button
+ /// </summary>
+ LeftThumbstickUp = 1 << 28,
+
+ /// <summary>
+ /// Left stick down direction button
+ /// </summary>
+ LeftThumbstickDown = 1 << 29,
+
+ /// <summary>
+ /// Left stick right direction button
+ /// </summary>
+ LeftThumbstickRight = 1 << 30,
+ }
+}
diff --git a/src/Input/Key.cs b/src/Input/Key.cs
new file mode 100644
index 00000000..71f9d85a
--- /dev/null
+++ b/src/Input/Key.cs
@@ -0,0 +1,380 @@
+ #region License
+ //
+ // The Open Toolkit Library License
+ //
+ // Copyright (c) 2006 - 2009 the Open Toolkit library.
+ //
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
+ // of this software and associated documentation files (the "Software"), to deal
+ // in the Software without restriction, including without limitation the rights to
+ // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+ // the Software, and to permit persons to whom the Software is furnished to do
+ // so, subject to the following conditions:
+ //
+ // The above copyright notice and this permission notice shall be included in all
+ // copies or substantial portions of the Software.
+ //
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ // OTHER DEALINGS IN THE SOFTWARE.
+ //
+ #endregion
+
+namespace Crow
+{
+ /// <summary>
+ /// The available keyboard keys.
+ /// </summary>
+ public enum Key : int
+ {
+ /// <summary>A key outside the known keys.</summary>
+ Unknown = 0,
+
+ // Modifiers
+ /// <summary>The left shift key.</summary>
+ ShiftLeft,
+ /// <summary>The left shift key (equivalent to ShiftLeft).</summary>
+ LShift = ShiftLeft,
+ /// <summary>The right shift key.</summary>
+ ShiftRight,
+ /// <summary>The right shift key (equivalent to ShiftRight).</summary>
+ RShift = ShiftRight,
+ /// <summary>The left control key.</summary>
+ ControlLeft,
+ /// <summary>The left control key (equivalent to ControlLeft).</summary>
+ LControl = ControlLeft,
+ /// <summary>The right control key.</summary>
+ ControlRight,
+ /// <summary>The right control key (equivalent to ControlRight).</summary>
+ RControl = ControlRight,
+ /// <summary>The left alt key.</summary>
+ AltLeft,
+ /// <summary>The left alt key (equivalent to AltLeft.</summary>
+ LAlt = AltLeft,
+ /// <summary>The right alt key.</summary>
+ AltRight,
+ /// <summary>The right alt key (equivalent to AltRight).</summary>
+ RAlt = AltRight,
+ /// <summary>The left win key.</summary>
+ WinLeft,
+ /// <summary>The left win key (equivalent to WinLeft).</summary>
+ LWin = WinLeft,
+ /// <summary>The right win key.</summary>
+ WinRight,
+ /// <summary>The right win key (equivalent to WinRight).</summary>
+ RWin = WinRight,
+ /// <summary>The menu key.</summary>
+ Menu,
+
+ // Function keys (hopefully enough for most keyboards - mine has 26)
+ // <keysymdef.h> on X11 reports up to 35 function keys.
+ /// <summary>The F1 key.</summary>
+ F1,
+ /// <summary>The F2 key.</summary>
+ F2,
+ /// <summary>The F3 key.</summary>
+ F3,
+ /// <summary>The F4 key.</summary>
+ F4,
+ /// <summary>The F5 key.</summary>
+ F5,
+ /// <summary>The F6 key.</summary>
+ F6,
+ /// <summary>The F7 key.</summary>
+ F7,
+ /// <summary>The F8 key.</summary>
+ F8,
+ /// <summary>The F9 key.</summary>
+ F9,
+ /// <summary>The F10 key.</summary>
+ F10,
+ /// <summary>The F11 key.</summary>
+ F11,
+ /// <summary>The F12 key.</summary>
+ F12,
+ /// <summary>The F13 key.</summary>
+ F13,
+ /// <summary>The F14 key.</summary>
+ F14,
+ /// <summary>The F15 key.</summary>
+ F15,
+ /// <summary>The F16 key.</summary>
+ F16,
+ /// <summary>The F17 key.</summary>
+ F17,
+ /// <summary>The F18 key.</summary>
+ F18,
+ /// <summary>The F19 key.</summary>
+ F19,
+ /// <summary>The F20 key.</summary>
+ F20,
+ /// <summary>The F21 key.</summary>
+ F21,
+ /// <summary>The F22 key.</summary>
+ F22,
+ /// <summary>The F23 key.</summary>
+ F23,
+ /// <summary>The F24 key.</summary>
+ F24,
+ /// <summary>The F25 key.</summary>
+ F25,
+ /// <summary>The F26 key.</summary>
+ F26,
+ /// <summary>The F27 key.</summary>
+ F27,
+ /// <summary>The F28 key.</summary>
+ F28,
+ /// <summary>The F29 key.</summary>
+ F29,
+ /// <summary>The F30 key.</summary>
+ F30,
+ /// <summary>The F31 key.</summary>
+ F31,
+ /// <summary>The F32 key.</summary>
+ F32,
+ /// <summary>The F33 key.</summary>
+ F33,
+ /// <summary>The F34 key.</summary>
+ F34,
+ /// <summary>The F35 key.</summary>
+ F35,
+
+ // Direction arrows
+ /// <summary>The up arrow key.</summary>
+ Up,
+ /// <summary>The down arrow key.</summary>
+ Down,
+ /// <summary>The left arrow key.</summary>
+ Left,
+ /// <summary>The right arrow key.</summary>
+ Right,
+
+ /// <summary>The enter key.</summary>
+ Enter,
+ /// <summary>The escape key.</summary>
+ Escape,
+ /// <summary>The space key.</summary>
+ Space,
+ /// <summary>The tab key.</summary>
+ Tab,
+ /// <summary>The backspace key.</summary>
+ BackSpace,
+ /// <summary>The backspace key (equivalent to BackSpace).</summary>
+ Back = BackSpace,
+ /// <summary>The insert key.</summary>
+ Insert,
+ /// <summary>The delete key.</summary>
+ Delete,
+ /// <summary>The page up key.</summary>
+ PageUp,
+ /// <summary>The page down key.</summary>
+ PageDown,
+ /// <summary>The home key.</summary>
+ Home,
+ /// <summary>The end key.</summary>
+ End,
+ /// <summary>The caps lock key.</summary>
+ CapsLock,
+ /// <summary>The scroll lock key.</summary>
+ ScrollLock,
+ /// <summary>The print screen key.</summary>
+ PrintScreen,
+ /// <summary>The pause key.</summary>
+ Pause,
+ /// <summary>The num lock key.</summary>
+ NumLock,
+
+ // Special keys
+ /// <summary>The clear key (Keypad5 with NumLock disabled, on typical keyboards).</summary>
+ Clear,
+ /// <summary>The sleep key.</summary>
+ Sleep,
+ /*LogOff,
+ Help,
+ Undo,
+ Redo,
+ New,
+ Open,
+ Close,
+ Reply,
+ Forward,
+ Send,
+ Spell,
+ Save,
+ Calculator,
+
+ // Folders and applications
+ Documents,
+ Pictures,
+ Music,
+ MediaPlayer,
+ Mail,
+ Browser,
+ Messenger,
+
+ // Multimedia keys
+ Mute,
+ PlayPause,
+ Stop,
+ VolumeUp,
+ VolumeDown,
+ TrackPrevious,
+ TrackNext,*/
+
+ // Keypad keys
+ /// <summary>The keypad 0 key.</summary>
+ Keypad0,
+ /// <summary>The keypad 1 key.</summary>
+ Keypad1,
+ /// <summary>The keypad 2 key.</summary>
+ Keypad2,
+ /// <summary>The keypad 3 key.</summary>
+ Keypad3,
+ /// <summary>The keypad 4 key.</summary>
+ Keypad4,
+ /// <summary>The keypad 5 key.</summary>
+ Keypad5,
+ /// <summary>The keypad 6 key.</summary>
+ Keypad6,
+ /// <summary>The keypad 7 key.</summary>
+ Keypad7,
+ /// <summary>The keypad 8 key.</summary>
+ Keypad8,
+ /// <summary>The keypad 9 key.</summary>
+ Keypad9,
+ /// <summary>The keypad divide key.</summary>
+ KeypadDivide,
+ /// <summary>The keypad multiply key.</summary>
+ KeypadMultiply,
+ /// <summary>The keypad subtract key.</summary>
+ KeypadSubtract,
+ /// <summary>The keypad minus key (equivalent to KeypadSubtract).</summary>
+ KeypadMinus = KeypadSubtract,
+ /// <summary>The keypad add key.</summary>
+ KeypadAdd,
+ /// <summary>The keypad plus key (equivalent to KeypadAdd).</summary>
+ KeypadPlus = KeypadAdd,
+ /// <summary>The keypad decimal key.</summary>
+ KeypadDecimal,
+ /// <summary>The keypad period key (equivalent to KeypadDecimal).</summary>
+ KeypadPeriod = KeypadDecimal,
+ /// <summary>The keypad enter key.</summary>
+ KeypadEnter,
+
+ // Letters
+ /// <summary>The A key.</summary>
+ A,
+ /// <summary>The B key.</summary>
+ B,
+ /// <summary>The C key.</summary>
+ C,
+ /// <summary>The D key.</summary>
+ D,
+ /// <summary>The E key.</summary>
+ E,
+ /// <summary>The F key.</summary>
+ F,
+ /// <summary>The G key.</summary>
+ G,
+ /// <summary>The H key.</summary>
+ H,
+ /// <summary>The I key.</summary>
+ I,
+ /// <summary>The J key.</summary>
+ J,
+ /// <summary>The K key.</summary>
+ K,
+ /// <summary>The L key.</summary>
+ L,
+ /// <summary>The M key.</summary>
+ M,
+ /// <summary>The N key.</summary>
+ N,
+ /// <summary>The O key.</summary>
+ O,
+ /// <summary>The P key.</summary>
+ P,
+ /// <summary>The Q key.</summary>
+ Q,
+ /// <summary>The R key.</summary>
+ R,
+ /// <summary>The S key.</summary>
+ S,
+ /// <summary>The T key.</summary>
+ T,
+ /// <summary>The U key.</summary>
+ U,
+ /// <summary>The V key.</summary>
+ V,
+ /// <summary>The W key.</summary>
+ W,
+ /// <summary>The X key.</summary>
+ X,
+ /// <summary>The Y key.</summary>
+ Y,
+ /// <summary>The Z key.</summary>
+ Z,
+
+ // Numbers
+ /// <summary>The number 0 key.</summary>
+ Number0,
+ /// <summary>The number 1 key.</summary>
+ Number1,
+ /// <summary>The number 2 key.</summary>
+ Number2,
+ /// <summary>The number 3 key.</summary>
+ Number3,
+ /// <summary>The number 4 key.</summary>
+ Number4,
+ /// <summary>The number 5 key.</summary>
+ Number5,
+ /// <summary>The number 6 key.</summary>
+ Number6,
+ /// <summary>The number 7 key.</summary>
+ Number7,
+ /// <summary>The number 8 key.</summary>
+ Number8,
+ /// <summary>The number 9 key.</summary>
+ Number9,
+
+ // Symbols
+ /// <summary>The tilde key.</summary>
+ Tilde,
+ /// <summary>The grave key (equivaent to Tilde).</summary>
+ Grave = Tilde,
+ /// <summary>The minus key.</summary>
+ Minus,
+ //Equal,
+ /// <summary>The plus key.</summary>
+ Plus,
+ /// <summary>The left bracket key.</summary>
+ BracketLeft,
+ /// <summary>The left bracket key (equivalent to BracketLeft).</summary>
+ LBracket = BracketLeft,
+ /// <summary>The right bracket key.</summary>
+ BracketRight,
+ /// <summary>The right bracket key (equivalent to BracketRight).</summary>
+ RBracket = BracketRight,
+ /// <summary>The semicolon key.</summary>
+ Semicolon,
+ /// <summary>The quote key.</summary>
+ Quote,
+ /// <summary>The comma key.</summary>
+ Comma,
+ /// <summary>The period key.</summary>
+ Period,
+ /// <summary>The slash key.</summary>
+ Slash,
+ /// <summary>The backslash key.</summary>
+ BackSlash,
+ /// <summary>The secondary backslash key.</summary>
+ NonUSBackSlash,
+ /// <summary>Indicates the last available keyboard key.</summary>
+ LastKey
+ }
+} \ No newline at end of file
diff --git a/src/Input/KeyModifiers.cs b/src/Input/KeyModifiers.cs
new file mode 100644
index 00000000..1314e737
--- /dev/null
+++ b/src/Input/KeyModifiers.cs
@@ -0,0 +1,57 @@
+#region License
+//
+// HatPosition.cs
+//
+// Author:
+// Stefanos A. <stapostol@gmail.com>
+//
+// Copyright (c) 2006-2014 Stefanos Apostolopoulos
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+//
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace Crow
+{
+ /// <summary>
+ /// Enumerates modifier keys.
+ /// </summary>
+ [Flags]
+ public enum KeyModifiers : byte
+ {
+ /// <summary>
+ /// The alt key modifier (option on Mac).
+ /// </summary>
+ Alt = 1 << 0,
+
+ /// <summary>
+ /// The control key modifier.
+ /// </summary>
+ Control = 1 << 1,
+
+ /// <summary>
+ /// The shift key modifier.
+ /// </summary>
+ Shift = 1 << 2
+ }
+}
diff --git a/src/Input/KeyboardKeyEventArgs.cs b/src/Input/KeyboardKeyEventArgs.cs
new file mode 100644
index 00000000..bfe0debb
--- /dev/null
+++ b/src/Input/KeyboardKeyEventArgs.cs
@@ -0,0 +1,168 @@
+#region License
+//
+// The Open Toolkit Library License
+//
+// Copyright (c) 2006 - 2009 the Open Toolkit library.
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights to
+// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+// the Software, and to permit persons to whom the Software is furnished to do
+// so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in all
+// copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+// OTHER DEALINGS IN THE SOFTWARE.
+//
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace Crow
+{
+ /// <summary>
+ /// Defines the event data for <see cref="KeyboardDevice"/> events.
+ /// </summary>
+ /// <remarks>
+ /// <para>
+ /// Do not cache instances of this type outside their event handler.
+ /// If necessary, you can clone a KeyboardEventArgs instance using the
+ /// <see cref="KeyboardKeyEventArgs(KeyboardKeyEventArgs)"/> constructor.
+ /// </para>
+ /// </remarks>
+ public class KeyboardKeyEventArgs : EventArgs
+ {
+ #region Fields
+
+ Key key;
+ bool repeat;
+ KeyboardState state;
+
+ #endregion
+
+ #region Constructors
+
+ /// <summary>
+ /// Constructs a new KeyboardEventArgs instance.
+ /// </summary>
+ public KeyboardKeyEventArgs(Key _key, bool _repeat, KeyboardState _state)
+ {
+ key = _key;
+ repeat = _repeat;
+ state = _state;
+ }
+
+ /// <summary>
+ /// Constructs a new KeyboardEventArgs instance.
+ /// </summary>
+ /// <param name="args">An existing KeyboardEventArgs instance to clone.</param>
+ public KeyboardKeyEventArgs(KeyboardKeyEventArgs args)
+ {
+ Key = args.Key;
+ }
+
+ #endregion
+
+ #region Public Members
+
+ /// <summary>
+ /// Gets the <see cref="Key"/> that generated this event.
+ /// </summary>
+ public Key Key
+ {
+ get { return key; }
+ internal set { key = value; }
+ }
+
+ /// <summary>
+ /// Gets the scancode which generated this event.
+ /// </summary>
+ [CLSCompliant(false)]
+ public uint ScanCode
+ {
+ get { return (uint)Key; }
+ }
+
+ /// <summary>
+ /// Gets a value indicating whether <see cref="OpenTK.Input.KeyModifiers.Alt"/> is pressed.
+ /// </summary>
+ /// <value><c>true</c> if pressed; otherwise, <c>false</c>.</value>
+ public bool Alt
+ {
+ get { return state[Key.AltLeft] || state[Key.AltRight]; }
+ }
+
+ /// <summary>
+ /// Gets a value indicating whether <see cref="OpenTK.Input.KeyModifiers.Control"/> is pressed.
+ /// </summary>
+ /// <value><c>true</c> if pressed; otherwise, <c>false</c>.</value>
+ public bool Control
+ {
+ get { return state[Key.ControlLeft] || state[Key.ControlRight]; }
+ }
+
+ /// <summary>
+ /// Gets a value indicating whether <see cref="OpenTK.Input.KeyModifiers.Shift"/> is pressed.
+ /// </summary>
+ /// <value><c>true</c> if pressed; otherwise, <c>false</c>.</value>
+ public bool Shift
+ {
+ get { return state[Key.ShiftLeft] || state[Key.ShiftRight]; }
+ }
+
+ /// <summary>
+ /// Gets a bitwise combination representing the <see cref="OpenTK.Input.KeyModifiers"/>
+ /// that are currently pressed.
+ /// </summary>
+ /// <value>The modifiers.</value>
+ public KeyModifiers Modifiers
+ {
+ get
+ {
+ KeyModifiers mods = 0;
+ mods |= Alt ? KeyModifiers.Alt : 0;
+ mods |= Control ? KeyModifiers.Control : 0;
+ mods |= Shift ? KeyModifiers.Shift : 0;
+ return mods;
+ }
+ }
+
+ /// <summary>
+ /// Gets the current <see cref="OpenTK.Input.KeyboardState"/>.
+ /// </summary>
+ /// <value>The keyboard.</value>
+ public KeyboardState Keyboard
+ {
+ get { return state; }
+ internal set { state = value; }
+ }
+
+ /// <summary>
+ /// Gets a <see cref="System.Boolean"/> indicating whether
+ /// this key event is a repeat.
+ /// </summary>
+ /// <value>
+ /// true, if this event was caused by the user holding down
+ /// a key; false, if this was caused by the user pressing a
+ /// key for the first time.
+ /// </value>
+ public bool IsRepeat
+ {
+ get { return repeat; }
+ internal set { repeat = value; }
+ }
+
+ #endregion
+ }
+}
diff --git a/src/Input/KeyboardState.cs b/src/Input/KeyboardState.cs
new file mode 100644
index 00000000..ba392cac
--- /dev/null
+++ b/src/Input/KeyboardState.cs
@@ -0,0 +1,316 @@
+ #region License
+ //
+ // The Open Toolkit Library License
+ //
+ // Copyright (c) 2006 - 2009 the Open Toolkit library.
+ //
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
+ // of this software and associated documentation files (the "Software"), to deal
+ // in the Software without restriction, including without limitation the rights to
+ // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+ // the Software, and to permit persons to whom the Software is furnished to do
+ // so, subject to the following conditions:
+ //
+ // The above copyright notice and this permission notice shall be included in all
+ // copies or substantial portions of the Software.
+ //
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ // OTHER DEALINGS IN THE SOFTWARE.
+ //
+ #endregion
+
+using System;
+using System.Collections.Specialized;
+using System.Text;
+
+namespace Crow
+{
+ /// <summary>
+ /// Encapsulates the state of a Keyboard device.
+ /// </summary>
+ public struct KeyboardState : IEquatable<KeyboardState>
+ {
+ #region Fields
+
+ // Allocate enough ints to store all keyboard keys
+ const int IntSize = sizeof(int);
+ const int NumInts = ((int)Key.LastKey + IntSize - 1) / IntSize;
+ // The following line triggers bogus CS0214 in gmcs 2.0.1, sigh...
+ unsafe fixed int Keys[NumInts];
+ bool is_connected;
+
+ #endregion
+
+ #region Public Members
+
+ /// <summary>
+ /// Gets a <see cref="System.Boolean"/> indicating whether the specified
+ /// <see cref="OpenTK.Input.Key"/> is pressed.
+ /// </summary>
+ /// <param name="key">The <see cref="OpenTK.Input.Key"/> to check.</param>
+ /// <returns>True if key is pressed; false otherwise.</returns>
+ public bool this[Key key]
+ {
+ get { return IsKeyDown(key); }
+ internal set { SetKeyState(key, value); }
+ }
+
+ /// <summary>
+ /// Gets a <see cref="System.Boolean"/> indicating whether the specified
+ /// <see cref="OpenTK.Input.Key"/> is pressed.
+ /// </summary>
+ /// <param name="code">The scancode to check.</param>
+ /// <returns>True if code is pressed; false otherwise.</returns>
+ public bool this[short code]
+ {
+ get { return IsKeyDown((Key)code); }
+ }
+
+ /// <summary>
+ /// Gets a <see cref="System.Boolean"/> indicating whether this key is down.
+ /// </summary>
+ /// <param name="key">The <see cref="OpenTK.Input.Key"/> to check.</param>
+ public bool IsKeyDown(Key key)
+ {
+ return ReadBit((int)key);
+ }
+
+ /// <summary>
+ /// Gets a <see cref="System.Boolean"/> indicating whether this scan code is down.
+ /// </summary>
+ /// <param name="code">The scan code to check.</param>
+ public bool IsKeyDown(short code)
+ {
+ return code >= 0 && code < (short)Key.LastKey && ReadBit(code);
+ }
+
+ /// <summary>
+ /// Gets a <see cref="System.Boolean"/> indicating whether this key is up.
+ /// </summary>
+ /// <param name="key">The <see cref="OpenTK.Input.Key"/> to check.</param>
+ public bool IsKeyUp(Key key)
+ {
+ return !ReadBit((int)key);
+ }
+
+ /// <summary>
+ /// Gets a <see cref="System.Boolean"/> indicating whether this scan code is down.
+ /// </summary>
+ /// <param name="code">The scan code to check.</param>
+ public bool IsKeyUp(short code)
+ {
+ return !IsKeyDown(code);
+ }
+
+ /// <summary>
+ /// Gets a <see cref="System.Boolean"/> indicating whether this keyboard
+ /// is connected.
+ /// </summary>
+ public bool IsConnected
+ {
+ get { return is_connected; }
+ internal set { is_connected = value; }
+ }
+
+#if false
+ // Disabled until the correct cross-platform API can be determined.
+ public bool IsLedOn(KeyboardLeds led)
+ {
+ return false;
+ }
+
+ public bool IsLedOff(KeyboardLeds led)
+ {
+ return false;
+ }
+#endif
+
+ /// <summary>
+ /// Checks whether two <see cref="KeyboardState" /> instances are equal.
+ /// </summary>
+ /// <param name="left">
+ /// A <see cref="KeyboardState"/> instance.
+ /// </param>
+ /// <param name="right">
+ /// A <see cref="KeyboardState"/> instance.
+ /// </param>
+ /// <returns>
+ /// True if both left is equal to right; false otherwise.
+ /// </returns>
+ public static bool operator ==(KeyboardState left, KeyboardState right)
+ {
+ return left.Equals(right);
+ }
+
+ /// <summary>
+ /// Checks whether two <see cref="KeyboardState" /> instances are not equal.
+ /// </summary>
+ /// <param name="left">
+ /// A <see cref="KeyboardState"/> instance.
+ /// </param>
+ /// <param name="right">
+ /// A <see cref="KeyboardState"/> instance.
+ /// </param>
+ /// <returns>
+ /// True if both left is not equal to right; false otherwise.
+ /// </returns>
+ public static bool operator !=(KeyboardState left, KeyboardState right)
+ {
+ return !left.Equals(right);
+ }
+
+ /// <summary>
+ /// Compares to an object instance for equality.
+ /// </summary>
+ /// <param name="obj">
+ /// The <see cref="System.Object"/> to compare to.
+ /// </param>
+ /// <returns>
+ /// True if this instance is equal to obj; false otherwise.
+ /// </returns>
+ public override bool Equals(object obj)
+ {
+ if (obj is KeyboardState)
+ {
+ return this == (KeyboardState)obj;
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ /// <summary>
+ /// Generates a hashcode for the current instance.
+ /// </summary>
+ /// <returns>
+ /// A <see cref="System.Int32"/> represting the hashcode for this instance.
+ /// </returns>
+ public override int GetHashCode()
+ {
+ unsafe
+ {
+ fixed (int* k = Keys)
+ {
+ int hashcode = 0;
+ for (int i = 0; i < NumInts; i++)
+ hashcode ^= (k + i)->GetHashCode();
+ return hashcode;
+ }
+ }
+ }
+
+ #endregion
+
+ #region Internal Members
+
+ internal void SetKeyState(Key key, bool down)
+ {
+ if (down)
+ {
+ EnableBit((int)key);
+ }
+ else
+ {
+ DisableBit((int)key);
+ }
+ }
+
+ internal bool ReadBit(int offset)
+ {
+ ValidateOffset(offset);
+
+ int int_offset = offset / 32;
+ int bit_offset = offset % 32;
+ unsafe
+ {
+ fixed (int* k = Keys) { return (*(k + int_offset) & (1 << bit_offset)) != 0u; }
+ }
+ }
+
+ internal void EnableBit(int offset)
+ {
+ ValidateOffset(offset);
+
+ int int_offset = offset / 32;
+ int bit_offset = offset % 32;
+ unsafe
+ {
+ fixed (int* k = Keys) { *(k + int_offset) |= 1 << bit_offset; }
+ }
+ }
+
+ internal void DisableBit(int offset)
+ {
+ ValidateOffset(offset);
+
+ int int_offset = offset / 32;
+ int bit_offset = offset % 32;
+ unsafe
+ {
+ fixed (int* k = Keys) { *(k + int_offset) &= ~(1 << bit_offset); }
+ }
+ }
+
+ 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);
+ }
+ }
+ IsConnected |= other.IsConnected;
+ }
+
+ internal void SetIsConnected(bool value)
+ {
+ IsConnected = value;
+ }
+
+ #endregion
+
+ #region Private Members
+
+ static void ValidateOffset(int offset)
+ {
+ if (offset < 0 || offset >= NumInts * IntSize)
+ throw new ArgumentOutOfRangeException();
+ }
+
+ #endregion
+
+ #region IEquatable<KeyboardState> Members
+
+ /// <summary>
+ /// Compares two KeyboardState instances.
+ /// </summary>
+ /// <param name="other">The instance to compare two.</param>
+ /// <returns>True, if both instances are equal; false otherwise.</returns>
+ public bool Equals(KeyboardState other)
+ {
+ bool equal = true;
+ unsafe
+ {
+ int* k2 = other.Keys;
+ fixed (int* k1 = Keys)
+ {
+ for (int i = 0; equal && i < NumInts; i++)
+ equal &= *(k1 + i) == *(k2 + i);
+ }
+ }
+ return equal;
+ }
+
+ #endregion
+ }
+}
diff --git a/src/Input/MouseButton.cs b/src/Input/MouseButton.cs
new file mode 100644
index 00000000..92be4774
--- /dev/null
+++ b/src/Input/MouseButton.cs
@@ -0,0 +1,92 @@
+ #region License
+ //
+ // The Open Toolkit Library License
+ //
+ // Copyright (c) 2006 - 2009 the Open Toolkit library.
+ //
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
+ // of this software and associated documentation files (the "Software"), to deal
+ // in the Software without restriction, including without limitation the rights to
+ // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+ // the Software, and to permit persons to whom the Software is furnished to do
+ // so, subject to the following conditions:
+ //
+ // The above copyright notice and this permission notice shall be included in all
+ // copies or substantial portions of the Software.
+ //
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ // OTHER DEALINGS IN THE SOFTWARE.
+ //
+ #endregion
+
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace Crow
+{
+ /// <summary>
+ /// Enumerates all possible mouse buttons.
+ /// </summary>
+ public enum MouseButton
+ {
+ /// <summary>
+ /// The left mouse button.
+ /// </summary>
+ Left = 0,
+ /// <summary>
+ /// The middle mouse button.
+ /// </summary>
+ Middle,
+ /// <summary>
+ /// The right mouse button.
+ /// </summary>
+ Right,
+ /// <summary>
+ /// The first extra mouse button.
+ /// </summary>
+ Button1,
+ /// <summary>
+ /// The second extra mouse button.
+ /// </summary>
+ Button2,
+ /// <summary>
+ /// The third extra mouse button.
+ /// </summary>
+ Button3,
+ /// <summary>
+ /// The fourth extra mouse button.
+ /// </summary>
+ Button4,
+ /// <summary>
+ /// The fifth extra mouse button.
+ /// </summary>
+ Button5,
+ /// <summary>
+ /// The sixth extra mouse button.
+ /// </summary>
+ Button6,
+ /// <summary>
+ /// The seventh extra mouse button.
+ /// </summary>
+ Button7,
+ /// <summary>
+ /// The eigth extra mouse button.
+ /// </summary>
+ Button8,
+ /// <summary>
+ /// The ninth extra mouse button.
+ /// </summary>
+ Button9,
+ /// <summary>
+ /// Indicates the last available mouse button.
+ /// </summary>
+ LastButton
+ }
+}
diff --git a/src/Input/MouseEventArgs.cs b/src/Input/MouseEventArgs.cs
new file mode 100644
index 00000000..758a5a69
--- /dev/null
+++ b/src/Input/MouseEventArgs.cs
@@ -0,0 +1,369 @@
+#region License
+//
+// MouseEventArgs.cs
+//
+// Author:
+// Stefanos A. <stapostol@gmail.com>
+//
+// Copyright (c) 2006-2014 Stefanos Apostolopoulos
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+//
+#endregion
+
+using System;
+#if !MINIMAL
+using System.Drawing;
+#endif
+
+namespace Crow
+{
+ /// <summary>
+ /// Defines the event data for <see cref="MouseDevice"/> events.
+ /// </summary>
+ /// <remarks>
+ /// <para>
+ /// Do not cache instances of this type outside their event handler.
+ /// If necessary, you can clone an instance using the
+ /// <see cref="MouseEventArgs(MouseEventArgs)"/> constructor.
+ /// </para>
+ /// </remarks>
+ public class MouseEventArgs : EventArgs
+ {
+ #region Fields
+
+ MouseState state;
+
+ #endregion
+
+ #region Constructors
+
+ /// <summary>
+ /// Constructs a new instance.
+ /// </summary>
+ public MouseEventArgs()
+ {
+ state.SetIsConnected(true);
+ }
+
+ /// <summary>
+ /// Constructs a new instance.
+ /// </summary>
+ /// <param name="x">The X position.</param>
+ /// <param name="y">The Y position.</param>
+ public MouseEventArgs(int x, int y)
+ : this()
+ {
+ state.X = x;
+ state.Y = y;
+ }
+
+ /// <summary>
+ /// Constructs a new instance.
+ /// </summary>
+ /// <param name="args">The <see cref="MouseEventArgs"/> instance to clone.</param>
+ public MouseEventArgs(MouseEventArgs args)
+ : this(args.X, args.Y)
+ {
+ }
+
+ #endregion
+
+ #region Protected Members
+
+ internal void SetButton(MouseButton button, ButtonState state)
+ {
+ if (button < 0 || button > MouseButton.LastButton)
+ throw new ArgumentOutOfRangeException();
+
+ switch (state)
+ {
+ case ButtonState.Pressed:
+ this.state.EnableBit((int)button);
+ break;
+
+ case ButtonState.Released:
+ this.state.DisableBit((int)button);
+ break;
+ }
+ }
+
+ internal ButtonState GetButton(MouseButton button)
+ {
+ if (button < 0 || button > MouseButton.LastButton)
+ throw new ArgumentOutOfRangeException();
+
+ return
+ state.ReadBit((int)button) ?
+ ButtonState.Pressed : ButtonState.Released;
+ }
+
+ #endregion
+
+ #region Public Members
+
+ /// <summary>
+ /// Gets the X position of the mouse for the event.
+ /// </summary>
+ public int X { get { return state.X; } internal set { state.X = value; } }
+
+ /// <summary>
+ /// Gets the Y position of the mouse for the event.
+ /// </summary>
+ public int Y { get { return state.Y; } internal set { state.Y = value; } }
+
+ /// <summary>
+ /// Gets a <see cref="System.Drawing.Point"/> representing the location of the mouse for the event.
+ /// </summary>
+ public Point Position
+ {
+ get { return new Point(state.X, state.Y); }
+ set
+ {
+ X = value.X;
+ Y = value.Y;
+ }
+ }
+
+ /// <summary>
+ /// Gets the current <see cref="OpenTK.Input.MouseState"/>.
+ /// </summary>
+ public MouseState Mouse
+ {
+ get { return state; }
+ internal set { state = value; }
+ }
+
+ #endregion
+ }
+
+ /// <summary>
+ /// Defines the event data for <see cref="MouseDevice.Move"/> events.
+ /// </summary>
+ /// <remarks>
+ /// <para>
+ /// Do not cache instances of this type outside their event handler.
+ /// If necessary, you can clone an instance using the
+ /// <see cref="MouseMoveEventArgs(MouseMoveEventArgs)"/> constructor.
+ /// </para>
+ /// </remarks>
+ public class MouseMoveEventArgs : MouseEventArgs
+ {
+ #region Fields
+
+ int x_delta, y_delta;
+
+ #endregion
+
+ #region Constructors
+
+ /// <summary>
+ /// Constructs a new <see cref="MouseMoveEventArgs"/> instance.
+ /// </summary>
+ public MouseMoveEventArgs() { }
+
+ /// <summary>
+ /// Constructs a new <see cref="MouseMoveEventArgs"/> instance.
+ /// </summary>
+ /// <param name="x">The X position.</param>
+ /// <param name="y">The Y position.</param>
+ /// <param name="xDelta">The change in X position produced by this event.</param>
+ /// <param name="yDelta">The change in Y position produced by this event.</param>
+ public MouseMoveEventArgs(int x, int y, int xDelta, int yDelta)
+ : base(x, y)
+ {
+ XDelta = xDelta;
+ YDelta = yDelta;
+ }
+
+ /// <summary>
+ /// Constructs a new <see cref="MouseMoveEventArgs"/> instance.
+ /// </summary>
+ /// <param name="args">The <see cref="MouseMoveEventArgs"/> instance to clone.</param>
+ public MouseMoveEventArgs(MouseMoveEventArgs args)
+ : this(args.X, args.Y, args.XDelta, args.YDelta)
+ {
+ }
+
+ #endregion
+
+ #region Public Members
+
+ /// <summary>
+ /// Gets the change in X position produced by this event.
+ /// </summary>
+ public int XDelta { get { return x_delta; } internal set { x_delta = value; } }
+
+ /// <summary>
+ /// Gets the change in Y position produced by this event.
+ /// </summary>
+ public int YDelta { get { return y_delta; } internal set { y_delta = value; } }
+
+ #endregion
+ }
+
+ /// <summary>
+ /// Defines the event data for <see cref="MouseDevice.ButtonDown"/> and <see cref="MouseDevice.ButtonUp"/> events.
+ /// </summary>
+ /// <remarks>
+ /// <para>
+ /// Do not cache instances of this type outside their event handler.
+ /// If necessary, you can clone an instance using the
+ /// <see cref="MouseButtonEventArgs(MouseButtonEventArgs)"/> constructor.
+ /// </para>
+ /// </remarks>
+ public class MouseButtonEventArgs : MouseEventArgs
+ {
+ #region Fields
+
+ MouseButton button;
+
+ #endregion
+
+ #region Constructors
+
+ /// <summary>
+ /// Constructs a new <see cref="MouseButtonEventArgs"/> instance.
+ /// </summary>
+ public MouseButtonEventArgs() { }
+
+ /// <summary>
+ /// Constructs a new <see cref="MouseButtonEventArgs"/> instance.
+ /// </summary>
+ /// <param name="x">The X position.</param>
+ /// <param name="y">The Y position.</param>
+ /// <param name="button">The mouse button for the event.</param>
+ /// <param name="pressed">The current state of the button.</param>
+ public MouseButtonEventArgs(int x, int y, MouseButton button, bool pressed)
+ : base(x, y)
+ {
+ this.button = button;
+ this.IsPressed = pressed;
+ }
+
+ /// <summary>
+ /// Constructs a new <see cref="MouseButtonEventArgs"/> instance.
+ /// </summary>
+ /// <param name="args">The <see cref="MouseButtonEventArgs"/> instance to clone.</param>
+ public MouseButtonEventArgs(MouseButtonEventArgs args)
+ : this(args.X, args.Y, args.Button, args.IsPressed)
+ {
+ }
+
+ #endregion
+
+ #region Public Members
+
+ /// <summary>
+ /// Gets the <see cref="MouseButton"/> that triggered this event.
+ /// </summary>
+ public MouseButton Button { get { return button; } internal set { button = value; } }
+
+ /// <summary>
+ /// Gets a System.Boolean representing the state of the mouse button for the event.
+ /// </summary>
+ public bool IsPressed
+ {
+ get { return GetButton(Button) == ButtonState.Pressed; }
+ internal set { SetButton(Button, value ? ButtonState.Pressed : ButtonState.Released); }
+ }
+
+ #endregion
+ }
+
+ /// <summary>
+ /// Defines the event data for <see cref="MouseDevice.WheelChanged"/> events.
+ /// </summary>
+ /// <remarks>
+ /// <para>
+ /// Do not cache instances of this type outside their event handler.
+ /// If necessary, you can clone an instance using the
+ /// <see cref="MouseWheelEventArgs(MouseWheelEventArgs)"/> constructor.
+ /// </para>
+ /// </remarks>
+ public class MouseWheelEventArgs : MouseEventArgs
+ {
+ #region Fields
+
+ float delta;
+
+ #endregion
+
+ #region Constructors
+
+ /// <summary>
+ /// Constructs a new <see cref="MouseWheelEventArgs"/> instance.
+ /// </summary>
+ public MouseWheelEventArgs() { }
+
+ /// <summary>
+ /// Constructs a new <see cref="MouseWheelEventArgs"/> instance.
+ /// </summary>
+ /// <param name="x">The X position.</param>
+ /// <param name="y">The Y position.</param>
+ /// <param name="value">The value of the wheel.</param>
+ /// <param name="delta">The change in value of the wheel for this event.</param>
+ public MouseWheelEventArgs(int x, int y, int value, int delta)
+ : base(x, y)
+ {
+ Mouse.SetScrollAbsolute(Mouse.Scroll.X, value);
+ this.delta = delta;
+ }
+
+ /// <summary>
+ /// Constructs a new <see cref="MouseWheelEventArgs"/> instance.
+ /// </summary>
+ /// <param name="args">The <see cref="MouseWheelEventArgs"/> instance to clone.</param>
+ public MouseWheelEventArgs(MouseWheelEventArgs args)
+ : this(args.X, args.Y, args.Value, args.Delta)
+ {
+ }
+
+ #endregion
+
+ #region Public Members
+
+ /// <summary>
+ /// Gets the value of the wheel in integer units.
+ /// To support high-precision mice, it is recommended to use <see cref="ValuePrecise"/> instead.
+ /// </summary>
+ public int Value { get { return (int)Math.Round(Mouse.Scroll.Y, MidpointRounding.AwayFromZero); } }
+
+ /// <summary>
+ /// Gets the change in value of the wheel for this event in integer units.
+ /// To support high-precision mice, it is recommended to use <see cref="DeltaPrecise"/> instead.
+ /// </summary>
+ public int Delta { get { return (int)Math.Round(delta, MidpointRounding.AwayFromZero); } }
+
+ /// <summary>
+ /// Gets the precise value of the wheel in floating-point units.
+ /// </summary>
+ public float ValuePrecise
+ {
+ get { return Mouse.Scroll.Y; }
+ }
+
+ /// <summary>
+ /// Gets the precise change in value of the wheel for this event in floating-point units.
+ /// </summary>
+ public float DeltaPrecise { get { return delta; } internal set { delta = value; } }
+
+ #endregion
+ }
+}
diff --git a/src/Input/MouseScroll.cs b/src/Input/MouseScroll.cs
new file mode 100644
index 00000000..a04e9d69
--- /dev/null
+++ b/src/Input/MouseScroll.cs
@@ -0,0 +1,118 @@
+#region License
+//
+// MouseWheel.cs
+//
+// Author:
+// Stefanos A. <stapostol@gmail.com>
+//
+// Copyright (c) 2006-2014 Stefanos Apostolopoulos
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+//
+#endregion
+
+using System;
+
+namespace Crow
+{
+ /// <summary>
+ /// Represents the state of a mouse wheel.
+ /// </summary>
+ public struct MouseScroll : IEquatable<MouseScroll>
+ {
+ #region Public Members
+
+ /// <summary>
+ /// Gets the absolute horizontal offset of the wheel,
+ /// or 0 if no horizontal scroll wheel exists.
+ /// </summary>
+ /// <value>The x.</value>
+ public float X { get; internal set; }
+
+ /// <summary>
+ /// Gets the absolute vertical offset of the wheel,
+ /// or 0 if no vertical scroll wheel exists.
+ /// </summary>
+ /// <value>The y.</value>
+ public float Y { get; internal set; }
+
+ /// <param name="left">A <see cref="MouseScroll"/> instance to test for equality.</param>
+ /// <param name="right">A <see cref="MouseScroll"/> instance to test for equality.</param>
+ public static bool operator ==(MouseScroll left, MouseScroll right)
+ {
+ return left.Equals(right);
+ }
+
+ /// <param name="left">A <see cref="MouseScroll"/> instance to test for inequality.</param>
+ /// <param name="right">A <see cref="MouseScroll"/> instance to test for inequality.</param>
+ public static bool operator !=(MouseScroll left, MouseScroll right)
+ {
+ return !left.Equals(right);
+ }
+
+ /// <summary>
+ /// Returns a <see cref="System.String"/> that represents the current <see cref="OpenTK.Input.MouseScroll"/>.
+ /// </summary>
+ /// <returns>A <see cref="System.String"/> that represents the current <see cref="OpenTK.Input.MouseScroll"/>.</returns>
+ public override string ToString()
+ {
+ return string.Format("[X={0:0.00}, Y={1:0.00}]", X, Y);
+ }
+
+ /// <summary>
+ /// Serves as a hash function for a <see cref="OpenTK.Input.MouseScroll"/> object.
+ /// </summary>
+ /// <returns>A hash code for this instance that is suitable for use in hashing algorithms and data structures such as a
+ /// hash table.</returns>
+ public override int GetHashCode()
+ {
+ return X.GetHashCode() ^ Y.GetHashCode();
+ }
+
+ /// <summary>
+ /// Determines whether the specified <see cref="System.Object"/> is equal to the current <see cref="OpenTK.Input.MouseScroll"/>.
+ /// </summary>
+ /// <param name="obj">The <see cref="System.Object"/> to compare with the current <see cref="OpenTK.Input.MouseScroll"/>.</param>
+ /// <returns><c>true</c> if the specified <see cref="System.Object"/> is equal to the current
+ /// <see cref="OpenTK.Input.MouseScroll"/>; otherwise, <c>false</c>.</returns>
+ public override bool Equals(object obj)
+ {
+ return
+ obj is MouseScroll &&
+ Equals((MouseScroll)obj);
+ }
+
+ #endregion
+
+ #region IEquatable Members
+
+ /// <summary>
+ /// Determines whether the specified <see cref="OpenTK.Input.MouseScroll"/> is equal to the current <see cref="OpenTK.Input.MouseScroll"/>.
+ /// </summary>
+ /// <param name="other">The <see cref="OpenTK.Input.MouseScroll"/> to compare with the current <see cref="OpenTK.Input.MouseScroll"/>.</param>
+ /// <returns><c>true</c> if the specified <see cref="OpenTK.Input.MouseScroll"/> is equal to the current
+ /// <see cref="OpenTK.Input.MouseScroll"/>; otherwise, <c>false</c>.</returns>
+ public bool Equals(MouseScroll other)
+ {
+ return X == other.X && Y == other.Y;
+ }
+
+ #endregion
+ }
+}
diff --git a/src/Input/MouseState.cs b/src/Input/MouseState.cs
new file mode 100644
index 00000000..c645062a
--- /dev/null
+++ b/src/Input/MouseState.cs
@@ -0,0 +1,360 @@
+ #region License
+ //
+ // The Open Toolkit Library License
+ //
+ // Copyright (c) 2006 - 2009 the Open Toolkit library.
+ //
+ // Permission is hereby granted, free of charge, to any person obtaining a copy
+ // of this software and associated documentation files (the "Software"), to deal
+ // in the Software without restriction, including without limitation the rights to
+ // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+ // the Software, and to permit persons to whom the Software is furnished to do
+ // so, subject to the following conditions:
+ //
+ // The above copyright notice and this permission notice shall be included in all
+ // copies or substantial portions of the Software.
+ //
+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ // OTHER DEALINGS IN THE SOFTWARE.
+ //
+ #endregion
+
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace Crow
+{
+ /// <summary>
+ /// Encapsulates the state of a mouse device.
+ /// </summary>
+ public struct MouseState : IEquatable<MouseState>
+ {
+ #region Fields
+
+ internal const int MaxButtons = 16; // we are storing in an ushort
+ Point position;
+ MouseScroll scroll;
+ ushort buttons;
+ bool is_connected;
+
+ #endregion
+
+ #region Public Members
+
+ /// <summary>
+ /// Gets a <see cref="System.Boolean"/> indicating whether the specified
+ /// <see cref="OpenTK.Input.MouseButton"/> is pressed.
+ /// </summary>
+ /// <param name="button">The <see cref="OpenTK.Input.MouseButton"/> to check.</param>
+ /// <returns>True if key is pressed; false otherwise.</returns>
+ public bool this[MouseButton button]
+ {
+ get { return IsButtonDown(button); }
+ internal set
+ {
+ if (value)
+ EnableBit((int)button);
+ else
+ DisableBit((int)button);
+ }
+ }
+
+ /// <summary>
+ /// Gets a <see cref="System.Boolean"/> indicating whether this button is down.
+ /// </summary>
+ /// <param name="button">The <see cref="OpenTK.Input.MouseButton"/> to check.</param>
+ public bool IsButtonDown(MouseButton button)
+ {
+ return ReadBit((int)button);
+ }
+
+ /// <summary>
+ /// Gets a <see cref="System.Boolean"/> indicating whether this button is up.
+ /// </summary>
+ /// <param name="button">The <see cref="OpenTK.Input.MouseButton"/> to check.</param>
+ public bool IsButtonUp(MouseButton button)
+ {
+ return !ReadBit((int)button);
+ }
+
+ /// <summary>
+ /// Gets the absolute wheel position in integer units.
+ /// To support high-precision mice, it is recommended to use <see cref="WheelPrecise"/> instead.
+ /// </summary>
+ public int Wheel
+ {
+ get { return (int)Math.Round(scroll.Y, MidpointRounding.AwayFromZero); }
+ }
+
+ /// <summary>
+ /// Gets the absolute wheel position in floating-point units.
+ /// </summary>
+ public float WheelPrecise
+ {
+ get { return scroll.Y; }
+ }
+
+ /// <summary>
+ /// Gets a <see cref="OpenTK.Input.MouseScroll"/> instance,
+ /// representing the current state of the mouse scroll wheel.
+ /// </summary>
+ public MouseScroll Scroll
+ {
+ get { return scroll; }
+ }
+
+ /// <summary>
+ /// Gets an integer representing the absolute x position of the pointer, in window pixel coordinates.
+ /// </summary>
+ public int X
+ {
+ get { return position.X; }
+ internal set { position.X = value; }
+ }
+
+ /// <summary>
+ /// Gets an integer representing the absolute y position of the pointer, in window pixel coordinates.
+ /// </summary>
+ public int Y
+ {
+ get { return position.Y; }
+ internal set { position.Y = value; }
+ }
+
+ /// <summary>
+ /// Gets a <see cref="System.Boolean"/> indicating whether the left mouse button is pressed.
+ /// This property is intended for XNA compatibility.
+ /// </summary>
+ public ButtonState LeftButton
+ {
+ get { return IsButtonDown(MouseButton.Left) ? ButtonState.Pressed : ButtonState.Released; }
+ }
+
+ /// <summary>
+ /// Gets a <see cref="System.Boolean"/> indicating whether the middle mouse button is pressed.
+ /// This property is intended for XNA compatibility.
+ /// </summary>
+ public ButtonState MiddleButton
+ {
+ get { return IsButtonDown(MouseButton.Middle) ? ButtonState.Pressed : ButtonState.Released; }
+ }
+
+ /// <summary>
+ /// Gets a <see cref="System.Boolean"/> indicating whether the right mouse button is pressed.
+ /// This property is intended for XNA compatibility.
+ /// </summary>
+ public ButtonState RightButton
+ {
+ get { return IsButtonDown(MouseButton.Right) ? ButtonState.Pressed : ButtonState.Released; }
+ }
+
+ /// <summary>
+ /// Gets a <see cref="System.Boolean"/> indicating whether the first extra mouse button is pressed.
+ /// This property is intended for XNA compatibility.
+ /// </summary>
+ public ButtonState XButton1
+ {
+ get { return IsButtonDown(MouseButton.Button1) ? ButtonState.Pressed : ButtonState.Released; }
+ }
+
+ /// <summary>
+ /// Gets a <see cref="System.Boolean"/> indicating whether the second extra mouse button is pressed.
+ /// This property is intended for XNA compatibility.
+ /// </summary>
+ public ButtonState XButton2
+ {
+ get { return IsButtonDown(MouseButton.Button2) ? ButtonState.Pressed : ButtonState.Released; }
+ }
+
+ /// <summary>
+ /// 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.
+ /// </summary>
+ public int ScrollWheelValue
+ {
+ get { return Wheel; }
+ }
+
+ /// <summary>
+ /// Gets a value indicating whether this instance is connected.
+ /// </summary>
+ /// <value><c>true</c> if this instance is connected; otherwise, <c>false</c>.</value>
+ public bool IsConnected
+ {
+ get { return is_connected; }
+ internal set { is_connected = value; }
+ }
+
+ /// <summary>
+ /// Checks whether two <see cref="MouseState" /> instances are equal.
+ /// </summary>
+ /// <param name="left">
+ /// A <see cref="MouseState"/> instance.
+ /// </param>
+ /// <param name="right">
+ /// A <see cref="MouseState"/> instance.
+ /// </param>
+ /// <returns>
+ /// True if both left is equal to right; false otherwise.
+ /// </returns>
+ public static bool operator ==(MouseState left, MouseState right)
+ {
+ return left.Equals(right);
+ }
+
+ /// <summary>
+ /// Checks whether two <see cref="MouseState" /> instances are not equal.
+ /// </summary>
+ /// <param name="left">
+ /// A <see cref="MouseState"/> instance.
+ /// </param>
+ /// <param name="right">
+ /// A <see cref="MouseState"/> instance.
+ /// </param>
+ /// <returns>
+ /// True if both left is not equal to right; false otherwise.
+ /// </returns>
+ public static bool operator !=(MouseState left, MouseState right)
+ {
+ return !left.Equals(right);
+ }
+
+ /// <summary>
+ /// Compares to an object instance for equality.
+ /// </summary>
+ /// <param name="obj">
+ /// The <see cref="System.Object"/> to compare to.
+ /// </param>
+ /// <returns>
+ /// True if this instance is equal to obj; false otherwise.
+ /// </returns>
+ public override bool Equals(object obj)
+ {
+ if (obj is MouseState)
+ {
+ return this == (MouseState)obj;
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ /// <summary>
+ /// Generates a hashcode for the current instance.
+ /// </summary>
+ /// <returns>
+ /// A <see cref="System.Int32"/> represting the hashcode for this instance.
+ /// </returns>
+ public override int GetHashCode()
+ {
+ return buttons.GetHashCode() ^ X.GetHashCode() ^ Y.GetHashCode() ^ scroll.GetHashCode();
+ }
+
+ /// <summary>
+ /// Returns a <see cref="System.String"/> that represents the current <see cref="OpenTK.Input.MouseState"/>.
+ /// </summary>
+ /// <returns>A <see cref="System.String"/> that represents the current <see cref="OpenTK.Input.MouseState"/>.</returns>
+ public override string ToString()
+ {
+ string b = Convert.ToString(buttons, 2).PadLeft(10, '0');
+ return String.Format("[X={0}, Y={1}, Scroll={2}, Buttons={3}, IsConnected={4}]",
+ X, Y, Scroll, b, IsConnected);
+ }
+
+ #endregion
+
+ #region Internal Members
+
+ internal Point Position
+ {
+ get { return position; }
+ set { position = value; }
+ }
+
+ internal bool ReadBit(int offset)
+ {
+ ValidateOffset(offset);
+ return (buttons & (1 << offset)) != 0;
+ }
+
+ internal void EnableBit(int offset)
+ {
+ ValidateOffset(offset);
+ buttons |= unchecked((ushort)(1 << offset));
+ }
+
+ internal void DisableBit(int offset)
+ {
+ ValidateOffset(offset);
+ buttons &= unchecked((ushort)(~(1 << offset)));
+ }
+
+ internal void MergeBits(MouseState other)
+ {
+ buttons |= other.buttons;
+ SetScrollRelative(other.scroll.X, other.scroll.Y);
+ X += other.X;
+ Y += other.Y;
+ IsConnected |= other.IsConnected;
+ }
+
+ internal void SetIsConnected(bool value)
+ {
+ IsConnected = value;
+ }
+
+ #region Internal Members
+
+ internal void SetScrollAbsolute(float x, float y)
+ {
+ scroll.X = x;
+ scroll.Y = y;
+ }
+
+ internal void SetScrollRelative(float x, float y)
+ {
+ scroll.X += x;
+ scroll.Y += y;
+ }
+
+ #endregion
+
+ #endregion
+
+ #region Private Members
+
+ static void ValidateOffset(int offset)
+ {
+ if (offset < 0 || offset >= 16)
+ throw new ArgumentOutOfRangeException("offset");
+ }
+
+ #endregion
+
+ #region IEquatable<MouseState> Members
+
+ /// <summary>
+ /// Compares two MouseState instances.
+ /// </summary>
+ /// <param name="other">The instance to compare two.</param>
+ /// <returns>True, if both instances are equal; false otherwise.</returns>
+ public bool Equals(MouseState other)
+ {
+ return
+ buttons == other.buttons &&
+ X == other.X &&
+ Y == other.Y &&
+ Scroll == other.Scroll;
+ }
+
+ #endregion
+ }
+}
diff --git a/src/OpenTKGameWindow.cs b/src/OpenTKGameWindow.cs
index 17d9581f..c6f95ba3 100644
--- a/src/OpenTKGameWindow.cs
+++ b/src/OpenTKGameWindow.cs
@@ -28,7 +28,6 @@ using System.Xml;
using Cairo;
using OpenTK;
using OpenTK.Graphics.OpenGL;
-using OpenTK.Input;
namespace Crow
{
@@ -179,11 +178,12 @@ namespace Crow
}
#region Events
//those events are raised only if mouse isn't in a graphic object
- public event EventHandler<MouseWheelEventArgs> MouseWheelChanged;
- public event EventHandler<MouseButtonEventArgs> MouseButtonUp;
- public event EventHandler<MouseButtonEventArgs> MouseButtonDown;
- public event EventHandler<MouseButtonEventArgs> MouseClick;
- public event EventHandler<MouseMoveEventArgs> MouseMove;
+ public event EventHandler<OpenTK.Input.MouseWheelEventArgs> MouseWheelChanged;
+ public event EventHandler<OpenTK.Input.MouseButtonEventArgs> MouseButtonUp;
+ public event EventHandler<OpenTK.Input.MouseButtonEventArgs> MouseButtonDown;
+ public event EventHandler<OpenTK.Input.MouseButtonEventArgs> MouseClick;
+ public event EventHandler<OpenTK.Input.MouseMoveEventArgs> MouseMove;
+ public event EventHandler<OpenTK.Input.KeyboardKeyEventArgs> KeyboardKeyDown;
#endregion
#region graphic contexte
@@ -430,11 +430,11 @@ namespace Crow
{
base.OnLoad(e);
- Keyboard.KeyDown += new EventHandler<KeyboardKeyEventArgs>(Keyboard_KeyDown);
- Mouse.WheelChanged += new EventHandler<MouseWheelEventArgs>(Mouse_WheelChanged);
- Mouse.ButtonDown += new EventHandler<MouseButtonEventArgs>(Mouse_ButtonDown);
- Mouse.ButtonUp += new EventHandler<MouseButtonEventArgs>(Mouse_ButtonUp);
- Mouse.Move += new EventHandler<MouseMoveEventArgs>(Mouse_Move);
+ Keyboard.KeyDown += new EventHandler<OpenTK.Input.KeyboardKeyEventArgs>(Keyboard_KeyDown);
+ Mouse.WheelChanged += new EventHandler<OpenTK.Input.MouseWheelEventArgs>(Mouse_WheelChanged);
+ Mouse.ButtonDown += new EventHandler<OpenTK.Input.MouseButtonEventArgs>(Mouse_ButtonDown);
+ Mouse.ButtonUp += new EventHandler<OpenTK.Input.MouseButtonEventArgs>(Mouse_ButtonUp);
+ Mouse.Move += new EventHandler<OpenTK.Input.MouseMoveEventArgs>(Mouse_Move);
GL.ClearColor(0.0f, 0.0f, 0.0f, 0.0f);
@@ -457,8 +457,11 @@ namespace Crow
#endregion
#region Mouse Handling
- void Mouse_Move(object sender, MouseMoveEventArgs e)
+
+ void Mouse_Move(object sender, OpenTK.Input.MouseMoveEventArgs otk_e)
{
+ MouseMoveEventArgs e = new MouseMoveEventArgs (otk_e.X, otk_e.Y, otk_e.XDelta, otk_e.YDelta);
+
if (_activeWidget != null) {
//first, ensure object is still in the graphic tree
if (_activeWidget.HostContainer == null) {
@@ -525,12 +528,14 @@ namespace Crow
}
}
hoverWidget = null;
- MouseMove.Raise (this, e);
+ MouseMove.Raise (this, otk_e);
}
- void Mouse_ButtonUp(object sender, MouseButtonEventArgs e)
+ void Mouse_ButtonUp(object sender, OpenTK.Input.MouseButtonEventArgs otk_e)
{
+ MouseButtonEventArgs e = new MouseButtonEventArgs (otk_e.X, otk_e.Y, (Crow.MouseButton)otk_e.Button, otk_e.IsPressed);
+
if (_activeWidget == null) {
- MouseButtonUp.Raise (this, e);
+ MouseButtonUp.Raise (this, otk_e);
return;
}
@@ -543,10 +548,12 @@ namespace Crow
_activeWidget.onMouseUp (this, e);
activeWidget = null;
}
- void Mouse_ButtonDown(object sender, MouseButtonEventArgs e)
- {
+ void Mouse_ButtonDown(object sender, OpenTK.Input.MouseButtonEventArgs otk_e)
+ {
+ MouseButtonEventArgs e = new MouseButtonEventArgs (otk_e.X, otk_e.Y, (Crow.MouseButton)otk_e.Button, otk_e.IsPressed);
+
if (hoverWidget == null) {
- MouseButtonDown.Raise (this, e);
+ MouseButtonDown.Raise (this, otk_e);
return;
}
@@ -559,10 +566,12 @@ namespace Crow
mouseRepeatThread = new Thread (mouseRepeatThreadFunc);
mouseRepeatThread.Start ();
}
- void Mouse_WheelChanged(object sender, MouseWheelEventArgs e)
+ void Mouse_WheelChanged(object sender, OpenTK.Input.MouseWheelEventArgs otk_e)
{
+ MouseWheelEventArgs e = new MouseWheelEventArgs (otk_e.X, otk_e.Y, otk_e.Value, otk_e.Delta);
+
if (hoverWidget == null) {
- MouseWheelChanged.Raise (this, e);
+ MouseWheelChanged.Raise (this, otk_e);
return;
}
hoverWidget.onMouseWheel (this, e);
@@ -584,10 +593,15 @@ namespace Crow
#endregion
#region keyboard Handling
- void Keyboard_KeyDown(object sender, KeyboardKeyEventArgs e)
- {
- if (_focusedWidget == null)
- return;
+ KeyboardState Keyboad = new KeyboardState ();
+ void Keyboard_KeyDown(object sender, OpenTK.Input.KeyboardKeyEventArgs otk_e)
+ {
+// if (_focusedWidget == null) {
+ KeyboardKeyDown.Raise (this, otk_e);
+// return;
+// }
+ Keyboad.SetKeyState ((Crow.Key)otk_e.Key, true);
+ KeyboardKeyEventArgs e = new KeyboardKeyEventArgs((Crow.Key)otk_e.Key, otk_e.IsRepeat,Keyboad);
_focusedWidget.onKeyDown (sender, e);
}
#endregion