]> O.S.I.I.S - jp/crow.git/commitdiff
keypress event
authorjp <jp_bruyere@hotmail.com>
Tue, 15 Mar 2016 13:10:54 +0000 (14:10 +0100)
committerjp <jp_bruyere@hotmail.com>
Tue, 15 Mar 2016 13:10:54 +0000 (14:10 +0100)
Crow.csproj
OTKCrow/OpenTKGameWindow.cs
src/GraphicObjects/GraphicObject.cs
src/GraphicObjects/TextBox.cs
src/Input/KeyPressEventArgs.cs [new file with mode: 0644]
src/Interface.cs

index baa5b7a903bfa51be3ff4e81dcd06433b533a38c..740f8558c3eba7e59e7b485e2514b7f990fa8e0c 100644 (file)
     <Compile Include="src\rsvg\SizeFunc.cs" />
     <Compile Include="src\MouseCursorChangedEventArgs.cs" />
     <Compile Include="src\GraphicObjects\IBindable.cs" />
+    <Compile Include="src\Input\KeyPressEventArgs.cs" />
   </ItemGroup>
   <ItemGroup>
     <Reference Include="System" />
index 94a52a0c6d014f3ebdd90f91786ecfea6f1a8f42..b11c2ce0d598ff97f94f1f7b402adc83f80cbf5b 100644 (file)
@@ -153,6 +153,8 @@ namespace Crow
                public event EventHandler<OpenTK.Input.MouseButtonEventArgs> MouseClick;
                public event EventHandler<OpenTK.Input.MouseMoveEventArgs> MouseMove;
                public event EventHandler<OpenTK.Input.KeyboardKeyEventArgs> KeyboardKeyDown;
+               public event EventHandler<OpenTK.Input.KeyboardKeyEventArgs> KeyboardKeyUp;
+
                #endregion
 
                #region graphic context
@@ -230,7 +232,9 @@ namespace Crow
                {
                        base.OnLoad(e);
 
+                       this.KeyPress += new EventHandler<OpenTK.KeyPressEventArgs>(OpenTKGameWindow_KeyPress);
                        Keyboard.KeyDown += new EventHandler<OpenTK.Input.KeyboardKeyEventArgs>(Keyboard_KeyDown);
+                       Keyboard.KeyUp += new EventHandler<OpenTK.Input.KeyboardKeyEventArgs>(Keyboard_KeyUp);
                        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);
@@ -246,6 +250,7 @@ namespace Crow
 
                        shader = new Crow.TexturedShader ();
                }
+
                protected override void OnUpdateFrame(FrameEventArgs e)
                {
                        base.OnUpdateFrame(e);
@@ -322,6 +327,15 @@ namespace Crow
                        if (!CrowInterface.ProcessKeyDown((int)otk_e.Key))
                                KeyboardKeyDown.Raise (this, otk_e);
         }
+               void Keyboard_KeyUp(object sender, OpenTK.Input.KeyboardKeyEventArgs otk_e)
+               {
+                       if (!CrowInterface.ProcessKeyUp((int)otk_e.Key))
+                               KeyboardKeyUp.Raise (this, otk_e);
+               }
+               void OpenTKGameWindow_KeyPress (object sender, OpenTK.KeyPressEventArgs e)
+               {
+                       CrowInterface.ProcessKeyPress (e.KeyChar);
+               }
         #endregion
     }
 }
index b61ecb326bbe976f5d7dc148e0bda0fb03759a04..c526e9096e4aeebe128985885c57fa96b216cb03 100644 (file)
@@ -156,6 +156,7 @@ namespace Crow
                public event EventHandler<MouseMoveEventArgs> MouseLeave;
                public event EventHandler<KeyboardKeyEventArgs> KeyDown;
                public event EventHandler<KeyboardKeyEventArgs> KeyUp;
+               public event EventHandler<KeyPressEventArgs> KeyPress;
                public event EventHandler Focused;
                public event EventHandler Unfocused;
                public event EventHandler<LayoutingEventArgs> LayoutChanged;
@@ -939,6 +940,9 @@ namespace Crow
                public virtual void onKeyDown(object sender, KeyboardKeyEventArgs e){
                        KeyDown.Raise (sender, e);
                }
+               public virtual void onKeyPress(object sender, KeyPressEventArgs e){
+                       KeyPress.Raise (sender, e);
+               }
         #endregion
 
                #region Mouse handling
