<Compile Include="src\GraphicObjects\TabView.cs" />
<Compile Include="src\GraphicObjects\TabItem.cs" />
<Compile Include="src\GraphicObjects\DummyTemplate.cs" />
+ <Compile Include="src\Input\KeyboardKeyEventArgs.cs" />
+ <Compile Include="src\Input\Buttons.cs" />
+ <Compile Include="src\Input\ButtonState.cs" />
+ <Compile Include="src\Input\Key.cs" />
+ <Compile Include="src\Input\KeyboardState.cs" />
+ <Compile Include="src\Input\KeyModifiers.cs" />
+ <Compile Include="src\Input\MouseButton.cs" />
+ <Compile Include="src\Input\MouseEventArgs.cs" />
+ <Compile Include="src\Input\MouseScroll.cs" />
+ <Compile Include="src\Input\MouseState.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="System" />
<Folder Include="src\OpenGL\" />
<Folder Include="src\Fill\" />
<Folder Include="Styles\" />
+ <Folder Include="src\Input\" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Images\Icons\updown.svg" />
using System.Runtime.InteropServices;
using OpenTK;
using OpenTK.Graphics.OpenGL;
-using OpenTK.Input;
using System.Diagnostics;
l.Text = tmp.ToString ();
}
- protected override void OnKeyDown (KeyboardKeyEventArgs e)
- {
- switch (e.Key) {
- case Key.Left:
- g.Left++;
- break;
- case Key.Right:
- g.Left--;
- break;
- case Key.Up:
- g.Top--;
- break;
- case Key.Down:
- g.Top++;
- break;
- default:
- break;
- }
- }
+// protected override void OnKeyDown (KeyboardKeyEventArgs e)
+// {
+// switch (e.Key) {
+// case Key.Left:
+// g.Left++;
+// break;
+// case Key.Right:
+// g.Left--;
+// break;
+// case Key.Up:
+// g.Top--;
+// break;
+// case Key.Down:
+// g.Top++;
+// break;
+// default:
+// break;
+// }
+// }
protected override void OnUpdateFrame (FrameEventArgs e)
{
base.OnUpdateFrame (e);
using System.Runtime.InteropServices;
using OpenTK;
using OpenTK.Graphics.OpenGL;
-using OpenTK.Input;
using System.Diagnostics;
using System.Runtime.InteropServices;
using OpenTK;
using OpenTK.Graphics.OpenGL;
-using OpenTK.Input;
using System.Diagnostics;
using System.Runtime.InteropServices;
using OpenTK;
using OpenTK.Graphics.OpenGL;
-using OpenTK.Input;
using System.Diagnostics;
using System.Runtime.InteropServices;
using OpenTK;
using OpenTK.Graphics.OpenGL;
-using OpenTK.Input;
using System.Diagnostics;
TestList = Directory.GetFileSystemEntries("/home/jp/tmp/mtgdata/a", "*.txt",SearchOption.AllDirectories).ToList();
ValueChanged.Raise(this, new ValueChangeEventArgs ("TestList", TestList));
}
- protected override void OnMouseMove (MouseMoveEventArgs e)
- {
- base.OnMouseMove (e);
- ValueChanged.Raise (this, new ValueChangeEventArgs ("Hover", Hover));
- ValueChanged.Raise (this, new ValueChangeEventArgs ("MousePos", e.Position.ToString()));
- }
+// protected override void OnMouseMove (MouseMoveEventArgs e)
+// {
+// base.OnMouseMove (e);
+// ValueChanged.Raise (this, new ValueChangeEventArgs ("Hover", Hover));
+// ValueChanged.Raise (this, new ValueChangeEventArgs ("MousePos", e.Position.ToString()));
+// }
protected override void OnUpdateFrame (FrameEventArgs e)
{
base.OnUpdateFrame (e);
}
- protected override void OnKeyDown (KeyboardKeyEventArgs e)
- {
- TestList = Directory.GetFileSystemEntries("/home/jp/tmp/mtgdata/a", "*.txt",SearchOption.AllDirectories).ToList();
- //TestList.Add ("newly added list item");
- ValueChanged.Raise(this, new ValueChangeEventArgs ("TestList", TestList));
- }
+// protected override void OnKeyDown (KeyboardKeyEventArgs e)
+// {
+// TestList = Directory.GetFileSystemEntries("/home/jp/tmp/mtgdata/a", "*.txt",SearchOption.AllDirectories).ToList();
+// //TestList.Add ("newly added list item");
+// ValueChanged.Raise(this, new ValueChangeEventArgs ("TestList", TestList));
+// }
[STAThread]
static void Main ()
using System.Runtime.InteropServices;
using OpenTK;
using OpenTK.Graphics.OpenGL;
-using OpenTK.Input;
using System.Diagnostics;
using System.Runtime.InteropServices;
using OpenTK;
using OpenTK.Graphics.OpenGL;
-using OpenTK.Input;
using System.Diagnostics;
{
base.OnLoad (e);
//this.AddWidget(new test4());
+ KeyboardKeyDown += GOLIBTests_KeyboardKeyDown1;;
GraphicObject obj = LoadInterface("Interfaces/" + testFiles[idx]);
obj.DataSource = this;
- }
- protected override void OnUpdateFrame (FrameEventArgs e)
- {
- //if (frameCpt % 8 == 0)
- base.OnUpdateFrame (e);
-
- fps = (int)RenderFrequency;
-
-
- if (frameCpt > 50) {
- resetFps ();
- frameCpt = 0;
- GC.Collect();
- GC.WaitForPendingFinalizers();
- NotifyValueChanged("memory", GC.GetTotalMemory (false).ToString());
- }
- frameCpt++;
}
- protected override void OnKeyDown (KeyboardKeyEventArgs e)
+
+ void GOLIBTests_KeyboardKeyDown1 (object sender, OpenTK.Input.KeyboardKeyEventArgs e)
{
- if (FocusedWidget is TextBox) {
- base.OnKeyDown (e);
- return;
- }
- if (e.Key == Key.Escape) {
+ if (e.Key == OpenTK.Input.Key.Escape) {
this.Quit ();
return;
- } else if (e.Key == Key.L) {
+ } else if (e.Key == OpenTK.Input.Key.L) {
TestList.Add ("new string");
NotifyValueChanged ("TestList", TestList);
return;
- } else if (e.Key == Key.W) {
+ } else if (e.Key == OpenTK.Input.Key.W) {
GraphicObject w = LoadInterface("Interfaces/testWindow.goml");
w.DataSource = this;
return;
this.Title = testFiles [idx];
GraphicObject obj = LoadInterface("Interfaces/" + testFiles[idx]);
obj.DataSource = this;
+ }
+
+ protected override void OnUpdateFrame (FrameEventArgs e)
+ {
+ //if (frameCpt % 8 == 0)
+ base.OnUpdateFrame (e);
+
+ fps = (int)RenderFrequency;
+
+ if (frameCpt > 50) {
+ resetFps ();
+ frameCpt = 0;
+ GC.Collect();
+ GC.WaitForPendingFinalizers();
+ NotifyValueChanged("memory", GC.GetTotalMemory (false).ToString());
+ }
+ frameCpt++;
}
void onButClick(object send, MouseButtonEventArgs e)
{
Debug.WriteLine ("cancel");
}
}
-}
\ No newline at end of file
+}
<Reference Include="Mono.Cairo" />
</ItemGroup>
<ItemGroup>
- <Compile Include="GOLIBTest_4.cs" />
<Compile Include="GOLIBTest_Listbox.cs" />
<Compile Include="GOLIBTest_0.cs" />
<Compile Include="GOLIBTest_TypeViewer.cs" />
using System;
-using OpenTK.Input;
namespace Crow
{
using System.Xml.Serialization;
using Cairo;
-using OpenTK.Input;
using System.ComponentModel;
namespace Crow
using System;
-using OpenTK.Input;
using System.ComponentModel;
using System.Xml.Serialization;
using System;
using System.Xml.Serialization;
using System.Reflection;
-using OpenTK.Input;
using System.ComponentModel;
using System.Linq;
using System;
-using OpenTK.Input;
using System.ComponentModel;
using System.Xml.Serialization;
using System.IO;
using System.Collections.Generic;
using System.Diagnostics;
-using OpenTK.Input;
using System.Linq;
using System.Text.RegularExpressions;
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
{
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
using System.Text.RegularExpressions;
using System.Xml.Serialization;
using System.ComponentModel;
-using OpenTK.Input;
namespace Crow
{
-//
+ //
// ListBox.cs
//
// Author:
using System;
using System.Xml.Serialization;
using System.ComponentModel;
-using OpenTK.Input;
using Cairo;
namespace Crow
using System;
-using OpenTK.Input;
using System.ComponentModel;
using System.Xml.Serialization;
using System.ComponentModel;
using System.Diagnostics;
using Cairo;
-using OpenTK.Input;
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)
}
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;
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);
}
#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);
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)
// 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
{
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)
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);
|| 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);
TabOffset = tmp;
}
}
- public void butCloseTabClick (object sender, OpenTK.Input.MouseButtonEventArgs e){
+ public void butCloseTabClick (object sender, MouseButtonEventArgs e){
(Parent as TabView).RemoveChild(this);
}
#endregion
using System.ComponentModel;
using Cairo;
using System.Diagnostics;
-using OpenTK.Input;
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);
}
using System.ComponentModel;
using System.IO;
using System.Xml;
-using System.Linq;
using System.Diagnostics;
+using System.Linq;
namespace Crow
{
using System.Collections.Generic;
using System.Linq;
using System.Text;
-using OpenTK.Input;
using Cairo;
using System.Diagnostics;
using System.Xml.Serialization;
using System.Text.RegularExpressions;
using System.Xml.Serialization;
using System.ComponentModel;
-using OpenTK.Input;
namespace Crow
{
using System.Xml.Serialization;
using System.ComponentModel;
using System.Diagnostics;
-using OpenTK.Input;
namespace Crow
{
--- /dev/null
+ #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
+ }
+}
--- /dev/null
+//
+// 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,
+ }
+}
--- /dev/null
+ #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
--- /dev/null
+#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
+ }
+}
--- /dev/null
+#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
+ }
+}
--- /dev/null
+ #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
+ }
+}
--- /dev/null
+ #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
+ }
+}
--- /dev/null
+#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
+ }
+}
--- /dev/null
+#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
+ }
+}
--- /dev/null
+ #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
+ }
+}
using Cairo;
using OpenTK;
using OpenTK.Graphics.OpenGL;
-using OpenTK.Input;
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
{
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);
#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) {
}
}
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;
}
_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;
}
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);
#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