From: jpbruyere Date: Sat, 13 Feb 2016 17:10:23 +0000 (+0100) Subject: base changed done, need mouse state to be updated X-Git-Tag: v0.4~93^2~17 X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=fa6dd3d807f7c7c9292b5f4d5cc10406d10e173d;p=jp%2Fcrow.git base changed done, need mouse state to be updated --- diff --git a/Crow.csproj b/Crow.csproj index 68975169..2c519d58 100644 --- a/Crow.csproj +++ b/Crow.csproj @@ -137,6 +137,16 @@ + + + + + + + + + + @@ -172,6 +182,7 @@ + diff --git a/Tests/GOLIBTest_0.cs b/Tests/GOLIBTest_0.cs index 32067ae2..a82c7d6d 100644 --- a/Tests/GOLIBTest_0.cs +++ b/Tests/GOLIBTest_0.cs @@ -5,7 +5,6 @@ using System; using System.Runtime.InteropServices; using OpenTK; using OpenTK.Graphics.OpenGL; -using OpenTK.Input; using System.Diagnostics; @@ -61,25 +60,25 @@ namespace test6 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); diff --git a/Tests/GOLIBTest_4.cs b/Tests/GOLIBTest_4.cs index 9c8fe385..37596eeb 100644 --- a/Tests/GOLIBTest_4.cs +++ b/Tests/GOLIBTest_4.cs @@ -5,7 +5,6 @@ using System; using System.Runtime.InteropServices; using OpenTK; using OpenTK.Graphics.OpenGL; -using OpenTK.Input; using System.Diagnostics; diff --git a/Tests/GOLIBTest_5.cs b/Tests/GOLIBTest_5.cs index 664483be..349549ec 100644 --- a/Tests/GOLIBTest_5.cs +++ b/Tests/GOLIBTest_5.cs @@ -2,7 +2,6 @@ using System; using System.Runtime.InteropServices; using OpenTK; using OpenTK.Graphics.OpenGL; -using OpenTK.Input; using System.Diagnostics; diff --git a/Tests/GOLIBTest_DirViewer.cs b/Tests/GOLIBTest_DirViewer.cs index a1d20c4b..04e46aa4 100644 --- a/Tests/GOLIBTest_DirViewer.cs +++ b/Tests/GOLIBTest_DirViewer.cs @@ -5,7 +5,6 @@ using System; using System.Runtime.InteropServices; using OpenTK; using OpenTK.Graphics.OpenGL; -using OpenTK.Input; using System.Diagnostics; diff --git a/Tests/GOLIBTest_Listbox.cs b/Tests/GOLIBTest_Listbox.cs index 1dd1f555..76631020 100644 --- a/Tests/GOLIBTest_Listbox.cs +++ b/Tests/GOLIBTest_Listbox.cs @@ -5,7 +5,6 @@ using System; using System.Runtime.InteropServices; using OpenTK; using OpenTK.Graphics.OpenGL; -using OpenTK.Input; using System.Diagnostics; @@ -97,23 +96,23 @@ namespace test 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 () diff --git a/Tests/GOLIBTest_TypeViewer.cs b/Tests/GOLIBTest_TypeViewer.cs index 8864d1da..39e5a527 100644 --- a/Tests/GOLIBTest_TypeViewer.cs +++ b/Tests/GOLIBTest_TypeViewer.cs @@ -5,7 +5,6 @@ using System; using System.Runtime.InteropServices; using OpenTK; using OpenTK.Graphics.OpenGL; -using OpenTK.Input; using System.Diagnostics; diff --git a/Tests/GOLIBTests.cs b/Tests/GOLIBTests.cs index b70a2542..a0c8a84c 100644 --- a/Tests/GOLIBTests.cs +++ b/Tests/GOLIBTests.cs @@ -5,7 +5,6 @@ using System; using System.Runtime.InteropServices; using OpenTK; using OpenTK.Graphics.OpenGL; -using OpenTK.Input; using System.Diagnostics; @@ -189,41 +188,22 @@ namespace test { 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; @@ -235,7 +215,24 @@ namespace test 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) { @@ -265,4 +262,4 @@ namespace test Debug.WriteLine ("cancel"); } } -} \ No newline at end of file +} diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj index a01a92af..b7c32c01 100644 --- a/Tests/Tests.csproj +++ b/Tests/Tests.csproj @@ -47,7 +47,6 @@ - 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 . 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 +{ + /// + /// Enumerates possible mouse button states. + /// + public enum ButtonState + { + /// + /// Indicates that a mouse button is released. + /// + Released = 0, + + /// + /// Indicates that a mouse button is pressed. + /// + 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 +{ + /// + /// Enumerates available buttons for a GamePad device. + /// + [Flags] + public enum Buttons + { + /// + /// DPad up direction button + /// + DPadUp = 1 << 0, + + /// + /// DPad down direction button + /// + DPadDown = 1 << 1, + + /// + /// DPad left direction button + /// + DPadLeft = 1 << 2, + + /// + /// DPad right direction button + /// + DPadRight = 1 << 3, + + /// + /// Start button + /// + Start = 1 << 4, + + /// + /// Back button + /// + Back = 1 << 5, + + /// + /// Left stick button + /// + LeftStick = 1 << 6, + + /// + /// Right stick button + /// + RightStick = 1 << 7, + + /// + /// Left shoulder button + /// + LeftShoulder = 1 << 8, + + /// + /// Right shoulder button + /// + RightShoulder = 1 << 9, + + /// + /// Home button + /// + Home = 1 << 11, + + /// + /// Home button + /// + BigButton = Home, + + /// + /// A button + /// + A = 1 << 12, + + /// + /// B button + /// + B = 1 << 13, + + /// + /// X button + /// + X = 1 << 14, + + /// + /// Y button + /// + Y = 1 << 15, + + /// + /// Left thumbstick left direction button + /// + LeftThumbstickLeft = 1 << 21, + + /// + /// Right trigger button + /// + RightTrigger = 1 << 22, + + /// + /// Left trigger button + /// + LeftTrigger = 1 << 23, + + /// + /// Right thumbstick up direction button + /// + RightThumbstickUp = 1 << 24, + + /// + /// Right thumbstick down direction button + /// + RightThumbstickDown = 1 << 25, + + /// + /// Right stick right direction button + /// + RightThumbstickRight = 1 << 26, + + /// + /// Right stick left direction button + /// + RightThumbstickLeft = 1 << 27, + + /// + /// Left stick up direction button + /// + LeftThumbstickUp = 1 << 28, + + /// + /// Left stick down direction button + /// + LeftThumbstickDown = 1 << 29, + + /// + /// Left stick right direction button + /// + 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 +{ + /// + /// The available keyboard keys. + /// + public enum Key : int + { + /// A key outside the known keys. + Unknown = 0, + + // Modifiers + /// The left shift key. + ShiftLeft, + /// The left shift key (equivalent to ShiftLeft). + LShift = ShiftLeft, + /// The right shift key. + ShiftRight, + /// The right shift key (equivalent to ShiftRight). + RShift = ShiftRight, + /// The left control key. + ControlLeft, + /// The left control key (equivalent to ControlLeft). + LControl = ControlLeft, + /// The right control key. + ControlRight, + /// The right control key (equivalent to ControlRight). + RControl = ControlRight, + /// The left alt key. + AltLeft, + /// The left alt key (equivalent to AltLeft. + LAlt = AltLeft, + /// The right alt key. + AltRight, + /// The right alt key (equivalent to AltRight). + RAlt = AltRight, + /// The left win key. + WinLeft, + /// The left win key (equivalent to WinLeft). + LWin = WinLeft, + /// The right win key. + WinRight, + /// The right win key (equivalent to WinRight). + RWin = WinRight, + /// The menu key. + Menu, + + // Function keys (hopefully enough for most keyboards - mine has 26) + // on X11 reports up to 35 function keys. + /// The F1 key. + F1, + /// The F2 key. + F2, + /// The F3 key. + F3, + /// The F4 key. + F4, + /// The F5 key. + F5, + /// The F6 key. + F6, + /// The F7 key. + F7, + /// The F8 key. + F8, + /// The F9 key. + F9, + /// The F10 key. + F10, + /// The F11 key. + F11, + /// The F12 key. + F12, + /// The F13 key. + F13, + /// The F14 key. + F14, + /// The F15 key. + F15, + /// The F16 key. + F16, + /// The F17 key. + F17, + /// The F18 key. + F18, + /// The F19 key. + F19, + /// The F20 key. + F20, + /// The F21 key. + F21, + /// The F22 key. + F22, + /// The F23 key. + F23, + /// The F24 key. + F24, + /// The F25 key. + F25, + /// The F26 key. + F26, + /// The F27 key. + F27, + /// The F28 key. + F28, + /// The F29 key. + F29, + /// The F30 key. + F30, + /// The F31 key. + F31, + /// The F32 key. + F32, + /// The F33 key. + F33, + /// The F34 key. + F34, + /// The F35 key. + F35, + + // Direction arrows + /// The up arrow key. + Up, + /// The down arrow key. + Down, + /// The left arrow key. + Left, + /// The right arrow key. + Right, + + /// The enter key. + Enter, + /// The escape key. + Escape, + /// The space key. + Space, + /// The tab key. + Tab, + /// The backspace key. + BackSpace, + /// The backspace key (equivalent to BackSpace). + Back = BackSpace, + /// The insert key. + Insert, + /// The delete key. + Delete, + /// The page up key. + PageUp, + /// The page down key. + PageDown, + /// The home key. + Home, + /// The end key. + End, + /// The caps lock key. + CapsLock, + /// The scroll lock key. + ScrollLock, + /// The print screen key. + PrintScreen, + /// The pause key. + Pause, + /// The num lock key. + NumLock, + + // Special keys + /// The clear key (Keypad5 with NumLock disabled, on typical keyboards). + Clear, + /// The sleep key. + 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 + /// The keypad 0 key. + Keypad0, + /// The keypad 1 key. + Keypad1, + /// The keypad 2 key. + Keypad2, + /// The keypad 3 key. + Keypad3, + /// The keypad 4 key. + Keypad4, + /// The keypad 5 key. + Keypad5, + /// The keypad 6 key. + Keypad6, + /// The keypad 7 key. + Keypad7, + /// The keypad 8 key. + Keypad8, + /// The keypad 9 key. + Keypad9, + /// The keypad divide key. + KeypadDivide, + /// The keypad multiply key. + KeypadMultiply, + /// The keypad subtract key. + KeypadSubtract, + /// The keypad minus key (equivalent to KeypadSubtract). + KeypadMinus = KeypadSubtract, + /// The keypad add key. + KeypadAdd, + /// The keypad plus key (equivalent to KeypadAdd). + KeypadPlus = KeypadAdd, + /// The keypad decimal key. + KeypadDecimal, + /// The keypad period key (equivalent to KeypadDecimal). + KeypadPeriod = KeypadDecimal, + /// The keypad enter key. + KeypadEnter, + + // Letters + /// The A key. + A, + /// The B key. + B, + /// The C key. + C, + /// The D key. + D, + /// The E key. + E, + /// The F key. + F, + /// The G key. + G, + /// The H key. + H, + /// The I key. + I, + /// The J key. + J, + /// The K key. + K, + /// The L key. + L, + /// The M key. + M, + /// The N key. + N, + /// The O key. + O, + /// The P key. + P, + /// The Q key. + Q, + /// The R key. + R, + /// The S key. + S, + /// The T key. + T, + /// The U key. + U, + /// The V key. + V, + /// The W key. + W, + /// The X key. + X, + /// The Y key. + Y, + /// The Z key. + Z, + + // Numbers + /// The number 0 key. + Number0, + /// The number 1 key. + Number1, + /// The number 2 key. + Number2, + /// The number 3 key. + Number3, + /// The number 4 key. + Number4, + /// The number 5 key. + Number5, + /// The number 6 key. + Number6, + /// The number 7 key. + Number7, + /// The number 8 key. + Number8, + /// The number 9 key. + Number9, + + // Symbols + /// The tilde key. + Tilde, + /// The grave key (equivaent to Tilde). + Grave = Tilde, + /// The minus key. + Minus, + //Equal, + /// The plus key. + Plus, + /// The left bracket key. + BracketLeft, + /// The left bracket key (equivalent to BracketLeft). + LBracket = BracketLeft, + /// The right bracket key. + BracketRight, + /// The right bracket key (equivalent to BracketRight). + RBracket = BracketRight, + /// The semicolon key. + Semicolon, + /// The quote key. + Quote, + /// The comma key. + Comma, + /// The period key. + Period, + /// The slash key. + Slash, + /// The backslash key. + BackSlash, + /// The secondary backslash key. + NonUSBackSlash, + /// Indicates the last available keyboard key. + 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. +// +// 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 +{ + /// + /// Enumerates modifier keys. + /// + [Flags] + public enum KeyModifiers : byte + { + /// + /// The alt key modifier (option on Mac). + /// + Alt = 1 << 0, + + /// + /// The control key modifier. + /// + Control = 1 << 1, + + /// + /// The shift key modifier. + /// + 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 +{ + /// + /// Defines the event data for events. + /// + /// + /// + /// Do not cache instances of this type outside their event handler. + /// If necessary, you can clone a KeyboardEventArgs instance using the + /// constructor. + /// + /// + public class KeyboardKeyEventArgs : EventArgs + { + #region Fields + + Key key; + bool repeat; + KeyboardState state; + + #endregion + + #region Constructors + + /// + /// Constructs a new KeyboardEventArgs instance. + /// + public KeyboardKeyEventArgs(Key _key, bool _repeat, KeyboardState _state) + { + key = _key; + repeat = _repeat; + state = _state; + } + + /// + /// Constructs a new KeyboardEventArgs instance. + /// + /// An existing KeyboardEventArgs instance to clone. + public KeyboardKeyEventArgs(KeyboardKeyEventArgs args) + { + Key = args.Key; + } + + #endregion + + #region Public Members + + /// + /// Gets the that generated this event. + /// + public Key Key + { + get { return key; } + internal set { key = value; } + } + + /// + /// Gets the scancode which generated this event. + /// + [CLSCompliant(false)] + public uint ScanCode + { + get { return (uint)Key; } + } + + /// + /// Gets a value indicating whether is pressed. + /// + /// true if pressed; otherwise, false. + public bool Alt + { + get { return state[Key.AltLeft] || state[Key.AltRight]; } + } + + /// + /// Gets a value indicating whether is pressed. + /// + /// true if pressed; otherwise, false. + public bool Control + { + get { return state[Key.ControlLeft] || state[Key.ControlRight]; } + } + + /// + /// Gets a value indicating whether is pressed. + /// + /// true if pressed; otherwise, false. + public bool Shift + { + get { return state[Key.ShiftLeft] || state[Key.ShiftRight]; } + } + + /// + /// Gets a bitwise combination representing the + /// that are currently pressed. + /// + /// The modifiers. + public KeyModifiers Modifiers + { + get + { + KeyModifiers mods = 0; + mods |= Alt ? KeyModifiers.Alt : 0; + mods |= Control ? KeyModifiers.Control : 0; + mods |= Shift ? KeyModifiers.Shift : 0; + return mods; + } + } + + /// + /// Gets the current . + /// + /// The keyboard. + public KeyboardState Keyboard + { + get { return state; } + internal set { state = value; } + } + + /// + /// Gets a indicating whether + /// this key event is a repeat. + /// + /// + /// 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. + /// + 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 +{ + /// + /// Encapsulates the state of a Keyboard device. + /// + public struct KeyboardState : IEquatable + { + #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 + + /// + /// Gets a indicating whether the specified + /// is pressed. + /// + /// The to check. + /// True if key is pressed; false otherwise. + public bool this[Key key] + { + get { return IsKeyDown(key); } + internal set { SetKeyState(key, value); } + } + + /// + /// Gets a indicating whether the specified + /// is pressed. + /// + /// The scancode to check. + /// True if code is pressed; false otherwise. + public bool this[short code] + { + get { return IsKeyDown((Key)code); } + } + + /// + /// Gets a indicating whether this key is down. + /// + /// The to check. + public bool IsKeyDown(Key key) + { + return ReadBit((int)key); + } + + /// + /// Gets a indicating whether this scan code is down. + /// + /// The scan code to check. + public bool IsKeyDown(short code) + { + return code >= 0 && code < (short)Key.LastKey && ReadBit(code); + } + + /// + /// Gets a indicating whether this key is up. + /// + /// The to check. + public bool IsKeyUp(Key key) + { + return !ReadBit((int)key); + } + + /// + /// Gets a indicating whether this scan code is down. + /// + /// The scan code to check. + public bool IsKeyUp(short code) + { + return !IsKeyDown(code); + } + + /// + /// Gets a indicating whether this keyboard + /// is connected. + /// + 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 + + /// + /// Checks whether two instances are equal. + /// + /// + /// A instance. + /// + /// + /// A instance. + /// + /// + /// True if both left is equal to right; false otherwise. + /// + public static bool operator ==(KeyboardState left, KeyboardState right) + { + return left.Equals(right); + } + + /// + /// Checks whether two instances are not equal. + /// + /// + /// A instance. + /// + /// + /// A instance. + /// + /// + /// True if both left is not equal to right; false otherwise. + /// + public static bool operator !=(KeyboardState left, KeyboardState right) + { + return !left.Equals(right); + } + + /// + /// Compares to an object instance for equality. + /// + /// + /// The to compare to. + /// + /// + /// True if this instance is equal to obj; false otherwise. + /// + public override bool Equals(object obj) + { + if (obj is KeyboardState) + { + return this == (KeyboardState)obj; + } + else + { + return false; + } + } + + /// + /// Generates a hashcode for the current instance. + /// + /// + /// A represting the hashcode for this instance. + /// + 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 Members + + /// + /// Compares two KeyboardState instances. + /// + /// The instance to compare two. + /// True, if both instances are equal; false otherwise. + 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 +{ + /// + /// Enumerates all possible mouse buttons. + /// + public enum MouseButton + { + /// + /// The left mouse button. + /// + Left = 0, + /// + /// The middle mouse button. + /// + Middle, + /// + /// The right mouse button. + /// + Right, + /// + /// The first extra mouse button. + /// + Button1, + /// + /// The second extra mouse button. + /// + Button2, + /// + /// The third extra mouse button. + /// + Button3, + /// + /// The fourth extra mouse button. + /// + Button4, + /// + /// The fifth extra mouse button. + /// + Button5, + /// + /// The sixth extra mouse button. + /// + Button6, + /// + /// The seventh extra mouse button. + /// + Button7, + /// + /// The eigth extra mouse button. + /// + Button8, + /// + /// The ninth extra mouse button. + /// + Button9, + /// + /// Indicates the last available mouse button. + /// + 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. +// +// 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 +{ + /// + /// Defines the event data for events. + /// + /// + /// + /// Do not cache instances of this type outside their event handler. + /// If necessary, you can clone an instance using the + /// constructor. + /// + /// + public class MouseEventArgs : EventArgs + { + #region Fields + + MouseState state; + + #endregion + + #region Constructors + + /// + /// Constructs a new instance. + /// + public MouseEventArgs() + { + state.SetIsConnected(true); + } + + /// + /// Constructs a new instance. + /// + /// The X position. + /// The Y position. + public MouseEventArgs(int x, int y) + : this() + { + state.X = x; + state.Y = y; + } + + /// + /// Constructs a new instance. + /// + /// The instance to clone. + 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 + + /// + /// Gets the X position of the mouse for the event. + /// + public int X { get { return state.X; } internal set { state.X = value; } } + + /// + /// Gets the Y position of the mouse for the event. + /// + public int Y { get { return state.Y; } internal set { state.Y = value; } } + + /// + /// Gets a representing the location of the mouse for the event. + /// + public Point Position + { + get { return new Point(state.X, state.Y); } + set + { + X = value.X; + Y = value.Y; + } + } + + /// + /// Gets the current . + /// + public MouseState Mouse + { + get { return state; } + internal set { state = value; } + } + + #endregion + } + + /// + /// Defines the event data for events. + /// + /// + /// + /// Do not cache instances of this type outside their event handler. + /// If necessary, you can clone an instance using the + /// constructor. + /// + /// + public class MouseMoveEventArgs : MouseEventArgs + { + #region Fields + + int x_delta, y_delta; + + #endregion + + #region Constructors + + /// + /// Constructs a new instance. + /// + public MouseMoveEventArgs() { } + + /// + /// Constructs a new instance. + /// + /// The X position. + /// The Y position. + /// The change in X position produced by this event. + /// The change in Y position produced by this event. + public MouseMoveEventArgs(int x, int y, int xDelta, int yDelta) + : base(x, y) + { + XDelta = xDelta; + YDelta = yDelta; + } + + /// + /// Constructs a new instance. + /// + /// The instance to clone. + public MouseMoveEventArgs(MouseMoveEventArgs args) + : this(args.X, args.Y, args.XDelta, args.YDelta) + { + } + + #endregion + + #region Public Members + + /// + /// Gets the change in X position produced by this event. + /// + public int XDelta { get { return x_delta; } internal set { x_delta = value; } } + + /// + /// Gets the change in Y position produced by this event. + /// + public int YDelta { get { return y_delta; } internal set { y_delta = value; } } + + #endregion + } + + /// + /// Defines the event data for and events. + /// + /// + /// + /// Do not cache instances of this type outside their event handler. + /// If necessary, you can clone an instance using the + /// constructor. + /// + /// + public class MouseButtonEventArgs : MouseEventArgs + { + #region Fields + + MouseButton button; + + #endregion + + #region Constructors + + /// + /// Constructs a new instance. + /// + public MouseButtonEventArgs() { } + + /// + /// Constructs a new instance. + /// + /// The X position. + /// The Y position. + /// The mouse button for the event. + /// The current state of the button. + public MouseButtonEventArgs(int x, int y, MouseButton button, bool pressed) + : base(x, y) + { + this.button = button; + this.IsPressed = pressed; + } + + /// + /// Constructs a new instance. + /// + /// The instance to clone. + public MouseButtonEventArgs(MouseButtonEventArgs args) + : this(args.X, args.Y, args.Button, args.IsPressed) + { + } + + #endregion + + #region Public Members + + /// + /// Gets the that triggered this event. + /// + public MouseButton Button { get { return button; } internal set { button = value; } } + + /// + /// Gets a System.Boolean representing the state of the mouse button for the event. + /// + public bool IsPressed + { + get { return GetButton(Button) == ButtonState.Pressed; } + internal set { SetButton(Button, value ? ButtonState.Pressed : ButtonState.Released); } + } + + #endregion + } + + /// + /// Defines the event data for events. + /// + /// + /// + /// Do not cache instances of this type outside their event handler. + /// If necessary, you can clone an instance using the + /// constructor. + /// + /// + public class MouseWheelEventArgs : MouseEventArgs + { + #region Fields + + float delta; + + #endregion + + #region Constructors + + /// + /// Constructs a new instance. + /// + public MouseWheelEventArgs() { } + + /// + /// Constructs a new instance. + /// + /// The X position. + /// The Y position. + /// The value of the wheel. + /// The change in value of the wheel for this event. + public MouseWheelEventArgs(int x, int y, int value, int delta) + : base(x, y) + { + Mouse.SetScrollAbsolute(Mouse.Scroll.X, value); + this.delta = delta; + } + + /// + /// Constructs a new instance. + /// + /// The instance to clone. + public MouseWheelEventArgs(MouseWheelEventArgs args) + : this(args.X, args.Y, args.Value, args.Delta) + { + } + + #endregion + + #region Public Members + + /// + /// Gets the value of the wheel in integer units. + /// To support high-precision mice, it is recommended to use instead. + /// + public int Value { get { return (int)Math.Round(Mouse.Scroll.Y, MidpointRounding.AwayFromZero); } } + + /// + /// Gets the change in value of the wheel for this event in integer units. + /// To support high-precision mice, it is recommended to use instead. + /// + public int Delta { get { return (int)Math.Round(delta, MidpointRounding.AwayFromZero); } } + + /// + /// Gets the precise value of the wheel in floating-point units. + /// + public float ValuePrecise + { + get { return Mouse.Scroll.Y; } + } + + /// + /// Gets the precise change in value of the wheel for this event in floating-point units. + /// + 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. +// +// 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 +{ + /// + /// Represents the state of a mouse wheel. + /// + public struct MouseScroll : IEquatable + { + #region Public Members + + /// + /// Gets the absolute horizontal offset of the wheel, + /// or 0 if no horizontal scroll wheel exists. + /// + /// The x. + public float X { get; internal set; } + + /// + /// Gets the absolute vertical offset of the wheel, + /// or 0 if no vertical scroll wheel exists. + /// + /// The y. + public float Y { get; internal set; } + + /// A instance to test for equality. + /// A instance to test for equality. + public static bool operator ==(MouseScroll left, MouseScroll right) + { + return left.Equals(right); + } + + /// A instance to test for inequality. + /// A instance to test for inequality. + public static bool operator !=(MouseScroll left, MouseScroll right) + { + return !left.Equals(right); + } + + /// + /// Returns a that represents the current . + /// + /// A that represents the current . + public override string ToString() + { + return string.Format("[X={0:0.00}, Y={1:0.00}]", X, Y); + } + + /// + /// Serves as a hash function for a object. + /// + /// A hash code for this instance that is suitable for use in hashing algorithms and data structures such as a + /// hash table. + public override int GetHashCode() + { + return X.GetHashCode() ^ Y.GetHashCode(); + } + + /// + /// Determines whether the specified is equal to the current . + /// + /// The to compare with the current . + /// true if the specified is equal to the current + /// ; otherwise, false. + public override bool Equals(object obj) + { + return + obj is MouseScroll && + Equals((MouseScroll)obj); + } + + #endregion + + #region IEquatable Members + + /// + /// Determines whether the specified is equal to the current . + /// + /// The to compare with the current . + /// true if the specified is equal to the current + /// ; otherwise, false. + 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 +{ + /// + /// Encapsulates the state of a mouse device. + /// + public struct MouseState : IEquatable + { + #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 + + /// + /// Gets a indicating whether the specified + /// is pressed. + /// + /// The to check. + /// True if key is pressed; false otherwise. + public bool this[MouseButton button] + { + get { return IsButtonDown(button); } + internal set + { + if (value) + EnableBit((int)button); + else + DisableBit((int)button); + } + } + + /// + /// Gets a indicating whether this button is down. + /// + /// The to check. + public bool IsButtonDown(MouseButton button) + { + return ReadBit((int)button); + } + + /// + /// Gets a indicating whether this button is up. + /// + /// The to check. + public bool IsButtonUp(MouseButton button) + { + return !ReadBit((int)button); + } + + /// + /// Gets the absolute wheel position in integer units. + /// To support high-precision mice, it is recommended to use instead. + /// + public int Wheel + { + get { return (int)Math.Round(scroll.Y, MidpointRounding.AwayFromZero); } + } + + /// + /// Gets the absolute wheel position in floating-point units. + /// + public float WheelPrecise + { + get { return scroll.Y; } + } + + /// + /// Gets a instance, + /// representing the current state of the mouse scroll wheel. + /// + public MouseScroll Scroll + { + get { return scroll; } + } + + /// + /// Gets an integer representing the absolute x position of the pointer, in window pixel coordinates. + /// + public int X + { + get { return position.X; } + internal set { position.X = value; } + } + + /// + /// Gets an integer representing the absolute y position of the pointer, in window pixel coordinates. + /// + public int Y + { + get { return position.Y; } + internal set { position.Y = value; } + } + + /// + /// Gets a indicating whether the left mouse button is pressed. + /// This property is intended for XNA compatibility. + /// + public ButtonState LeftButton + { + get { return IsButtonDown(MouseButton.Left) ? ButtonState.Pressed : ButtonState.Released; } + } + + /// + /// Gets a indicating whether the middle mouse button is pressed. + /// This property is intended for XNA compatibility. + /// + public ButtonState MiddleButton + { + get { return IsButtonDown(MouseButton.Middle) ? ButtonState.Pressed : ButtonState.Released; } + } + + /// + /// Gets a indicating whether the right mouse button is pressed. + /// This property is intended for XNA compatibility. + /// + public ButtonState RightButton + { + get { return IsButtonDown(MouseButton.Right) ? ButtonState.Pressed : ButtonState.Released; } + } + + /// + /// Gets a indicating whether the first extra mouse button is pressed. + /// This property is intended for XNA compatibility. + /// + public ButtonState XButton1 + { + get { return IsButtonDown(MouseButton.Button1) ? ButtonState.Pressed : ButtonState.Released; } + } + + /// + /// Gets a indicating whether the second extra mouse button is pressed. + /// This property is intended for XNA compatibility. + /// + public ButtonState XButton2 + { + get { return IsButtonDown(MouseButton.Button2) ? ButtonState.Pressed : ButtonState.Released; } + } + + /// + /// 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 instead. + /// + public int ScrollWheelValue + { + get { return Wheel; } + } + + /// + /// Gets a value indicating whether this instance is connected. + /// + /// true if this instance is connected; otherwise, false. + public bool IsConnected + { + get { return is_connected; } + internal set { is_connected = value; } + } + + /// + /// Checks whether two instances are equal. + /// + /// + /// A instance. + /// + /// + /// A instance. + /// + /// + /// True if both left is equal to right; false otherwise. + /// + public static bool operator ==(MouseState left, MouseState right) + { + return left.Equals(right); + } + + /// + /// Checks whether two instances are not equal. + /// + /// + /// A instance. + /// + /// + /// A instance. + /// + /// + /// True if both left is not equal to right; false otherwise. + /// + public static bool operator !=(MouseState left, MouseState right) + { + return !left.Equals(right); + } + + /// + /// Compares to an object instance for equality. + /// + /// + /// The to compare to. + /// + /// + /// True if this instance is equal to obj; false otherwise. + /// + public override bool Equals(object obj) + { + if (obj is MouseState) + { + return this == (MouseState)obj; + } + else + { + return false; + } + } + + /// + /// Generates a hashcode for the current instance. + /// + /// + /// A represting the hashcode for this instance. + /// + public override int GetHashCode() + { + return buttons.GetHashCode() ^ X.GetHashCode() ^ Y.GetHashCode() ^ scroll.GetHashCode(); + } + + /// + /// Returns a that represents the current . + /// + /// A that represents the current . + 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 Members + + /// + /// Compares two MouseState instances. + /// + /// The instance to compare two. + /// True, if both instances are equal; false otherwise. + 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 MouseWheelChanged; - public event EventHandler MouseButtonUp; - public event EventHandler MouseButtonDown; - public event EventHandler MouseClick; - public event EventHandler MouseMove; + public event EventHandler MouseWheelChanged; + public event EventHandler MouseButtonUp; + public event EventHandler MouseButtonDown; + public event EventHandler MouseClick; + public event EventHandler MouseMove; + public event EventHandler KeyboardKeyDown; #endregion #region graphic contexte @@ -430,11 +430,11 @@ namespace Crow { base.OnLoad(e); - Keyboard.KeyDown += new EventHandler(Keyboard_KeyDown); - Mouse.WheelChanged += new EventHandler(Mouse_WheelChanged); - Mouse.ButtonDown += new EventHandler(Mouse_ButtonDown); - Mouse.ButtonUp += new EventHandler(Mouse_ButtonUp); - Mouse.Move += new EventHandler(Mouse_Move); + Keyboard.KeyDown += new EventHandler(Keyboard_KeyDown); + Mouse.WheelChanged += new EventHandler(Mouse_WheelChanged); + Mouse.ButtonDown += new EventHandler(Mouse_ButtonDown); + Mouse.ButtonUp += new EventHandler(Mouse_ButtonUp); + Mouse.Move += new EventHandler(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