index 14cc18304465adde738124e0f685fa83005a5201..d3b8319c0256a42b3e90d34a9b112dfd127ebbb7 100644 (file)
@@ -72,7 +72,6 @@ namespace Crow
                public override void onKeyDown (object sender, KeyboardKeyEventArgs e)
                {
                        base.onKeyDown (sender, e);
-
                        Key key = e.Key;
 
                        switch (key)
@@ -80,9 +79,9 @@ namespace Crow
                        case Key.Back:
                                if (!selectionIsEmpty)
                                {
-//                                     Text = Text.Remove(selectionStart, selectionEnd - selectionStart);
-//                                     selReleasePos = -1;
-//                                     currentCol = selBeginPos;
+                                       //                                      Text = Text.Remove(selectionStart, selectionEnd - selectionStart);
+                                       //                                      selReleasePos = -1;
+                                       //                                      currentCol = selBeginPos;
                                }
                                else 
                                        this.DeleteChar();
@@ -141,62 +140,24 @@ namespace Crow
                                break;
                        case Key.RWin:
                                break;
-                       case Key.Tab:
-                               this.Insert("\t");
-                               break;
-                       case Key.KeypadDecimal:
-                               this.Insert (".");                                      
-                               break;
-                       case Key.Space:
-                               this.Insert(" ");
-                               break;
-                       case Key.KeypadDivide:
-                       case Key.Slash:
-                               this.Insert("/");
-                               break;
-                       case Key.KeypadMultiply:
-                               this.Insert("*");
-                               break;
-                       case Key.KeypadMinus:
-                       case Key.Minus:
-                               this.Insert("-");
-                               break;
-                       case Key.KeypadPlus:
-                       case Key.Plus:
-                               this.Insert("+");
-                               break;
-                       case Key.ShiftLeft:
-                       case Key.ShiftRight:
-                       case Key.AltLeft:
-                       case Key.AltRight:
-                               break;
-                       case Key.Semicolon:
-                               this.Insert(";");
-                               break;
                        default:
-                               if (!selectionIsEmpty)
-                               {
-//                                     Text = Text.Remove(selectionStart, selectionEnd - selectionStart);
-//                                     currentCol = selBeginPos;
-                               }
-
-                               string k = "?";
-                               if ((char)key >= 67 && (char)key <= 76)
-                                       k = ((int)key - 67).ToString();
-                               else if ((char)key >= 109 && (char)key <= 118)
-                                       k = ((int)key - 109).ToString();
-                               else if (e.Shift)
-                                       k = key.ToString();
-                               else
-                                       k = key.ToString().ToLower();
+                               break;
+                       }
+                       if (Width < 0)
+                               RegisterForLayouting (LayoutingType.Width);
+                       if (Height < 0)
+                               RegisterForLayouting (LayoutingType.Height);
+                       RegisterForGraphicUpdate();
+               }
+               public override void onKeyPress (object sender, KeyPressEventArgs e)
+               {
+                       base.onKeyPress (sender, e);
 
-                               this.Insert (k);
+                       this.Insert (e.KeyChar.ToString());
 
-                               SelRelease = -1;
-                               SelBegin = new Point(CurrentColumn, SelBegin.Y);
+                       SelRelease = -1;
+                       SelBegin = new Point(CurrentColumn, SelBegin.Y);
 
-                               break;
-                       }
                        if (Width < 0)
                                RegisterForLayouting (LayoutingType.Width);
                        if (Height < 0)
diff --git a/src/Input/KeyPressEventArgs.cs b/src/Input/KeyPressEventArgs.cs
new file mode 100644 (file)
index 0000000..7399061
--- /dev/null
@@ -0,0 +1,58 @@
+// #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;
+
+namespace Crow
+{
+    /// <summary>
+    /// Defines the event arguments for KeyPress events. Instances of this class are cached:
+    /// KeyPressEventArgs should only be used inside the relevant event, unless manually cloned.
+    /// </summary>
+    public class KeyPressEventArgs : EventArgs
+    {
+        char key_char;
+        
+        /// <summary>
+        /// Constructs a new instance.
+        /// </summary>
+        /// <param name="keyChar">The ASCII character that was typed.</param>
+        public KeyPressEventArgs(char keyChar)
+        {
+            KeyChar = keyChar;
+        }
+
+        /// <summary>
+        /// Gets a <see cref="System.Char"/> that defines the ASCII character that was typed.
+        /// </summary>
+        public char KeyChar
+        {
+            get { return key_char; }
+            internal set { key_char = value; }
+        }
+    }
+}
index 7531091851a3ae431a7c4f0c4eab499c305cb12b..86f3008818548801ad49cefd2032dd43d998c890 100644 (file)
@@ -663,6 +663,14 @@ namespace Crow
                        return true;
                }
 
+               public bool ProcessKeyPress(char Key){
+                       if (_focusedWidget == null)
+                               return false;
+                       KeyPressEventArgs e = new KeyPressEventArgs(Key);
+                       _focusedWidget.onKeyPress (this, e);
+                       return true;
+               }
+
                volatile bool mouseRepeatOn;
                volatile int mouseRepeatCount;
                Thread mouseRepeatThread;